Package advene :: Package util :: Module alias
[hide private]
[frames] | no frames]

Module alias

source code


I define the alias decorator.

The alias decorator aims at replacing the following code inside a class body:

  method_a = method_b

by the following code, considered better:

  @alias(method_b)
  def method_a(self):
      # method_a is the same as method_b
      pass

Why is this considered better:
* it actually has the same effect, so has no performance cost at runtime
* there is a statement that looks like a definition of the method (with def),
  and hence will be found by naive tools, such as grep.

Note that it is a good practice to explain as a comment that this is an alias
and why it is so. It is *not* a good practice to do that in a docstring because
that would seem to imply that the aliased object will have that docstring,
while it will in fact have the same docstring as the original: they really are
the same object (think hard-link, not soft-link).

Functions [hide private]
 
alias(real_object) source code