aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-02-21 16:24:11 +0200
committerMatti Picus <matti.picus@gmail.com>2021-02-21 16:24:11 +0200
commit8ebf638620e034f7c46442269dec9bbdd0941084 (patch)
treefe4cb5b2548cdd0f4293e096708d4bc5ca21a570
parentfix translation error on 32b Linux (diff)
downloadpypy-8ebf638620e034f7c46442269dec9bbdd0941084.tar.gz
pypy-8ebf638620e034f7c46442269dec9bbdd0941084.tar.bz2
pypy-8ebf638620e034f7c46442269dec9bbdd0941084.zip
test, fix for PyObject_Format(space.wrap(type('a')), None)
-rw-r--r--pypy/module/cpyext/object.py4
-rw-r--r--pypy/module/cpyext/test/test_object.py2
2 files changed, 6 insertions, 0 deletions
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