diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index ce3dcaf9b0..87f9b27698 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -1794,7 +1794,6 @@ impl<'a> Checker<'a> { self.visit_expr(&generator.iter); self.semantic.push_scope(ScopeKind::Generator(kind)); - self.semantic.flags = flags | SemanticModelFlags::COMPREHENSION_ASSIGNMENT; self.visit_expr(&generator.target); self.semantic.flags = flags; @@ -1805,7 +1804,6 @@ impl<'a> Checker<'a> { for generator in iterator { self.visit_expr(&generator.iter); - self.semantic.flags = flags | SemanticModelFlags::COMPREHENSION_ASSIGNMENT; self.visit_expr(&generator.target); self.semantic.flags = flags; diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs b/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs index 04d627a8e9..c8f2c9b657 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs @@ -23,8 +23,7 @@ pub(crate) fn is_typing_reference(reference: &ResolvedReference, settings: &Sett // type definition to be considered a typing reference || (reference.in_type_definition() && (reference.in_typing_only_annotation() - || reference.in_complex_string_type_definition() - || reference.in_simple_string_type_definition() + || reference.in_string_type_definition() || (settings.quote_annotations && reference.in_runtime_evaluated_annotation()))) } diff --git a/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs b/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs index 7681d69228..44468db417 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/import_private_name.rs @@ -151,8 +151,7 @@ pub(crate) fn import_private_name( fn is_typing(reference: &ResolvedReference) -> bool { reference.in_type_checking_block() || reference.in_typing_only_annotation() - || reference.in_complex_string_type_definition() - || reference.in_simple_string_type_definition() + || reference.in_string_type_definition() || reference.in_runtime_evaluated_annotation() } diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index 9826be9a76..159f1152ae 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -1742,12 +1742,6 @@ impl<'a> SemanticModel<'a> { .intersects(SemanticModelFlags::NAMED_EXPRESSION_ASSIGNMENT) } - /// Return `true` if the model is in a comprehension assignment (e.g., `_ for x in y`). - pub const fn in_comprehension_assignment(&self) -> bool { - self.flags - .intersects(SemanticModelFlags::COMPREHENSION_ASSIGNMENT) - } - /// Return `true` if the model is visiting the r.h.s. of an `__all__` definition /// (e.g. `"foo"` in `__all__ = ["foo"]`) pub const fn in_dunder_all_definition(&self) -> bool { @@ -2141,14 +2135,6 @@ bitflags! { /// ``` const NAMED_EXPRESSION_ASSIGNMENT = 1 << 19; - /// The model is in a comprehension variable assignment. - /// - /// For example, the model could be visiting `x` in: - /// ```python - /// [_ for x in range(10)] - /// ``` - const COMPREHENSION_ASSIGNMENT = 1 << 20; - /// The model is in a docstring as described in [PEP 257]. /// /// For example, the model could be visiting either the module, class, @@ -2168,7 +2154,7 @@ bitflags! { /// ``` /// /// [PEP 257]: https://peps.python.org/pep-0257/#what-is-a-docstring - const PEP_257_DOCSTRING = 1 << 21; + const PEP_257_DOCSTRING = 1 << 20; /// The model is visiting the r.h.s. of a module-level `__all__` definition. /// @@ -2180,7 +2166,7 @@ bitflags! { /// __all__ = ("bar",) /// __all__ += ("baz,") /// ``` - const DUNDER_ALL_DEFINITION = 1 << 22; + const DUNDER_ALL_DEFINITION = 1 << 21; /// The model is in an f-string replacement field. /// @@ -2189,7 +2175,7 @@ bitflags! { /// ```python /// f"first {x} second {y}" /// ``` - const F_STRING_REPLACEMENT_FIELD = 1 << 23; + const F_STRING_REPLACEMENT_FIELD = 1 << 22; /// The model is visiting the bases tuple of a class. /// @@ -2199,11 +2185,11 @@ bitflags! { /// class Baz(Foo, Bar): /// pass /// ``` - const CLASS_BASE = 1 << 24; + const CLASS_BASE = 1 << 23; /// The model is visiting a class base that was initially deferred /// while traversing the AST. (This only happens in stub files.) - const DEFERRED_CLASS_BASE = 1 << 25; + const DEFERRED_CLASS_BASE = 1 << 24; /// The model is in an attribute docstring. /// @@ -2228,7 +2214,7 @@ bitflags! { /// static-analysis tools. /// /// [PEP 257]: https://peps.python.org/pep-0257/#what-is-a-docstring - const ATTRIBUTE_DOCSTRING = 1 << 26; + const ATTRIBUTE_DOCSTRING = 1 << 25; /// The context is in any type annotation. const ANNOTATION = Self::TYPING_ONLY_ANNOTATION.bits() | Self::RUNTIME_EVALUATED_ANNOTATION.bits() | Self::RUNTIME_REQUIRED_ANNOTATION.bits(); diff --git a/crates/ruff_python_semantic/src/reference.rs b/crates/ruff_python_semantic/src/reference.rs index de6fab3021..6799e76893 100644 --- a/crates/ruff_python_semantic/src/reference.rs +++ b/crates/ruff_python_semantic/src/reference.rs @@ -63,28 +63,10 @@ impl ResolvedReference { .intersects(SemanticModelFlags::RUNTIME_EVALUATED_ANNOTATION) } - /// Return `true` if the context is in a "simple" string type definition. - pub const fn in_simple_string_type_definition(&self) -> bool { + /// Return `true` if the context is in a string type definition. + pub const fn in_string_type_definition(&self) -> bool { self.flags - .intersects(SemanticModelFlags::SIMPLE_STRING_TYPE_DEFINITION) - } - - /// Return `true` if the context is in a "complex" string type definition. - pub const fn in_complex_string_type_definition(&self) -> bool { - self.flags - .intersects(SemanticModelFlags::COMPLEX_STRING_TYPE_DEFINITION) - } - - /// Return `true` if the context is in a `__future__` type definition. - pub const fn in_future_type_definition(&self) -> bool { - self.flags - .intersects(SemanticModelFlags::FUTURE_TYPE_DEFINITION) - } - - /// Return `true` if the context is in any kind of deferred type definition. - pub const fn in_deferred_type_definition(&self) -> bool { - self.flags - .intersects(SemanticModelFlags::DEFERRED_TYPE_DEFINITION) + .intersects(SemanticModelFlags::STRING_TYPE_DEFINITION) } /// Return `true` if the context is in any kind of type definition.