Author: Ronan Lamy <[email protected]>
Branch: py3.5
Changeset: r86756:c1d25a7b9783
Date: 2016-08-30 19:50 +0100
http://bitbucket.org/pypy/pypy/changeset/c1d25a7b9783/

Log:    format(object(), 'x') now raises an error (since 3.4)

diff --git a/pypy/module/__builtin__/test/test_format.py 
b/pypy/module/__builtin__/test/test_format.py
--- a/pypy/module/__builtin__/test/test_format.py
+++ b/pypy/module/__builtin__/test/test_format.py
@@ -1,22 +1,7 @@
-class AppTestFormat:
+class AppTestFormat(object):
 
     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
-
+        """Test error from format(object(), 'nonempty')"""
         fmt_strs = ['', 's']
 
         class A:
@@ -24,7 +9,7 @@
                 return format('', fmt_str)
 
         for fmt_str in fmt_strs:
-            test_deprecated(A(), fmt_str, False)
+            format(A(), fmt_str)  # does not raise
 
         class B:
             pass
@@ -34,5 +19,7 @@
 
         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)
+                if fmt_str:
+                    raises(TypeError, format, cls(), fmt_str)
+                else:
+                    format(cls(), fmt_str)  # does not raise
diff --git a/pypy/objspace/std/objectobject.py 
b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -195,8 +195,8 @@
     else:
         raise oefmt(space.w_TypeError, "format_spec must be a string")
     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_DeprecationWarning)
+        raise oefmt(space.w_TypeError,
+                    "non-empty format string passed to object.__format__")
     return space.format(w_as_str, w_format_spec)
 
 def descr__eq__(space, w_self, w_other):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to