1.1 --- a/TO_DO.txt Sun Oct 13 15:45:26 2013 +0200
1.2 +++ b/TO_DO.txt Sun Oct 13 18:40:30 2013 +0200
1.3 @@ -1,6 +1,3 @@
1.4 -Add a namespace attribute counter for specific definitions/declarations of things like
1.5 -classes and functions, used to number multiple definitions in a given module.
1.6 -
1.7 Name usage types: as parameters, as base classes, as callables. This potentially restricts
1.8 attribute usage effects because names mentioned as base classes are not propagated and
1.9 made freely available for use in attribute accesses.
2.1 --- a/micropython/data.py Sun Oct 13 15:45:26 2013 +0200
2.2 +++ b/micropython/data.py Sun Oct 13 18:40:30 2013 +0200
2.3 @@ -365,6 +365,10 @@
2.4
2.5 self.assignments = None
2.6
2.7 + # Number of static "class" or "def" assignments per name.
2.8 +
2.9 + self.static_assignments = 0
2.10 +
2.11 # Value-related methods.
2.12
2.13 def get_contexts(self):
2.14 @@ -1474,7 +1478,9 @@
2.15 original_name = name
2.16
2.17 if parent.has_key(name):
2.18 - name = "%s#%d" % (name, parent[name].assignments + 1)
2.19 + assignments = parent[name].static_assignments
2.20 + if assignments > 1:
2.21 + name = "%s#%d" % (name, assignments + 1)
2.22
2.23 cls = Class(name, parent, module, node, original_name)
2.24
2.25 @@ -1497,15 +1503,9 @@
2.26 original_name = name
2.27
2.28 if parent.has_key(name):
2.29 - # NOTE: Handle AtLeast(n) situations, such as in cases where modules
2.30 - # NOTE: may mutate others (doctest "monkeypatching" linecache, for
2.31 - # NOTE: example).
2.32 - # NOTE: Should probably have a separate attribute tracking actual
2.33 - # NOTE: declarations rather than use the assignments attribute.
2.34 - assignments = parent[name].assignments
2.35 - if isinstance(assignments, AtLeast):
2.36 - assignments = assignments.count
2.37 - name = "%s#%d" % (name, assignments + 1)
2.38 + assignments = parent[name].static_assignments
2.39 + if assignments > 1:
2.40 + name = "%s#%d" % (name, assignments + 1)
2.41
2.42 fn = Function(name, parent, argnames, defaults, has_star, has_dstar,
2.43 dynamic_def, module, node, original_name)
3.1 --- a/micropython/inspect.py Sun Oct 13 15:45:26 2013 +0200
3.2 +++ b/micropython/inspect.py Sun Oct 13 18:40:30 2013 +0200
3.3 @@ -415,9 +415,13 @@
3.4 namespaces = namespaces or self.namespaces
3.5 return len(namespaces) > 1 and isinstance(namespaces[-2], Class)
3.6
3.7 - def store(self, name, obj):
3.8 + def store(self, name, obj, static_def=False):
3.9
3.10 - "Record attribute or local 'name', storing 'obj'."
3.11 + """
3.12 + Record attribute or local 'name', storing 'obj'. Where 'static_def' is
3.13 + specified and set to a true value, the namespace will record a static
3.14 + definition for the given name.
3.15 + """
3.16
3.17 # Store in the module.
3.18
3.19 @@ -425,7 +429,7 @@
3.20 if self.in_loop and self.used_in_scope(name, "builtins"):
3.21 raise InspectError("Name %r already used as a built-in." % name)
3.22 else:
3.23 - self.set(name, obj, not self.in_loop)
3.24 + ns = self
3.25
3.26 # Or store locally.
3.27
3.28 @@ -437,7 +441,11 @@
3.29 elif self.in_loop and locals.used_in_scope(name, "builtins"):
3.30 raise InspectError("Name %r already used as a built-in." % name)
3.31 else:
3.32 - locals.set(name, obj, not self.in_loop)
3.33 + ns = locals
3.34 +
3.35 + ns.set(name, obj, not self.in_loop)
3.36 + if static_def:
3.37 + ns.get(name).static_assignments += 1
3.38
3.39 def store_lambda(self, obj):
3.40
3.41 @@ -800,7 +808,7 @@
3.42 # Store the function.
3.43
3.44 if name is not None:
3.45 - self.store(name, function)
3.46 + self.store(name, function, static_def=True)
3.47 else:
3.48 self.store_lambda(function)
3.49
3.50 @@ -1019,7 +1027,7 @@
3.51 # Make an entry for the class in the parent namespace.
3.52
3.53 self.namespaces.pop()
3.54 - self.store(node.name, cls)
3.55 + self.store(node.name, cls, static_def=True)
3.56 self.define_attribute_user(node)
3.57 self.add_object(cls)
3.58
4.1 --- a/micropython/report.py Sun Oct 13 15:45:26 2013 +0200
4.2 +++ b/micropython/report.py Sun Oct 13 18:40:30 2013 +0200
4.3 @@ -271,10 +271,15 @@
4.4 can be used to customise the CSS classes employed.
4.5 """
4.6
4.7 + if isinstance(obj, (Class, Function)):
4.8 + name = obj.original_name
4.9 + else:
4.10 + name = obj.name
4.11 +
4.12 if isinstance(obj, Class) or (isinstance(obj, Function) and obj.is_method()):
4.13 - self._summary_link(module.full_name(), obj.full_name(), obj.name, classes)
4.14 + self._summary_link(module.full_name(), obj.full_name(), name, classes)
4.15 else:
4.16 - self._span(obj.name, classes)
4.17 + self._span(name, classes)
4.18
4.19 def _object_name_ref(self, module, obj, name=None, classes=None):
4.20