1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 """
20 I define the alias decorator.
21
22 The alias decorator aims at replacing the following code inside a class body:
23
24 method_a = method_b
25
26 by the following code, considered better:
27
28 @alias(method_b)
29 def method_a(self):
30 # method_a is the same as method_b
31 pass
32
33 Why is this considered better:
34 * it actually has the same effect, so has no performance cost at runtime
35 * there is a statement that looks like a definition of the method (with def),
36 and hence will be found by naive tools, such as grep.
37
38 Note that it is a good practice to explain as a comment that this is an alias
39 and why it is so. It is *not* a good practice to do that in a docstring because
40 that would seem to imply that the aliased object will have that docstring,
41 while it will in fact have the same docstring as the original: they really are
42 the same object (think hard-link, not soft-link).
43 """
44
46 def make_alias(named_object):
47 return real_object
48 return make_alias
49