mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 07:04:53 +00:00
![]() Summary -- This PR resolves https://github.com/astral-sh/ruff/issues/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, `typing-extensions`, is `true`, preserving the current behavior. Setting it to `false` will bail out of the new `Checker::typing_importer` method, which has been refactored from the `Checker::import_from_typing` method in https://github.com/astral-sh/ruff/pull/17340), with `None`, which is then handled specially by each rule that calls it. I considered some alternatives to a config option, such as checking if `typing_extensions` has been imported or checking for a `TYPE_CHECKING` block we could use, but I think defaulting to allowing `typing_extensions` imports and allowing the user to disable this with an option is both simple to implement and pretty intuitive. [here]: https://github.com/astral-sh/ruff/issues/9761#issuecomment-2790492853 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. |
||
---|---|---|
.. | ||
checkers | ||
comments | ||
cst | ||
docstrings | ||
fix | ||
importer | ||
message | ||
registry | ||
rules | ||
settings | ||
snapshots | ||
codes.rs | ||
directives.rs | ||
doc_lines.rs | ||
fs.rs | ||
lib.rs | ||
line_width.rs | ||
linter.rs | ||
locator.rs | ||
logging.rs | ||
noqa.rs | ||
package.rs | ||
packaging.rs | ||
preview.rs | ||
pyproject_toml.rs | ||
registry.rs | ||
renamer.rs | ||
rule_redirects.rs | ||
rule_selector.rs | ||
source_kind.rs | ||
test.rs | ||
text_helpers.rs | ||
upstream_categories.rs |