#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 nthiery):
Replying to [comment:6 SimonKing]:
> What about the documentation? Of course, if we have an instance x and a
conditionally defined method meth, then `x.meth` will be a specific
implementation, and we get its documentation. But what shall be the
documentation of `x.__class__.meth`?
>
> In the simplest approach, it would be the documentation of the default
method.
>
> In a less simple approach, it would prepend `"Conditionally defined
method: "` to the doc string of the one of the methods (I guess the
default is the method inherited from the super class).
>
> In an even less simple approach, it would start with `"Conditionally
defined method, choosing from methods with the following documentation:"`,
followed by a concatenation of the doc string of the inherited method and
the specialised method. The inherited method might be conditional, too.
So, we might take care of nesting.
>
> In the most complicated approach, we would even add the documentation of
the choosing function to the documentation of the wrapped methods.
Hmm, good point.
For now I would go for the simplest: just use the documentation of the
method. And add a recommendation that this documentation should
mention that the method is conditionally defined. A typical use case
would then be:
{{{
@conditionally_defined(hasattr="bar")
def product(self, x, y):
"""
Return the product of `x` and `y`.
.. NOTE::
This implementation uses ``self.product_on_basis`` and is
only defined if this method is defined.
"""
...
}}}
Once we will have some practical experience, it will be always time to
implement something more sophisticated if we fill it's really needed.
Cheers,
Nicolas
--
Ticket URL: <http://trac.sagemath.org/ticket/12978#comment:7>
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.