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

Source Code for Module advene.util.alias

 1  # 
 2  # This file is part of Advene. 
 3  #  
 4  # Advene is free software; you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published by 
 6  # the Free Software Foundation; either version 2 of the License, or 
 7  # (at your option) any later version. 
 8  #  
 9  # Advene is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
12  # GNU General Public License for more details. 
13  #  
14  # You should have received a copy of the GNU General Public License 
15  # along with Foobar; if not, write to the Free Software 
16  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
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   
45 -def alias(real_object):
46 def make_alias(named_object): 47 return real_object
48 return make_alias 49