Commits

Antonio Cuni  committed 1ce7bee

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

  • Participants
  • Parent commits af6e5e8

Comments (0)

Files changed (2)

File pypy/rlib/objectmodel.py

     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

File pypy/rlib/test/test_objectmodel.py

     # 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):