mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Improve detection of TYPE_CHECKING
blocks imported from typing_extensions
or _typeshed
(#8429)
~Improves detection of types imported from `typing_extensions`. Removes the hard-coded list of supported types in `typing_extensions`; instead assuming all types could be imported from `typing`, `_typeshed`, or `typing_extensions`.~ ~The typing extensions package appears to re-export types even if they do not need modification.~ Adds detection of `if typing_extensions.TYPE_CHECKING` blocks. Avoids inserting a new `if TYPE_CHECKING` block and `from typing import TYPE_CHECKING` if `typing_extensions.TYPE_CHECKING` is used (closes https://github.com/astral-sh/ruff/issues/8427) --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
This commit is contained in:
parent
9d167a1f5c
commit
565ddebb15
16 changed files with 194 additions and 9 deletions
|
@ -200,6 +200,14 @@ impl<'a> SemanticModel<'a> {
|
|||
false
|
||||
}
|
||||
|
||||
/// Return an iterator over the set of `typing` modules allowed in the semantic model.
|
||||
pub fn typing_modules(&self) -> impl Iterator<Item = &str> {
|
||||
["typing", "_typeshed", "typing_extensions"]
|
||||
.iter()
|
||||
.copied()
|
||||
.chain(self.typing_modules.iter().map(String::as_str))
|
||||
}
|
||||
|
||||
/// Create a new [`Binding`] for a builtin.
|
||||
pub fn push_builtin(&mut self) -> BindingId {
|
||||
self.bindings.push(Binding {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue