mirror of
https://github.com/python/cpython.git
synced 2025-07-12 05:45:15 +00:00
Implement stage B0 of PEP 237: add warnings for operations that
currently return inconsistent results for ints and longs; in particular: hex/oct/%u/%o/%x/%X of negative short ints, and x<<n that either loses bits or changes sign. (No warnings for repr() of a long, though that will also change to lose the trailing 'L' eventually.) This introduces some warnings in the test suite; I'll take care of those later.
This commit is contained in:
parent
d92ae840e9
commit
078151da90
4 changed files with 50 additions and 4 deletions
|
@ -5219,6 +5219,10 @@ int usprintf(register Py_UNICODE *buffer, char *format, ...)
|
|||
return len;
|
||||
}
|
||||
|
||||
/* XXX To save some code duplication, formatfloat/long/int could have been
|
||||
shared with stringobject.c, converting from 8-bit to Unicode after the
|
||||
formatting is done. */
|
||||
|
||||
static int
|
||||
formatfloat(Py_UNICODE *buf,
|
||||
size_t buflen,
|
||||
|
@ -5294,6 +5298,12 @@ formatint(Py_UNICODE *buf,
|
|||
x = PyInt_AsLong(v);
|
||||
if (x == -1 && PyErr_Occurred())
|
||||
return -1;
|
||||
if (x < 0 && type != 'd' && type != 'i') {
|
||||
if (PyErr_Warn(PyExc_DeprecationWarning,
|
||||
"%u/%o/%x/%X of negative int will return "
|
||||
"a signed string in Python 2.4 and up") < 0)
|
||||
return -1;
|
||||
}
|
||||
if (prec < 0)
|
||||
prec = 1;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue