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