1.1 --- a/annotate.py Sat Dec 16 00:51:02 2006 +0100
1.2 +++ b/annotate.py Sat Dec 16 01:14:18 2006 +0100
1.3 @@ -539,6 +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
1.9 # Revoke this type from any name involved.
1.10
1.11 @@ -554,6 +555,7 @@
1.12 else:
1.13 if not attr in non_accesses:
1.14 non_accesses.append(attr)
1.15 + combine(self.namespace.raises, self.get_builtin_instances("AttributeError"))
1.16
1.17 # Revoke this type from any name involved.
1.18
1.19 @@ -867,6 +869,9 @@
1.20
1.21 # Utility methods.
1.22
1.23 + def get_builtin_instances(self, name):
1.24 + return [Attribute(None, self._new_instance(attr.type)) for attr in self.builtins.namespace[name]]
1.25 +
1.26 def new_instance(self, node, reason, target, type):
1.27
1.28 "Create, on the given 'node', a new instance with the given 'type'."
1.29 @@ -875,22 +880,26 @@
1.30 node.instances = {}
1.31
1.32 if not node.instances.has_key((reason, target, type)):
1.33 -
1.34 - # Insist on a single instance per type.
1.35 - # NOTE: Strategy-dependent instantiation.
1.36 -
1.37 - if len(type.instances) == 0:
1.38 - instance = Instance()
1.39 - instance.namespace = Namespace()
1.40 - instance.namespace.store("__class__", [Attribute(None, type)])
1.41 - type.instances.append(instance)
1.42 - else:
1.43 - instance = type.instances[0]
1.44 -
1.45 + instance = self._new_instance(type)
1.46 node.instances[(reason, target, type)] = instance
1.47
1.48 return node.instances[(reason, target, type)]
1.49
1.50 + def _new_instance(self, type):
1.51 +
1.52 + # Insist on a single instance per type.
1.53 + # NOTE: Strategy-dependent instantiation.
1.54 +
1.55 + if len(type.instances) == 0:
1.56 + instance = Instance()
1.57 + instance.namespace = Namespace()
1.58 + instance.namespace.store("__class__", [Attribute(None, type)])
1.59 + type.instances.append(instance)
1.60 + else:
1.61 + instance = type.instances[0]
1.62 +
1.63 + return instance
1.64 +
1.65 def invoke_subprogram(self, invoke, attribute):
1.66
1.67 """
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tests/tryexcept2.py Sat Dec 16 01:14:18 2006 +0100
2.3 @@ -0,0 +1,15 @@
2.4 +class A:
2.5 + pass
2.6 +
2.7 +def f(x):
2.8 + try:
2.9 + try:
2.10 + y = x.attr
2.11 + except AttributeError, e:
2.12 + f = e
2.13 + except Exception, e:
2.14 + f = e
2.15 + return f
2.16 +
2.17 +x = A()
2.18 +f(x)