Skip to content
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

Change RawIOBase return types from None to MaybeNone #12686

Merged
merged 2 commits into from
Oct 2, 2024

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Sep 23, 2024

Closes: #12684
Closes: #12414

@srittau srittau changed the title FileIO.read and write can return None in non-blocking mode Change RawIOBase return types from None to MaybeNone Sep 23, 2024
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

mypy_primer (https://github.com/hauntsaninja/mypy_primer)
+ mypy_primer/utils.py:173: error: Unused "type: ignore" comment  [unused-ignore]

werkzeug (https://github.com/pallets/werkzeug)
- tests/test_wsgi.py:159: error: Argument 1 to "load" has incompatible type "LimitedStream"; expected "SupportsRead[str | bytes]"  [arg-type]
- tests/test_wsgi.py:159: note: Following member(s) of "LimitedStream" have conflicts:
- tests/test_wsgi.py:159: note:     Expected:
- tests/test_wsgi.py:159: note:         def read(self, int = ..., /) -> str | bytes
- tests/test_wsgi.py:159: note:     Got:
- tests/test_wsgi.py:159: note:         def read(self, int = ..., /) -> bytes | None

@srittau
Copy link
Collaborator Author

srittau commented Sep 23, 2024

Two fixed false positives according to primer.

@srittau srittau added the topic: io I/O related issues label Sep 23, 2024
@JelleZijlstra
Copy link
Member

How bad would it be if we did the type-safe thing here and used | None instead?

@srittau
Copy link
Collaborator Author

srittau commented Oct 2, 2024

#12414 is the main argument why we shouldn't use None. Also, the two fixed primer hits. In my experience, non-blocking I/O is a specialty feature that shouldn't need coding around. See also the discussion in python/cpython#122179, where there is even resistance against defensive coding around this in the stdlib.

@JelleZijlstra JelleZijlstra merged commit f266dc2 into python:main Oct 2, 2024
63 checks passed
@srittau srittau deleted the fileio branch October 2, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: io I/O related issues
Projects
None yet
2 participants