1.1 --- a/micropython/data.py Sat Jul 07 20:40:09 2012 +0200
1.2 +++ b/micropython/data.py Sun Jul 08 02:26:27 2012 +0200
1.3 @@ -2023,6 +2023,11 @@
1.4
1.5 self.all_objects = set()
1.6
1.7 + # Whether the module is imported in a circular fashion, exposing the
1.8 + # unfinished namespace to external modification.
1.9 +
1.10 + self.circular_import = self in importer.circular_imports
1.11 +
1.12 # A set of global names that cannot support combined attribute usage
1.13 # observations because they may be modified within functions during
1.14 # initialisation.
1.15 @@ -2084,29 +2089,46 @@
1.16 if not self.namespace.has_key(name):
1.17 self.namespace[name] = Attr(None, self, name)
1.18
1.19 + # Indicate that there is at least one assignment to the name, although
1.20 + # no actual values are recorded.
1.21 +
1.22 attr = self.namespace[name]
1.23 attr.update_assignments(1, False)
1.24
1.25 + def set(self, name, value, single_assignment=1):
1.26 +
1.27 + """
1.28 + Set the module attribute with the given 'name', having the given 'value'
1.29 + that is assigned once if 'single_assignment' is omitted to given as a
1.30 + true value.
1.31 +
1.32 + Where the module is imported before it is completely initialised, all
1.33 + assignments will be regarded as multiple assignments since it is
1.34 + possible that an external assignment to the name may occur.
1.35 + """
1.36 +
1.37 + NamespaceDict.set(self, name, value, not self.circular_import and single_assignment)
1.38 +
1.39 # Attribute usage methods that apply to module globals in certain
1.40 # circumstances.
1.41
1.42 def _use_attribute(self, name, attrname, value=None):
1.43 - if name not in self.modified_names:
1.44 + if name not in self.modified_names and not self.circular_import:
1.45 return NamespaceDict._use_attribute(self, name, attrname, value)
1.46 else:
1.47 self.importer.use_name(attrname, self.full_name(), value)
1.48 return []
1.49
1.50 def _define_attribute_user_for_name(self, node, name):
1.51 - if name not in self.modified_names:
1.52 + if name not in self.modified_names and not self.circular_import:
1.53 NamespaceDict._define_attribute_user_for_name(self, node, name)
1.54
1.55 def _init_attribute_user_for_name(self, node, name):
1.56 - if name not in self.modified_names:
1.57 + if name not in self.modified_names and not self.circular_import:
1.58 NamespaceDict._init_attribute_user_for_name(self, node, name)
1.59
1.60 def _define_attribute_accessor(self, name, attrname, node, value):
1.61 - if name not in self.modified_names:
1.62 + if name not in self.modified_names and not self.circular_import:
1.63 NamespaceDict._define_attribute_accessor(self, name, attrname, node, value)
1.64 else:
1.65 self.importer.use_name(attrname, self.full_name(), value)