# HG changeset patch # User Paul Boddie # Date 1203797462 -3600 # Node ID 8a0028b6ef9db6330c9f3e4228a6b6136229fc13 # Parent 0fef6a91098cda91110dbb050475199039b658ac Added docstrings. Fixed the erroneous redefinition of instance attributes in the all_attributes method. diff -r 0fef6a91098c -r 8a0028b6ef9d micropython/inspect.py --- a/micropython/inspect.py Fri Feb 22 00:42:28 2008 +0100 +++ b/micropython/inspect.py Sat Feb 23 21:11:02 2008 +0100 @@ -120,6 +120,14 @@ self.set(name, value) def set(self, name, value, single_assignment=1): + + """ + A more powerful set operation, making 'name' refer to 'value' whilst + indicating whether a 'single_assignment' (true by default) occurs in + this operation (or whether the operation covers potentially many + assignments in the lifetime of a program). + """ + if name in self.globals: self.global_namespace.set(name, value, 0) else: @@ -131,12 +139,23 @@ attr.update(value, single_assignment) def set_module(self, name, value): + + """ + A specialised set operation, making 'name' refer to 'value' in the + context of making a module reference available in association with + 'name' as part of the import of that module or a submodule of that + module. + """ + attr = self._set(name, value) if attr.assignments is None: attr.assignments = 1 attr.assignment_values.add(value) def _set(self, name, value): + + "The underlying set operation associating 'name' with 'value'." + if not self.namespace.has_key(name): self.namespace[name] = Attr(self.attr_position, self, name, value) self.attr_position += 1 @@ -203,6 +222,16 @@ self.assignment_values = set() def update(self, value, single_assignment): + + """ + Update the attribute, adding the 'value' provided to the known values + associated with the attribute, changing the number of assignments + according to the 'single_assignment' status of the operation, where + a true value indicates that only one assignment is associated with the + update, and a false value indicates that potentially many assignments + may be involved. + """ + if self.assignments is None: if single_assignment: self.assignments = 1 @@ -251,12 +280,16 @@ self.parent_name = parent_name self.node = node + # Superclasses and attributes. + self.bases = [] self.instattr = set() # instance attributes self.instattr_relocated = set() # instance attributes which do not have # the same position as those of the same # name in some superclasses + # Caches. + self.all_instattr = None # cache for instance_attributes self.all_instattr_names = None # from all_instattr self.all_classattr = None # cache for all_class_attributes @@ -419,10 +452,10 @@ if self.allattr is None: self.allattr = {} self.allattr.update(self.all_class_attributes()) - for i, name in enumerate(self.instance_attribute_names()): + for name, attr in self.instance_attributes().items(): if self.allattr.has_key(name): print "Instance attribute %r in %r overrides class attribute." % (name, self) - self.allattr[name] = Attr(i, None, name) + self.allattr[name] = attr return self.allattr class Function(NamespaceDict, Naming):