#11224: Support for the descriptor protocol for lazy_import'ed objects
---------------------------------+------------------------------------------
Reporter: nthiery | Owner: jason
Type: enhancement | Status: new
Priority: major | Milestone: sage-4.7.1
Component: misc | Keywords:
Author: Nicolas M. ThiƩry | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
---------------------------------+------------------------------------------
This patch enable to lazy import objects using the descriptor protocol
(readonly at this point: just the __get__ method).
A sample application taken from the doc::
{{{
Here we show how to take a function in a module, and lazy
import it as a method of a class. For the sake of this
example, we add manually a function in sage.all::
sage: def my_method(self): return self
sage: sage.all.my_method = my_method
Now we lazy import it as a method of a new class ``Foo``::
sage: from sage.misc.lazy_import import LazyImport
sage: class Foo:
... my_method = LazyImport('sage.all', 'my_method')
Now we can use it as a usual method::
sage: Foo().my_method()
<__main__.Foo instance at ...>
sage: Foo.my_method
<unbound method Foo.my_method>
sage: Foo().my_method
<bound method Foo.my_method of <__main__.Foo instance at ...>>
Currently, ``my_method`` remains a lazy imported object in the
class dictionary, even when it has already been used, which is
not as efficient as it could be (but see #11003)::
sage: type(Foo.__dict__["my_method"])
<type 'sage.misc.lazy_import.LazyImport'>
}}}
In practice, I needed this feature for further work on categories and
functorial constructions, around #11111 and #10963.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11224>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.