# HG changeset patch # User Paul Boddie # Date 1194197240 -3600 # Node ID 53b37a00af29298315848105adc77d1028926fb7 # Parent 26517d26da42763c4c5c0658fc744c8478655d03 Added tests for globals not initialised at the top level of the modules in which they reside. diff -r 26517d26da42 -r 53b37a00af29 micropython/inspect.py --- a/micropython/inspect.py Sat Nov 03 02:59:43 2007 +0100 +++ b/micropython/inspect.py Sun Nov 04 18:27:20 2007 +0100 @@ -418,6 +418,11 @@ if isinstance(value, Module) and not value.loaded: del self[name] + # Complain about globals not initialised at the module level. + + if isinstance(value, Global): + print "Warning: global %r in module %r not initialised at the module level." % (name, self.name) + # Namespace methods. def store(self, name, obj): @@ -619,7 +624,7 @@ for name in node.names: self.namespaces[-1].make_global(name) if not self.has_key(name): - self[name] = None + self[name] = Global() def visitIf(self, node): for test, body in node.tests: @@ -733,6 +738,15 @@ pass +class Global: + + """ + A reference to an object assigned to a global from outside the module + top-level. + """ + + pass + # Built-in types initialisation. class Builtins(Module): @@ -757,9 +771,13 @@ 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', 'bool', 'buffer', 'complex', 'dict', 'file', 'float', 'int', 'list', - 'long', 'object', 'slice', 'str', 'tuple', 'type', 'unicode']: + 'long', 'object', 'slice', 'str', 'tuple', 'type', 'unicode', + 'xrange']: self[key] = Class(key, self.full_name()) + for key in ['id', 'len']: + self[key] = Function(key, self.full_name(), ['arg'], 0, 0) + builtins = Builtins() # vim: tabstop=4 expandtab shiftwidth=4