#10963: More functorial constructions
-------------------------------------+-------------------------------------
Reporter: nthiery | Owner: stumpc5
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-6.1
Component: categories | Resolution:
Keywords: days54 | Merged in:
Authors: Nicolas M. Thiéry | Reviewers: Simon King, Frédéric
Report Upstream: N/A | Chapoton
Branch: | Work issues: Detect and fix
public/ticket/10963 | Heisenbugs
Dependencies: #11224, #8327, | Commit:
#10193, #12895, #14516, #14722, | 5ccf253b17c151d8e773037ac634a64f84f03075
#13589, #14471, #15069, #15094, | Stopgaps:
#11688, #13394, #15150, #15506 |
-------------------------------------+-------------------------------------
Comment (by SimonKing):
Replying to [comment:245 nbruin]:
> A little further experimenting shows that the recursion occurs in the
`assert` statement in the fragment
> {{{
> base_module =
importlib.import_module("sage.categories."+base_module_name)
> base_category_class = getattr(base_module, base_name)
> assert getattr(base_category_class, axiom, None) is cls,
\
> "Missing (lazy import) link for %s to %s for axiom
%s?"%(base_category_class, cls, axiom)
> return base_category_class, axiom
> }}}
Indeed, this looks suspicious. It could result in importing something
while importing it.
> This is a cached method, but since it is still running through its first
call the cache isn't there yet, so another call happens.
This could be a work-around: Start the function by ''filling'' the cache
of this function with some value (say: `(cls, '')`, or some special value
like `NotImplemented` that can be tested against when calling the function
somewhere), so that the function really will be called only once for each
input.
Or rather: We could wrap it in `try: ... finally:`, emptying the cache
from the wrong value. Then, in case of an error being raised, the cache
will be clean afterwards, and if there is no error then the cache will be
filled with the correct value anyway.
BTW, note the typo in the docstring: `however we ca notdo it robustly`...
> The surprising thing is that the code finishes at all.
Indeed.
> To fix this: it seems that a lot of magic (looking at module
> names etc.) is there for convenience (i.e., that a !FiniteSet is a Set
with the
> Finite axiom). Perhaps it's worthwhile to consider coding these bits a
little
> more conservatively, exchanging some convenience for enhanced
maintainability.
+1. In some discussion above, I suggested to keep track of the axioms of a
category by a tuple that is stored as an attribute. Actually I suggested a
different approach to implement axioms. But I think this ticket has
progressed too much, and ''if'' (really "if", I don't know if I will) I
want to try to implement the alternative approach, then I can still do it
after merging Nicolas' approach.
--
Ticket URL: <http://trac.sagemath.org/ticket/10963#comment:250>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.