# HG changeset patch # User paulb@localhost.localdomain # Date 1172965325 -3600 # Node ID 665ac29a312a5bae678d771c87f7e29a1c206b28 # Parent 2068510e5d266d797c16e8baf48e278aac22aebf Fixed name resolution by enforcing the share_locals attribute. Added a test exposing incorrect resolution. diff -r 2068510e5d26 -r 665ac29a312a fixnames.py --- a/fixnames.py Sun Mar 04 00:41:21 2007 +0100 +++ b/fixnames.py Sun Mar 04 00:42:05 2007 +0100 @@ -152,18 +152,19 @@ # Obtain a namespace either based on locals or on a structure. structure = structure=getattr(node, "structure", None) - self.namespace = NameOrganiser(structure) + + # If passed some namespace, use that as the current namespace. + + if namespace is not None: + self.namespace.merge_namespace(namespace) + else: + self.namespace = NameOrganiser(structure) # Record the current subprogram and namespace. self.current_subprograms.append(node) self.current_namespaces.append(self.namespace) - # If passed some namespace, merge its contents into this namespace. - - if namespace is not None: - self.namespace.merge_namespace(namespace) - # NOTE: Avoid PEP 227 (nested scopes) whilst permitting references to a # NOTE: subprogram within itself. Do not define the name of the function # NOTE: within a method definition. @@ -403,7 +404,11 @@ # The special case of internal subprogram invocation is addressed by # propagating namespace information to the subprogram and processing it. - subprogram = self.process_node(invoke.ref, self.namespace) + if invoke.share_locals: + subprogram = self.process_node(invoke.ref, self.namespace) + else: + subprogram = self.process_node(invoke.ref) + if subprogram is not None: self.subprograms.append(subprogram) return invoke diff -r 2068510e5d26 -r 665ac29a312a tests/while2.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/while2.py Sun Mar 04 00:42:05 2007 +0100 @@ -0,0 +1,7 @@ +def f(x): + while x: + y = 3 + x -= 1 + return y + +f(1)