# HG changeset patch # User Paul Boddie # Date 1276297472 -7200 # Node ID 662e6ce9a75039a77d863ff23fa54aa375e225ae # Parent 5dadd4e4a171ee1a0a981337d10f339853f6c871 Fixed scope handling where names are imported into namespaces. Added a simple iter built-in function. Made the xrange test use the iteration protocol. diff -r 5dadd4e4a171 -r 662e6ce9a750 lib/builtins.py --- a/lib/builtins.py Sun Jun 06 15:27:50 2010 +0200 +++ b/lib/builtins.py Sat Jun 12 01:04:32 2010 +0200 @@ -367,7 +367,12 @@ def input(prompt=None): pass def isinstance(obj, cls_or_tuple): pass def issubclass(obj, cls_or_tuple): pass -def iter(collection_or_callable, sentinel=None): pass + +def iter(collection): + + "Implementation of iter without callable plus sentinel support." + + return collection.__iter__() def len(obj): diff -r 5dadd4e4a171 -r 662e6ce9a750 micropython/inspect.py --- a/micropython/inspect.py Sun Jun 06 15:27:50 2010 +0200 +++ b/micropython/inspect.py Sat Jun 12 01:04:32 2010 +0200 @@ -899,6 +899,7 @@ if self.importer.predefined_constants.has_key(name): attr = self.importer.get_predefined_constant(name) + node._scope = "constant" # Locals. @@ -908,6 +909,7 @@ # Note usage of the local (potentially a class attribute). self.use_specific_attribute(None, name) + node._scope = "local" # Globals. @@ -917,18 +919,21 @@ # Note usage of the module attribute. self.use_specific_attribute(self.full_name(), name) + node._scope = "global" # Builtins. elif self.builtins is not None and self.builtins.has_key(name): attr = self.builtins[name] self.use_specific_attribute(self.builtins.full_name(), name) + node._scope = "builtins" # Unknown. else: attr = None self.use_name(name) + node._scope = "unknown" return attr diff -r 5dadd4e4a171 -r 662e6ce9a750 micropython/trans.py --- a/micropython/trans.py Sun Jun 06 15:27:50 2010 +0200 +++ b/micropython/trans.py Sat Jun 12 01:04:32 2010 +0200 @@ -1164,7 +1164,14 @@ """ name = node.name - scope = self.get_scope(name) + + # Transfer scope information if this was set during inspection. + + if hasattr(node, "_scope"): + scope = node._scope + else: + scope = self.get_scope(name) + #print self.module.name, node.lineno, name, scope self._generateName(name, scope, classes, node) diff -r 5dadd4e4a171 -r 662e6ce9a750 tests/xrange.py --- a/tests/xrange.py Sun Jun 06 15:27:50 2010 +0200 +++ b/tests/xrange.py Sat Jun 12 01:04:32 2010 +0200 @@ -4,5 +4,7 @@ result_0 = xr.start result_10 = xr.end result_1 = xr.step +iter = iter(xr) +result1_0 = iter.next() # vim: tabstop=4 expandtab shiftwidth=4