diff options
author | Guido van Rossum <guido@python.org> | 2003-11-29 23:52:13 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-11-29 23:52:13 (GMT) |
commit | 6c9e130524533263b690e86639a36b6f3e7a8eeb (patch) | |
tree | 39023f825688f630245ddcaa60af9942a859522c /Objects/intobject.c | |
parent | 37e136373e0d9ab3bdf25ecd9c42b86281ed21d3 (diff) | |
download | cpython-6c9e130524533263b690e86639a36b6f3e7a8eeb.zip cpython-6c9e130524533263b690e86639a36b6f3e7a8eeb.tar.gz cpython-6c9e130524533263b690e86639a36b6f3e7a8eeb.tar.bz2 |
- 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.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index b97e2bc..47acbff 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -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); } |