Skip to content

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
@github-actions
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
@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

Development

Successfully merging this pull request may close these issues.

Shouldn't FileIO indicate None as possible return of read/write? file_digest.file_digest signature is overly strict

2 participants