From 4522f35ea7671676bb69c8b663b0aba72dea42f9 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 24 Oct 2025 09:48:57 +0200 Subject: [PATCH] [ty] Add comment explaining why `HasTrackedScope` is implemented for `Identifier` and why it works (#21057) --- crates/ty_python_semantic/src/semantic_model.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ty_python_semantic/src/semantic_model.rs b/crates/ty_python_semantic/src/semantic_model.rs index 6a71f7adfb..34efa22a02 100644 --- a/crates/ty_python_semantic/src/semantic_model.rs +++ b/crates/ty_python_semantic/src/semantic_model.rs @@ -505,8 +505,10 @@ impl HasTrackedScope for ast::Expr {} impl HasTrackedScope for ast::ExprRef<'_> {} impl HasTrackedScope for &ast::ExprRef<'_> {} -// See https://github.com/astral-sh/ty/issues/572 why this implementation exists -// even when we never register identifiers during semantic index building. +// We never explicitly register the scope of an `Identifier`. +// However, `ExpressionsScopeMap` stores the text ranges of each scope. +// That allows us to look up the identifier's scope for as long as it's +// inside an expression (because the ranges overlap). impl HasTrackedScope for ast::Identifier {} #[cfg(test)]