-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Merge {IO,Environment,Windows}Error into OSError for Python 3.3+ #1852
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
Conversation
stdlib/3/builtins.pyi
Outdated
if sys.version_info >= (3, 4): | ||
filename2 = ... # type: Union[str, bytes, None] | ||
if sys.platform == 'win32': | ||
winerror = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a good idea to put sys.platform
checks in? The winerror
attribute is missing entirely on non-Windows platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that makes sense.
Starting with Python 3.3, IOError, EnvironmentError and WindowsError are aliases for OSError, which has all the attributes. Also, tested on Python 3.6 that OSerror.filename/filename2 may be bytes and may also be None. Reference: * https://docs.python.org/3/library/exceptions.html#OSError * https://www.python.org/dev/peps/pep-3151/
Question for the maintainers: Can't we leave out the branch for Python < 3.3? README.md says that typeshed targets Python 2.7 and 3.3+. |
Yes, we don't care about 3.0-3.2. (We could also seriously consider dropping support for 3.3, since that has reached EOL.) |
Thanks! I got rid of the Python <3.3 check. It still fails a test in mypy code, which uses What's the correct fix in this case? Should I submit a PR to mypy to create a new variable in this context? Or should I revert the |
I created a PR for Mypy here: python/mypy#4541. I'll see whether that gets merged. |
Per comment from GvR, I changed the |
Thanks! ✨ 🍰 ✨ |
Starting with Python 3.3, IOError, EnvironmentError and WindowsError are
aliases for OSError, which has all their attributes.
Also, tested on Python 3.6 that OSError.filename/filename2 may also be
bytes and None, so annotated them as Any.
Reference: