[pypy-commit] pypy default: create noneify() method to handle unions with s_None

rlamy noreply at buildbot.pypy.org
Tue May 27 19:59:24 CEST 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: 
Changeset: r71744:f02e2ea76f2e
Date: 2014-05-27 18:57 +0100
http://bitbucket.org/pypy/pypy/changeset/f02e2ea76f2e/

Log:	create noneify() method to handle unions with s_None

diff --git a/rpython/annotator/binaryop.py b/rpython/annotator/binaryop.py
--- a/rpython/annotator/binaryop.py
+++ b/rpython/annotator/binaryop.py
@@ -768,6 +768,22 @@
 
 # mixing Nones with other objects
 
+class __extend__(pairtype(SomeObject, SomeNone)):
+    def union((obj, none)):
+        return obj.noneify()
+
+class __extend__(pairtype(SomeNone, SomeObject)):
+    def union((none, obj)):
+        return obj.noneify()
+
+class __extend__(pairtype(SomeImpossibleValue, SomeNone)):
+    def union((imp1, none)):
+        return s_None
+
+class __extend__(pairtype(SomeNone, SomeImpossibleValue)):
+    def union((none, imp2)):
+        return s_None
+
 def _make_none_union(classname, constructor_args='', glob=None):
     if glob is None:
         glob = globals()
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -122,6 +122,9 @@
     def can_be_none(self):
         return True
 
+    def noneify(self):
+        raise UnionError(self, s_None)
+
     def nonnoneify(self):
         return self
 
@@ -476,7 +479,12 @@
         return self.can_be_None
 
     def nonnoneify(self):
-        return SomePBC(self.descriptions, can_be_None=False)
+        return SomePBC(self.descriptions, can_be_None=False,
+                subset_of=self.subset_of)
+
+    def noneify(self):
+        return SomePBC(self.descriptions, can_be_None=True,
+                subset_of=self.subset_of)
 
     def fmt_descriptions(self, pbis):
         if hasattr(self, 'const'):


More information about the pypy-commit mailing list