[pypy-commit] pypy py3.3: Upgrade the warning from format(object, fmt_str) with non-empty format string.
kvas
noreply at buildbot.pypy.org
Sun Aug 3 21:58:18 CEST 2014
Author: Vasily Kuznetsov <kvas.it at gmail.com>
Branch: py3.3
Changeset: r72680:3b7ff7cf933b
Date: 2014-08-02 11:25 +0200
http://bitbucket.org/pypy/pypy/changeset/3b7ff7cf933b/
Log: Upgrade the warning from format(object, fmt_str) with non-empty
format string.
diff --git a/pypy/module/__builtin__/test/test_format.py b/pypy/module/__builtin__/test/test_format.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__builtin__/test/test_format.py
@@ -0,0 +1,38 @@
+class AppTestFormat:
+
+ def test_format(self):
+ """Test deprecation warnings from format(object(), 'nonempty')"""
+
+ import warnings
+
+ def test_deprecated(obj, fmt_str, should_raise_warning):
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always", DeprecationWarning)
+ format(obj, fmt_str)
+ if should_raise_warning:
+ assert len(w) == 1
+ assert isinstance(w[0].message, DeprecationWarning)
+ assert 'object.__format__ with a non-empty format string '\
+ in str(w[0].message)
+ else:
+ assert len(w) == 0
+
+ fmt_strs = ['', 's']
+
+ class A:
+ def __format__(self, fmt_str):
+ return format('', fmt_str)
+
+ for fmt_str in fmt_strs:
+ test_deprecated(A(), fmt_str, False)
+
+ class B:
+ pass
+
+ class C(object):
+ pass
+
+ for cls in [object, B, C]:
+ for fmt_str in fmt_strs:
+ print(cls, fmt_str)
+ test_deprecated(cls(), fmt_str, len(fmt_str) != 0)
diff --git a/pypy/objspace/std/objecttype.py b/pypy/objspace/std/objecttype.py
--- a/pypy/objspace/std/objecttype.py
+++ b/pypy/objspace/std/objecttype.py
@@ -154,7 +154,7 @@
raise OperationError(space.w_TypeError, space.wrap(msg))
if space.len_w(w_format_spec) > 0:
msg = "object.__format__ with a non-empty format string is deprecated"
- space.warn(space.wrap(msg), space.w_PendingDeprecationWarning)
+ space.warn(space.wrap(msg), space.w_DeprecationWarning)
return space.format(w_as_str, w_format_spec)
def descr___subclasshook__(space, __args__):
More information about the pypy-commit
mailing list