Exemple #1
0
        private void FinishLoadKnownTypes(PythonTypeDatabase db)
        {
            _itemCache.Clear();

            if (db == null)
            {
                db    = PythonTypeDatabase.CreateDefaultTypeDatabase(LanguageVersion.ToVersion());
                Types = KnownTypes.Create(this, db);
            }
            else
            {
                Types = KnownTypes.CreateDefault(this, db);
            }

            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();
        }
Exemple #2
0
        private void LoadInitialKnownTypes()
        {
            if (_builtinModule != null)
            {
                Debug.Fail("LoadInitialKnownTypes should only be called once");
                return;
            }

            var fallbackDb = PythonTypeDatabase.CreateDefaultTypeDatabase(LanguageVersion.ToVersion());

            _builtinModule = _modules.GetBuiltinModule(fallbackDb.GetModule(SharedDatabaseState.BuiltinName2x));

            FinishLoadKnownTypes(fallbackDb);
        }
        private void LoadKnownTypes()
        {
            _itemCache.Clear();

            ModuleReference moduleRef;

            if (Modules.TryImport(_builtinName, out moduleRef))
            {
                _builtinModule = (BuiltinModule)moduleRef.Module;
            }
            else
            {
                var fallbackDb = PythonTypeDatabase.CreateDefaultTypeDatabase(LanguageVersion.ToVersion());
                _builtinModule        = _modules.GetBuiltinModule(fallbackDb.GetModule(SharedDatabaseState.BuiltinName2x));
                Modules[_builtinName] = new ModuleReference(_builtinModule);
            }

            Types      = new KnownTypes(this);
            ClassInfos = (IKnownClasses)Types;

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

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

            AddBuiltInSpecializations();

            ModuleReference sysModule;

            if (_modules.TryImport("sys", out sysModule))
            {
                var bm = sysModule.AnalysisModule as BuiltinModule;
                if (bm != null)
                {
                    sysModule.Module = new SysModuleInfo(bm);
                }
            }
        }
Exemple #4
0
        private async Task <IReadOnlyList <string> > GetTypeShedPathsAsync()
        {
            // Assume caller has already done the quick checks

            IReadOnlyList <string> typeShedPaths;
            var typeshed = await FindModuleInSearchPathAsync("typeshed");

            lock (_searchPathsLock) {
                // Final check after searching and locking
                if (_typeShedPaths != null)
                {
                    return(_typeShedPaths);
                }

                if (typeshed.HasValue)
                {
                    typeShedPaths = GetTypeShedPaths(PathUtils.GetParent(typeshed.Value.SourceFile), LanguageVersion.ToVersion()).ToArray();
                }
                else
                {
                    typeShedPaths = Array.Empty <string>();
                }

                if (_typeShedPaths == null)
                {
                    _typeShedPaths = typeShedPaths;
                }
                else
                {
                    typeShedPaths = _typeShedPaths;
                }
            }

            return(typeShedPaths);
        }