diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 5f39ccaada..284ad30aff 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -547,6 +547,12 @@ struct ScopeInferenceExtra<'db> { /// The diagnostics for this region. diagnostics: TypeCheckDiagnostics, + + /// The parameters of a function definition (without any default values filled in). + parameters: Option>>, + + /// The return type of a function definition. + return_type: Option>, } impl<'db> ScopeInference<'db> { diff --git a/crates/ty_python_semantic/src/types/infer/builder.rs b/crates/ty_python_semantic/src/types/infer/builder.rs index 372d78dac3..5659746d60 100644 --- a/crates/ty_python_semantic/src/types/infer/builder.rs +++ b/crates/ty_python_semantic/src/types/infer/builder.rs @@ -12347,17 +12347,17 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { mut expressions, scope, cycle_recovery, + parameters, + return_type, // Ignored, because scope types are never extended into other scopes. deferred: _, bindings: _, declarations: _, + parameter_defaults: _, // Ignored; only relevant to definition regions undecorated_type: _, - parameters: _, - parameter_defaults: _, - return_type: _, // Builder only state dataclass_field_specifiers: _, @@ -12375,15 +12375,20 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let _ = scope; let diagnostics = context.finish(); - let extra = - (!string_annotations.is_empty() || !diagnostics.is_empty() || cycle_recovery.is_some()) - .then(|| { - Box::new(ScopeInferenceExtra { - string_annotations, - cycle_recovery, - diagnostics, - }) - }); + let extra = (!string_annotations.is_empty() + || !diagnostics.is_empty() + || cycle_recovery.is_some() + || parameters.is_some() + || return_type.is_some()) + .then(|| { + Box::new(ScopeInferenceExtra { + string_annotations, + cycle_recovery, + diagnostics, + parameters, + return_type, + }) + }); expressions.shrink_to_fit();