1.1 --- a/micropython/data.py Sun Jun 06 03:03:09 2010 +0200
1.2 +++ b/micropython/data.py Sun Jun 06 15:27:50 2010 +0200
1.3 @@ -560,6 +560,15 @@
1.4
1.5 self.context_values.update(context_values)
1.6
1.7 + def is_constant(self):
1.8 +
1.9 + """
1.10 + Return whether this attribute references something that can be regarded
1.11 + as being constant within a particular scope.
1.12 + """
1.13 +
1.14 + return self.assignments == 1
1.15 +
1.16 def is_strict_constant(self):
1.17
1.18 """
1.19 @@ -656,7 +665,7 @@
1.20 return 0
1.21
1.22 def __repr__(self):
1.23 - return "Attr(%r, %s, %r) # [%s], %r" % (
1.24 + return "Attr(%r, %s, %r) # {[%s] (%r)}" % (
1.25 self.position, shortrepr(self.parent), self.name,
1.26 self._context_values_str(), self.assignments
1.27 )
1.28 @@ -1093,7 +1102,8 @@
1.29
1.30 "An inspected function."
1.31
1.32 - def __init__(self, name, parent, argnames, defaults, has_star, has_dstar, module=None, node=None):
1.33 + def __init__(self, name, parent, argnames, defaults, has_star, has_dstar,
1.34 + dynamic_def=0, module=None, node=None):
1.35
1.36 """
1.37 Initialise the function with the given 'name', 'parent', list of
1.38 @@ -1109,6 +1119,7 @@
1.39 self.defaults = defaults
1.40 self.has_star = has_star
1.41 self.has_dstar = has_dstar
1.42 + self.dynamic_def = dynamic_def
1.43 self.astnode = node
1.44 node._def = self
1.45
1.46 @@ -1210,7 +1221,7 @@
1.47
1.48 if self.dynamic is None:
1.49 for attr in self.default_attrs:
1.50 - if not attr.is_strict_constant():
1.51 + if not attr.is_strict_constant() and self.dynamic_def:
1.52 self.dynamic = 1
1.53 self._make_dynamic()
1.54 break
1.55 @@ -1333,7 +1344,7 @@
1.56 "Make an instantiator function from a method, keeping all arguments."
1.57
1.58 function = Function(self.parent.name, self.parent.parent, self.argnames, self.defaults,
1.59 - self.has_star, self.has_dstar, self.module, self.astnode)
1.60 + self.has_star, self.has_dstar, self.dynamic_def, self.module, self.astnode)
1.61 function.default_attrs = self.default_attrs
1.62 return function
1.63