[pypy-commit] pypy anntype: Implement unions of SomeExceptions
rlamy
noreply at buildbot.pypy.org
Fri Nov 20 12:25:01 EST 2015
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: anntype
Changeset: r80810:f0b297934dd7
Date: 2015-11-20 17:25 +0000
http://bitbucket.org/pypy/pypy/changeset/f0b297934dd7/
Log: Implement unions of SomeExceptions
diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -689,6 +689,10 @@
def union((s_inst, s_exc)):
return unionof(s_exc.as_SomeInstance(), s_inst)
+class __extend__(pairtype(SomeException, SomeException)):
+ def union((s_exc1, s_exc2)):
+ return SomeException(s_exc1.classdefs | s_exc2.classdefs)
+
@op.getitem.register_transform(SomeInstance, SomeObject)
def getitem_SomeInstance(annotator, v_ins, v_idx):
diff --git a/rpython/annotator/test/test_model.py b/rpython/annotator/test/test_model.py
--- a/rpython/annotator/test/test_model.py
+++ b/rpython/annotator/test/test_model.py
@@ -148,3 +148,6 @@
s_nullable = unionof(s_None, bk.new_exception([ValueError]))
assert isinstance(s_nullable, SomeInstance)
assert s_nullable.can_be_None
+ s_exc1 = bk.new_exception([ValueError])
+ s_exc2 = bk.new_exception([IndexError])
+ unionof(s_exc1, s_exc2) == unionof(s_exc2, s_exc1)
More information about the pypy-commit
mailing list