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
This is a follow-up to bpo-13532 which fixed problems with IDLE's sys.stdout and sys.stderr implementation.
Presently, sys.stdin has a write method, but does not raise "io.UnsupportedOperation: not writable" when passed a string. Instead, it writes to the IDLE shell.
To me, this is part of bpo-15319. sys.stdin is broken in being writable but not readable. Unwrapping is just the first, trivial step to fixing it. So I think we should close this in favor of the other.
Serhiy: can you please explicitly list what issues your patch fixes?
I can think of many *more* issues that your patch doesn't fix, e.g. sys.stdin.read(sys) and sys.stdout.read().
I'm quite opposed to monkey-patching, so I won't commit any patch that involves monkey-patching (i.e. _checked_text_writer). I'm also unsure what problem this change to monkey-patching solves: I believe the current code is fine in this respect as it stands.
Before you grow the patch to add many more lines of code, please try to stick to the "one issue at a time" principle. As a guideline: if you need to write additional lines of code, it's a separate issue.
loewis commented on Jul 11, 2012
loewismannequin
Mannequin
More actions
As an additional note: the change to monkey-patching breaks the test
Serhiy: can you please explicitly list what issues your patch fixes?
bpo-12967. And sys.std* in IDLE lacks other common sys.std* methods and
attributes.
I can think of many *more* issues that your patch doesn't fix, e.g. sys.stdin.read(sys) and sys.stdout.read().
sys.stdin.read(sys) and sys.stdout.read() should not work.
I'm quite opposed to monkey-patching, so I won't commit any patch that involves monkey-patching (i.e. _checked_text_writer). I'm also unsure what problem this change to monkey-patching solves: I believe the current code is fine in this respect as it stands.
I introduced _checked_text_writer, because the implementation of
_RPCFile was broken (I wrote this patch last evening and debug it this
morning). In addition, _RPCFile is a wrapper around RPCFile, which
itself is a wrapper. There are too many layers for me. If you are sure
that the current implementation of _RPCFile is correct, it is not
necessary.
Before you grow the patch to add many more lines of code, please try to stick to the "one issue at a time" principle.
In IDLE sys.std* bad mimic text streams -- this is one issue.
"implements textio badly" is *not* a well-defined issue.
First it is a personal judgement: some think it's really bad, some think it's quite ok.
More importantly, such issue has no clear success criterion: how do we know we are done - can we hope to EVER close such an issue? No, because somebody might still find bad behavior. An issue absolutely needs anobjective test to determine whether it is resolved, and to reproduce it, this is not negotiable. "it behaves badly" provides no test.
In any case,this issue is about sys.stdin being writable.
In any case,this issue is about sys.stdin being writable.
I already got confused with all these closing/reopening/renaming of
issues and floating code. Should I open my own issue even if it
duplicates and supersedes some other?
Any objection to checking in my patch?
It does not fixes the issue. sys.stdin.writelines does not raise
exception.
Inheritance input file from output file looks very strange.
_RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
PyShell.stdin.
loewis commented on Jul 11, 2012
loewismannequin
Mannequin
More actions
I already got confused with all these closing/reopening/renaming of
issues and floating code. Should I open my own issue even if it
duplicates and supersedes some other?
I personally think it would be best if these issues where closed
*first*, and only then you submit a patch to fix any remaining issues.
> Any objection to checking in my patch?
It does not fixes the issue. sys.stdin.writelines does not raise
exception.
Ah. See blockfiles-3.diff then.
Inheritance input file from output file looks very strange.
Where do you see that? In my patch, _RPCInputFile inherits from
_RPCFile, which is neither output nor input. Instead, _RPCOutputFile
also inherits from _RPCFile.
_RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
PyShell.stdin.
It is necessary, as rpc will not communicate the exceptions properly.
serwy commented on Jul 12, 2012
serwymannequin
MannequinAuthor
More actions
I tested blockfile-3.diff against the latest code in the repository.
sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...
The attached blockfile-4.diff incorporates blockfile-3 and creates a decorator in _RPCFile to ensure the argument is a string and applies it to the _RPCInputFile and _RPCOutputFile write methods.
A simpler alternative would be duplicating the string check code in _RPCInputFile before the raise statement.
Well, I have no objections. Patch fixes this issue.
Where do you see that? In my patch, _RPCInputFile inherits from
_RPCFile, which is neither output nor input. Instead, _RPCOutputFile
also inherits from _RPCFile.
I made a mistake. I mean PseudoInputFile, but it just monkey-patched.
> _RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
> PyShell.stdin.
It is necessary, as rpc will not communicate the exceptions properly.
Yes, this is yet another issue. Rpc not communicates properly only
OSError. Remove "except socket.error: raise" in SocketIO.localcall in Lib/idlelib/rpc.py and io.UnsupportedOperation will transparently
transfered.
sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...
It's not a bug. sys.stdin.write raises io.UnsupportedOperation in
standard interpreter.
> sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...
It's not a bug. sys.stdin.write raises io.UnsupportedOperation in
standard interpreter.
Here's what I get from the standard interpreter:
Python 3.3.0b1 (default:4752fafb579d, Jul 11 2012, 22:05:03)
[GCC 4.5.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdin.write(123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be str, not int
>>>
Activity
serwy commentedon Jul 10, 2012
This is a follow-up to bpo-13532 which fixed problems with IDLE's sys.stdout and sys.stderr implementation.
Presently, sys.stdin has a write method, but does not raise "io.UnsupportedOperation: not writable" when passed a string. Instead, it writes to the IDLE shell.
terryjreedy commentedon Jul 11, 2012
To me, this is part of bpo-15319. sys.stdin is broken in being writable but not readable. Unwrapping is just the first, trivial step to fixing it. So I think we should close this in favor of the other.
serwy commentedon Jul 11, 2012
I agree. I'll close it.
loewis commentedon Jul 11, 2012
It's *clearly* not a duplicate. While bpo-15319 is fixed, this issue remains - so it can't possibly be a duplicate.
loewis commentedon Jul 11, 2012
I propose the attached patch to block write() calls.
loewis commentedon Jul 11, 2012
Revised
serhiy-storchaka commentedon Jul 11, 2012
sys.std* streams have many other issues.
>>> sys.stdin.readable() Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> sys.stdin.readable() AttributeError: readable >>> sys.stdout.writable() Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> sys.stdout.writable() AttributeError: writable >>> sys.stdout.newlines Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> sys.stdout.newlines AttributeError: newlines >>> sys.stdin.read(1) Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> sys.stdin.read(1) AttributeError: readAnd some other.
Here is a patch that fixes almost all IDLE sys.std* issues.
serhiy-storchaka commentedon Jul 11, 2012
Added getvar method to PyShell.console.
loewis commentedon Jul 11, 2012
Serhiy: can you please explicitly list what issues your patch fixes?
I can think of many *more* issues that your patch doesn't fix, e.g. sys.stdin.read(sys) and sys.stdout.read().
I'm quite opposed to monkey-patching, so I won't commit any patch that involves monkey-patching (i.e. _checked_text_writer). I'm also unsure what problem this change to monkey-patching solves: I believe the current code is fine in this respect as it stands.
Before you grow the patch to add many more lines of code, please try to stick to the "one issue at a time" principle. As a guideline: if you need to write additional lines of code, it's a separate issue.
loewis commentedon Jul 11, 2012
As an additional note: the change to monkey-patching breaks the test
which currently succeeds.
serhiy-storchaka commentedon Jul 11, 2012
bpo-12967. And sys.std* in IDLE lacks other common sys.std* methods and
attributes.
sys.stdin.read(sys) and sys.stdout.read() should not work.
I introduced _checked_text_writer, because the implementation of
_RPCFile was broken (I wrote this patch last evening and debug it this
morning). In addition, _RPCFile is a wrapper around RPCFile, which
itself is a wrapper. There are too many layers for me. If you are sure
that the current implementation of _RPCFile is correct, it is not
necessary.
In IDLE sys.std* bad mimic text streams -- this is one issue.
1 remaining item
serhiy-storchaka commentedon Jul 11, 2012
bpo-9290 also has relation to this.
serhiy-storchaka commentedon Jul 11, 2012
bpo-7163 is another PseudoFile-related issue.
loewis commentedon Jul 11, 2012
"implements textio badly" is *not* a well-defined issue.
First it is a personal judgement: some think it's really bad, some think it's quite ok.
More importantly, such issue has no clear success criterion: how do we know we are done - can we hope to EVER close such an issue? No, because somebody might still find bad behavior. An issue absolutely needs anobjective test to determine whether it is resolved, and to reproduce it, this is not negotiable. "it behaves badly" provides no test.
In any case,this issue is about sys.stdin being writable.
Any objection to checking in my patch?
serhiy-storchaka commentedon Jul 11, 2012
I already got confused with all these closing/reopening/renaming of
issues and floating code. Should I open my own issue even if it
duplicates and supersedes some other?
It does not fixes the issue. sys.stdin.writelines does not raise
exception.
Inheritance input file from output file looks very strange.
_RPCInputFile unnecessary, if redirect stdin not on PyShell self, but on
PyShell.stdin.
loewis commentedon Jul 11, 2012
I personally think it would be best if these issues where closed
*first*, and only then you submit a patch to fix any remaining issues.
Ah. See blockfiles-3.diff then.
Where do you see that? In my patch, _RPCInputFile inherits from
_RPCFile, which is neither output nor input. Instead, _RPCOutputFile
also inherits from _RPCFile.
It is necessary, as rpc will not communicate the exceptions properly.
serwy commentedon Jul 12, 2012
I tested blockfile-3.diff against the latest code in the repository.
sys.stdin.write returns the wrong error message when passed a non-string. Presently it returns io.UnsupportedOperation instead of TypeError: must be str, not ...
The attached blockfile-4.diff incorporates blockfile-3 and creates a decorator in _RPCFile to ensure the argument is a string and applies it to the _RPCInputFile and _RPCOutputFile write methods.
A simpler alternative would be duplicating the string check code in _RPCInputFile before the raise statement.
serhiy-storchaka commentedon Jul 12, 2012
Well, I have no objections. Patch fixes this issue.
I made a mistake. I mean PseudoInputFile, but it just monkey-patched.
Yes, this is yet another issue. Rpc not communicates properly only
OSError. Remove "except socket.error: raise" in SocketIO.localcall in
Lib/idlelib/rpc.py and io.UnsupportedOperation will transparently
transfered.
serhiy-storchaka commentedon Jul 12, 2012
It's not a bug. sys.stdin.write raises io.UnsupportedOperation in
standard interpreter.
serwy commentedon Jul 12, 2012
On 07/12/2012 04:13 AM, Serhiy Storchaka wrote:
Here's what I get from the standard interpreter:
Python 3.3.0b1 (default:4752fafb579d, Jul 11 2012, 22:05:03) [GCC 4.5.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.stdin.write(123) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: must be str, not int >>>serhiy-storchaka commentedon Jul 12, 2012
>>> sys.stdin.write('qwe') Traceback (most recent call last): File "<stdin>", line 1, in <module> io.UnsupportedOperation: not writableserwy commentedon Jul 12, 2012
>>>> sys.stdin.write('qwe') > Traceback (most recent call last): > File "<stdin>", line 1, in<module> > io.UnsupportedOperation: not writable > >I'm passing a number, *not* a string.
python-dev commentedon Jul 25, 2012
New changeset a82fd35e28be by Martin v. Löwis in branch '3.2':
Issue bpo-15318: Prevent writing to sys.stdin.
http://hg.python.org/cpython/rev/a82fd35e28be
python-dev commentedon Jul 25, 2012
New changeset fa7d4ecc6357 by Martin v. Löwis in branch '2.7':
Issue bpo-15318: Prevent writing to sys.stdin.
http://hg.python.org/cpython/rev/fa7d4ecc6357