mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue 9856: Change object.__format__ with a non-empty format string from a PendingDeprecationWarning to a DeprecationWarning.
This commit is contained in:
parent
e4f6a80ed8
commit
b9cd3531c4
4 changed files with 21 additions and 17 deletions
|
@ -1279,14 +1279,14 @@ class BuiltinTest(unittest.TestCase):
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Issue #7994: object.__format__ with a non-empty format string is
|
# Issue #7994: object.__format__ with a non-empty format string is
|
||||||
# pending deprecated
|
# deprecated
|
||||||
def test_deprecated_format_string(obj, fmt_str, should_raise_warning):
|
def test_deprecated_format_string(obj, fmt_str, should_raise_warning):
|
||||||
with warnings.catch_warnings(record=True) as w:
|
with warnings.catch_warnings(record=True) as w:
|
||||||
warnings.simplefilter("always", PendingDeprecationWarning)
|
warnings.simplefilter("always", DeprecationWarning)
|
||||||
format(obj, fmt_str)
|
format(obj, fmt_str)
|
||||||
if should_raise_warning:
|
if should_raise_warning:
|
||||||
self.assertEqual(len(w), 1)
|
self.assertEqual(len(w), 1)
|
||||||
self.assertIsInstance(w[0].message, PendingDeprecationWarning)
|
self.assertIsInstance(w[0].message, DeprecationWarning)
|
||||||
self.assertIn('object.__format__ with a non-empty format '
|
self.assertIn('object.__format__ with a non-empty format '
|
||||||
'string', str(w[0].message))
|
'string', str(w[0].message))
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -614,7 +614,7 @@ class UnicodeTest(string_tests.CommonTest,
|
||||||
self.assertEqual('{0!s}'.format(G('data')), 'string is data')
|
self.assertEqual('{0!s}'.format(G('data')), 'string is data')
|
||||||
|
|
||||||
msg = 'object.__format__ with a non-empty format string is deprecated'
|
msg = 'object.__format__ with a non-empty format string is deprecated'
|
||||||
with support.check_warnings((msg, PendingDeprecationWarning)):
|
with support.check_warnings((msg, DeprecationWarning)):
|
||||||
self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ')
|
self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ')
|
||||||
self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ')
|
self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ')
|
||||||
self.assertEqual('{0:>15s}'.format(G('data')), ' string is data')
|
self.assertEqual('{0:>15s}'.format(G('data')), ' string is data')
|
||||||
|
|
|
@ -10,6 +10,10 @@ What's New in Python 3.3 Alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #9856: Change object.__format__ with a non-empty format string
|
||||||
|
to be a DeprecationWarning. In 3.2 it was a PendingDeprecationWarning.
|
||||||
|
In 3.4 it will be a TypeError.
|
||||||
|
|
||||||
- Issue #11244: The peephole optimizer is now able to constant-fold
|
- Issue #11244: The peephole optimizer is now able to constant-fold
|
||||||
arbitrarily complex expressions. This also fixes a 3.2 regression where
|
arbitrarily complex expressions. This also fixes a 3.2 regression where
|
||||||
operations involving negative numbers were not constant-folded.
|
operations involving negative numbers were not constant-folded.
|
||||||
|
|
|
@ -3401,21 +3401,21 @@ object_format(PyObject *self, PyObject *args)
|
||||||
self_as_str = PyObject_Str(self);
|
self_as_str = PyObject_Str(self);
|
||||||
if (self_as_str != NULL) {
|
if (self_as_str != NULL) {
|
||||||
/* Issue 7994: If we're converting to a string, we
|
/* Issue 7994: If we're converting to a string, we
|
||||||
should reject format specifications */
|
should reject format specifications */
|
||||||
if (PyUnicode_GET_SIZE(format_spec) > 0) {
|
if (PyUnicode_GET_SIZE(format_spec) > 0) {
|
||||||
if (PyErr_WarnEx(PyExc_PendingDeprecationWarning,
|
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||||
"object.__format__ with a non-empty format "
|
"object.__format__ with a non-empty format "
|
||||||
"string is deprecated", 1) < 0) {
|
"string is deprecated", 1) < 0) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Eventually this will become an error:
|
/* Eventually this will become an error:
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"non-empty format string passed to object.__format__");
|
"non-empty format string passed to object.__format__");
|
||||||
goto done;
|
goto done;
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
result = PyObject_Format(self_as_str, format_spec);
|
result = PyObject_Format(self_as_str, format_spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue