1.1 --- a/micropython/inspect.py Fri Feb 22 00:42:28 2008 +0100
1.2 +++ b/micropython/inspect.py Sat Feb 23 21:11:02 2008 +0100
1.3 @@ -120,6 +120,14 @@
1.4 self.set(name, value)
1.5
1.6 def set(self, name, value, single_assignment=1):
1.7 +
1.8 + """
1.9 + A more powerful set operation, making 'name' refer to 'value' whilst
1.10 + indicating whether a 'single_assignment' (true by default) occurs in
1.11 + this operation (or whether the operation covers potentially many
1.12 + assignments in the lifetime of a program).
1.13 + """
1.14 +
1.15 if name in self.globals:
1.16 self.global_namespace.set(name, value, 0)
1.17 else:
1.18 @@ -131,12 +139,23 @@
1.19 attr.update(value, single_assignment)
1.20
1.21 def set_module(self, name, value):
1.22 +
1.23 + """
1.24 + A specialised set operation, making 'name' refer to 'value' in the
1.25 + context of making a module reference available in association with
1.26 + 'name' as part of the import of that module or a submodule of that
1.27 + module.
1.28 + """
1.29 +
1.30 attr = self._set(name, value)
1.31 if attr.assignments is None:
1.32 attr.assignments = 1
1.33 attr.assignment_values.add(value)
1.34
1.35 def _set(self, name, value):
1.36 +
1.37 + "The underlying set operation associating 'name' with 'value'."
1.38 +
1.39 if not self.namespace.has_key(name):
1.40 self.namespace[name] = Attr(self.attr_position, self, name, value)
1.41 self.attr_position += 1
1.42 @@ -203,6 +222,16 @@
1.43 self.assignment_values = set()
1.44
1.45 def update(self, value, single_assignment):
1.46 +
1.47 + """
1.48 + Update the attribute, adding the 'value' provided to the known values
1.49 + associated with the attribute, changing the number of assignments
1.50 + according to the 'single_assignment' status of the operation, where
1.51 + a true value indicates that only one assignment is associated with the
1.52 + update, and a false value indicates that potentially many assignments
1.53 + may be involved.
1.54 + """
1.55 +
1.56 if self.assignments is None:
1.57 if single_assignment:
1.58 self.assignments = 1
1.59 @@ -251,12 +280,16 @@
1.60 self.parent_name = parent_name
1.61 self.node = node
1.62
1.63 + # Superclasses and attributes.
1.64 +
1.65 self.bases = []
1.66 self.instattr = set() # instance attributes
1.67 self.instattr_relocated = set() # instance attributes which do not have
1.68 # the same position as those of the same
1.69 # name in some superclasses
1.70
1.71 + # Caches.
1.72 +
1.73 self.all_instattr = None # cache for instance_attributes
1.74 self.all_instattr_names = None # from all_instattr
1.75 self.all_classattr = None # cache for all_class_attributes
1.76 @@ -419,10 +452,10 @@
1.77 if self.allattr is None:
1.78 self.allattr = {}
1.79 self.allattr.update(self.all_class_attributes())
1.80 - for i, name in enumerate(self.instance_attribute_names()):
1.81 + for name, attr in self.instance_attributes().items():
1.82 if self.allattr.has_key(name):
1.83 print "Instance attribute %r in %r overrides class attribute." % (name, self)
1.84 - self.allattr[name] = Attr(i, None, name)
1.85 + self.allattr[name] = attr
1.86 return self.allattr
1.87
1.88 class Function(NamespaceDict, Naming):