Author: Antonio Cuni <anto.c...@gmail.com> Branch: py3k Changeset: r56798:230a83193f7a Date: 2012-08-22 13:44 +0200 http://bitbucket.org/pypy/pypy/changeset/230a83193f7a/
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): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit