#12978: conditionally_defined decorator for methods and nested classes
-------------------------------------------------+-------------------------
       Reporter:  nthiery                        |        Owner:  jason
           Type:  enhancement                    |       Status:  new
       Priority:  major                          |    Milestone:  sage-
      Component:  misc                           |  wishlist
       Keywords:  categories,                    |   Resolution:
  conditionally_defined                          |    Merged in:
        Authors:                                 |    Reviewers:
Report Upstream:  N/A                            |  Work issues:
         Branch:                                 |       Commit:
   Dependencies:                                 |     Stopgaps:
-------------------------------------------------+-------------------------

Comment (by SimonKing):

 The problem with nested classes is that, if you define
 {{{
 class C:
     __metaclass__ = NestedClassMetaclass
     class D:
         pass
 }}}
 then ''during creation of C'' (`NestedClassMetaclass.__init__(C)`) all
 attributes of C that are classes get their names changed (here: It becomes
 "C.D" instead of "D"). But if you pack the nested class into a
 conditionally_defined decorator, then `NestedClassMetaclass.__init__(C)`
 will not realise that D is a class, and will thus not change the name.

 Moreover, at least in the current implementation, the
 conditionally_defined decorator operates with the name of the wrapped
 object. But if this name is not a valid attribute name (such as `"C.D"`)
 then the whole construction will fail anyway.

 In any case, I think it would be more interesting to be able to
 conditionally define a cached method, in ''both'' versions I suggested:
 {{{
     @cached_method
     @conditionally_defined(...):
     def meth(...):
         ...
 }}}
 being a cached method whose underlying implementation is conditional, and
 {{{
     @conditionally_defined(...):
     @cached_method
     def meth(...):
         ...
 }}}
 being a cached method that is only used conditionally.

--
Ticket URL: <http://trac.sagemath.org/ticket/12978#comment:14>
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.

Reply via email to