Skip to content

Shouldn't FileIO indicate None as possible return of read/write? #12684

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

Closed
dcolascione opened this issue Sep 21, 2024 · 3 comments · Fixed by #12686
Closed

Shouldn't FileIO indicate None as possible return of read/write? #12684

dcolascione opened this issue Sep 21, 2024 · 3 comments · Fixed by #12686
Labels
topic: io I/O related issues

Comments

@dcolascione
Copy link

Typeshed currently has these declarations in io.pyi for FileIO.

    def write(self, b: ReadableBuffer, /) -> int: ...
    def read(self, size: int = -1, /) -> bytes: ...

Shouldn't these return int | None and bytes | None? A FileIO is non-blocking mode can return None from these methods, yes?

@dcolascione dcolascione changed the title Shouldn't FileIO indicate None for return of read/write? Shouldn't FileIO indicate None as possible return of read/write? Sep 21, 2024
@AlexWaygood AlexWaygood added the topic: io I/O related issues label Sep 21, 2024
@tomasr8
Copy link
Member

tomasr8 commented Sep 22, 2024

Looking at the code, both read and write return None when EAGAIN is raised so technically the return annotation should include None as well.

@srittau
Copy link
Collaborator

srittau commented Sep 23, 2024

For reference, this is similar to what has been discussed in https://discuss.python.org/t/handling-sys-stdin-read-in-non-blocking-mode/59633.

@srittau
Copy link
Collaborator

srittau commented Sep 23, 2024

Also related to #12414. PR: #12686

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 a pull request may close this issue.

4 participants