mirror of
https://github.com/python/cpython.git
synced 2025-07-15 23:35:23 +00:00
Issue19995: passing a non-int to %o, %c, %x, or %X now raises an exception
This commit is contained in:
parent
8e5d0caf92
commit
38d872ee5d
5 changed files with 10 additions and 43 deletions
|
@ -13987,23 +13987,11 @@ mainformatlong(PyObject *v,
|
|||
goto wrongtype;
|
||||
|
||||
/* make sure number is a type of integer */
|
||||
/* if not, issue deprecation warning for now */
|
||||
if (!PyLong_Check(v)) {
|
||||
if (type == 'o' || type == 'x' || type == 'X') {
|
||||
iobj = PyNumber_Index(v);
|
||||
if (iobj == NULL) {
|
||||
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;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -14085,22 +14073,10 @@ formatchar(PyObject *v)
|
|||
PyObject *iobj;
|
||||
long x;
|
||||
/* make sure number is a type of integer */
|
||||
/* if not, issue deprecation warning for now */
|
||||
if (!PyLong_Check(v)) {
|
||||
iobj = PyNumber_Index(v);
|
||||
if (iobj == NULL) {
|
||||
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;
|
||||
}
|
||||
goto onError;
|
||||
}
|
||||
v = iobj;
|
||||
Py_DECREF(iobj);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue