I had a short discussion about aliases in Sage Days 79. It might be
appropriate for general Python programming to have an alias() function
for adding aliases of functions and methods.
The usage should be something like:
new_alias = alias("new_alias", orig_function)
It should copy the docstring of orig_function and prepend to it
"new_alias is an alias of orig_function\n". For better documentation it
should also add to orig_function the existence of such aliases. One way
to implement it is to add an attribute orig_function._aliases to be the
list of aliases. Then, the docstring of orig_function will have an
ALIASES section (dynamically created) in its documentation if _aliases
exist and is not empty.
It gets trickier to implement for methods in Cython classes and Python
classes that only use __slots__, because we need to dynamically add
attributes.
For class methods, having such an alias() function helps with
inheritance, not just with citations. Suppose we have
class A(object):
def foo(self):
print "A.foo"
also_foo = foo
class B(A):
def foo(self):
print "B.foo"
Then we get different behavior of foo() and also_foo() in B:
sage: b = B()
sage: b.foo()
B.foo
sage: b.also_foo() # Surprise!
A.foo
BTW, tab completion is not enough to discover aliases, because not all
aliases are prefixes. See for example the short docstring of
gaussian_binomial which is an alias for q_binomial.
Regards,
TB