1.1 --- a/annotate.py Sun Jan 07 23:44:39 2007 +0100
1.2 +++ b/annotate.py Mon Jan 08 23:37:53 2007 +0100
1.3 @@ -949,9 +949,10 @@
1.4 using_module_namespace = 0
1.5
1.6 # NOTE: Avoid PEP 227 (nested scopes) whilst permitting references to a
1.7 - # NOTE: subprogram within itself.
1.8 + # NOTE: subprogram within itself. Do not define the name of the function
1.9 + # NOTE: within a method definition.
1.10
1.11 - if hasattr(target, "name") and target.name is not None:
1.12 + if getattr(target, "name", None) is not None and not getattr(target, "is_method", 0):
1.13 namespace.store(target.name, [Attribute(None, target)])
1.14
1.15 # Process the subprogram.
2.1 --- a/fixnames.py Sun Jan 07 23:44:39 2007 +0100
2.2 +++ b/fixnames.py Mon Jan 08 23:37:53 2007 +0100
2.3 @@ -165,9 +165,10 @@
2.4 self.namespace.merge_namespace(namespace)
2.5
2.6 # NOTE: Avoid PEP 227 (nested scopes) whilst permitting references to a
2.7 - # NOTE: subprogram within itself.
2.8 + # NOTE: subprogram within itself. Do not define the name of the function
2.9 + # NOTE: within a method definition.
2.10
2.11 - if hasattr(node, "name") and node.name is not None:
2.12 + if getattr(node, "name", None) is not None and not getattr(node, "is_method", 0):
2.13 self.namespace.store(node.name)
2.14
2.15 # Register the names of parameters in the namespace.
3.1 --- a/simplify.py Sun Jan 07 23:44:39 2007 +0100
3.2 +++ b/simplify.py Mon Jan 08 23:37:53 2007 +0100
3.3 @@ -73,6 +73,7 @@
3.4 self.constants = {} # Constants.
3.5 self.current_subprograms = [] # Current subprograms being processed.
3.6 self.current_structures = [] # Current structures being processed.
3.7 + self.within_class = 0 # Whether a class is being defined.
3.8 self.builtins = builtins # Whether the builtins are being processed.
3.9
3.10 # Convenience attributes.
3.11 @@ -434,6 +435,8 @@
3.12
3.13 structure = Class(name=class_.name, module=self.module, bases=self.dispatches(bases))
3.14 self.structures.append(structure)
3.15 + within_class = self.within_class
3.16 + self.within_class = 1
3.17
3.18 # Make a subprogram which initialises the class structure.
3.19
3.20 @@ -445,6 +448,7 @@
3.21
3.22 subprogram.code = self.dispatch(class_.code) + [ReturnFromBlock()]
3.23
3.24 + self.within_class = within_class
3.25 self.current_structures.pop()
3.26 self.current_subprograms.pop()
3.27 self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram
3.28 @@ -803,10 +807,15 @@
3.29 """
3.30
3.31 subprogram = Subprogram(name=function.name, module=self.module, structures=self.current_structures[:],
3.32 - internal=0, returns_value=1, star=None, dstar=None)
3.33 + internal=0, returns_value=1, star=None, dstar=None, is_method=self.within_class)
3.34
3.35 self.current_subprograms.append(subprogram)
3.36 + within_class = self.within_class
3.37 + self.within_class = 0
3.38 +
3.39 subprogram.code = self.dispatch(function.code) + [ReturnFromFunction()]
3.40 +
3.41 + self.within_class = within_class
3.42 self.current_subprograms.pop()
3.43 self._visitFunction(function, subprogram)
3.44
4.1 --- a/tests/nested_functions.py Sun Jan 07 23:44:39 2007 +0100
4.2 +++ b/tests/nested_functions.py Mon Jan 08 23:37:53 2007 +0100
4.3 @@ -1,3 +1,14 @@
4.4 +class C:
4.5 + def f(self):
4.6 + return f
4.7 +
4.8 + def f2(self):
4.9 + def g2(x):
4.10 + if x <= 0:
4.11 + return x
4.12 + return g2(x - 1) + x
4.13 + return g2
4.14 +
4.15 def f():
4.16 def g(x):
4.17 if x <= 0:
4.18 @@ -7,3 +18,7 @@
4.19
4.20 a = f()
4.21 b = a(3)
4.22 +c = C()
4.23 +c.f()
4.24 +d = c.f2()
4.25 +e = d(3)