1.1 --- a/micropython/data.py Tue May 05 20:25:51 2009 +0200
1.2 +++ b/micropython/data.py Sat May 09 01:45:42 2009 +0200
1.3 @@ -751,42 +751,52 @@
1.4
1.5 "Make sure that the instance attributes are fully defined."
1.6
1.7 - if self.all_instattr is None:
1.8 - self.all_instattr = {}
1.9 - instattr = {}
1.10 -
1.11 - # Record provisional position information for attributes of this
1.12 - # instance.
1.13 -
1.14 - for name in self.instattr:
1.15 - instattr[name] = set() # position not yet defined
1.16 -
1.17 - reversed_bases = self.bases[:]
1.18 - reversed_bases.reverse()
1.19 -
1.20 - # For the bases in reverse order, acquire instance attribute
1.21 - # details.
1.22 + # Cache the attributes by converting the positioned attributes into a
1.23 + # dictionary.
1.24
1.25 - for cls in reversed_bases:
1.26 - for name, attr in cls.instance_attributes().items():
1.27 -
1.28 - # Record previous attribute information.
1.29 -
1.30 - if instattr.has_key(name):
1.31 - instattr[name].add(attr.position)
1.32 -
1.33 - # Cache the attributes by converting the positioned attributes into
1.34 - # a dictionary.
1.35 -
1.36 - if not instattr:
1.37 - self.all_instattr = {}
1.38 - else:
1.39 - self.all_instattr = self._get_attributes(instattr)
1.40 -
1.41 + if self.all_instattr is None:
1.42 + self.all_instattr = self._get_attributes()
1.43 self.all_instattr_names = self.all_instattr.keys()
1.44
1.45 return self.all_instattr
1.46
1.47 + def _get_attributes(self):
1.48 +
1.49 + """
1.50 + Return a dictionary mapping names to Attr instances incorporating
1.51 + information about their positions in the final instance structure.
1.52 + """
1.53 +
1.54 + instattr = {}
1.55 +
1.56 + # Record provisional position information for attributes of this
1.57 + # instance.
1.58 +
1.59 + for name in self.instattr:
1.60 + instattr[name] = set() # position not yet defined
1.61 +
1.62 + reversed_bases = self.bases[:]
1.63 + reversed_bases.reverse()
1.64 +
1.65 + # For the bases in reverse order, acquire instance attribute
1.66 + # details.
1.67 +
1.68 + for cls in reversed_bases:
1.69 + for name, attr in cls.instance_attributes().items():
1.70 +
1.71 + # Record previous attribute information.
1.72 +
1.73 + if instattr.has_key(name):
1.74 + instattr[name].add(attr.position)
1.75 +
1.76 + # Build the dictionary of attributes using the existing positions known
1.77 + # for each name.
1.78 +
1.79 + d = {}
1.80 + for i, name in enumerate(self._get_position_list(instattr)):
1.81 + d[name] = Attr(i, Instance(), name)
1.82 + return d
1.83 +
1.84 def _get_position_list(self, positions):
1.85
1.86 """
1.87 @@ -827,19 +837,6 @@
1.88 #print "->", namearray
1.89 return namearray
1.90
1.91 - def _get_attributes(self, positions):
1.92 -
1.93 - """
1.94 - For the given 'positions' mapping from names to positions, return a
1.95 - dictionary mapping names to Attr instances incorporating information
1.96 - about their positions in the final instance structure.
1.97 - """
1.98 -
1.99 - d = {}
1.100 - for i, name in enumerate(self._get_position_list(positions)):
1.101 - d[name] = Attr(i, Instance(), name)
1.102 - return d
1.103 -
1.104 def _cmp_positions(self, a, b):
1.105
1.106 "Compare name plus position list operands 'a' and 'b'."
1.107 @@ -1050,9 +1047,16 @@
1.108 Defaults are also finalised by this method.
1.109 """
1.110
1.111 + if self.finalised:
1.112 + return
1.113 +
1.114 + # Defaults.
1.115 +
1.116 for i, default in enumerate(self.default_attrs):
1.117 default.position = i
1.118
1.119 + # Locals.
1.120 +
1.121 i = None
1.122 for i, name in enumerate(self.argnames):
1.123 self[name].position = i