[pypy-commit] pypy default: don't complain if we pass None to something which expects unicode or str

antocuni noreply at buildbot.pypy.org
Wed Aug 22 18:52:23 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r56808:1ce7beebfd5f
Date: 2012-08-22 13:44 +0200
http://bitbucket.org/pypy/pypy/changeset/1ce7beebfd5f/

Log:	don't complain if we pass None to something which expects unicode or
	str

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -129,10 +129,13 @@
     def decorator(f):
         def get_annotation(t):
             from pypy.annotation.signature import annotation
-            from pypy.annotation.model import SomeObject
+            from pypy.annotation.model import SomeObject, SomeStringOrUnicode
             if isinstance(t, SomeObject):
                 return t
-            return annotation(t)
+            s_result = annotation(t)
+            if isinstance(s_result, SomeStringOrUnicode):
+                return s_result.__class__(can_be_None=True)
+            return s_result
         def get_type_descr_of_argument(arg):
             # we don't want to check *all* the items in list/dict: we assume
             # they are already homogeneous, so we only check the first
diff --git a/pypy/rlib/test/test_objectmodel.py b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -450,6 +450,12 @@
     # in RPython there is an implicit int->float promotion
     assert f(42) == 42
 
+def test_enforceargs_None_string():
+    @enforceargs(str, unicode)
+    def f(a, b):
+        return a, b
+    assert f(None, None) == (None, None)
+
 def test_enforceargs_complex_types():
     @enforceargs([int], {str: int})
     def f(a, b):


More information about the pypy-commit mailing list