# HG changeset patch # User Paul Boddie # Date 1258916645 -3600 # Node ID 85e350584da735ff319c3f273515981cddf49fe7 # Parent f9896e300492670590e278a24ad9449d23aace25 Added "unfinalisation" of attributes in order to properly redefine structures. (Since finalisation of attributes is done to build the object table, this could be weakened in order to avoid doing such work twice.) Removed the object.__iadd__ method in the builtins module. Fixed the Class.all_class_attribute_names method to actually return the names. diff -r f9896e300492 -r 85e350584da7 lib/builtins.py --- a/lib/builtins.py Sun Nov 22 18:54:52 2009 +0100 +++ b/lib/builtins.py Sun Nov 22 20:04:05 2009 +0100 @@ -23,7 +23,6 @@ class object: def __init__(self): pass def __bool__(self): pass - def __iadd__(self, other): pass class basestring(object): def __init__(self, x=None): pass diff -r f9896e300492 -r 85e350584da7 micropython/data.py --- a/micropython/data.py Sun Nov 22 18:54:52 2009 +0100 +++ b/micropython/data.py Sun Nov 22 20:04:05 2009 +0100 @@ -264,10 +264,13 @@ l[attr.position] = attr return l - def finalise_attributes(self): + def finalise_attributes(self, reset=0): "Make sure all attributes are fully defined." + if reset: + self.unfinalise_attributes() + if self.finalised: return @@ -278,6 +281,12 @@ self.finalised = 1 + def unfinalise_attributes(self): + + "Open attribute definitions to editing and subsequent finalisation." + + self.finalised = 0 + # Attribute usage methods. def get_active_attributes(self): @@ -641,12 +650,7 @@ # 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 - self.all_classattr_names = None # from all_classattr - self.allattr = None # cache for all_attributes - self.allattr_names = None # from allattr + self.reset_caches() # Image generation details. @@ -668,6 +672,17 @@ self.set("__class__", self) + def reset_caches(self): + + "Reset the 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 + self.all_classattr_names = None # from all_classattr + self.allattr = None # cache for all_attributes + self.allattr_names = None # from allattr + def __repr__(self): if self.location is not None: return "Class(%r, %s, location=%r)" % (self.name, shortrepr(self.parent), self.location) @@ -703,10 +718,13 @@ return NamespaceDict.get_updated_context_values(self, results) - def finalise_attributes(self): + def finalise_attributes(self, reset=0): "Make sure that all attributes are fully defined." + if reset: + self.unfinalise_attributes() + if self.finalised: return @@ -714,6 +732,13 @@ self.finalise_instance_attributes() self.finalised = 1 + def unfinalise_attributes(self): + + "Open attribute definitions to editing and subsequent finalisation." + + self.reset_caches() + self.finalised = 0 + # Convenience methods for accessing functions and methods. def get_instantiator(self): @@ -766,6 +791,7 @@ if self.all_classattr_names is None: self.all_class_attributes() + self.all_classattr_names = self.all_classattr.keys() return self.all_classattr_names def all_class_attributes(self): @@ -1127,7 +1153,7 @@ return 1 return 0 - def finalise_attributes(self): + def finalise_attributes(self, reset=0): """ Make sure all attributes (locals) are fully defined. Note that locals @@ -1135,6 +1161,9 @@ Defaults are also finalised by this method. """ + if reset: + self.unfinalise_attributes() + if self.finalised: return diff -r f9896e300492 -r 85e350584da7 micropython/inspect.py --- a/micropython/inspect.py Sun Nov 22 18:54:52 2009 +0100 +++ b/micropython/inspect.py Sun Nov 22 20:04:05 2009 +0100 @@ -237,8 +237,8 @@ "Finalise the module." for obj in self.all_objects: - if isinstance(obj, (Class, Function)): - obj.finalise_attributes() + if isinstance(obj, (Class, Function)): # NOTE: Perhaps not required. + obj.finalise_attributes(reset=1) def add_object(self, obj, any_scope=0):