summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-05-26 15:43:38 (GMT)
committerGitHub <noreply@github.com>2020-05-26 15:43:38 (GMT)
commit578c3955e0222ec7b3146197467fbb0fcfae12fe (patch)
tree1314ca1eb6153feaf3fb1cae341784270ce24c32 /Python
parent8ad052464a4e0aef9a11663b80f187087b773592 (diff)
downloadcpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.zip
cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.tar.gz
cpython-578c3955e0222ec7b3146197467fbb0fcfae12fe.tar.bz2
bpo-37999: No longer use __int__ in implicit integer conversions. (GH-15636)
Only __index__ should be used to make integer conversions lossless.
Diffstat (limited to 'Python')
-rw-r--r--Python/clinic/_warnings.c.h7
-rw-r--r--Python/clinic/bltinmodule.c.h27
-rw-r--r--Python/clinic/import.c.h7
-rw-r--r--Python/clinic/marshal.c.h12
-rw-r--r--Python/clinic/sysmodule.c.h27
-rw-r--r--Python/clinic/traceback.c.h12
-rw-r--r--Python/getargs.c66
7 files changed, 18 insertions, 140 deletions
diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h
index 67ab0e3..80ed2ae 100644
--- a/Python/clinic/_warnings.c.h
+++ b/Python/clinic/_warnings.c.h
@@ -43,11 +43,6 @@ warnings_warn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObjec
}
}
if (args[2]) {
- if (PyFloat_Check(args[2])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
{
Py_ssize_t ival = -1;
PyObject *iobj = PyNumber_Index(args[2]);
@@ -71,4 +66,4 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=b7bb54c73b5433ec input=a9049054013a1b77]*/
+/*[clinic end generated code: output=484e5ffe94edf0f0 input=a9049054013a1b77]*/
diff --git a/Python/clinic/bltinmodule.c.h b/Python/clinic/bltinmodule.c.h
index d15af1f..377afde 100644
--- a/Python/clinic/bltinmodule.c.h
+++ b/Python/clinic/bltinmodule.c.h
@@ -134,11 +134,6 @@ builtin_chr(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int i;
- if (PyFloat_Check(arg)) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
i = _PyLong_AsInt(arg);
if (i == -1 && PyErr_Occurred()) {
goto exit;
@@ -216,11 +211,6 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
goto skip_optional_pos;
}
if (args[3]) {
- if (PyFloat_Check(args[3])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
flags = _PyLong_AsInt(args[3]);
if (flags == -1 && PyErr_Occurred()) {
goto exit;
@@ -230,11 +220,6 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
}
}
if (args[4]) {
- if (PyFloat_Check(args[4])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
dont_inherit = _PyLong_AsInt(args[4]);
if (dont_inherit == -1 && PyErr_Occurred()) {
goto exit;
@@ -244,11 +229,6 @@ builtin_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObj
}
}
if (args[5]) {
- if (PyFloat_Check(args[5])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
optimize = _PyLong_AsInt(args[5]);
if (optimize == -1 && PyErr_Occurred()) {
goto exit;
@@ -261,11 +241,6 @@ skip_optional_pos:
if (!noptargs) {
goto skip_optional_kwonly;
}
- if (PyFloat_Check(args[6])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
feature_version = _PyLong_AsInt(args[6]);
if (feature_version == -1 && PyErr_Occurred()) {
goto exit;
@@ -855,4 +830,4 @@ builtin_issubclass(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=29686a89b739d600 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=780fd9712ec6a6db input=a9049054013a1b77]*/
diff --git a/Python/clinic/import.c.h b/Python/clinic/import.c.h
index e4867f3..4e013cc 100644
--- a/Python/clinic/import.c.h
+++ b/Python/clinic/import.c.h
@@ -420,11 +420,6 @@ _imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb
if (!args) {
goto exit;
}
- if (PyFloat_Check(args[0])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
key = PyLong_AsLong(args[0]);
if (key == -1 && PyErr_Occurred()) {
goto exit;
@@ -454,4 +449,4 @@ exit:
#ifndef _IMP_EXEC_DYNAMIC_METHODDEF
#define _IMP_EXEC_DYNAMIC_METHODDEF
#endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
-/*[clinic end generated code: output=3dc495e9c64d944e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=7c31c433af88af6b input=a9049054013a1b77]*/
diff --git a/Python/clinic/marshal.c.h b/Python/clinic/marshal.c.h
index 05d4830..f80d5ef 100644
--- a/Python/clinic/marshal.c.h
+++ b/Python/clinic/marshal.c.h
@@ -42,11 +42,6 @@ marshal_dump(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (nargs < 3) {
goto skip_optional;
}
- if (PyFloat_Check(args[2])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
version = _PyLong_AsInt(args[2]);
if (version == -1 && PyErr_Occurred()) {
goto exit;
@@ -111,11 +106,6 @@ marshal_dumps(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (nargs < 2) {
goto skip_optional;
}
- if (PyFloat_Check(args[1])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
version = _PyLong_AsInt(args[1]);
if (version == -1 && PyErr_Occurred()) {
goto exit;
@@ -165,4 +155,4 @@ exit:
return return_value;
}
-/*[clinic end generated code: output=a859dabe8b0afeb6 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=68b78f38bfe0c06d input=a9049054013a1b77]*/
diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h
index 4615eba..c1a9a2d 100644
--- a/Python/clinic/sysmodule.c.h
+++ b/Python/clinic/sysmodule.c.h
@@ -372,11 +372,6 @@ sys_setrecursionlimit(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int new_limit;
- if (PyFloat_Check(arg)) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
new_limit = _PyLong_AsInt(arg);
if (new_limit == -1 && PyErr_Occurred()) {
goto exit;
@@ -417,11 +412,6 @@ sys_set_coroutine_origin_tracking_depth(PyObject *module, PyObject *const *args,
if (!args) {
goto exit;
}
- if (PyFloat_Check(args[0])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
depth = _PyLong_AsInt(args[0]);
if (depth == -1 && PyErr_Occurred()) {
goto exit;
@@ -590,11 +580,6 @@ sys_setdlopenflags(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int new_val;
- if (PyFloat_Check(arg)) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
new_val = _PyLong_AsInt(arg);
if (new_val == -1 && PyErr_Occurred()) {
goto exit;
@@ -650,11 +635,6 @@ sys_mdebug(PyObject *module, PyObject *arg)
PyObject *return_value = NULL;
int flag;
- if (PyFloat_Check(arg)) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
flag = _PyLong_AsInt(arg);
if (flag == -1 && PyErr_Occurred()) {
goto exit;
@@ -790,11 +770,6 @@ sys__getframe(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (nargs < 1) {
goto skip_optional;
}
- if (PyFloat_Check(args[0])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
depth = _PyLong_AsInt(args[0]);
if (depth == -1 && PyErr_Occurred()) {
goto exit;
@@ -970,4 +945,4 @@ sys_getandroidapilevel(PyObject *module, PyObject *Py_UNUSED(ignored))
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
-/*[clinic end generated code: output=39eb34a01fb9a919 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=87baa3357293ea65 input=a9049054013a1b77]*/
diff --git a/Python/clinic/traceback.c.h b/Python/clinic/traceback.c.h
index 04daf2a..404a0c4 100644
--- a/Python/clinic/traceback.c.h
+++ b/Python/clinic/traceback.c.h
@@ -36,20 +36,10 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
goto exit;
}
tb_frame = (PyFrameObject *)fastargs[1];
- if (PyFloat_Check(fastargs[2])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
tb_lasti = _PyLong_AsInt(fastargs[2]);
if (tb_lasti == -1 && PyErr_Occurred()) {
goto exit;
}
- if (PyFloat_Check(fastargs[3])) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- goto exit;
- }
tb_lineno = _PyLong_AsInt(fastargs[3]);
if (tb_lineno == -1 && PyErr_Occurred()) {
goto exit;
@@ -59,4 +49,4 @@ tb_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=3def6c06248feed8 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=403778d7af5ebef9 input=a9049054013a1b77]*/
diff --git a/Python/getargs.c b/Python/getargs.c
index 7742428..63afae2 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -643,22 +643,6 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
#define CONV_UNICODE "(unicode conversion error)"
-/* Explicitly check for float arguments when integers are expected.
- Return 1 for error, 0 if ok.
- XXX Should be removed after the end of the deprecation period in
- _PyLong_FromNbIndexOrNbInt. */
-static int
-float_argument_error(PyObject *arg)
-{
- if (PyFloat_Check(arg)) {
- PyErr_SetString(PyExc_TypeError,
- "integer argument expected, got float" );
- return 1;
- }
- else
- return 0;
-}
-
/* Convert a non-tuple argument. Return NULL if conversion went OK,
or a string with a message describing the failure. The message is
formatted as "must be <desired type>, not <actual type>".
@@ -704,10 +688,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'b': { /* unsigned byte -- very short int */
char *p = va_arg(*p_va, char *);
- long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsLong(arg);
+ long ival = PyLong_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else if (ival < 0) {
@@ -728,11 +709,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'B': {/* byte sized bitfield - both signed and unsigned
values allowed */
char *p = va_arg(*p_va, char *);
- long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsUnsignedLongMask(arg);
- if (ival == -1 && PyErr_Occurred())
+ unsigned long ival = PyLong_AsUnsignedLongMask(arg);
+ if (ival == (unsigned long)-1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else
*p = (unsigned char) ival;
@@ -741,10 +719,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'h': {/* signed short int */
short *p = va_arg(*p_va, short *);
- long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsLong(arg);
+ long ival = PyLong_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else if (ival < SHRT_MIN) {
@@ -765,11 +740,8 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'H': { /* short int sized bitfield, both signed and
unsigned allowed */
unsigned short *p = va_arg(*p_va, unsigned short *);
- long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsUnsignedLongMask(arg);
- if (ival == -1 && PyErr_Occurred())
+ unsigned long ival = PyLong_AsUnsignedLongMask(arg);
+ if (ival == (unsigned long)-1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else
*p = (unsigned short) ival;
@@ -778,10 +750,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'i': {/* signed int */
int *p = va_arg(*p_va, int *);
- long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsLong(arg);
+ long ival = PyLong_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else if (ival > INT_MAX) {
@@ -802,14 +771,11 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'I': { /* int sized bitfield, both signed and
unsigned allowed */
unsigned int *p = va_arg(*p_va, unsigned int *);
- unsigned int ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = (unsigned int)PyLong_AsUnsignedLongMask(arg);
- if (ival == (unsigned int)-1 && PyErr_Occurred())
+ unsigned long ival = PyLong_AsUnsignedLongMask(arg);
+ if (ival == (unsigned long)-1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else
- *p = ival;
+ *p = (unsigned int) ival;
break;
}
@@ -818,8 +784,6 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
PyObject *iobj;
Py_ssize_t *p = va_arg(*p_va, Py_ssize_t *);
Py_ssize_t ival = -1;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
iobj = PyNumber_Index(arg);
if (iobj != NULL) {
ival = PyLong_AsSsize_t(iobj);
@@ -832,10 +796,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
}
case 'l': {/* long int */
long *p = va_arg(*p_va, long *);
- long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsLong(arg);
+ long ival = PyLong_AsLong(arg);
if (ival == -1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else
@@ -856,10 +817,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
case 'L': {/* long long */
long long *p = va_arg( *p_va, long long * );
- long long ival;
- if (float_argument_error(arg))
- RETURN_ERR_OCCURRED;
- ival = PyLong_AsLongLong(arg);
+ long long ival = PyLong_AsLongLong(arg);
if (ival == (long long)-1 && PyErr_Occurred())
RETURN_ERR_OCCURRED;
else