[ty] Fix Self resolution for classes nested within methods by charliermarsh · Pull Request #22964 · astral-sh/ruff (original) (raw)

I think you can do this using higher-level APIs that mean we don't have to access the raw AST (which is always best avoided where possible, as it hurts our incrementality)

diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index 79802a4fc3..c50b143f06 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -8,8 +8,8 @@ use ruff_python_ast as ast; use ruff_python_ast:📛:Name; use rustc_hash::{FxHashMap, FxHashSet};

-use crate::semantic_index::definition::{Definition, DefinitionKind}; -use crate::semantic_index::scope::{FileScopeId, NodeWithScopeKind, NodeWithScopeRef, ScopeId}; +use crate::semantic_index::definition::Definition; +use crate::semantic_index::scope::{FileScopeId, NodeWithScopeKind, ScopeId}; use crate::semantic_index::{SemanticIndex, semantic_index}; use crate::types::class::ClassType; use crate::types::class_base::ClassBase; @@ -27,10 +27,9 @@ use crate::types::{ ClassLiteral, FindLegacyTypeVarsVisitor, IntersectionType, KnownClass, KnownInstanceType, MaterializationKind, NormalizedVisitor, Type, TypeContext, TypeMapping, TypeVarBoundOrConstraints, TypeVarIdentity, TypeVarInstance, TypeVarKind, TypeVarVariance,

}; use crate::{Db, FxOrderMap, FxOrderSet}; -use ruff_db::parsed::parsed_module;

/// Returns an iterator of any generic context introduced by the given scope or any enclosing /// scope. @@ -163,19 +162,14 @@ pub(crate) fn typing_self<'db>( // // and the first match would be (method, Outer) -- wrong. let containing_scope = typevar_binding_context