ruff/crates/ruff_workspace/src
Brent Westbrook 01a31c08f5
Add config option to disable `typing_extensions` imports (#17611)
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.
2025-04-28 14:57:36 -04:00
..
configuration.rs Add config option to disable `typing_extensions` imports (#17611) 2025-04-28 14:57:36 -04:00
lib.rs Add most formatter options to `ruff.toml` / `pyproject.toml` (#7566) 2023-09-22 15:47:57 +00:00
options.rs Add config option to disable `typing_extensions` imports (#17611) 2025-04-28 14:57:36 -04:00
options_base.rs Better error message when `--config` is given a table key and a non-inline-table value (#15266) 2025-01-06 13:20:28 +00:00
pyproject.rs Update pre-commit dependencies (#17073) 2025-03-31 07:42:15 +00:00
resolver.rs Update pre-commit dependencies (#17073) 2025-03-31 07:42:15 +00:00
settings.rs Add `per-file-target-version` option (#16257) 2025-02-24 08:47:13 -05:00