1.1 --- a/micropython/inspect.py Sun Oct 13 15:45:26 2013 +0200
1.2 +++ b/micropython/inspect.py Sun Oct 13 18:40:30 2013 +0200
1.3 @@ -415,9 +415,13 @@
1.4 namespaces = namespaces or self.namespaces
1.5 return len(namespaces) > 1 and isinstance(namespaces[-2], Class)
1.6
1.7 - def store(self, name, obj):
1.8 + def store(self, name, obj, static_def=False):
1.9
1.10 - "Record attribute or local 'name', storing 'obj'."
1.11 + """
1.12 + Record attribute or local 'name', storing 'obj'. Where 'static_def' is
1.13 + specified and set to a true value, the namespace will record a static
1.14 + definition for the given name.
1.15 + """
1.16
1.17 # Store in the module.
1.18
1.19 @@ -425,7 +429,7 @@
1.20 if self.in_loop and self.used_in_scope(name, "builtins"):
1.21 raise InspectError("Name %r already used as a built-in." % name)
1.22 else:
1.23 - self.set(name, obj, not self.in_loop)
1.24 + ns = self
1.25
1.26 # Or store locally.
1.27
1.28 @@ -437,7 +441,11 @@
1.29 elif self.in_loop and locals.used_in_scope(name, "builtins"):
1.30 raise InspectError("Name %r already used as a built-in." % name)
1.31 else:
1.32 - locals.set(name, obj, not self.in_loop)
1.33 + ns = locals
1.34 +
1.35 + ns.set(name, obj, not self.in_loop)
1.36 + if static_def:
1.37 + ns.get(name).static_assignments += 1
1.38
1.39 def store_lambda(self, obj):
1.40
1.41 @@ -800,7 +808,7 @@
1.42 # Store the function.
1.43
1.44 if name is not None:
1.45 - self.store(name, function)
1.46 + self.store(name, function, static_def=True)
1.47 else:
1.48 self.store_lambda(function)
1.49
1.50 @@ -1019,7 +1027,7 @@
1.51 # Make an entry for the class in the parent namespace.
1.52
1.53 self.namespaces.pop()
1.54 - self.store(node.name, cls)
1.55 + self.store(node.name, cls, static_def=True)
1.56 self.define_attribute_user(node)
1.57 self.add_object(cls)
1.58