-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add _typeshed.(Opt)ExcInfo #7645
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44f1fcd
Add _typeshed.(Opt)ExcInfo
srittau 00ebbcf
Replace one more custom instance
srittau 5fbbd51
Fixes
srittau 4fbc763
Add missing import
srittau 3a04e62
Remove unused imports
srittau 71822d9
Merge branch 'master' into exc-info
srittau abbb276
Merge fix
srittau f5ece2f
Remove a todo comment
srittau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm,
tuple[type[BaseException], BaseException, TracebackType] | tuple[None, None, None]
is a different type totuple[type[BaseException] | None, BaseException | None, TracebackType | None]
, so this is a semantic changeThere 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.
Indeed, but usually the latter was a shortcut used for the former. See the typical
__exit__
annotation that should properly be annotated using an overload.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.
Right, the latter is a supertype of the former
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.
I believe it's not strictly true that it's always either all-None or all-non-None, at least before 3.11. (Irit did some work in 3.11 that made it always true.) See here: https://github.com/python/cpython/blob/84c279b514141f608cf480905c87d48998e296d1/Python/ceval.c#L4474
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.
This could be a remnant of Python 2 string exceptions.
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.
Maybe it's better to err on the side of safety here and define
_typeshed.OptExcInfo
astuple[type[BaseException] | None, BaseException | None, TracebackType | None]
instead oftuple[type[BaseException], BaseException, TracebackType] | tuple[None, None, None]
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.
Primer output looks good and from a type safety perspective, I'd rather go with the more strict/correct annotation. Personally, I've not come across a situation where the type is
None
when the other fields are not, and allowing that could certainly introduce subtle bugs. It would also disagree with the documentation of bothsys.exc_info
andcontextmanager.__exit__
.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.
@JelleZijlstra, do you know of any real-world examples where some (but not all) elements of the tuple are
None
?If not, I'm fine with merging this, as it's probably just a theoretical issue :)
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.
From python/cpython#89874 (comment), sounds like it could only happen with interesting use of the C API, so probably not worth worrying about.