-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add config option to disable typing_extensions
imports
#17611
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
Open
ntBre
wants to merge
12
commits into
main
Choose a base branch
from
brent/typing-extensions-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
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
Summary -- This PR resolves #9761 by adding a linter configuration option to disable `typing_extensions` imports. As mentioned [here], it would be ideal if we could detect whether or not `typing_extensions` is available as a dependency automatically, but this seems like a much easier fix in the meantime. The default for the new option `disable-typing-extensions` is `false`, preserving the current behavior. Setting it to `true` will bail out of the new `Checker::import_from_typing` method (#17340) with a new `TypingImportError::TypingExtensionsDisabled` error, which should log an explanatory message whenever `Diagnostic::try_set_fix` is used. [here]: #9761 (comment) Test Plan -- New linter tests exercising several combinations of Python versions and the new config option for PYI019. We could also test other rules, but any rule using `import_from_typing` should behave the same way.
this has more to do with the python version than the config option. changing the option doesn't actually have any effect here. the version must be validated somewhere else along the way
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Summary
This PR resolves #9761 by adding a linter configuration option to disable
typing_extensions
imports. As mentioned here, it would be ideal if we coulddetect whether or not
typing_extensions
is available as a dependencyautomatically, but this seems like a much easier fix in the meantime.
The default for the new option,
disable-typing-extensions
, isfalse
,preserving the current behavior. Setting it to
true
will bail out of the newChecker::import_from_typing
method (#17340)with
Ok(None)
, which had to be handled specially by each rule that callsimport_from_typing
.I'm not particularly happy with this API. It's too easy to pass the result to
Diagnostic::try_set_optional_fix
when you really need to return without a diagnostic in theOk(None)
case because the lint is not actionable if the user has explicitly disabledtyping_extensions
. On the other hand, this is actually a benefit when you don't need to consider this case, such as whenPythonVersion::lowest
is used and theOk(None)
case is impossible.I considered some alternatives to a config option, such as checking if
typing_extensions
has been imported or checking for aTYPE_CHECKING
block we could use, but I think defaulting to allowingtyping_extensions
imports and allowing the user to disable this with an option is both simple to implement and pretty intuitive.Test Plan
New linter tests exercising several combinations of Python versions and the new config option for PYI019. I also added tests for the other affected rules, but only in the case where the new config option is enabled. The rules' existing tests also cover the default case.