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

sys standard streams can be None #11778

Open
mondeja opened this issue Apr 17, 2024 · 1 comment · May be fixed by #11826
Open

sys standard streams can be None #11778

mondeja opened this issue Apr 17, 2024 · 1 comment · May be fixed by #11826
Labels
topic: io I/O related issues

Comments

@mondeja
Copy link
Contributor

mondeja commented Apr 17, 2024

Bug Report

File descriptors could be None at Python initialization.

To Reproduce (unix)

$ python3 -c 'import sys;print(sys.stdin)' 0>&- 
None
$ python3 -c 'import sys;print(sys.stderr)' 2>&-
None
$ python3 -c 'import sys;print(sys.stdout, file=sys.stderr)' 1>&-
None
$ python3 -c 'import sys;print(sys.__stdin__)' 0>&-
None
$ python3 -c 'import sys;print(sys.__stderr__)' 2>&-
None
$ python3 -c 'import sys;print(sys.__stdout__, file=sys.stderr)' 1>&-
None

Expected Behavior

I want the real possible types of the previous sys.std* variables.

Actual Behavior

https://github.com/python/mypy/blob/df35dcf020b3b03a8e3280edf8ada8c6ad8e0da5/mypy/typeshed/stdlib/sys/__init__.pyi#L71-L80

Your Environment

N/A

@mondeja mondeja changed the title File descriptors could be None sys standard streams can be None Apr 17, 2024
@JelleZijlstra JelleZijlstra transferred this issue from python/mypy Apr 17, 2024
@AlexWaygood AlexWaygood added the topic: io I/O related issues label Apr 17, 2024
@Akuli
Copy link
Collaborator

Akuli commented Apr 18, 2024

There is also another, perhaps more common way for sys.stdin, sys.stdout and sys.stderr to be None. On Windows, if you run a file with pythonw.exe (by naming it foo.pyw and double-clicking it, for example), it will run without a command prompt window, and with sys.std* files set to None.

This is how GUI apps usually run on Windows. For code that should work in these GUI apps, you need print(foo, file=sys.stderr) instead of sys.stderr.write(foo), or explicit None checks.

srittau added a commit to srittau/typeshed that referenced this issue Apr 24, 2024
@srittau srittau linked a pull request Apr 24, 2024 that will close this issue
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.

3 participants