New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
file.readline: bad exception recovery #47771
Comments
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__
method At this point, any f.read or f.readline calls fail with a similar In 2.5, float size arg worked with a deprecation warning, so issue does |
Good catch! This looks pretty simple to fix; I think a type check is missing In fact, the 2.6 version of io.py already has the necessary checks. |
Patch attached, suggested test below. def test_readline():
for mode in ('r', 'rb', 'r+', 'r+b'):
f = open(__file__, mode)
try:
f.readline(0.1)
except TypeError:
tmp = f.readline()
f.close()
print('OK')
test_readline() |
Maybe this one should be in 3.0.1? Benchmarking the isinstance approach The io-c branch doesn't have this bug, so 3.1 is OK :) |
Fixed in r71855 |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: