Example #1
0
        private async Task LoadKnownTypesAsync(CancellationToken token)
        {
            _itemCache.Clear();

            var fallback = new FallbackBuiltinModule(_langVersion);

            var moduleRef = await Modules.TryImportAsync(_builtinName, token).ConfigureAwait(false);

            if (moduleRef != null)
            {
                _builtinModule = (BuiltinModule)moduleRef.Module;
            }
            else
            {
                _builtinModule        = new BuiltinModule(fallback, this);
                Modules[_builtinName] = new ModuleReference(_builtinModule, _builtinName);
            }
            _builtinModule.InterpreterModule.Imported(_defaultContext);

            Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap);
            Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap);

            _knownTypes = KnownTypes.Create(this, fallback);

            _noneInst = (ConstantInfo)GetCached(
                _nullKey,
                () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant)
                );

            AddBuiltInSpecializations();
        }
        private async Task LoadKnownTypesAsync(CancellationToken token)
        {
            _itemCache.Clear();

            var fallback = new FallbackBuiltinModule(LanguageVersion);

            if (Modules.TryImport(_builtinName, out var moduleRef))
            {
                _builtinModule = (BuiltinModule)moduleRef.Module;
            }
            else
            {
                _builtinModule = new BuiltinModule(fallback, this);
                Modules.SetModule(_builtinName, BuiltinModule);
            }
            _builtinModule.InterpreterModule.Imported(_defaultContext);

            var builtinModuleNamesMember = ((IBuiltinPythonModule)_builtinModule.InterpreterModule).GetAnyMember("__builtin_module_names__");

            if (builtinModuleNamesMember is Interpreter.Ast.AstPythonStringLiteral builtinModuleNamesLiteral && builtinModuleNamesLiteral.Value != null)
            {
                var builtinModuleNames = builtinModuleNamesLiteral.Value.Split(',').Select(n => n.Trim());
                _pathResolver.SetBuiltins(builtinModuleNames);
            }

            Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap);
            Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap);

            _knownTypes = KnownTypes.Create(this, fallback);

            _noneInst = (ConstantInfo)GetCached(
                _nullKey,
                () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant)
                );

            AddBuiltInSpecializations();
        }
Example #3
0
        private async Task LoadKnownTypesAsync()
        {
            _itemCache.Clear();

            var fallback = new FallbackBuiltinModule(_langVersion);

            var moduleRef = await Modules.TryImportAsync(_builtinName).ConfigureAwait(false);

            if (moduleRef != null)
            {
                _builtinModule = (BuiltinModule)moduleRef.Module;
            }
            else
            {
                _builtinModule        = new BuiltinModule(fallback, this);
                Modules[_builtinName] = new ModuleReference(_builtinModule, _builtinName);
            }

            Modules.AddBuiltinModuleWrapper("sys", SysModuleInfo.Wrap);
            Modules.AddBuiltinModuleWrapper("typing", TypingModuleInfo.Wrap);

            Types = KnownTypes.Create(this, fallback);

            ClassInfos = (IKnownClasses)Types;
            _noneInst  = (ConstantInfo)GetCached(
                _nullKey,
                () => new ConstantInfo(ClassInfos[BuiltinTypeId.NoneType], null, PythonMemberType.Constant)
                );

            DoNotUnionInMro = AnalysisSet.Create(new AnalysisValue[] {
                ClassInfos[BuiltinTypeId.Object],
                ClassInfos[BuiltinTypeId.Type]
            });

            AddBuiltInSpecializations();
        }
 public FallbackBuiltinPythonType(FallbackBuiltinModule declaringModule, BuiltinTypeId typeId) :
     base(typeId.GetModuleName(declaringModule.LanguageVersion), declaringModule, declaringModule.Documentation, null)
 {
     TypeId = typeId;
 }