Skip to content

gh-109523: Reading text from a non-blocking stream with read may now raise a BlockingIOError if the operation cannot immediately return bytes. #122933

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

Merged
merged 22 commits into from
Dec 2, 2024

Conversation

giosiragusa
Copy link
Contributor

@giosiragusa giosiragusa commented Aug 12, 2024

  • Updated _io_TextIOWrapper_read_impl to raise a BlockingIOError when read() does not return bytes.
  • Introduced test_read_non_blocking to ensure that a BlockingIOError is raised when attempting to read from a non-blocking pipe with no data using os.pipe().

- Introduced `test_read_non_blocking` to ensure proper handling of non-blocking reads using `os.pipe()`.
- The test verifies that a `BlockingIOError` is raised when attempting to read from a non-blocking pipe with no data.
- Updated code to raise `BlockingIOError` with a specific message when `read()` does not return bytes.
@bedevere-app
Copy link

bedevere-app bot commented Aug 12, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@giosiragusa giosiragusa marked this pull request as ready for review August 14, 2024 00:12
Copy link
Contributor

@cmaloney cmaloney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code in _pyio's implementation of TextIO should ideally be changed in this PR as well so the two main implementations stay in sync (I think, in specific the code around https://github.com/python/cpython/blob/main/Lib/_pyio.py#L2288-L2293, when updating the test to use self.io.open the test I think will fail on PyIO which should help validate where it should go to match behavior)

Definitely liking the direction, looking forward to the next iteration

…dling of BlockingIOError in non-blocking I/O scenarios
…) to ensure the test runs under both _io and _pyio implementations. Also, explicitly specified 'rt' mode in the open() call for clarity, as the test is focused on TextIO behavior.
…n `buffer.read()` returns zero bytes.

- Fix double backticks in the documentation.
Copy link
Contributor

@cmaloney cmaloney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think all the code is correct. I have some personal stylistic nitpicks (How I program / what I'd match doesn't match what you did, but I don't have any strong argument to leave or change, take them or leave them as you wish). Think this needs a more experienced Python reviewer than me at this point.

Thanks a lot for the improvements!

…IOError change

Revised the NEWS entry in `MISC/NEWS.d/next/C_API` to specify that the recent 
change affecting the `BlockingIOError` now applies to both `_io.TextIOWrapper.read()` 
and `_pyio.TextIOWrapper.read()`.
- Adapted documentation to reflect common Python style practices.
- Refactored code to use a clearer variable name.
@giosiragusa giosiragusa changed the title gh-109523: In _io_TextIOWrapper_read_impl, raise BlockingIOError when read() from a non-blocking pipe does not return bytes. gh-109523: Reading text from a non-blocking stream with read may now raise a :exc:BlockingIOError if the operation cannot immediately return bytes. Aug 22, 2024
@giosiragusa giosiragusa changed the title gh-109523: Reading text from a non-blocking stream with read may now raise a :exc:BlockingIOError if the operation cannot immediately return bytes. gh-109523: Reading text from a non-blocking stream with read may now raise a BlockingIOError if the operation cannot immediately return bytes. Aug 22, 2024
@giosiragusa
Copy link
Contributor Author

Just dropping a friendly ping here. This pull request is in good shape and has undergone intensive review. Could a maintainer kindly take a look for final review and, if everything looks good, consider merging it?

@picnixz
Copy link
Member

picnixz commented Nov 27, 2024

cc @serhiy-storchaka

@giosiragusa
Copy link
Contributor Author

Also a trivial question from my side. Would this change qualify for an entry in Misc/ACKS? I'd be happy to add it if appropriate.

@picnixz
Copy link
Member

picnixz commented Nov 27, 2024

Simce it's a user facing change I'd say it warrants both a NEWS and a What's New entry to be on the safe side.

You can add yourself to ACKS I think (sorry I only read the Misc part and not the file...). Technically, every contributor is free to add themselves there (or am I wrong? I know I've never added myself due to laziness).

@giosiragusa
Copy link
Contributor Author

Simce it's a user facing change I'd say it warrants both a NEWS and a What's New entry to be on the safe side.

You can add yourself to ACKS I think (sorry I only read the Misc part and not the file...). Technically, every contributor is free to add themselves there (or am I wrong? I know I've never added myself due to laziness).

Thanks for the feedback.
I was referring to the "Crediting" section in here: https://devguide.python.org/getting-started/pull-request-lifecycle/
Since this is my first pull request I was not sure how to proceed.

I have the news entry, but I'm not sure how to handle the "What's New entry". How am I supposed to write one?

@picnixz
Copy link
Member

picnixz commented Nov 28, 2024

Look at the 3.14.rst file for example. The What's New entry should looks like

io
--

* Blabla
  (Contributed by YOU in :gh:`ISSUE_NUMBER`.)

The blabla text is usually the same as the one in the blurb.
You can look at how previous features were documented. I'll review any style issue afterwards.

@giosiragusa
Copy link
Contributor Author

Look at the 3.14.rst file for example. The What's New entry should looks like

io
--

* Blabla
  (Contributed by YOU in :gh:`ISSUE_NUMBER`.)

The blabla text is usually the same as the one in the blurb. You can look at how previous features were documented. I'll review any style issue afterwards.

Hi Benedikt,
I'm still unsure which file name should I use?

Doc/wathsnew/3.X.rst
or
Doc/whatsnew/next.rts?

@picnixz
Copy link
Member

picnixz commented Nov 29, 2024

The 3.14.rst file. The next.rst file is for the full changelog and is managed automatically.

Added entry in ACKS.
Fix missing indents and other syntax issues.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@encukou encukou merged commit 31f16e4 into python:main Dec 2, 2024
41 checks passed
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
ebonnal pushed a commit to ebonnal/cpython that referenced this pull request Jan 12, 2025
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.

6 participants