Skip to content

Let patched sys.stderr.write() and sys.stdout.write() return number of written bytes#134

Merged
albertosottile merged 1 commit into
py2exe:masterfrom
manueljacob:stdio-write-return_value
Jul 3, 2022
Merged

Let patched sys.stderr.write() and sys.stdout.write() return number of written bytes#134
albertosottile merged 1 commit into
py2exe:masterfrom
manueljacob:stdio-write-return_value

Conversation

@manueljacob

Copy link
Copy Markdown
Contributor

On Python 3, a file’s write() method is expected to return the number of
written bytes.

It’s a bit unclear what do when no data is actually written (log file
couldn’t be opened in case of stderr or data is deliberately ignored in
case of stdout). I think it’s reasonable in this case to pretend that
all passed data was written. If we returned 0, a caller which calls
write() repeatedly until all data has been written will end up in an
infinite loop.

@albertosottile

Copy link
Copy Markdown
Member

This LGTM, thanks for this contribution. Any idea why the CI workflow was not triggered? I was expecting an approval request, but I cannot even see that...

@manueljacob manueljacob force-pushed the stdio-write-return_value branch from 9da5416 to 5965646 Compare July 2, 2022 13:36
@manueljacob

Copy link
Copy Markdown
Contributor Author

The “workflow awaiting approval” went missing. Now, after force-push, it appeared again. Do you get the approval request now?

@manueljacob

Copy link
Copy Markdown
Contributor Author

Note: the tests will fail on master when you retrigger CI.

@albertosottile

Copy link
Copy Markdown
Member

I fixed the CI on master, could you rebase?

…f written bytes

On Python 3, a file’s write() method is expected to return the number of
written bytes.

It’s a bit unclear what do when no data is actually written (log file
couldn’t be opened in case of stderr or data is deliberately ignored in
case of stdout). I think it’s reasonable in this case to pretend that
all passed data was written. If we returned 0, a caller which calls
write() repeatedly until all data has been written will end up in an
infinite loop.
@manueljacob manueljacob force-pushed the stdio-write-return_value branch from 5965646 to 7c8dfb7 Compare July 3, 2022 01:10
@albertosottile albertosottile merged commit 73c3afa into py2exe:master Jul 3, 2022
@albertosottile

Copy link
Copy Markdown
Member

Thank you for this contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants