You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PyArg_Parse* should raise TypeError for float parsed with integer format #49330
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/mdickinson'closed_at=<Date2010-01-01.19:30:02.485>created_at=<Date2009-01-27.12:23:56.157>labels= ['type-bug']
title='PyArg_Parse* should raise TypeError for float parsed with integer format'updated_at=<Date2010-01-01.19:30:02.484>user='https://github.com/mdickinson'
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.
Can we turn that DeprecationWarning into a TypeError for 2.7? (It's
already a TypeError in 3.x.) I'd like to see things like 'range(-0.3)'
and 'itertools.combinations(range(3), 5.1)' raise TypeError.
N.B. The relevant format codes in 2.7 include 'I' and 'n' in addition to
the six codes listed above.
Hmm. That's unfortunate: for argument type in 'bBHiIlkKn', an attempt to
pass a float results in a DeprecationWarning. For type 'L', there's no
DeprecationWarning, and the float is silently truncated. So for type 'L'
I guess we still have to go through a round of DeprecationWarning.
I'm not sure what 'h' does; there don't appear to be any tests for it,
currently.
Activity
mdickinson commentedon Jan 27, 2009
Since Python 2.3, PyArg_ParseTuple and friends give a DeprecationWarning
for floating-point arguments where integers are expected. From
http://www.python.org/download/releases/2.3/NEWS.txt:
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.
Can we turn that DeprecationWarning into a TypeError for 2.7? (It's
already a TypeError in 3.x.) I'd like to see things like 'range(-0.3)'
and 'itertools.combinations(range(3), 5.1)' raise TypeError.
N.B. The relevant format codes in 2.7 include 'I' and 'n' in addition to
the six codes listed above.
birkenfeld commentedon Sep 4, 2009
+1.
vstinner commentedon Sep 7, 2009
+10. It would fix the os.urandom(1.2) bug. On Linux, os.urandom() displays
the following warnings and then go into an unlimited loop...
/usr/lib/python2.5/os.py:734: DeprecationWarning: integer argument expected,
got float
bytes += read(_urandomfd, n - len(bytes))
read(1.2 - 1) ~> read(0.2) ~> read(0)...
Tolerate float as integers introduces "subtle" bugs like byte/unicode bugs...
pitrou commentedon Nov 19, 2009
+1 for a TypeError too.
pitrou commentedon Nov 20, 2009
I think this should be signalled on the mailing-list, by the way. I
expect everyone to agree of course :)
mdickinson commentedon Nov 20, 2009
Yes, checking with python-dev sounds sensible. I'll wait until there's
a working patch, though.
mdickinson commentedon Dec 20, 2009
Hmm. That's unfortunate: for argument type in 'bBHiIlkKn', an attempt to
pass a float results in a DeprecationWarning. For type 'L', there's no
DeprecationWarning, and the float is silently truncated. So for type 'L'
I guess we still have to go through a round of DeprecationWarning.
I'm not sure what 'h' does; there don't appear to be any tests for it,
currently.
mdickinson commentedon Dec 20, 2009
'h' also produces a DeprecationWarning; I just added the missing tests
for it in r76930 (trunk) and r76931 (py3k).
mdickinson commentedon Dec 21, 2009
Here's a patch that makes the DeprecationWarning a TypeError, and adds a
new DeprecationWarning for the 'L' format.
mdickinson commentedon Jan 1, 2010
Applied to trunk in r77218. The DeprecationWarning for the 'L' format
needs to be merged to py3k.
mdickinson commentedon Jan 1, 2010
Merged relevant bits to py3k in r77220.