[pypy-svn] pypy default: (fijal, arigo)
arigo
commits-noreply at bitbucket.org
Thu Jan 20 12:18:29 CET 2011
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r40978:8b936960cb37
Date: 2011-01-20 12:16 +0100
http://bitbucket.org/pypy/pypy/changeset/8b936960cb37/
Log: (fijal, arigo)
Check the return type of __format__().
diff --git a/pypy/module/__builtin__/operation.py b/pypy/module/__builtin__/operation.py
--- a/pypy/module/__builtin__/operation.py
+++ b/pypy/module/__builtin__/operation.py
@@ -262,8 +262,6 @@
function). Note that classes are callable."""
return space.callable(w_object)
-def format(space, w_obj, w_format_spec=NoneNotWrapped):
+def format(space, w_obj, w_format_spec=""):
"""Format a obj according to format_spec"""
- if w_format_spec is None:
- w_format_spec = space.wrap("")
return space.format(w_obj, w_format_spec)
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -316,11 +316,18 @@
def format(space, w_obj, w_format_spec):
w_descr = space.lookup(w_obj, '__format__')
if w_descr is None:
- typename = space.type(w_obj).getname(space, '?')
+ typename = space.type(w_obj).getname(space)
raise operationerrfmt(space.w_TypeError,
"'%s' object does not define __format__",
typename)
- return space.get_and_call_function(w_descr, w_obj, w_format_spec)
+ w_res = space.get_and_call_function(w_descr, w_obj, w_format_spec)
+ if not space.is_true(space.isinstance(w_res, space.w_basestring)):
+ typename = space.type(w_obj).getname(space)
+ restypename = space.type(w_res).getname(space)
+ raise operationerrfmt(space.w_TypeError,
+ "%s.__format__ must return string or unicode, not %s",
+ typename, restypename)
+ return w_res
def pow(space, w_obj1, w_obj2, w_obj3):
w_typ1 = space.type(w_obj1)
More information about the Pypy-commit
mailing list