1.1 --- a/micropython/data.py Sun Nov 22 18:54:52 2009 +0100
1.2 +++ b/micropython/data.py Sun Nov 22 20:04:05 2009 +0100
1.3 @@ -264,10 +264,13 @@
1.4 l[attr.position] = attr
1.5 return l
1.6
1.7 - def finalise_attributes(self):
1.8 + def finalise_attributes(self, reset=0):
1.9
1.10 "Make sure all attributes are fully defined."
1.11
1.12 + if reset:
1.13 + self.unfinalise_attributes()
1.14 +
1.15 if self.finalised:
1.16 return
1.17
1.18 @@ -278,6 +281,12 @@
1.19
1.20 self.finalised = 1
1.21
1.22 + def unfinalise_attributes(self):
1.23 +
1.24 + "Open attribute definitions to editing and subsequent finalisation."
1.25 +
1.26 + self.finalised = 0
1.27 +
1.28 # Attribute usage methods.
1.29
1.30 def get_active_attributes(self):
1.31 @@ -641,12 +650,7 @@
1.32
1.33 # Caches.
1.34
1.35 - self.all_instattr = None # cache for instance_attributes
1.36 - self.all_instattr_names = None # from all_instattr
1.37 - self.all_classattr = None # cache for all_class_attributes
1.38 - self.all_classattr_names = None # from all_classattr
1.39 - self.allattr = None # cache for all_attributes
1.40 - self.allattr_names = None # from allattr
1.41 + self.reset_caches()
1.42
1.43 # Image generation details.
1.44
1.45 @@ -668,6 +672,17 @@
1.46
1.47 self.set("__class__", self)
1.48
1.49 + def reset_caches(self):
1.50 +
1.51 + "Reset the caches."
1.52 +
1.53 + self.all_instattr = None # cache for instance_attributes
1.54 + self.all_instattr_names = None # from all_instattr
1.55 + self.all_classattr = None # cache for all_class_attributes
1.56 + self.all_classattr_names = None # from all_classattr
1.57 + self.allattr = None # cache for all_attributes
1.58 + self.allattr_names = None # from allattr
1.59 +
1.60 def __repr__(self):
1.61 if self.location is not None:
1.62 return "Class(%r, %s, location=%r)" % (self.name, shortrepr(self.parent), self.location)
1.63 @@ -703,10 +718,13 @@
1.64
1.65 return NamespaceDict.get_updated_context_values(self, results)
1.66
1.67 - def finalise_attributes(self):
1.68 + def finalise_attributes(self, reset=0):
1.69
1.70 "Make sure that all attributes are fully defined."
1.71
1.72 + if reset:
1.73 + self.unfinalise_attributes()
1.74 +
1.75 if self.finalised:
1.76 return
1.77
1.78 @@ -714,6 +732,13 @@
1.79 self.finalise_instance_attributes()
1.80 self.finalised = 1
1.81
1.82 + def unfinalise_attributes(self):
1.83 +
1.84 + "Open attribute definitions to editing and subsequent finalisation."
1.85 +
1.86 + self.reset_caches()
1.87 + self.finalised = 0
1.88 +
1.89 # Convenience methods for accessing functions and methods.
1.90
1.91 def get_instantiator(self):
1.92 @@ -766,6 +791,7 @@
1.93
1.94 if self.all_classattr_names is None:
1.95 self.all_class_attributes()
1.96 + self.all_classattr_names = self.all_classattr.keys()
1.97 return self.all_classattr_names
1.98
1.99 def all_class_attributes(self):
1.100 @@ -1127,7 +1153,7 @@
1.101 return 1
1.102 return 0
1.103
1.104 - def finalise_attributes(self):
1.105 + def finalise_attributes(self, reset=0):
1.106
1.107 """
1.108 Make sure all attributes (locals) are fully defined. Note that locals
1.109 @@ -1135,6 +1161,9 @@
1.110 Defaults are also finalised by this method.
1.111 """
1.112
1.113 + if reset:
1.114 + self.unfinalise_attributes()
1.115 +
1.116 if self.finalised:
1.117 return
1.118