diff options
-rw-r--r-- | pypy/doc/whatsnew-head.rst | 4 | ||||
-rw-r--r-- | pypy/module/cpyext/object.py | 4 | ||||
-rw-r--r-- | pypy/module/cpyext/test/test_object.py | 2 |
3 files changed, 10 insertions, 0 deletions
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst index cf7632de21..26094691b6 100644 --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -85,3 +85,7 @@ new "builtin" types (wide chars, complex, etc.). .. branch: intbound-improvements-3 Refactor the intbound analysis in the JIT + +.. branch: issue-3404 + +Fix ``PyObject_Format`` for type objects diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py index 776886db50..346ac6515e 100644 --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -195,6 +195,10 @@ def PyObject_Repr(space, w_obj): def PyObject_Format(space, w_obj, w_format_spec): if w_format_spec is None: w_format_spec = space.newtext('') + # issue 3404: handle PyObject_Format(type('a'), '') + if (space.isinstance_w(w_format_spec, space.w_unicode) and + space.len_w(w_format_spec) == 0): + return space.unicode_from_object(w_obj) w_ret = space.call_method(w_obj, '__format__', w_format_spec) if space.isinstance_w(w_format_spec, space.w_unicode): return space.unicode_from_object(w_ret) diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py index 2aeded1de3..a153f26708 100644 --- a/pypy/module/cpyext/test/test_object.py +++ b/pypy/module/cpyext/test/test_object.py @@ -377,6 +377,8 @@ class AppTestObject(AppTestCpythonExtensionBase): """)]) a = module.empty_format('hello') assert isinstance(a, unicode) + a = module.empty_format(type('hello')) + assert isinstance(a, unicode) def test_add_memory_pressure(self): self.reset_memory_pressure() # for the potential skip |