1.1 --- a/micropython/inspect.py Sat Nov 03 02:59:43 2007 +0100
1.2 +++ b/micropython/inspect.py Sun Nov 04 18:27:20 2007 +0100
1.3 @@ -418,6 +418,11 @@
1.4 if isinstance(value, Module) and not value.loaded:
1.5 del self[name]
1.6
1.7 + # Complain about globals not initialised at the module level.
1.8 +
1.9 + if isinstance(value, Global):
1.10 + print "Warning: global %r in module %r not initialised at the module level." % (name, self.name)
1.11 +
1.12 # Namespace methods.
1.13
1.14 def store(self, name, obj):
1.15 @@ -619,7 +624,7 @@
1.16 for name in node.names:
1.17 self.namespaces[-1].make_global(name)
1.18 if not self.has_key(name):
1.19 - self[name] = None
1.20 + self[name] = Global()
1.21
1.22 def visitIf(self, node):
1.23 for test, body in node.tests:
1.24 @@ -733,6 +738,15 @@
1.25
1.26 pass
1.27
1.28 +class Global:
1.29 +
1.30 + """
1.31 + A reference to an object assigned to a global from outside the module
1.32 + top-level.
1.33 + """
1.34 +
1.35 + pass
1.36 +
1.37 # Built-in types initialisation.
1.38
1.39 class Builtins(Module):
1.40 @@ -757,9 +771,13 @@
1.41 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning',
1.42 'ValueError', 'Warning', 'ZeroDivisionError',
1.43 'bool', 'buffer', 'complex', 'dict', 'file', 'float', 'int', 'list',
1.44 - 'long', 'object', 'slice', 'str', 'tuple', 'type', 'unicode']:
1.45 + 'long', 'object', 'slice', 'str', 'tuple', 'type', 'unicode',
1.46 + 'xrange']:
1.47 self[key] = Class(key, self.full_name())
1.48
1.49 + for key in ['id', 'len']:
1.50 + self[key] = Function(key, self.full_name(), ['arg'], 0, 0)
1.51 +
1.52 builtins = Builtins()
1.53
1.54 # vim: tabstop=4 expandtab shiftwidth=4