summaryrefslogtreecommitdiff
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-08-11 04:24:12 +0000
committerGuido van Rossum <guido@python.org>2002-08-11 04:24:12 +0000
commit937becc9c6d790a32a1a483640f1f197ba9df1cb (patch)
tree3ca3931e5804232074d2775886feafe40c6a7173 /Objects/stringobject.c
parentdde0a20b255a9a715edd7bb2149c86620061b1ef (diff)
downloadcpython-937becc9c6d790a32a1a483640f1f197ba9df1cb.tar.gz
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.
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r--Objects/stringobject.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 1d5277c0c7..1bbd201047 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3311,6 +3311,12 @@ formatint(char *buf, size_t buflen, int flags,
PyErr_SetString(PyExc_TypeError, "int argument required");
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;