summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2014-01-12 07:20:58 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2014-01-12 07:20:58 (GMT)
commitf9bba9c67f7928be185bd81614881ae88a46aaab (patch)
tree6115322a5032536b3dbe72e2ca3a34d92c4878ed /Objects/unicodeobject.c
parent57bc1e21e7df2fe85ec87fcc11451939a309a4af (diff)
downloadcpython-f9bba9c67f7928be185bd81614881ae88a46aaab.zip
cpython-f9bba9c67f7928be185bd81614881ae88a46aaab.tar.gz
cpython-f9bba9c67f7928be185bd81614881ae88a46aaab.tar.bz2
Issue19995: issue deprecation warning for non-integer values to %c, %o, %x, %X
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 48eccf7..c8370bd 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14004,11 +14004,24 @@ mainformatlong(PyObject *v,
if (!PyNumber_Check(v))
goto wrongtype;
+ /* make sure number is a type of integer */
+ /* if not, issue depracation warning for now */
if (!PyLong_Check(v)) {
if (type == 'o' || type == 'x' || type == 'X') {
iobj = PyNumber_Index(v);
if (iobj == NULL) {
- return -1;
+ PyErr_Clear();
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "automatic int conversions have been deprecated",
+ 1)) {
+ return -1;
+ }
+ iobj = PyNumber_Long(v);
+ if (iobj == NULL ) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ goto wrongtype;
+ return -1;
+ }
}
}
else {
@@ -14090,10 +14103,22 @@ formatchar(PyObject *v)
PyObject *iobj;
long x;
/* make sure number is a type of integer */
+ /* if not, issue depracation warning for now */
if (!PyLong_Check(v)) {
iobj = PyNumber_Index(v);
if (iobj == NULL) {
- goto onError;
+ PyErr_Clear();
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "automatic int conversions have been deprecated",
+ 1)) {
+ return -1;
+ }
+ iobj = PyNumber_Long(v);
+ if (iobj == NULL ) {
+ if (PyErr_ExceptionMatches(PyExc_TypeError))
+ goto onError;
+ return -1;
+ }
}
v = iobj;
Py_DECREF(iobj);