diff --git a/src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.Scopes.cs b/src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.Scopes.cs index 99329b895..4de9b669e 100644 --- a/src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.Scopes.cs +++ b/src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.Scopes.cs @@ -124,7 +124,10 @@ public IDisposable OpenScope(IPythonModule module, ScopeStatement node, out Scop return Disposable.Empty; } - var gs = module.GlobalScope as Scope ?? GlobalScope; + // During analysis module global scope has not changed yet since it updates + // When the analysis completed. Therefore if module is the one we are + // analyzing, use scope from the evaluator rather than from the module. + var gs = Module.Equals(module) || module == null ? GlobalScope : module.GlobalScope as Scope; if (node.Parent != null) { fromScope = gs .TraverseBreadthFirst(s => s.Children.OfType())