1.1 --- a/annotate.py Sun Jan 21 00:17:09 2007 +0100
1.2 +++ b/annotate.py Sun Jan 21 00:17:44 2007 +0100
1.3 @@ -539,7 +539,7 @@
1.4 if not attributes:
1.5 if not attr in non_accesses:
1.6 non_accesses.append(attr)
1.7 - combine(self.namespace.raises, self.get_builtin_instances("AttributeError"))
1.8 + combine(self.namespace.raises, self.get_builtin_instances(loadattr, "AttributeError"))
1.9
1.10 # Revoke this type from any name involved.
1.11
1.12 @@ -555,7 +555,7 @@
1.13 else:
1.14 if not attr in non_accesses:
1.15 non_accesses.append(attr)
1.16 - combine(self.namespace.raises, self.get_builtin_instances("AttributeError"))
1.17 + combine(self.namespace.raises, self.get_builtin_instances(loadattr, "AttributeError"))
1.18
1.19 # Revoke this type from any name involved.
1.20
1.21 @@ -869,8 +869,8 @@
1.22
1.23 # Utility methods.
1.24
1.25 - def get_builtin_instances(self, name):
1.26 - return [Attribute(None, self._new_instance(attr.type)) for attr in self.builtins.namespace[name]]
1.27 + def get_builtin_instances(self, node, name):
1.28 + return [Attribute(None, self._new_instance(node, attr.type)) for attr in self.builtins.namespace[name]]
1.29
1.30 def new_instance(self, node, reason, target, type):
1.31
1.32 @@ -880,23 +880,22 @@
1.33 node.instances = {}
1.34
1.35 if not node.instances.has_key((reason, target, type)):
1.36 - instance = self._new_instance(type)
1.37 + instance = self._new_instance(node, type)
1.38 node.instances[(reason, target, type)] = instance
1.39
1.40 return node.instances[(reason, target, type)]
1.41
1.42 - def _new_instance(self, type):
1.43 + def _new_instance(self, node, type):
1.44
1.45 - # Insist on a single instance per type.
1.46 - # NOTE: Strategy-dependent instantiation.
1.47 + "For the given 'node', obtain an instance from the given 'type'."
1.48
1.49 - if len(type.instances) == 0:
1.50 + if not type.has_instance(node):
1.51 instance = Instance()
1.52 instance.namespace = Namespace()
1.53 instance.namespace.store("__class__", [Attribute(None, type)])
1.54 - type.instances.append(instance)
1.55 + type.add_instance(node, instance)
1.56 else:
1.57 - instance = type.instances[0]
1.58 + instance = type.get_instance(node)
1.59
1.60 return instance
1.61