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
WinXP, 3.0b2
>>>f=open('somefile', 'r')
>>>f.readline(somefloat)
Traceback (most recent call last):
File "<pyshell#70>", line 1, in <module>
f.readline(1.0)
File "C:\Program Files\Python30\lib\io.py", line 1766, in readlinereturn line[:endpos]
TypeError: slice indices must be integers or None or have an __index__
method
At this point, any f.read or f.readline calls fail with a similar
TypeError. The error recovery seems incomplete. The same does *not*
happen with f.read(float). Recovery is complete and subsequent
f.read/f.readline calls work.
In 2.5, float size arg worked with a deprecation warning, so issue does
not arise. I presume same is true in 2.6.
This looks pretty simple to fix; I think a type check is missing
(actually several, there are at least two implementations in io.py).
In fact, the 2.6 version of io.py already has the necessary checks.
(But merging those forward is not 100% trivial since in 3.0 the 'long'
type doesn't exist.)
Activity
terryjreedy commentedon Aug 7, 2008
WinXP, 3.0b2 >>>f=open('somefile', 'r') >>>f.readline(somefloat) Traceback (most recent call last): File "<pyshell#70>", line 1, in <module> f.readline(1.0) File "C:\Program Files\Python30\lib\io.py", line 1766, in readline return line[:endpos] TypeError: slice indices must be integers or None or have an __index__ methodAt this point, any f.read or f.readline calls fail with a similar
TypeError. The error recovery seems incomplete. The same does *not*
happen with f.read(float). Recovery is complete and subsequent
f.read/f.readline calls work.
In 2.5, float size arg worked with a deprecation warning, so issue does
not arise. I presume same is true in 2.6.
gvanrossum commentedon Aug 7, 2008
Good catch!
This looks pretty simple to fix; I think a type check is missing
(actually several, there are at least two implementations in io.py).
In fact, the 2.6 version of io.py already has the necessary checks.
(But merging those forward is not 100% trivial since in 3.0 the 'long'
type doesn't exist.)
devdanzin commentedon Aug 27, 2008
Patch attached, suggested test below.
devdanzin commentedon Feb 8, 2009
Maybe this one should be in 3.0.1? Benchmarking the isinstance approach
against int() would be interesting.
The io-c branch doesn't have this bug, so 3.1 is OK :)
benjaminp commentedon Apr 24, 2009
Fixed in r71855