From d7dd2a055bb35d86efe41f5c93eab3255dc10e68 Mon Sep 17 00:00:00 2001 From: Daniil Kalinin Date: Wed, 18 Nov 2026 16:13:36 +0100 Subject: [PATCH] Bind the functools wrapper mutation literal with an empty range The synthetic literal used the whole module's range, so its type trace shadowed an expression spanning the whole module (a single expression without a trailing newline): range-based type queries returned `Literal[False]` for it. An empty range, as the empty-bindings constructor already uses, cannot collide with a real expression. Fixes #5670 Co-Authored-By: Claude Opus 5.5 --- pyrefly/lib/binding/bindings.rs | 5 +++-- .../lib/test/tsp/tsp_interaction/get_type_queries.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pyrefly/lib/binding/bindings.rs b/pyrefly/lib/binding/bindings.rs index 06c6930ac8..5c96201b85 100644 --- a/pyrefly/lib/binding/bindings.rs +++ b/pyrefly/lib/binding/bindings.rs @@ -1107,7 +1107,6 @@ impl Bindings { infer_param_types_from_docstring: bool, use_shape_comments_and_stubs: bool, ) -> Self { - let module_range = x.range; let dunder_all_entries = exports .dunder_all_names() .filter_map(|(_, name, content_range)| { @@ -1284,7 +1283,9 @@ impl Bindings { let module_deletes = scope_trace.module_deletes().clone(); let functools_wrapper_mutation = bind_functools_wrapper_mutation( &mut builder.table, - module_range, + // An empty range keeps the literal's type trace from shadowing an expression that + // spans the whole module + TextRange::default(), builder.has_functools_wrapper_mutation, ); builder.table.insert( diff --git a/pyrefly/lib/test/tsp/tsp_interaction/get_type_queries.rs b/pyrefly/lib/test/tsp/tsp_interaction/get_type_queries.rs index 7d6e87658f..2ec5a259c8 100644 --- a/pyrefly/lib/test/tsp/tsp_interaction/get_type_queries.rs +++ b/pyrefly/lib/test/tsp/tsp_interaction/get_type_queries.rs @@ -374,6 +374,18 @@ fn test_get_computed_type_list_is_class() { tsp.shutdown(); } +#[test] +fn test_get_computed_type_expression_spanning_whole_module() { + // Without a trailing newline, the expression's range equals the module's range. + let (mut tsp, file_uri, snapshot) = setup_project("[1, 2, 3]"); + + let result = get_computed_type_range_ok(&mut tsp, &file_uri, 0, 0, 0, 9, snapshot); + let name = result.pointer("/declaration/name").and_then(|v| v.as_str()); + assert_eq!(name, Some("list"), "Expected class name 'list'"); + + tsp.shutdown(); +} + #[test] fn test_get_computed_type_function_is_function_type() { // A function definition should produce a FunctionType with CALLABLE flag