Davide Rizzo <sor...@gmail.com> added the comment:

The bugs seems not to be limited to the REPL.

# Python 2.6 with readline on Mac OS X
$ python -c "raw_input()"
^Z
[1]+  Stopped                 python -c "raw_input()"
$ fg
python -c "raw_input()"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
EOFError


# Python 3.1 on Debian Linux
$ python3.1 -c "print(input())"
^Z
[1]+  Stopped                 python3.1 -c "print(input())"
$ fg
python3.1 -c "print(input())"
hello
hello


# Python 3.3(267578b2422d) without readline, OS X (I've put two extra printfs 
around fgets in myreadline.c)
$ ./python.exe -c "print(input())"
Entering fgets
^Z
[1]+  Stopped                 ./python.exe -c "print(input())"
$ fg
./python.exe -c "print(input())"
fgets returned 0
Traceback (most recent call last):
  File "<string>", line 1, in <module>
EOFError
[36537 refs]


# same as before with Charles-Francois patch applied
$ ./python.exe -c "print(input())"
^Z
[1]+  Stopped                 ./python.exe -c "print(input())"
$ fg
./python.exe -c "print(input())"
hello
hello
[36538 refs]


Some remarks here:
1) the bug is in all tested versions running on OS X, and the patch does fix it.

2) I tested with and without GNU readline and input()'s behavior doesn't change 
when running with python -c (i.e. it uses myreadline.c instead of GNU 
readline). Though, if run interactively, input() uses readline.
Isn't input() supposed to use readline whenever reading from a tty, not only if 
called from the REPL? Or even if it were to fallback, shouldn't that be on 
TextIOWrapper(sys.stdin).readline()?

3) io module seems to be doing it right already. sys.stdin.read() raises an 
IOError (not an EOFError as input() incorrectly does, this is acceptable as a 
platform quirk) when interrupted, while sys.stdin.readline() handles the 
interruption without complaining at all.
Maybe myreadline.c is too old and wants to be replaced (or backed) by io in 3.3?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11650>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to