diff Objects/stringobject.c @ 24736:ff05eef3a6d1 legacy-trunk

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.
author Guido van Rossum <guido@python.org>
date Sun, 11 Aug 2002 04:24:12 +0000
parents 12e146171f3d
children ab63af3ec349
line wrap: on
line diff
--- a/Objects/stringobject.c	Sun Aug 11 04:15:09 2002 +0000
+++ b/Objects/stringobject.c	Sun Aug 11 04:24:12 2002 +0000
@@ -3311,6 +3311,12 @@
 		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;