-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Make importlib context manager not swallow exceptions #13733
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
Conversation
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
The importlib context manager doesn't swallow exceptions. Make sure that the type reflects that by having `Literal[False]` as the return type of `exit`.
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
srittau
approved these changes
Mar 28, 2025
Collaborator
srittau
left a comment
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.
Thanks!
facebook-github-bot
pushed a commit
to facebook/pyrefly
that referenced
this pull request
Mar 29, 2025
Summary: I want the change from python/typeshed#13733, so upgrade all of typeshed. One change to Any (which was broken before and is a slight improvement) and one change in tuple (which is worse, will aim to solve that on top). Reviewed By: stroxler Differential Revision: D72057759 fbshipit-source-id: 5882711d4cb55f2d05bd612443fde000866457b0
facebook-github-bot
pushed a commit
to facebook/pyre-check
that referenced
this pull request
Mar 31, 2025
Summary: I want the change from python/typeshed#13733, so upgrade all of typeshed. One change to Any (which was broken before and is a slight improvement) and one change in tuple (which is worse, will aim to solve that on top). Reviewed By: stroxler Differential Revision: D72057759 fbshipit-source-id: 5882711d4cb55f2d05bd612443fde000866457b0
facebook-github-bot
pushed a commit
to facebook/pyrefly
that referenced
this pull request
Apr 2, 2025
…`object.__new__` Summary: retain-cycle While calculating the type of `__new__` for a given class, there's a step where we take a look at the defining class of `__new__` and determine if it's the builtin `object` class -- if it's not, some special logic needs to happen; Otherwise, we fall back to the default behavior. To determine whether the defining class of `__new__` is `object`, we obtain the `object` class from `AnswerSolver::stdlib`, and check if the defining class of the `__new__` attribute is the same as the reference to `object` class in `stdlib`. This approach works 99.999% of the time. But it fails in exactly one scenario: while we are calculating the type of `object.__new__` during bootstrapping. In this case, because we are bootstrapping, the bootstrapping `stdlib` won't contain a valid reference to `object` (we may actually still be in the process of constructing this object!). So the query to `stdlib.object_class_type()` would always lead to a type checker runtime crash. With D72057759, the bootstrapping process never computes the type for `object.__new__` ([my PR](python/typeshed#13733) seems to have removed the last occurrence of `XXX = object()` in typeshed stubs, and hence there's no long any need to query the type for `object.__new__`). But this can be pretty fragile since someone may add another `XXX = object()` definition to typeshed in the future, and we may want to be a little bit more resilient against that. This diff proposes that we check the qname of the defining class of `__new__` instead so the logic would work regardless of `stdlib` availability. Reviewed By: rchen152 Differential Revision: D72274856 fbshipit-source-id: 180a61850684f9ab9bcc6ffc2a8213ccb0922c0f
facebook-github-bot
pushed a commit
to facebook/pyre-check
that referenced
this pull request
Apr 4, 2025
…`object.__new__` Summary: retain-cycle While calculating the type of `__new__` for a given class, there's a step where we take a look at the defining class of `__new__` and determine if it's the builtin `object` class -- if it's not, some special logic needs to happen; Otherwise, we fall back to the default behavior. To determine whether the defining class of `__new__` is `object`, we obtain the `object` class from `AnswerSolver::stdlib`, and check if the defining class of the `__new__` attribute is the same as the reference to `object` class in `stdlib`. This approach works 99.999% of the time. But it fails in exactly one scenario: while we are calculating the type of `object.__new__` during bootstrapping. In this case, because we are bootstrapping, the bootstrapping `stdlib` won't contain a valid reference to `object` (we may actually still be in the process of constructing this object!). So the query to `stdlib.object_class_type()` would always lead to a type checker runtime crash. With D72057759, the bootstrapping process never computes the type for `object.__new__` ([my PR](python/typeshed#13733) seems to have removed the last occurrence of `XXX = object()` in typeshed stubs, and hence there's no long any need to query the type for `object.__new__`). But this can be pretty fragile since someone may add another `XXX = object()` definition to typeshed in the future, and we may want to be a little bit more resilient against that. This diff proposes that we check the qname of the defining class of `__new__` instead so the logic would work regardless of `stdlib` availability. Reviewed By: rchen152 Differential Revision: D72274856 fbshipit-source-id: 180a61850684f9ab9bcc6ffc2a8213ccb0922c0f
mmingyu
pushed a commit
to mmingyu/typeshed
that referenced
this pull request
May 16, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The importlib context manager doesn't swallow exceptions. Make sure that the type reflects that by having
Literal[False]as the return type ofexit.Required to make one of the projects I was type checking work properly, to ensure it doesn't return None because of exception handling.