Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit cd6f824

Browse files
authored
Create stub resolver before builtins (microsoft#723)
Fixes microsoft#719. Looking at the stack trace on that issue, `Initialize` occurs, which eventually gets an AST, which then spawns a task which eventually calls `CreateModule`, which refers back to `PythonInterpreter`, whose stub resolver has not yet been instantiated. I don't believe instantiating it earlier has any effect other than that it's there earlier so won't be `null`, as `InitializeAsync` only sets up an internal path resolver. I'm not really sure if this is the "true" fix, since it seems weird for there to be this sort of cycle, but I'm not the most familiar with this specific bit.
1 parent 32a1378 commit cd6f824

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Analysis/Ast/Impl/Analyzer/PythonInterpreter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ private async Task LoadBuiltinTypesAsync(string root, IServiceManager sm, Cancel
4949
_moduleResolution = new MainModuleResolution(root, sm);
5050
await _moduleResolution.InitializeAsync(cancellationToken);
5151

52+
_stubResolution = new TypeshedResolution(sm);
53+
await _stubResolution.InitializeAsync(cancellationToken);
54+
5255
var builtinModule = _moduleResolution.BuiltinsModule;
5356
lock (_lock) {
5457
_builtinTypes[BuiltinTypeId.NoneType]
@@ -57,9 +60,6 @@ private async Task LoadBuiltinTypesAsync(string root, IServiceManager sm, Cancel
5760
= UnknownType = new PythonType("Unknown", builtinModule, string.Empty, LocationInfo.Empty);
5861
}
5962
await _moduleResolution.LoadBuiltinTypesAsync(cancellationToken);
60-
61-
_stubResolution = new TypeshedResolution(sm);
62-
await _stubResolution.InitializeAsync(cancellationToken);
6363
}
6464

6565
public static async Task<IPythonInterpreter> CreateAsync(InterpreterConfiguration configuration, string root, IServiceManager sm, CancellationToken cancellationToken = default) {

0 commit comments

Comments
 (0)