Author: Ronan Lamy <[email protected]>
Branch: anntype
Changeset: r80764:4bf6d2c87b5c
Date: 2015-11-18 18:20 +0000
http://bitbucket.org/pypy/pypy/changeset/4bf6d2c87b5c/
Log: Add SomeExceptCase and clarify the meaning of SomeException
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -11,7 +11,7 @@
from rpython.translator import simplify, transform
from rpython.annotator import model as annmodel, signature
from rpython.annotator.model import (
- SomeTypeOf, SomeException, s_ImpossibleValue)
+ SomeTypeOf, SomeException, SomeExceptCase, s_ImpossibleValue)
from rpython.annotator.bookkeeper import Bookkeeper
from rpython.rtyper.normalizecalls import perform_normalizations
@@ -497,7 +497,7 @@
s_exception = SomeException(set(can_only_throw))
for link in exits:
case = link.exitcase
- s_case = SomeException({case})
+ s_case = SomeExceptCase(case)
if case is None:
self.follow_link(graph, link, {})
continue
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -446,20 +446,21 @@
return SomeInstance(self.classdef, can_be_None=True)
class SomeException(SomeObject):
+ """The set of exceptions obeying type(exc) in self.classes"""
def __init__(self, classes):
self.classes = classes
def intersection(self, other):
- classes = {c for c in self.classes
- if any(issubclass(c, c2) for c2 in other.classes)}
+ assert isinstance(other, SomeExceptCase)
+ classes = {c for c in self.classes if issubclass(c, other.case)}
if classes:
return SomeException(classes)
else:
return s_ImpossibleValue
def difference(self, other):
- classes = {c for c in self.classes
- if not any(issubclass(c, c2) for c2 in other.classes)}
+ assert isinstance(other, SomeExceptCase)
+ classes = {c for c in self.classes if not issubclass(c, other.case)}
if classes:
return SomeException(classes)
else:
@@ -469,6 +470,15 @@
return unionof(*[bk.valueoftype(cls) for cls in self.classes])
+class SomeExceptCase(SomeObject):
+ """The set of exceptions that match a given except clause.
+
+ IOW, the set of exceptions that verify isinstance(exc, self.case).
+ """
+ def __init__(self, case):
+ self.case = case
+
+
class SomePBC(SomeObject):
"""Stands for a global user instance, built prior to the analysis,
or a set of such instances."""
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit