From 37390885659acba9a14fdaf3e3c0210f169bdae1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 25 Oct 2024 19:22:38 +0100 Subject: [PATCH] feedback --- .../red_knot_python_semantic/src/types/infer.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 58f721552cf21..f2137560725b3 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -2329,8 +2329,6 @@ impl<'db> TypeInferenceBuilder<'db> { .expect("Symbol table should create a symbol for every Name node") .is_bound(); - let mut ty = Type::Unbound; - // In function-like scopes, any local variable (symbol that is bound in this scope) can // only have a definition in this scope, or error; it never references another scope. // (At runtime, it would use the `LOAD_FAST` opcode.) @@ -2361,8 +2359,10 @@ impl<'db> TypeInferenceBuilder<'db> { // No nonlocal binding, check module globals. Avoid infinite recursion if `self.scope` // already is module globals. - if !file_scope_id.is_global() { - ty = global_symbol_ty(self.db, self.file, name); + let ty = if file_scope_id.is_global() { + Type::Unbound + } else { + global_symbol_ty(self.db, self.file, name) }; // Still possibly unbound? All modules are instances of `types.ModuleType`; @@ -2391,11 +2391,13 @@ impl<'db> TypeInferenceBuilder<'db> { ); builtin_ty = typing_extensions_symbol_ty(self.db, name); } - ty = ty.replace_unbound_with(self.db, builtin_ty); + ty.replace_unbound_with(self.db, builtin_ty) + } else { + ty } + } else { + Type::Unbound } - - ty } fn infer_name_expression(&mut self, name: &ast::ExprName) -> Type<'db> {