diff options
author | 2021-02-21 20:20:13 +0200 | |
---|---|---|
committer | 2021-02-21 20:20:13 +0200 | |
commit | a7e447f25977c14954bb31da6426b3f38651d273 (patch) | |
tree | 5cb62cc50caf2139fff59855e6505acf9b97d200 | |
parent | update cffi to c16abb8f809f (diff) | |
parent | test, fix for PyObject_Format(space.wrap(type('a')), None) (diff) | |
download | pypy-a7e447f25977c14954bb31da6426b3f38651d273.tar.gz pypy-a7e447f25977c14954bb31da6426b3f38651d273.tar.bz2 pypy-a7e447f25977c14954bb31da6426b3f38651d273.zip |
merge branch to fix PyObject_Format for type objects (issue 3404)
-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 |