mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
- Removed FutureWarnings related to hex/oct literals and conversions
and left shifts. (Thanks to Kalle Svensson for SF patch 849227.) This addresses most of the remaining semantic changes promised by PEP 237, except for repr() of a long, which still shows the trailing 'L'. The PEP appears to promise warnings for operations that changed semantics compared to Python 2.3, but this is not implemented; we've suffered through enough warnings related to hex/oct literals and I think it's best to be silent now.
This commit is contained in:
parent
37e136373e
commit
6c9e130524
11 changed files with 120 additions and 148 deletions
|
@ -278,7 +278,6 @@ PyInt_FromString(char *s, char **pend, int base)
|
|||
char *end;
|
||||
long x;
|
||||
char buffer[256]; /* For errors */
|
||||
int warn = 0;
|
||||
|
||||
if ((base != 0 && base < 2) || base > 36) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
@ -292,7 +291,7 @@ PyInt_FromString(char *s, char **pend, int base)
|
|||
if (base == 0 && s[0] == '0') {
|
||||
x = (long) PyOS_strtoul(s, &end, base);
|
||||
if (x < 0)
|
||||
warn = 1;
|
||||
return PyLong_FromString(s, pend, base);
|
||||
}
|
||||
else
|
||||
x = PyOS_strtol(s, &end, base);
|
||||
|
@ -312,11 +311,6 @@ PyInt_FromString(char *s, char **pend, int base)
|
|||
return NULL;
|
||||
return PyLong_FromString(s, pend, base);
|
||||
}
|
||||
if (warn) {
|
||||
if (PyErr_Warn(PyExc_FutureWarning,
|
||||
"int('0...', 0): sign will change in Python 2.4") < 0)
|
||||
return NULL;
|
||||
}
|
||||
if (pend)
|
||||
*pend = end;
|
||||
return PyInt_FromLong(x);
|
||||
|
@ -766,18 +760,13 @@ int_lshift(PyIntObject *v, PyIntObject *w)
|
|||
if (a == 0 || b == 0)
|
||||
return int_pos(v);
|
||||
if (b >= LONG_BIT) {
|
||||
if (PyErr_Warn(PyExc_FutureWarning,
|
||||
"x<<y losing bits or changing sign "
|
||||
"will return a long in Python 2.4 and up") < 0)
|
||||
return NULL;
|
||||
return PyInt_FromLong(0L);
|
||||
return PyNumber_Lshift(PyLong_FromLong(PyInt_AS_LONG(v)),
|
||||
PyLong_FromLong(PyInt_AS_LONG(w)));
|
||||
}
|
||||
c = a << b;
|
||||
if (a != Py_ARITHMETIC_RIGHT_SHIFT(long, c, b)) {
|
||||
if (PyErr_Warn(PyExc_FutureWarning,
|
||||
"x<<y losing bits or changing sign "
|
||||
"will return a long in Python 2.4 and up") < 0)
|
||||
return NULL;
|
||||
return PyNumber_Lshift(PyLong_FromLong(PyInt_AS_LONG(v)),
|
||||
PyLong_FromLong(PyInt_AS_LONG(w)));
|
||||
}
|
||||
return PyInt_FromLong(c);
|
||||
}
|
||||
|
@ -868,13 +857,9 @@ int_oct(PyIntObject *v)
|
|||
{
|
||||
char buf[100];
|
||||
long x = v -> ob_ival;
|
||||
if (x < 0) {
|
||||
if (PyErr_Warn(PyExc_FutureWarning,
|
||||
"hex()/oct() of negative int will return "
|
||||
"a signed string in Python 2.4 and up") < 0)
|
||||
return NULL;
|
||||
}
|
||||
if (x == 0)
|
||||
if (x < 0)
|
||||
PyOS_snprintf(buf, sizeof(buf), "-0%lo", -x);
|
||||
else if (x == 0)
|
||||
strcpy(buf, "0");
|
||||
else
|
||||
PyOS_snprintf(buf, sizeof(buf), "0%lo", x);
|
||||
|
@ -886,13 +871,10 @@ int_hex(PyIntObject *v)
|
|||
{
|
||||
char buf[100];
|
||||
long x = v -> ob_ival;
|
||||
if (x < 0) {
|
||||
if (PyErr_Warn(PyExc_FutureWarning,
|
||||
"hex()/oct() of negative int will return "
|
||||
"a signed string in Python 2.4 and up") < 0)
|
||||
return NULL;
|
||||
}
|
||||
PyOS_snprintf(buf, sizeof(buf), "0x%lx", x);
|
||||
if (x < 0)
|
||||
PyOS_snprintf(buf, sizeof(buf), "-0x%lx", -x);
|
||||
else
|
||||
PyOS_snprintf(buf, sizeof(buf), "0x%lx", x);
|
||||
return PyString_FromString(buf);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue