Is there some Python idiom to alias class methods that respects subclassing? Usually the docstring of aliases in Sage containes less examples, and when the original method is updated (e.g. warn about an edge case), there is a risk of not updating the alias' docstring.

What I would like to see is, assuming we have something like

class C(object):
    def foo():
        "The full docstring of foo"

    alias(foo, "bar")

is that automagically bar.__doc__ is now

"""
bar is an alias of :meth:`C.foo`.

The full docstring of foo
"""

Or do we have to mess with C.__{get,set}attr__?

Regards,
TB

On 11/13/2014 04:54 PM, Travis Scrimshaw wrote:
    In those cases, those are functions (or classes), not methods, and
so they are "safe". There are cases where methods get aliased, and there
the user my experience something unexpected when first trying to
subclass, but they won't experience a sudden change when upgrading Sage.
However I'm not opposed to mentioning in the docstring that it is an
alias. Yet the docstring is short, so I won't remove it. IMO we should
never have the docstring just be "Alias for :meth:`foo`", at the very
least the short description should tell what the (redirected) function does.

Best,
Travis


On Thursday, November 13, 2014 1:18:11 AM UTC-8, Jori Mantysalo wrote:

    On Wed, 12 Nov 2014, Travis Scrimshaw wrote:

     > That's exactly what I'm saying. With this change, that may not
    occur if
     > someone had overwritten interval() with some slightly different
    behavior in
     > a subclass and was calling closed_interval(), they would
    experience an
     > unexpected change (or, perhaps more likely, a major slow-down).
    It would be
     > calling the interval() of FinitePoset rather than the subclass.

    rsk.py contains "robinson_schensted_knuth = RSK", posets.py contains
    "Posets_all = Posets" and poset_examples.py contains "posets = Posets".
    Does same thing happen with those also?

       * * *

    As I wrote to ticket, it seems a little confusing for me to have
    documentation with two functions, both with examples and so, that
    actually
    does same thing. Maybe docstring of other could be only "Alias for
    <link>xxx()</link>."?

    --
    Jori Mäntysalo

--
You received this message because you are subscribed to the Google
Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sage-devel+unsubscr...@googlegroups.com
<mailto:sage-devel+unsubscr...@googlegroups.com>.
To post to this group, send email to sage-devel@googlegroups.com
<mailto:sage-devel@googlegroups.com>.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to