#12978: conditionally_defined decorator for methods and other attributes
-------------------------------------------------+-------------------------
       Reporter:  nthiery                        |        Owner:  jason
           Type:  enhancement                    |       Status:
       Priority:  major                          |  needs_review
      Component:  misc                           |    Milestone:  sage-
       Keywords:  categories,                    |  wishlist
  conditionally_defined                          |   Resolution:
        Authors:                                 |    Merged in:
Report Upstream:  N/A                            |    Reviewers:
         Branch:                                 |  Work issues:
   Dependencies:  #15056                         |       Commit:
                                                 |     Stopgaps:
-------------------------------------------------+-------------------------
Changes (by SimonKing):

 * status:  new => needs_review


Comment:

 I have attached a new patch version, and now I think the
 conditionally_defined wrapper is feature-complete. The documentation
 provides extensive tests.

 Restriction:
 - We *must* have new style classes, since for an old style class there
 seems to be no way to access the class hierarchy.

 What one can do with the wrapper:
 - It works on usual methods and special Python methods (`__hash__`,
 `__len__`, ...)
 - It works well in combination with other wrappers such as cached_method
 and lazy_attribute.
 - It works within the category framework. To make it work, if `B` is a
 class, `B.bar` must yield the wrapper and not the unbound method in
 default implementation.
 - Even though `B.bar` is a wrapper, it behaves like an unbound method:
 When calling it like `B.bar(b, *args, **kwds)` with `b` an instance of `B`
 then it calls the default implementation on `b` with the given additional
 arguments. Note that this is not necessarily the same as
 `b.bar(*args,**kwds)`, because the latter may be the non-default
 implementation inherited from a super-class.
 - Introspection works. Again, since `B.bar` is a wrapper and not an
 unbound method, we need some magic, namely methods `_sage_doc_`,
 `_sage_src_` etc.

 The only thing I can currently think of that does not work:
 {{{
 class A(object):
     x = 5
 class B(A):
     @conditionally_defined(lambda x: x.condition>0)
     x = 7
 }}}
 No idea how this can be made work.

 I just realise that I forgot to add examples for the introspection method.
 Once they are added, it can be reviewed!

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