Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
87bd9a81
Commit
87bd9a81
authored
Feb 04, 2003
by
Neil Schemenauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If a float is passed where a int is expected, issue a DeprecationWarning
instead of raising a TypeError. Closes #660144 (again).
parent
373e29ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
15 deletions
+29
-15
Misc/NEWS
Misc/NEWS
+4
-3
Python/getargs.c
Python/getargs.c
+25
-12
No files found.
Misc/NEWS
View file @
87bd9a81
...
...
@@ -223,9 +223,10 @@ Build
C
API
-----
-
The
PyArg_Parse
functions
now
raise
a
TypeError
instead
of
truncating
float
arguments
if
an
integer
is
specified
(
this
affects
the
'b'
,
'B'
,
'h'
,
'H'
,
'i'
,
and
'l'
codes
).
-
The
PyArg_Parse
functions
now
issue
a
DeprecationWarning
if
a
float
argument
is
provided
when
an
integer
is
specified
(
this
affects
the
'b'
,
'B'
,
'h'
,
'H'
,
'i'
,
and
'l'
codes
).
Future
versions
of
Python
will
raise
a
TypeError
.
New
platforms
...
...
Python/getargs.c
View file @
87bd9a81
...
...
@@ -387,6 +387,19 @@ converterr(char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
#define CONV_UNICODE "(unicode conversion error)"
/* explicitly check for float arguments when integers are expected. For now
* signal a warning. Returns true if an exception was raised. */
static
int
float_argument_error
(
PyObject
*
arg
)
{
if
(
PyFloat_Check
(
arg
)
&&
PyErr_Warn
(
PyExc_DeprecationWarning
,
"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>".
...
...
@@ -409,8 +422,8 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf,
case
'b'
:
{
/* unsigned byte -- very short int */
char
*
p
=
va_arg
(
*
p_va
,
char
*
);
long
ival
;
if
(
PyFloat_Check
(
arg
))
return
converterr
(
"integer"
,
arg
,
msgbuf
,
bufsize
)
;
if
(
float_argument_error
(
arg
))
return
NULL
;
ival
=
PyInt_AsLong
(
arg
);
if
(
ival
==
-
1
&&
PyErr_Occurred
())
return
converterr
(
"integer<b>"
,
arg
,
msgbuf
,
bufsize
);
...
...
@@ -433,8 +446,8 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf,
values allowed */
char
*
p
=
va_arg
(
*
p_va
,
char
*
);
long
ival
;
if
(
PyFloat_Check
(
arg
))
return
converterr
(
"integer"
,
arg
,
msgbuf
,
bufsize
)
;
if
(
float_argument_error
(
arg
))
return
NULL
;
ival
=
PyInt_AsLong
(
arg
);
if
(
ival
==
-
1
&&
PyErr_Occurred
())
return
converterr
(
"integer<b>"
,
arg
,
msgbuf
,
bufsize
);
...
...
@@ -456,8 +469,8 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf,
case
'h'
:
{
/* signed short int */
short
*
p
=
va_arg
(
*
p_va
,
short
*
);
long
ival
;
if
(
PyFloat_Check
(
arg
))
return
converterr
(
"integer"
,
arg
,
msgbuf
,
bufsize
)
;
if
(
float_argument_error
(
arg
))
return
NULL
;
ival
=
PyInt_AsLong
(
arg
);
if
(
ival
==
-
1
&&
PyErr_Occurred
())
return
converterr
(
"integer<h>"
,
arg
,
msgbuf
,
bufsize
);
...
...
@@ -480,8 +493,8 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf,
unsigned allowed */
unsigned
short
*
p
=
va_arg
(
*
p_va
,
unsigned
short
*
);
long
ival
;
if
(
PyFloat_Check
(
arg
))
return
converterr
(
"integer"
,
arg
,
msgbuf
,
bufsize
)
;
if
(
float_argument_error
(
arg
))
return
NULL
;
ival
=
PyInt_AsLong
(
arg
);
if
(
ival
==
-
1
&&
PyErr_Occurred
())
return
converterr
(
"integer<H>"
,
arg
,
msgbuf
,
bufsize
);
...
...
@@ -503,8 +516,8 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf,
case
'i'
:
{
/* signed int */
int
*
p
=
va_arg
(
*
p_va
,
int
*
);
long
ival
;
if
(
PyFloat_Check
(
arg
))
return
converterr
(
"integer"
,
arg
,
msgbuf
,
bufsize
)
;
if
(
float_argument_error
(
arg
))
return
NULL
;
ival
=
PyInt_AsLong
(
arg
);
if
(
ival
==
-
1
&&
PyErr_Occurred
())
return
converterr
(
"integer<i>"
,
arg
,
msgbuf
,
bufsize
);
...
...
@@ -526,8 +539,8 @@ convertsimple(PyObject *arg, char **p_format, va_list *p_va, char *msgbuf,
case
'l'
:
{
/* long int */
long
*
p
=
va_arg
(
*
p_va
,
long
*
);
long
ival
;
if
(
PyFloat_Check
(
arg
))
return
converterr
(
"integer"
,
arg
,
msgbuf
,
bufsize
)
;
if
(
float_argument_error
(
arg
))
return
NULL
;
ival
=
PyInt_AsLong
(
arg
);
if
(
ival
==
-
1
&&
PyErr_Occurred
())
return
converterr
(
"integer<l>"
,
arg
,
msgbuf
,
bufsize
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment