# HG changeset patch # User Paul Boddie # Date 1241826342 -7200 # Node ID 6bcd2a7c7a2ae7b8fad879658ebbd469d809e41c # Parent eb198a981723ad3be887724e530373bc0242de86 Reorganised the instance attribute positioning methods. diff -r eb198a981723 -r 6bcd2a7c7a2a micropython/data.py --- a/micropython/data.py Tue May 05 20:25:51 2009 +0200 +++ b/micropython/data.py Sat May 09 01:45:42 2009 +0200 @@ -751,42 +751,52 @@ "Make sure that the instance attributes are fully defined." - if self.all_instattr is None: - self.all_instattr = {} - instattr = {} - - # Record provisional position information for attributes of this - # instance. - - for name in self.instattr: - instattr[name] = set() # position not yet defined - - reversed_bases = self.bases[:] - reversed_bases.reverse() - - # For the bases in reverse order, acquire instance attribute - # details. + # Cache the attributes by converting the positioned attributes into a + # dictionary. - for cls in reversed_bases: - for name, attr in cls.instance_attributes().items(): - - # Record previous attribute information. - - if instattr.has_key(name): - instattr[name].add(attr.position) - - # Cache the attributes by converting the positioned attributes into - # a dictionary. - - if not instattr: - self.all_instattr = {} - else: - self.all_instattr = self._get_attributes(instattr) - + if self.all_instattr is None: + self.all_instattr = self._get_attributes() self.all_instattr_names = self.all_instattr.keys() return self.all_instattr + def _get_attributes(self): + + """ + Return a dictionary mapping names to Attr instances incorporating + information about their positions in the final instance structure. + """ + + instattr = {} + + # Record provisional position information for attributes of this + # instance. + + for name in self.instattr: + instattr[name] = set() # position not yet defined + + reversed_bases = self.bases[:] + reversed_bases.reverse() + + # For the bases in reverse order, acquire instance attribute + # details. + + for cls in reversed_bases: + for name, attr in cls.instance_attributes().items(): + + # Record previous attribute information. + + if instattr.has_key(name): + instattr[name].add(attr.position) + + # Build the dictionary of attributes using the existing positions known + # for each name. + + d = {} + for i, name in enumerate(self._get_position_list(instattr)): + d[name] = Attr(i, Instance(), name) + return d + def _get_position_list(self, positions): """ @@ -827,19 +837,6 @@ #print "->", namearray return namearray - def _get_attributes(self, positions): - - """ - For the given 'positions' mapping from names to positions, return a - dictionary mapping names to Attr instances incorporating information - about their positions in the final instance structure. - """ - - d = {} - for i, name in enumerate(self._get_position_list(positions)): - d[name] = Attr(i, Instance(), name) - return d - def _cmp_positions(self, a, b): "Compare name plus position list operands 'a' and 'b'." @@ -1050,9 +1047,16 @@ Defaults are also finalised by this method. """ + if self.finalised: + return + + # Defaults. + for i, default in enumerate(self.default_attrs): default.position = i + # Locals. + i = None for i, name in enumerate(self.argnames): self[name].position = i