This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE suppresses sys.stdout.write() return value
Type: behavior Stage:
Components: IDLE Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, loewis, python-dev, roger.serwy, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2009-10-17 22:38 by terry.reedy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue7163.patch roger.serwy, 2012-03-12 02:11 review
Messages (10)
msg94191 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-10-17 22:38
IDLE
Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit
(Intel)] on win32

>>> import sys
>>> sys.stdout.write('abc')
abc

whereas

Command Window
Python 3.1 (r31:73574, Jun 26 2009, 20:21:35) [MSC v.1500 32 bit
(Intel)] on win32

>>> import sys
>>> sys.stdout.write('abc')
abc3
msg102661 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2010-04-09 00:52
sys.stdout is a idlelib.rpc.RPCProxy in IDLE. It calls Idlelib.PyShell.PseudoFile.write ->
.PyShell.write -> 
.OutputWindow.OutputWindow.write ->
.Percolator.Percolator.insert ->
...

I suppose we could mimic the return value patching PseudoFile.write (for educational purposes?).
msg149360 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-12-12 22:31
Re-verified on 3.2.2, win 7.
#13532 shows a worse problem with sys.stdout.write on the above.
msg149369 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2011-12-13 00:57
If you add "return len(s)" to PseudoFile::write in PyShell.py, then it will work. However, this approach may not be "the right thing to do."
msg155431 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-03-12 02:11
Attached is a patch against 3.3 to return the count.
msg165293 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-07-12 09:44
Reply to Roger's emailed answer to my Rietveld comment.

> On 07/11/2012 11:10 AM, storchaka@gmail.com wrote:
> > http://bugs.python.org/review/7163/diff/4367/Lib/idlelib/OutputWindow.py
> > File Lib/idlelib/OutputWindow.py (right):
> >
> > http://bugs.python.org/review/7163/diff/4367/Lib/idlelib/OutputWindow.py#newcode43
> > Lib/idlelib/OutputWindow.py:43: return len(s)
> > write() should return count of bytes if argument is bytes.
> Only strings should be passed into the write method in 3.3. The  code 
> for decoding bytes is a historical artifact that should be removed. You 
> can witness this evolution by using hgtk datamine.

We can ask the author.

Martin, why OutputWindow.write accepts bytes in a724279fc931? Should it be deleted if it is deprecated artifact or should OutputWindow.write return bytes count for bytes if it will return character count for string?

> On 2.7, byte counts (AFAIK)  are not returned for sys.stdout.write.

On Python2 sys.stdout.write does not returns any count.
msg165299 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-12 11:47
> We can ask the author.
>
> Martin, why OutputWindow.write accepts bytes in a724279fc931?

That change was to add support for str8, a type that no longer exists.

> Should it be deleted if it is deprecated artifact or should  
> OutputWindow.write return bytes count for bytes if it will return  
> character count for string?

The general design guideline apparently is that sys.stdout in IDLE
should work the same as the interactive shell.

Since the interactive shell doesn't support bytes (and gives a TypeError),
so should IDLE.
msg165300 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-07-12 12:30
> That change was to add support for str8, a type that no longer exists.

str8 was renamed to bytes in 0d462d789b18.

> The general design guideline apparently is that sys.stdout in IDLE
> should work the same as the interactive shell.
> 
> Since the interactive shell doesn't support bytes (and gives a TypeError),
> so should IDLE.

Now OutputWindow is not sys.stdout and sys.stdout has own argument
check. If someone uses OutputWindow directly (not sys.stdout) as output
_binary_ file (because OutputWindow supports binary output), then he
would be expected that write will return the number of written bytes.
Can we break those expectations?
msg166376 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-07-25 09:33
New changeset f72965374b2a by Martin v. Löwis in branch '3.2':
Issue #7163: Propagate return value of sys.stdout.write.
http://hg.python.org/cpython/rev/f72965374b2a
msg166377 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-07-25 09:33
Thanks for the patch!
History
Date User Action Args
2022-04-11 14:56:54adminsetgithub: 51412
2012-07-25 09:33:55loewissetstatus: open -> closed
resolution: fixed
messages: + msg166377
2012-07-25 09:33:14python-devsetnosy: + python-dev
messages: + msg166376
2012-07-12 12:30:34serhiy.storchakasetmessages: + msg165300
2012-07-12 11:47:35loewissetmessages: + msg165299
2012-07-12 09:44:26serhiy.storchakasetnosy: + loewis
messages: + msg165293
2012-07-11 16:11:28serhiy.storchakasetnosy: + serhiy.storchaka
2012-03-12 02:11:59roger.serwysetfiles: + issue7163.patch
keywords: + patch
messages: + msg155431
2011-12-13 00:57:23roger.serwysetnosy: + roger.serwy
messages: + msg149369
2011-12-12 22:31:29terry.reedysetmessages: + msg149360
versions: + Python 3.3, - Python 3.1
2010-04-09 00:52:51ajaksu2setpriority: normal

nosy: + ajaksu2
messages: + msg102661

type: behavior
2009-10-17 22:38:01terry.reedycreate