diff --git a/build/Common.Build.Core.settings b/build/Common.Build.Core.settings index cb16b74fa..a38d4dbea 100644 --- a/build/Common.Build.Core.settings +++ b/build/Common.Build.Core.settings @@ -16,18 +16,10 @@ 10.0 16.0 15.0 - 14.0 - 12.0 - 11.0 - 10.0 - + 2019 2017 - 2015 - 2013 - 2012 - 2010 - + $(BUILD_BUILDNUMBER) 1000.00 + 1701;1702;1998;$(NoWarn) + 7.2 + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + + + + diff --git a/src/Analysis/Ast/Impl/Modules/BuiltinsPythonModule.cs b/src/Analysis/Ast/Impl/Modules/BuiltinsPythonModule.cs new file mode 100644 index 000000000..334a68d12 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/BuiltinsPythonModule.cs @@ -0,0 +1,157 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Specializations; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; + +namespace Microsoft.Python.Analysis.Modules { + /// + /// Represents builtins module. Typically generated for a given Python interpreter + /// by running special 'scraper' Python script that generates Python code via + /// introspection of the compiled built-in language types. + /// + internal sealed class BuiltinsPythonModule : CompiledPythonModule, IBuiltinsPythonModule { + private readonly HashSet _hiddenNames = new HashSet(); + private IPythonType _boolType; + + public BuiltinsPythonModule(string moduleName, string filePath, IServiceContainer services) + : base(moduleName, ModuleType.Builtins, filePath, null, services, ModuleLoadOptions.None) { } // TODO: builtins stub + + public override IMember GetMember(string name) => _hiddenNames.Contains(name) ? null : base.GetMember(name); + + public IMember GetAnyMember(string name) => base.GetMember(name); + + public override IEnumerable GetMemberNames() => base.GetMemberNames().Except(_hiddenNames).ToArray(); + + protected override IEnumerable GetScrapeArguments(IPythonInterpreter interpreter) + => !InstallPath.TryGetFile("scrape_module.py", out var sb) ? null : new List { "-B", "-E", sb }; + + protected override void OnAnalysisComplete() { + lock (AnalysisLock) { + SpecializeTypes(); + SpecializeFunctions(); + } + } + + private void SpecializeTypes() { + IPythonType noneType = null; + var isV3 = Interpreter.LanguageVersion.Is3x(); + + foreach (BuiltinTypeId typeId in Enum.GetValues(typeof(BuiltinTypeId))) { + var m = GetMember("__{0}__".FormatInvariant(typeId)); + if (!(m is PythonType biType && biType.IsBuiltin)) { + continue; + } + + if (biType.IsHidden) { + _hiddenNames.Add(biType.Name); + } + + _hiddenNames.Add("__{0}__".FormatInvariant(typeId)); + + // In V2 Unicode string is 'Unicode' and regular string is 'Str' or 'Bytes'. + // In V3 Unicode and regular strings are 'Str' and ASCII/byte string is 'Bytes'. + switch (typeId) { + case BuiltinTypeId.Bytes: { + var id = !isV3 ? BuiltinTypeId.Str : BuiltinTypeId.Bytes; + biType.TrySetTypeId(id); + biType.AddMember(@"__iter__", BuiltinsSpecializations.__iter__(Interpreter, id), true); + break; + } + case BuiltinTypeId.BytesIterator: { + biType.TrySetTypeId(!isV3 ? BuiltinTypeId.StrIterator : BuiltinTypeId.BytesIterator); + break; + } + case BuiltinTypeId.Unicode: { + var id = isV3 ? BuiltinTypeId.Str : BuiltinTypeId.Unicode; + biType.TrySetTypeId(id); + biType.AddMember(@"__iter__", BuiltinsSpecializations.__iter__(Interpreter, id), true); + break; + } + case BuiltinTypeId.UnicodeIterator: { + biType.TrySetTypeId(isV3 ? BuiltinTypeId.StrIterator : BuiltinTypeId.UnicodeIterator); + break; + } + case BuiltinTypeId.Str: { + biType.AddMember(@"__iter__", BuiltinsSpecializations.__iter__(Interpreter, typeId), true); + } + break; + default: + biType.TrySetTypeId(typeId); + switch (typeId) { + case BuiltinTypeId.Bool: + _boolType = _boolType ?? biType; + break; + case BuiltinTypeId.NoneType: + noneType = noneType ?? biType; + break; + } + break; + } + } + + _hiddenNames.Add("__builtin_module_names__"); + + if (_boolType != null) { + Analysis.GlobalScope.DeclareVariable("True", _boolType, LocationInfo.Empty); + Analysis.GlobalScope.DeclareVariable("False", _boolType, LocationInfo.Empty); + } + + if (noneType != null) { + Analysis.GlobalScope.DeclareVariable("None", noneType, LocationInfo.Empty); + } + + foreach (var n in GetMemberNames()) { + var t = GetMember(n).GetPythonType(); + if (t.TypeId == BuiltinTypeId.Unknown && t.MemberType != PythonMemberType.Unknown) { + (t as PythonType)?.TrySetTypeId(BuiltinTypeId.Type); + } + } + } + + private void SpecializeFunctions() { + // TODO: deal with commented out functions. + SpecializeFunction("abs", BuiltinsSpecializations.Identity); + SpecializeFunction("cmp", Interpreter.GetBuiltinType(BuiltinTypeId.Int)); + SpecializeFunction("dir", BuiltinsSpecializations.ListOfStrings); + SpecializeFunction("eval", Interpreter.GetBuiltinType(BuiltinTypeId.Object)); + SpecializeFunction("globals", BuiltinsSpecializations.DictStringToObject); + SpecializeFunction(@"isinstance", _boolType); + SpecializeFunction(@"issubclass", _boolType); + SpecializeFunction(@"iter", BuiltinsSpecializations.Iterator); + SpecializeFunction("locals", BuiltinsSpecializations.DictStringToObject); + //SpecializeFunction(_builtinName, "max", ReturnUnionOfInputs); + //SpecializeFunction(_builtinName, "min", ReturnUnionOfInputs); + SpecializeFunction("next", BuiltinsSpecializations.Next); + //SpecializeFunction(_builtinName, "open", SpecialOpen); + SpecializeFunction("ord", Interpreter.GetBuiltinType(BuiltinTypeId.Int)); + SpecializeFunction("pow", BuiltinsSpecializations.Identity); + SpecializeFunction("range", BuiltinsSpecializations.Range); + SpecializeFunction("type", BuiltinsSpecializations.TypeInfo); + + //SpecializeFunction(_builtinName, "range", RangeConstructor); + //SpecializeFunction(_builtinName, "sorted", ReturnsListOfInputIterable); + SpecializeFunction("sum", BuiltinsSpecializations.CollectionItem); + //SpecializeFunction(_builtinName, "super", SpecialSuper); + SpecializeFunction("vars", BuiltinsSpecializations.DictStringToObject); + } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/CompiledBuiltinPythonModule.cs b/src/Analysis/Ast/Impl/Modules/CompiledBuiltinPythonModule.cs new file mode 100644 index 000000000..aceff65f8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/CompiledBuiltinPythonModule.cs @@ -0,0 +1,47 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.IO; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; + +namespace Microsoft.Python.Analysis.Modules { + /// + /// Represents compiled module that is built into the language. + /// + internal sealed class CompiledBuiltinPythonModule : CompiledPythonModule { + public CompiledBuiltinPythonModule(string moduleName, IPythonModule stub, IServiceContainer services) + : base(moduleName, ModuleType.Compiled, MakeFakeFilePath(moduleName, services), stub, services) { } + + protected override IEnumerable GetScrapeArguments(IPythonInterpreter interpreter) + => !InstallPath.TryGetFile("scrape_module.py", out var sm) + ? null : new List { "-B", "-E", sm, "-u8", Name }; + + private static string MakeFakeFilePath(string name, IServiceContainer services) { + var interpreterPath = services.GetService().Configuration.InterpreterPath; + + if (string.IsNullOrEmpty(interpreterPath)) { + return "python.{0}.exe".FormatInvariant(name); + } + var ext = Path.GetExtension(interpreterPath); + if (ext.Length > 0) { // Typically Windows, make python.exe into python.name.exe + return Path.ChangeExtension(interpreterPath, name) + ext; + } + return $"{interpreterPath}.{name}.exe"; // Fake the extension + } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/CompiledPythonModule.cs b/src/Analysis/Ast/Impl/Modules/CompiledPythonModule.cs new file mode 100644 index 000000000..acfd75cba --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/CompiledPythonModule.cs @@ -0,0 +1,109 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.OS; + +namespace Microsoft.Python.Analysis.Modules { + internal class CompiledPythonModule : PythonModule { + protected IModuleCache ModuleCache => Interpreter.ModuleResolution.ModuleCache; + + public CompiledPythonModule(string moduleName, ModuleType moduleType, string filePath, IPythonModule stub, + IServiceContainer services, ModuleLoadOptions options = ModuleLoadOptions.Analyze) + : base(moduleName, filePath, moduleType, options, stub, services) { } + + public override string Documentation + => GetMember("__doc__").TryGetConstant(out var s) ? s : string.Empty; + + protected virtual IEnumerable GetScrapeArguments(IPythonInterpreter interpreter) { + var args = new List { "-B", "-E" }; + + var mp = Interpreter.ModuleResolution.FindModule(FilePath); + if (string.IsNullOrEmpty(mp.FullName)) { + return null; + } + + if (!InstallPath.TryGetFile("scrape_module.py", out var sm)) { + return null; + } + + args.Add(sm); + args.Add("-u8"); + args.Add(mp.ModuleName); + args.Add(mp.LibraryPath); + + return args; + } + + protected override string LoadContent(ModuleLoadOptions options) { + var code = string.Empty; + if ((options & ModuleLoadOptions.Load) == ModuleLoadOptions.Load) { + code = ModuleCache.ReadCachedModule(FilePath); + if (string.IsNullOrEmpty(code)) { + if (!FileSystem.FileExists(Interpreter.Configuration.InterpreterPath)) { + return string.Empty; + } + + code = ScrapeModule(); + SaveCachedCode(code); + } + } + return code; + } + + protected virtual void SaveCachedCode(string code) => ModuleCache.WriteCachedModule(FilePath, code); + + private string ScrapeModule() { + var args = GetScrapeArguments(Interpreter); + if (args == null) { + return string.Empty; + } + + var sb = new StringBuilder(); + using (var proc = new ProcessHelper( + Interpreter.Configuration.InterpreterPath, + args, + Interpreter.Configuration.LibraryPath + )) { + proc.StartInfo.StandardOutputEncoding = Encoding.UTF8; + proc.OnOutputLine = s => sb.AppendLine(s); + proc.OnErrorLine = s => Log?.Log(TraceEventType.Error, "Scrape", s); + + Log?.Log(TraceEventType.Information, "Scrape", proc.FileName, proc.Arguments); + + proc.Start(); + var exitCode = proc.Wait(60000); + + if (exitCode == null) { + proc.Kill(); + Log?.Log(TraceEventType.Error, "ScrapeTimeout", proc.FileName, proc.Arguments); + return string.Empty; + } + + if (exitCode != 0) { + Log?.Log(TraceEventType.Error, "Scrape", "ExitCode", exitCode); + return string.Empty; + } + } + + return sb.ToString(); + } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/Definitions/IModuleCache.cs b/src/Analysis/Ast/Impl/Modules/Definitions/IModuleCache.cs new file mode 100644 index 000000000..6d735aadf --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/Definitions/IModuleCache.cs @@ -0,0 +1,28 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Documents; + +namespace Microsoft.Python.Analysis.Modules { + public interface IModuleCache { + string SearchPathCachePath { get; } + Task ImportFromCacheAsync(string name, CancellationToken cancellationToken); + string GetCacheFilePath(string filePath); + string ReadCachedModule(string filePath); + void WriteCachedModule(string filePath, string code); + } +} diff --git a/src/Analysis/Ast/Impl/Modules/Definitions/IModuleResolution.cs b/src/Analysis/Ast/Impl/Modules/Definitions/IModuleResolution.cs new file mode 100644 index 000000000..c896bc270 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/Definitions/IModuleResolution.cs @@ -0,0 +1,77 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Modules { + public interface IModuleResolution { + string BuiltinModuleName { get; } + Task> GetSearchPathsAsync(CancellationToken cancellationToken = default); + Task> GetImportableModulesAsync(CancellationToken cancellationToken = default); + Task> GetImportableModulesAsync(IEnumerable searchPaths, CancellationToken cancellationToken = default); + ModulePath FindModule(string filePath); + IReadOnlyCollection GetPackagesFromDirectory(string searchPath, CancellationToken cancellationToken = default); + + /// + /// Determines if directory contains Python package. + /// + bool IsPackage(string directory); + + /// + /// Path resolver providing file resolution in module imports. + /// + PathResolverSnapshot CurrentPathResolver { get; } + + /// + /// Returns an IPythonModule for a given module name. Returns null if + /// the module does not exist. The import is performed asynchronously. + /// + Task ImportModuleAsync(string name, CancellationToken cancellationToken = default); + + /// + /// Builtins module. + /// + IBuiltinsPythonModule BuiltinsModule { get; } + + IModuleCache ModuleCache { get; } + + Task ReloadAsync(CancellationToken token = default); + + void AddModulePath(string path); + + /// + /// Provides ability to specialize module by replacing module import by + /// implementation in code. Real module + /// content is loaded and analyzed only for class/functions definitions + /// so the original documentation can be extracted. + /// + /// Module to specialize. + /// Specialized module constructor. + /// Cancellation token. + /// Original (library) module loaded as stub. + Task SpecializeModuleAsync(string name, Func specializationConstructor, CancellationToken cancellationToken = default); + + /// + /// Returns specialized module, if any. + /// + IPythonModule GetSpecializedModule(string name); + } +} diff --git a/src/Analysis/Ast/Impl/Modules/Definitions/ModuleCreationOptions.cs b/src/Analysis/Ast/Impl/Modules/Definitions/ModuleCreationOptions.cs new file mode 100644 index 000000000..7731b29be --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/Definitions/ModuleCreationOptions.cs @@ -0,0 +1,56 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Modules { + public sealed class ModuleCreationOptions { + /// + /// The name of the module. + /// + public string ModuleName { get; set; } + + /// + /// Module content. Can be null if file path or URI are provided. + /// + public string Content { get; set; } + + /// + /// The path to the file on disk. Can be null if URI is provided. + /// + public string FilePath { get; set; } + + /// + /// Document URI. Can be null if file path is provided. + /// + public Uri Uri { get; set; } + + /// + /// Module type (user, library, compiled, stub, ...). + /// + public ModuleType ModuleType { get; set; } = ModuleType.User; + + /// + /// Module stub, if any. + /// + public IPythonModule Stub { get; set; } + + /// + /// Module loading options. + /// + public ModuleLoadOptions LoadOptions { get; set; } = ModuleLoadOptions.Analyze; + } +} diff --git a/src/Analysis/Ast/Impl/Modules/Definitions/ModuleLoadOptions.cs b/src/Analysis/Ast/Impl/Modules/Definitions/ModuleLoadOptions.cs new file mode 100644 index 000000000..0fa7c340c --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/Definitions/ModuleLoadOptions.cs @@ -0,0 +1,47 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; + +namespace Microsoft.Python.Analysis.Modules { + [Flags] + public enum ModuleLoadOptions { + /// + /// Do nothing. Typically this is a placeholder or empty module. + /// + None, + + /// + /// Just load the document, do not parse or analyze. + /// + Load = 1, + + /// + /// Load and parse. Do not analyze. + /// + Ast = Load | 2, + + /// + /// Load, parse and analyze. + /// + Analyze = Ast | 4, + + /// + /// The document is opened in the editor. + /// This implies Ast and Analysis. + /// + Open = Analyze | 8 + } +} diff --git a/src/Analysis/Ast/Impl/Modules/Definitions/ModuleType.cs b/src/Analysis/Ast/Impl/Modules/Definitions/ModuleType.cs new file mode 100644 index 000000000..b017e0708 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/Definitions/ModuleType.cs @@ -0,0 +1,66 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; + +namespace Microsoft.Python.Analysis.Modules { + [Flags] + public enum ModuleType { + /// + /// Module is user file in the workspace. + /// + User, + + /// + /// Module is library module in Python. + /// + Library, + + /// + /// Module is a stub module. + /// + Stub, + + /// + /// Module source was scraped from a compiled module. + /// + Compiled, + + /// + /// Module source was scraped from a built-in compiled module. + /// + CompiledBuiltin, + + /// + /// Module is the Python 'builtins' module. + /// + Builtins, + + /// + /// Module that contains child modules + /// + Package, + + /// + /// Unresolved import. + /// + Unresolved, + + /// + /// Module that is implemented inside the analyzer, such as 'typing'. + /// + Specialized + } +} diff --git a/src/Analysis/Ast/Impl/Modules/FallbackBuiltinModule.cs b/src/Analysis/Ast/Impl/Modules/FallbackBuiltinModule.cs new file mode 100644 index 000000000..6d54c2092 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/FallbackBuiltinModule.cs @@ -0,0 +1,74 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing; + +namespace Microsoft.Python.Analysis.Modules { + internal sealed class FallbackBuiltinsModule : PythonModule, IBuiltinsPythonModule { + public readonly PythonLanguageVersion LanguageVersion; + private readonly Dictionary _cachedInstances; + + public FallbackBuiltinsModule(PythonLanguageVersion version) + : base(BuiltinTypeId.Unknown.GetModuleName(version), ModuleType.Builtins, null) { + LanguageVersion = version; + _cachedInstances = new Dictionary(); + } + + private IPythonType GetOrCreate(BuiltinTypeId typeId) { + if (typeId.IsVirtualId()) { + switch (typeId) { + case BuiltinTypeId.Str: + typeId = BuiltinTypeId.Str; + break; + case BuiltinTypeId.StrIterator: + typeId = BuiltinTypeId.StrIterator; + break; + default: + typeId = BuiltinTypeId.Unknown; + break; + } + } + + lock (_cachedInstances) { + if (!_cachedInstances.TryGetValue(typeId, out var value)) { + _cachedInstances[typeId] = value = new FallbackBuiltinPythonType(this, typeId); + } + return value; + } + } + + public IMember GetAnyMember(string name) { + foreach (BuiltinTypeId typeId in Enum.GetValues(typeof(BuiltinTypeId))) { + if (typeId.GetTypeName(LanguageVersion) == name) { + return GetOrCreate(typeId); + } + } + return GetOrCreate(BuiltinTypeId.Unknown); + } + } + + class FallbackBuiltinPythonType : PythonType { + public FallbackBuiltinPythonType(FallbackBuiltinsModule declaringModule, BuiltinTypeId typeId) : + base(typeId.GetModuleName(declaringModule.LanguageVersion), declaringModule, declaringModule.Documentation, null) { + TypeId = typeId; + } + + public override PythonMemberType MemberType => PythonMemberType.Class; + public override BuiltinTypeId TypeId { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/ModuleCache.cs b/src/Analysis/Ast/Impl/Modules/ModuleCache.cs new file mode 100644 index 000000000..b9d19afb0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/ModuleCache.cs @@ -0,0 +1,159 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Diagnostics; +using System.IO; +using System.Security.Cryptography; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Documents; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Logging; + +namespace Microsoft.Python.Analysis.Modules { + internal sealed class ModuleCache : IModuleCache { + private readonly IServiceContainer _services; + private readonly IPythonInterpreter _interpreter; + private readonly IFileSystem _fs; + private readonly ILogger _log; + private readonly bool _skipCache; + private bool _loggedBadDbPath; + + private string ModuleCachePath => _interpreter.Configuration.ModuleCachePath; + + public ModuleCache(IPythonInterpreter interpreter, IServiceContainer services) { + _interpreter = interpreter; + _services = services; + _fs = services.GetService(); + _log = services.GetService(); + _skipCache = string.IsNullOrEmpty(_interpreter.Configuration.ModuleCachePath); + SearchPathCachePath = Path.Combine(_interpreter.Configuration.ModuleCachePath, "database.path"); + } + + public string SearchPathCachePath { get; } + + public async Task ImportFromCacheAsync(string name, CancellationToken cancellationToken) { + if (string.IsNullOrEmpty(ModuleCachePath)) { + return null; + } + + var cache = GetCacheFilePath("python.{0}.pyi".FormatInvariant(name)); + if (!_fs.FileExists(cache)) { + cache = GetCacheFilePath("python._{0}.pyi".FormatInvariant(name)); + if (!_fs.FileExists(cache)) { + cache = GetCacheFilePath("{0}.pyi".FormatInvariant(name)); + if (!_fs.FileExists(cache)) { + return null; + } + } + } + + var rdt = _services.GetService(); + var mco = new ModuleCreationOptions { + ModuleName = name, + ModuleType = ModuleType.Stub, + FilePath = cache, + LoadOptions = ModuleLoadOptions.Analyze + }; + var module = rdt.AddModule(mco); + + await module.LoadAndAnalyzeAsync(cancellationToken).ConfigureAwait(false); + return module; + } + + public string GetCacheFilePath(string filePath) { + if (string.IsNullOrEmpty(filePath) || !PathEqualityComparer.IsValidPath(ModuleCachePath)) { + if (!_loggedBadDbPath) { + _loggedBadDbPath = true; + _log?.Log(TraceEventType.Warning, $"Invalid module cache path: {ModuleCachePath}"); + } + return null; + } + + var name = PathUtils.GetFileName(filePath); + if (!PathEqualityComparer.IsValidPath(name)) { + _log?.Log(TraceEventType.Warning, $"Invalid cache name: {name}"); + return null; + } + try { + var candidate = Path.ChangeExtension(Path.Combine(ModuleCachePath, name), ".pyi"); + if (_fs.FileExists(candidate)) { + return candidate; + } + } catch (ArgumentException) { + return null; + } + + var hash = SHA256.Create(); + var dir = Path.GetDirectoryName(filePath) ?? string.Empty; + if (_fs.StringComparison == StringComparison.OrdinalIgnoreCase) { + dir = dir.ToLowerInvariant(); + } + + var dirHash = Convert.ToBase64String(hash.ComputeHash(new UTF8Encoding(false).GetBytes(dir))) + .Replace('/', '_').Replace('+', '-'); + + return Path.ChangeExtension(Path.Combine( + ModuleCachePath, + Path.Combine(dirHash, name) + ), ".pyi"); + } + + public string ReadCachedModule(string filePath) { + if (_skipCache) { + return string.Empty; + } + + var path = GetCacheFilePath(filePath); + if (string.IsNullOrEmpty(path)) { + return string.Empty; + } + + var fileIsOkay = false; + try { + var cacheTime = _fs.GetLastWriteTimeUtc(path); + var sourceTime = _fs.GetLastWriteTimeUtc(filePath); + if (sourceTime <= cacheTime) { + var assemblyTime = _fs.GetLastWriteTimeUtc(GetType().Assembly.Location); + if (assemblyTime <= cacheTime) { + fileIsOkay = true; + } + } + } catch (Exception ex) when (!ex.IsCriticalException()) { + } + + if (fileIsOkay) { + try { + return _fs.ReadAllText(filePath); + } catch (IOException) { } catch (UnauthorizedAccessException) { } + } + + _log?.Log(TraceEventType.Verbose, "Invalidate cached module", path); + _fs.DeleteFileWithRetries(path); + return string.Empty; + } + + public void WriteCachedModule(string filePath, string code) { + var cache = GetCacheFilePath(filePath); + if (!string.IsNullOrEmpty(cache)) { + _log?.Log(TraceEventType.Verbose, "Write cached module: ", cache); + _fs.WriteTextWithRetry(cache, code); + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/ModuleResolution.cs b/src/Analysis/Ast/Impl/Modules/ModuleResolution.cs new file mode 100644 index 000000000..9128af8e3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/ModuleResolution.cs @@ -0,0 +1,475 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Analysis.Documents; +using Microsoft.Python.Analysis.Specializations; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Logging; + +namespace Microsoft.Python.Analysis.Modules { + internal sealed class ModuleResolution : IModuleResolution { + private static readonly IReadOnlyDictionary _emptyModuleSet = EmptyDictionary.Instance; + private readonly ConcurrentDictionary _modules = new ConcurrentDictionary(); + private readonly IReadOnlyList _typeStubPaths; + private readonly IServiceContainer _services; + private readonly IPythonInterpreter _interpreter; + private readonly IFileSystem _fs; + private readonly ILogger _log; + private readonly bool _requireInitPy; + private readonly string _root; + + private PathResolver _pathResolver; + private IReadOnlyDictionary _searchPathPackages; + private IReadOnlyList _searchPaths; + + private InterpreterConfiguration Configuration => _interpreter.Configuration; + + public ModuleResolution(string root, IServiceContainer services) { + _root = root; + _services = services; + _interpreter = services.GetService(); + _fs = services.GetService(); + _log = services.GetService(); + + _requireInitPy = ModulePath.PythonVersionRequiresInitPyFiles(_interpreter.Configuration.Version); + // TODO: merge with user-provided stub paths + _typeStubPaths = GetTypeShedPaths(_interpreter.Configuration?.TypeshedPath).ToArray(); + } + + internal async Task LoadBuiltinTypesAsync(CancellationToken cancellationToken = default) { + // Add names from search paths + await ReloadAsync(cancellationToken); + + // Initialize built-in + var moduleName = BuiltinTypeId.Unknown.GetModuleName(_interpreter.LanguageVersion); + var modulePath = ModuleCache.GetCacheFilePath(_interpreter.Configuration.InterpreterPath ?? "python.exe"); + + var b = new BuiltinsPythonModule(moduleName, modulePath, _services); + _modules[BuiltinModuleName] = BuiltinsModule = b; + await b.LoadAndAnalyzeAsync(cancellationToken); + + // Add built-in module names + var builtinModuleNamesMember = BuiltinsModule.GetAnyMember("__builtin_module_names__"); + if (builtinModuleNamesMember.TryGetConstant(out var s)) { + var builtinModuleNames = s.Split(',').Select(n => n.Trim()); + _pathResolver.SetBuiltins(builtinModuleNames); + } + } + + public IModuleCache ModuleCache { get; private set; } + public string BuiltinModuleName => BuiltinTypeId.Unknown.GetModuleName(_interpreter.LanguageVersion); + + /// + /// Path resolver providing file resolution in module imports. + /// + public PathResolverSnapshot CurrentPathResolver => _pathResolver.CurrentSnapshot; + + /// + /// Builtins module. + /// + public IBuiltinsPythonModule BuiltinsModule { get; private set; } + + public async Task> GetImportableModulesAsync(CancellationToken cancellationToken) { + if (_searchPathPackages != null) { + return _searchPathPackages; + } + + var packageDict = await GetImportableModulesAsync(Configuration.SearchPaths, cancellationToken).ConfigureAwait(false); + if (!packageDict.Any()) { + return _emptyModuleSet; + } + + _searchPathPackages = packageDict; + return packageDict; + } + + public async Task> GetSearchPathsAsync(CancellationToken cancellationToken = default) { + if (_searchPaths != null) { + return _searchPaths; + } + + _searchPaths = await GetInterpreterSearchPathsAsync(cancellationToken).ConfigureAwait(false); + Debug.Assert(_searchPaths != null, "Should have search paths"); + _searchPaths = _searchPaths.Concat(Configuration.SearchPaths ?? Array.Empty()).ToArray(); + _log?.Log(TraceEventType.Information, "SearchPaths", _searchPaths.Cast().ToArray()); + return _searchPaths; + } + + public async Task> GetImportableModulesAsync(IEnumerable searchPaths, CancellationToken cancellationToken = default) { + var packageDict = new Dictionary(); + + foreach (var searchPath in searchPaths.MaybeEnumerate()) { + IReadOnlyCollection packages = null; + if (_fs.FileExists(searchPath)) { + packages = GetPackagesFromZipFile(searchPath, cancellationToken); + } else if (_fs.DirectoryExists(searchPath)) { + packages = await Task.Run(() + => GetPackagesFromDirectory(searchPath, cancellationToken), cancellationToken).ConfigureAwait(false); + } + foreach (var package in packages.MaybeEnumerate()) { + cancellationToken.ThrowIfCancellationRequested(); + packageDict[package] = searchPath; + } + } + + return packageDict; + } + + private async Task> GetInterpreterSearchPathsAsync(CancellationToken cancellationToken = default) { + if (!_fs.FileExists(Configuration.InterpreterPath)) { + return Array.Empty(); + } + + _log?.Log(TraceEventType.Information, "GetCurrentSearchPaths", Configuration.InterpreterPath, ModuleCache.SearchPathCachePath); + try { + var paths = await PythonLibraryPath.GetDatabaseSearchPathsAsync(Configuration, ModuleCache.SearchPathCachePath).ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); + return paths.MaybeEnumerate().Select(p => p.Path).ToArray(); + } catch (InvalidOperationException) { + return Array.Empty(); + } + } + + private async Task TryImportModuleAsync(string name, CancellationToken cancellationToken = default) { + if (string.IsNullOrEmpty(name)) { + return TryImportModuleResult.ModuleNotFound; + } + if (name == BuiltinModuleName) { + return new TryImportModuleResult(BuiltinsModule); + } + + Debug.Assert(!name.EndsWithOrdinal("."), $"{name} should not end with '.'"); + // Return any existing module + if (_modules.TryGetValue(name, out var module) && module != null) { + if (module is SentinelModule) { + // TODO: we can't just wait here or we hang. There are two cases: + // a. Recursion on the same analysis chain (A -> B -> A) + // b. Call from another chain (A -> B -> C and D -> B -> E). + // TODO: Both should be resolved at the dependency chain level. + _log?.Log(TraceEventType.Warning, $"Recursive import: {name}"); + } + return new TryImportModuleResult(module); + } + + // Set up a sentinel so we can detect recursive imports + var sentinelValue = new SentinelModule(name, _services); + if (!_modules.TryAdd(name, sentinelValue)) { + // Try to get the new module, in case we raced with a .Clear() + if (_modules.TryGetValue(name, out module) && !(module is SentinelModule)) { + return new TryImportModuleResult(module); + } + // If we reach here, the race is too complicated to recover + // from. Signal the caller to try importing again. + _log?.Log(TraceEventType.Warning, $"Retry import: {name}"); + return TryImportModuleResult.NeedRetry; + } + + // Do normal searches + try { + module = await ImportFromSearchPathsAsync(name, cancellationToken).ConfigureAwait(false); + } catch (OperationCanceledException) { + _log?.Log(TraceEventType.Error, $"Import timeout {name}"); + return TryImportModuleResult.Timeout; + } + + module = module ?? await ModuleCache.ImportFromCacheAsync(name, cancellationToken); + + // Replace our sentinel + if (!_modules.TryUpdate(name, module, sentinelValue)) { + // Try to get the new module, in case we raced + if (_modules.TryGetValue(name, out module) && !(module is SentinelModule)) { + return new TryImportModuleResult(module); + } + // If we reach here, the race is too complicated to recover + // from. Signal the caller to try importing again. + _log?.Log(TraceEventType.Warning, $"Retry import: {name}"); + return TryImportModuleResult.NeedRetry; + } + + return new TryImportModuleResult(module); + } + + public IReadOnlyCollection GetPackagesFromDirectory(string searchPath, CancellationToken cancellationToken) { + return ModulePath.GetModulesInPath( + searchPath, + recurse: false, + includePackages: true, + requireInitPy: _requireInitPy + ).Select(mp => mp.ModuleName).Where(n => !string.IsNullOrEmpty(n)).TakeWhile(_ => !cancellationToken.IsCancellationRequested).ToList(); + } + + public async Task ImportModuleAsync(string name, CancellationToken cancellationToken = default) { + if (name == BuiltinModuleName) { + return BuiltinsModule; + } + + for (var retries = 5; retries > 0; --retries) { + cancellationToken.ThrowIfCancellationRequested(); + + // The call should be cancelled by the cancellation token, but since we + // are blocking here we wait for slightly longer. Timeouts are handled + // gracefully by TryImportModuleAsync(), so we want those to trigger if + // possible, but if all else fails then we'll abort and treat it as an + // error. + // (And if we've got a debugger attached, don't time out at all.) + TryImportModuleResult result; + try { + result = await TryImportModuleAsync(name, cancellationToken); + } catch (OperationCanceledException) { + _log?.Log(TraceEventType.Error, $"Import timeout: {name}"); + Debug.Fail("Import timeout"); + return null; + } + + switch (result.Status) { + case TryImportModuleResultCode.Success: + return result.Module; + case TryImportModuleResultCode.ModuleNotFound: + _log?.Log(TraceEventType.Information, $"Import not found: {name}"); + return null; + case TryImportModuleResultCode.NeedRetry: + case TryImportModuleResultCode.Timeout: + break; + case TryImportModuleResultCode.NotSupported: + _log?.Log(TraceEventType.Error, $"Import not supported: {name}"); + return null; + } + } + // Never succeeded, so just log the error and fail + _log?.Log(TraceEventType.Error, $"Retry import failed: {name}"); + return null; + } + + public async Task ReloadAsync(CancellationToken cancellationToken = default) { + ModuleCache = new ModuleCache(_interpreter, _services); + + _pathResolver = new PathResolver(_interpreter.LanguageVersion); + + var addedRoots = _pathResolver.SetRoot(_root); + ReloadModulePaths(addedRoots); + + var interpreterPaths = await GetSearchPathsAsync(cancellationToken); + addedRoots = _pathResolver.SetInterpreterSearchPaths(interpreterPaths); + ReloadModulePaths(addedRoots); + + addedRoots = _pathResolver.SetUserSearchPaths(_interpreter.Configuration.SearchPaths); + ReloadModulePaths(addedRoots); + } + + public void AddModulePath(string path) => _pathResolver.TryAddModulePath(path, out var _); + + /// + /// Determines whether the specified directory is an importable package. + /// + public bool IsPackage(string directory) + => ModulePath.PythonVersionRequiresInitPyFiles(Configuration.Version) ? + !string.IsNullOrEmpty(ModulePath.GetPackageInitPy(directory)) : + _fs.DirectoryExists(directory); + + public ModulePath FindModule(string filePath) { + var bestLibraryPath = string.Empty; + + foreach (var p in Configuration.SearchPaths) { + if (PathEqualityComparer.Instance.StartsWith(filePath, p)) { + if (p.Length > bestLibraryPath.Length) { + bestLibraryPath = p; + } + } + } + + var mp = ModulePath.FromFullPath(filePath, bestLibraryPath); + return mp; + } + + /// + /// Provides ability to specialize module by replacing module import by + /// implementation in code. Real module + /// content is loaded and analyzed only for class/functions definitions + /// so the original documentation can be extracted. + /// + /// Module to specialize. + /// Specialized module constructor. + /// Cancellation token. + /// Original (library) module loaded as stub. + public async Task SpecializeModuleAsync(string name, Func specializationConstructor, CancellationToken cancellationToken = default) { + var import = CurrentPathResolver.GetModuleImportFromModuleName(name); + if (!string.IsNullOrEmpty(import?.ModulePath)) { + var module = specializationConstructor(import.ModulePath); + _modules[name] = module; + await module.LoadAndAnalyzeAsync(cancellationToken); + return module; + } + return null; + } + + /// + /// Returns specialized module, if any. + /// + public IPythonModule GetSpecializedModule(string name) + => _modules.TryGetValue(name, out var m) && m is SpecializedModule ? m : null; + + private async Task ImportFromSearchPathsAsync(string name, CancellationToken cancellationToken) { + var moduleImport = CurrentPathResolver.GetModuleImportFromModuleName(name); + if (moduleImport == null) { + _log?.Log(TraceEventType.Verbose, "Import not found: ", name); + return null; + } + // If there is a stub, make sure it is loaded and attached + var stub = await ImportFromTypeStubsAsync(moduleImport.IsBuiltin ? name : moduleImport.FullName, cancellationToken); + IPythonModule module; + + if (moduleImport.IsBuiltin) { + _log?.Log(TraceEventType.Verbose, "Import built-in compiled (scraped) module: ", name, Configuration.InterpreterPath); + module = new CompiledBuiltinPythonModule(name, stub, _services); + } else if (moduleImport.IsCompiled) { + _log?.Log(TraceEventType.Verbose, "Import compiled (scraped): ", moduleImport.FullName, moduleImport.ModulePath, moduleImport.RootPath); + module = new CompiledPythonModule(moduleImport.FullName, ModuleType.Compiled, moduleImport.ModulePath, stub, _services); + } else { + _log?.Log(TraceEventType.Verbose, "Import: ", moduleImport.FullName, moduleImport.ModulePath); + var rdt = _services.GetService(); + // TODO: handle user code and library module separately. + var mco = new ModuleCreationOptions { + ModuleName = moduleImport.FullName, + ModuleType = ModuleType.Library, + FilePath = moduleImport.ModulePath, + Stub = stub, + LoadOptions = ModuleLoadOptions.Analyze + }; + module = rdt.AddModule(mco); + } + + await module.LoadAndAnalyzeAsync(cancellationToken).ConfigureAwait(false); + return module; + } + + private async Task ImportFromTypeStubsAsync(string name, CancellationToken cancellationToken = default) { + var mp = FindModuleInSearchPath(_typeStubPaths, null, name); + if (mp != null) { + if (mp.Value.IsCompiled) { + _log?.Log(TraceEventType.Warning, "Unsupported native module in stubs", mp.Value.FullName, mp.Value.SourceFile); + return null; + } + return await CreateStubModuleAsync(mp.Value.FullName, mp.Value.SourceFile, cancellationToken); + } + + var i = name.IndexOf('.'); + if (i == 0) { + Debug.Fail("Invalid module name"); + return null; + } + + var stubPath = CurrentPathResolver.GetPossibleModuleStubPaths(name).FirstOrDefault(p => _fs.FileExists(p)); + return stubPath != null ? await CreateStubModuleAsync(name, stubPath, cancellationToken) : null; + } + + private async Task CreateStubModuleAsync(string moduleName, string filePath, CancellationToken cancellationToken = default) { + _log?.Log(TraceEventType.Verbose, "Import type stub", moduleName, filePath); + var module = new StubPythonModule(moduleName, filePath, _services); + await module.LoadAndAnalyzeAsync(cancellationToken); + return module; + } + + private ModulePath? FindModuleInSearchPath(IReadOnlyList searchPaths, IReadOnlyDictionary packages, string name) { + if (searchPaths == null || searchPaths.Count == 0) { + return null; + } + + _log?.Log(TraceEventType.Verbose, "FindModule", name, "system", string.Join(", ", searchPaths)); + + var i = name.IndexOf('.'); + var firstBit = i < 0 ? name : name.Remove(i); + + ModulePath mp; + Func isPackage = IsPackage; + if (firstBit.EndsWithOrdinal("-stubs", ignoreCase: true)) { + isPackage = _fs.DirectoryExists; + } + + var requireInitPy = ModulePath.PythonVersionRequiresInitPyFiles(Configuration.Version); + if (packages != null && packages.TryGetValue(firstBit, out var searchPath) && !string.IsNullOrEmpty(searchPath)) { + if (ModulePath.FromBasePathAndName_NoThrow(searchPath, name, isPackage, null, requireInitPy, out mp, out _, out _, out _)) { + return mp; + } + } + + foreach (var sp in searchPaths.MaybeEnumerate()) { + if (ModulePath.FromBasePathAndName_NoThrow(sp, name, isPackage, null, requireInitPy, out mp, out _, out _, out _)) { + return mp; + } + } + + return null; + } + + private async Task> GetModuleStubsAsync(string moduleName, string modulePath, CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + + // Also search for type stub packages if enabled and we are not a blacklisted module + if (_typeStubPaths.Count > 0 && moduleName != "typing") { + var tsModule = await ImportFromTypeStubsAsync(moduleName, cancellationToken); + if (tsModule != null) { + // TODO: What about custom stub files? + return new[] { tsModule }; + } + } + return Array.Empty(); + } + + private IEnumerable GetTypeShedPaths(string typeshedRootPath) { + if (string.IsNullOrEmpty(typeshedRootPath)) { + yield break; + } + + var stdlib = Path.Combine(typeshedRootPath, "stdlib"); + var thirdParty = Path.Combine(typeshedRootPath, "third_party"); + + var v = Configuration.Version; + foreach (var subdir in new[] { v.ToString(), v.Major.ToString(), "2and3" }) { + yield return Path.Combine(stdlib, subdir); + } + + foreach (var subdir in new[] { v.ToString(), v.Major.ToString(), "2and3" }) { + yield return Path.Combine(thirdParty, subdir); + } + } + + private static IReadOnlyCollection GetPackagesFromZipFile(string searchPath, CancellationToken cancellationToken) { + // TODO: Search zip files for packages + return new string[0]; + } + + private void ReloadModulePaths(in IEnumerable rootPaths) { + foreach (var modulePath in rootPaths.Where(Directory.Exists).SelectMany(p => PathUtils.EnumerateFiles(p))) { + _pathResolver.TryAddModulePath(modulePath, out _); + } + } + + // For tests + internal void AddUnimportableModule(string moduleName) + => _modules[moduleName] = new SentinelModule(moduleName, _services); + } +} diff --git a/src/Analysis/Ast/Impl/Modules/PythonModule.cs b/src/Analysis/Ast/Impl/Modules/PythonModule.cs new file mode 100644 index 000000000..60bc74cae --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/PythonModule.cs @@ -0,0 +1,505 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Analyzer; +using Microsoft.Python.Analysis.Diagnostics; +using Microsoft.Python.Analysis.Documents; +using Microsoft.Python.Analysis.Extensions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Logging; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Modules { + /// + /// Primary base for all modules and user documents. Provides access + /// to AST and the module analysis. + /// + [DebuggerDisplay("{Name} : {ModuleType}")] + public class PythonModule : IDocument, IAnalyzable, IDisposable, IEquatable { + private readonly DocumentBuffer _buffer = new DocumentBuffer(); + private readonly CancellationTokenSource _allProcessingCts = new CancellationTokenSource(); + private IReadOnlyList _parseErrors = Array.Empty(); + + private ModuleLoadOptions _options; + private string _documentation = string.Empty; + + private TaskCompletionSource _analysisTcs; + private CancellationTokenSource _linkedAnalysisCts; // cancellation token combined with the 'dispose' cts + private CancellationTokenSource _parseCts; + private CancellationTokenSource _linkedParseCts; // combined with 'dispose' cts + private Task _parsingTask; + private PythonAst _ast; + private bool _loaded; + + protected ILogger Log { get; } + protected IFileSystem FileSystem { get; } + protected IServiceContainer Services { get; } + protected IDocumentAnalysis Analysis { get; private set; } = DocumentAnalysis.Empty; + protected object AnalysisLock { get; } = new object(); + + protected PythonModule(string name, ModuleType moduleType, IServiceContainer services) { + Check.ArgumentNotNull(nameof(name), name); + Name = name; + Services = services; + ModuleType = moduleType; + + Log = services?.GetService(); + Interpreter = services?.GetService(); + } + + protected PythonModule(string moduleName, string filePath, ModuleType moduleType, ModuleLoadOptions loadOptions, IPythonModule stub, IServiceContainer services) : + this(new ModuleCreationOptions { + ModuleName = moduleName, + FilePath = filePath, + ModuleType = moduleType, + Stub = stub, + LoadOptions = loadOptions + }, services) { } + + internal PythonModule(ModuleCreationOptions creationOptions, IServiceContainer services) + : this(creationOptions.ModuleName, creationOptions.ModuleType, services) { + Check.ArgumentNotNull(nameof(services), services); + + FileSystem = services.GetService(); + Location = new LocationInfo(creationOptions.FilePath, creationOptions.Uri, 1, 1); + + var uri = creationOptions.Uri; + if (uri == null && !string.IsNullOrEmpty(creationOptions.FilePath)) { + Uri.TryCreate(creationOptions.FilePath, UriKind.Absolute, out uri); + } + Uri = uri; + FilePath = creationOptions.FilePath ?? uri?.LocalPath; + Stub = creationOptions.Stub; + + InitializeContent(creationOptions.Content, creationOptions.LoadOptions); + } + + #region IPythonType + public string Name { get; } + public virtual IPythonModule DeclaringModule => null; + public BuiltinTypeId TypeId => BuiltinTypeId.Module; + public bool IsBuiltin => true; + public bool IsAbstract => false; + public virtual bool IsSpecialized => false; + + public IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) => this; + public PythonMemberType MemberType => PythonMemberType.Module; + public IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) => GetMember(memberName); + public IMember Index(IPythonInstance instance, object index) => Interpreter.UnknownType; + + public virtual string Documentation { + get { + _documentation = _documentation ?? _ast?.Documentation; + if (_documentation == null) { + var m = GetMember("__doc__"); + _documentation = m.TryGetConstant(out var s) ? s : string.Empty; + if (string.IsNullOrEmpty(_documentation)) { + m = GetMember($"_{Name}"); + _documentation = m?.GetPythonType()?.Documentation; + if (string.IsNullOrEmpty(_documentation)) { + _documentation = TryGetDocFromModuleInitFile(); + } + } + } + return _documentation; + } + } + + #endregion + + #region IMemberContainer + public virtual IMember GetMember(string name) => Analysis.GlobalScope.Variables[name]?.Value; + public virtual IEnumerable GetMemberNames() => Analysis.GlobalScope.Variables.Names; + #endregion + + #region IPythonFile + public virtual string FilePath { get; } + public virtual Uri Uri { get; } + #endregion + + #region IPythonModule + public IPythonInterpreter Interpreter { get; } + + /// + /// Associated stub module. Note that in case of specialized modules + /// stub may be actually a real module that is being specialized in code. + /// + public IPythonModule Stub { get; } + + /// + /// Global cope of the module. + /// + public IGlobalScope GlobalScope { get; private set; } + + /// + /// Ensures that module content is loaded and analysis has started. + /// Typically module content is loaded at the creation time, but delay + /// loaded (lazy) modules may choose to defer content retrieval and + /// analysis until later time, when module members are actually needed. + /// + public virtual Task LoadAndAnalyzeAsync(CancellationToken cancellationToken = default) { + InitializeContent(null, ModuleLoadOptions.Analyze); + return GetAnalysisAsync(cancellationToken); + } + + protected virtual string LoadContent(ModuleLoadOptions options) { + if (options.ShouldLoad() && ModuleType != ModuleType.Unresolved) { + return FileSystem.ReadAllText(FilePath); + } + return null; // Keep content as null so module can be loaded later. + } + + private void InitializeContent(string content, ModuleLoadOptions newOptions) { + lock (AnalysisLock) { + if (!_loaded) { + if (!newOptions.ShouldLoad()) { + return; + } + content = content ?? LoadContent(newOptions); + _buffer.Reset(0, content); + _loaded = true; + } + + IsOpen = (newOptions & ModuleLoadOptions.Open) == ModuleLoadOptions.Open; + newOptions = newOptions | (IsOpen ? ModuleLoadOptions.Analyze : 0); + + var change = (_options ^ newOptions); + var startAnalysis = change.ShouldAnalyze() && _analysisTcs?.Task == null; + var startParse = change.ShouldParse() && _parsingTask == null; + + _options = newOptions; + + if (startAnalysis) { + _analysisTcs = new TaskCompletionSource(); + } + + if (startParse) { + Parse(); + } + } + } + #endregion + + #region ILocatedMember + public virtual LocationInfo Location { get; } + #endregion + + #region IDisposable + public void Dispose() => Dispose(true); + + protected virtual void Dispose(bool disposing) { + _allProcessingCts.Cancel(); + _allProcessingCts.Dispose(); + } + #endregion + + #region IDocument + public event EventHandler NewAst; + public event EventHandler NewAnalysis; + + /// + /// Module content version (increments after every change). + /// + public int Version => _buffer.Version; + + /// + /// Indicates that the document is open in the editor. + /// + public bool IsOpen { get; set; } + + /// + /// Module type (user, library, stub). + /// + public ModuleType ModuleType { get; } + + /// + /// Returns module content (code). + /// + public string Content => _buffer.Text; + #endregion + + #region Parsing + /// + /// Returns document parse tree. + /// + public async Task GetAstAsync(CancellationToken cancellationToken = default) { + Task t = null; + while (t != _parsingTask) { + cancellationToken.ThrowIfCancellationRequested(); + t = _parsingTask; + try { + await t; + break; + } catch (OperationCanceledException) { + // Parsing as canceled, try next task. + } + } + cancellationToken.ThrowIfCancellationRequested(); + return _ast; + } + + public PythonAst GetAnyAst() => _ast; + + /// + /// Provides collection of parsing errors, if any. + /// + public IEnumerable GetParseErrors() => _parseErrors.ToArray(); + + public void Update(IEnumerable changes) { + lock (AnalysisLock) { + ExpectedAnalysisVersion++; + + _linkedAnalysisCts?.Cancel(); + _analysisTcs = new TaskCompletionSource(); + + _parseCts?.Cancel(); + _parseCts = new CancellationTokenSource(); + + _linkedParseCts?.Dispose(); + _linkedParseCts = CancellationTokenSource.CreateLinkedTokenSource(_allProcessingCts.Token, _parseCts.Token); + + _buffer.Update(changes); + Parse(); + } + } + + private void Parse() { + _parseCts?.Cancel(); + _parseCts = new CancellationTokenSource(); + _linkedParseCts?.Dispose(); + _linkedParseCts = CancellationTokenSource.CreateLinkedTokenSource(_allProcessingCts.Token, _parseCts.Token); + _parsingTask = Task.Run(() => Parse(_linkedParseCts.Token), _linkedParseCts.Token); + } + + private void Parse(CancellationToken cancellationToken) { + var sink = new CollectingErrorSink(); + int version; + Parser parser; + + Log?.Log(TraceEventType.Verbose, $"Parse begins: {Name}"); + + lock (AnalysisLock) { + version = _buffer.Version; + parser = Parser.CreateParser(new StringReader(_buffer.Text), Interpreter.LanguageVersion, new ParserOptions { + StubFile = FilePath != null && Path.GetExtension(FilePath).Equals(".pyi", FileSystem.StringComparison), + ErrorSink = sink + }); + } + + var ast = parser.ParseFile(); + + Log?.Log(TraceEventType.Verbose, $"Parse complete: {Name}"); + + lock (AnalysisLock) { + cancellationToken.ThrowIfCancellationRequested(); + if (version != _buffer.Version) { + throw new OperationCanceledException(); + } + _ast = ast; + _parseErrors = sink.Diagnostics; + _parsingTask = null; + } + + NewAst?.Invoke(this, EventArgs.Empty); + + if ((_options & ModuleLoadOptions.Analyze) == ModuleLoadOptions.Analyze) { + Log?.Log(TraceEventType.Verbose, $"Analysis queued: {Name}"); + + _linkedAnalysisCts?.Dispose(); + _linkedAnalysisCts = CancellationTokenSource.CreateLinkedTokenSource(_allProcessingCts.Token, cancellationToken); + + var analyzer = Services.GetService(); + if (ModuleType == ModuleType.User || ModuleType == ModuleType.Library) { + analyzer.AnalyzeDocumentDependencyChainAsync(this, _linkedAnalysisCts.Token).DoNotWait(); + } else { + analyzer.AnalyzeDocumentAsync(this, _linkedAnalysisCts.Token).DoNotWait(); + } + } + } + + private class CollectingErrorSink : ErrorSink { + private readonly List _diagnostics = new List(); + + public IReadOnlyList Diagnostics => _diagnostics; + public override void Add(string message, SourceSpan span, int errorCode, Severity severity) + => _diagnostics.Add(new DiagnosticsEntry(message, span, $"parser-{errorCode}", severity)); + } + #endregion + + #region IAnalyzable + /// + /// Expected version of the analysis when asynchronous operations complete. + /// Typically every change to the document or documents that depend on it + /// increment the expected version. At the end of the analysis if the expected + /// version is still the same, the analysis is applied to the document and + /// becomes available to consumers. + /// + public int ExpectedAnalysisVersion { get; private set; } + + /// + /// Notifies document that analysis is now pending. Typically document increments + /// the expected analysis version. The method can be called repeatedly without + /// calling `CompleteAnalysis` first. The method is invoked for every dependency + /// in the chain to ensure that objects know that their dependencies have been + /// modified and the current analysis is no longer up to date. + /// + public void NotifyAnalysisPending() { + lock (AnalysisLock) { + // The notification comes from the analyzer when it needs to invalidate + // current analysis since one of the dependencies changed. Upon text + // buffer change the version may be incremented twice - once in Update() + // and then here. This is normal. + ExpectedAnalysisVersion++; + _analysisTcs = _analysisTcs ?? new TaskCompletionSource(); + Log?.Log(TraceEventType.Verbose, $"Analysis pending: {Name}"); + } + } + + public virtual bool NotifyAnalysisComplete(IDocumentAnalysis analysis) { + lock (AnalysisLock) { + Log?.Log(TraceEventType.Verbose, $"Analysis complete: {Name}, Version: {analysis.Version}, Expected: {ExpectedAnalysisVersion}"); + if (analysis.Version == ExpectedAnalysisVersion) { + Analysis = analysis; + // Derived classes can override OnAnalysisComplete if they want + // to perform additional actions on the completed analysis such + // as declare additional variables, etc. + OnAnalysisComplete(); + _analysisTcs.TrySetResult(analysis); + _analysisTcs = null; + + GlobalScope = analysis.GlobalScope; + NewAnalysis?.Invoke(this, EventArgs.Empty); + return true; + } + Debug.Assert(ExpectedAnalysisVersion > analysis.Version); + return false; + } + } + + protected virtual void OnAnalysisComplete() { } + #endregion + + #region Analysis + public IDocumentAnalysis GetAnyAnalysis() => Analysis; + + public Task GetAnalysisAsync(CancellationToken cancellationToken = default) { + lock (AnalysisLock) { + if ((_options & ModuleLoadOptions.Analyze) != ModuleLoadOptions.Analyze) { + return Task.FromResult(DocumentAnalysis.Empty); + } + return Analysis.Version == ExpectedAnalysisVersion ? Task.FromResult(Analysis) : _analysisTcs.Task; + } + } + #endregion + + private string TryGetDocFromModuleInitFile() { + if (string.IsNullOrEmpty(FilePath) || !FileSystem.FileExists(FilePath)) { + return string.Empty; + } + + try { + using (var sr = new StreamReader(FilePath)) { + string quote = null; + string line; + while (true) { + line = sr.ReadLine()?.Trim(); + if (line == null) { + break; + } + if (line.Length == 0 || line.StartsWithOrdinal("#")) { + continue; + } + if (line.StartsWithOrdinal("\"\"\"") || line.StartsWithOrdinal("r\"\"\"")) { + quote = "\"\"\""; + } else if (line.StartsWithOrdinal("'''") || line.StartsWithOrdinal("r'''")) { + quote = "'''"; + } + break; + } + + if (quote != null) { + // Check if it is a single-liner + if (line.EndsWithOrdinal(quote) && line.IndexOf(quote, StringComparison.Ordinal) < line.LastIndexOf(quote, StringComparison.Ordinal)) { + return line.Substring(quote.Length, line.Length - 2 * quote.Length).Trim(); + } + var sb = new StringBuilder(); + while (true) { + line = sr.ReadLine(); + if (line == null || line.EndsWithOrdinal(quote)) { + break; + } + sb.AppendLine(line); + } + return sb.ToString(); + } + } + } catch (IOException) { } catch (UnauthorizedAccessException) { } + return string.Empty; + } + + /// + /// Provides ability to specialize function return type manually. + /// + protected void SpecializeFunction(string name, IMember returnValue) { + var f = GetOrCreateFunction(name); + if (f != null) { + foreach (var o in f.Overloads.OfType()) { + o.SetReturnValue(returnValue, true); + } + } + } + + /// + /// Provides ability to dynamically calculate function return type. + /// + internal void SpecializeFunction(string name, ReturnValueProvider returnTypeCallback) { + var f = GetOrCreateFunction(name); + if (f != null) { + foreach (var o in f.Overloads.OfType()) { + o.SetReturnValueProvider(returnTypeCallback); + } + f.Specialize(); + } + } + + private PythonFunctionType GetOrCreateFunction(string name) { + var f = Analysis.GlobalScope.Variables[name]?.Value as PythonFunctionType; + // We DO want to replace class by function. Consider type() in builtins. + // 'type()' in code is a function call, not a type class instantiation. + if (f == null) { + f = PythonFunctionType.ForSpecialization(name, this); + f.AddOverload(new PythonFunctionOverload(name, this, LocationInfo.Empty)); + Analysis.GlobalScope.DeclareVariable(name, f, LocationInfo.Empty); + } + return f; + } + + public bool Equals(IPythonModule other) => Name.Equals(other?.Name) && FilePath.Equals(other?.FilePath); + } +} diff --git a/src/Analysis/Ast/Impl/Modules/PythonPackage.cs b/src/Analysis/Ast/Impl/Modules/PythonPackage.cs new file mode 100644 index 000000000..c0afd16c2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/PythonPackage.cs @@ -0,0 +1,51 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Modules { + /// + /// Represents package with child modules. Typically + /// used in scenarios such as 'import a.b.c'. + /// + internal sealed class PythonPackage : PythonModule, IPythonPackage { + private readonly ConcurrentDictionary _childModules = new ConcurrentDictionary(); + + public PythonPackage(string name, IServiceContainer services) + : base(name, ModuleType.Package, services) { } + + public void AddChildModule(string name, IPythonModule module) { + if (!_childModules.ContainsKey(name)) { + _childModules[name] = module; + } + } + + public override IEnumerable GetMemberNames() => _childModules.Keys.ToArray(); + public override IMember GetMember(string name) => _childModules.TryGetValue(name, out var v) ? v : null; + public IEnumerable GetChildrenModuleNames() => GetMemberNames(); + + protected override void OnAnalysisComplete() { + foreach (var childModuleName in GetChildrenModuleNames()) { + var name = $"{Name}.{childModuleName}"; + Analysis.GlobalScope.DeclareVariable(name, this, LocationInfo.Empty); + } + base.OnAnalysisComplete(); + } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/SentinelModule.cs b/src/Analysis/Ast/Impl/Modules/SentinelModule.cs new file mode 100644 index 000000000..9eca1e39e --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/SentinelModule.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Modules { + internal sealed class SentinelModule : PythonModule { + public SentinelModule(string name, IServiceContainer services) + : base(name, ModuleType.Unresolved, services) { } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/SpecializedModule.cs b/src/Analysis/Ast/Impl/Modules/SpecializedModule.cs new file mode 100644 index 000000000..77fe8e2db --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/SpecializedModule.cs @@ -0,0 +1,45 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.IO; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Modules { + /// + /// Base class for specialized modules. Specialized modules are implementations + /// that replace real Python module in imports. Content is loaded from the + /// original module and analyzed only for the class/functions documentation. + /// + /// + /// Specialization is helpful when it is easier to express module members + /// behavior to the analyzer in code. Example of specialization is 'typing' + /// module. Specialized module can use actual library module as a source + /// of documentation for its members. See . + /// + public abstract class SpecializedModule : PythonModule { + protected SpecializedModule(string name, string modulePath, IServiceContainer services) + : base(name, modulePath, ModuleType.Specialized, ModuleLoadOptions.Analyze, null, services) { } + + protected override string LoadContent(ModuleLoadOptions options) { + try { + if (FileSystem.FileExists(FilePath)) { + return FileSystem.ReadAllText(FilePath); + } + } catch (IOException) { } catch (UnauthorizedAccessException) { } + return string.Empty; + } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/StubPythonModule.cs b/src/Analysis/Ast/Impl/Modules/StubPythonModule.cs new file mode 100644 index 000000000..0d2a8f51d --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/StubPythonModule.cs @@ -0,0 +1,43 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Modules { + /// + /// Represents module that contains stub code such as from typeshed. + /// + internal class StubPythonModule : CompiledPythonModule { + public StubPythonModule(string moduleName, string stubPath, IServiceContainer services) + : base(moduleName, ModuleType.Stub, stubPath, null, services) { + } + + protected override string LoadContent(ModuleLoadOptions options) { + try { + if (FileSystem.FileExists(FilePath) && (options & ModuleLoadOptions.Load) == ModuleLoadOptions.Load) { + return FileSystem.ReadAllText(FilePath); + } + } catch (IOException) { } catch(UnauthorizedAccessException) { } + return string.Empty; + } + + protected override IEnumerable GetScrapeArguments(IPythonInterpreter factory) => Enumerable.Empty(); + protected override void SaveCachedCode(string code) { } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/TryImportModuleContext.cs b/src/Analysis/Ast/Impl/Modules/TryImportModuleContext.cs new file mode 100644 index 000000000..6ecd7fab6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/TryImportModuleContext.cs @@ -0,0 +1,33 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Modules { + public sealed class TryImportModuleContext { + public IPythonInterpreter Interpreter { get; set; } + public ConcurrentDictionary ModuleCache { get; set; } + public IPythonModule BuiltinModule { get; set; } + public Func> FindModuleInUserSearchPathAsync { get; set; } + public IReadOnlyList TypeStubPaths { get; set; } + public bool MergeTypeStubPackages { get; set; } + } +} diff --git a/src/Analysis/Ast/Impl/Modules/TryImportModuleResult.cs b/src/Analysis/Ast/Impl/Modules/TryImportModuleResult.cs new file mode 100644 index 000000000..ccb00d243 --- /dev/null +++ b/src/Analysis/Ast/Impl/Modules/TryImportModuleResult.cs @@ -0,0 +1,47 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Modules { + public enum TryImportModuleResultCode { + Success, + ModuleNotFound, + NeedRetry, + NotSupported, + Timeout + } + + public struct TryImportModuleResult { + public readonly TryImportModuleResultCode Status; + public readonly IPythonModule Module; + + public TryImportModuleResult(IPythonModule module) { + Status = module == null ? TryImportModuleResultCode.ModuleNotFound : TryImportModuleResultCode.Success; + Module = module; + } + + public TryImportModuleResult(TryImportModuleResultCode status) { + Status = status; + Module = null; + } + + public static TryImportModuleResult ModuleNotFound => new TryImportModuleResult(TryImportModuleResultCode.ModuleNotFound); + public static TryImportModuleResult NeedRetry => new TryImportModuleResult(TryImportModuleResultCode.NeedRetry); + public static TryImportModuleResult NotSupported => new TryImportModuleResult(TryImportModuleResultCode.NotSupported); + public static TryImportModuleResult Timeout => new TryImportModuleResult(TryImportModuleResultCode.Timeout); + } + +} diff --git a/src/Analysis/Ast/Impl/Properties/AssemblyInfo.cs b/src/Analysis/Ast/Impl/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..cfcc08c5c --- /dev/null +++ b/src/Analysis/Ast/Impl/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.Python.Analysis.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/src/Analysis/Ast/Impl/Resources.Designer.cs b/src/Analysis/Ast/Impl/Resources.Designer.cs new file mode 100644 index 000000000..89bef1d20 --- /dev/null +++ b/src/Analysis/Ast/Impl/Resources.Designer.cs @@ -0,0 +1,715 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.Python.Analysis { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Python.Analysis.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Parameter {0} already specified.. + /// + internal static string Analysis_ParameterAlreadySpecified { + get { + return ResourceManager.GetString("Analysis_ParameterAlreadySpecified", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Parameter {0} is missing.. + /// + internal static string Analysis_ParameterMissing { + get { + return ResourceManager.GetString("Analysis_ParameterMissing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Positional arguments are not allowed after keyword argument.. + /// + internal static string Analysis_PositionalArgumentAfterKeyword { + get { + return ResourceManager.GetString("Analysis_PositionalArgumentAfterKeyword", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Too many function arguments.. + /// + internal static string Analysis_TooManyFunctionArguments { + get { + return ResourceManager.GetString("Analysis_TooManyFunctionArguments", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Too many positional arguments before '*' argument.. + /// + internal static string Analysis_TooManyPositionalArgumentBeforeStar { + get { + return ResourceManager.GetString("Analysis_TooManyPositionalArgumentBeforeStar", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Unknown parameter name.. + /// + internal static string Analysis_UnknownParameterName { + get { + return ResourceManager.GetString("Analysis_UnknownParameterName", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, statements separated by semicolons are moved onto individual lines. If unchecked, lines with multiple statements are not modified.. + /// + internal static string BreakMultipleStatementsPerLineLong { + get { + return ResourceManager.GetString("BreakMultipleStatementsPerLineLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Place statements on separate lines. + /// + internal static string BreakMultipleStatementsPerLineShort { + get { + return ResourceManager.GetString("BreakMultipleStatementsPerLineShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Documentation is still being calculated, please try again soon.. + /// + internal static string CalculatingDocumentation { + get { + return ResourceManager.GetString("CalculatingDocumentation", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to '{0}' may not be callable. + /// + internal static string ErrorNotCallable { + get { + return ResourceManager.GetString("ErrorNotCallable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to object may not be callable. + /// + internal static string ErrorNotCallableEmpty { + get { + return ResourceManager.GetString("ErrorNotCallableEmpty", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to unresolved import '{0}'. + /// + internal static string ErrorUnresolvedImport { + get { + return ResourceManager.GetString("ErrorUnresolvedImport", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to '{0}' used before definition. + /// + internal static string ErrorUseBeforeDef { + get { + return ResourceManager.GetString("ErrorUseBeforeDef", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The number of empty lines to include between class or function declarations at the top level of a module.. + /// + internal static string LinesBetweenLevelDeclarationsLong { + get { + return ResourceManager.GetString("LinesBetweenLevelDeclarationsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lines between top-level declarations. + /// + internal static string LinesBetweenLevelDeclarationsShort { + get { + return ResourceManager.GetString("LinesBetweenLevelDeclarationsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The number of empty lines to insert between method or class declarations within a class.. + /// + internal static string LinesBetweenMethodsInClassLong { + get { + return ResourceManager.GetString("LinesBetweenMethodsInClassLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Lines between class member declarations. + /// + internal static string LinesBetweenMethodsInClassShort { + get { + return ResourceManager.GetString("LinesBetweenMethodsInClassShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to property of type {0}. + /// + internal static string PropertyOfType { + get { + return ResourceManager.GetString("PropertyOfType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to property of unknown type. + /// + internal static string PropertyOfUnknownType { + get { + return ResourceManager.GetString("PropertyOfUnknownType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, removes blank lines between methods and inserts the number specified below. Otherwise, lines between methods are not modified.. + /// + internal static string RemoveExtraLinesBetweenMethodsLong { + get { + return ResourceManager.GetString("RemoveExtraLinesBetweenMethodsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Remove blank lines between methods. + /// + internal static string RemoveExtraLinesBetweenMethodsShort { + get { + return ResourceManager.GetString("RemoveExtraLinesBetweenMethodsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, semicolons at the end of lines will be removed. If unchecked, unnecessary semicolons are not modified.. + /// + internal static string RemoveTrailingSemicolonsLong { + get { + return ResourceManager.GetString("RemoveTrailingSemicolonsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Remove unnecessary semicolons. + /// + internal static string RemoveTrailingSemicolonsShort { + get { + return ResourceManager.GetString("RemoveTrailingSemicolonsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, import statements with multiple modules are separated onto individual lines. If unchecked, import statements with multiple modules are not modified.. + /// + internal static string ReplaceMultipleImportsWithMultipleStatementsLong { + get { + return ResourceManager.GetString("ReplaceMultipleImportsWithMultipleStatementsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Place imported modules on new line. + /// + internal static string ReplaceMultipleImportsWithMultipleStatementsShort { + get { + return ResourceManager.GetString("ReplaceMultipleImportsWithMultipleStatementsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added before and after '->' operators in function definitions. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceAroundAnnotationArrowLong { + get { + return ResourceManager.GetString("SpaceAroundAnnotationArrowLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space before and after return annotation operators. + /// + internal static string SpaceAroundAnnotationArrowShort { + get { + return ResourceManager.GetString("SpaceAroundAnnotationArrowShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added before and after '=' operators in function definitions. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceAroundDefaultValueEqualsLong { + get { + return ResourceManager.GetString("SpaceAroundDefaultValueEqualsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert spaces around '=' in default parameter values. + /// + internal static string SpaceAroundDefaultValueEqualsShort { + get { + return ResourceManager.GetString("SpaceAroundDefaultValueEqualsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added between the name and opening parenthesis of the argument list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceBeforeCallParenLong { + get { + return ResourceManager.GetString("SpaceBeforeCallParenLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space between the function name and argument list in calls. + /// + internal static string SpaceBeforeCallParenShort { + get { + return ResourceManager.GetString("SpaceBeforeCallParenShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added between the name and opening parenthesis of the bases list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceBeforeClassDeclarationParenLong { + get { + return ResourceManager.GetString("SpaceBeforeClassDeclarationParenLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space between a class name and bases list. + /// + internal static string SpaceBeforeClassDeclarationParenShort { + get { + return ResourceManager.GetString("SpaceBeforeClassDeclarationParenShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added between the name and opening parenthesis of the parameter list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceBeforeFunctionDeclarationParenLong { + get { + return ResourceManager.GetString("SpaceBeforeFunctionDeclarationParenLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space between a function name and parameter list in declarations. + /// + internal static string SpaceBeforeFunctionDeclarationParenShort { + get { + return ResourceManager.GetString("SpaceBeforeFunctionDeclarationParenShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added before an open square bracket. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceBeforeIndexBracketLong { + get { + return ResourceManager.GetString("SpaceBeforeIndexBracketLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space before open square bracket. + /// + internal static string SpaceBeforeIndexBracketShort { + get { + return ResourceManager.GetString("SpaceBeforeIndexBracketShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added before and after '=' operators in assignments. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpacesAroundAssignmentOperatorLong { + get { + return ResourceManager.GetString("SpacesAroundAssignmentOperatorLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert spaces around assignments. + /// + internal static string SpacesAroundAssignmentOperatorShort { + get { + return ResourceManager.GetString("SpacesAroundAssignmentOperatorShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added before and after binary operators. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpacesAroundBinaryOperatorsLong { + get { + return ResourceManager.GetString("SpacesAroundBinaryOperatorsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert spaces around binary operators. + /// + internal static string SpacesAroundBinaryOperatorsShort { + get { + return ResourceManager.GetString("SpacesAroundBinaryOperatorsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added between the open square bracket and the close square bracket. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpacesWithinEmptyListExpressionLong { + get { + return ResourceManager.GetString("SpacesWithinEmptyListExpressionLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within empty square brackets. + /// + internal static string SpacesWithinEmptyListExpressionShort { + get { + return ResourceManager.GetString("SpacesWithinEmptyListExpressionShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open square bracket and before the close square bracket of the list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpacesWithinListExpressionLong { + get { + return ResourceManager.GetString("SpacesWithinListExpressionLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert spaces within square brackets of lists. + /// + internal static string SpacesWithinListExpressionShort { + get { + return ResourceManager.GetString("SpacesWithinListExpressionShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of the tuple. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpacesWithinParenthesisedTupleExpressionLong { + get { + return ResourceManager.GetString("SpacesWithinParenthesisedTupleExpressionLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within tuple parentheses. + /// + internal static string SpacesWithinParenthesisedTupleExpressionShort { + get { + return ResourceManager.GetString("SpacesWithinParenthesisedTupleExpressionShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of an expression. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpacesWithinParenthesisExpressionLong { + get { + return ResourceManager.GetString("SpacesWithinParenthesisExpressionLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within parentheses of expression. + /// + internal static string SpacesWithinParenthesisExpressionShort { + get { + return ResourceManager.GetString("SpacesWithinParenthesisExpressionShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of an argument list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinCallParensLong { + get { + return ResourceManager.GetString("SpaceWithinCallParensLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within argument list parentheses. + /// + internal static string SpaceWithinCallParensShort { + get { + return ResourceManager.GetString("SpaceWithinCallParensShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of a bases list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinClassDeclarationParensLong { + get { + return ResourceManager.GetString("SpaceWithinClassDeclarationParensLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within bases list parentheses. + /// + internal static string SpaceWithinClassDeclarationParensShort { + get { + return ResourceManager.GetString("SpaceWithinClassDeclarationParensShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of an empty bases list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinEmptyBaseClassListLong { + get { + return ResourceManager.GetString("SpaceWithinEmptyBaseClassListLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within empty bases list parentheses. + /// + internal static string SpaceWithinEmptyBaseClassListShort { + get { + return ResourceManager.GetString("SpaceWithinEmptyBaseClassListShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of an empty argument list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinEmptyCallArgumentListLong { + get { + return ResourceManager.GetString("SpaceWithinEmptyCallArgumentListLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within empty argument list parentheses. + /// + internal static string SpaceWithinEmptyCallArgumentListShort { + get { + return ResourceManager.GetString("SpaceWithinEmptyCallArgumentListShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of an empty parameter list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinEmptyParameterListLong { + get { + return ResourceManager.GetString("SpaceWithinEmptyParameterListLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within empty parameter list parentheses. + /// + internal static string SpaceWithinEmptyParameterListShort { + get { + return ResourceManager.GetString("SpaceWithinEmptyParameterListShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of an empty tuple. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinEmptyTupleExpressionLong { + get { + return ResourceManager.GetString("SpaceWithinEmptyTupleExpressionLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within empty tuple parentheses. + /// + internal static string SpaceWithinEmptyTupleExpressionShort { + get { + return ResourceManager.GetString("SpaceWithinEmptyTupleExpressionShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open parenthesis and before the close parenthesis of a parameter list. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinFunctionDeclarationParensLong { + get { + return ResourceManager.GetString("SpaceWithinFunctionDeclarationParensLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within parameter list parentheses. + /// + internal static string SpaceWithinFunctionDeclarationParensShort { + get { + return ResourceManager.GetString("SpaceWithinFunctionDeclarationParensShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, a space is added after the open square bracket and before the close square bracket. If unchecked, spaces are removed. Otherwise, spaces are not modified.. + /// + internal static string SpaceWithinIndexBracketsLong { + get { + return ResourceManager.GetString("SpaceWithinIndexBracketsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Insert space within square brackets. + /// + internal static string SpaceWithinIndexBracketsShort { + get { + return ResourceManager.GetString("SpaceWithinIndexBracketsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to If checked, comments are wrapped to the specified width. If unchecked, comments are not modified.. + /// + internal static string WrapCommentsLong { + get { + return ResourceManager.GetString("WrapCommentsLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to # Not wrapped: + ///# There should be one-- and preferably only one --obvious way to do it.. + /// + internal static string WrapCommentsLong_Example { + get { + return ResourceManager.GetString("WrapCommentsLong_Example", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wrap comments that are too wide. + /// + internal static string WrapCommentsShort { + get { + return ResourceManager.GetString("WrapCommentsShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to # Wrapped to 40 columns: + ///# There should be one-- and preferably + ///# only one --obvious way to do it.. + /// + internal static string WrapCommentsShort_Example { + get { + return ResourceManager.GetString("WrapCommentsShort_Example", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to # Sets the width for wrapping comments + ///# and documentation strings.. + /// + internal static string WrappingWidth_Doc { + get { + return ResourceManager.GetString("WrappingWidth_Doc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The number of the last column that should include comment text. Words after this column are moved to the following line.. + /// + internal static string WrappingWidthLong { + get { + return ResourceManager.GetString("WrappingWidthLong", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Maximum comment width. + /// + internal static string WrappingWidthShort { + get { + return ResourceManager.GetString("WrappingWidthShort", resourceCulture); + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Resources.resx b/src/Analysis/Ast/Impl/Resources.resx new file mode 100644 index 000000000..10cd30723 --- /dev/null +++ b/src/Analysis/Ast/Impl/Resources.resx @@ -0,0 +1,342 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + If checked, statements separated by semicolons are moved onto individual lines. If unchecked, lines with multiple statements are not modified. + + + Place statements on separate lines + + + The number of empty lines to include between class or function declarations at the top level of a module. + + + Lines between top-level declarations + + + The number of empty lines to insert between method or class declarations within a class. + + + Lines between class member declarations + + + If checked, removes blank lines between methods and inserts the number specified below. Otherwise, lines between methods are not modified. + + + Remove blank lines between methods + + + If checked, semicolons at the end of lines will be removed. If unchecked, unnecessary semicolons are not modified. + + + Remove unnecessary semicolons + + + If checked, import statements with multiple modules are separated onto individual lines. If unchecked, import statements with multiple modules are not modified. + + + Place imported modules on new line + + + If checked, a space is added before and after '->' operators in function definitions. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space before and after return annotation operators + + + If checked, a space is added before and after '=' operators in function definitions. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert spaces around '=' in default parameter values + + + If checked, a space is added between the name and opening parenthesis of the argument list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space between the function name and argument list in calls + + + If checked, a space is added between the name and opening parenthesis of the bases list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space between a class name and bases list + + + If checked, a space is added between the name and opening parenthesis of the parameter list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space between a function name and parameter list in declarations + + + If checked, a space is added before an open square bracket. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space before open square bracket + + + If checked, a space is added before and after '=' operators in assignments. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert spaces around assignments + + + If checked, a space is added before and after binary operators. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert spaces around binary operators + + + If checked, a space is added between the open square bracket and the close square bracket. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within empty square brackets + + + If checked, a space is added after the open square bracket and before the close square bracket of the list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert spaces within square brackets of lists + + + If checked, a space is added after the open parenthesis and before the close parenthesis of the tuple. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within tuple parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of an expression. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within parentheses of expression + + + If checked, a space is added after the open parenthesis and before the close parenthesis of an argument list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within argument list parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of a bases list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within bases list parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of an empty bases list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within empty bases list parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of an empty argument list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within empty argument list parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of an empty parameter list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within empty parameter list parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of an empty tuple. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within empty tuple parentheses + + + If checked, a space is added after the open parenthesis and before the close parenthesis of a parameter list. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within parameter list parentheses + + + If checked, a space is added after the open square bracket and before the close square bracket. If unchecked, spaces are removed. Otherwise, spaces are not modified. + + + Insert space within square brackets + + + If checked, comments are wrapped to the specified width. If unchecked, comments are not modified. + + + # Not wrapped: +# There should be one-- and preferably only one --obvious way to do it. + Line breaks and # symbols must be preserved. No new line breaks should be added. + + + Wrap comments that are too wide + + + # Wrapped to 40 columns: +# There should be one-- and preferably +# only one --obvious way to do it. + Line breaks and # symbols must be preserved. There must be no more than 40 characters on each line of the localized text (except for the first line) + + + The number of the last column that should include comment text. Words after this column are moved to the following line. + + + Maximum comment width + + + # Sets the width for wrapping comments +# and documentation strings. + + + Documentation is still being calculated, please try again soon. + + + '{0}' may not be callable + + + object may not be callable + + + unresolved import '{0}' + + + '{0}' used before definition + + + property of type {0} + + + property of unknown type + + + Parameter {0} already specified. + + + Parameter {0} is missing. + + + Positional arguments are not allowed after keyword argument. + + + Too many function arguments. + + + Too many positional arguments before '*' argument. + + + Unknown parameter name. + + \ No newline at end of file diff --git a/src/Analysis/Ast/Impl/Specializations/BuiltinsSpecializations.cs b/src/Analysis/Ast/Impl/Specializations/BuiltinsSpecializations.cs new file mode 100644 index 000000000..98ba65bd3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/BuiltinsSpecializations.cs @@ -0,0 +1,82 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Specializations.Typing.Values; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Specializations { + public static class BuiltinsSpecializations { + public static ReturnValueProvider Identity + => (module, overload, location, args) => args.Count > 0 ? args[0] : null; + + public static ReturnValueProvider TypeInfo + => (module, overload, location, args) => args.Count > 0 ? args[0].GetPythonType() : null; + + public static IMember Iterator(IPythonModule module, IPythonFunctionOverload overload, LocationInfo location, IReadOnlyList args) { + if (args.Count > 0) { + if (args[0] is IPythonCollection seq) { + return seq.GetIterator(); + } + var t = args[0].GetPythonType(); + if (t.IsBuiltin && t.Name == "str") { + return new PythonTypeIterator(BuiltinTypeId.StrIterator, BuiltinTypeId.Str, module.Interpreter); + } + } + return null; + } + + public static IMember List(IPythonInterpreter interpreter, IPythonFunctionOverload overload, LocationInfo location, IReadOnlyList args) + => PythonCollectionType.CreateList(interpreter, location, args); + + public static IMember ListOfStrings(IPythonModule module, IPythonFunctionOverload overload, LocationInfo location, IReadOnlyList args) { + var type = new TypingListType("List", module.Interpreter.GetBuiltinType(BuiltinTypeId.Str), module.Interpreter, false); + return new TypingList(type, location); + } + public static IMember DictStringToObject(IPythonModule module, IPythonFunctionOverload overload, LocationInfo location, IReadOnlyList args) { + var str = module.Interpreter.GetBuiltinType(BuiltinTypeId.Str); + var obj = module.Interpreter.GetBuiltinType(BuiltinTypeId.Object); + var type = new TypingDictionaryType("Dict", str, obj, module.Interpreter, false); + return new TypingDictionary(type, location); + } + + public static ReturnValueProvider Next + => (module, overload, location, args) => args.Count > 0 && args[0] is IPythonIterator it ? it.Next : null; + + public static IMember __iter__(IPythonInterpreter interpreter, BuiltinTypeId contentTypeId) { + var fn = new PythonFunctionType(@"__iter__", interpreter.ModuleResolution.BuiltinsModule, null, string.Empty, LocationInfo.Empty); + var o = new PythonFunctionOverload(fn.Name, interpreter.ModuleResolution.BuiltinsModule, _ => fn.Location); + o.AddReturnValue(PythonTypeIterator.FromTypeId(interpreter, contentTypeId)); + fn.AddOverload(o); + return fn; + } + + public static IMember Range(IPythonModule module, IPythonFunctionOverload overload, LocationInfo location, IReadOnlyList args) { + if (args.Count > 0) { + var type = new PythonCollectionType(null, BuiltinTypeId.List, module.Interpreter, false); + return new PythonCollection(type, location, new [] {args[0]}); + } + return null; + } + + public static ReturnValueProvider CollectionItem + => (module, overload, location, args) => args.Count > 0 && args[0] is PythonCollection c ? c.Contents.FirstOrDefault() : null; + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Specialized.cs b/src/Analysis/Ast/Impl/Specializations/Specialized.cs new file mode 100644 index 000000000..169b57b60 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Specialized.cs @@ -0,0 +1,36 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations { + internal static class Specialized { + public static IPythonPropertyType Property(string name, IPythonModule declaringModule, IPythonType declaringType, IMember returnValue) { + var prop = new PythonPropertyType(name, declaringModule, declaringType, false, LocationInfo.Empty); + var o = new PythonFunctionOverload(prop.Name, declaringModule, LocationInfo.Empty); + o.AddReturnValue(returnValue); + prop.AddOverload(o); + return prop; + } + + public static IPythonFunctionType Function(string name, IPythonModule declaringModule, IPythonType declaringType, string documentation, IMember returnValue) { + var prop = new PythonFunctionType(name, declaringModule, declaringType, documentation, LocationInfo.Empty); + var o = new PythonFunctionOverload(prop.Name, declaringModule, LocationInfo.Empty); + o.AddReturnValue(returnValue); + prop.AddOverload(o); + return prop; + } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/IGenericType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/IGenericType.cs new file mode 100644 index 000000000..1a653b86a --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/IGenericType.cs @@ -0,0 +1,31 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + /// + /// Represents generic type, such as class or function. + /// Generic type is a template for the actual type. + /// + public interface IGenericType: IPythonType { + /// + /// Creates instance of a type information with the specific + /// type arguments from the generic template. + /// + IPythonType CreateSpecificType(IReadOnlyList typeArguments, IPythonModule declaringModule, LocationInfo location = null); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/IGenericTypeParameter.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/IGenericTypeParameter.cs new file mode 100644 index 000000000..6470d6c36 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/IGenericTypeParameter.cs @@ -0,0 +1,30 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + /// + /// Represents generic type parameter. Typically value returned by TypeVar. + /// + public interface IGenericTypeParameter: IPythonType { + /// + /// List of constraints for the type. + /// + /// See 'https://docs.python.org/3/library/typing.html#typing.TypeVar' + IReadOnlyList Constraints { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingDictionaryType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingDictionaryType.cs new file mode 100644 index 000000000..257fe94ce --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingDictionaryType.cs @@ -0,0 +1,37 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + /// + /// Represents typed dictionary, such as typing.Dict[KT, VT] + /// + public interface ITypingDictionaryType: IPythonCollectionType { + /// + /// Key type. + /// + IPythonType KeyType { get; } + /// + /// Key type. + /// + IPythonType ValueType { get; } + + /// + /// Item type, normally Tuple[TK, TV]. + /// + IPythonType ItemType { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingIteratorType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingIteratorType.cs new file mode 100644 index 000000000..6733768ba --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingIteratorType.cs @@ -0,0 +1,24 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + public interface ITypingIteratorType: IPythonIteratorType { + IReadOnlyList ItemTypes { get; } + bool Repeat { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingListType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingListType.cs new file mode 100644 index 000000000..9ef6b9ee5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingListType.cs @@ -0,0 +1,22 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + public interface ITypingListType: IPythonCollectionType { + IPythonType ItemType { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingNamedTupleType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingNamedTupleType.cs new file mode 100644 index 000000000..17d5acbe8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingNamedTupleType.cs @@ -0,0 +1,26 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + /// + /// Represents typing.NamedTuple. + /// + public interface ITypingNamedTupleType : ITypingTupleType { + string TupleName { get; } + IReadOnlyList ItemNames { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingTupleType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingTupleType.cs new file mode 100644 index 000000000..da86d9403 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Definitions/ITypingTupleType.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + public interface ITypingTupleType : IPythonCollectionType { + IReadOnlyList ItemTypes { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/AnyType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/AnyType.cs new file mode 100644 index 000000000..b2267a486 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/AnyType.cs @@ -0,0 +1,46 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal sealed class AnyType : IPythonType { + public AnyType(IPythonModule declaringModule) { + DeclaringModule = declaringModule; + } + public string Name => "Any"; + public IPythonModule DeclaringModule { get; } + public BuiltinTypeId TypeId => BuiltinTypeId.Type; + public string Documentation => Name; + public bool IsBuiltin => false; + public bool IsAbstract => false; + public bool IsSpecialized => true; + + public PythonMemberType MemberType => PythonMemberType.Class; + public IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) + => DeclaringModule.Interpreter.UnknownType; + public IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new PythonInstance(this, location); + + public IMember GetMember(string name) => null; + public IEnumerable GetMemberNames() => Array.Empty(); + + public IMember Index(IPythonInstance instance, object index) + => DeclaringModule.Interpreter.UnknownType; + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/GenericType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/GenericType.cs new file mode 100644 index 000000000..de9f6382d --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/GenericType.cs @@ -0,0 +1,68 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + /// + /// Base class for generic types and type declarations. + /// + internal class GenericType : IGenericType { + private readonly Func, IPythonModule, LocationInfo, IPythonType> _typeConstructor; + + public GenericType(string name, IPythonModule declaringModule, + Func, IPythonModule, LocationInfo, IPythonType> typeConstructor) { + + Name = name ?? throw new ArgumentNullException(nameof(name)); + DeclaringModule = declaringModule ?? throw new ArgumentNullException(nameof(declaringModule)); + _typeConstructor = typeConstructor ?? throw new ArgumentNullException(nameof(typeConstructor)); + } + + public IPythonType CreateSpecificType(IReadOnlyList typeArguments, IPythonModule declaringModule, LocationInfo location = null) + => _typeConstructor(typeArguments, declaringModule, location); + + #region IPythonType + public string Name { get; } + public IPythonModule DeclaringModule { get; } + public PythonMemberType MemberType => PythonMemberType.Generic; + public IMember GetMember(string name) => null; + public IEnumerable GetMemberNames() => Enumerable.Empty(); + public BuiltinTypeId TypeId => BuiltinTypeId.Unknown; + public virtual string Documentation => Name; + public bool IsBuiltin => false; + public bool IsAbstract => true; + public bool IsSpecialized => true; + + public IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) { + var types = args.Values(); + if (types.Count != args.Arguments.Count) { + throw new ArgumentException(@"Generic type instance construction arguments must be all of IPythonType", nameof(args)); + } + var specific = CreateSpecificType(types, DeclaringModule, location); + return specific == null + ? DeclaringModule.Interpreter.UnknownType + : specific.CreateInstance(typeName, location, null); + } + + public virtual IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) => DeclaringModule.Interpreter.UnknownType; + public virtual IMember Index(IPythonInstance instance, object index) => DeclaringModule.Interpreter.UnknownType; + #endregion + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/GenericTypeParameter.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/GenericTypeParameter.cs new file mode 100644 index 000000000..bd1779456 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/GenericTypeParameter.cs @@ -0,0 +1,59 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Utilities; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal sealed class GenericTypeParameter : PythonType, IGenericTypeParameter { + public GenericTypeParameter(string name, IPythonModule declaringModule, IReadOnlyList constraints, string documentation, LocationInfo location) + : base(name, declaringModule, documentation, location) { + Constraints = constraints ?? Array.Empty(); + } + public IReadOnlyList Constraints { get; } + + public override BuiltinTypeId TypeId => BuiltinTypeId.Type; + public override PythonMemberType MemberType => PythonMemberType.Generic; + public override bool IsSpecialized => true; + + + public static IPythonType FromTypeVar(IReadOnlyList args, IPythonModule declaringModule, LocationInfo location) { + if (args.Count == 0) { + // TODO: report that at least one argument is required. + return declaringModule.Interpreter.UnknownType; + } + + var name = (args[0] as IPythonConstant)?.Value as string; + if (string.IsNullOrEmpty(name)) { + // TODO: report that type name is not a string. + return declaringModule.Interpreter.UnknownType; + } + + var constraints = args.Skip(1).Select(a => a.GetPythonType()).ToArray(); + if (constraints.Any(c => c.IsUnknown())) { + // TODO: report that some constraints could be be resolved. + } + + var docArgs = new[] { $"'{name}'" }.Concat(constraints.Select(c => c.IsUnknown() ? "?" : c.Name)); + var documentation = CodeFormatter.FormatSequence("TypeVar", '(', docArgs); + + return new GenericTypeParameter(name, declaringModule, constraints, documentation, location); + } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/NamedTupleType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/NamedTupleType.cs new file mode 100644 index 000000000..2178c700d --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/NamedTupleType.cs @@ -0,0 +1,63 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Specializations.Typing.Values; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Utilities; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal sealed class NamedTupleType : TypingTupleType, ITypingNamedTupleType { + /// + /// Creates type info for a strongly-typed tuple, such as Tuple[T1, T2, ...]. + /// + public NamedTupleType(string tupleName, IReadOnlyList itemNames, IReadOnlyList itemTypes, IPythonInterpreter interpreter) + : base(itemTypes, interpreter) { + TupleName = tupleName ?? throw new ArgumentNullException(nameof(tupleName)); + ItemNames = itemNames; + + var typeNames = itemTypes.Select(t => t.IsUnknown() ? string.Empty : t.Name); + var pairs = itemNames.Zip(typeNames, (name, typeName) => string.IsNullOrEmpty(typeName) ? name : $"{name}: {typeName}"); + Name = CodeFormatter.FormatSequence(tupleName, '(', pairs); + } + + public string TupleName { get; } + public IReadOnlyList ItemNames { get; } + + public override string Name { get; } + public override bool IsSpecialized => true; + + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new TypingTuple(this, location); + + // NamedTuple does not create instances, it defines a type. + public override IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) => this; + + public override IEnumerable GetMemberNames() => ItemNames.Concat(base.GetMemberNames()); + + public override IMember GetMember(string name) { + var index = ItemNames.IndexOf(n => n == name); + if (index >= 0 && index < ItemTypes.Count) { + return new PythonInstance(ItemTypes[index]); + } + return base.GetMember(name); + } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/OptionalType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/OptionalType.cs new file mode 100644 index 000000000..99ad93829 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/OptionalType.cs @@ -0,0 +1,42 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal sealed class OptionalType : PythonTypeWrapper, IPythonUnionType { + public OptionalType(IPythonModule declaringModule, IPythonType type) : base(type, declaringModule) { + Name = $"Optional[{type.Name}]"; + } + public override string Name { get; } + public override PythonMemberType MemberType => PythonMemberType.Union; + public override bool IsSpecialized => true; + + public IEnumerator GetEnumerator() + => Enumerable.Repeat(DeclaringModule.Interpreter.GetBuiltinType(BuiltinTypeId.NoneType), 1) + .Concat(Enumerable.Repeat(InnerType, 1)).GetEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + + public IPythonUnionType Add(IPythonType t) => this; + public IPythonUnionType Add(IPythonUnionType types) => this; + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => InnerType.CreateInstance(typeName, location, args); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypeAlias.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypeAlias.cs new file mode 100644 index 000000000..ffcbde6a1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypeAlias.cs @@ -0,0 +1,27 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal sealed class TypeAlias: PythonTypeWrapper { + public TypeAlias(string name, IPythonType type) : base(type) { + Name = name; + } + public override string Name { get; } + public override bool IsSpecialized => true; + + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingDictionaryType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingDictionaryType.cs new file mode 100644 index 000000000..5705476c6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingDictionaryType.cs @@ -0,0 +1,75 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Specializations.Typing.Values; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + /// + /// Represents type info of typing.Dict[TK, TV] + /// + internal class TypingDictionaryType : PythonDictionaryType, ITypingDictionaryType { + private IPythonType _itemType; + + /// + /// Creates type info of typing.Dict[TK, TV] + /// + /// Type name (Dict, Mapping, ...) + /// Type of dictionary keys. + /// Type of dictionary values. + /// Python interpreter + /// Tells if collection is mutable (Dict) or not (Mapping) + public TypingDictionaryType(string name, IPythonType keyType, IPythonType valueType, IPythonInterpreter interpreter, bool isMutable) + : base(interpreter, isMutable) { + KeyType = keyType; + ValueType = valueType; + Name = $"{name}[{keyType.Name}, {valueType.Name}]"; + } + + public IPythonType KeyType { get; } + public IPythonType ValueType { get; } + public IPythonType ItemType => _itemType ?? (_itemType = CreateItemType()); + + public override string Name { get; } + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new TypingDictionary(this, location); + public override IMember Index(IPythonInstance instance, object index) => new PythonInstance(ValueType); + public override bool IsSpecialized => true; + + private TypingTupleType CreateItemType() { + var itemType = new TypingTupleType(new[] { KeyType, ValueType }, DeclaringModule.Interpreter); + return itemType; + } + + public override bool Equals(object obj) { + if (!(obj is TypingDictionaryType other)) { + return false; + } + + if ((KeyType.IsGenericParameter() && ValueType.IsGenericParameter()) || + (other.KeyType.IsGenericParameter() && other.ValueType.IsGenericParameter())) { + // Generic match - i.e. Mapping[K, V] matches Dict[int, str]. + return true; + } + return PythonTypeComparer.Instance.Equals(KeyType, other.KeyType) && + PythonTypeComparer.Instance.Equals(ValueType, other.ValueType); + } + + public override int GetHashCode() => KeyType.GetHashCode() ^ ValueType.GetHashCode() ^ Name.GetHashCode(); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingIteratorType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingIteratorType.cs new file mode 100644 index 000000000..63460fa70 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingIteratorType.cs @@ -0,0 +1,82 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Utilities; +using Microsoft.Python.Core.Diagnostics; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + /// + /// Describes iterator for a typed collection. + /// + internal sealed class TypingIteratorType : PythonIteratorType, ITypingIteratorType { + /// + /// Implements iteration over list-like typed collection such as List[T] + /// or Sequence[T]. Similar to the Iterator[T]. The iterator does not + /// track items in the collection, it repeats the same item endlessly. + /// + public TypingIteratorType(IPythonType itemType, BuiltinTypeId iteratorType, IPythonInterpreter interpreter) + : base(iteratorType, interpreter) { + ItemTypes = new[] { itemType }; + Repeat = true; + Name = $"Iterator[{itemType.Name}]"; + } + + /// + /// Implements iteration over tuple-like typed collection such as Tuple[T1, T2, T3, ...] + /// The iterator goes along declared items types and stops when there are no more types. + /// + public TypingIteratorType(IReadOnlyList itemTypes, BuiltinTypeId iteratorType, IPythonInterpreter interpreter) + : base(iteratorType, interpreter) { + Check.ArgumentOutOfRange(nameof(itemTypes), () => itemTypes.Count == 0); + ItemTypes = itemTypes; + Name = $"Iterator[{CodeFormatter.FormatSequence(string.Empty, '(', itemTypes)}]"; + } + + public IReadOnlyList ItemTypes { get; } + public bool Repeat { get; } + public override string Name { get; } + public override bool IsSpecialized => true; + + + public override bool Equals(object obj) { + if (!(obj is IPythonType other)) { + return false; + } + + if (obj is TypingIteratorType iterator) { + // Compare item types + if (ItemTypes.Count != iterator.ItemTypes.Count) { + return false; + } + for (var i = 0; i < ItemTypes.Count; i++) { + if (ItemTypes[i].IsGenericParameter() || iterator.ItemTypes[i].IsGenericParameter()) { + continue; + } + if (!PythonTypeComparer.Instance.Equals(ItemTypes[i], iterator.ItemTypes[i])) { + return false; + } + } + } + return other.TypeId == TypeId || PythonTypeComparer.Instance.Equals(this, other); + } + + public override int GetHashCode() + => ItemTypes.Aggregate(0, (current, item) => current ^ item.GetHashCode()) ^ Name.GetHashCode(); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingListType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingListType.cs new file mode 100644 index 000000000..400e7c4ab --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingListType.cs @@ -0,0 +1,74 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Analysis.Specializations.Typing.Values; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal class TypingListType : PythonCollectionType, ITypingListType { + /// + /// Creates type info for a list-like strongly typed collection, such as List[T]. + /// + /// Type name. + /// List item type. + /// Python interpreter + /// Tells of list represents a mutable collection. + /// If true, type will append item type names to the base type name. + public TypingListType(string typeName, IPythonType itemType, IPythonInterpreter interpreter, bool isMutable, bool formatName = true) + : this(typeName, BuiltinTypeId.List, itemType, interpreter, isMutable, formatName) { } + + /// + /// Creates type info for a list-like strongly typed collection, such as List[T]. + /// + /// Type name. + /// Collection type id. Can be used when list is used to simulate other collections, like a set. + /// List item type. + /// Python interpreter + /// Tells of list represents a mutable collection. + /// If true, type will append item type names to the base type name. + public TypingListType(string typeName, BuiltinTypeId typeId, IPythonType itemType, IPythonInterpreter interpreter, bool isMutable, bool formatName = true) + : base(null, typeId, interpreter, isMutable) { + ItemType = itemType; + Name = formatName ? $"{typeName}[{itemType.Name}]" : typeName; + } + + public override string Name { get; } + public override bool IsAbstract => false; + public override bool IsSpecialized => true; + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new TypingList(this, location); + public IPythonType ItemType { get; } + + public override IMember Index(IPythonInstance instance, object index) => new PythonInstance(ItemType); + + public override bool Equals(object obj) { + if (!(obj is TypingListType other)) { + return false; + } + + if (ItemType.IsGenericParameter() || other.ItemType.IsGenericParameter()) { + // Generic match - i.e. Sequence[T] matches List[str]. + return true; + } + return PythonTypeComparer.Instance.Equals(ItemType, other.ItemType); + } + + public override int GetHashCode() => ItemType.GetHashCode() ^ Name.GetHashCode(); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingTupleType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingTupleType.cs new file mode 100644 index 000000000..5994ae8c3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Types/TypingTupleType.cs @@ -0,0 +1,79 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Specializations.Typing.Values; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Utilities; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Types { + internal class TypingTupleType : PythonCollectionType, ITypingTupleType { + /// + /// Creates type info for a strongly-typed tuple, such as Tuple[T1, T2, ...]. + /// + /// Tuple item types. + /// Python interpreter. + public TypingTupleType(IReadOnlyList itemTypes, IPythonInterpreter interpreter) + : base(null, BuiltinTypeId.Tuple, interpreter, false) { + ItemTypes = itemTypes; + Name = CodeFormatter.FormatSequence("Tuple", '[', itemTypes); + } + + public IReadOnlyList ItemTypes { get; } + + public override string Name { get; } + public override bool IsAbstract => false; + public override bool IsSpecialized => true; + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new TypingTuple(this, location); + + public override IMember Index(IPythonInstance instance, object index) { + var n = PythonCollection.GetIndex(index); + if (n < 0) { + n = ItemTypes.Count + n; // -1 means last, etc. + } + if (n >= 0 && n < ItemTypes.Count) { + return ItemTypes[n]; + } + return UnknownType; + } + + public override bool Equals(object obj) { + if (!(obj is TypingTupleType other)) { + return false; + } + if (ItemTypes.Count != other.ItemTypes.Count) { + return false; + } + for (var i = 0; i < ItemTypes.Count; i++) { + if (ItemTypes[i].IsGenericParameter() || other.ItemTypes[i].IsGenericParameter()) { + continue; + } + if (!PythonTypeComparer.Instance.Equals(ItemTypes[i], other.ItemTypes[i])) { + return false; + } + } + return true; + } + + public override int GetHashCode() + => ItemTypes.Aggregate(0, (current, item) => current ^ item.GetHashCode()) ^ Name.GetHashCode(); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/TypingModule.cs b/src/Analysis/Ast/Impl/Specializations/Typing/TypingModule.cs new file mode 100644 index 000000000..f308d734a --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/TypingModule.cs @@ -0,0 +1,292 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Modules; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + internal sealed class TypingModule : SpecializedModule { + private readonly Dictionary _members = new Dictionary(); + + private TypingModule(string modulePath, IServiceContainer services) : base("typing", modulePath, services) { } + + public static async Task CreateAsync(IServiceContainer services, CancellationToken cancellationToken = default) { + var interpreter = services.GetService(); + var module = await interpreter.ModuleResolution + .SpecializeModuleAsync("typing", modulePath => new TypingModule(modulePath, services), cancellationToken) as TypingModule; + module?.SpecializeMembers(); + return module; + } + + #region IMemberContainer + public override IMember GetMember(string name) => _members.TryGetValue(name, out var m) ? m : null; + public override IEnumerable GetMemberNames() => _members.Keys; + #endregion + + private void SpecializeMembers() { + // TypeVar + var fn = new PythonFunctionType("TypeVar", this, null, GetMemberDocumentation, GetMemberLocation); + var o = new PythonFunctionOverload(fn.Name, this, _ => fn.Location); + // When called, create generic parameter type. For documentation + // use original TypeVar declaration so it appear as a tooltip. + o.SetReturnValueProvider((interpreter, overload, location, args) => GenericTypeParameter.FromTypeVar(args, interpreter, location)); + + fn.AddOverload(o); + _members["TypeVar"] = fn; + + // NewType + fn = new PythonFunctionType("NewType", this, null, GetMemberDocumentation, GetMemberLocation); + o = new PythonFunctionOverload(fn.Name, this, _ => fn.Location); + // When called, create generic parameter type. For documentation + // use original TypeVar declaration so it appear as a tooltip. + o.SetReturnValueProvider((interpreter, overload, location, args) => CreateTypeAlias(args)); + fn.AddOverload(o); + _members["NewType"] = fn; + + // NewType + fn = new PythonFunctionType("Type", this, null, GetMemberDocumentation, GetMemberLocation); + o = new PythonFunctionOverload(fn.Name, this, _ => fn.Location); + // When called, create generic parameter type. For documentation + // use original TypeVar declaration so it appear as a tooltip. + o.SetReturnValueProvider((interpreter, overload, location, args) => args.Count == 1 ? args[0] : Interpreter.UnknownType); + fn.AddOverload(o); + _members["Type"] = fn; + + _members["Iterator"] = new GenericType("Iterator", this, + (typeArgs, module, location) => CreateIteratorType(typeArgs)); + + _members["Iterable"] = new GenericType("Iterable", this, + (typeArgs, module, location) => CreateListType("Iterable", BuiltinTypeId.List, typeArgs, false)); + _members["Sequence"] = new GenericType("Sequence", this, + (typeArgs, module, location) => CreateListType("Sequence", BuiltinTypeId.List, typeArgs, false)); + _members["MutableSequence"] = new GenericType("MutableSequence", this, + (typeArgs, module, location) => CreateListType("MutableSequence", BuiltinTypeId.List, typeArgs, true)); + _members["List"] = new GenericType("List", this, + (typeArgs, module, location) => CreateListType("List", BuiltinTypeId.List, typeArgs, true)); + + _members["MappingView"] = new GenericType("MappingView", this, + (typeArgs, module, location) => CreateDictionary("MappingView", typeArgs, false)); + _members["KeysView"] = new GenericType("KeysView", this, + (typeArgs, module, location) => CreateKeysViewType(typeArgs)); + _members["ValuesView"] = new GenericType("ValuesView", this, + (typeArgs, module, location) => CreateValuesViewType(typeArgs)); + _members["ItemsView"] = new GenericType("ItemsView", this, + (typeArgs, module, location) => CreateItemsViewType(typeArgs)); + + _members["Set"] = new GenericType("Set", this, + (typeArgs, module, location) => CreateListType("Set", BuiltinTypeId.Set, typeArgs, true)); + _members["MutableSet"] = new GenericType("MutableSet", this, + (typeArgs, module, location) => CreateListType("MutableSet", BuiltinTypeId.Set, typeArgs, true)); + _members["FrozenSet"] = new GenericType("FrozenSet", this, + (typeArgs, module, location) => CreateListType("FrozenSet", BuiltinTypeId.Set, typeArgs, false)); + + _members["Tuple"] = new GenericType("Tuple", this, + (typeArgs, module, location) => CreateTupleType(typeArgs)); + + _members["Mapping"] = new GenericType("Mapping", this, + (typeArgs, module, location) => CreateDictionary("Mapping", typeArgs, false)); + _members["MutableMapping"] = new GenericType("MutableMapping", this, + (typeArgs, module, location) => CreateDictionary("MutableMapping", typeArgs, true)); + _members["Dict"] = new GenericType("Dict", this, + (typeArgs, module, location) => CreateDictionary("Dict", typeArgs, true)); + _members["OrderedDict"] = new GenericType("OrderedDict", this, + (typeArgs, module, location) => CreateDictionary("OrderedDict", typeArgs, true)); + _members["DefaultDict"] = new GenericType("DefaultDict", this, + (typeArgs, module, location) => CreateDictionary("DefaultDict", typeArgs, true)); + + _members["Union"] = new GenericType("Union", this, + (typeArgs, module, location) => CreateUnion(typeArgs)); + + _members["Counter"] = Specialized.Function("Counter", this, null, "Counter", new PythonInstance(Interpreter.GetBuiltinType(BuiltinTypeId.Int))); + + _members["SupportsInt"] = Interpreter.GetBuiltinType(BuiltinTypeId.Int); + _members["SupportsFloat"] = Interpreter.GetBuiltinType(BuiltinTypeId.Float); + _members["SupportsComplex"] = Interpreter.GetBuiltinType(BuiltinTypeId.Complex); + _members["SupportsBytes"] = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); + _members["ByteString"] = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); + + fn = new PythonFunctionType("NamedTuple", this, null, GetMemberDocumentation, GetMemberLocation); + o = new PythonFunctionOverload(fn.Name, this, _ => fn.Location); + o.SetReturnValueProvider((interpreter, overload, location, args) => CreateNamedTuple(args)); + fn.AddOverload(o); + _members["NamedTuple"] = fn; + + _members["Any"] = new AnyType(this); + + // AnyStr + var str = Interpreter.GetBuiltinType(BuiltinTypeId.Str); + var bytes = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes); + var unicode = Interpreter.GetBuiltinType(BuiltinTypeId.Unicode); + var anyStrName = new PythonConstant("AnyStr", str, LocationInfo.Empty); + + var anyStrArgs = Interpreter.LanguageVersion.Is3x() + ? new IMember[] { anyStrName, str, bytes } + : new IMember[] { anyStrName, str, unicode }; + _members["AnyStr"] = GenericTypeParameter.FromTypeVar(anyStrArgs, this, LocationInfo.Empty); + + _members["Optional"] = new GenericType("Optional", this, (typeArgs, module, location) => CreateOptional(typeArgs)); + _members["Type"] = new GenericType("Type", this, (typeArgs, module, location) => CreateType(typeArgs)); + } + + + private string GetMemberDocumentation(string name) + => base.GetMember(name)?.GetPythonType()?.Documentation; + private LocationInfo GetMemberLocation(string name) + => (base.GetMember(name)?.GetPythonType() as ILocatedMember)?.Location ?? LocationInfo.Empty; + + private IPythonType CreateListType(string typeName, BuiltinTypeId typeId, IReadOnlyList typeArgs, bool isMutable) { + if (typeArgs.Count == 1) { + return TypingTypeFactory.CreateListType(Interpreter, typeName, typeId, typeArgs[0], isMutable); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateTupleType(IReadOnlyList typeArgs) + => TypingTypeFactory.CreateTupleType(Interpreter, typeArgs); + + private IPythonType CreateIteratorType(IReadOnlyList typeArgs) { + if (typeArgs.Count == 1) { + return TypingTypeFactory.CreateIteratorType(Interpreter, typeArgs[0]); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateDictionary(string typeName, IReadOnlyList typeArgs, bool isMutable) { + if (typeArgs.Count == 2) { + return TypingTypeFactory.CreateDictionary(Interpreter, typeName, typeArgs[0], typeArgs[1], isMutable); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateKeysViewType(IReadOnlyList typeArgs) { + if (typeArgs.Count == 1) { + return TypingTypeFactory.CreateKeysViewType(Interpreter, typeArgs[0]); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateValuesViewType(IReadOnlyList typeArgs) { + if (typeArgs.Count == 1) { + return TypingTypeFactory.CreateValuesViewType(Interpreter, typeArgs[0]); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateItemsViewType(IReadOnlyList typeArgs) { + if (typeArgs.Count == 2) { + return TypingTypeFactory.CreateItemsViewType(Interpreter, typeArgs[0], typeArgs[1]); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateTypeAlias(IReadOnlyList typeArgs) { + if (typeArgs.Count == 2) { + var typeName = (typeArgs[0] as IPythonConstant)?.Value as string; + if (!string.IsNullOrEmpty(typeName)) { + return new TypeAlias(typeName, typeArgs[1].GetPythonType() ?? Interpreter.UnknownType); + } + // TODO: report incorrect first argument to NewVar + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateUnion(IReadOnlyList typeArgs) { + if (typeArgs.Count > 0) { + return TypingTypeFactory.CreateUnionType(Interpreter, typeArgs.Select(a => a.GetPythonType()).ToArray()); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateNamedTuple(IReadOnlyList typeArgs) { + if (typeArgs.Count != 2) { + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + ; + if (!typeArgs[0].TryGetConstant(out var tupleName) || string.IsNullOrEmpty(tupleName)) { + // TODO: report name is incorrect. + return Interpreter.UnknownType; + } + + var argList = (typeArgs[1] as IPythonCollection)?.Contents; + if (argList == null) { + // TODO: report type spec is not a list. + return Interpreter.UnknownType; + } + + var itemNames = new List(); + var itemTypes = new List(); + foreach (var a in argList) { + if (a.TryGetConstant(out string itemName1)) { + // Not annotated + itemNames.Add(itemName1); + itemTypes.Add(Interpreter.UnknownType); + continue; + } + + // Now assume annotated pair that comes as a tuple. + if (!(a is IPythonCollection c) || c.Type.TypeId != BuiltinTypeId.Tuple) { + // TODO: report that item is not a tuple. + continue; + } + if (c.Contents.Count != 2) { + // TODO: report extra items in the element spec. + continue; + } + if (!c.Contents[0].TryGetConstant(out var itemName2)) { + // TODO: report item name is not a string. + continue; + } + + itemNames.Add(itemName2); + itemTypes.Add(c.Contents[1].GetPythonType()); + } + return TypingTypeFactory.CreateNamedTupleType(Interpreter, tupleName, itemNames, itemTypes); + } + + private IPythonType CreateOptional(IReadOnlyList typeArgs) { + if (typeArgs.Count == 1) { + return TypingTypeFactory.CreateOptionalType(this, typeArgs[0]); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + + private IPythonType CreateType(IReadOnlyList typeArgs) { + if (typeArgs.Count == 1) { + return TypingTypeFactory.CreateType(this, typeArgs[0]); + } + // TODO: report wrong number of arguments + return Interpreter.UnknownType; + } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/TypingTypeFactory.cs b/src/Analysis/Ast/Impl/Specializations/Typing/TypingTypeFactory.cs new file mode 100644 index 000000000..a2bf09d7f --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/TypingTypeFactory.cs @@ -0,0 +1,67 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Specializations.Typing.Values; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Utilities; + +namespace Microsoft.Python.Analysis.Specializations.Typing { + internal static class TypingTypeFactory { + public static ITypingListType CreateListType(IPythonInterpreter interpreter, string typeName, BuiltinTypeId typeId, IPythonType itemType, bool isMutable) + => new TypingListType(typeName, typeId, itemType, interpreter, isMutable); + + public static ITypingTupleType CreateTupleType(IPythonInterpreter interpreter, IReadOnlyList types) + => new TypingTupleType(types, interpreter); + + public static ITypingIteratorType CreateIteratorType(IPythonInterpreter interpreter, IPythonType itemType) + => new TypingIteratorType(itemType, BuiltinTypeId.ListIterator, interpreter); + + public static ITypingDictionaryType CreateDictionary(IPythonInterpreter interpreter, string typeName, IPythonType keyType, IPythonType valueType, bool isMutable) + => new TypingDictionaryType(typeName, keyType, valueType, interpreter, isMutable); + + public static ITypingListType CreateKeysViewType(IPythonInterpreter interpreter, IPythonType keyType) + => new TypingListType("KeysView", BuiltinTypeId.DictKeys, keyType, interpreter, false); + + public static ITypingListType CreateValuesViewType(IPythonInterpreter interpreter, IPythonType valueType) + => new TypingListType("ValuesView", BuiltinTypeId.DictKeys, valueType, interpreter, false); + + public static ITypingListType CreateItemsViewType(IPythonInterpreter interpreter, ITypingDictionaryType dict) { + var typeName = CodeFormatter.FormatSequence("ItemsView", '[', new[] { dict.KeyType, dict.ValueType }); + return new TypingListType(typeName, BuiltinTypeId.DictItems, dict.ItemType, interpreter, false, false); + } + + public static ITypingListType CreateItemsViewType(IPythonInterpreter interpreter, IPythonType keyType, IPythonType valueType) { + var types = new[] {keyType, valueType}; + var typeName = CodeFormatter.FormatSequence("ItemsView", '[', types); + var itemType = CreateTupleType(interpreter, types); + return new TypingListType(typeName, BuiltinTypeId.DictItems, itemType, interpreter, false, false); + } + + public static IPythonType CreateUnionType(IPythonInterpreter interpreter, IReadOnlyList types) + => new PythonUnionType(types.Select(a => a.GetPythonType())); + + public static ITypingNamedTupleType CreateNamedTupleType(IPythonInterpreter interpreter, string tupleName, IReadOnlyList itemNames, IReadOnlyList itemTypes) + => new NamedTupleType(tupleName, itemNames, itemTypes, interpreter); + + public static IPythonType CreateOptionalType(IPythonModule declaringModule, IPythonType type) + => new OptionalType(declaringModule, type); + + public static IPythonType CreateType(IPythonModule declaringModule, IPythonType type) + => new TypingType(declaringModule, type); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingDictionary.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingDictionary.cs new file mode 100644 index 000000000..be5927aaf --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingDictionary.cs @@ -0,0 +1,80 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Values { + /// + /// Represents instance of typing.Dict[TK, TV] + /// + internal class TypingDictionary : PythonDictionary { + private readonly TypingDictionaryType _dictType; + + public TypingDictionary(TypingDictionaryType dictType, LocationInfo location = null) + : base(dictType, location ?? LocationInfo.Empty, EmptyDictionary.Instance) { + _dictType = dictType; + } + + public override IPythonIterator GetIterator() { + var iteratorTypeId = _dictType.TypeId.GetIteratorTypeId(); + var iteratorType = new TypingIteratorType(_dictType.ItemType, iteratorTypeId, Type.DeclaringModule.Interpreter); + return new TypingIterator(iteratorType, this); + } + + public override IMember Index(object key) => new PythonInstance(_dictType.ValueType); + + public override IMember Call(string memberName, IArgumentSet args) { + // Specializations + switch (memberName) { + case @"get": + return new PythonInstance(_dictType.ValueType); + case @"items": + return GetItems(); + case @"keys": + return GetKeys(); + case @"values": + return GetValues(); + case @"iterkeys": + return GetKeys().GetIterator(); + case @"itervalues": + return GetValues().GetIterator(); + case @"iteritems": + return GetItems().GetIterator(); + case @"pop": + return new PythonInstance(_dictType.ValueType); + case @"popitem": + return new PythonInstance(_dictType.ItemType); + } + return base.Call(memberName, args); + } + + private TypingList _keys; + private TypingList GetKeys() + => _keys ?? (_keys = new TypingList(TypingTypeFactory.CreateKeysViewType(_dictType.DeclaringModule.Interpreter, _dictType.KeyType))); + + private TypingList _values; + private TypingList GetValues() + => _values ?? (_values = new TypingList(TypingTypeFactory.CreateValuesViewType(_dictType.DeclaringModule.Interpreter, _dictType.ValueType))); + + private TypingList _items; + private TypingList GetItems() + =>_items ?? (_items = new TypingList(TypingTypeFactory.CreateItemsViewType(_dictType.DeclaringModule.Interpreter, _dictType))); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingIterator.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingIterator.cs new file mode 100644 index 000000000..d5ce5312b --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingIterator.cs @@ -0,0 +1,47 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Values { + /// + /// Implements iterator over a typed collection. + /// + internal sealed class TypingIterator : PythonIterator { + private readonly TypingIteratorType _iteratorType; + private int _index; + + public TypingIterator(TypingIteratorType iteratorType, IPythonCollection collection) + : base(iteratorType.TypeId, collection) { + _iteratorType = iteratorType; + } + + public override IMember Next { + get { + IPythonType itemType = null; + if (_iteratorType.Repeat) { + itemType = _iteratorType.ItemTypes[0]; + } else if (_index < _iteratorType.ItemTypes.Count) { + itemType = _iteratorType.ItemTypes[_index++]; + } + return itemType?.CreateInstance(itemType.Name, LocationInfo.Empty, ArgumentSet.Empty) ?? UnknownType; + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingList.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingList.cs new file mode 100644 index 000000000..783b59a8b --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingList.cs @@ -0,0 +1,39 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Values { + internal class TypingList : PythonCollection { + private readonly ITypingListType _collectionType; + + public TypingList(ITypingListType collectionType, LocationInfo location = null) + : base(collectionType, location ?? LocationInfo.Empty, Array.Empty()) { + _collectionType = collectionType; + } + + public override IPythonIterator GetIterator() { + var iteratorTypeId = _collectionType.TypeId.GetIteratorTypeId(); + var iteratorType = new TypingIteratorType(_collectionType.ItemType, iteratorTypeId, _collectionType.DeclaringModule.Interpreter); + return new TypingIterator(iteratorType, this); + } + + public override IMember Index(object index) => _collectionType.Index(this, index); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingTuple.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingTuple.cs new file mode 100644 index 000000000..099d6e5f7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingTuple.cs @@ -0,0 +1,39 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Analysis.Specializations.Typing.Types; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Values { + internal class TypingTuple : PythonCollection { + private readonly TypingTupleType _collectionType; + public TypingTuple(TypingTupleType collectionType, LocationInfo location = null) + : base(collectionType, location ?? LocationInfo.Empty, collectionType.ItemTypes) { + _collectionType = collectionType; + } + + public override IPythonIterator GetIterator() { + var iteratorTypeId = _collectionType.TypeId.GetIteratorTypeId(); + var iteratorType = new TypingIteratorType(_collectionType.ItemTypes, iteratorTypeId, _collectionType.DeclaringModule.Interpreter); + return new TypingIterator(iteratorType, this); + } + + public override IMember Index(object index) + => _collectionType.Index(this, index).GetPythonType().CreateInstance(null, LocationInfo.Empty, ArgumentSet.Empty); + } +} diff --git a/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingType.cs b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingType.cs new file mode 100644 index 000000000..7400ca83c --- /dev/null +++ b/src/Analysis/Ast/Impl/Specializations/Typing/Values/TypingType.cs @@ -0,0 +1,49 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Specializations.Typing.Values { + /// + /// Holds type info of the generic parameter. + /// + internal sealed class TypingType : IPythonType { + private readonly IPythonType _type; + + public TypingType(IPythonModule declaringModule, IPythonType type) { + _type = type ?? throw new ArgumentNullException(nameof(type)); + DeclaringModule = declaringModule; + Name = $"Type[{_type.Name}]"; + } + + public string Name { get; } + public IPythonModule DeclaringModule { get; } + public BuiltinTypeId TypeId => BuiltinTypeId.Type; + public string Documentation => Name; + public bool IsBuiltin => false; + public bool IsAbstract => false; + public bool IsSpecialized => true; + + public PythonMemberType MemberType => PythonMemberType.Class; + public IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) => _type.Call(instance, memberName, args); + public IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args ) => _type; + public IMember GetMember(string name) => _type.GetMember(name); + public IEnumerable GetMemberNames() => _type.GetMemberNames(); + public IMember Index(IPythonInstance instance, object index) => _type.Index(instance, index); + } +} diff --git a/src/Analysis/Ast/Impl/Types/ArgumentSet.cs b/src/Analysis/Ast/Impl/Types/ArgumentSet.cs new file mode 100644 index 000000000..96f315ffb --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/ArgumentSet.cs @@ -0,0 +1,316 @@ +// Python Tools for Visual Studio +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Analyzer.Evaluation; +using Microsoft.Python.Analysis.Diagnostics; +using Microsoft.Python.Analysis.Extensions; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; +using ErrorCodes = Microsoft.Python.Analysis.Diagnostics.ErrorCodes; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Set of arguments for a function call. + /// + internal sealed class ArgumentSet : IArgumentSet { + private readonly List _arguments = new List(); + private readonly List _errors = new List(); + private readonly ExpressionEval _eval; + private readonly ListArg _listArgument; + private readonly DictArg _dictArgument; + private bool _evaluated; + + public static IArgumentSet Empty = new ArgumentSet(); + + public IReadOnlyList Arguments => _arguments; + public IListArgument ListArgument => _listArgument; + public IDictionaryArgument DictionaryArgument => _dictArgument; + public IReadOnlyList Errors => _errors; + + private ArgumentSet() { } + + public ArgumentSet(IPythonFunctionType fn, IPythonInstance instance, CallExpression callExpr, ExpressionEval eval) : + this(fn, instance, callExpr, eval.Module, eval) { } + + /// + /// Creates set of arguments for a function call based on the call expression + /// and the function signature. The result contains expressions + /// for arguments, but not actual values. on how to + /// get values for actual parameters. + /// + /// Function to call. + /// Type instance the function is bound to. For derived classes it is different from the declared type. + /// Call expression that invokes the function. + /// Module that contains the call expression. + /// Evaluator that can calculate values of arguments from their respective expressions. + public ArgumentSet(IPythonFunctionType fn, IPythonInstance instance, CallExpression callExpr, IPythonModule module, ExpressionEval eval) { + _eval = eval; + + var fd = fn.FunctionDefinition; + if (fd == null || fn.IsSpecialized) { + // Typically specialized function, like TypeVar() that does not actually have AST definition. + // Make the arguments from the call expression. If argument does not have name, + // try using name from the function definition based on the argument position. + _arguments = new List(); + for (var i = 0; i < callExpr.Args.Count; i++) { + var name = callExpr.Args[i].Name; + if (string.IsNullOrEmpty(name)) { + name = fd != null && i < fd.Parameters.Length ? fd.Parameters[i].Name : null; + } + name = name ?? $"arg{i}"; + _arguments.Add(new Argument(name, ParameterKind.Normal) { Expression = callExpr.Args[i].Expression }); + } + return; + } + + if (callExpr == null) { + // Typically invoked by specialization code without call expression in the code. + // Caller usually does not care about arguments. + _evaluated = true; + return; + } + var callLocation = callExpr.GetLocation(module); + + // https://www.python.org/dev/peps/pep-3102/#id5 + // For each formal parameter, there is a slot which will be used to contain + // the value of the argument assigned to that parameter. Slots which have + // had values assigned to them are marked as 'filled'.Slots which have + // no value assigned to them yet are considered 'empty'. + + var slots = fd.Parameters.Select(p => new Argument(p.Name, p.Kind)).ToArray(); + // Locate sequence argument, if any + var sa = slots.Where(s => s.Kind == ParameterKind.List).ToArray(); + if (sa.Length > 1) { + // Error should have been reported at the function definition location by the parser. + return; + } + + var da = slots.Where(s => s.Kind == ParameterKind.Dictionary).ToArray(); + if (da.Length > 1) { + // Error should have been reported at the function definition location by the parser. + return; + } + + _listArgument = sa.Length == 1 && sa[0].Name.Length > 0 ? new ListArg(sa[0].Name) : null; + _dictArgument = da.Length == 1 ? new DictArg(da[0].Name) : null; + + // Class methods + var formalParamIndex = 0; + if (fn.DeclaringType != null && fn.HasClassFirstArgument() && slots.Length > 0) { + slots[0].Value = instance != null ? instance.GetPythonType() : fn.DeclaringType; + formalParamIndex++; + } + + try { + // Positional arguments + var callParamIndex = 0; + for (; callParamIndex < callExpr.Args.Count; callParamIndex++, formalParamIndex++) { + var arg = callExpr.Args[callParamIndex]; + + if (!string.IsNullOrEmpty(arg.Name) && !arg.Name.StartsWithOrdinal("**")) { + // Keyword argument. Done with positionals. + break; + } + + if (formalParamIndex >= fd.Parameters.Length) { + // We ran out of formal parameters and yet haven't seen + // any sequence or dictionary ones. This looks like an error. + _errors.Add(new DiagnosticsEntry(Resources.Analysis_TooManyFunctionArguments, arg.GetLocation(module).Span, + ErrorCodes.TooManyFunctionArguments, Severity.Warning)); + return; + } + + var formalParam = fd.Parameters[formalParamIndex]; + if (formalParam.IsList) { + if (string.IsNullOrEmpty(formalParam.Name)) { + // If the next unfilled slot is a vararg slot, and it does not have a name, then it is an error. + _errors.Add(new DiagnosticsEntry(Resources.Analysis_TooManyPositionalArgumentBeforeStar, arg.GetLocation(module).Span, + ErrorCodes.TooManyPositionalArgumentsBeforeStar, Severity.Warning)); + return; + } + + // If the next unfilled slot is a vararg slot then all remaining + // non-keyword arguments are placed into the vararg slot. + if (_listArgument == null) { + _errors.Add(new DiagnosticsEntry(Resources.Analysis_TooManyFunctionArguments, arg.GetLocation(module).Span, + ErrorCodes.TooManyFunctionArguments, Severity.Warning)); + return; + } + + for (; callParamIndex < callExpr.Args.Count; callParamIndex++) { + arg = callExpr.Args[callParamIndex]; + if (!string.IsNullOrEmpty(arg.Name)) { + // Keyword argument. Done here. + break; + } + + _listArgument._Expressions.Add(arg.Expression); + } + + break; // Sequence or dictionary parameter found. Done here. + } + + if (formalParam.IsDictionary) { + // Next slot is a dictionary slot, but we have positional arguments still. + _errors.Add(new DiagnosticsEntry(Resources.Analysis_TooManyPositionalArgumentBeforeStar, arg.GetLocation(module).Span, + ErrorCodes.TooManyPositionalArgumentsBeforeStar, Severity.Warning)); + return; + } + + // Regular parameter + slots[formalParamIndex].Expression = arg.Expression; + } + + // Keyword arguments + for (; callParamIndex < callExpr.Args.Count; callParamIndex++) { + var arg = callExpr.Args[callParamIndex]; + + if (string.IsNullOrEmpty(arg.Name)) { + _errors.Add(new DiagnosticsEntry(Resources.Analysis_PositionalArgumentAfterKeyword, arg.GetLocation(module).Span, + ErrorCodes.PositionalArgumentAfterKeyword, Severity.Warning)); + return; + } + + var nvp = slots.FirstOrDefault(s => s.Name.EqualsOrdinal(arg.Name)); + if (nvp == null) { + // 'def f(a, b)' and then 'f(0, c=1)'. Per spec: + // if there is a 'keyword dictionary' argument, the argument is added + // to the dictionary using the keyword name as the dictionary key, + // unless there is already an entry with that key, in which case it is an error. + if (_dictArgument == null) { + _errors.Add(new DiagnosticsEntry(Resources.Analysis_UnknownParameterName, arg.GetLocation(module).Span, + ErrorCodes.UnknownParameterName, Severity.Warning)); + return; + } + + if (_dictArgument.Arguments.ContainsKey(arg.Name)) { + _errors.Add(new DiagnosticsEntry(Resources.Analysis_ParameterAlreadySpecified.FormatUI(arg.Name), arg.GetLocation(module).Span, + ErrorCodes.ParameterAlreadySpecified, Severity.Warning)); + return; + } + + _dictArgument._Expressions[arg.Name] = arg.Expression; + continue; + } + + if (nvp.Expression != null || nvp.Value != null) { + // Slot is already filled. + _errors.Add(new DiagnosticsEntry(Resources.Analysis_ParameterAlreadySpecified.FormatUI(arg.Name), arg.GetLocation(module).Span, + ErrorCodes.ParameterAlreadySpecified, Severity.Warning)); + return; + } + + // OK keyword parameter + nvp.Expression = arg.Expression; + } + + // We went through all positionals and keywords. + // For each remaining empty slot: if there is a default value for that slot, + // then fill the slot with the default value. If there is no default value, + // then it is an error. + foreach (var slot in slots.Where(s => s.Kind != ParameterKind.List && s.Kind != ParameterKind.Dictionary && s.Value == null)) { + if (slot.Expression == null) { + var parameter = fd.Parameters.First(p => p.Name == slot.Name); + if (parameter.DefaultValue == null) { + // TODO: parameter is not assigned and has no default value. + _errors.Add(new DiagnosticsEntry(Resources.Analysis_ParameterMissing.FormatUI(slot.Name), callLocation.Span, + ErrorCodes.ParameterMissing, Severity.Warning)); + } + + slot.Expression = parameter.DefaultValue; + } + } + } finally { + // Optimistically return what we gathered, even if there are errors. + _arguments = slots.Where(s => s.Kind != ParameterKind.List && s.Kind != ParameterKind.Dictionary).ToList(); + } + } + + public async Task EvaluateAsync(CancellationToken cancellationToken = default) { + if (_evaluated || _eval == null) { + return this; + } + + foreach (var a in _arguments.Where(x => x.Value == null)) { + a.Value = await _eval.GetValueFromExpressionAsync(a.Expression, cancellationToken); + } + + if (_listArgument != null) { + foreach (var e in _listArgument.Expressions) { + var value = await _eval.GetValueFromExpressionAsync(e, cancellationToken); + _listArgument._Values.Add(value); + } + } + + if (_dictArgument != null) { + foreach (var e in _dictArgument.Expressions) { + var value = await _eval.GetValueFromExpressionAsync(e.Value, cancellationToken); + _dictArgument._Args[e.Key] = value; + } + } + + _evaluated = true; + return this; + } + + private sealed class Argument : IArgument { + public string Name { get; } + public object Value { get; internal set; } + + public ParameterKind Kind { get; } + public Expression Expression { get; set; } + + public Argument(string name, ParameterKind kind) { + Name = name; + Kind = kind; + } + } + + private sealed class ListArg : IListArgument { + public string Name { get; } + public IReadOnlyList Values => _Values; + public IReadOnlyList Expressions => _Expressions; + + public List _Values { get; } = new List(); + public List _Expressions { get; } = new List(); + + public ListArg(string name) { + Name = name; + } + } + + private sealed class DictArg : IDictionaryArgument { + public string Name { get; } + public IReadOnlyDictionary Arguments => _Args; + public IReadOnlyDictionary Expressions => _Expressions; + + public Dictionary _Args { get; } = new Dictionary(); + public Dictionary _Expressions { get; } = new Dictionary(); + + public DictArg(string name) { + Name = name; + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Collections/PythonCollectionType.cs b/src/Analysis/Ast/Impl/Types/Collections/PythonCollectionType.cs new file mode 100644 index 000000000..68135c117 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Collections/PythonCollectionType.cs @@ -0,0 +1,115 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Types.Collections { + /// + /// Type info for an iterable entity. Most base collection class. + /// + internal class PythonCollectionType : PythonTypeWrapper, IPythonCollectionType { + private string _typeName; + + /// + /// Creates type info for an collection. + /// + /// Iterable type name. If null, name of the type id will be used. + /// Collection type id, such as . + /// Python interpreter. + /// Indicates if collection is mutable (like list) or immutable (like tuple). + public PythonCollectionType( + string typeName, + BuiltinTypeId collectionTypeId, + IPythonInterpreter interpreter, + bool isMutable + ) : base(collectionTypeId, interpreter.ModuleResolution.BuiltinsModule) { + _typeName = typeName; + TypeId = collectionTypeId; + IteratorType = new PythonIteratorType(collectionTypeId.GetIteratorTypeId(), interpreter); + IsMutable = isMutable; + } + + #region IPythonCollectionType + /// + /// Indicates if collection is mutable (such as list) or not (such as tuple). + /// + public bool IsMutable { get; } + public virtual IPythonIterator GetIterator(IPythonInstance instance) => (instance as IPythonCollection)?.GetIterator(); + public IPythonIteratorType IteratorType { get; } + #endregion + + #region IPythonType + public override string Name { + get { + if (_typeName == null) { + var type = DeclaringModule.Interpreter.GetBuiltinType(TypeId); + if (!type.IsUnknown()) { + _typeName = type.Name; + } + } + return _typeName ?? ""; ; + } + } + + public override BuiltinTypeId TypeId { get; } + public override PythonMemberType MemberType => PythonMemberType.Class; + public override IMember GetMember(string name) => name == @"__iter__" ? IteratorType : base.GetMember(name); + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new PythonCollection(this, location, args.Arguments.Select(a => a.Value).OfType().ToArray()); + + // Constructor call + public override IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) + => CreateInstance(Name, instance?.Location ?? LocationInfo.Empty, args); + + public override IMember Index(IPythonInstance instance, object index) + => (instance as IPythonCollection)?.Index(index) ?? UnknownType; + #endregion + + public static IPythonCollection CreateList(IPythonInterpreter interpreter, LocationInfo location, IArgumentSet args) { + IReadOnlyList contents = null; + if (args.Arguments.Count > 1) { + // self and list like in list.__init__ and 'list([1, 'str', 3.0])' + contents = (args.Arguments[1].Value as PythonCollection)?.Contents; + } else { + // Try list argument as n '__init__(self, *args, **kwargs)' + contents = args.ListArgument?.Values; + } + return CreateList(interpreter, location, contents ?? Array.Empty()); + } + + public static IPythonCollection CreateList(IPythonInterpreter interpreter, LocationInfo location, IReadOnlyList contents, bool flatten = true) { + var collectionType = new PythonCollectionType(null, BuiltinTypeId.List, interpreter, true); + return new PythonCollection(collectionType, location, contents, flatten); + } + + public static IPythonCollection CreateTuple(IPythonInterpreter interpreter, LocationInfo location, IReadOnlyList contents) { + var collectionType = new PythonCollectionType(null, BuiltinTypeId.Tuple, interpreter, false); + return new PythonCollection(collectionType, location, contents); + } + public static IPythonCollection CreateSet(IPythonInterpreter interpreter, LocationInfo location, IReadOnlyList contents, bool flatten = true) { + var collectionType = new PythonCollectionType(null, BuiltinTypeId.Set, interpreter, true); + return new PythonCollection(collectionType, location, contents, flatten); + } + + public override bool Equals(object obj) + => obj is IPythonType pt && (PythonTypeComparer.Instance.Equals(pt, this) || PythonTypeComparer.Instance.Equals(pt, this.InnerType)); + public override int GetHashCode() => PythonTypeComparer.Instance.GetHashCode(this); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Collections/PythonDictionaryType.cs b/src/Analysis/Ast/Impl/Types/Collections/PythonDictionaryType.cs new file mode 100644 index 000000000..df6433fff --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Collections/PythonDictionaryType.cs @@ -0,0 +1,41 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Types.Collections { + internal class PythonDictionaryType : PythonCollectionType { + public PythonDictionaryType(IPythonInterpreter interpreter, bool isMutable = true) + : base(null, BuiltinTypeId.Dict, interpreter, isMutable) { + } + + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) { + var contents = args.Arguments.Count == 1 + ? args.Arguments[0].Value as IReadOnlyDictionary + : EmptyDictionary.Instance; + return new PythonDictionary(this, location, contents); + } + + // Constructor call + public override IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) + => CreateInstance(Name, instance?.Location ?? LocationInfo.Empty, args); + + public override BuiltinTypeId TypeId => BuiltinTypeId.Dict; + public override PythonMemberType MemberType => PythonMemberType.Class; + } +} diff --git a/src/Analysis/Ast/Impl/Types/Collections/PythonIteratorType.cs b/src/Analysis/Ast/Impl/Types/Collections/PythonIteratorType.cs new file mode 100644 index 000000000..865cebae9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Collections/PythonIteratorType.cs @@ -0,0 +1,40 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types.Collections { + /// + /// Implements iterator type. Iterator type is used to supply information + /// to the analysis on the return type of the 'next' method. 'Next' method + /// is implemented manually via specialized function overload. + /// + internal class PythonIteratorType : PythonTypeWrapper, IPythonIteratorType { + /// + /// Creates type info for an iterator. + /// + /// Iterator type id, such as . + /// Python interpreter + public PythonIteratorType(BuiltinTypeId typeId, IPythonInterpreter interpreter) + : base(typeId, interpreter.ModuleResolution.BuiltinsModule) { + TypeId = typeId; + } + + public virtual IMember Next(IPythonInstance instance) => (instance as IPythonIterator)?.Next ?? UnknownType; + + public override BuiltinTypeId TypeId { get; } + public override PythonMemberType MemberType => PythonMemberType.Class; + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/BuiltinTypeId.cs b/src/Analysis/Ast/Impl/Types/Definitions/BuiltinTypeId.cs new file mode 100644 index 000000000..e7dffcf4d --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/BuiltinTypeId.cs @@ -0,0 +1,108 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Well known built-in types that the analysis engine needs for doing interpretation. + /// + public enum BuiltinTypeId { + Unknown, + Object, + Type, + NoneType, + + Bool, + Int, + /// + /// The long integer type. + /// + /// + /// Interpreters should map this value to Int if they only have one + /// integer type. + /// + Long, + Float, + Complex, + + Tuple, + List, + Dict, + Set, + FrozenSet, + + /// + /// The default string type. + /// + /// + /// Interpreters should map this value to either Bytes or Unicode + /// depending on the type of "abc" + /// + Str, + /// + /// The non-Unicode string type. + /// + Bytes, + /// + /// The Unicode string type. + /// + Unicode, + + /// + /// The iterator for the default string type. + /// + /// + /// Interpreters should map this value to either BytesIterator or + /// UnicodeIterator depending on the type of iter("abc"). + /// + StrIterator, + /// + /// The iterator for the non-Unicode string type. + /// + BytesIterator, + /// + /// The iterator for the Unicode string type. + /// + UnicodeIterator, + + Module, + Function, + Method, + Generator, + + Property, + ClassMethod, + StaticMethod, + + Ellipsis, + + TupleIterator, + ListIterator, + /// + /// The type returned by dict.iterkeys (2.x) or dict.keys (3.x) + /// Also the type returned by iter(dict()) + /// + DictKeys, + /// + /// The type returned by dict.itervalues (2.x) or dict.values (3.x) + /// + DictValues, + /// + /// The type returned by dict.iteritems (2.x) or dict.items (3.x) + /// + DictItems, + SetIterator, + CallableIterator + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IArgumentSet.cs b/src/Analysis/Ast/Impl/Types/Definitions/IArgumentSet.cs new file mode 100644 index 000000000..bb9d37d08 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IArgumentSet.cs @@ -0,0 +1,44 @@ +// Python Tools for Visual Studio +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + public interface IArgument { + string Name { get; } + Expression Expression { get; } + object Value { get; } + } + + public interface IListArgument { + string Name { get; } + IReadOnlyList Expressions { get; } + IReadOnlyList Values { get; } + } + + public interface IDictionaryArgument { + string Name { get; } + IReadOnlyDictionary Arguments { get; } + IReadOnlyDictionary Expressions { get; } + } + + public interface IArgumentSet { + IReadOnlyList Arguments { get; } + IListArgument ListArgument { get; } + IDictionaryArgument DictionaryArgument { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IBuiltinPythonModule.cs b/src/Analysis/Ast/Impl/Types/Definitions/IBuiltinPythonModule.cs new file mode 100644 index 000000000..28f4d1177 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IBuiltinPythonModule.cs @@ -0,0 +1,37 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents a built-in Python module. The built-in module needs to respond to + /// some extra requests for members by name which supports getting hidden members + /// such as "NoneType" which logically live in the built-in module but don't actually + /// exist there by name. + /// + /// The full list of types which will be accessed through GetAnyMember but don't exist + /// in the built-in module includes: + /// NoneType + /// generator + /// builtin_function + /// builtin_method_descriptor + /// function + /// ellipsis + /// + /// These are the addition types in BuiltinTypeId which do not exist in __builtin__. + /// + public interface IBuiltinsPythonModule : IPythonModule { + IMember GetAnyMember(string name); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IHasQualifiedName.cs b/src/Analysis/Ast/Impl/Types/Definitions/IHasQualifiedName.cs new file mode 100644 index 000000000..2b9f9a48b --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IHasQualifiedName.cs @@ -0,0 +1,38 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; + +namespace Microsoft.Python.Analysis.Types { + public interface IHasQualifiedName { + /// + /// Gets the fully qualified, dot-separated name of the value. + /// This is typically used for displaying to users. + /// + string FullyQualifiedName { get; } + + /// + /// Gets the import and eval names of the value. The first part + /// should be importable, and the second is a name that can be + /// resolved with getattr(). + /// These are often seen separated with a colon. + /// + /// + /// The value cannot be resolved (for example, a nested function). + /// + KeyValuePair FullyQualifiedNamePair { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/ILocatedMember.cs b/src/Analysis/Ast/Impl/Types/Definitions/ILocatedMember.cs new file mode 100644 index 000000000..9a87ac5e7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/ILocatedMember.cs @@ -0,0 +1,27 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Provides the location of a member. This should be implemented on a class + /// which also implements IPythonType. + /// + public interface ILocatedMember: IMember { + /// + /// Returns where the member is located or null if the location is not known. + /// + LocationInfo Location { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IMember.cs b/src/Analysis/Ast/Impl/Types/Definitions/IMember.cs new file mode 100644 index 000000000..fc7137dbe --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IMember.cs @@ -0,0 +1,27 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents lowest common denominator in the analysis. + /// Both instance and its type information are members. + /// + public interface IMember { + /// + /// Member type. + /// + PythonMemberType MemberType { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IMemberContainer.cs b/src/Analysis/Ast/Impl/Types/Definitions/IMemberContainer.cs new file mode 100644 index 000000000..62d77e272 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IMemberContainer.cs @@ -0,0 +1,27 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Runtime.InteropServices.ComTypes; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents type which has members. + /// + public interface IMemberContainer { + IMember GetMember(string name); + IEnumerable GetMemberNames(); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IParameterInfo.cs b/src/Analysis/Ast/Impl/Types/Definitions/IParameterInfo.cs new file mode 100644 index 000000000..8f7d7d714 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IParameterInfo.cs @@ -0,0 +1,58 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents information about an individual parameter. Used for providing + /// signature help. + /// + public interface IParameterInfo { + /// + /// The name of the parameter. + /// + string Name { get; } + + /// + /// Type of the parameter. + /// + IPythonType Type { get; } + + /// + /// Documentation for the parameter. + /// + string Documentation { get; } + + /// + /// True if the parameter is a *args parameter. + /// + bool IsParamArray { get; } + + /// + /// True if the parameter is a **args parameter. + /// + bool IsKeywordDict { get; } + + /// + /// Default value. Returns empty string for optional parameters, + /// or a string representation of the default value. + /// + string DefaultValueString { get; } + + /// + /// Default value type. + /// + IPythonType DefaultValueType { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonClassMember.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonClassMember.cs new file mode 100644 index 000000000..9ea3e402f --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonClassMember.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents member of a class. + /// + public interface IPythonClassMember : IPythonType { + IPythonType DeclaringType { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonClassType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonClassType.cs new file mode 100644 index 000000000..e44ca95f1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonClassType.cs @@ -0,0 +1,28 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents Python class type definition. + /// + public interface IPythonClassType : IPythonType { + ClassDefinition ClassDefinition { get; } + IReadOnlyList Mro { get; } + IReadOnlyList Bases { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonCollectionType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonCollectionType.cs new file mode 100644 index 000000000..000fa0987 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonCollectionType.cs @@ -0,0 +1,38 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents instance of a collection. + /// + public interface IPythonCollectionType : IPythonType { + /// + /// Type of the collection iterator. + /// + IPythonIteratorType IteratorType { get; } + + /// + /// Retrieves iterator from an instance. + /// + IPythonIterator GetIterator(IPythonInstance instance); + + /// + /// Indicates if the collection is mutable (such as list) or not (such as tuple). + /// + bool IsMutable { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonFile.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonFile.cs new file mode 100644 index 000000000..897c7bf48 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonFile.cs @@ -0,0 +1,30 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; + +namespace Microsoft.Python.Analysis.Types { + public interface IPythonFile { + /// + /// File path to the module. + /// + string FilePath { get; } + + /// + /// Module URI. + /// + Uri Uri { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonFunctionOverload.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonFunctionOverload.cs new file mode 100644 index 000000000..bd8be66cd --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonFunctionOverload.cs @@ -0,0 +1,60 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents a single overload of a function. + /// + public interface IPythonFunctionOverload { + /// + /// The corresponding function definition node. + /// + FunctionDefinition FunctionDefinition { get; } + + /// + /// Function name. + /// + string Name { get; } + + /// + /// Overload documentation. + /// + string Documentation { get; } + + /// + /// Overload parameters. + /// + IReadOnlyList Parameters { get; } + + /// + /// Determines return value type given arguments for the particular call. + /// For annotated or stubbed functions the annotation type is always returned. + /// + IMember GetReturnValue(LocationInfo callLocation, IArgumentSet args); + + /// + /// Return value documentation. + /// + string ReturnDocumentation { get; } + + /// + /// Function definition is decorated with @overload. + /// + bool IsOverload { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonFunctionType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonFunctionType.cs new file mode 100644 index 000000000..7ab68acd6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonFunctionType.cs @@ -0,0 +1,54 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents a function. + /// + public interface IPythonFunctionType : IPythonClassMember { + /// + /// Function definition in the AST. + /// + FunctionDefinition FunctionDefinition { get; } + + /// + /// Function is a @classmethod. + /// + bool IsClassMethod { get; } + + /// + /// Function is @staticmethod. + /// + bool IsStatic { get; } + + /// + /// Function is @overload. + /// + bool IsOverload { get; } + + /// + /// Function is a stub definition. + /// + bool IsStub { get; } + + /// + /// List of function overloads + /// + IReadOnlyList Overloads { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonIteratorType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonIteratorType.cs new file mode 100644 index 000000000..eb364dc01 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonIteratorType.cs @@ -0,0 +1,22 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types { + public interface IPythonIteratorType : IPythonType { + IMember Next(IPythonInstance instance); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonModule.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonModule.cs new file mode 100644 index 000000000..2e3fbcb4f --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonModule.cs @@ -0,0 +1,54 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Modules; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents a Python module. + /// + public interface IPythonModule : IPythonType, IPythonFile, ILocatedMember { + /// + /// Interpreter associated with the module. + /// + IPythonInterpreter Interpreter { get; } + + /// + /// Module type (user, library, stub). + /// + ModuleType ModuleType { get; } + + /// + /// Module stub, if any. + /// + IPythonModule Stub { get; } + + /// + /// Global cope of the module. + /// + IGlobalScope GlobalScope { get; } + + /// + /// Ensures that module content is loaded and analysis has completed. + /// Typically module content is loaded at the creation time, but delay + /// loaded (lazy) modules may choose to defer content retrieval and + /// analysis until later time, when module members are actually needed. + /// + Task LoadAndAnalyzeAsync(CancellationToken cancellationToken = default); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonPackage.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonPackage.cs new file mode 100644 index 000000000..6f64d255e --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonPackage.cs @@ -0,0 +1,25 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; + +namespace Microsoft.Python.Analysis.Types { + public interface IPythonPackage : IPythonModule { + /// + /// Modules imported by this module. + /// + IEnumerable GetChildrenModuleNames(); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonPropertyType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonPropertyType.cs new file mode 100644 index 000000000..20fc3c932 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonPropertyType.cs @@ -0,0 +1,38 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents a built-in property which has a getter/setter. + /// + public interface IPythonPropertyType : IPythonClassMember { + /// + /// Function definition in the AST. + /// + FunctionDefinition FunctionDefinition { get; } + + /// + /// A user readable description of the property. + /// + string Description { get; } + + /// + /// True if the property is read-only. + /// + bool IsReadOnly { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonType.cs new file mode 100644 index 000000000..a55d3f947 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonType.cs @@ -0,0 +1,84 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Type information of an instance. + /// + public interface IPythonType : IMember, IMemberContainer { + /// + /// Type name. + /// + string Name { get; } + + /// + /// Module the type is declared in. + /// + IPythonModule DeclaringModule { get; } + + /// + /// Indicates built-in type id such as 'int' or 'str' + /// or 'type' for user-defined entities. + /// + BuiltinTypeId TypeId { get; } + + /// + /// Human-readable documentation that may be displayed in the editor hover tooltip. + /// + string Documentation { get; } + + /// + /// Indicates if type is a built-in type. + /// + bool IsBuiltin { get; } + + /// + /// Indicates if type is an abstract type. + /// + bool IsAbstract { get; } + + /// + /// Indicates if type is specialized in code. + /// + bool IsSpecialized { get; } + + /// + /// Create instance of the type, if any. + /// + /// Name of the type. Used in specialization scenarios + /// where constructor may want to create specialized type. + /// Instance location + /// Any custom arguments required to create the instance. + IMember CreateInstance(string typeName = null, LocationInfo location = null, IArgumentSet args = null); + + /// + /// Invokes method or property on the specified instance. + /// + /// Instance of the type. + /// Member name to call, if applicable. + /// Call arguments. + IMember Call(IPythonInstance instance, string memberName, IArgumentSet argSet); + + /// + /// Invokes indexer on the specified instance. + /// + /// Instance of the type. + /// Index arguments. + IMember Index(IPythonInstance instance, object index); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/IPythonUnionType.cs b/src/Analysis/Ast/Impl/Types/Definitions/IPythonUnionType.cs new file mode 100644 index 000000000..eb7aeaf9b --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/IPythonUnionType.cs @@ -0,0 +1,26 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Represents union of types + /// + public interface IPythonUnionType: IPythonType, IEnumerable { + IPythonUnionType Add(IPythonType t); + IPythonUnionType Add(IPythonUnionType types); + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/LocationInfo.cs b/src/Analysis/Ast/Impl/Types/Definitions/LocationInfo.cs new file mode 100644 index 000000000..97dfffb4d --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/LocationInfo.cs @@ -0,0 +1,99 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using Microsoft.Python.Core.Text; + +namespace Microsoft.Python.Analysis.Types { + public sealed class LocationInfo : IEquatable { + [DebuggerDisplay("{StartLine}, {StartColumn} - {EndLine}, {EndColumn}")] + public static readonly LocationInfo Empty = new LocationInfo(); + + private LocationInfo() { + FilePath = string.Empty; + } + + public LocationInfo(string path, Uri documentUri, int line, int column) : + this(path, documentUri, line, column, null, null) { + } + + public LocationInfo(string path, Uri documentUri, int line, int column, int? endLine, int? endColumn) { + FilePath = path; + DocumentUri = documentUri; + StartLine = line; + StartColumn = column; + EndLine = endLine; + EndColumn = endColumn; + } + + public string FilePath { get; } + + public Uri DocumentUri { get; } + + public int StartLine { get; } + + public int StartColumn { get; } + + public int? EndLine { get; } + + public int? EndColumn { get; } + + public SourceSpan Span => new SourceSpan( + new SourceLocation(StartLine, StartColumn), + new SourceLocation(EndLine ?? StartLine, EndColumn ?? StartColumn) + ); + + public override bool Equals(object obj) => Equals(obj as LocationInfo); + + public override int GetHashCode() => StartLine.GetHashCode() ^ (FilePath?.GetHashCode() ?? 0); + + public bool Equals(LocationInfo other) { + if (other == null) { + return false; + } + + // currently we filter only to line & file - so we'll only show 1 ref per each line + // This works nicely for get and call which can both add refs and when they're broken + // apart you still see both refs, but when they're together you only see 1. + return StartLine == other.StartLine && + FilePath == other.FilePath; + } + + /// + /// Provides an IEqualityComparer that compares line, column and project entries. By + /// default locations are equaitable based upon only line/project entry. + /// + public static IEqualityComparer FullComparer { get; } = new FullLocationComparer(); + + sealed class FullLocationComparer : IEqualityComparer { + public bool Equals(LocationInfo x, LocationInfo y) { + if (x == null || y == null) { + return x == null && y == null; + } + + return x.StartLine == y.StartLine && + x.StartColumn == y.StartColumn && + x.FilePath == y.FilePath && + x.EndLine == y.EndLine && + x.EndColumn == y.EndColumn; + } + + public int GetHashCode(LocationInfo obj) + => obj.StartLine.GetHashCode() ^ obj.StartColumn.GetHashCode() ^ (obj.FilePath?.GetHashCode() ?? 0); + } + } +} diff --git a/src/Analysis/Ast/Impl/Types/Definitions/PythonMemberType.cs b/src/Analysis/Ast/Impl/Types/Definitions/PythonMemberType.cs new file mode 100644 index 000000000..c7dda2ba4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/Definitions/PythonMemberType.cs @@ -0,0 +1,62 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Types { + /// + /// Indicates the type of a variable result eval. + /// + /// Types can indicate a physical 1st class object (function, module, etc...) or they can + /// represent a logic piece of storage (field) + /// + public enum PythonMemberType { + Unknown, + /// + /// Class definition. + /// + Class, + /// + /// An instance of a type. + /// + Instance, + /// + /// Function type information. + /// + Function, + /// + /// Method type information. + /// + Method, + /// + /// An instance of a module. + /// + Module, + /// + /// A class property definition. + /// + Property, + /// + /// A union of multiple types. + /// + Union, + /// + /// Member is a variable. + /// + Variable, + /// + /// Generic type. + /// + Generic + } +} diff --git a/src/Analysis/Ast/Impl/Types/ParameterInfo.cs b/src/Analysis/Ast/Impl/Types/ParameterInfo.cs new file mode 100644 index 000000000..da3ddc6e5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/ParameterInfo.cs @@ -0,0 +1,53 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + internal sealed class ParameterInfo : IParameterInfo { + public ParameterInfo(PythonAst ast, Parameter p, IPythonType type) { + Name = p?.Name ?? throw new ArgumentNullException(nameof(p)); + Documentation = string.Empty; + DefaultValueString = p.DefaultValue?.ToCodeString(ast).Trim(); + if (DefaultValueString == "...") { + DefaultValueString = null; + } + IsParamArray = p.Kind == ParameterKind.List; + IsKeywordDict = p.Kind == ParameterKind.Dictionary; + Type = type; + } + + public string Name { get; } + public string Documentation { get; } + public bool IsParamArray { get; } + public bool IsKeywordDict { get; } + public IPythonType Type { get; private set; } + public string DefaultValueString { get; } + public IPythonType DefaultValueType { get; private set; } + + internal void SetType(IPythonType type) { + if (Type.IsUnknown()) { + Type = type; + } + } + internal void SetDefaultValueType(IPythonType type) { + if (DefaultValueType.IsUnknown()) { + DefaultValueType = type; + SetType(type); + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonClassType.cs b/src/Analysis/Ast/Impl/Types/PythonClassType.cs new file mode 100644 index 000000000..359d939f9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonClassType.cs @@ -0,0 +1,227 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using Microsoft.Python.Analysis.Modules; +using Microsoft.Python.Analysis.Types.Collections; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Analysis.Values.Collections; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + [DebuggerDisplay("Class {Name}")] + internal sealed class PythonClassType : PythonType, IPythonClassType, IEquatable { + private readonly object _lock = new object(); + + private IReadOnlyList _mro; + private readonly AsyncLocal _isProcessing = new AsyncLocal(); + + // For tests + internal PythonClassType(string name, IPythonModule declaringModule) + : base(name, declaringModule, string.Empty, LocationInfo.Empty, BuiltinTypeId.Type) { } + + public PythonClassType( + ClassDefinition classDefinition, + IPythonModule declaringModule, + LocationInfo location, + BuiltinTypeId builtinTypeId = BuiltinTypeId.Type + ) : base(classDefinition.Name, declaringModule, classDefinition.GetDocumentation(), location, builtinTypeId) { + ClassDefinition = classDefinition; + } + + #region IPythonType + public override PythonMemberType MemberType => PythonMemberType.Class; + + public override IEnumerable GetMemberNames() { + var names = new HashSet(); + lock (_lock) { + names.UnionWith(Members.Keys); + } + foreach (var m in Mro.Skip(1)) { + names.UnionWith(m.GetMemberNames()); + } + return names; + } + + public override IMember GetMember(string name) { + IMember member; + lock (_lock) { + if (Members.TryGetValue(name, out member)) { + return member; + } + + // Special case names that we want to add to our own Members dict + switch (name) { + case "__mro__": + member = AddMember(name, PythonCollectionType.CreateList(DeclaringModule.Interpreter, LocationInfo.Empty, Mro), true); + return member; + } + } + if (Push()) { + try { + foreach (var m in Mro.Reverse()) { + if (m == this) { + return member; + } + member = member ?? m.GetMember(name); + } + } finally { + Pop(); + } + } + return null; + } + + public override string Documentation { + get { + var doc = base.Documentation; + if (string.IsNullOrEmpty(doc) && Bases != null) { + // Try bases + doc = Bases.FirstOrDefault(b => !string.IsNullOrEmpty(b?.Documentation))?.Documentation; + } + if (string.IsNullOrEmpty(doc)) { + doc = GetMember("__init__")?.GetPythonType()?.Documentation; + } + return doc; + } + } + + // Constructor call + public override IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) { + // Specializations + switch (typeName) { + case "list": + return PythonCollectionType.CreateList(DeclaringModule.Interpreter, location, args); + case "dict": { + // self, then contents + var contents = args.Values().Skip(1).FirstOrDefault(); + return new PythonDictionary(DeclaringModule.Interpreter, location, contents); + } + case "tuple": { + var contents = args.Values(); + return PythonCollectionType.CreateTuple(DeclaringModule.Interpreter, location, contents); + } + } + return new PythonInstance(this, location); + } + #endregion + + #region IPythonClass + public ClassDefinition ClassDefinition { get; } + public IReadOnlyList Bases { get; private set; } + + public IReadOnlyList Mro { + get { + lock (_lock) { + if (_mro != null) { + return _mro; + } + if (Bases == null) { + //Debug.Fail("Accessing Mro before SetBases has been called"); + return new IPythonType[] { this }; + } + _mro = new IPythonType[] { this }; + _mro = CalculateMro(this); + return _mro; + } + } + } + #endregion + + internal void SetBases(IPythonInterpreter interpreter, IEnumerable bases) { + lock (_lock) { + if (Bases != null) { + return; // Already set + } + + Bases = bases.MaybeEnumerate().ToArray(); + if (Bases.Count > 0) { + AddMember("__base__", Bases[0], true); + } + + if (!(DeclaringModule is BuiltinsPythonModule)) { + // TODO: If necessary, we can set __bases__ on builtins when the module is fully analyzed. + AddMember("__bases__", PythonCollectionType.CreateList(DeclaringModule.Interpreter, LocationInfo.Empty, Bases), true); + } + } + } + + internal static IReadOnlyList CalculateMro(IPythonType cls, HashSet recursionProtection = null) { + if (cls == null) { + return Array.Empty(); + } + if (recursionProtection == null) { + recursionProtection = new HashSet(); + } + if (!recursionProtection.Add(cls)) { + return Array.Empty(); + } + try { + var mergeList = new List> { new List() }; + var finalMro = new List { cls }; + + var bases = (cls as PythonClassType)?.Bases; + if (bases == null) { + var members = (cls.GetMember("__bases__") as IPythonCollection)?.Contents ?? Array.Empty(); + bases = members.Select(m => m.GetPythonType()).ToArray(); + } + + foreach (var b in bases) { + var b_mro = new List(); + b_mro.AddRange(CalculateMro(b, recursionProtection)); + mergeList.Add(b_mro); + } + + while (mergeList.Any()) { + // Next candidate is the first head that does not appear in + // any other tails. + var nextInMro = mergeList.FirstOrDefault(mro => { + var m = mro.FirstOrDefault(); + return m != null && !mergeList.Any(m2 => m2.Skip(1).Contains(m)); + })?.FirstOrDefault(); + + if (nextInMro == null) { + // MRO is invalid, so return just this class + return new[] { cls }; + } + + finalMro.Add(nextInMro); + + // Remove all instances of that class from potentially being returned again + foreach (var mro in mergeList) { + mro.RemoveAll(ns => ns == nextInMro); + } + + // Remove all lists that are now empty. + mergeList.RemoveAll(mro => !mro.Any()); + } + + return finalMro; + } finally { + recursionProtection.Remove(cls); + } + } + + private bool Push() => !_isProcessing.Value && (_isProcessing.Value = true); + private void Pop() => _isProcessing.Value = false; + public bool Equals(IPythonClassType other) + => Name == other?.Name && DeclaringModule.Equals(other?.DeclaringModule); + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonFunctionOverload.cs b/src/Analysis/Ast/Impl/Types/PythonFunctionOverload.cs new file mode 100644 index 000000000..d05daefa9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonFunctionOverload.cs @@ -0,0 +1,163 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Analyzer.Evaluation; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Delegate that is invoked to determine function return type dynamically. + /// Can be used in specializations or when return type depends on actual arguments. + /// + /// Module making the call. + /// Function overload the return value is requested for. + /// Call location, if any. + /// Call arguments. + /// + public delegate IMember ReturnValueProvider( + IPythonModule declaringModule, + IPythonFunctionOverload overload, + LocationInfo location, + IReadOnlyList args); + + internal sealed class PythonFunctionOverload : IPythonFunctionOverload, ILocatedMember { + private readonly Func _locationProvider; + private readonly IPythonModule _declaringModule; + + // Allow dynamic function specialization, such as defining return types for builtin + // functions that are impossible to scrape and that are missing from stubs. + // Parameters: declaring module, overload for the return value, list of arguments. + private ReturnValueProvider _returnValueProvider; + + // Return value can be an instance or a type info. Consider type(C()) returning + // type info of C vs. return C() that returns an instance of C. + private Func _documentationProvider; + private bool _fromAnnotation; + + public PythonFunctionOverload(string name, IPythonModule declaringModule, LocationInfo location, string returnDocumentation = null) + : this(name, declaringModule, _ => location ?? LocationInfo.Empty, returnDocumentation) { + _declaringModule = declaringModule; + } + + public PythonFunctionOverload(FunctionDefinition fd, IPythonModule declaringModule, LocationInfo location, string returnDocumentation = null) + : this(fd.Name, declaringModule, _ => location, returnDocumentation) { + FunctionDefinition = fd; + } + + public PythonFunctionOverload(string name, IPythonModule declaringModule, + Func locationProvider, string returnDocumentation = null) { + Name = name ?? throw new ArgumentNullException(nameof(name)); + ReturnDocumentation = returnDocumentation; + _declaringModule = declaringModule; + _locationProvider = locationProvider; + } + + internal void SetParameters(IReadOnlyList parameters) => Parameters = parameters; + + internal void SetDocumentationProvider(Func documentationProvider) + => _documentationProvider = _documentationProvider ?? documentationProvider; + + internal void AddReturnValue(IMember value) { + if (value.IsUnknown()) { + return; // Don't add useless values. + } + if (StaticReturnValue.IsUnknown()) { + SetReturnValue(value, false); + return; + } + // If return value is set from annotation, it should not be changing. + var currentType = StaticReturnValue.GetPythonType(); + var valueType = value.GetPythonType(); + if (!_fromAnnotation && !currentType.Equals(valueType)) { + var type = PythonUnionType.Combine(currentType, valueType); + // Track instance vs type info. + StaticReturnValue = value is IPythonInstance ? new PythonInstance(type) : (IMember)type; + } + } + + internal void SetReturnValue(IMember value, bool fromAnnotation) { + StaticReturnValue = value; + _fromAnnotation = fromAnnotation; + } + + internal void SetReturnValueProvider(ReturnValueProvider provider) + => _returnValueProvider = provider; + + internal IMember StaticReturnValue { get; private set; } + + + #region IPythonFunctionOverload + public FunctionDefinition FunctionDefinition { get; } + public string Name { get; } + + public string Documentation { + get { + var s = _documentationProvider?.Invoke(Name); + if (string.IsNullOrEmpty(s)) { + s = FunctionDefinition.GetDocumentation(); + } + return s ?? string.Empty; + } + } + + public string ReturnDocumentation { get; } + public bool IsOverload { get; private set; } + public IReadOnlyList Parameters { get; private set; } = Array.Empty(); + public LocationInfo Location => _locationProvider?.Invoke(Name) ?? LocationInfo.Empty; + public PythonMemberType MemberType => PythonMemberType.Function; + + public IMember GetReturnValue(LocationInfo callLocation, IArgumentSet args) { + if (!_fromAnnotation) { + // First try supplied specialization callback. + var rt = _returnValueProvider?.Invoke(_declaringModule, this, callLocation, args.Values()); + if (!rt.IsUnknown()) { + return rt; + } + } + return StaticReturnValue; + } + #endregion + + private void ProcessDecorators(FunctionDefinition fd) { + foreach (var dec in (fd.Decorators?.Decorators).MaybeEnumerate().OfType()) { + // TODO: warn about incompatible combinations. + switch (dec.Name) { + case @"overload": + IsOverload = true; + break; + } + } + } + + //private sealed class ReturnValueCache { + // private const int MaxResults = 10; + // private readonly Dictionary _results = new Dictionary(new ArgumentSetComparer()); + + // public bool TryGetResult(IReadOnlyList args, out IMember result) + // => _results.TryGetValue(new ArgumentSet(args), out result); + + // public void AddResult(IReadOnlyList args, out IMember result) { + // var key = new ArgumentSet(args); + // Debug.Assert(!_results.ContainsKey(key)); + // _results[key] = result; + // } + //} + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonFunctionType.cs b/src/Analysis/Ast/Impl/Types/PythonFunctionType.cs new file mode 100644 index 000000000..bf5a0a7f7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonFunctionType.cs @@ -0,0 +1,242 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + [DebuggerDisplay("Function {Name} ({TypeId})")] + internal class PythonFunctionType : PythonType, IPythonFunctionType { + private readonly List _overloads = new List(); + private readonly string _doc; + private readonly object _lock = new object(); + private bool _isAbstract; + private bool _isSpecialized; + + /// + /// Creates function for specializations + /// + public static PythonFunctionType ForSpecialization(string name, IPythonModule declaringModule) + => new PythonFunctionType(name, declaringModule, true); + + private PythonFunctionType(string name, IPythonModule declaringModule, bool isSpecialized = false) : + base(name, declaringModule, null, LocationInfo.Empty, BuiltinTypeId.Function) { + DeclaringType = declaringModule; + _isSpecialized = isSpecialized; + } + + /// + /// Creates function type to use in special cases when function is dynamically + /// created, such as in specializations and custom iterators, without the actual + /// function definition in the AST. + /// + public PythonFunctionType( + string name, + IPythonModule declaringModule, + IPythonType declaringType, + string documentation, + LocationInfo location = null + ) : this(name, declaringModule, declaringType, _ => documentation, _ => location ?? LocationInfo.Empty) { } + + /// + /// Creates function type to use in special cases when function is dynamically + /// created, such as in specializations and custom iterators, without the actual + /// function definition in the AST. + /// + public PythonFunctionType( + string name, + IPythonModule declaringModule, + IPythonType declaringType, + Func documentationProvider, + Func locationProvider, + IPythonFunctionOverload overload = null + ) : base(name, declaringModule, documentationProvider, locationProvider, + declaringType != null ? BuiltinTypeId.Method : BuiltinTypeId.Function) { + DeclaringType = declaringType; + if (overload != null) { + AddOverload(overload); + } + } + + public PythonFunctionType( + FunctionDefinition fd, + IPythonModule declaringModule, + IPythonType declaringType, + LocationInfo location = null + ) : base(fd.Name, declaringModule, fd.Documentation, location ?? LocationInfo.Empty, + declaringType != null ? BuiltinTypeId.Method : BuiltinTypeId.Function) { + + FunctionDefinition = fd; + DeclaringType = declaringType; + + if (fd.Name == "__init__") { + _doc = declaringType?.Documentation; + } + + ProcessDecorators(fd); + } + + #region IPythonType + public override PythonMemberType MemberType + => TypeId == BuiltinTypeId.Function ? PythonMemberType.Function : PythonMemberType.Method; + + public override IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) { + // Now we can go and find overload with matching arguments. + var overload = FindOverload(args); + return overload?.GetReturnValue(instance?.Location ?? LocationInfo.Empty, args) ?? DeclaringModule.Interpreter.UnknownType; + } + + internal override void SetDocumentationProvider(Func provider) { + foreach (var o in Overloads) { + (o as PythonFunctionOverload)?.SetDocumentationProvider(provider); + } + base.SetDocumentationProvider(provider); + } + + #endregion + + #region IPythonFunction + public FunctionDefinition FunctionDefinition { get; } + public IPythonType DeclaringType { get; } + public override string Documentation => _doc ?? _overloads.FirstOrDefault()?.Documentation; + public virtual bool IsClassMethod { get; private set; } + public virtual bool IsStatic { get; private set; } + public override bool IsAbstract => _isAbstract; + public override bool IsSpecialized => _isSpecialized; + + public bool IsOverload { get; private set; } + public bool IsStub { get; internal set; } + + public IReadOnlyList Overloads => _overloads.ToArray(); + #endregion + + #region IHasQualifiedName + public override string FullyQualifiedName => FullyQualifiedNamePair.CombineNames(); + public override KeyValuePair FullyQualifiedNamePair => + new KeyValuePair((DeclaringType as IHasQualifiedName)?.FullyQualifiedName ?? DeclaringType?.Name ?? DeclaringModule?.Name, Name); + #endregion + + internal void Specialize() => _isSpecialized = true; + + internal void AddOverload(IPythonFunctionOverload overload) { + lock (_lock) { + _overloads.Add(overload); + } + } + + internal IPythonFunctionType ToUnbound() => new PythonUnboundMethod(this); + + private void ProcessDecorators(FunctionDefinition fd) { + foreach (var dec in (fd.Decorators?.Decorators).MaybeEnumerate().OfType()) { + // TODO: warn about incompatible combinations. + switch (dec.Name) { + case @"staticmethod": + IsStatic = true; + break; + case @"classmethod": + IsClassMethod = true; + break; + case @"abstractmethod": + _isAbstract = true; + break; + case @"abstractstaticmethod": + IsStatic = true; + _isAbstract = true; + break; + case @"abstractclassmethod": + IsClassMethod = true; + _isAbstract = true; + break; + case @"overload": + IsOverload = true; + break; + case @"property": + case @"abstractproperty": + Debug.Assert(false, "Found property attribute while processing function. Properties should be handled in the respective class."); + break; + } + } + } + + private IPythonFunctionOverload FindOverload(IArgumentSet args) { + // Find best overload match. Of only one, use it. + if (Overloads.Count == 1) { + return Overloads[0]; + } + // Try matching parameters + return Overloads.FirstOrDefault(o => IsMatch(args, o.Parameters)); + } + + public static bool IsMatch(IArgumentSet args, IReadOnlyList parameters) { + // Arguments passed to function are created off the function definition + // and hence match by default. However, if multiple overloads are specified, + // we need to figure out if annotated types match. + // https://docs.python.org/3/library/typing.html#typing.overload + // + // @overload + // def process(response: None) -> None: + // @overload + // def process(response: int) -> Tuple[int, str]: + // + // Note that in overloads there are no * or ** parameters. + // We match loosely by type. + + var d = parameters.ToDictionary(p => p.Name, p => p.Type); + foreach (var a in args.Arguments()) { + if (!d.TryGetValue(a.Key, out var t)) { + return false; + } + + var at = a.Value?.GetPythonType(); + if (t == null && at == null) { + continue; + } + + if (t != null && at != null && !t.Equals(at)) { + return false; + } + } + return true; + } + + + /// + /// Represents unbound method, such in C.f where C is class rather than the instance. + /// + private sealed class PythonUnboundMethod : PythonTypeWrapper, IPythonFunctionType { + private readonly IPythonFunctionType _pf; + + public PythonUnboundMethod(IPythonFunctionType function) : base(function, function.DeclaringModule) { + _pf = function; + } + + public FunctionDefinition FunctionDefinition => _pf.FunctionDefinition; + public IPythonType DeclaringType => _pf.DeclaringType; + public bool IsStatic => _pf.IsStatic; + public bool IsClassMethod => _pf.IsClassMethod; + public bool IsOverload => _pf.IsOverload; + public bool IsStub => _pf.IsStub; + + public IReadOnlyList Overloads => _pf.Overloads; + public override BuiltinTypeId TypeId => BuiltinTypeId.Function; + public override PythonMemberType MemberType => PythonMemberType.Function; + } + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonPropertyType.cs b/src/Analysis/Ast/Impl/Types/PythonPropertyType.cs new file mode 100644 index 000000000..bb8d11b3e --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonPropertyType.cs @@ -0,0 +1,53 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Types { + class PythonPropertyType : PythonType, IPythonPropertyType { + private IPythonFunctionOverload _getter; + + public PythonPropertyType(FunctionDefinition fd, IPythonModule declaringModule, IPythonType declaringType, bool isAbstract, LocationInfo location) + : this(fd.Name, declaringModule, declaringType, isAbstract, location) { + FunctionDefinition = fd; + } + + public PythonPropertyType(string name, IPythonModule declaringModule, IPythonType declaringType, bool isAbstract, LocationInfo location) + : base(name, declaringModule, null, location) { + DeclaringType = declaringType; + IsAbstract = isAbstract; + } + + #region IPythonType + public override PythonMemberType MemberType => PythonMemberType.Property; + #endregion + + #region IPythonPropertyType + public FunctionDefinition FunctionDefinition { get; } + public override bool IsAbstract { get; } + public bool IsReadOnly => true; + public IPythonType DeclaringType { get; } + public string Description + => Type == null ? Resources.PropertyOfUnknownType : Resources.PropertyOfType.FormatUI(Type.Name); + public override IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) + => _getter.GetReturnValue(instance?.Location ?? LocationInfo.Empty, args); + #endregion + + internal void AddOverload(IPythonFunctionOverload overload) => _getter = _getter ?? overload; + private IPythonType Type => _getter?.GetReturnValue(null, ArgumentSet.Empty)?.GetPythonType(); + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonType.cs b/src/Analysis/Ast/Impl/Types/PythonType.cs new file mode 100644 index 000000000..54dff441b --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonType.cs @@ -0,0 +1,167 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types { + [DebuggerDisplay("{Name}")] + internal class PythonType : IPythonType, ILocatedMember, IHasQualifiedName, IEquatable { + private readonly object _lock = new object(); + private readonly Func _locationProvider; + private Func _documentationProvider; + private Dictionary _members; + private BuiltinTypeId _typeId; + + protected IReadOnlyDictionary Members => WritableMembers; + + private Dictionary WritableMembers => + _members ?? (_members = new Dictionary()); + + public PythonType( + string name, + IPythonModule declaringModule, + string documentation, + LocationInfo location, + BuiltinTypeId typeId = BuiltinTypeId.Unknown + ) : this(name, declaringModule, _ => documentation, _ => location ?? LocationInfo.Empty, typeId) { } + + public PythonType( + string name, + IPythonModule declaringModule, + Func documentationProvider, + Func locationProvider, + BuiltinTypeId typeId = BuiltinTypeId.Unknown + ) : this(name, typeId) { + DeclaringModule = declaringModule; + _documentationProvider = documentationProvider; + _locationProvider = locationProvider; + } + + public PythonType(string name, BuiltinTypeId typeId) { + Name = name ?? throw new ArgumentNullException(nameof(name)); + _typeId = typeId; + } + + #region IPythonType + public virtual string Name { get; } + public virtual string Documentation => _documentationProvider?.Invoke(Name); + public IPythonModule DeclaringModule { get; } + public virtual PythonMemberType MemberType => _typeId.GetMemberId(); + public virtual BuiltinTypeId TypeId => _typeId; + public bool IsBuiltin => DeclaringModule == null || DeclaringModule is IBuiltinsPythonModule; + public virtual bool IsAbstract => false; + public virtual bool IsSpecialized => false; + + /// + /// Create instance of the type, if any. + /// + /// Name of the type. Used in specialization scenarios + /// where constructor may want to create specialized type. + /// Instance location + /// Any custom arguments required to create the instance. + public virtual IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new PythonInstance(this, location); + + /// + /// Invokes method or property on the specified instance. + /// + /// Instance of the type. + /// Member name to call, if applicable. + /// Call arguments. + public virtual IMember Call(IPythonInstance instance, string memberName, IArgumentSet argSet) + => instance?.Call(memberName, argSet) ?? UnknownType; + + /// + /// Invokes indexer on the specified instance. + /// + /// Instance of the type. + /// Index arguments. + public virtual IMember Index(IPythonInstance instance, object index) => instance?.Index(index) ?? UnknownType; + #endregion + + #region ILocatedMember + public virtual LocationInfo Location => _locationProvider?.Invoke(Name) ?? LocationInfo.Empty; + #endregion + + #region IHasQualifiedName + public virtual string FullyQualifiedName => FullyQualifiedNamePair.CombineNames(); + public virtual KeyValuePair FullyQualifiedNamePair + => new KeyValuePair(DeclaringModule?.Name ?? string.Empty, Name); + #endregion + + #region IMemberContainer + public virtual IMember GetMember(string name) => Members.TryGetValue(name, out var member) ? member : null; + public virtual IEnumerable GetMemberNames() => Members.Keys; + #endregion + + internal bool TrySetTypeId(BuiltinTypeId typeId) { + if (_typeId != BuiltinTypeId.Unknown) { + return false; + } + _typeId = typeId; + return true; + } + + internal virtual void SetDocumentationProvider(Func provider) => _documentationProvider = provider; + + internal void AddMembers(IEnumerable variables, bool overwrite) { + lock (_lock) { + foreach (var v in variables.Where(m => overwrite || !Members.ContainsKey(m.Name))) { + WritableMembers[v.Name] = v.Value.GetPythonType(); + } + } + } + + internal void AddMembers(IEnumerable> members, bool overwrite) { + lock (_lock) { + foreach (var kv in members.Where(m => overwrite || !Members.ContainsKey(m.Key))) { + WritableMembers[kv.Key] = kv.Value; + } + } + } + + internal void AddMembers(IPythonClassType cls, bool overwrite) { + if (cls != null) { + var names = cls.GetMemberNames(); + var members = names.Select(n => new KeyValuePair(n, cls.GetMember(n))); + AddMembers(members, overwrite); + } + } + + internal IMember AddMember(string name, IMember member, bool overwrite) { + lock (_lock) { + if (overwrite || !Members.ContainsKey(name)) { + WritableMembers[name] = member; + } + return member; + } + } + + internal bool IsHidden => ContainsMember("__hidden__"); + + protected bool ContainsMember(string name) => Members.ContainsKey(name); + protected IMember UnknownType => DeclaringModule.Interpreter.UnknownType; + + public bool Equals(IPythonType other) => PythonTypeComparer.Instance.Equals(this, other); + + public override bool Equals(object obj) + => obj is IPythonType pt && PythonTypeComparer.Instance.Equals(this, pt); + public override int GetHashCode() => 0; + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonTypeComparer.cs b/src/Analysis/Ast/Impl/Types/PythonTypeComparer.cs new file mode 100644 index 000000000..7bda97e93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonTypeComparer.cs @@ -0,0 +1,48 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Types { + public sealed class PythonTypeComparer : IEqualityComparer { + public static readonly PythonTypeComparer Instance = new PythonTypeComparer(); + + public bool Equals(IPythonType x, IPythonType y) { + if (x == null || y == null) { + return x == null && y == null; + } + if (ReferenceEquals(x, y)) { + return true; + } + if(x is IPythonUnionType utx && y is IPythonUnionType uty) { + return utx.SetEquals(uty, Instance); + } + return x.TypeId == y.TypeId && + x.Name == y.Name && + x.IsBuiltin == y.IsBuiltin && + x.DeclaringModule == y.DeclaringModule && + x.Documentation == y.Documentation; + } + + public int GetHashCode(IPythonType obj) { + return obj.TypeId.GetHashCode() ^ + obj.Name?.GetHashCode() ?? 0 ^ + obj.IsBuiltin.GetHashCode() ^ + obj.DeclaringModule?.GetHashCode() ?? 0 ^ + obj.Documentation?.GetHashCode() ?? 0; + } + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonTypeWrapper.cs b/src/Analysis/Ast/Impl/Types/PythonTypeWrapper.cs new file mode 100644 index 000000000..0a47f8d7a --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonTypeWrapper.cs @@ -0,0 +1,96 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Types { + /// + /// Delegates most of the methods to the wrapped/inner class. + /// + internal class PythonTypeWrapper : IPythonType, ILocatedMember, IHasQualifiedName { + private readonly BuiltinTypeId _builtinTypeId; + private IPythonType _innerType; + + protected IPythonType InnerType + => _innerType ?? (_innerType = DeclaringModule.Interpreter.GetBuiltinType(_builtinTypeId)); + + /// + /// Creates delegate type wrapper over an existing type. + /// Use dedicated constructor for wrapping builtin types. + /// + public PythonTypeWrapper(IPythonType type) + : this(type, type.DeclaringModule) { + } + + /// + /// Creates delegate type wrapper over an existing type. + /// Use dedicated constructor for wrapping builtin types. + /// + public PythonTypeWrapper(IPythonType type, IPythonModule declaringModule) { + _innerType = type ?? throw new ArgumentNullException(nameof(type)); + DeclaringModule = declaringModule; + } + + /// + /// Creates type wrapper for a built-in type. This is preferable way to + /// wrap builtins since it can be done when builtins module is not loaded + /// yet - such as when builtins module itself is being imported or specialized. + /// + public PythonTypeWrapper(BuiltinTypeId builtinTypeId, IPythonModule declaringModule) { + DeclaringModule = declaringModule ?? throw new ArgumentNullException(nameof(declaringModule)); + _builtinTypeId = builtinTypeId; + } + + #region IPythonType + public virtual string Name => InnerType.Name; + public IPythonModule DeclaringModule { get; } + public virtual string Documentation => InnerType.Documentation; + public virtual BuiltinTypeId TypeId => InnerType.TypeId; + public virtual PythonMemberType MemberType => InnerType.MemberType; + public virtual bool IsBuiltin => InnerType.IsBuiltin; + public virtual bool IsAbstract => InnerType.IsAbstract; + public virtual bool IsSpecialized => InnerType.IsSpecialized; + + public virtual IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => IsAbstract ? null : InnerType.CreateInstance(typeName, location, args); + public virtual IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) + => InnerType.Call(instance, memberName, args); + public virtual IMember Index(IPythonInstance instance, object index) + => InnerType.Index(instance, index); + #endregion + + #region ILocatedMember + public virtual LocationInfo Location => (InnerType as ILocatedMember)?.Location ?? LocationInfo.Empty; + #endregion + + #region IMemberContainer + public virtual IMember GetMember(string name) => InnerType.GetMember(name); + public virtual IEnumerable GetMemberNames() => InnerType.GetMemberNames(); + #endregion + + #region IHasQualifiedName + public virtual string FullyQualifiedName => (InnerType as IHasQualifiedName)?.FullyQualifiedName; + public virtual KeyValuePair FullyQualifiedNamePair => (InnerType as IHasQualifiedName)?.FullyQualifiedNamePair ?? default; + #endregion + + protected IMember UnknownType => DeclaringModule.Interpreter.UnknownType; + + public override bool Equals(object obj) + => obj is IPythonType pt && (PythonTypeComparer.Instance.Equals(pt, this) || PythonTypeComparer.Instance.Equals(pt, InnerType)); + public override int GetHashCode() => PythonTypeComparer.Instance.GetHashCode(this); + } +} diff --git a/src/Analysis/Ast/Impl/Types/PythonUnionType.cs b/src/Analysis/Ast/Impl/Types/PythonUnionType.cs new file mode 100644 index 000000000..3e13f3485 --- /dev/null +++ b/src/Analysis/Ast/Impl/Types/PythonUnionType.cs @@ -0,0 +1,131 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. } + +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Utilities; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; + +namespace Microsoft.Python.Analysis.Types { + internal sealed class PythonUnionType : IPythonUnionType { + private readonly HashSet _types = new HashSet(PythonTypeComparer.Instance); + private readonly object _lock = new object(); + + public PythonUnionType(IEnumerable types) { + _types.UnionWith(types); + } + + private PythonUnionType(IPythonType x, IPythonType y) { + Check.Argument(nameof(x), () => !(x is IPythonUnionType)); + Check.Argument(nameof(y), () => !(y is IPythonUnionType)); + _types.Add(x); + _types.Add(y); + } + + #region IPythonType + + public string Name { + get { + lock (_lock) { + return CodeFormatter.FormatSequence("Union", '[', _types.ToArray()); + } + } + } + + public IPythonModule DeclaringModule => null; + public BuiltinTypeId TypeId => BuiltinTypeId.Type; + public PythonMemberType MemberType => PythonMemberType.Union; + public string Documentation => Name; + public bool IsBuiltin { + get { lock (_lock) { return _types.All(t => t.IsBuiltin); } } + } + public bool IsAbstract => false; + public bool IsSpecialized => true; + + public IMember CreateInstance(string typeName, LocationInfo location, IArgumentSet args) + => new PythonUnion(this, location); + + public IMember Call(IPythonInstance instance, string memberName, IArgumentSet args) + => DeclaringModule?.Interpreter.UnknownType ?? this; + public IMember Index(IPythonInstance instance, object index) + => DeclaringModule?.Interpreter.UnknownType ?? this; + #endregion + + #region IPythonUnionType + public IPythonUnionType Add(IPythonType t) { + lock (_lock) { + if (t is IPythonUnionType ut) { + return Add(ut); + } + if (!_types.Contains(t)) { + _types.Add(t); + } + return this; + } + } + + public IPythonUnionType Add(IPythonUnionType types) { + lock (_lock) { + _types.UnionWith(types); + return this; + } + } + + public IEnumerator GetEnumerator() { + lock (_lock) { + return _types.ToList().GetEnumerator(); + } + } + + public IMember GetMember(string name) { + lock (_lock) { + return _types.Select(t => t.GetMember(name)).ExcludeDefault().FirstOrDefault(); + } + } + + public IEnumerable GetMemberNames() { + lock (_lock) { + return _types.SelectMany(t => t.GetMemberNames()).ToArray(); + } + } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + #endregion + + public static IPythonType Combine(IPythonType x, IPythonType y) { + var utx = x as IPythonUnionType; + var uty = y as IPythonUnionType; + + if (x == null) { + return y; + } + if (y == null) { + return x; + } + + if (utx == null && uty == null) { + return new PythonUnionType(x, y); + } + + if (utx != null && uty == null) { + return utx.Add(y); + } + + return utx == null ? uty.Add(x) : utx.Add(uty); + } + } +} diff --git a/src/Analysis/Ast/Impl/Typeshed/LICENSE b/src/Analysis/Ast/Impl/Typeshed/LICENSE new file mode 100644 index 000000000..e5833ae42 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/LICENSE @@ -0,0 +1,238 @@ +The "typeshed" project is licensed under the terms of the Apache license, as +reproduced below. + += = = = = + +Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + += = = = = + +Parts of typeshed are licensed under different licenses (like the MIT +license), reproduced below. + += = = = = + +The MIT License + +Copyright (c) 2015 Jukka Lehtosalo and contributors + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + += = = = = + diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/BaseHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/BaseHTTPServer.pyi new file mode 100644 index 000000000..8bb34b887 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/BaseHTTPServer.pyi @@ -0,0 +1,47 @@ +# Stubs for BaseHTTPServer (Python 2.7) + +from typing import Any, BinaryIO, Mapping, Optional, Tuple, Union +import SocketServer +import mimetools + +class HTTPServer(SocketServer.TCPServer): + server_name = ... # type: str + server_port = ... # type: int + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type) -> None: ... + +class BaseHTTPRequestHandler: + client_address = ... # type: Tuple[str, int] + server = ... # type: SocketServer.BaseServer + close_connection = ... # type: bool + command = ... # type: str + path = ... # type: str + request_version = ... # type: str + headers = ... # type: mimetools.Message + rfile = ... # type: BinaryIO + wfile = ... # type: BinaryIO + server_version = ... # type: str + sys_version = ... # type: str + error_message_format = ... # type: str + error_content_type = ... # type: str + protocol_version = ... # type: str + MessageClass = ... # type: type + responses = ... # type: Mapping[int, Tuple[str, str]] + def __init__(self, request: bytes, client_address: Tuple[str, int], + server: SocketServer.BaseServer) -> None: ... + def handle(self) -> None: ... + def handle_one_request(self) -> None: ... + def send_error(self, code: int, message: Optional[str] = ...) -> None: ... + def send_response(self, code: int, + message: Optional[str] = ...) -> None: ... + def send_header(self, keyword: str, value: str) -> None: ... + def end_headers(self) -> None: ... + def flush_headers(self) -> None: ... + def log_request(self, code: Union[int, str] = ..., + size: Union[int, str] = ...) -> None: ... + def log_error(self, format: str, *args: Any) -> None: ... + def log_message(self, format: str, *args: Any) -> None: ... + def version_string(self) -> str: ... + def date_time_string(self, timestamp: Optional[int] = ...) -> str: ... + def log_date_time_string(self) -> str: ... + def address_string(self) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ConfigParser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ConfigParser.pyi new file mode 100644 index 000000000..203d75319 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ConfigParser.pyi @@ -0,0 +1,95 @@ +from typing import Any, IO, Sequence, Tuple, Union, List, Dict + +DEFAULTSECT = ... # type: str +MAX_INTERPOLATION_DEPTH = ... # type: int + +class Error(Exception): + message = ... # type: Any + def __init__(self, msg: str = ...) -> None: ... + def _get_message(self) -> None: ... + def _set_message(self, value: str) -> None: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + +class NoSectionError(Error): + section = ... # type: str + def __init__(self, section: str) -> None: ... + +class DuplicateSectionError(Error): + section = ... # type: str + def __init__(self, section: str) -> None: ... + +class NoOptionError(Error): + section = ... # type: str + option = ... # type: str + def __init__(self, option: str, section: str) -> None: ... + +class InterpolationError(Error): + section = ... # type: str + option = ... # type: str + msg = ... # type: str + def __init__(self, option: str, section: str, msg: str) -> None: ... + +class InterpolationMissingOptionError(InterpolationError): + reference = ... # type: str + def __init__(self, option: str, section: str, rawval: str, reference: str) -> None: ... + +class InterpolationSyntaxError(InterpolationError): ... + +class InterpolationDepthError(InterpolationError): + def __init__(self, option: str, section: str, rawval: str) -> None: ... + +class ParsingError(Error): + filename = ... # type: str + errors = ... # type: List[Tuple[Any, Any]] + def __init__(self, filename: str) -> None: ... + def append(self, lineno: Any, line: Any) -> None: ... + +class MissingSectionHeaderError(ParsingError): + lineno = ... # type: Any + line = ... # type: Any + def __init__(self, filename: str, lineno: Any, line: Any) -> None: ... + + +class RawConfigParser: + _dict = ... # type: Any + _sections = ... # type: dict + _defaults = ... # type: dict + _optcre = ... # type: Any + SECTCRE = ... # type: Any + OPTCRE = ... # type: Any + OPTCRE_NV = ... # type: Any + def __init__(self, defaults: Dict[Any, Any] = ..., dict_type: Any = ..., allow_no_value: bool = ...) -> None: ... + def defaults(self) -> Dict[Any, Any]: ... + def sections(self) -> List[str]: ... + def add_section(self, section: str) -> None: ... + def has_section(self, section: str) -> bool: ... + def options(self, section: str) -> List[str]: ... + def read(self, filenames: Union[str, Sequence[str]]) -> List[str]: ... + def readfp(self, fp: IO[str], filename: str = ...) -> None: ... + def get(self, section: str, option: str) -> str: ... + def items(self, section: str) -> List[Tuple[Any, Any]]: ... + def _get(self, section: str, conv: type, option: str) -> Any: ... + def getint(self, section: str, option: str) -> int: ... + def getfloat(self, section: str, option: str) -> float: ... + _boolean_states = ... # type: Dict[str, bool] + def getboolean(self, section: str, option: str) -> bool: ... + def optionxform(self, optionstr: str) -> str: ... + def has_option(self, section: str, option: str) -> bool: ... + def set(self, section: str, option: str, value: Any = ...) -> None: ... + def write(self, fp: IO[str]) -> None: ... + def remove_option(self, section: str, option: Any) -> bool: ... + def remove_section(self, section: str) -> bool: ... + def _read(self, fp: IO[str], fpname: str) -> None: ... + +class ConfigParser(RawConfigParser): + _KEYCRE = ... # type: Any + def get(self, section: str, option: str, raw: bool = ..., vars: dict = ...) -> Any: ... + def items(self, section: str, raw: bool = ..., vars: dict = ...) -> List[Tuple[str, Any]]: ... + def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... + def _interpolation_replace(self, match: Any) -> str: ... + +class SafeConfigParser(ConfigParser): + _interpvar_re = ... # type: Any + def _interpolate(self, section: str, option: str, rawval: Any, vars: Any) -> str: ... + def _interpolate_some(self, option: str, accum: list, rest: str, section: str, map: dict, depth: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/Cookie.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/Cookie.pyi new file mode 100644 index 000000000..a4e634404 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/Cookie.pyi @@ -0,0 +1,40 @@ +from typing import Any + +class CookieError(Exception): ... + +class Morsel(dict): + key = ... # type: Any + def __init__(self): ... + def __setitem__(self, K, V): ... + def isReservedKey(self, K): ... + value = ... # type: Any + coded_value = ... # type: Any + def set(self, key, val, coded_val, LegalChars=..., idmap=..., translate=...): ... + def output(self, attrs=None, header=...): ... + def js_output(self, attrs=None): ... + def OutputString(self, attrs=None): ... + +class BaseCookie(dict): + def value_decode(self, val): ... + def value_encode(self, val): ... + def __init__(self, input=None): ... + def __setitem__(self, key, value): ... + def output(self, attrs=None, header=..., sep=...): ... + def js_output(self, attrs=None): ... + def load(self, rawdata): ... + +class SimpleCookie(BaseCookie): + def value_decode(self, val): ... + def value_encode(self, val): ... + +class SerialCookie(BaseCookie): + def __init__(self, input=None): ... + def value_decode(self, val): ... + def value_encode(self, val): ... + +class SmartCookie(BaseCookie): + def __init__(self, input=None): ... + def value_decode(self, val): ... + def value_encode(self, val): ... + +Cookie = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/HTMLParser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/HTMLParser.pyi new file mode 100644 index 000000000..989e14c80 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/HTMLParser.pyi @@ -0,0 +1,31 @@ +from typing import List, Tuple, AnyStr +from markupbase import ParserBase + +class HTMLParser(ParserBase): + def __init__(self) -> None: ... + def feed(self, feed: AnyStr) -> None: ... + def close(self) -> None: ... + def reset(self) -> None: ... + + def get_starttag_text(self) -> AnyStr: ... + def set_cdata_mode(self, AnyStr) -> None: ... + def clear_cdata_mode(self) -> None: ... + + def handle_startendtag(self, tag: AnyStr, attrs: List[Tuple[AnyStr, AnyStr]]): ... + def handle_starttag(self, tag: AnyStr, attrs: List[Tuple[AnyStr, AnyStr]]): ... + def handle_endtag(self, tag: AnyStr): ... + def handle_charref(self, name: AnyStr): ... + def handle_entityref(self, name: AnyStr): ... + def handle_data(self, data: AnyStr): ... + def handle_comment(self, data: AnyStr): ... + def handle_decl(self, decl: AnyStr): ... + def handle_pi(self, data: AnyStr): ... + + def unknown_decl(self, data: AnyStr): ... + + def unescape(self, s: AnyStr) -> AnyStr: ... + +class HTMLParseError(Exception): + msg = ... # type: str + lineno = ... # type: int + offset = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/Queue.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/Queue.pyi new file mode 100644 index 000000000..831b96cc4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/Queue.pyi @@ -0,0 +1,29 @@ +# Stubs for Queue (Python 2) + +from typing import Any, TypeVar, Generic, Optional + +_T = TypeVar('_T') + +class Empty(Exception): ... +class Full(Exception): ... + +class Queue(Generic[_T]): + maxsize = ... # type: Any + mutex = ... # type: Any + not_empty = ... # type: Any + not_full = ... # type: Any + all_tasks_done = ... # type: Any + unfinished_tasks = ... # type: Any + def __init__(self, maxsize: int = ...) -> None: ... + def task_done(self) -> None: ... + def join(self) -> None: ... + def qsize(self) -> int: ... + def empty(self) -> bool: ... + def full(self) -> bool: ... + def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... + def put_nowait(self, item: _T) -> None: ... + def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... + def get_nowait(self) -> _T: ... + +class PriorityQueue(Queue): ... +class LifoQueue(Queue): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/SimpleHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/SimpleHTTPServer.pyi new file mode 100644 index 000000000..5bfed2a5f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/SimpleHTTPServer.pyi @@ -0,0 +1,16 @@ +# Stubs for SimpleHTTPServer (Python 2) + +from typing import Any, AnyStr, IO, Mapping, Optional, Union +import BaseHTTPServer +from StringIO import StringIO + +class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + server_version = ... # type: str + def do_GET(self) -> None: ... + def do_HEAD(self) -> None: ... + def send_head(self) -> Optional[IO[str]]: ... + def list_directory(self, path: Union[str, unicode]) -> Optional[StringIO]: ... + def translate_path(self, path: AnyStr) -> AnyStr: ... + def copyfile(self, source: IO[AnyStr], outputfile: IO[AnyStr]): ... + def guess_type(self, path: Union[str, unicode]) -> str: ... + extensions_map = ... # type: Mapping[str, str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/SocketServer.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/SocketServer.pyi new file mode 100644 index 000000000..3c4aec6cd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/SocketServer.pyi @@ -0,0 +1,99 @@ +# NB: SocketServer.pyi and socketserver.pyi must remain consistent! +# Stubs for socketserver + +from typing import Any, BinaryIO, Optional, Tuple, Type +from socket import SocketType +import sys +import types + +class BaseServer: + address_family = ... # type: int + RequestHandlerClass = ... # type: type + server_address = ... # type: Tuple[str, int] + socket = ... # type: SocketType + allow_reuse_address = ... # type: bool + request_queue_size = ... # type: int + socket_type = ... # type: int + timeout = ... # type: Optional[float] + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type) -> None: ... + def fileno(self) -> int: ... + def handle_request(self) -> None: ... + def serve_forever(self, poll_interval: float = ...) -> None: ... + def shutdown(self) -> None: ... + def server_close(self) -> None: ... + def finish_request(self, request: bytes, + client_address: Tuple[str, int]) -> None: ... + def get_request(self) -> None: ... + def handle_error(self, request: bytes, + client_address: Tuple[str, int]) -> None: ... + def handle_timeout(self) -> None: ... + def process_request(self, request: bytes, + client_address: Tuple[str, int]) -> None: ... + def server_activate(self) -> None: ... + def server_bind(self) -> None: ... + def verify_request(self, request: bytes, + client_address: Tuple[str, int]) -> bool: ... + if sys.version_info >= (3, 6): + def __enter__(self) -> 'BaseServer': ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[types.TracebackType]) -> bool: ... + if sys.version_info >= (3, 3): + def service_actions(self) -> None: ... + +class TCPServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + +class UDPServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + +if sys.platform != 'win32': + class UnixStreamServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + + class UnixDatagramServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + +class ForkingMixIn: ... +class ThreadingMixIn: ... + +class ForkingTCPServer(ForkingMixIn, TCPServer): ... +class ForkingUDPServer(ForkingMixIn, UDPServer): ... +class ThreadingTCPServer(ThreadingMixIn, TCPServer): ... +class ThreadingUDPServer(ThreadingMixIn, UDPServer): ... +if sys.platform != 'win32': + class ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer): ... + class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer): ... + + +class BaseRequestHandler: + # Those are technically of types, respectively: + # * Union[SocketType, Tuple[bytes, SocketType]] + # * Union[Tuple[str, int], str] + # But there are some concerns that having unions here would cause + # too much inconvenience to people using it (see + # https://github.com/python/typeshed/pull/384#issuecomment-234649696) + request = ... # type: Any + client_address = ... # type: Any + + server = ... # type: BaseServer + def setup(self) -> None: ... + def handle(self) -> None: ... + def finish(self) -> None: ... + +class StreamRequestHandler(BaseRequestHandler): + rfile = ... # type: BinaryIO + wfile = ... # type: BinaryIO + +class DatagramRequestHandler(BaseRequestHandler): + rfile = ... # type: BinaryIO + wfile = ... # type: BinaryIO diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/StringIO.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/StringIO.pyi new file mode 100644 index 000000000..0526edff2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/StringIO.pyi @@ -0,0 +1,30 @@ +# Stubs for StringIO (Python 2) + +from typing import Any, IO, AnyStr, Iterator, Iterable, Generic, List, Optional + +class StringIO(IO[AnyStr], Generic[AnyStr]): + closed = ... # type: bool + softspace = ... # type: int + len = ... # type: int + name = ... # type: str + def __init__(self, buf: AnyStr = ...) -> None: ... + def __iter__(self) -> Iterator[AnyStr]: ... + def next(self) -> AnyStr: ... + def close(self) -> None: ... + def isatty(self) -> bool: ... + def seek(self, pos: int, mode: int = ...) -> int: ... + def tell(self) -> int: ... + def read(self, n: int = ...) -> AnyStr: ... + def readline(self, length: int = ...) -> AnyStr: ... + def readlines(self, sizehint: int = ...) -> List[AnyStr]: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def write(self, s: AnyStr) -> int: ... + def writelines(self, iterable: Iterable[AnyStr]) -> None: ... + def flush(self) -> None: ... + def getvalue(self) -> AnyStr: ... + def __enter__(self) -> Any: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> Any: ... + def fileno(self) -> int: ... + def readable(self) -> bool: ... + def seekable(self) -> bool: ... + def writable(self) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserDict.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserDict.pyi new file mode 100644 index 000000000..33ebd1a51 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserDict.pyi @@ -0,0 +1,44 @@ +from typing import (Any, Container, Dict, Generic, Iterable, Iterator, List, + Mapping, Optional, Sized, Tuple, TypeVar, Union, overload) + +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') +_T = TypeVar('_T') + +class UserDict(Dict[_KT, _VT], Generic[_KT, _VT]): + data = ... # type: Mapping[_KT, _VT] + + def __init__(self, initialdata: Mapping[_KT, _VT] = ...) -> None: ... + + # TODO: __iter__ is not available for UserDict + +class IterableUserDict(UserDict[_KT, _VT], Generic[_KT, _VT]): + ... + +class DictMixin(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT]): + def has_key(self, key: _KT) -> bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_KT]: ... + + # From typing.Mapping[_KT, _VT] + # (can't inherit because of keys()) + @overload + def get(self, k: _KT) -> Optional[_VT]: ... + @overload + def get(self, k: _KT, default: Union[_VT, _T]) -> Union[_VT, _T]: ... + def values(self) -> List[_VT]: ... + def items(self) -> List[Tuple[_KT, _VT]]: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def __contains__(self, o: Any) -> bool: ... + + # From typing.MutableMapping[_KT, _VT] + def clear(self) -> None: ... + def pop(self, k: _KT, default: _VT = ...) -> _VT: ... + def popitem(self) -> Tuple[_KT, _VT]: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + @overload + def update(self, m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def update(self, m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserList.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserList.pyi new file mode 100644 index 000000000..b8466eed1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserList.pyi @@ -0,0 +1,18 @@ +from typing import Iterable, MutableSequence, TypeVar, Union, overload + +_T = TypeVar("_T") +_ULT = TypeVar("_ULT", bound=UserList) + +class UserList(MutableSequence[_T]): + def insert(self, index: int, object: _T) -> None: ... + @overload + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __len__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> _T: ... + @overload + def __getitem__(self: _ULT, s: slice) -> _ULT: ... + def sort(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserString.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserString.pyi new file mode 100644 index 000000000..11436371b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/UserString.pyi @@ -0,0 +1,70 @@ +import collections +from typing import Any, Iterable, List, MutableSequence, Sequence, Optional, overload, Text, TypeVar, Tuple, Union + +_UST = TypeVar("_UST", bound=UserString) +_MST = TypeVar("_MST", bound=MutableString) + +class UserString(Sequence[UserString]): + def __init__(self, seq: object) -> None: ... + def __int__(self) -> int: ... + def __long__(self) -> long: ... + def __float__(self) -> float: ... + def __complex__(self) -> complex: ... + def __hash__(self) -> int: ... + def __len__(self) -> int: ... + @overload + def __getitem__(self: _UST, i: int) -> _UST: ... + @overload + def __getitem__(self: _UST, s: slice) -> _UST: ... + def __add__(self: _UST, other: Any) -> _UST: ... + def __radd__(self: _UST, other: Any) -> _UST: ... + def __mul__(self: _UST, other: int) -> _UST: ... + def __rmul__(self: _UST, other: int) -> _UST: ... + def __mod__(self: _UST, args: Any) -> _UST: ... + def capitalize(self: _UST) -> _UST: ... + def center(self: _UST, width: int, *args: Any) -> _UST: ... + def count(self, sub: int, start: int = ..., end: int = ...) -> int: ... + def decode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ... + def encode(self: _UST, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UST: ... + def endswith(self, suffix: Text, start: int = ..., end: int = ...) -> bool: ... + def expandtabs(self: _UST, tabsize: int = ...) -> _UST: ... + def find(self, sub: Text, start: int = ..., end: int = ...) -> int: ... + def index(self, sub: Text, start: int = ..., end: int = ...) -> int: ... + def isalpha(self) -> bool: ... + def isalnum(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, seq: Iterable[Text]) -> Text: ... + def ljust(self: _UST, width: int, *args: Any) -> _UST: ... + def lower(self: _UST) -> _UST: ... + def lstrip(self: _UST, chars: Optional[Text] = ...) -> _UST: ... + def partition(self, sep: Text) -> Tuple[Text, Text, Text]: ... + def replace(self: _UST, old: Text, new: Text, maxsplit: int = ...) -> _UST: ... + def rfind(self, sub: Text, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: Text, start: int = ..., end: int = ...) -> int: ... + def rjust(self: _UST, width: int, *args: Any) -> _UST: ... + def rpartition(self, sep: Text) -> Tuple[Text, Text, Text]: ... + def rstrip(self: _UST, chars: Optional[Text] = ...) -> _UST: ... + def split(self, sep: Optional[Text] = ..., maxsplit: int = ...) -> List[Text]: ... + def rsplit(self, sep: Optional[Text] = ..., maxsplit: int = ...) -> List[Text]: ... + def splitlines(self, keepends: int = ...) -> List[Text]: ... + def startswith(self, suffix: Text, start: int = ..., end: int = ...) -> bool: ... + def strip(self: _UST, chars: Optional[Text] = ...) -> _UST: ... + def swapcase(self: _UST) -> _UST: ... + def title(self: _UST) -> _UST: ... + def translate(self: _UST, *args: Any) -> _UST: ... + def upper(self: _UST) -> _UST: ... + def zfill(self: _UST, width: int) -> _UST: ... + +class MutableString(UserString, MutableSequence[MutableString]): + def __setitem__(self, index: Union[int, slice], sub: Any) -> None: ... + def __delitem__(self, index: Union[int, slice]) -> None: ... + def immutable(self) -> UserString: ... + def __iadd__(self: _MST, other: Any) -> _MST: ... + def __imul__(self, n: int) -> _MST: ... + def insert(self, index: int, value: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/__builtin__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/__builtin__.pyi new file mode 100644 index 000000000..ffb8f14b8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/__builtin__.pyi @@ -0,0 +1,1086 @@ +# NB: __builtin__.pyi and builtins.pyi must remain consistent! +# Stubs for builtins (Python 2.7) + +# True and False are deliberately omitted because they are keywords in +# Python 3, and stub files conform to Python 3 syntax. + +from typing import ( + TypeVar, Iterator, Iterable, NoReturn, overload, + Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set, + AbstractSet, FrozenSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, + SupportsComplex, SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, + MutableSet, ItemsView, KeysView, ValuesView, Optional, Container, Type +) +from abc import abstractmethod, ABCMeta + +_T = TypeVar('_T') +_T_co = TypeVar('_T_co', covariant=True) +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') +_S = TypeVar('_S') +_T1 = TypeVar('_T1') +_T2 = TypeVar('_T2') +_T3 = TypeVar('_T3') +_T4 = TypeVar('_T4') +_T5 = TypeVar('_T5') +_TT = TypeVar('_TT', bound='type') + +class object: + __doc__ = ... # type: Optional[str] + __class__ = ... # type: type + __dict__ = ... # type: Dict[str, Any] + __slots__ = ... # type: Union[str, unicode, Iterable[Union[str, unicode]]] + __module__ = ... # type: str + + def __init__(self) -> None: ... + def __new__(cls) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __eq__(self, o: object) -> bool: ... + def __ne__(self, o: object) -> bool: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __hash__(self) -> int: ... + def __format__(self, format_spec: str) -> str: ... + def __getattribute__(self, name: str) -> Any: ... + def __delattr__(self, name: str) -> None: ... + def __sizeof__(self) -> int: ... + def __reduce__(self) -> tuple: ... + def __reduce_ex__(self, protocol: int) -> tuple: ... + +class staticmethod(object): # Special, only valid as a decorator. + __func__ = ... # type: function + + def __init__(self, f: function) -> None: ... + def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... + +class classmethod(object): # Special, only valid as a decorator. + __func__ = ... # type: function + + def __init__(self, f: function) -> None: ... + def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... + +class type(object): + __bases__ = ... # type: Tuple[type, ...] + __name__ = ... # type: str + __module__ = ... # type: str + + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... + # TODO: __new__ may have to be special and not a static method. + @overload + def __new__(cls, o: object) -> type: ... + @overload + def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... + def __call__(self, *args: Any, **kwds: Any) -> Any: ... + + # Only new-style classes + __mro__ = ... # type: Tuple[type, ...] + # Note: the documentation doesnt specify what the return type is, the standard + # implementation seems to be returning a list. + def mro(self) -> List[type]: ... + def __subclasses__(self: _TT) -> List[_TT]: ... + def __instancecheck__(self, instance: Any) -> bool: ... + def __subclasscheck__(self, subclass: type) -> bool: ... + +class int: + @overload + def __init__(self, x: SupportsInt = ...) -> None: ... + @overload + def __init__(self, x: Union[str, unicode, bytearray], base: int = ...) -> None: ... + + def bit_length(self) -> int: ... + + def __add__(self, x: int) -> int: ... + def __sub__(self, x: int) -> int: ... + def __mul__(self, x: int) -> int: ... + def __floordiv__(self, x: int) -> int: ... + def __div__(self, x: int) -> int: ... + def __truediv__(self, x: int) -> float: ... + def __mod__(self, x: int) -> int: ... + def __divmod__(self, x: int) -> Tuple[int, int]: ... + def __radd__(self, x: int) -> int: ... + def __rsub__(self, x: int) -> int: ... + def __rmul__(self, x: int) -> int: ... + def __rfloordiv__(self, x: int) -> int: ... + def __rdiv__(self, x: int) -> int: ... + def __rtruediv__(self, x: int) -> float: ... + def __rmod__(self, x: int) -> int: ... + def __rdivmod__(self, x: int) -> Tuple[int, int]: ... + def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __rpow__(self, x: int) -> Any: ... + def __and__(self, n: int) -> int: ... + def __or__(self, n: int) -> int: ... + def __xor__(self, n: int) -> int: ... + def __lshift__(self, n: int) -> int: ... + def __rshift__(self, n: int) -> int: ... + def __rand__(self, n: int) -> int: ... + def __ror__(self, n: int) -> int: ... + def __rxor__(self, n: int) -> int: ... + def __rlshift__(self, n: int) -> int: ... + def __rrshift__(self, n: int) -> int: ... + def __neg__(self) -> int: ... + def __pos__(self) -> int: ... + def __invert__(self) -> int: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: int) -> bool: ... + def __le__(self, x: int) -> bool: ... + def __gt__(self, x: int) -> bool: ... + def __ge__(self, x: int) -> bool: ... + + def __str__(self) -> str: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + def __abs__(self) -> int: ... + def __hash__(self) -> int: ... + def __nonzero__(self) -> bool: ... + +class float: + def __init__(self, x: Union[SupportsFloat, str, unicode, bytearray] = ...) -> None: ... + def as_integer_ratio(self) -> Tuple[int, int]: ... + def hex(self) -> str: ... + def is_integer(self) -> bool: ... + @classmethod + def fromhex(cls, s: str) -> float: ... + + def __add__(self, x: float) -> float: ... + def __sub__(self, x: float) -> float: ... + def __mul__(self, x: float) -> float: ... + def __floordiv__(self, x: float) -> float: ... + def __div__(self, x: float) -> float: ... + def __truediv__(self, x: float) -> float: ... + def __mod__(self, x: float) -> float: ... + def __divmod__(self, x: float) -> Tuple[float, float]: ... + def __pow__(self, x: float) -> float: ... + def __radd__(self, x: float) -> float: ... + def __rsub__(self, x: float) -> float: ... + def __rmul__(self, x: float) -> float: ... + def __rfloordiv__(self, x: float) -> float: ... + def __rdiv__(self, x: float) -> float: ... + def __rtruediv__(self, x: float) -> float: ... + def __rmod__(self, x: float) -> float: ... + def __rdivmod__(self, x: float) -> Tuple[float, float]: ... + def __rpow__(self, x: float) -> float: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: float) -> bool: ... + def __le__(self, x: float) -> bool: ... + def __gt__(self, x: float) -> bool: ... + def __ge__(self, x: float) -> bool: ... + def __neg__(self) -> float: ... + def __pos__(self) -> float: ... + + def __str__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __abs__(self) -> float: ... + def __hash__(self) -> int: ... + def __nonzero__(self) -> bool: ... + +class complex: + @overload + def __init__(self, re: float = ..., im: float = ...) -> None: ... + @overload + def __init__(self, s: str) -> None: ... + @overload + def __init__(self, s: SupportsComplex) -> None: ... + + @property + def real(self) -> float: ... + @property + def imag(self) -> float: ... + + def conjugate(self) -> complex: ... + + def __add__(self, x: complex) -> complex: ... + def __sub__(self, x: complex) -> complex: ... + def __mul__(self, x: complex) -> complex: ... + def __pow__(self, x: complex) -> complex: ... + def __div__(self, x: complex) -> complex: ... + def __truediv__(self, x: complex) -> complex: ... + def __radd__(self, x: complex) -> complex: ... + def __rsub__(self, x: complex) -> complex: ... + def __rmul__(self, x: complex) -> complex: ... + def __rpow__(self, x: complex) -> complex: ... + def __rdiv__(self, x: complex) -> complex: ... + def __rtruediv__(self, x: complex) -> complex: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __neg__(self) -> complex: ... + def __pos__(self) -> complex: ... + + def __complex__(self) -> complex: ... + def __str__(self) -> str: ... + def __abs__(self) -> float: ... + def __hash__(self) -> int: ... + def __nonzero__(self) -> bool: ... + +class super(object): + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + +class basestring(metaclass=ABCMeta): ... + +class unicode(basestring, Sequence[unicode]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... + def capitalize(self) -> unicode: ... + def center(self, width: int, fillchar: unicode = ...) -> unicode: ... + def count(self, x: unicode) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> unicode: ... + def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... + def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[unicode]) -> unicode: ... + def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def lower(self) -> unicode: ... + def lstrip(self, chars: unicode = ...) -> unicode: ... + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... + def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def rstrip(self, chars: unicode = ...) -> unicode: ... + def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[unicode]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def strip(self, chars: unicode = ...) -> unicode: ... + def swapcase(self) -> unicode: ... + def title(self) -> unicode: ... + def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... + def upper(self) -> unicode: ... + def zfill(self, width: int) -> unicode: ... + + @overload + def __getitem__(self, i: int) -> unicode: ... + @overload + def __getitem__(self, s: slice) -> unicode: ... + def __getslice__(self, start: int, stop: int) -> unicode: ... + def __add__(self, s: unicode) -> unicode: ... + def __mul__(self, n: int) -> unicode: ... + def __rmul__(self, n: int) -> unicode: ... + def __mod__(self, x: Any) -> unicode: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + + def __len__(self) -> int: ... + def __contains__(self, s: object) -> bool: ... + def __iter__(self) -> Iterator[unicode]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + +class str(basestring, Sequence[str]): + def __init__(self, object: object = ...) -> None: ... + def capitalize(self) -> str: ... + def center(self, width: int, fillchar: str = ...) -> str: ... + def count(self, x: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> str: ... + def find(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> str: ... + def index(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... + def ljust(self, width: int, fillchar: str = ...) -> str: ... + def lower(self) -> str: ... + @overload + def lstrip(self, chars: str = ...) -> str: ... + @overload + def lstrip(self, chars: unicode) -> unicode: ... + @overload + def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def partition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... + def rfind(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rindex(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: str = ...) -> str: ... + @overload + def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + @overload + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + @overload + def rstrip(self, chars: str = ...) -> str: ... + @overload + def rstrip(self, chars: unicode) -> unicode: ... + @overload + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[str]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + @overload + def strip(self, chars: str = ...) -> str: ... + @overload + def strip(self, chars: unicode) -> unicode: ... + def swapcase(self) -> str: ... + def title(self) -> str: ... + def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... + def upper(self) -> str: ... + def zfill(self, width: int) -> str: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> str: ... + @overload + def __getitem__(self, s: slice) -> str: ... + def __getslice__(self, start: int, stop: int) -> str: ... + def __add__(self, s: AnyStr) -> AnyStr: ... + def __mul__(self, n: int) -> str: ... + def __rmul__(self, n: int) -> str: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + def __mod__(self, x: Any) -> str: ... + +class bytearray(MutableSequence[int]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, x: Union[Iterable[int], str]) -> None: ... + @overload + def __init__(self, x: unicode, encoding: unicode, + errors: unicode = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + def capitalize(self) -> bytearray: ... + def center(self, width: int, fillchar: str = ...) -> bytearray: ... + def count(self, x: str) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[str, Tuple[str, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytearray: ... + def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def insert(self, index: int, object: int) -> None: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[str]) -> bytearray: ... + def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... + def lower(self) -> bytearray: ... + def lstrip(self, chars: str = ...) -> bytearray: ... + def partition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... + def replace(self, old: str, new: str, count: int = ...) -> bytearray: ... + def rfind(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: str = ...) -> bytearray: ... + def rpartition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def rstrip(self, chars: str = ...) -> bytearray: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... + def startswith(self, prefix: Union[str, Tuple[str, ...]]) -> bool: ... + def strip(self, chars: str = ...) -> bytearray: ... + def swapcase(self) -> bytearray: ... + def title(self) -> bytearray: ... + def translate(self, table: str) -> bytearray: ... + def upper(self) -> bytearray: ... + def zfill(self, width: int) -> bytearray: ... + @staticmethod + def fromhex(x: str) -> bytearray: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytearray: ... + def __getslice__(self, start: int, stop: int) -> bytearray: ... + @overload + def __setitem__(self, i: int, x: int) -> None: ... + @overload + def __setitem__(self, s: slice, x: Union[Iterable[int], str]) -> None: ... + def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + def __add__(self, s: str) -> bytearray: ... + def __mul__(self, n: int) -> bytearray: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: str) -> bool: ... + def __le__(self, x: str) -> bool: ... + def __gt__(self, x: str) -> bool: ... + def __ge__(self, x: str) -> bool: ... + +class bool(int): + def __init__(self, o: object = ...) -> None: ... + @overload # type: ignore + def __and__(self, x: bool) -> bool: ... + @overload # type: ignore + def __and__(self, x: int) -> int: ... + @overload # type: ignore + def __or__(self, x: bool) -> bool: ... + @overload # type: ignore + def __or__(self, x: int) -> int: ... + @overload # type: ignore + def __xor__(self, x: bool) -> bool: ... + @overload # type: ignore + def __xor__(self, x: int) -> int: ... + @overload # type: ignore + def __rand__(self, x: bool) -> bool: ... + @overload # type: ignore + def __rand__(self, x: int) -> int: ... + @overload # type: ignore + def __ror__(self, x: bool) -> bool: ... + @overload # type: ignore + def __ror__(self, x: int) -> int: ... + @overload # type: ignore + def __rxor__(self, x: bool) -> bool: ... + @overload # type: ignore + def __rxor__(self, x: int) -> int: ... + +class slice(object): + start = ... # type: Optional[int] + step = ... # type: Optional[int] + stop = ... # type: Optional[int] + @overload + def __init__(self, stop: Optional[int]) -> None: ... + @overload + def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> None: ... + def indices(self, len: int) -> Tuple[int, int, int]: ... + +class tuple(Sequence[_T_co], Generic[_T_co]): + def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, x: object) -> bool: ... + @overload + def __getitem__(self, x: int) -> _T_co: ... + @overload + def __getitem__(self, x: slice) -> Tuple[_T_co, ...]: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __lt__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... + def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... + def count(self, x: Any) -> int: ... + def index(self, x: Any) -> int: ... + +class function: + # TODO name of the class (corresponds to Python 'function' class) + __name__ = ... # type: str + __module__ = ... # type: str + +class list(MutableSequence[_T], Generic[_T]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def append(self, object: _T) -> None: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def pop(self, index: int = ...) -> _T: ... + def index(self, object: _T, start: int = ..., stop: int = ...) -> int: ... + def count(self, object: _T) -> int: ... + def insert(self, index: int, object: _T) -> None: ... + def remove(self, object: _T) -> None: ... + def reverse(self) -> None: ... + def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> _T: ... + @overload + def __getitem__(self, s: slice) -> List[_T]: ... + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + @overload + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... + def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + def __add__(self, x: List[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __mul__(self, n: int) -> List[_T]: ... + def __rmul__(self, n: int) -> List[_T]: ... + def __contains__(self, o: object) -> bool: ... + def __reversed__(self) -> Iterator[_T]: ... + def __gt__(self, x: List[_T]) -> bool: ... + def __ge__(self, x: List[_T]) -> bool: ... + def __lt__(self, x: List[_T]) -> bool: ... + def __le__(self, x: List[_T]) -> bool: ... + +class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): + # NOTE: Keyword arguments are special. If they are used, _KT must include + # str, but we have no way of enforcing it here. + @overload + def __init__(self, **kwargs: _VT) -> None: ... + @overload + def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + + def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... + + def has_key(self, k: _KT) -> bool: ... + def clear(self) -> None: ... + def copy(self) -> Dict[_KT, _VT]: ... + def popitem(self) -> Tuple[_KT, _VT]: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + @overload + def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + @overload + def update(self, **kwargs: _VT) -> None: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def viewkeys(self) -> KeysView[_KT]: ... + def viewvalues(self) -> ValuesView[_VT]: ... + def viewitems(self) -> ItemsView[_KT, _VT]: ... + @staticmethod + @overload + def fromkeys(seq: Sequence[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) + @staticmethod + @overload + def fromkeys(seq: Sequence[_T], value: _S) -> Dict[_T, _S]: ... + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + +class set(MutableSet[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T] = ...) -> None: ... + def add(self, element: _T) -> None: ... + def clear(self) -> None: ... + def copy(self) -> Set[_T]: ... + def difference(self, *s: Iterable[Any]) -> Set[_T]: ... + def difference_update(self, *s: Iterable[Any]) -> None: ... + def discard(self, element: _T) -> None: ... + def intersection(self, *s: Iterable[Any]) -> Set[_T]: ... + def intersection_update(self, *s: Iterable[Any]) -> None: ... + def isdisjoint(self, s: Iterable[object]) -> bool: ... + def issubset(self, s: Iterable[object]) -> bool: ... + def issuperset(self, s: Iterable[object]) -> bool: ... + def pop(self) -> _T: ... + def remove(self, element: _T) -> None: ... + def symmetric_difference(self, s: Iterable[_T]) -> Set[_T]: ... + def symmetric_difference_update(self, s: Iterable[_T]) -> None: ... + def union(self, *s: Iterable[_T]) -> Set[_T]: ... + def update(self, *s: Iterable[_T]) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __and__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __sub__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __isub__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __le__(self, s: AbstractSet[object]) -> bool: ... + def __lt__(self, s: AbstractSet[object]) -> bool: ... + def __ge__(self, s: AbstractSet[object]) -> bool: ... + def __gt__(self, s: AbstractSet[object]) -> bool: ... + +class frozenset(AbstractSet[_T], Generic[_T]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def copy(self) -> FrozenSet[_T]: ... + def difference(self, *s: Iterable[object]) -> FrozenSet[_T]: ... + def intersection(self, *s: Iterable[object]) -> FrozenSet[_T]: ... + def isdisjoint(self, s: Iterable[_T]) -> bool: ... + def issubset(self, s: Iterable[object]) -> bool: ... + def issuperset(self, s: Iterable[object]) -> bool: ... + def symmetric_difference(self, s: Iterable[_T]) -> FrozenSet[_T]: ... + def union(self, *s: Iterable[_T]) -> FrozenSet[_T]: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __and__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... + def __or__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... + def __sub__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... + def __xor__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... + def __le__(self, s: AbstractSet[object]) -> bool: ... + def __lt__(self, s: AbstractSet[object]) -> bool: ... + def __ge__(self, s: AbstractSet[object]) -> bool: ... + def __gt__(self, s: AbstractSet[object]) -> bool: ... + +class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): + def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... + def __iter__(self) -> Iterator[Tuple[int, _T]]: ... + def next(self) -> Tuple[int, _T]: ... + # TODO __getattribute__ + +class xrange(Sized, Iterable[int], Reversible[int]): + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __getitem__(self, i: int) -> int: ... + def __reversed__(self) -> Iterator[int]: ... + +class property(object): + def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., + fset: Optional[Callable[[Any, Any], None]] = ..., + fdel: Optional[Callable[[Any], None]] = ..., doc: Optional[str] = ...) -> None: ... + def getter(self, fget: Callable[[Any], Any]) -> property: ... + def setter(self, fset: Callable[[Any, Any], None]) -> property: ... + def deleter(self, fdel: Callable[[Any], None]) -> property: ... + def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ... + def __set__(self, obj: Any, value: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... + def fget(self) -> Any: ... + def fset(self, value: Any) -> None: ... + def fdel(self) -> None: ... + +long = int +bytes = str + +NotImplemented = ... # type: Any + +def abs(n: SupportsAbs[_T]) -> _T: ... +def all(i: Iterable[object]) -> bool: ... +def any(i: Iterable[object]) -> bool: ... +def bin(number: int) -> str: ... +def callable(o: object) -> bool: ... +def chr(code: int) -> str: ... +def compile(source: Any, filename: unicode, mode: str, flags: int = ..., + dont_inherit: int = ...) -> Any: ... +def delattr(o: Any, name: unicode) -> None: ... +def dir(o: object = ...) -> List[str]: ... +@overload +def divmod(a: int, b: int) -> Tuple[int, int]: ... +@overload +def divmod(a: float, b: float) -> Tuple[float, float]: ... +def exit(code: Any = ...) -> NoReturn: ... +@overload +def filter(function: None, + iterable: Iterable[Optional[_T]]) -> List[_T]: ... +@overload +def filter(function: Callable[[_T], Any], + iterable: Iterable[_T]) -> List[_T]: ... +def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode +def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ... +def hasattr(o: Any, name: unicode) -> bool: ... +def hash(o: object) -> int: ... +def hex(i: int) -> str: ... # TODO __index__ +def id(o: object) -> int: ... +def input(prompt: Any = ...) -> Any: ... +def intern(string: str) -> str: ... +@overload +def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... +@overload +def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... +def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def len(o: Sized) -> int: ... +@overload +def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... +@overload +def map(func: None, + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +@overload +def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[_S]: ... +@overload +def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[_S]: ... +@overload +def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def next(i: Iterator[_T]) -> _T: ... +@overload +def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... +def oct(i: int) -> str: ... # TODO __index__ +@overload +def open(file: str, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... +@overload +def open(file: unicode, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... +@overload +def open(file: int, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... +def ord(c: unicode) -> int: ... +# This is only available after from __future__ import print_function. +def print(*values: Any, sep: unicode = ..., end: unicode = ..., + file: IO[Any] = ...) -> None: ... +@overload +def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y. +@overload +def pow(x: int, y: int, z: int) -> Any: ... +@overload +def pow(x: float, y: float) -> float: ... +@overload +def pow(x: float, y: float, z: float) -> float: ... +def quit(code: int = ...) -> None: ... +def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... +def raw_input(prompt: Any = ...) -> str: ... + +@overload +def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... +@overload +def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... + +def reload(module: Any) -> Any: ... +@overload +def reversed(object: Sequence[_T]) -> Iterator[_T]: ... +@overload +def reversed(object: Reversible[_T]) -> Iterator[_T]: ... +def repr(o: object) -> str: ... +@overload +def round(number: float) -> float: ... +@overload +def round(number: float, ndigits: int) -> float: ... # Always return a float if given ndigits. +@overload +def round(number: SupportsRound[_T]) -> _T: ... +@overload +def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def setattr(object: Any, name: unicode, value: Any) -> None: ... +def sorted(iterable: Iterable[_T], *, + cmp: Callable[[_T, _T], int] = ..., + key: Callable[[_T], Any] = ..., + reverse: bool = ...) -> List[_T]: ... +@overload +def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... +@overload +def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... +def unichr(i: int) -> unicode: ... +def vars(object: Any = ...) -> Dict[str, Any]: ... +@overload +def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... +@overload +def zip(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, + _T3, _T4]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... +@overload +def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +def __import__(name: unicode, + globals: Dict[str, Any] = ..., + locals: Dict[str, Any] = ..., + fromlist: List[str] = ..., level: int = ...) -> Any: ... + +def globals() -> Dict[str, Any]: ... +def locals() -> Dict[str, Any]: ... + +# Actually the type of Ellipsis is , but since it's +# not exposed anywhere under that name, we make it private here. +class ellipsis: ... +Ellipsis = ... # type: ellipsis + +# TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. +_AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) + +class buffer(Sized): + def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... + def __add__(self, other: _AnyBuffer) -> str: ... + def __cmp__(self, other: _AnyBuffer) -> bool: ... + def __getitem__(self, key: Union[int, slice]) -> str: ... + def __getslice__(self, i: int, j: int) -> str: ... + def __len__(self) -> int: ... + def __mul__(self, x: int) -> str: ... + +class memoryview(Sized, Container[bytes]): + format = ... # type: str + itemsize = ... # type: int + shape = ... # type: Optional[Tuple[int, ...]] + strides = ... # type: Optional[Tuple[int, ...]] + suboffsets = ... # type: Optional[Tuple[int, ...]] + readonly = ... # type: bool + ndim = ... # type: int + + def __init__(self, obj: Union[str, bytearray, buffer, memoryview]) -> None: ... + + @overload + def __getitem__(self, i: int) -> bytes: ... + @overload + def __getitem__(self, s: slice) -> memoryview: ... + + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[bytes]: ... + def __len__(self) -> int: ... + + @overload + def __setitem__(self, i: int, o: bytes) -> None: ... + @overload + def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... + @overload + def __setitem__(self, s: slice, o: memoryview) -> None: ... + + def tobytes(self) -> bytes: ... + def tolist(self) -> List[int]: ... + +class BaseException(object): + args = ... # type: Tuple[Any, ...] + message = ... # type: Any + def __init__(self, *args: object, **kwargs: object) -> None: ... + def __getitem__(self, i: int) -> Any: ... + def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + +class GeneratorExit(BaseException): ... +class KeyboardInterrupt(BaseException): ... +class SystemExit(BaseException): + code = 0 +class Exception(BaseException): ... +class StopIteration(Exception): ... +class StandardError(Exception): ... +class ArithmeticError(StandardError): ... +class BufferError(StandardError): ... +class EnvironmentError(StandardError): + errno = 0 + strerror = ... # type: str + # TODO can this be unicode? + filename = ... # type: str +class LookupError(StandardError): ... +class RuntimeError(StandardError): ... +class ValueError(StandardError): ... +class AssertionError(StandardError): ... +class AttributeError(StandardError): ... +class EOFError(StandardError): ... +class FloatingPointError(ArithmeticError): ... +class IOError(EnvironmentError): ... +class ImportError(StandardError): ... +class IndexError(LookupError): ... +class KeyError(LookupError): ... +class MemoryError(StandardError): ... +class NameError(StandardError): ... +class NotImplementedError(RuntimeError): ... +class OSError(EnvironmentError): ... +class WindowsError(OSError): + winerror = ... # type: int +class OverflowError(ArithmeticError): ... +class ReferenceError(StandardError): ... +class SyntaxError(StandardError): + msg = ... # type: str + lineno = ... # type: int + offset = ... # type: int + text = ... # type: str + filename = ... # type: str +class IndentationError(SyntaxError): ... +class TabError(IndentationError): ... +class SystemError(StandardError): ... +class TypeError(StandardError): ... +class UnboundLocalError(NameError): ... +class UnicodeError(ValueError): ... +class UnicodeDecodeError(UnicodeError): + encoding: bytes + object: bytes + start: int + end: int + reason: bytes + def __init__(self, __encoding: bytes, __object: bytes, __start: int, __end: int, + __reason: bytes) -> None: ... +class UnicodeEncodeError(UnicodeError): + encoding: bytes + object: unicode + start: int + end: int + reason: bytes + def __init__(self, __encoding: bytes, __object: unicode, __start: int, __end: int, + __reason: bytes) -> None: ... +class UnicodeTranslateError(UnicodeError): ... +class ZeroDivisionError(ArithmeticError): ... + +class Warning(Exception): ... +class UserWarning(Warning): ... +class DeprecationWarning(Warning): ... +class SyntaxWarning(Warning): ... +class RuntimeWarning(Warning): ... +class FutureWarning(Warning): ... +class PendingDeprecationWarning(Warning): ... +class ImportWarning(Warning): ... +class UnicodeWarning(Warning): ... +class BytesWarning(Warning): ... + +def eval(s: Union[str, unicode], globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ...) -> Any: ... +def exec(object: str, + globals: Optional[Dict[str, Any]] = ..., + locals: Optional[Dict[str, Any]] = ...) -> Any: ... # TODO code object as source + +def cmp(x: Any, y: Any) -> int: ... + +def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... + +class file(BinaryIO): + @overload + def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def __enter__(self) -> BinaryIO: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def flush(self) -> None: ... + def fileno(self) -> int: ... + def isatty(self) -> bool: ... + def close(self) -> None: ... + + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def seekable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def write(self, data: str) -> int: ... + def writelines(self, data: Iterable[str]) -> None: ... + def truncate(self, pos: Optional[int] = ...) -> int: ... + +# Very old builtins +def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... +_N = TypeVar('_N', bool, int, float, complex) +def coerce(x: _N, y: _N) -> Tuple[_N, _N]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_ast.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_ast.pyi new file mode 100644 index 000000000..a0a7a00c8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_ast.pyi @@ -0,0 +1,328 @@ +import typing +from typing import Optional, Union + +__version__ = ... # type: str + +PyCF_ONLY_AST = ... # type: int + +_identifier = str + +class AST: + _attributes = ... # type: typing.Tuple[str, ...] + _fields = ... # type: typing.Tuple[str, ...] + def __init__(self, *args, **kwargs) -> None: ... + +class mod(AST): + ... + +class Module(mod): + body = ... # type: typing.List[stmt] + +class Interactive(mod): + body = ... # type: typing.List[stmt] + +class Expression(mod): + body = ... # type: expr + +class Suite(mod): + body = ... # type: typing.List[stmt] + + +class stmt(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class FunctionDef(stmt): + name = ... # type: _identifier + args = ... # type: arguments + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + +class ClassDef(stmt): + name = ... # type: _identifier + bases = ... # type: typing.List[expr] + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + +class Return(stmt): + value = ... # type: Optional[expr] + +class Delete(stmt): + targets = ... # type: typing.List[expr] + +class Assign(stmt): + targets = ... # type: typing.List[expr] + value = ... # type: expr + +class AugAssign(stmt): + target = ... # type: expr + op = ... # type: operator + value = ... # type: expr + +class Print(stmt): + dest = ... # type: Optional[expr] + values = ... # type: typing.List[expr] + nl = ... # type: bool + +class For(stmt): + target = ... # type: expr + iter = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class While(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class If(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class With(stmt): + context_expr = ... # type: expr + optional_vars = ... # type: Optional[expr] + body = ... # type: typing.List[stmt] + +class Raise(stmt): + type = ... # type: Optional[expr] + inst = ... # type: Optional[expr] + tback = ... # type: Optional[expr] + +class TryExcept(stmt): + body = ... # type: typing.List[stmt] + handlers = ... # type: typing.List[ExceptHandler] + orelse = ... # type: typing.List[stmt] + +class TryFinally(stmt): + body = ... # type: typing.List[stmt] + finalbody = ... # type: typing.List[stmt] + +class Assert(stmt): + test = ... # type: expr + msg = ... # type: Optional[expr] + +class Import(stmt): + names = ... # type: typing.List[alias] + +class ImportFrom(stmt): + module = ... # type: Optional[_identifier] + names = ... # type: typing.List[alias] + level = ... # type: Optional[int] + +class Exec(stmt): + body = ... # type: expr + globals = ... # type: Optional[expr] + locals = ... # type: Optional[expr] + +class Global(stmt): + names = ... # type: typing.List[_identifier] + +class Expr(stmt): + value = ... # type: expr + +class Pass(stmt): ... +class Break(stmt): ... +class Continue(stmt): ... + + +class slice(AST): + ... + +_slice = slice # this lets us type the variable named 'slice' below + +class Slice(slice): + lower = ... # type: Optional[expr] + upper = ... # type: Optional[expr] + step = ... # type: Optional[expr] + +class ExtSlice(slice): + dims = ... # type: typing.List[slice] + +class Index(slice): + value = ... # type: expr + +class Ellipsis(slice): ... + + +class expr(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class BoolOp(expr): + op = ... # type: boolop + values = ... # type: typing.List[expr] + +class BinOp(expr): + left = ... # type: expr + op = ... # type: operator + right = ... # type: expr + +class UnaryOp(expr): + op = ... # type: unaryop + operand = ... # type: expr + +class Lambda(expr): + args = ... # type: arguments + body = ... # type: expr + +class IfExp(expr): + test = ... # type: expr + body = ... # type: expr + orelse = ... # type: expr + +class Dict(expr): + keys = ... # type: typing.List[expr] + values = ... # type: typing.List[expr] + +class Set(expr): + elts = ... # type: typing.List[expr] + +class ListComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class SetComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class DictComp(expr): + key = ... # type: expr + value = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class GeneratorExp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class Yield(expr): + value = ... # type: Optional[expr] + +class Compare(expr): + left = ... # type: expr + ops = ... # type: typing.List[cmpop] + comparators = ... # type: typing.List[expr] + +class Call(expr): + func = ... # type: expr + args = ... # type: typing.List[expr] + keywords = ... # type: typing.List[keyword] + starargs = ... # type: Optional[expr] + kwargs = ... # type: Optional[expr] + +class Repr(expr): + value = ... # type: expr + +class Num(expr): + n = ... # type: Union[int, float] + +class Str(expr): + s = ... # type: str + +class Attribute(expr): + value = ... # type: expr + attr = ... # type: _identifier + ctx = ... # type: expr_context + +class Subscript(expr): + value = ... # type: expr + slice = ... # type: _slice + ctx = ... # type: expr_context + +class Name(expr): + id = ... # type: _identifier + ctx = ... # type: expr_context + +class List(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + +class Tuple(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + + +class expr_context(AST): + ... + +class AugLoad(expr_context): ... +class AugStore(expr_context): ... +class Del(expr_context): ... +class Load(expr_context): ... +class Param(expr_context): ... +class Store(expr_context): ... + + +class boolop(AST): + ... + +class And(boolop): ... +class Or(boolop): ... + +class operator(AST): + ... + +class Add(operator): ... +class BitAnd(operator): ... +class BitOr(operator): ... +class BitXor(operator): ... +class Div(operator): ... +class FloorDiv(operator): ... +class LShift(operator): ... +class Mod(operator): ... +class Mult(operator): ... +class Pow(operator): ... +class RShift(operator): ... +class Sub(operator): ... + +class unaryop(AST): + ... + +class Invert(unaryop): ... +class Not(unaryop): ... +class UAdd(unaryop): ... +class USub(unaryop): ... + +class cmpop(AST): + ... + +class Eq(cmpop): ... +class Gt(cmpop): ... +class GtE(cmpop): ... +class In(cmpop): ... +class Is(cmpop): ... +class IsNot(cmpop): ... +class Lt(cmpop): ... +class LtE(cmpop): ... +class NotEq(cmpop): ... +class NotIn(cmpop): ... + + +class comprehension(AST): + target = ... # type: expr + iter = ... # type: expr + ifs = ... # type: typing.List[expr] + + +class ExceptHandler(AST): + type = ... # type: Optional[expr] + name = ... # type: Optional[expr] + body = ... # type: typing.List[stmt] + lineno = ... # type: int + col_offset = ... # type: int + + +class arguments(AST): + args = ... # type: typing.List[expr] + vararg = ... # type: Optional[_identifier] + kwarg = ... # type: Optional[_identifier] + defaults = ... # type: typing.List[expr] + +class keyword(AST): + arg = ... # type: _identifier + value = ... # type: expr + +class alias(AST): + name = ... # type: _identifier + asname = ... # type: Optional[_identifier] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_collections.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_collections.pyi new file mode 100644 index 000000000..156cda06a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_collections.pyi @@ -0,0 +1,41 @@ +"""Stub file for the '_collections' module.""" + +from typing import Any, Generic, Iterator, TypeVar, Optional, Union + +class defaultdict(dict): + default_factory = ... # type: None + def __init__(self, default: Any = ..., init: Any = ...) -> None: ... + def __missing__(self, key) -> Any: + raise KeyError() + def __copy__(self) -> "defaultdict": ... + def copy(self) -> "defaultdict": ... + +_T = TypeVar('_T') +_T2 = TypeVar('_T2') + +class deque(Generic[_T]): + maxlen = ... # type: Optional[int] + def __init__(self, iterable: Iterator[_T] = ..., maxlen: int = ...) -> None: ... + def append(self, x: _T) -> None: ... + def appendleft(self, x: _T) -> None: ... + def clear(self) -> None: ... + def count(self, x: Any) -> int: ... + def extend(self, iterable: Iterator[_T]) -> None: ... + def extendleft(self, iterable: Iterator[_T]) -> None: ... + def pop(self) -> _T: + raise IndexError() + def popleft(self) -> _T: + raise IndexError() + def remove(self, value: _T) -> None: + raise IndexError() + def reverse(self) -> None: ... + def rotate(self, n: int = ...) -> None: ... + def __contains__(self, o: Any) -> bool: ... + def __copy__(self) -> "deque[_T]": ... + def __getitem__(self, i: int) -> _T: + raise IndexError() + def __iadd__(self, other: "deque[_T2]") -> "deque[Union[_T, _T2]]": ... + def __iter__(self) -> Iterator[_T]: ... + def __len__(self) -> int: ... + def __reversed__(self) -> Iterator[_T]: ... + def __setitem__(self, i: int, x: _T) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_functools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_functools.pyi new file mode 100644 index 000000000..555d3e1ae --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_functools.pyi @@ -0,0 +1,20 @@ +"""Stub file for the '_functools' module.""" + +from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Tuple, overload + +_T = TypeVar("_T") +_S = TypeVar("_S") + +@overload +def reduce(function: Callable[[_T, _T], _T], + sequence: Iterable[_T]) -> _T: ... +@overload +def reduce(function: Callable[[_T, _S], _T], + sequence: Iterable[_S], initial: _T) -> _T: ... + +class partial(object): + func = ... # type: Callable[..., Any] + args = ... # type: Tuple[Any, ...] + keywords = ... # type: Dict[str, Any] + def __init__(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_hotshot.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_hotshot.pyi new file mode 100644 index 000000000..8a9c8d72b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_hotshot.pyi @@ -0,0 +1,34 @@ +"""Stub file for the '_hotshot' module.""" +# This is an autogenerated file. It serves as a starting point +# for a more precise manual annotation of this module. +# Feel free to edit the source below, but remove this header when you do. + +from typing import Any, List, Tuple, Dict, Generic + +def coverage(a: str) -> Any: ... + +def logreader(a: str) -> LogReaderType: + raise IOError() + raise RuntimeError() + +def profiler(a: str, *args, **kwargs) -> Any: + raise IOError() + +def resolution() -> tuple: ... + + +class LogReaderType(object): + def close(self) -> None: ... + def fileno(self) -> int: + raise ValueError() + +class ProfilerType(object): + def addinfo(self, a: str, b: str) -> None: ... + def close(self) -> None: ... + def fileno(self) -> int: + raise ValueError() + def runcall(self, *args, **kwargs) -> Any: ... + def runcode(self, a, b, *args, **kwargs) -> Any: + raise TypeError() + def start(self) -> None: ... + def stop(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_io.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_io.pyi new file mode 100644 index 000000000..55c7e8fa2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_io.pyi @@ -0,0 +1,183 @@ +from typing import Any, AnyStr, BinaryIO, IO, Text, TextIO, Iterable, Iterator, List, Optional, Type, Tuple, TypeVar, Union +from mmap import mmap +from types import TracebackType + +_bytearray_like = Union[bytearray, mmap] + +DEFAULT_BUFFER_SIZE = ... # type: int + +class BlockingIOError(IOError): + characters_written = ... # type: int + +class UnsupportedOperation(ValueError, IOError): ... + +_T = TypeVar("_T") + +class _IOBase(BinaryIO): + @property + def closed(self) -> bool: ... + def _checkClosed(self) -> None: ... + def _checkReadable(self) -> None: ... + def _checkSeekable(self) -> None: ... + def _checkWritable(self) -> None: ... + # All these methods are concrete here (you can instantiate this) + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def readable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def __enter__(self: _T) -> _T: ... + def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> bool: ... + def __iter__(self: _T) -> _T: ... + # The parameter type of writelines[s]() is determined by that of write(): + def writelines(self, lines: Iterable[bytes]) -> None: ... + # The return type of readline[s]() and next() is determined by that of read(): + def readline(self, limit: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def next(self) -> bytes: ... + # These don't actually exist but we need to pretend that it does + # so that this class is concrete. + def write(self, s: bytes) -> int: ... + def read(self, n: int = ...) -> bytes: ... + +class _BufferedIOBase(_IOBase): + def read1(self, n: int) -> bytes: ... + def read(self, size: int = ...) -> bytes: ... + def readinto(self, buffer: _bytearray_like) -> int: ... + def write(self, s: bytes) -> int: ... + def detach(self) -> _IOBase: ... + +class BufferedRWPair(_BufferedIOBase): + def __init__(self, reader: _RawIOBase, writer: _RawIOBase, + buffer_size: int = ..., max_buffer_size: int = ...) -> None: ... + def peek(self, n: int = ...) -> bytes: ... + def __enter__(self) -> BufferedRWPair: ... + +class BufferedRandom(_BufferedIOBase): + mode = ... # type: str + name = ... # type: str + raw = ... # type: _IOBase + def __init__(self, raw: _IOBase, + buffer_size: int = ..., + max_buffer_size: int = ...) -> None: ... + def peek(self, n: int = ...) -> bytes: ... + +class BufferedReader(_BufferedIOBase): + mode = ... # type: str + name = ... # type: str + raw = ... # type: _IOBase + def __init__(self, raw: _IOBase, buffer_size: int = ...) -> None: ... + def peek(self, n: int = ...) -> bytes: ... + +class BufferedWriter(_BufferedIOBase): + name = ... # type: str + raw = ... # type: _IOBase + mode = ... # type: str + def __init__(self, raw: _IOBase, + buffer_size: int = ..., + max_buffer_size: int = ...) -> None: ... + +class BytesIO(_BufferedIOBase): + def __init__(self, initial_bytes: bytes = ...) -> None: ... + def __setstate__(self, tuple) -> None: ... + def __getstate__(self) -> tuple: ... + # BytesIO does not contain a "name" field. This workaround is necessary + # to allow BytesIO sub-classes to add this field, as it is defined + # as a read-only property on IO[]. + name: Any + def getvalue(self) -> bytes: ... + def write(self, s: bytes) -> int: ... + def writelines(self, lines: Iterable[bytes]) -> None: ... + def read1(self, size: int) -> bytes: ... + def next(self) -> bytes: ... + +class _RawIOBase(_IOBase): + def readall(self) -> str: ... + def read(self, n: int = ...) -> str: ... + +class FileIO(_RawIOBase, BytesIO): # type: ignore # for __enter__ + mode = ... # type: str + closefd = ... # type: bool + def __init__(self, file: Union[str, int], mode: str = ..., closefd: bool = ...) -> None: ... + def readinto(self, buffer: _bytearray_like)-> int: ... + def write(self, pbuf: str) -> int: ... + +class IncrementalNewlineDecoder(object): + newlines = ... # type: Union[str, unicode] + def __init__(self, decoder, translate, z=...) -> None: ... + def decode(self, input, final) -> Any: ... + def getstate(self) -> Tuple[Any, int]: ... + def setstate(self, state: Tuple[Any, int]) -> None: ... + def reset(self) -> None: ... + + +# Note: In the actual _io.py, _TextIOBase inherits from _IOBase. +class _TextIOBase(TextIO): + errors = ... # type: Optional[str] + # TODO: On _TextIOBase, this is always None. But it's unicode/bytes in subclasses. + newlines = ... # type: Union[None, unicode, bytes] + encoding = ... # type: str + @property + def closed(self) -> bool: ... + def _checkClosed(self) -> None: ... + def _checkReadable(self) -> None: ... + def _checkSeekable(self) -> None: ... + def _checkWritable(self) -> None: ... + def close(self) -> None: ... + def detach(self) -> IO: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def next(self) -> unicode: ... + def read(self, size: int = ...) -> unicode: ... + def readable(self) -> bool: ... + def readline(self, limit: int = ...) -> unicode: ... + def readlines(self, hint: int = ...) -> list[unicode]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def write(self, pbuf: unicode) -> int: ... + def writelines(self, lines: Iterable[unicode]) -> None: ... + def __enter__(self: _T) -> _T: ... + def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> bool: ... + def __iter__(self: _T) -> _T: ... + +class StringIO(_TextIOBase): + line_buffering = ... # type: bool + def __init__(self, + initial_value: Optional[unicode] = ..., + newline: Optional[unicode] = ...) -> None: ... + def __setstate__(self, state: tuple) -> None: ... + def __getstate__(self) -> tuple: ... + # StringIO does not contain a "name" field. This workaround is necessary + # to allow StringIO sub-classes to add this field, as it is defined + # as a read-only property on IO[]. + name: Any + def getvalue(self) -> unicode: ... + +class TextIOWrapper(_TextIOBase): + name = ... # type: str + line_buffering = ... # type: bool + buffer = ... # type: BinaryIO + _CHUNK_SIZE = ... # type: int + def __init__(self, buffer: IO, + encoding: Optional[Text] = ..., + errors: Optional[Text] = ..., + newline: Optional[Text] = ..., + line_buffering: bool = ..., + write_through: bool = ...) -> None: ... + +def open(file: Union[str, unicode, int], + mode: unicode = ..., + buffering: int = ..., + encoding: Optional[Text] = ..., + errors: Optional[Text] = ..., + newline: Optional[Text] = ..., + closefd: bool = ...) -> IO[Any]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_json.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_json.pyi new file mode 100644 index 000000000..028b7b229 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_json.pyi @@ -0,0 +1,17 @@ +"""Stub file for the '_json' module.""" +# This is an autogenerated file. It serves as a starting point +# for a more precise manual annotation of this module. +# Feel free to edit the source below, but remove this header when you do. + +from typing import Any, List, Tuple, Dict, Generic + +def encode_basestring_ascii(*args, **kwargs) -> str: + raise TypeError() + +def scanstring(a, b, *args, **kwargs) -> tuple: + raise TypeError() + + +class Encoder(object): ... + +class Scanner(object): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_md5.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_md5.pyi new file mode 100644 index 000000000..862b68f75 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_md5.pyi @@ -0,0 +1,13 @@ +blocksize = ... # type: int +digest_size = ... # type: int + +class MD5Type(object): + name = ... # type: str + block_size = ... # type: int + digest_size = ... # type: int + def copy(self) -> "MD5Type": ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def update(self, arg: str) -> None: ... + +def new(arg: str = ...) -> MD5Type: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha.pyi new file mode 100644 index 000000000..eb750e0d7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha.pyi @@ -0,0 +1,15 @@ +blocksize = ... # type: int +block_size = ... # type: int +digest_size = ... # type: int + +class sha(object): # not actually exposed + name = ... # type: str + block_size = ... # type: int + digest_size = ... # type: int + digestsize = ... # type: int + def copy(self) -> "sha": ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def update(self, arg: str) -> None: ... + +def new(arg: str = ...) -> sha: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha256.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha256.pyi new file mode 100644 index 000000000..4cf40c1f3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha256.pyi @@ -0,0 +1,23 @@ +from typing import Optional + +class sha224(object): + name = ... # type: str + block_size = ... # type: int + digest_size = ... # type: int + digestsize = ... # type: int + def __init__(self, init: Optional[str]) -> None: ... + def copy(self) -> "sha224": ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def update(self, arg: str) -> None: ... + +class sha256(object): + name = ... # type: str + block_size = ... # type: int + digest_size = ... # type: int + digestsize = ... # type: int + def __init__(self, init: Optional[str]) -> None: ... + def copy(self) -> "sha256": ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def update(self, arg: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha512.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha512.pyi new file mode 100644 index 000000000..f9e4928af --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sha512.pyi @@ -0,0 +1,23 @@ +from typing import Optional + +class sha384(object): + name = ... # type: str + block_size = ... # type: int + digest_size = ... # type: int + digestsize = ... # type: int + def __init__(self, init: Optional[str]) -> None: ... + def copy(self) -> "sha384": ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def update(self, arg: str) -> None: ... + +class sha512(object): + name = ... # type: str + block_size = ... # type: int + digest_size = ... # type: int + digestsize = ... # type: int + def __init__(self, init: Optional[str]) -> None: ... + def copy(self) -> "sha512": ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def update(self, arg: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_socket.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_socket.pyi new file mode 100644 index 000000000..cfd615e5d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_socket.pyi @@ -0,0 +1,287 @@ +from typing import Tuple, Union, IO, Any, Optional, overload + +AF_APPLETALK = ... # type: int +AF_ASH = ... # type: int +AF_ATMPVC = ... # type: int +AF_ATMSVC = ... # type: int +AF_AX25 = ... # type: int +AF_BLUETOOTH = ... # type: int +AF_BRIDGE = ... # type: int +AF_DECnet = ... # type: int +AF_ECONET = ... # type: int +AF_INET = ... # type: int +AF_INET6 = ... # type: int +AF_IPX = ... # type: int +AF_IRDA = ... # type: int +AF_KEY = ... # type: int +AF_LLC = ... # type: int +AF_NETBEUI = ... # type: int +AF_NETLINK = ... # type: int +AF_NETROM = ... # type: int +AF_PACKET = ... # type: int +AF_PPPOX = ... # type: int +AF_ROSE = ... # type: int +AF_ROUTE = ... # type: int +AF_SECURITY = ... # type: int +AF_SNA = ... # type: int +AF_TIPC = ... # type: int +AF_UNIX = ... # type: int +AF_UNSPEC = ... # type: int +AF_WANPIPE = ... # type: int +AF_X25 = ... # type: int +AI_ADDRCONFIG = ... # type: int +AI_ALL = ... # type: int +AI_CANONNAME = ... # type: int +AI_NUMERICHOST = ... # type: int +AI_NUMERICSERV = ... # type: int +AI_PASSIVE = ... # type: int +AI_V4MAPPED = ... # type: int +BDADDR_ANY = ... # type: str +BDADDR_LOCAL = ... # type: str +BTPROTO_HCI = ... # type: int +BTPROTO_L2CAP = ... # type: int +BTPROTO_RFCOMM = ... # type: int +BTPROTO_SCO = ... # type: int +EAI_ADDRFAMILY = ... # type: int +EAI_AGAIN = ... # type: int +EAI_BADFLAGS = ... # type: int +EAI_FAIL = ... # type: int +EAI_FAMILY = ... # type: int +EAI_MEMORY = ... # type: int +EAI_NODATA = ... # type: int +EAI_NONAME = ... # type: int +EAI_OVERFLOW = ... # type: int +EAI_SERVICE = ... # type: int +EAI_SOCKTYPE = ... # type: int +EAI_SYSTEM = ... # type: int +EBADF = ... # type: int +EINTR = ... # type: int +HCI_DATA_DIR = ... # type: int +HCI_FILTER = ... # type: int +HCI_TIME_STAMP = ... # type: int +INADDR_ALLHOSTS_GROUP = ... # type: int +INADDR_ANY = ... # type: int +INADDR_BROADCAST = ... # type: int +INADDR_LOOPBACK = ... # type: int +INADDR_MAX_LOCAL_GROUP = ... # type: int +INADDR_NONE = ... # type: int +INADDR_UNSPEC_GROUP = ... # type: int +IPPORT_RESERVED = ... # type: int +IPPORT_USERRESERVED = ... # type: int +IPPROTO_AH = ... # type: int +IPPROTO_DSTOPTS = ... # type: int +IPPROTO_EGP = ... # type: int +IPPROTO_ESP = ... # type: int +IPPROTO_FRAGMENT = ... # type: int +IPPROTO_GRE = ... # type: int +IPPROTO_HOPOPTS = ... # type: int +IPPROTO_ICMP = ... # type: int +IPPROTO_ICMPV6 = ... # type: int +IPPROTO_IDP = ... # type: int +IPPROTO_IGMP = ... # type: int +IPPROTO_IP = ... # type: int +IPPROTO_IPIP = ... # type: int +IPPROTO_IPV6 = ... # type: int +IPPROTO_NONE = ... # type: int +IPPROTO_PIM = ... # type: int +IPPROTO_PUP = ... # type: int +IPPROTO_RAW = ... # type: int +IPPROTO_ROUTING = ... # type: int +IPPROTO_RSVP = ... # type: int +IPPROTO_TCP = ... # type: int +IPPROTO_TP = ... # type: int +IPPROTO_UDP = ... # type: int +IPV6_CHECKSUM = ... # type: int +IPV6_DSTOPTS = ... # type: int +IPV6_HOPLIMIT = ... # type: int +IPV6_HOPOPTS = ... # type: int +IPV6_JOIN_GROUP = ... # type: int +IPV6_LEAVE_GROUP = ... # type: int +IPV6_MULTICAST_HOPS = ... # type: int +IPV6_MULTICAST_IF = ... # type: int +IPV6_MULTICAST_LOOP = ... # type: int +IPV6_NEXTHOP = ... # type: int +IPV6_PKTINFO = ... # type: int +IPV6_RECVDSTOPTS = ... # type: int +IPV6_RECVHOPLIMIT = ... # type: int +IPV6_RECVHOPOPTS = ... # type: int +IPV6_RECVPKTINFO = ... # type: int +IPV6_RECVRTHDR = ... # type: int +IPV6_RECVTCLASS = ... # type: int +IPV6_RTHDR = ... # type: int +IPV6_RTHDRDSTOPTS = ... # type: int +IPV6_RTHDR_TYPE_0 = ... # type: int +IPV6_TCLASS = ... # type: int +IPV6_UNICAST_HOPS = ... # type: int +IPV6_V6ONLY = ... # type: int +IP_ADD_MEMBERSHIP = ... # type: int +IP_DEFAULT_MULTICAST_LOOP = ... # type: int +IP_DEFAULT_MULTICAST_TTL = ... # type: int +IP_DROP_MEMBERSHIP = ... # type: int +IP_HDRINCL = ... # type: int +IP_MAX_MEMBERSHIPS = ... # type: int +IP_MULTICAST_IF = ... # type: int +IP_MULTICAST_LOOP = ... # type: int +IP_MULTICAST_TTL = ... # type: int +IP_OPTIONS = ... # type: int +IP_RECVOPTS = ... # type: int +IP_RECVRETOPTS = ... # type: int +IP_RETOPTS = ... # type: int +IP_TOS = ... # type: int +IP_TTL = ... # type: int +MSG_CTRUNC = ... # type: int +MSG_DONTROUTE = ... # type: int +MSG_DONTWAIT = ... # type: int +MSG_EOR = ... # type: int +MSG_OOB = ... # type: int +MSG_PEEK = ... # type: int +MSG_TRUNC = ... # type: int +MSG_WAITALL = ... # type: int +MethodType = ... # type: type +NETLINK_DNRTMSG = ... # type: int +NETLINK_FIREWALL = ... # type: int +NETLINK_IP6_FW = ... # type: int +NETLINK_NFLOG = ... # type: int +NETLINK_ROUTE = ... # type: int +NETLINK_USERSOCK = ... # type: int +NETLINK_XFRM = ... # type: int +NI_DGRAM = ... # type: int +NI_MAXHOST = ... # type: int +NI_MAXSERV = ... # type: int +NI_NAMEREQD = ... # type: int +NI_NOFQDN = ... # type: int +NI_NUMERICHOST = ... # type: int +NI_NUMERICSERV = ... # type: int +PACKET_BROADCAST = ... # type: int +PACKET_FASTROUTE = ... # type: int +PACKET_HOST = ... # type: int +PACKET_LOOPBACK = ... # type: int +PACKET_MULTICAST = ... # type: int +PACKET_OTHERHOST = ... # type: int +PACKET_OUTGOING = ... # type: int +PF_PACKET = ... # type: int +SHUT_RD = ... # type: int +SHUT_RDWR = ... # type: int +SHUT_WR = ... # type: int +SOCK_DGRAM = ... # type: int +SOCK_RAW = ... # type: int +SOCK_RDM = ... # type: int +SOCK_SEQPACKET = ... # type: int +SOCK_STREAM = ... # type: int +SOL_HCI = ... # type: int +SOL_IP = ... # type: int +SOL_SOCKET = ... # type: int +SOL_TCP = ... # type: int +SOL_TIPC = ... # type: int +SOL_UDP = ... # type: int +SOMAXCONN = ... # type: int +SO_ACCEPTCONN = ... # type: int +SO_BROADCAST = ... # type: int +SO_DEBUG = ... # type: int +SO_DONTROUTE = ... # type: int +SO_ERROR = ... # type: int +SO_KEEPALIVE = ... # type: int +SO_LINGER = ... # type: int +SO_OOBINLINE = ... # type: int +SO_RCVBUF = ... # type: int +SO_RCVLOWAT = ... # type: int +SO_RCVTIMEO = ... # type: int +SO_REUSEADDR = ... # type: int +SO_REUSEPORT = ... # type: int +SO_SNDBUF = ... # type: int +SO_SNDLOWAT = ... # type: int +SO_SNDTIMEO = ... # type: int +SO_TYPE = ... # type: int +SSL_ERROR_EOF = ... # type: int +SSL_ERROR_INVALID_ERROR_CODE = ... # type: int +SSL_ERROR_SSL = ... # type: int +SSL_ERROR_SYSCALL = ... # type: int +SSL_ERROR_WANT_CONNECT = ... # type: int +SSL_ERROR_WANT_READ = ... # type: int +SSL_ERROR_WANT_WRITE = ... # type: int +SSL_ERROR_WANT_X509_LOOKUP = ... # type: int +SSL_ERROR_ZERO_RETURN = ... # type: int +TCP_CORK = ... # type: int +TCP_DEFER_ACCEPT = ... # type: int +TCP_INFO = ... # type: int +TCP_KEEPCNT = ... # type: int +TCP_KEEPIDLE = ... # type: int +TCP_KEEPINTVL = ... # type: int +TCP_LINGER2 = ... # type: int +TCP_MAXSEG = ... # type: int +TCP_NODELAY = ... # type: int +TCP_QUICKACK = ... # type: int +TCP_SYNCNT = ... # type: int +TCP_WINDOW_CLAMP = ... # type: int +TIPC_ADDR_ID = ... # type: int +TIPC_ADDR_NAME = ... # type: int +TIPC_ADDR_NAMESEQ = ... # type: int +TIPC_CFG_SRV = ... # type: int +TIPC_CLUSTER_SCOPE = ... # type: int +TIPC_CONN_TIMEOUT = ... # type: int +TIPC_CRITICAL_IMPORTANCE = ... # type: int +TIPC_DEST_DROPPABLE = ... # type: int +TIPC_HIGH_IMPORTANCE = ... # type: int +TIPC_IMPORTANCE = ... # type: int +TIPC_LOW_IMPORTANCE = ... # type: int +TIPC_MEDIUM_IMPORTANCE = ... # type: int +TIPC_NODE_SCOPE = ... # type: int +TIPC_PUBLISHED = ... # type: int +TIPC_SRC_DROPPABLE = ... # type: int +TIPC_SUBSCR_TIMEOUT = ... # type: int +TIPC_SUB_CANCEL = ... # type: int +TIPC_SUB_PORTS = ... # type: int +TIPC_SUB_SERVICE = ... # type: int +TIPC_TOP_SRV = ... # type: int +TIPC_WAIT_FOREVER = ... # type: int +TIPC_WITHDRAWN = ... # type: int +TIPC_ZONE_SCOPE = ... # type: int + +# PyCapsule +CAPI = ... # type: Any + +has_ipv6 = ... # type: bool + +class error(IOError): ... +class gaierror(error): ... +class timeout(error): ... + +class SocketType(object): + family = ... # type: int + type = ... # type: int + proto = ... # type: int + timeout = ... # type: float + + def __init__(self, family: int = ..., type: int = ..., proto: int = ...) -> None: ... + def accept(self) -> Tuple['SocketType', tuple]: ... + def bind(self, address: tuple) -> None: ... + def close(self) -> None: ... + def connect(self, address: tuple) -> None: + raise gaierror + raise timeout + def connect_ex(self, address: tuple) -> int: ... + def dup(self) -> "SocketType": ... + def fileno(self) -> int: ... + def getpeername(self) -> tuple: ... + def getsockname(self) -> tuple: ... + def getsockopt(self, level: int, option: int, buffersize: int = ...) -> str: ... + def gettimeout(self) -> float: ... + def listen(self, backlog: int) -> None: + raise error + def makefile(self, mode: str = ..., buffersize: int = ...) -> IO[Any]: ... + def recv(self, buffersize: int, flags: int = ...) -> str: ... + def recv_into(self, buffer: bytearray, nbytes: int = ..., flags: int = ...) -> int: ... + def recvfrom(self, buffersize: int, flags: int = ...) -> tuple: + raise error + def recvfrom_into(self, buffer: bytearray, nbytes: int = ..., + flags: int = ...) -> int: ... + def send(self, data: str, flags: int =...) -> int: ... + def sendall(self, data: str, flags: int = ...) -> None: ... + @overload + def sendto(self, data: str, address: tuple) -> int: ... + @overload + def sendto(self, data: str, flags: int, address: tuple) -> int: ... + def setblocking(self, flag: bool) -> None: ... + def setsockopt(self, level: int, option: int, value: Union[int, str]) -> None: ... + def settimeout(self, value: Optional[float]) -> None: ... + def shutdown(self, flag: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sre.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sre.pyi new file mode 100644 index 000000000..1b6b5bc23 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_sre.pyi @@ -0,0 +1,53 @@ +"""Stub file for the '_sre' module.""" + +from typing import Any, Union, Iterable, Optional, Mapping, Sequence, Dict, List, Tuple, overload + +CODESIZE = ... # type: int +MAGIC = ... # type: int +MAXREPEAT = ... # type: long +copyright = ... # type: str + +class SRE_Match(object): + def start(self, group: int = ...) -> int: + raise IndexError() + def end(self, group: int = ...) -> int: + raise IndexError() + def expand(self, s: str) -> Any: ... + @overload + def group(self) -> str: ... + @overload + def group(self, group: int = ...) -> Optional[str]: ... + def groupdict(self) -> Dict[int, Optional[str]]: ... + def groups(self) -> Tuple[Optional[str], ...]: ... + def span(self) -> Tuple[int, int]: + raise IndexError() + +class SRE_Scanner(object): + pattern = ... # type: str + def match(self) -> SRE_Match: ... + def search(self) -> SRE_Match: ... + +class SRE_Pattern(object): + pattern = ... # type: str + flags = ... # type: int + groups = ... # type: int + groupindex = ... # type: Mapping[str, int] + indexgroup = ... # type: Sequence[int] + def findall(self, source: str, pos: int = ..., endpos: int = ...) -> List[Union[tuple, str]]: ... + def finditer(self, source: str, pos: int = ..., endpos: int = ...) -> Iterable[Union[tuple, str]]: ... + def match(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ... + def scanner(self, s: str, start: int = ..., end: int = ...) -> SRE_Scanner: ... + def search(self, pattern, pos: int = ..., endpos: int = ...) -> SRE_Match: ... + def split(self, source: str, maxsplit: int = ...) -> List[Optional[str]]: ... + def sub(self, repl: str, string: str, count: int = ...) -> tuple: ... + def subn(self, repl: str, string: str, count: int = ...) -> tuple: ... + +def compile(pattern: str, flags: int, code: List[int], + groups: int = ..., + groupindex: Mapping[str, int] = ..., + indexgroup: Sequence[int] = ...) -> SRE_Pattern: + raise OverflowError() + +def getcodesize() -> int: ... + +def getlower(a: int, b: int) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_struct.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_struct.pyi new file mode 100644 index 000000000..add6f842d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_struct.pyi @@ -0,0 +1,22 @@ +"""Stub file for the '_struct' module.""" + +from typing import Any, AnyStr, Tuple + +class error(Exception): ... + +class Struct(object): + size = ... # type: int + format = ... # type: str + + def __init__(self, fmt: str) -> None: ... + def pack_into(self, buffer: bytearray, offset: int, obj: Any) -> None: ... + def pack(self, *args) -> str: ... + def unpack(self, s: str) -> Tuple[Any, ...]: ... + def unpack_from(self, buffer: bytearray, offset: int = ...) -> Tuple[Any, ...]: ... + +def _clearcache() -> None: ... +def calcsize(fmt: str) -> int: ... +def pack(fmt: AnyStr, obj: Any) -> str: ... +def pack_into(fmt: AnyStr, buffer: bytearray, offset: int, obj: Any) -> None: ... +def unpack(fmt: AnyStr, data: str) -> Tuple[Any, ...]: ... +def unpack_from(fmt: AnyStr, buffer: bytearray, offset: int = ...) -> Tuple[Any, ...]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_symtable.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_symtable.pyi new file mode 100644 index 000000000..fd8b691f1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_symtable.pyi @@ -0,0 +1,39 @@ +from typing import List, Dict + +CELL = ... # type: int +DEF_BOUND = ... # type: int +DEF_FREE = ... # type: int +DEF_FREE_CLASS = ... # type: int +DEF_GLOBAL = ... # type: int +DEF_IMPORT = ... # type: int +DEF_LOCAL = ... # type: int +DEF_PARAM = ... # type: int +FREE = ... # type: int +GLOBAL_EXPLICIT = ... # type: int +GLOBAL_IMPLICIT = ... # type: int +LOCAL = ... # type: int +OPT_BARE_EXEC = ... # type: int +OPT_EXEC = ... # type: int +OPT_IMPORT_STAR = ... # type: int +SCOPE_MASK = ... # type: int +SCOPE_OFF = ... # type: int +TYPE_CLASS = ... # type: int +TYPE_FUNCTION = ... # type: int +TYPE_MODULE = ... # type: int +USE = ... # type: int + +class _symtable_entry(object): + ... + +class symtable(object): + children = ... # type: List[_symtable_entry] + id = ... # type: int + lineno = ... # type: int + name = ... # type: str + nested = ... # type: int + optimized = ... # type: int + symbols = ... # type: Dict[str, int] + type = ... # type: int + varnames = ... # type: List[str] + + def __init__(self, src: str, filename: str, startstr: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_threading_local.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_threading_local.pyi new file mode 100644 index 000000000..512bf5874 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_threading_local.pyi @@ -0,0 +1,14 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/_threading_local.py +from typing import Any, List + +__all__: List[str] + +class _localbase(object): ... + +class local(_localbase): + def __getattribute__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __delattr__(self, name: str) -> None: ... + def __del__(self) -> None: ... + +def _patch(self: local) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_warnings.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_warnings.pyi new file mode 100644 index 000000000..63fd9d486 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/_warnings.pyi @@ -0,0 +1,11 @@ +from typing import Any, List, Optional, Type + +default_action = ... # type: str +filters = ... # type: List[tuple] +once_registry = ... # type: dict + +def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... +def warn_explicit(message: Warning, category: Optional[Type[Warning]], + filename: str, lineno: int, + module: Any = ..., registry: dict = ..., + module_globals: dict = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/abc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/abc.pyi new file mode 100644 index 000000000..e21065e5c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/abc.pyi @@ -0,0 +1,29 @@ +from typing import Any, Dict, Set, Tuple, Type +import _weakrefset + +# NOTE: mypy has special processing for ABCMeta and abstractmethod. + +def abstractmethod(funcobj: Any) -> Any: ... + +class ABCMeta(type): + # TODO: FrozenSet + __abstractmethods__ = ... # type: Set[Any] + _abc_cache = ... # type: _weakrefset.WeakSet + _abc_invalidation_counter = ... # type: int + _abc_negative_cache = ... # type: _weakrefset.WeakSet + _abc_negative_cache_version = ... # type: int + _abc_registry = ... # type: _weakrefset.WeakSet + def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[Any, Any]) -> None: ... + def __instancecheck__(cls: "ABCMeta", instance: Any) -> Any: ... + def __subclasscheck__(cls: "ABCMeta", subclass: Any) -> Any: ... + def _dump_registry(cls: "ABCMeta", *args: Any, **kwargs: Any) -> None: ... + def register(cls: "ABCMeta", subclass: Type[Any]) -> None: ... + +# TODO: The real abc.abstractproperty inherits from "property". +class abstractproperty(object): + def __new__(cls, func: Any) -> Any: ... + __isabstractmethod__ = ... # type: bool + doc = ... # type: Any + fdel = ... # type: Any + fget = ... # type: Any + fset = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ast.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ast.pyi new file mode 100644 index 000000000..e4ba3b6f1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ast.pyi @@ -0,0 +1,29 @@ +# Python 2.7 ast + +import typing +from typing import Any, Iterator, Union + +from _ast import * +from _ast import AST, Module + +__version__ = ... # type: str +PyCF_ONLY_AST = ... # type: int + + +def parse(source: Union[str, unicode], filename: Union[str, unicode] = ..., mode: Union[str, unicode] = ...) -> Module: ... +def copy_location(new_node: AST, old_node: AST) -> AST: ... +def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ... +def fix_missing_locations(node: AST) -> AST: ... +def get_docstring(node: AST, clean: bool = ...) -> str: ... +def increment_lineno(node: AST, n: int = ...) -> AST: ... +def iter_child_nodes(node: AST) -> Iterator[AST]: ... +def iter_fields(node: AST) -> Iterator[typing.Tuple[str, Any]]: ... +def literal_eval(node_or_string: Union[str, unicode, AST]) -> Any: ... +def walk(node: AST) -> Iterator[AST]: ... + +class NodeVisitor(): + def visit(self, node: AST) -> Any: ... + def generic_visit(self, node: AST) -> None: ... + +class NodeTransformer(NodeVisitor): + def generic_visit(self, node: AST) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/atexit.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/atexit.pyi new file mode 100644 index 000000000..13d2602b0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/atexit.pyi @@ -0,0 +1,5 @@ +from typing import TypeVar, Any + +_FT = TypeVar('_FT') + +def register(func: _FT, *args: Any, **kargs: Any) -> _FT: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/builtins.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/builtins.pyi new file mode 100644 index 000000000..ffb8f14b8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/builtins.pyi @@ -0,0 +1,1086 @@ +# NB: __builtin__.pyi and builtins.pyi must remain consistent! +# Stubs for builtins (Python 2.7) + +# True and False are deliberately omitted because they are keywords in +# Python 3, and stub files conform to Python 3 syntax. + +from typing import ( + TypeVar, Iterator, Iterable, NoReturn, overload, + Sequence, Mapping, Tuple, List, Any, Dict, Callable, Generic, Set, + AbstractSet, FrozenSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsAbs, + SupportsComplex, SupportsRound, IO, BinaryIO, Union, AnyStr, MutableSequence, MutableMapping, + MutableSet, ItemsView, KeysView, ValuesView, Optional, Container, Type +) +from abc import abstractmethod, ABCMeta + +_T = TypeVar('_T') +_T_co = TypeVar('_T_co', covariant=True) +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') +_S = TypeVar('_S') +_T1 = TypeVar('_T1') +_T2 = TypeVar('_T2') +_T3 = TypeVar('_T3') +_T4 = TypeVar('_T4') +_T5 = TypeVar('_T5') +_TT = TypeVar('_TT', bound='type') + +class object: + __doc__ = ... # type: Optional[str] + __class__ = ... # type: type + __dict__ = ... # type: Dict[str, Any] + __slots__ = ... # type: Union[str, unicode, Iterable[Union[str, unicode]]] + __module__ = ... # type: str + + def __init__(self) -> None: ... + def __new__(cls) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __eq__(self, o: object) -> bool: ... + def __ne__(self, o: object) -> bool: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __hash__(self) -> int: ... + def __format__(self, format_spec: str) -> str: ... + def __getattribute__(self, name: str) -> Any: ... + def __delattr__(self, name: str) -> None: ... + def __sizeof__(self) -> int: ... + def __reduce__(self) -> tuple: ... + def __reduce_ex__(self, protocol: int) -> tuple: ... + +class staticmethod(object): # Special, only valid as a decorator. + __func__ = ... # type: function + + def __init__(self, f: function) -> None: ... + def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... + +class classmethod(object): # Special, only valid as a decorator. + __func__ = ... # type: function + + def __init__(self, f: function) -> None: ... + def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... + +class type(object): + __bases__ = ... # type: Tuple[type, ...] + __name__ = ... # type: str + __module__ = ... # type: str + + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... + # TODO: __new__ may have to be special and not a static method. + @overload + def __new__(cls, o: object) -> type: ... + @overload + def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... + def __call__(self, *args: Any, **kwds: Any) -> Any: ... + + # Only new-style classes + __mro__ = ... # type: Tuple[type, ...] + # Note: the documentation doesnt specify what the return type is, the standard + # implementation seems to be returning a list. + def mro(self) -> List[type]: ... + def __subclasses__(self: _TT) -> List[_TT]: ... + def __instancecheck__(self, instance: Any) -> bool: ... + def __subclasscheck__(self, subclass: type) -> bool: ... + +class int: + @overload + def __init__(self, x: SupportsInt = ...) -> None: ... + @overload + def __init__(self, x: Union[str, unicode, bytearray], base: int = ...) -> None: ... + + def bit_length(self) -> int: ... + + def __add__(self, x: int) -> int: ... + def __sub__(self, x: int) -> int: ... + def __mul__(self, x: int) -> int: ... + def __floordiv__(self, x: int) -> int: ... + def __div__(self, x: int) -> int: ... + def __truediv__(self, x: int) -> float: ... + def __mod__(self, x: int) -> int: ... + def __divmod__(self, x: int) -> Tuple[int, int]: ... + def __radd__(self, x: int) -> int: ... + def __rsub__(self, x: int) -> int: ... + def __rmul__(self, x: int) -> int: ... + def __rfloordiv__(self, x: int) -> int: ... + def __rdiv__(self, x: int) -> int: ... + def __rtruediv__(self, x: int) -> float: ... + def __rmod__(self, x: int) -> int: ... + def __rdivmod__(self, x: int) -> Tuple[int, int]: ... + def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __rpow__(self, x: int) -> Any: ... + def __and__(self, n: int) -> int: ... + def __or__(self, n: int) -> int: ... + def __xor__(self, n: int) -> int: ... + def __lshift__(self, n: int) -> int: ... + def __rshift__(self, n: int) -> int: ... + def __rand__(self, n: int) -> int: ... + def __ror__(self, n: int) -> int: ... + def __rxor__(self, n: int) -> int: ... + def __rlshift__(self, n: int) -> int: ... + def __rrshift__(self, n: int) -> int: ... + def __neg__(self) -> int: ... + def __pos__(self) -> int: ... + def __invert__(self) -> int: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: int) -> bool: ... + def __le__(self, x: int) -> bool: ... + def __gt__(self, x: int) -> bool: ... + def __ge__(self, x: int) -> bool: ... + + def __str__(self) -> str: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + def __abs__(self) -> int: ... + def __hash__(self) -> int: ... + def __nonzero__(self) -> bool: ... + +class float: + def __init__(self, x: Union[SupportsFloat, str, unicode, bytearray] = ...) -> None: ... + def as_integer_ratio(self) -> Tuple[int, int]: ... + def hex(self) -> str: ... + def is_integer(self) -> bool: ... + @classmethod + def fromhex(cls, s: str) -> float: ... + + def __add__(self, x: float) -> float: ... + def __sub__(self, x: float) -> float: ... + def __mul__(self, x: float) -> float: ... + def __floordiv__(self, x: float) -> float: ... + def __div__(self, x: float) -> float: ... + def __truediv__(self, x: float) -> float: ... + def __mod__(self, x: float) -> float: ... + def __divmod__(self, x: float) -> Tuple[float, float]: ... + def __pow__(self, x: float) -> float: ... + def __radd__(self, x: float) -> float: ... + def __rsub__(self, x: float) -> float: ... + def __rmul__(self, x: float) -> float: ... + def __rfloordiv__(self, x: float) -> float: ... + def __rdiv__(self, x: float) -> float: ... + def __rtruediv__(self, x: float) -> float: ... + def __rmod__(self, x: float) -> float: ... + def __rdivmod__(self, x: float) -> Tuple[float, float]: ... + def __rpow__(self, x: float) -> float: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: float) -> bool: ... + def __le__(self, x: float) -> bool: ... + def __gt__(self, x: float) -> bool: ... + def __ge__(self, x: float) -> bool: ... + def __neg__(self) -> float: ... + def __pos__(self) -> float: ... + + def __str__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __abs__(self) -> float: ... + def __hash__(self) -> int: ... + def __nonzero__(self) -> bool: ... + +class complex: + @overload + def __init__(self, re: float = ..., im: float = ...) -> None: ... + @overload + def __init__(self, s: str) -> None: ... + @overload + def __init__(self, s: SupportsComplex) -> None: ... + + @property + def real(self) -> float: ... + @property + def imag(self) -> float: ... + + def conjugate(self) -> complex: ... + + def __add__(self, x: complex) -> complex: ... + def __sub__(self, x: complex) -> complex: ... + def __mul__(self, x: complex) -> complex: ... + def __pow__(self, x: complex) -> complex: ... + def __div__(self, x: complex) -> complex: ... + def __truediv__(self, x: complex) -> complex: ... + def __radd__(self, x: complex) -> complex: ... + def __rsub__(self, x: complex) -> complex: ... + def __rmul__(self, x: complex) -> complex: ... + def __rpow__(self, x: complex) -> complex: ... + def __rdiv__(self, x: complex) -> complex: ... + def __rtruediv__(self, x: complex) -> complex: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __neg__(self) -> complex: ... + def __pos__(self) -> complex: ... + + def __complex__(self) -> complex: ... + def __str__(self) -> str: ... + def __abs__(self) -> float: ... + def __hash__(self) -> int: ... + def __nonzero__(self) -> bool: ... + +class super(object): + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + +class basestring(metaclass=ABCMeta): ... + +class unicode(basestring, Sequence[unicode]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, o: str, encoding: unicode = ..., errors: unicode = ...) -> None: ... + def capitalize(self) -> unicode: ... + def center(self, width: int, fillchar: unicode = ...) -> unicode: ... + def count(self, x: unicode) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> unicode: ... + def find(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> unicode: ... + def format_map(self, map: Mapping[unicode, Any]) -> unicode: ... + def index(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[unicode]) -> unicode: ... + def ljust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def lower(self) -> unicode: ... + def lstrip(self, chars: unicode = ...) -> unicode: ... + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: unicode, new: unicode, count: int = ...) -> unicode: ... + def rfind(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: unicode, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: unicode = ...) -> unicode: ... + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def rsplit(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def rstrip(self, chars: unicode = ...) -> unicode: ... + def split(self, sep: Optional[unicode] = ..., maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[unicode]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]], start: int = ..., + end: int = ...) -> bool: ... + def strip(self, chars: unicode = ...) -> unicode: ... + def swapcase(self) -> unicode: ... + def title(self) -> unicode: ... + def translate(self, table: Union[Dict[int, Any], unicode]) -> unicode: ... + def upper(self) -> unicode: ... + def zfill(self, width: int) -> unicode: ... + + @overload + def __getitem__(self, i: int) -> unicode: ... + @overload + def __getitem__(self, s: slice) -> unicode: ... + def __getslice__(self, start: int, stop: int) -> unicode: ... + def __add__(self, s: unicode) -> unicode: ... + def __mul__(self, n: int) -> unicode: ... + def __rmul__(self, n: int) -> unicode: ... + def __mod__(self, x: Any) -> unicode: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + + def __len__(self) -> int: ... + def __contains__(self, s: object) -> bool: ... + def __iter__(self) -> Iterator[unicode]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + +class str(basestring, Sequence[str]): + def __init__(self, object: object = ...) -> None: ... + def capitalize(self) -> str: ... + def center(self, width: int, fillchar: str = ...) -> str: ... + def count(self, x: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> unicode: ... + def encode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> str: ... + def find(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> str: ... + def index(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[AnyStr]) -> AnyStr: ... + def ljust(self, width: int, fillchar: str = ...) -> str: ... + def lower(self) -> str: ... + @overload + def lstrip(self, chars: str = ...) -> str: ... + @overload + def lstrip(self, chars: unicode) -> unicode: ... + @overload + def partition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def partition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def partition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + def replace(self, old: AnyStr, new: AnyStr, count: int = ...) -> AnyStr: ... + def rfind(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rindex(self, sub: unicode, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: str = ...) -> str: ... + @overload + def rpartition(self, sep: bytearray) -> Tuple[str, bytearray, str]: ... + @overload + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + @overload + def rpartition(self, sep: unicode) -> Tuple[unicode, unicode, unicode]: ... + @overload + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def rsplit(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + @overload + def rstrip(self, chars: str = ...) -> str: ... + @overload + def rstrip(self, chars: unicode) -> unicode: ... + @overload + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + @overload + def split(self, sep: unicode, maxsplit: int = ...) -> List[unicode]: ... + def splitlines(self, keepends: bool = ...) -> List[str]: ... + def startswith(self, prefix: Union[unicode, Tuple[unicode, ...]]) -> bool: ... + @overload + def strip(self, chars: str = ...) -> str: ... + @overload + def strip(self, chars: unicode) -> unicode: ... + def swapcase(self) -> str: ... + def title(self) -> str: ... + def translate(self, table: Optional[AnyStr], deletechars: AnyStr = ...) -> AnyStr: ... + def upper(self) -> str: ... + def zfill(self, width: int) -> str: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> str: ... + @overload + def __getitem__(self, s: slice) -> str: ... + def __getslice__(self, start: int, stop: int) -> str: ... + def __add__(self, s: AnyStr) -> AnyStr: ... + def __mul__(self, n: int) -> str: ... + def __rmul__(self, n: int) -> str: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: unicode) -> bool: ... + def __le__(self, x: unicode) -> bool: ... + def __gt__(self, x: unicode) -> bool: ... + def __ge__(self, x: unicode) -> bool: ... + def __mod__(self, x: Any) -> str: ... + +class bytearray(MutableSequence[int]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, x: Union[Iterable[int], str]) -> None: ... + @overload + def __init__(self, x: unicode, encoding: unicode, + errors: unicode = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + def capitalize(self) -> bytearray: ... + def center(self, width: int, fillchar: str = ...) -> bytearray: ... + def count(self, x: str) -> int: ... + def decode(self, encoding: unicode = ..., errors: unicode = ...) -> str: ... + def endswith(self, suffix: Union[str, Tuple[str, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytearray: ... + def find(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def insert(self, index: int, object: int) -> None: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[str]) -> bytearray: ... + def ljust(self, width: int, fillchar: str = ...) -> bytearray: ... + def lower(self) -> bytearray: ... + def lstrip(self, chars: str = ...) -> bytearray: ... + def partition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... + def replace(self, old: str, new: str, count: int = ...) -> bytearray: ... + def rfind(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def rjust(self, width: int, fillchar: str = ...) -> bytearray: ... + def rpartition(self, sep: str) -> Tuple[bytearray, bytearray, bytearray]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def rstrip(self, chars: str = ...) -> bytearray: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... + def startswith(self, prefix: Union[str, Tuple[str, ...]]) -> bool: ... + def strip(self, chars: str = ...) -> bytearray: ... + def swapcase(self) -> bytearray: ... + def title(self) -> bytearray: ... + def translate(self, table: str) -> bytearray: ... + def upper(self) -> bytearray: ... + def zfill(self, width: int) -> bytearray: ... + @staticmethod + def fromhex(x: str) -> bytearray: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytearray: ... + def __getslice__(self, start: int, stop: int) -> bytearray: ... + @overload + def __setitem__(self, i: int, x: int) -> None: ... + @overload + def __setitem__(self, s: slice, x: Union[Iterable[int], str]) -> None: ... + def __setslice__(self, start: int, stop: int, x: Union[Sequence[int], str]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + def __add__(self, s: str) -> bytearray: ... + def __mul__(self, n: int) -> bytearray: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: str) -> bool: ... + def __le__(self, x: str) -> bool: ... + def __gt__(self, x: str) -> bool: ... + def __ge__(self, x: str) -> bool: ... + +class bool(int): + def __init__(self, o: object = ...) -> None: ... + @overload # type: ignore + def __and__(self, x: bool) -> bool: ... + @overload # type: ignore + def __and__(self, x: int) -> int: ... + @overload # type: ignore + def __or__(self, x: bool) -> bool: ... + @overload # type: ignore + def __or__(self, x: int) -> int: ... + @overload # type: ignore + def __xor__(self, x: bool) -> bool: ... + @overload # type: ignore + def __xor__(self, x: int) -> int: ... + @overload # type: ignore + def __rand__(self, x: bool) -> bool: ... + @overload # type: ignore + def __rand__(self, x: int) -> int: ... + @overload # type: ignore + def __ror__(self, x: bool) -> bool: ... + @overload # type: ignore + def __ror__(self, x: int) -> int: ... + @overload # type: ignore + def __rxor__(self, x: bool) -> bool: ... + @overload # type: ignore + def __rxor__(self, x: int) -> int: ... + +class slice(object): + start = ... # type: Optional[int] + step = ... # type: Optional[int] + stop = ... # type: Optional[int] + @overload + def __init__(self, stop: Optional[int]) -> None: ... + @overload + def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> None: ... + def indices(self, len: int) -> Tuple[int, int, int]: ... + +class tuple(Sequence[_T_co], Generic[_T_co]): + def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, x: object) -> bool: ... + @overload + def __getitem__(self, x: int) -> _T_co: ... + @overload + def __getitem__(self, x: slice) -> Tuple[_T_co, ...]: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __lt__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... + def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... + def count(self, x: Any) -> int: ... + def index(self, x: Any) -> int: ... + +class function: + # TODO name of the class (corresponds to Python 'function' class) + __name__ = ... # type: str + __module__ = ... # type: str + +class list(MutableSequence[_T], Generic[_T]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def append(self, object: _T) -> None: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def pop(self, index: int = ...) -> _T: ... + def index(self, object: _T, start: int = ..., stop: int = ...) -> int: ... + def count(self, object: _T) -> int: ... + def insert(self, index: int, object: _T) -> None: ... + def remove(self, object: _T) -> None: ... + def reverse(self) -> None: ... + def sort(self, cmp: Callable[[_T, _T], Any] = ..., key: Callable[[_T], Any] = ..., reverse: bool = ...) -> None: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> _T: ... + @overload + def __getitem__(self, s: slice) -> List[_T]: ... + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + @overload + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... + def __setslice__(self, start: int, stop: int, o: Sequence[_T]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + def __add__(self, x: List[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __mul__(self, n: int) -> List[_T]: ... + def __rmul__(self, n: int) -> List[_T]: ... + def __contains__(self, o: object) -> bool: ... + def __reversed__(self) -> Iterator[_T]: ... + def __gt__(self, x: List[_T]) -> bool: ... + def __ge__(self, x: List[_T]) -> bool: ... + def __lt__(self, x: List[_T]) -> bool: ... + def __le__(self, x: List[_T]) -> bool: ... + +class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): + # NOTE: Keyword arguments are special. If they are used, _KT must include + # str, but we have no way of enforcing it here. + @overload + def __init__(self, **kwargs: _VT) -> None: ... + @overload + def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + + def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... + + def has_key(self, k: _KT) -> bool: ... + def clear(self) -> None: ... + def copy(self) -> Dict[_KT, _VT]: ... + def popitem(self) -> Tuple[_KT, _VT]: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + @overload + def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + @overload + def update(self, **kwargs: _VT) -> None: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def viewkeys(self) -> KeysView[_KT]: ... + def viewvalues(self) -> ValuesView[_VT]: ... + def viewitems(self) -> ItemsView[_KT, _VT]: ... + @staticmethod + @overload + def fromkeys(seq: Sequence[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) + @staticmethod + @overload + def fromkeys(seq: Sequence[_T], value: _S) -> Dict[_T, _S]: ... + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + +class set(MutableSet[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T] = ...) -> None: ... + def add(self, element: _T) -> None: ... + def clear(self) -> None: ... + def copy(self) -> Set[_T]: ... + def difference(self, *s: Iterable[Any]) -> Set[_T]: ... + def difference_update(self, *s: Iterable[Any]) -> None: ... + def discard(self, element: _T) -> None: ... + def intersection(self, *s: Iterable[Any]) -> Set[_T]: ... + def intersection_update(self, *s: Iterable[Any]) -> None: ... + def isdisjoint(self, s: Iterable[object]) -> bool: ... + def issubset(self, s: Iterable[object]) -> bool: ... + def issuperset(self, s: Iterable[object]) -> bool: ... + def pop(self) -> _T: ... + def remove(self, element: _T) -> None: ... + def symmetric_difference(self, s: Iterable[_T]) -> Set[_T]: ... + def symmetric_difference_update(self, s: Iterable[_T]) -> None: ... + def union(self, *s: Iterable[_T]) -> Set[_T]: ... + def update(self, *s: Iterable[_T]) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __and__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __sub__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __isub__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __le__(self, s: AbstractSet[object]) -> bool: ... + def __lt__(self, s: AbstractSet[object]) -> bool: ... + def __ge__(self, s: AbstractSet[object]) -> bool: ... + def __gt__(self, s: AbstractSet[object]) -> bool: ... + +class frozenset(AbstractSet[_T], Generic[_T]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def copy(self) -> FrozenSet[_T]: ... + def difference(self, *s: Iterable[object]) -> FrozenSet[_T]: ... + def intersection(self, *s: Iterable[object]) -> FrozenSet[_T]: ... + def isdisjoint(self, s: Iterable[_T]) -> bool: ... + def issubset(self, s: Iterable[object]) -> bool: ... + def issuperset(self, s: Iterable[object]) -> bool: ... + def symmetric_difference(self, s: Iterable[_T]) -> FrozenSet[_T]: ... + def union(self, *s: Iterable[_T]) -> FrozenSet[_T]: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __and__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... + def __or__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... + def __sub__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... + def __xor__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... + def __le__(self, s: AbstractSet[object]) -> bool: ... + def __lt__(self, s: AbstractSet[object]) -> bool: ... + def __ge__(self, s: AbstractSet[object]) -> bool: ... + def __gt__(self, s: AbstractSet[object]) -> bool: ... + +class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): + def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... + def __iter__(self) -> Iterator[Tuple[int, _T]]: ... + def next(self) -> Tuple[int, _T]: ... + # TODO __getattribute__ + +class xrange(Sized, Iterable[int], Reversible[int]): + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __getitem__(self, i: int) -> int: ... + def __reversed__(self) -> Iterator[int]: ... + +class property(object): + def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., + fset: Optional[Callable[[Any, Any], None]] = ..., + fdel: Optional[Callable[[Any], None]] = ..., doc: Optional[str] = ...) -> None: ... + def getter(self, fget: Callable[[Any], Any]) -> property: ... + def setter(self, fset: Callable[[Any, Any], None]) -> property: ... + def deleter(self, fdel: Callable[[Any], None]) -> property: ... + def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ... + def __set__(self, obj: Any, value: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... + def fget(self) -> Any: ... + def fset(self, value: Any) -> None: ... + def fdel(self) -> None: ... + +long = int +bytes = str + +NotImplemented = ... # type: Any + +def abs(n: SupportsAbs[_T]) -> _T: ... +def all(i: Iterable[object]) -> bool: ... +def any(i: Iterable[object]) -> bool: ... +def bin(number: int) -> str: ... +def callable(o: object) -> bool: ... +def chr(code: int) -> str: ... +def compile(source: Any, filename: unicode, mode: str, flags: int = ..., + dont_inherit: int = ...) -> Any: ... +def delattr(o: Any, name: unicode) -> None: ... +def dir(o: object = ...) -> List[str]: ... +@overload +def divmod(a: int, b: int) -> Tuple[int, int]: ... +@overload +def divmod(a: float, b: float) -> Tuple[float, float]: ... +def exit(code: Any = ...) -> NoReturn: ... +@overload +def filter(function: None, + iterable: Iterable[Optional[_T]]) -> List[_T]: ... +@overload +def filter(function: Callable[[_T], Any], + iterable: Iterable[_T]) -> List[_T]: ... +def format(o: object, format_spec: str = ...) -> str: ... # TODO unicode +def getattr(o: Any, name: unicode, default: Optional[Any] = ...) -> Any: ... +def hasattr(o: Any, name: unicode) -> bool: ... +def hash(o: object) -> int: ... +def hex(i: int) -> str: ... # TODO __index__ +def id(o: object) -> int: ... +def input(prompt: Any = ...) -> Any: ... +def intern(string: str) -> str: ... +@overload +def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... +@overload +def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... +def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def len(o: Sized) -> int: ... +@overload +def map(func: None, iter1: Iterable[_T1]) -> List[_T1]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, _T3, _T4]]: ... +@overload +def map(func: None, + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... +@overload +def map(func: None, + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +@overload +def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> List[_S]: ... +@overload +def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[_S]: ... +@overload +def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def next(i: Iterator[_T]) -> _T: ... +@overload +def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... +def oct(i: int) -> str: ... # TODO __index__ +@overload +def open(file: str, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... +@overload +def open(file: unicode, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... +@overload +def open(file: int, mode: unicode = ..., buffering: int = ...) -> BinaryIO: ... +def ord(c: unicode) -> int: ... +# This is only available after from __future__ import print_function. +def print(*values: Any, sep: unicode = ..., end: unicode = ..., + file: IO[Any] = ...) -> None: ... +@overload +def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y. +@overload +def pow(x: int, y: int, z: int) -> Any: ... +@overload +def pow(x: float, y: float) -> float: ... +@overload +def pow(x: float, y: float, z: float) -> float: ... +def quit(code: int = ...) -> None: ... +def range(x: int, y: int = ..., step: int = ...) -> List[int]: ... +def raw_input(prompt: Any = ...) -> str: ... + +@overload +def reduce(function: Callable[[_T, _S], _T], iterable: Iterable[_S], initializer: _T) -> _T: ... +@overload +def reduce(function: Callable[[_T, _T], _T], iterable: Iterable[_T]) -> _T: ... + +def reload(module: Any) -> Any: ... +@overload +def reversed(object: Sequence[_T]) -> Iterator[_T]: ... +@overload +def reversed(object: Reversible[_T]) -> Iterator[_T]: ... +def repr(o: object) -> str: ... +@overload +def round(number: float) -> float: ... +@overload +def round(number: float, ndigits: int) -> float: ... # Always return a float if given ndigits. +@overload +def round(number: SupportsRound[_T]) -> _T: ... +@overload +def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def setattr(object: Any, name: unicode, value: Any) -> None: ... +def sorted(iterable: Iterable[_T], *, + cmp: Callable[[_T, _T], int] = ..., + key: Callable[[_T], Any] = ..., + reverse: bool = ...) -> List[_T]: ... +@overload +def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... +@overload +def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... +def unichr(i: int) -> unicode: ... +def vars(object: Any = ...) -> Dict[str, Any]: ... +@overload +def zip(iter1: Iterable[_T1]) -> List[Tuple[_T1]]: ... +@overload +def zip(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> List[Tuple[_T1, _T2]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> List[Tuple[_T1, _T2, _T3]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> List[Tuple[_T1, _T2, + _T3, _T4]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> List[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... +@overload +def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> List[Tuple[Any, ...]]: ... +def __import__(name: unicode, + globals: Dict[str, Any] = ..., + locals: Dict[str, Any] = ..., + fromlist: List[str] = ..., level: int = ...) -> Any: ... + +def globals() -> Dict[str, Any]: ... +def locals() -> Dict[str, Any]: ... + +# Actually the type of Ellipsis is , but since it's +# not exposed anywhere under that name, we make it private here. +class ellipsis: ... +Ellipsis = ... # type: ellipsis + +# TODO: buffer support is incomplete; e.g. some_string.startswith(some_buffer) doesn't type check. +_AnyBuffer = TypeVar('_AnyBuffer', str, unicode, bytearray, buffer) + +class buffer(Sized): + def __init__(self, object: _AnyBuffer, offset: int = ..., size: int = ...) -> None: ... + def __add__(self, other: _AnyBuffer) -> str: ... + def __cmp__(self, other: _AnyBuffer) -> bool: ... + def __getitem__(self, key: Union[int, slice]) -> str: ... + def __getslice__(self, i: int, j: int) -> str: ... + def __len__(self) -> int: ... + def __mul__(self, x: int) -> str: ... + +class memoryview(Sized, Container[bytes]): + format = ... # type: str + itemsize = ... # type: int + shape = ... # type: Optional[Tuple[int, ...]] + strides = ... # type: Optional[Tuple[int, ...]] + suboffsets = ... # type: Optional[Tuple[int, ...]] + readonly = ... # type: bool + ndim = ... # type: int + + def __init__(self, obj: Union[str, bytearray, buffer, memoryview]) -> None: ... + + @overload + def __getitem__(self, i: int) -> bytes: ... + @overload + def __getitem__(self, s: slice) -> memoryview: ... + + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[bytes]: ... + def __len__(self) -> int: ... + + @overload + def __setitem__(self, i: int, o: bytes) -> None: ... + @overload + def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... + @overload + def __setitem__(self, s: slice, o: memoryview) -> None: ... + + def tobytes(self) -> bytes: ... + def tolist(self) -> List[int]: ... + +class BaseException(object): + args = ... # type: Tuple[Any, ...] + message = ... # type: Any + def __init__(self, *args: object, **kwargs: object) -> None: ... + def __getitem__(self, i: int) -> Any: ... + def __getslice__(self, start: int, stop: int) -> Tuple[Any, ...]: ... + +class GeneratorExit(BaseException): ... +class KeyboardInterrupt(BaseException): ... +class SystemExit(BaseException): + code = 0 +class Exception(BaseException): ... +class StopIteration(Exception): ... +class StandardError(Exception): ... +class ArithmeticError(StandardError): ... +class BufferError(StandardError): ... +class EnvironmentError(StandardError): + errno = 0 + strerror = ... # type: str + # TODO can this be unicode? + filename = ... # type: str +class LookupError(StandardError): ... +class RuntimeError(StandardError): ... +class ValueError(StandardError): ... +class AssertionError(StandardError): ... +class AttributeError(StandardError): ... +class EOFError(StandardError): ... +class FloatingPointError(ArithmeticError): ... +class IOError(EnvironmentError): ... +class ImportError(StandardError): ... +class IndexError(LookupError): ... +class KeyError(LookupError): ... +class MemoryError(StandardError): ... +class NameError(StandardError): ... +class NotImplementedError(RuntimeError): ... +class OSError(EnvironmentError): ... +class WindowsError(OSError): + winerror = ... # type: int +class OverflowError(ArithmeticError): ... +class ReferenceError(StandardError): ... +class SyntaxError(StandardError): + msg = ... # type: str + lineno = ... # type: int + offset = ... # type: int + text = ... # type: str + filename = ... # type: str +class IndentationError(SyntaxError): ... +class TabError(IndentationError): ... +class SystemError(StandardError): ... +class TypeError(StandardError): ... +class UnboundLocalError(NameError): ... +class UnicodeError(ValueError): ... +class UnicodeDecodeError(UnicodeError): + encoding: bytes + object: bytes + start: int + end: int + reason: bytes + def __init__(self, __encoding: bytes, __object: bytes, __start: int, __end: int, + __reason: bytes) -> None: ... +class UnicodeEncodeError(UnicodeError): + encoding: bytes + object: unicode + start: int + end: int + reason: bytes + def __init__(self, __encoding: bytes, __object: unicode, __start: int, __end: int, + __reason: bytes) -> None: ... +class UnicodeTranslateError(UnicodeError): ... +class ZeroDivisionError(ArithmeticError): ... + +class Warning(Exception): ... +class UserWarning(Warning): ... +class DeprecationWarning(Warning): ... +class SyntaxWarning(Warning): ... +class RuntimeWarning(Warning): ... +class FutureWarning(Warning): ... +class PendingDeprecationWarning(Warning): ... +class ImportWarning(Warning): ... +class UnicodeWarning(Warning): ... +class BytesWarning(Warning): ... + +def eval(s: Union[str, unicode], globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ...) -> Any: ... +def exec(object: str, + globals: Optional[Dict[str, Any]] = ..., + locals: Optional[Dict[str, Any]] = ...) -> Any: ... # TODO code object as source + +def cmp(x: Any, y: Any) -> int: ... + +def execfile(filename: str, globals: Optional[Dict[str, Any]] = ..., locals: Optional[Dict[str, Any]] = ...) -> None: ... + +class file(BinaryIO): + @overload + def __init__(self, file: str, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: unicode, mode: str = ..., buffering: int = ...) -> None: ... + @overload + def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def __enter__(self) -> BinaryIO: ... + def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... + def flush(self) -> None: ... + def fileno(self) -> int: ... + def isatty(self) -> bool: ... + def close(self) -> None: ... + + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def seekable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def write(self, data: str) -> int: ... + def writelines(self, data: Iterable[str]) -> None: ... + def truncate(self, pos: Optional[int] = ...) -> int: ... + +# Very old builtins +def apply(func: Callable[..., _T], args: Optional[Sequence[Any]] = ..., kwds: Optional[Mapping[str, Any]] = ...) -> _T: ... +_N = TypeVar('_N', bool, int, float, complex) +def coerce(x: _N, y: _N) -> Tuple[_N, _N]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cPickle.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cPickle.pyi new file mode 100644 index 000000000..fb129d1b5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cPickle.pyi @@ -0,0 +1,32 @@ +from typing import Any, IO, List + +HIGHEST_PROTOCOL = ... # type: int +compatible_formats = ... # type: List[str] +format_version = ... # type: str + +class Pickler: + def __init__(self, file: IO[str], protocol: int = ...) -> None: ... + + def dump(self, obj: Any) -> None: ... + + def clear_memo(self) -> None: ... + + +class Unpickler: + def __init__(self, file: IO[str]) -> None: ... + + def load(self) -> Any: ... + + def noload(self) -> Any: ... + + +def dump(obj: Any, file: IO[str], protocol: int = ...) -> None: ... +def dumps(obj: Any, protocol: int = ...) -> str: ... +def load(file: IO[str]) -> Any: ... +def loads(str: str) -> Any: ... + +class PickleError(Exception): ... +class UnpicklingError(PickleError): ... +class BadPickleGet(UnpicklingError): ... +class PicklingError(PickleError): ... +class UnpickleableError(PicklingError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cStringIO.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cStringIO.pyi new file mode 100644 index 000000000..db67cda46 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cStringIO.pyi @@ -0,0 +1,54 @@ +# Stubs for cStringIO (Python 2.7) +# See https://docs.python.org/2/library/stringio.html + +from abc import ABCMeta +from typing import overload, IO, List, Iterable, Iterator, Optional, Union +from types import TracebackType + +# TODO the typing.IO[] generics should be split into input and output. + +# This class isn't actually abstract, but you can't instantiate it +# directly, so we might as well treat it as abstract in the stub. +class InputType(IO[str], Iterator[str], metaclass=ABCMeta): + def getvalue(self) -> str: ... + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def read(self, size: int = ...) -> str: ... + def readline(self, size: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def __iter__(self) -> 'InputType': ... + def next(self) -> str: ... + def reset(self) -> None: ... + + +class OutputType(IO[str], Iterator[str], metaclass=ABCMeta): + @property + def softspace(self) -> int: ... + def getvalue(self) -> str: ... + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def read(self, size: int = ...) -> str: ... + def readline(self, size: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def __iter__(self) -> 'OutputType': ... + def next(self) -> str: ... + def reset(self) -> None: ... + def write(self, b: Union[str, unicode]) -> int: ... + def writelines(self, lines: Iterable[Union[str, unicode]]) -> None: ... + +@overload +def StringIO() -> OutputType: ... +@overload +def StringIO(s: str) -> InputType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/collections.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/collections.pyi new file mode 100644 index 000000000..b8963c6f6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/collections.pyi @@ -0,0 +1,129 @@ +# Stubs for collections + +# Based on http://docs.python.org/2.7/library/collections.html + +# These are not exported. +import typing +from typing import Dict, Generic, TypeVar, Tuple, overload, Type, Optional, List, Union, Reversible + +# These are exported. +from typing import ( + Callable as Callable, + Container as Container, + Hashable as Hashable, + ItemsView as ItemsView, + Iterable as Iterable, + Iterator as Iterator, + KeysView as KeysView, + Mapping as Mapping, + MappingView as MappingView, + MutableMapping as MutableMapping, + MutableSequence as MutableSequence, + MutableSet as MutableSet, + Sequence as Sequence, + AbstractSet as Set, + Sized as Sized, + ValuesView as ValuesView, +) + +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +# namedtuple is special-cased in the type checker; the initializer is ignored. +def namedtuple(typename: Union[str, unicode], field_names: Union[str, unicode, Iterable[Union[str, unicode]]], *, + verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ... + +class deque(Sized, Iterable[_T], Reversible[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T] = ..., + maxlen: int = ...) -> None: ... + @property + def maxlen(self) -> Optional[int]: ... + def append(self, x: _T) -> None: ... + def appendleft(self, x: _T) -> None: ... + def clear(self) -> None: ... + def count(self, x: _T) -> int: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def extendleft(self, iterable: Iterable[_T]) -> None: ... + def pop(self) -> _T: ... + def popleft(self) -> _T: ... + def remove(self, value: _T) -> None: ... + def reverse(self) -> None: ... + def rotate(self, n: int) -> None: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __hash__(self) -> int: ... + def __getitem__(self, i: int) -> _T: ... + def __setitem__(self, i: int, x: _T) -> None: ... + def __contains__(self, o: _T) -> bool: ... + def __reversed__(self) -> Iterator[_T]: ... + +_CounterT = TypeVar('_CounterT', bound=Counter) + +class Counter(Dict[_T, int], Generic[_T]): + @overload + def __init__(self, **kwargs: int) -> None: ... + @overload + def __init__(self, mapping: Mapping[_T, int]) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def copy(self: _CounterT) -> _CounterT: ... + def elements(self) -> Iterator[_T]: ... + def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... + @overload + def subtract(self, __mapping: Mapping[_T, int]) -> None: ... + @overload + def subtract(self, iterable: Iterable[_T]) -> None: ... + # The Iterable[Tuple[...]] argument type is not actually desirable + # (the tuples will be added as keys, breaking type safety) but + # it's included so that the signature is compatible with + # Dict.update. Not sure if we should use '# type: ignore' instead + # and omit the type from the union. + @overload + def update(self, __m: Mapping[_T, int], **kwargs: int) -> None: ... + @overload + def update(self, __m: Union[Iterable[_T], Iterable[Tuple[_T, int]]], **kwargs: int) -> None: ... + @overload + def update(self, **kwargs: int) -> None: ... + + def __add__(self, other: Counter[_T]) -> Counter[_T]: ... + def __sub__(self, other: Counter[_T]) -> Counter[_T]: ... + def __and__(self, other: Counter[_T]) -> Counter[_T]: ... + def __or__(self, other: Counter[_T]) -> Counter[_T]: ... + def __iadd__(self, other: Counter[_T]) -> Counter[_T]: ... + def __isub__(self, other: Counter[_T]) -> Counter[_T]: ... + def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... + def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... + +_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) + +class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): + def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... + def copy(self: _OrderedDictT) -> _OrderedDictT: ... + def __reversed__(self) -> Iterator[_KT]: ... + +_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) + +class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): + default_factory = ... # type: Callable[[], _VT] + @overload + def __init__(self, **kwargs: _VT) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]]) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], **kwargs: _VT) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + map: Mapping[_KT, _VT]) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + iterable: Iterable[Tuple[_KT, _VT]]) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + def __missing__(self, key: _KT) -> _VT: ... + def copy(self: _DefaultDictT) -> _DefaultDictT: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/commands.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/commands.pyi new file mode 100644 index 000000000..e321f0844 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/commands.pyi @@ -0,0 +1,12 @@ +from typing import overload, AnyStr, Text, Tuple + +def getstatus(file: Text) -> str: ... +def getoutput(cmd: Text) -> str: ... +def getstatusoutput(cmd: Text) -> Tuple[int, str]: ... + +@overload +def mk2arg(head: bytes, x: bytes) -> bytes: ... +@overload +def mk2arg(head: Text, x: Text) -> Text: ... + +def mkarg(x: AnyStr) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/compileall.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/compileall.pyi new file mode 100644 index 000000000..c3e861e1e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/compileall.pyi @@ -0,0 +1,10 @@ +# Stubs for compileall (Python 2) + +from typing import Optional, Pattern, Union + +_Path = Union[str, bytes] + +# rx can be any object with a 'search' method; once we have Protocols we can change the type +def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ... +def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ...) -> int: ... +def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ...) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cookielib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cookielib.pyi new file mode 100644 index 000000000..e17f17ad9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/cookielib.pyi @@ -0,0 +1,106 @@ +from typing import Any + +class Cookie: + version = ... # type: Any + name = ... # type: Any + value = ... # type: Any + port = ... # type: Any + port_specified = ... # type: Any + domain = ... # type: Any + domain_specified = ... # type: Any + domain_initial_dot = ... # type: Any + path = ... # type: Any + path_specified = ... # type: Any + secure = ... # type: Any + expires = ... # type: Any + discard = ... # type: Any + comment = ... # type: Any + comment_url = ... # type: Any + rfc2109 = ... # type: Any + def __init__(self, version, name, value, port, port_specified, domain, domain_specified, domain_initial_dot, path, path_specified, secure, expires, discard, comment, comment_url, rest, rfc2109=False): ... + def has_nonstandard_attr(self, name): ... + def get_nonstandard_attr(self, name, default=None): ... + def set_nonstandard_attr(self, name, value): ... + def is_expired(self, now=None): ... + +class CookiePolicy: + def set_ok(self, cookie, request): ... + def return_ok(self, cookie, request): ... + def domain_return_ok(self, domain, request): ... + def path_return_ok(self, path, request): ... + +class DefaultCookiePolicy(CookiePolicy): + DomainStrictNoDots = ... # type: Any + DomainStrictNonDomain = ... # type: Any + DomainRFC2965Match = ... # type: Any + DomainLiberal = ... # type: Any + DomainStrict = ... # type: Any + netscape = ... # type: Any + rfc2965 = ... # type: Any + rfc2109_as_netscape = ... # type: Any + hide_cookie2 = ... # type: Any + strict_domain = ... # type: Any + strict_rfc2965_unverifiable = ... # type: Any + strict_ns_unverifiable = ... # type: Any + strict_ns_domain = ... # type: Any + strict_ns_set_initial_dollar = ... # type: Any + strict_ns_set_path = ... # type: Any + def __init__(self, blocked_domains=None, allowed_domains=None, netscape=True, rfc2965=False, rfc2109_as_netscape=None, hide_cookie2=False, strict_domain=False, strict_rfc2965_unverifiable=True, strict_ns_unverifiable=False, strict_ns_domain=..., strict_ns_set_initial_dollar=False, strict_ns_set_path=False): ... + def blocked_domains(self): ... + def set_blocked_domains(self, blocked_domains): ... + def is_blocked(self, domain): ... + def allowed_domains(self): ... + def set_allowed_domains(self, allowed_domains): ... + def is_not_allowed(self, domain): ... + def set_ok(self, cookie, request): ... + def set_ok_version(self, cookie, request): ... + def set_ok_verifiability(self, cookie, request): ... + def set_ok_name(self, cookie, request): ... + def set_ok_path(self, cookie, request): ... + def set_ok_domain(self, cookie, request): ... + def set_ok_port(self, cookie, request): ... + def return_ok(self, cookie, request): ... + def return_ok_version(self, cookie, request): ... + def return_ok_verifiability(self, cookie, request): ... + def return_ok_secure(self, cookie, request): ... + def return_ok_expires(self, cookie, request): ... + def return_ok_port(self, cookie, request): ... + def return_ok_domain(self, cookie, request): ... + def domain_return_ok(self, domain, request): ... + def path_return_ok(self, path, request): ... + +class Absent: ... + +class CookieJar: + non_word_re = ... # type: Any + quote_re = ... # type: Any + strict_domain_re = ... # type: Any + domain_re = ... # type: Any + dots_re = ... # type: Any + magic_re = ... # type: Any + def __init__(self, policy=None): ... + def set_policy(self, policy): ... + def add_cookie_header(self, request): ... + def make_cookies(self, response, request): ... + def set_cookie_if_ok(self, cookie, request): ... + def set_cookie(self, cookie): ... + def extract_cookies(self, response, request): ... + def clear(self, domain=None, path=None, name=None): ... + def clear_session_cookies(self): ... + def clear_expired_cookies(self): ... + def __iter__(self): ... + def __len__(self): ... + +class LoadError(IOError): ... + +class FileCookieJar(CookieJar): + filename = ... # type: Any + delayload = ... # type: Any + def __init__(self, filename=None, delayload=False, policy=None): ... + def save(self, filename=None, ignore_discard=False, ignore_expires=False): ... + def load(self, filename=None, ignore_discard=False, ignore_expires=False): ... + def revert(self, filename=None, ignore_discard=False, ignore_expires=False): ... + +MozillaCookieJar = FileCookieJar +LWPCookieJar = FileCookieJar +def lwp_cookie_str(cookie: Cookie) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/decimal.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/decimal.pyi new file mode 100644 index 000000000..98d754113 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/decimal.pyi @@ -0,0 +1,245 @@ +# Stubs for decimal (Python 2) + +from typing import ( + Any, Dict, NamedTuple, Optional, Sequence, Tuple, Union, + SupportsAbs, SupportsFloat, SupportsInt, +) + +_Decimal = Union[Decimal, int] +_ComparableNum = Union[Decimal, int, float] + +DecimalTuple = NamedTuple('DecimalTuple', + [('sign', int), + ('digits', Sequence[int]), # TODO: Use Tuple[int, ...] + ('exponent', int)]) + +ROUND_DOWN = ... # type: str +ROUND_HALF_UP = ... # type: str +ROUND_HALF_EVEN = ... # type: str +ROUND_CEILING = ... # type: str +ROUND_FLOOR = ... # type: str +ROUND_UP = ... # type: str +ROUND_HALF_DOWN = ... # type: str +ROUND_05UP = ... # type: str + +class DecimalException(ArithmeticError): + def handle(self, context, *args): ... + +class Clamped(DecimalException): ... + +class InvalidOperation(DecimalException): ... + +class ConversionSyntax(InvalidOperation): ... + +class DivisionByZero(DecimalException, ZeroDivisionError): ... + +class DivisionImpossible(InvalidOperation): ... + +class DivisionUndefined(InvalidOperation, ZeroDivisionError): ... + +class Inexact(DecimalException): ... + +class InvalidContext(InvalidOperation): ... + +class Rounded(DecimalException): ... + +class Subnormal(DecimalException): ... + +class Overflow(Inexact, Rounded): ... + +class Underflow(Inexact, Rounded, Subnormal): ... + +def setcontext(context: Context): ... +def getcontext() -> Context: ... +def localcontext(ctx: Optional[Context] = ...) -> _ContextManager: ... + +class Decimal(SupportsAbs[Decimal], SupportsFloat, SupportsInt): + def __init__(cls, value: Union[_Decimal, float, str, unicode, + Tuple[int, Sequence[int], int]] = ..., + context: Context = ...) -> None: ... + @classmethod + def from_float(cls, f: float) -> Decimal: ... + def __nonzero__(self) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __lt__(self, other: _ComparableNum) -> bool: ... + def __le__(self, other: _ComparableNum) -> bool: ... + def __gt__(self, other: _ComparableNum) -> bool: ... + def __ge__(self, other: _ComparableNum) -> bool: ... + def compare(self, other: _Decimal) -> Decimal: ... + def __hash__(self) -> int: ... + def as_tuple(self) -> DecimalTuple: ... + def to_eng_string(self, context: Context = ...) -> str: ... + def __neg__(self) -> Decimal: ... + def __pos__(self) -> Decimal: ... + def __abs__(self, round: bool = ...) -> Decimal: ... + def __add__(self, other: _Decimal) -> Decimal: ... + def __radd__(self, other: int) -> Decimal: ... + def __sub__(self, other: _Decimal) -> Decimal: ... + def __rsub__(self, other: int) -> Decimal: ... + def __mul__(self, other: _Decimal) -> Decimal: ... + def __rmul__(self, other: int) -> Decimal: ... + def __truediv__(self, other: _Decimal) -> Decimal: ... + def __rtruediv__(self, other: int) -> Decimal: ... + def __div__(self, other: _Decimal) -> Decimal: ... + def __rdiv__(self, other: int) -> Decimal: ... + def __divmod__(self, other: _Decimal) -> Tuple[Decimal, Decimal]: ... + def __rdivmod__(self, other: int) -> Tuple[Decimal, Decimal]: ... + def __mod__(self, other: _Decimal) -> Decimal: ... + def __rmod__(self, other: int) -> Decimal: ... + def remainder_near(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def __floordiv__(self, other: _Decimal) -> Decimal: ... + def __rfloordiv__(self, other: int) -> Decimal: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + def __trunc__(self) -> int: ... + @property + def imag(self) -> Decimal: ... + @property + def real(self) -> Decimal: ... + def conjugate(self) -> Decimal: ... + def __complex__(self) -> complex: ... + def __long__(self) -> long: ... + def fma(self, other: _Decimal, third: _Decimal, context: Context = ...) -> Decimal: ... + def __pow__(self, other: _Decimal) -> Decimal: ... + def __rpow__(self, other: int) -> Decimal: ... + def normalize(self, context: Context = ...) -> Decimal: ... + def quantize(self, exp: _Decimal, rounding: str = ..., + context: Context = ...) -> Decimal: ... + def same_quantum(self, other: Decimal) -> bool: ... + def to_integral(self, rounding: str = ..., context: Context = ...) -> Decimal: ... + def to_integral_exact(self, rounding: str = ..., context: Context = ...) -> Decimal: ... + def to_integral_value(self, rounding: str = ..., context: Context = ...) -> Decimal: ... + def sqrt(self, context: Context = ...) -> Decimal: ... + def max(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def min(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def adjusted(self) -> int: ... + def canonical(self, context: Context = ...) -> Decimal: ... + def compare_signal(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def compare_total(self, other: _Decimal) -> Decimal: ... + def compare_total_mag(self, other: _Decimal) -> Decimal: ... + def copy_abs(self) -> Decimal: ... + def copy_negate(self) -> Decimal: ... + def copy_sign(self, other: _Decimal) -> Decimal: ... + def exp(self, context: Context = ...) -> Decimal: ... + def is_canonical(self) -> bool: ... + def is_finite(self) -> bool: ... + def is_infinite(self) -> bool: ... + def is_nan(self) -> bool: ... + def is_normal(self, context: Context = ...) -> bool: ... + def is_qnan(self) -> bool: ... + def is_signed(self) -> bool: ... + def is_snan(self) -> bool: ... + def is_subnormal(self, context: Context = ...) -> bool: ... + def is_zero(self) -> bool: ... + def ln(self, context: Context = ...) -> Decimal: ... + def log10(self, context: Context = ...) -> Decimal: ... + def logb(self, context: Context = ...) -> Decimal: ... + def logical_and(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def logical_invert(self, context: Context = ...) -> Decimal: ... + def logical_or(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def logical_xor(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def max_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def min_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def next_minus(self, context: Context = ...) -> Decimal: ... + def next_plus(self, context: Context = ...) -> Decimal: ... + def next_toward(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def number_class(self, context: Context = ...) -> str: ... + def radix(self) -> Decimal: ... + def rotate(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def scaleb(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def shift(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def __reduce__(self): ... + def __copy__(self): ... + def __deepcopy__(self, memo): ... + def __format__(self, specifier, context=None, _localeconv=None) -> str: ... + +class _ContextManager: + new_context = ... # type: Context + saved_context = ... # type: Context + def __init__(self, new_context: Context) -> None: ... + def __enter__(self): ... + def __exit__(self, t, v, tb): ... + +class Context: + prec = ... # type: int + rounding = ... # type: str + Emin = ... # type: int + Emax = ... # type: int + capitals = ... # type: int + traps = ... # type: Dict[type, bool] + flags = ... # type: Any + def __init__(self, prec=None, rounding=None, traps=None, flags=None, Emin=None, Emax=None, capitals=None, _clamp=0, _ignored_flags=None): ... + def clear_flags(self): ... + def copy(self): ... + __copy__ = ... # type: Any + __hash__ = ... # type: Any + def Etiny(self): ... + def Etop(self): ... + def create_decimal(self, num=...): ... + def create_decimal_from_float(self, f): ... + def abs(self, a): ... + def add(self, a, b): ... + def canonical(self, a): ... + def compare(self, a, b): ... + def compare_signal(self, a, b): ... + def compare_total(self, a, b): ... + def compare_total_mag(self, a, b): ... + def copy_abs(self, a): ... + def copy_decimal(self, a): ... + def copy_negate(self, a): ... + def copy_sign(self, a, b): ... + def divide(self, a, b): ... + def divide_int(self, a, b): ... + def divmod(self, a, b): ... + def exp(self, a): ... + def fma(self, a, b, c): ... + def is_canonical(self, a): ... + def is_finite(self, a): ... + def is_infinite(self, a): ... + def is_nan(self, a): ... + def is_normal(self, a): ... + def is_qnan(self, a): ... + def is_signed(self, a): ... + def is_snan(self, a): ... + def is_subnormal(self, a): ... + def is_zero(self, a): ... + def ln(self, a): ... + def log10(self, a): ... + def logb(self, a): ... + def logical_and(self, a, b): ... + def logical_invert(self, a): ... + def logical_or(self, a, b): ... + def logical_xor(self, a, b): ... + def max(self, a, b): ... + def max_mag(self, a, b): ... + def min(self, a, b): ... + def min_mag(self, a, b): ... + def minus(self, a): ... + def multiply(self, a, b): ... + def next_minus(self, a): ... + def next_plus(self, a): ... + def next_toward(self, a, b): ... + def normalize(self, a): ... + def number_class(self, a): ... + def plus(self, a): ... + def power(self, a, b, modulo=None): ... + def quantize(self, a, b): ... + def radix(self): ... + def remainder(self, a, b): ... + def remainder_near(self, a, b): ... + def rotate(self, a, b): ... + def same_quantum(self, a, b): ... + def scaleb(self, a, b): ... + def shift(self, a, b): ... + def sqrt(self, a): ... + def subtract(self, a, b): ... + def to_eng_string(self, a): ... + def to_sci_string(self, a): ... + def to_integral_exact(self, a): ... + def to_integral_value(self, a): ... + def to_integral(self, a): ... + +DefaultContext = ... # type: Context +BasicContext = ... # type: Context +ExtendedContext = ... # type: Context diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/dircache.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/dircache.pyi new file mode 100644 index 000000000..ac6732b6c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/dircache.pyi @@ -0,0 +1,10 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/dircache.py + +from typing import List, MutableSequence, Text, Union + +def reset() -> None: ... +def listdir(path: Text) -> List[str]: ... + +opendir = listdir + +def annotate(head: Text, list: Union[MutableSequence[str], MutableSequence[Text], MutableSequence[Union[str, Text]]]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/distutils/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/distutils/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/distutils/emxccompiler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/distutils/emxccompiler.pyi new file mode 100644 index 000000000..97e4a29ad --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/distutils/emxccompiler.pyi @@ -0,0 +1,5 @@ +# Stubs for emxccompiler + +from distutils.unixccompiler import UnixCCompiler + +class EMXCCompiler(UnixCCompiler): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/dummy_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/dummy_thread.pyi new file mode 100644 index 000000000..28041002a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/dummy_thread.pyi @@ -0,0 +1,21 @@ +from typing import Any, Callable, Dict, NoReturn, Optional, Tuple + +class error(Exception): + def __init__(self, *args: Any) -> None: ... + +def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: Dict[str, Any] = ...) -> None: ... +def exit() -> NoReturn: ... +def get_ident() -> int: ... +def allocate_lock() -> LockType: ... +def stack_size(size: Optional[int] = ...) -> int: ... + +class LockType(object): + locked_status: bool + def __init__(self) -> None: ... + def acquire(self, waitflag: Optional[bool] = ...) -> bool: ... + def __enter__(self, waitflag: Optional[bool] = ...) -> bool: ... + def __exit__(self, typ: Any, val: Any, tb: Any) -> None: ... + def release(self) -> bool: ... + def locked(self) -> bool: ... + +def interrupt_main() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/MIMEText.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/MIMEText.pyi new file mode 100644 index 000000000..3b059778a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/MIMEText.pyi @@ -0,0 +1,4 @@ +from email.mime.nonmultipart import MIMENonMultipart + +class MIMEText(MIMENonMultipart): + def __init__(self, _text, _subtype=..., _charset=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/__init__.pyi new file mode 100644 index 000000000..384d9567f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/__init__.pyi @@ -0,0 +1,6 @@ +from typing import IO, Any, AnyStr + +def message_from_string(s: AnyStr, *args, **kwargs): ... +def message_from_bytes(s: str, *args, **kwargs): ... +def message_from_file(fp: IO[AnyStr], *args, **kwargs): ... +def message_from_binary_file(fp: IO[str], *args, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/_parseaddr.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/_parseaddr.pyi new file mode 100644 index 000000000..beba33f19 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/_parseaddr.pyi @@ -0,0 +1,40 @@ +from typing import Any + +def parsedate_tz(data): ... +def parsedate(data): ... +def mktime_tz(data): ... +def quote(str): ... + +class AddrlistClass: + specials = ... # type: Any + pos = ... # type: Any + LWS = ... # type: Any + CR = ... # type: Any + FWS = ... # type: Any + atomends = ... # type: Any + phraseends = ... # type: Any + field = ... # type: Any + commentlist = ... # type: Any + def __init__(self, field): ... + def gotonext(self): ... + def getaddrlist(self): ... + def getaddress(self): ... + def getrouteaddr(self): ... + def getaddrspec(self): ... + def getdomain(self): ... + def getdelimited(self, beginchar, endchars, allowcomments=True): ... + def getquote(self): ... + def getcomment(self): ... + def getdomainliteral(self): ... + def getatom(self, atomends=None): ... + def getphraselist(self): ... + +class AddressList(AddrlistClass): + addresslist = ... # type: Any + def __init__(self, field): ... + def __len__(self): ... + def __add__(self, other): ... + def __iadd__(self, other): ... + def __sub__(self, other): ... + def __isub__(self, other): ... + def __getitem__(self, index): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/base64mime.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/base64mime.pyi new file mode 100644 index 000000000..f05003b8d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/base64mime.pyi @@ -0,0 +1,8 @@ +def base64_len(s: bytes) -> int: ... +def header_encode(header, charset=..., keep_eols=..., maxlinelen=..., eol=...): ... +def encode(s, binary=..., maxlinelen=..., eol=...): ... +body_encode = encode +encodestring = encode +def decode(s, convert_eols=...): ... +body_decode = decode +decodestring = decode diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/charset.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/charset.pyi new file mode 100644 index 000000000..82ba6c0bb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/charset.pyi @@ -0,0 +1,22 @@ +def add_charset(charset, header_enc=..., body_enc=..., output_charset=...) -> None: ... +def add_alias(alias, canonical) -> None: ... +def add_codec(charset, codecname) -> None: ... + +class Charset: + input_charset = ... + header_encoding = ... + body_encoding = ... + output_charset = ... + input_codec = ... + output_codec = ... + def __init__(self, input_charset=...) -> None: ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def get_body_encoding(self): ... + def convert(self, s): ... + def to_splittable(self, s): ... + def from_splittable(self, ustr, to_output: bool = ...): ... + def get_output_charset(self): ... + def encoded_header_len(self, s): ... + def header_encode(self, s, convert: bool = ...): ... + def body_encode(self, s, convert: bool = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/encoders.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/encoders.pyi new file mode 100644 index 000000000..5670cbaf0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/encoders.pyi @@ -0,0 +1,4 @@ +def encode_base64(msg) -> None: ... +def encode_quopri(msg) -> None: ... +def encode_7or8bit(msg) -> None: ... +def encode_noop(msg) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/feedparser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/feedparser.pyi new file mode 100644 index 000000000..51f825939 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/feedparser.pyi @@ -0,0 +1,18 @@ +class BufferedSubFile: + def __init__(self) -> None: ... + def push_eof_matcher(self, pred) -> None: ... + def pop_eof_matcher(self): ... + def close(self) -> None: ... + def readline(self): ... + def unreadline(self, line) -> None: ... + def push(self, data): ... + def pushlines(self, lines) -> None: ... + def is_closed(self): ... + def __iter__(self): ... + def next(self): ... + + +class FeedParser: + def __init__(self, _factory=...) -> None: ... + def feed(self, data) -> None: ... + def close(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/generator.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/generator.pyi new file mode 100644 index 000000000..96cfe2d21 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/generator.pyi @@ -0,0 +1,9 @@ +class Generator: + def __init__(self, outfp, mangle_from_: bool = ..., maxheaderlen: int = ...) -> None: ... + def write(self, s) -> None: ... + def flatten(self, msg, unixfrom: bool = ...) -> None: ... + def clone(self, fp): ... + + +class DecodedGenerator(Generator): + def __init__(self, outfp, mangle_from_: bool = ..., maxheaderlen: int = ..., fmt=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/header.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/header.pyi new file mode 100644 index 000000000..69c936300 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/header.pyi @@ -0,0 +1,11 @@ +def decode_header(header): ... +def make_header(decoded_seq, maxlinelen=..., header_name=..., continuation_ws=...): ... + +class Header: + def __init__(self, s=..., charset=..., maxlinelen=..., header_name=..., continuation_ws=..., + errors=...) -> None: ... + def __unicode__(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def append(self, s, charset=..., errors=...) -> None: ... + def encode(self, splitchars=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/iterators.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/iterators.pyi new file mode 100644 index 000000000..48aaf06a6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/iterators.pyi @@ -0,0 +1,5 @@ +from typing import Generator + +def walk(self) -> Generator: ... +def body_line_iterator(msg, decode: bool = ...) -> Generator: ... +def typed_subpart_iterator(msg, maintype=..., subtype=...) -> Generator: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/message.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/message.pyi new file mode 100644 index 000000000..bd3c6220d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/message.pyi @@ -0,0 +1,45 @@ +from typing import Generator + +class Message: + preamble = ... + epilogue = ... + defects = ... + def __init__(self): ... + def as_string(self, unixfrom=...): ... + def is_multipart(self) -> bool: ... + def set_unixfrom(self, unixfrom) -> None: ... + def get_unixfrom(self): ... + def attach(self, payload) -> None: ... + def get_payload(self, i=..., decode: bool = ...): ... + def set_payload(self, payload, charset=...) -> None: ... + def set_charset(self, charset): ... + def get_charset(self): ... + def __len__(self): ... + def __getitem__(self, name): ... + def __setitem__(self, name, val) -> None: ... + def __delitem__(self, name) -> None: ... + def __contains__(self, name): ... + def has_key(self, name) -> bool: ... + def keys(self): ... + def values(self): ... + def items(self): ... + def get(self, name, failobj=...): ... + def get_all(self, name, failobj=...): ... + def add_header(self, _name, _value, **_params) -> None: ... + def replace_header(self, _name, _value) -> None: ... + def get_content_type(self): ... + def get_content_maintype(self): ... + def get_content_subtype(self): ... + def get_default_type(self): ... + def set_default_type(self, ctype) -> None: ... + def get_params(self, failobj=..., header=..., unquote: bool = ...): ... + def get_param(self, param, failobj=..., header=..., unquote: bool = ...): ... + def set_param(self, param, value, header=..., requote: bool = ..., charset=..., language=...) -> None: ... + def del_param(self, param, header=..., requote: bool = ...): ... + def set_type(self, type, header=..., requote: bool = ...): ... + def get_filename(self, failobj=...): ... + def get_boundary(self, failobj=...): ... + def set_boundary(self, boundary) -> None: ... + def get_content_charset(self, failobj=...): ... + def get_charsets(self, failobj=...): ... + def walk(self) -> Generator: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/application.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/application.pyi new file mode 100644 index 000000000..99da67287 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/application.pyi @@ -0,0 +1,11 @@ +# Stubs for email.mime.application + +from typing import Callable, Optional, Tuple, Union +from email.mime.nonmultipart import MIMENonMultipart + +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] + +class MIMEApplication(MIMENonMultipart): + def __init__(self, _data: bytes, _subtype: str = ..., + _encoder: Callable[[MIMEApplication], None] = ..., + **_params: _ParamsType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/audio.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/audio.pyi new file mode 100644 index 000000000..406ade11b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/audio.pyi @@ -0,0 +1,5 @@ +from email.mime.nonmultipart import MIMENonMultipart + + +class MIMEAudio(MIMENonMultipart): + def __init__(self, _audiodata, _subtype=..., _encoder=..., **_params) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/base.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/base.pyi new file mode 100644 index 000000000..4bde4f073 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/base.pyi @@ -0,0 +1,4 @@ +from email import message + +class MIMEBase(message.Message): + def __init__(self, _maintype, _subtype, **_params) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/image.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/image.pyi new file mode 100644 index 000000000..2dfb098b8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/image.pyi @@ -0,0 +1,5 @@ +from email.mime.nonmultipart import MIMENonMultipart + + +class MIMEImage(MIMENonMultipart): + def __init__(self, _imagedata, _subtype=..., _encoder=..., **_params) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/message.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/message.pyi new file mode 100644 index 000000000..33552faf2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/message.pyi @@ -0,0 +1,5 @@ +from email.mime.nonmultipart import MIMENonMultipart + + +class MIMEMessage(MIMENonMultipart): + def __init__(self, _msg, _subtype=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/multipart.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/multipart.pyi new file mode 100644 index 000000000..0a7d3fa8a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/multipart.pyi @@ -0,0 +1,4 @@ +from email.mime.base import MIMEBase + +class MIMEMultipart(MIMEBase): + def __init__(self, _subtype=..., boundary=..., _subparts=..., **_params) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/nonmultipart.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/nonmultipart.pyi new file mode 100644 index 000000000..04d130e3d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/nonmultipart.pyi @@ -0,0 +1,4 @@ +from email.mime.base import MIMEBase + +class MIMENonMultipart(MIMEBase): + def attach(self, payload): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/text.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/text.pyi new file mode 100644 index 000000000..3b059778a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/mime/text.pyi @@ -0,0 +1,4 @@ +from email.mime.nonmultipart import MIMENonMultipart + +class MIMEText(MIMENonMultipart): + def __init__(self, _text, _subtype=..., _charset=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/parser.pyi new file mode 100644 index 000000000..4f2282834 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/parser.pyi @@ -0,0 +1,10 @@ +from .feedparser import FeedParser as FeedParser # not in __all__ but listed in documentation + +class Parser: + def __init__(self, *args, **kws) -> None: ... + def parse(self, fp, headersonly: bool = ...): ... + def parsestr(self, text, headersonly: bool = ...): ... + +class HeaderParser(Parser): + def parse(self, fp, headersonly: bool = ...): ... + def parsestr(self, text, headersonly: bool = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/quoprimime.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/quoprimime.pyi new file mode 100644 index 000000000..3f2963c06 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/quoprimime.pyi @@ -0,0 +1,18 @@ +def header_quopri_check(c): ... +def body_quopri_check(c): ... +def header_quopri_len(s): ... +def body_quopri_len(str): ... +def unquote(s): ... +def quote(c): ... +def header_encode(header, charset: str = ..., keep_eols: bool = ..., maxlinelen: int = ..., eol=...): ... +def encode(body, binary: bool = ..., maxlinelen: int = ..., eol=...): ... + +body_encode = encode +encodestring = encode + +def decode(encoded, eol=...): ... + +body_decode = decode +decodestring = decode + +def header_decode(s): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/utils.pyi new file mode 100644 index 000000000..293a4c3e4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/email/utils.pyi @@ -0,0 +1,18 @@ +from email._parseaddr import AddressList as _AddressList +from email._parseaddr import mktime_tz as mktime_tz +from email._parseaddr import parsedate as _parsedate +from email._parseaddr import parsedate_tz as _parsedate_tz +from quopri import decodestring as _qdecode + +def formataddr(pair): ... +def getaddresses(fieldvalues): ... +def formatdate(timeval=None, localtime=False, usegmt=False): ... +def make_msgid(idstring=None): ... +def parsedate(data): ... +def parsedate_tz(data): ... +def parseaddr(addr): ... +def unquote(str): ... +def decode_rfc2231(s): ... +def encode_rfc2231(s, charset=None, language=None): ... +def decode_params(params): ... +def collapse_rfc2231_value(value, errors=..., fallback_charset=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/encodings/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/encodings/__init__.pyi new file mode 100644 index 000000000..2ae6c0a93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/encodings/__init__.pyi @@ -0,0 +1,6 @@ +import codecs + +import typing + +def search_function(encoding: str) -> codecs.CodecInfo: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/encodings/utf_8.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/encodings/utf_8.pyi new file mode 100644 index 000000000..d38bd58d0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/encodings/utf_8.pyi @@ -0,0 +1,15 @@ +import codecs +from typing import Text, Tuple + +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input: Text, final: bool = ...) -> bytes: ... + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def _buffer_decode(self, input: bytes, errors: str, final: bool) -> Tuple[Text, int]: ... + +class StreamWriter(codecs.StreamWriter): ... +class StreamReader(codecs.StreamReader): ... + +def getregentry() -> codecs.CodecInfo: ... +def encode(input: Text, errors: Text = ...) -> bytes: ... +def decode(input: bytes, errors: Text = ...) -> Text: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/exceptions.pyi new file mode 100644 index 000000000..6e4bafc9a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/exceptions.pyi @@ -0,0 +1,48 @@ +from __builtin__ import ArithmeticError as ArithmeticError +from __builtin__ import AssertionError as AssertionError +from __builtin__ import AttributeError as AttributeError +from __builtin__ import BaseException as BaseException +from __builtin__ import BufferError as BufferError +from __builtin__ import BytesWarning as BytesWarning +from __builtin__ import DeprecationWarning as DeprecationWarning +from __builtin__ import EOFError as EOFError +from __builtin__ import EnvironmentError as EnvironmentError +from __builtin__ import Exception as Exception +from __builtin__ import FloatingPointError as FloatingPointError +from __builtin__ import FutureWarning as FutureWarning +from __builtin__ import GeneratorExit as GeneratorExit +from __builtin__ import IOError as IOError +from __builtin__ import ImportError as ImportError +from __builtin__ import ImportWarning as ImportWarning +from __builtin__ import IndentationError as IndentationError +from __builtin__ import IndexError as IndexError +from __builtin__ import KeyError as KeyError +from __builtin__ import KeyboardInterrupt as KeyboardInterrupt +from __builtin__ import LookupError as LookupError +from __builtin__ import MemoryError as MemoryError +from __builtin__ import NameError as NameError +from __builtin__ import NotImplementedError as NotImplementedError +from __builtin__ import OSError as OSError +from __builtin__ import OverflowError as OverflowError +from __builtin__ import PendingDeprecationWarning as PendingDeprecationWarning +from __builtin__ import ReferenceError as ReferenceError +from __builtin__ import RuntimeError as RuntimeError +from __builtin__ import RuntimeWarning as RuntimeWarning +from __builtin__ import StandardError as StandardError +from __builtin__ import StopIteration as StopIteration +from __builtin__ import SyntaxError as SyntaxError +from __builtin__ import SyntaxWarning as SyntaxWarning +from __builtin__ import SystemError as SystemError +from __builtin__ import SystemExit as SystemExit +from __builtin__ import TabError as TabError +from __builtin__ import TypeError as TypeError +from __builtin__ import UnboundLocalError as UnboundLocalError +from __builtin__ import UnicodeError as UnicodeError +from __builtin__ import UnicodeDecodeError as UnicodeDecodeError +from __builtin__ import UnicodeEncodeError as UnicodeEncodeError +from __builtin__ import UnicodeTranslateError as UnicodeTranslateError +from __builtin__ import UnicodeWarning as UnicodeWarning +from __builtin__ import UserWarning as UserWarning +from __builtin__ import ValueError as ValueError +from __builtin__ import Warning as Warning +from __builtin__ import ZeroDivisionError as ZeroDivisionError diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/fcntl.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/fcntl.pyi new file mode 100644 index 000000000..c7ff895e4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/fcntl.pyi @@ -0,0 +1,87 @@ +from typing import Any, Union, IO +import io + +FASYNC = ... # type: int +FD_CLOEXEC = ... # type: int + +DN_ACCESS = ... # type: int +DN_ATTRIB = ... # type: int +DN_CREATE = ... # type: int +DN_DELETE = ... # type: int +DN_MODIFY = ... # type: int +DN_MULTISHOT = ... # type: int +DN_RENAME = ... # type: int +F_DUPFD = ... # type: int +F_EXLCK = ... # type: int +F_GETFD = ... # type: int +F_GETFL = ... # type: int +F_GETLEASE = ... # type: int +F_GETLK = ... # type: int +F_GETLK64 = ... # type: int +F_GETOWN = ... # type: int +F_GETSIG = ... # type: int +F_NOTIFY = ... # type: int +F_RDLCK = ... # type: int +F_SETFD = ... # type: int +F_SETFL = ... # type: int +F_SETLEASE = ... # type: int +F_SETLK = ... # type: int +F_SETLK64 = ... # type: int +F_SETLKW = ... # type: int +F_SETLKW64 = ... # type: int +F_SETOWN = ... # type: int +F_SETSIG = ... # type: int +F_SHLCK = ... # type: int +F_UNLCK = ... # type: int +F_WRLCK = ... # type: int +I_ATMARK = ... # type: int +I_CANPUT = ... # type: int +I_CKBAND = ... # type: int +I_FDINSERT = ... # type: int +I_FIND = ... # type: int +I_FLUSH = ... # type: int +I_FLUSHBAND = ... # type: int +I_GETBAND = ... # type: int +I_GETCLTIME = ... # type: int +I_GETSIG = ... # type: int +I_GRDOPT = ... # type: int +I_GWROPT = ... # type: int +I_LINK = ... # type: int +I_LIST = ... # type: int +I_LOOK = ... # type: int +I_NREAD = ... # type: int +I_PEEK = ... # type: int +I_PLINK = ... # type: int +I_POP = ... # type: int +I_PUNLINK = ... # type: int +I_PUSH = ... # type: int +I_RECVFD = ... # type: int +I_SENDFD = ... # type: int +I_SETCLTIME = ... # type: int +I_SETSIG = ... # type: int +I_SRDOPT = ... # type: int +I_STR = ... # type: int +I_SWROPT = ... # type: int +I_UNLINK = ... # type: int +LOCK_EX = ... # type: int +LOCK_MAND = ... # type: int +LOCK_NB = ... # type: int +LOCK_READ = ... # type: int +LOCK_RW = ... # type: int +LOCK_SH = ... # type: int +LOCK_UN = ... # type: int +LOCK_WRITE = ... # type: int + +_ANYFILE = Union[int, IO] + +# TODO All these return either int or bytes depending on the value of +# cmd (not on the type of arg). +def fcntl(fd: _ANYFILE, op: int, arg: Union[int, bytes] = ...) -> Any: ... + +# TODO: arg: int or read-only buffer interface or read-write buffer interface +def ioctl(fd: _ANYFILE, op: int, arg: Union[int, bytes] = ..., + mutate_flag: bool = ...) -> Any: ... + +def flock(fd: _ANYFILE, op: int) -> None: ... +def lockf(fd: _ANYFILE, op: int, length: int = ..., start: int = ..., + whence: int = ...) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/fnmatch.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/fnmatch.pyi new file mode 100644 index 000000000..e933b7b2c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/fnmatch.pyi @@ -0,0 +1,8 @@ +from typing import AnyStr, Iterable, List, Union + +_EitherStr = Union[str, unicode] + +def fnmatch(filename: _EitherStr, pattern: _EitherStr) -> bool: ... +def fnmatchcase(filename: _EitherStr, pattern: _EitherStr) -> bool: ... +def filter(names: Iterable[AnyStr], pattern: _EitherStr) -> List[AnyStr]: ... +def translate(pattern: AnyStr) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/functools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/functools.pyi new file mode 100644 index 000000000..a0e1a8fa2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/functools.pyi @@ -0,0 +1,34 @@ +# Stubs for functools (Python 2.7) + +# NOTE: These are incomplete! + +from abc import ABCMeta, abstractmethod +from typing import Any, Callable, Generic, Dict, Iterable, Optional, Sequence, Tuple, TypeVar, overload +from collections import namedtuple + +_AnyCallable = Callable[..., Any] + +_T = TypeVar("_T") +_S = TypeVar("_S") +@overload +def reduce(function: Callable[[_T, _T], _T], + sequence: Iterable[_T]) -> _T: ... +@overload +def reduce(function: Callable[[_T, _S], _T], + sequence: Iterable[_S], initial: _T) -> _T: ... + +WRAPPER_ASSIGNMENTS = ... # type: Sequence[str] +WRAPPER_UPDATES = ... # type: Sequence[str] + +def update_wrapper(wrapper: _AnyCallable, wrapped: _AnyCallable, assigned: Sequence[str] = ..., + updated: Sequence[str] = ...) -> _AnyCallable: ... +def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_AnyCallable], _AnyCallable]: ... +def total_ordering(cls: type) -> type: ... +def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ... + +class partial(Generic[_T]): + func = ... # Callable[..., _T] + args = ... # type: Tuple[Any, ...] + keywords = ... # type: Dict[str, Any] + def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/future_builtins.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/future_builtins.pyi new file mode 100644 index 000000000..a9b25b2fe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/future_builtins.pyi @@ -0,0 +1,14 @@ +from typing import Any + +from itertools import ifilter as filter +from itertools import imap as map +from itertools import izip as zip + + +def ascii(obj: Any) -> str: ... + + +def hex(x: int) -> str: ... + + +def oct(x: int) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gc.pyi new file mode 100644 index 000000000..d93e996a5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gc.pyi @@ -0,0 +1,29 @@ +# Stubs for gc + +from typing import Any, List, Tuple + + +def enable() -> None: ... +def disable() -> None: ... +def isenabled() -> bool: ... +def collect(generation: int = ...) -> int: ... +def set_debug(flags: int) -> None: ... +def get_debug() -> int: ... +def get_objects() -> List[Any]: ... +def set_threshold(threshold0: int, threshold1: int = ..., + threshold2: int = ...) -> None: ... +def get_count() -> Tuple[int, int, int]: ... +def get_threshold() -> Tuple[int, int, int]: ... +def get_referrers(*objs: Any) -> List[Any]: ... +def get_referents(*objs: Any) -> List[Any]: ... +def is_tracked(obj: Any) -> bool: ... + +garbage = ... # type: List[Any] + +DEBUG_STATS = ... # type: int +DEBUG_COLLECTABLE = ... # type: int +DEBUG_UNCOLLECTABLE = ... # type: int +DEBUG_INSTANCES = ... # type: int +DEBUG_OBJECTS = ... # type: int +DEBUG_SAVEALL = ... # type: int +DEBUG_LEAK = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/genericpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/genericpath.pyi new file mode 100644 index 000000000..24bbbba3b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/genericpath.pyi @@ -0,0 +1,12 @@ +from typing import AnyStr, List + +class _unicode: ... + +def commonprefix(list: List[AnyStr]) -> AnyStr: ... +def exists(path: unicode) -> bool: ... +def getatime(path: unicode) -> float: ... +def getmtime(path: unicode) -> float: ... +def getctime(path: unicode) -> float: ... +def getsize(path: unicode) -> int: ... +def isfile(path: unicode) -> bool: ... +def isdir(path: unicode) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/getopt.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/getopt.pyi new file mode 100644 index 000000000..bc6577fc3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/getopt.pyi @@ -0,0 +1,17 @@ +from typing import List, Tuple + +class GetoptError(Exception): + opt = ... # type: str + msg = ... # type: str + def __init__(self, msg: str, opt: str=...) -> None: ... + def __str__(self) -> str: ... + +error = GetoptError + +def getopt(args: List[str], shortopts: str, + longopts: List[str]=...) -> Tuple[List[Tuple[str, str]], + List[str]]: ... + +def gnu_getopt(args: List[str], shortopts: str, + longopts: List[str]=...) -> Tuple[List[Tuple[str, str]], + List[str]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/getpass.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/getpass.pyi new file mode 100644 index 000000000..011fc8e79 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/getpass.pyi @@ -0,0 +1,8 @@ +# Stubs for getpass (Python 2) + +from typing import Any, IO + +class GetPassWarning(UserWarning): ... + +def getpass(prompt: str = ..., stream: IO[Any] = ...) -> str: ... +def getuser() -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gettext.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gettext.pyi new file mode 100644 index 000000000..a12d54123 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gettext.pyi @@ -0,0 +1,41 @@ +from typing import Any, Container, Dict, IO, List, Optional, Sequence, Type, Union + +def bindtextdomain(domain: str, localedir: str = ...) -> str: ... +def bind_textdomain_codeset(domain: str, codeset: str = ...) -> str: ... +def textdomain(domain: str = ...) -> str: ... +def gettext(message: str) -> str: ... +def lgettext(message: str) -> str: ... +def dgettext(domain: str, message: str) -> str: ... +def ldgettext(domain: str, message: str) -> str: ... +def ngettext(singular: str, plural: str, n: int) -> str: ... +def lngettext(singular: str, plural: str, n: int) -> str: ... +def dngettext(domain: str, singular: str, plural: str, n: int) -> str: ... +def ldngettext(domain: str, singular: str, plural: str, n: int) -> str: ... + +class NullTranslations(object): + def __init__(self, fp: IO[str] = ...) -> None: ... + def _parse(self, fp: IO[str]) -> None: ... + def add_fallback(self, fallback: NullTranslations) -> None: ... + def gettext(self, message: str) -> str: ... + def lgettext(self, message: str) -> str: ... + def ugettext(self, message: Union[str, unicode]) -> unicode: ... + def ngettext(self, singular: str, plural: str, n: int) -> str: ... + def lngettext(self, singular: str, plural: str, n: int) -> str: ... + def ungettext(self, singular: Union[str, unicode], plural: Union[str, unicode], n: int) -> unicode: ... + def info(self) -> Dict[str, str]: ... + def charset(self) -> Optional[str]: ... + def output_charset(self) -> Optional[str]: ... + def set_output_charset(self, charset: Optional[str]) -> None: ... + def install(self, unicode: bool = ..., names: Container[str] = ...) -> None: ... + +class GNUTranslations(NullTranslations): + LE_MAGIC = ... # type: int + BE_MAGIC = ... # type: int + +def find(domain: str, localedir: Optional[str] = ..., languages: Optional[Sequence[str]] = ..., + all: Any = ...) -> Optional[Union[str, List[str]]]: ... + +def translation(domain: str, localedir: Optional[str] = ..., languages: Optional[Sequence[str]] = ..., + class_: Optional[Type[NullTranslations]] = ..., fallback: bool = ..., codeset: Optional[str] = ...) -> NullTranslations: ... +def install(domain: str, localedir: Optional[str] = ..., unicode: bool = ..., codeset: Optional[str] = ..., + names: Container[str] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/glob.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/glob.pyi new file mode 100644 index 000000000..667a51f2f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/glob.pyi @@ -0,0 +1,6 @@ +from typing import List, Iterator, Union, AnyStr + +def glob(pathname: AnyStr) -> List[AnyStr]: ... +def iglob(pathname: AnyStr) -> Iterator[AnyStr]: ... +def glob1(dirname: Union[str, unicode], pattern: AnyStr) -> List[AnyStr]: ... +def glob0(dirname: Union[str, unicode], basename: AnyStr) -> List[AnyStr]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gzip.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gzip.pyi new file mode 100644 index 000000000..3177bbaf9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/gzip.pyi @@ -0,0 +1,37 @@ +from typing import Any, IO, Text +import io + +class GzipFile(io.BufferedIOBase): + myfileobj = ... # type: Any + max_read_chunk = ... # type: Any + mode = ... # type: Any + extrabuf = ... # type: Any + extrasize = ... # type: Any + extrastart = ... # type: Any + name = ... # type: Any + min_readsize = ... # type: Any + compress = ... # type: Any + fileobj = ... # type: Any + offset = ... # type: Any + mtime = ... # type: Any + def __init__(self, filename: str = ..., mode: Text = ..., compresslevel: int = ..., + fileobj: IO[str] = ..., mtime: float = ...) -> None: ... + @property + def filename(self): ... + size = ... # type: Any + crc = ... # type: Any + def write(self, data): ... + def read(self, size=...): ... + @property + def closed(self): ... + def close(self): ... + def flush(self, zlib_mode=...): ... + def fileno(self): ... + def rewind(self): ... + def readable(self): ... + def writable(self): ... + def seekable(self): ... + def seek(self, offset, whence=...): ... + def readline(self, size=...): ... + +def open(filename: str, mode: Text = ..., compresslevel: int = ...) -> GzipFile: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/hashlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/hashlib.pyi new file mode 100644 index 000000000..fa1dbce59 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/hashlib.pyi @@ -0,0 +1,31 @@ +# Stubs for hashlib (Python 2) + +from typing import Tuple, Union + +_DataType = Union[str, unicode, bytearray, buffer, memoryview] + +class _hash(object): # This is not actually in the module namespace. + name = ... # type: str + block_size = 0 + digest_size = 0 + digestsize = 0 + def __init__(self, arg: _DataType = ...) -> None: ... + def update(self, arg: _DataType) -> None: ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def copy(self) -> _hash: ... + +def new(name: str, data: str = ...) -> _hash: ... + +def md5(s: _DataType = ...) -> _hash: ... +def sha1(s: _DataType = ...) -> _hash: ... +def sha224(s: _DataType = ...) -> _hash: ... +def sha256(s: _DataType = ...) -> _hash: ... +def sha384(s: _DataType = ...) -> _hash: ... +def sha512(s: _DataType = ...) -> _hash: ... + +algorithms = ... # type: Tuple[str, ...] +algorithms_guaranteed = ... # type: Tuple[str, ...] +algorithms_available = ... # type: Tuple[str, ...] + +def pbkdf2_hmac(name: str, password: str, salt: str, rounds: int, dklen: int = ...) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/heapq.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/heapq.pyi new file mode 100644 index 000000000..00abb31a6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/heapq.pyi @@ -0,0 +1,16 @@ +from typing import TypeVar, List, Iterable, Any, Callable, Optional + +_T = TypeVar('_T') + +def cmp_lt(x, y) -> bool: ... +def heappush(heap: List[_T], item: _T) -> None: ... +def heappop(heap: List[_T]) -> _T: + raise IndexError() # if heap is empty +def heappushpop(heap: List[_T], item: _T) -> _T: ... +def heapify(x: List[_T]) -> None: ... +def heapreplace(heap: List[_T], item: _T) -> _T: + raise IndexError() # if heap is empty +def merge(*iterables: Iterable[_T]) -> Iterable[_T]: ... +def nlargest(n: int, iterable: Iterable[_T], + key: Optional[Callable[[_T], Any]] = ...) -> List[_T]: ... +def nsmallest(n: int, iterable: Iterable[_T]) -> List[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/htmlentitydefs.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/htmlentitydefs.pyi new file mode 100644 index 000000000..08445e6d9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/htmlentitydefs.pyi @@ -0,0 +1,5 @@ +from typing import Any, Mapping + +name2codepoint = ... # type: Mapping[str, int] +codepoint2name = ... # type: Mapping[int, str] +entitydefs = ... # type: Mapping[str, str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/httplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/httplib.pyi new file mode 100644 index 000000000..d8d5e5132 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/httplib.pyi @@ -0,0 +1,189 @@ +# Stubs for httplib (Python 2) +# +# Generated by stubgen and manually massaged a bit. +# Needs lots more work! + +from typing import Any, Dict +import mimetools + +class HTTPMessage(mimetools.Message): + def addheader(self, key: str, value: str) -> None: ... + def addcontinue(self, key: str, more: str) -> None: ... + dict = ... # type: Dict[str, str] + unixfrom = ... # type: str + headers = ... # type: Any + status = ... # type: str + seekable = ... # type: bool + def readheaders(self) -> None: ... + +class HTTPResponse: + fp = ... # type: Any + debuglevel = ... # type: Any + strict = ... # type: Any + msg = ... # type: Any + version = ... # type: Any + status = ... # type: Any + reason = ... # type: Any + chunked = ... # type: Any + chunk_left = ... # type: Any + length = ... # type: Any + will_close = ... # type: Any + def __init__(self, sock, debuglevel=0, strict=0, method=None, buffering: bool=...) -> None: ... + def begin(self): ... + def close(self): ... + def isclosed(self): ... + def read(self, amt=None): ... + def fileno(self): ... + def getheader(self, name, default=None): ... + def getheaders(self): ... + +class HTTPConnection: + response_class = ... # type: Any + default_port = ... # type: Any + auto_open = ... # type: Any + debuglevel = ... # type: Any + strict = ... # type: Any + timeout = ... # type: Any + source_address = ... # type: Any + sock = ... # type: Any + def __init__(self, host, port=None, strict=None, timeout=..., source_address=None) -> None: ... + def set_tunnel(self, host, port=None, headers=None): ... + def set_debuglevel(self, level): ... + def connect(self): ... + def close(self): ... + def send(self, data): ... + def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0): ... + def putheader(self, header, *values): ... + def endheaders(self, message_body=None): ... + def request(self, method, url, body=None, headers=...): ... + def getresponse(self, buffering: bool=...): ... + +class HTTP: + debuglevel = ... # type: Any + def __init__(self, host: str=..., port=None, strict=None) -> None: ... + def connect(self, host=None, port=None): ... + def getfile(self): ... + file = ... # type: Any + headers = ... # type: Any + def getreply(self, buffering: bool=...): ... + def close(self): ... + +class HTTPSConnection(HTTPConnection): + default_port = ... # type: Any + key_file = ... # type: Any + cert_file = ... # type: Any + def __init__(self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=..., source_address=None, context=None) -> None: ... + sock = ... # type: Any + def connect(self): ... + +class HTTPS(HTTP): + key_file = ... # type: Any + cert_file = ... # type: Any + def __init__(self, host: str=..., port=None, key_file=None, cert_file=None, strict=None, context=None) -> None: ... + +class HTTPException(Exception): ... +class NotConnected(HTTPException): ... +class InvalidURL(HTTPException): ... + +class UnknownProtocol(HTTPException): + args = ... # type: Any + version = ... # type: Any + def __init__(self, version) -> None: ... + +class UnknownTransferEncoding(HTTPException): ... +class UnimplementedFileMode(HTTPException): ... + +class IncompleteRead(HTTPException): + args = ... # type: Any + partial = ... # type: Any + expected = ... # type: Any + def __init__(self, partial, expected=None) -> None: ... + +class ImproperConnectionState(HTTPException): ... +class CannotSendRequest(ImproperConnectionState): ... +class CannotSendHeader(ImproperConnectionState): ... +class ResponseNotReady(ImproperConnectionState): ... + +class BadStatusLine(HTTPException): + args = ... # type: Any + line = ... # type: Any + def __init__(self, line) -> None: ... + +class LineTooLong(HTTPException): + def __init__(self, line_type) -> None: ... + +error = ... # type: Any + +class LineAndFileWrapper: + def __init__(self, line, file) -> None: ... + def __getattr__(self, attr): ... + def read(self, amt=None): ... + def readline(self): ... + def readlines(self, size=None): ... + +# Constants + +responses = ... # type: Dict[int, str] + +HTTP_PORT = ... # type: int +HTTPS_PORT = ... # type: int + +# status codes +# informational +CONTINUE = ... # type: int +SWITCHING_PROTOCOLS = ... # type: int +PROCESSING = ... # type: int + +# successful +OK = ... # type: int +CREATED = ... # type: int +ACCEPTED = ... # type: int +NON_AUTHORITATIVE_INFORMATION = ... # type: int +NO_CONTENT = ... # type: int +RESET_CONTENT = ... # type: int +PARTIAL_CONTENT = ... # type: int +MULTI_STATUS = ... # type: int +IM_USED = ... # type: int + +# redirection +MULTIPLE_CHOICES = ... # type: int +MOVED_PERMANENTLY = ... # type: int +FOUND = ... # type: int +SEE_OTHER = ... # type: int +NOT_MODIFIED = ... # type: int +USE_PROXY = ... # type: int +TEMPORARY_REDIRECT = ... # type: int + +# client error +BAD_REQUEST = ... # type: int +UNAUTHORIZED = ... # type: int +PAYMENT_REQUIRED = ... # type: int +FORBIDDEN = ... # type: int +NOT_FOUND = ... # type: int +METHOD_NOT_ALLOWED = ... # type: int +NOT_ACCEPTABLE = ... # type: int +PROXY_AUTHENTICATION_REQUIRED = ... # type: int +REQUEST_TIMEOUT = ... # type: int +CONFLICT = ... # type: int +GONE = ... # type: int +LENGTH_REQUIRED = ... # type: int +PRECONDITION_FAILED = ... # type: int +REQUEST_ENTITY_TOO_LARGE = ... # type: int +REQUEST_URI_TOO_LONG = ... # type: int +UNSUPPORTED_MEDIA_TYPE = ... # type: int +REQUESTED_RANGE_NOT_SATISFIABLE = ... # type: int +EXPECTATION_FAILED = ... # type: int +UNPROCESSABLE_ENTITY = ... # type: int +LOCKED = ... # type: int +FAILED_DEPENDENCY = ... # type: int +UPGRADE_REQUIRED = ... # type: int + +# server error +INTERNAL_SERVER_ERROR = ... # type: int +NOT_IMPLEMENTED = ... # type: int +BAD_GATEWAY = ... # type: int +SERVICE_UNAVAILABLE = ... # type: int +GATEWAY_TIMEOUT = ... # type: int +HTTP_VERSION_NOT_SUPPORTED = ... # type: int +INSUFFICIENT_STORAGE = ... # type: int +NOT_EXTENDED = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/imp.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/imp.pyi new file mode 100644 index 000000000..ffb1ad367 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/imp.pyi @@ -0,0 +1,35 @@ +"""Stubs for the 'imp' module.""" + +from typing import List, Optional, Tuple, Iterable, IO, Any +import types + +C_BUILTIN = ... # type: int +C_EXTENSION = ... # type: int +IMP_HOOK = ... # type: int +PKG_DIRECTORY = ... # type: int +PY_CODERESOURCE = ... # type: int +PY_COMPILED = ... # type: int +PY_FROZEN = ... # type: int +PY_RESOURCE = ... # type: int +PY_SOURCE = ... # type: int +SEARCH_ERROR = ... # type: int + +def acquire_lock() -> None: ... +def find_module(name: str, path: Iterable[str] = ...) -> Optional[Tuple[str, str, Tuple[str, str, int]]]: ... +def get_magic() -> str: ... +def get_suffixes() -> List[Tuple[str, str, int]]: ... +def init_builtin(name: str) -> types.ModuleType: ... +def init_frozen(name: str) -> types.ModuleType: ... +def is_builtin(name: str) -> int: ... +def is_frozen(name: str) -> bool: ... +def load_compiled(name: str, pathname: str, file: IO[Any] = ...) -> types.ModuleType: ... +def load_dynamic(name: str, pathname: str, file: IO[Any] = ...) -> types.ModuleType: ... +def load_module(name: str, file: str, pathname: str, description: Tuple[str, str, int]) -> types.ModuleType: ... +def load_source(name: str, pathname: str, file: IO[Any] = ...) -> types.ModuleType: ... +def lock_held() -> bool: ... +def new_module(name: str) -> types.ModuleType: ... +def release_lock() -> None: ... + +class NullImporter: + def __init__(self, path_string: str) -> None: ... + def find_module(self, fullname: str, path: str = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/importlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/importlib.pyi new file mode 100644 index 000000000..8bb179a4b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/importlib.pyi @@ -0,0 +1,4 @@ +import types +from typing import Optional, Text + +def import_module(name: Text, package: Optional[Text] = ...) -> types.ModuleType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/inspect.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/inspect.pyi new file mode 100644 index 000000000..2887a1a4d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/inspect.pyi @@ -0,0 +1,135 @@ +from types import CodeType, TracebackType, FrameType, ModuleType +from typing import Any, Dict, Callable, List, NamedTuple, Optional, Sequence, Tuple, Type, Union + +# Types and members +class EndOfBlock(Exception): ... + +class BlockFinder: + indent: int + islambda: bool + started: bool + passline: bool + last: int + def tokeneater(self, type: int, token: str, srow_scol: Tuple[int, int], + erow_ecol: Tuple[int, int], line: str) -> None: ... + +CO_GENERATOR = ... # type: int +CO_NESTED = ... # type: int +CO_NEWLOCALS = ... # type: int +CO_NOFREE = ... # type: int +CO_OPTIMIZED = ... # type: int +CO_VARARGS = ... # type: int +CO_VARKEYWORDS = ... # type: int +TPFLAGS_IS_ABSTRACT = ... # type: int + +ModuleInfo = NamedTuple('ModuleInfo', [('name', str), + ('suffix', str), + ('mode', str), + ('module_type', int), + ]) +def getmembers( + object: object, + predicate: Optional[Callable[[Any], bool]] = ... +) -> List[Tuple[str, Any]]: ... +def getmoduleinfo(path: str) -> Optional[ModuleInfo]: ... +def getmodulename(path: str) -> Optional[str]: ... + +def ismodule(object: object) -> bool: ... +def isclass(object: object) -> bool: ... +def ismethod(object: object) -> bool: ... +def isfunction(object: object) -> bool: ... +def isgeneratorfunction(object: object) -> bool: ... +def isgenerator(object: object) -> bool: ... +def istraceback(object: object) -> bool: ... +def isframe(object: object) -> bool: ... +def iscode(object: object) -> bool: ... +def isbuiltin(object: object) -> bool: ... +def isroutine(object: object) -> bool: ... +def isabstract(object: object) -> bool: ... +def ismethoddescriptor(object: object) -> bool: ... +def isdatadescriptor(object: object) -> bool: ... +def isgetsetdescriptor(object: object) -> bool: ... +def ismemberdescriptor(object: object) -> bool: ... + +# Retrieving source code +def findsource(object: object) -> Tuple[List[str], int]: ... +def getabsfile(object: object) -> str: ... +def getblock(lines: Sequence[str]) -> Sequence[str]: ... +def getdoc(object: object) -> str: ... +def getcomments(object: object) -> str: ... +def getfile(object: object) -> str: ... +def getmodule(object: object) -> ModuleType: ... +def getsourcefile(object: object) -> str: ... +# TODO restrict to "module, class, method, function, traceback, frame, +# or code object" +def getsourcelines(object: object) -> Tuple[List[str], int]: ... +# TODO restrict to "a module, class, method, function, traceback, frame, +# or code object" +def getsource(object: object) -> str: ... +def cleandoc(doc: str) -> str: ... +def indentsize(line: str) -> int: ... + +# Classes and functions +def getclasstree(classes: List[type], unique: bool = ...) -> List[ + Union[Tuple[type, Tuple[type, ...]], list]]: ... + +ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), + ('varargs', Optional[str]), + ('keywords', Optional[str]), + ('defaults', tuple), + ]) + +ArgInfo = NamedTuple('ArgInfo', [('args', List[str]), + ('varargs', Optional[str]), + ('keywords', Optional[str]), + ('locals', Dict[str, Any]), + ]) + +Arguments = NamedTuple('Arguments', [('args', List[Union[str, List[Any]]]), + ('varargs', Optional[str]), + ('keywords', Optional[str]), + ]) + +def getargs(co: CodeType) -> Arguments: ... +def getargspec(func: object) -> ArgSpec: ... +def getargvalues(frame: FrameType) -> ArgInfo: ... +def formatargspec(args, varargs=..., varkw=..., defaults=..., + formatarg=..., formatvarargs=..., formatvarkw=..., formatvalue=..., + join=...) -> str: ... +def formatargvalues(args, varargs=..., varkw=..., defaults=..., + formatarg=..., formatvarargs=..., formatvarkw=..., formatvalue=..., + join=...) -> str: ... +def getmro(cls: type) -> Tuple[type, ...]: ... +def getcallargs(func, *args, **kwds) -> Dict[str, Any]: ... + +# The interpreter stack + +Traceback = NamedTuple( + 'Traceback', + [ + ('filename', str), + ('lineno', int), + ('function', str), + ('code_context', List[str]), + ('index', int), + ] +) + +_FrameInfo = Tuple[FrameType, str, int, str, List[str], int] + +def getouterframes(frame: FrameType, context: int = ...) -> List[_FrameInfo]: ... +def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ... +def getinnerframes(traceback: TracebackType, context: int = ...) -> List[_FrameInfo]: ... +def getlineno(frame: FrameType) -> int: ... + +def currentframe(depth: int = ...) -> FrameType: ... +def stack(context: int = ...) -> List[_FrameInfo]: ... +def trace(context: int = ...) -> List[_FrameInfo]: ... + +Attribute = NamedTuple('Attribute', [('name', str), + ('kind', str), + ('defining_class', type), + ('object', object), + ]) + +def classify_class_attrs(cls: type) -> List[Attribute]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/io.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/io.pyi new file mode 100644 index 000000000..07f247186 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/io.pyi @@ -0,0 +1,42 @@ +# Stubs for io + +# Based on https://docs.python.org/2/library/io.html + +# Only a subset of functionality is included. + +from typing import List, BinaryIO, TextIO, IO, overload, Iterator, Iterable, Any, Union, Optional +import _io + +from _io import BlockingIOError as BlockingIOError +from _io import BufferedRWPair as BufferedRWPair +from _io import BufferedRandom as BufferedRandom +from _io import BufferedReader as BufferedReader +from _io import BufferedWriter as BufferedWriter +from _io import BytesIO as BytesIO +from _io import DEFAULT_BUFFER_SIZE as DEFAULT_BUFFER_SIZE +from _io import FileIO as FileIO +from _io import IncrementalNewlineDecoder as IncrementalNewlineDecoder +from _io import StringIO as StringIO +from _io import TextIOWrapper as TextIOWrapper +from _io import UnsupportedOperation as UnsupportedOperation +from _io import open as open + +def _OpenWrapper(file: Union[str, unicode, int], + mode: unicode = ..., buffering: int = ..., encoding: unicode = ..., + errors: unicode = ..., newline: unicode = ..., + closefd: bool = ...) -> IO[Any]: ... + +SEEK_SET = ... # type: int +SEEK_CUR = ... # type: int +SEEK_END = ... # type: int + + +class IOBase(_io._IOBase): ... + +class RawIOBase(_io._RawIOBase, IOBase): ... + +class BufferedIOBase(_io._BufferedIOBase, IOBase): ... + +# Note: In the actual io.py, TextIOBase subclasses IOBase. +# (Which we don't do here because we don't want to subclass both TextIO and BinaryIO.) +class TextIOBase(_io._TextIOBase): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/itertools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/itertools.pyi new file mode 100644 index 000000000..5dbfc343a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/itertools.pyi @@ -0,0 +1,166 @@ +# Stubs for itertools + +# Based on https://docs.python.org/2/library/itertools.html + +from typing import (Iterator, TypeVar, Iterable, overload, Any, Callable, Tuple, + Union, Sequence, Generic, Optional) + +_T = TypeVar('_T') +_S = TypeVar('_S') + +def count(start: int = ..., + step: int = ...) -> Iterator[int]: ... # more general types? +def cycle(iterable: Iterable[_T]) -> Iterator[_T]: ... + +def repeat(object: _T, times: int = ...) -> Iterator[_T]: ... + +def accumulate(iterable: Iterable[_T]) -> Iterator[_T]: ... + +class chain(Iterator[_T], Generic[_T]): + def __init__(self, *iterables: Iterable[_T]) -> None: ... + def next(self) -> _T: ... + def __iter__(self) -> Iterator[_T]: ... + @staticmethod + def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ... + +def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ... +def dropwhile(predicate: Callable[[_T], Any], + iterable: Iterable[_T]) -> Iterator[_T]: ... +def ifilter(predicate: Optional[Callable[[_T], Any]], + iterable: Iterable[_T]) -> Iterator[_T]: ... +def ifilterfalse(predicate: Optional[Callable[[_T], Any]], + iterable: Iterable[_T]) -> Iterator[_T]: ... + +@overload +def groupby(iterable: Iterable[_T]) -> Iterator[Tuple[_T, Iterator[_T]]]: ... +@overload +def groupby(iterable: Iterable[_T], + key: Callable[[_T], _S]) -> Iterator[Tuple[_S, Iterator[_T]]]: ... + +@overload +def islice(iterable: Iterable[_T], stop: Optional[int]) -> Iterator[_T]: ... +@overload +def islice(iterable: Iterable[_T], start: Optional[int], stop: Optional[int], + step: Optional[int] = ...) -> Iterator[_T]: ... + +_T1 = TypeVar('_T1') +_T2 = TypeVar('_T2') +_T3 = TypeVar('_T3') +_T4 = TypeVar('_T4') +_T5 = TypeVar('_T5') +_T6 = TypeVar('_T6') + +@overload +def imap(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... +@overload +def imap(func: Callable[[_T1, _T2], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[_S]: ... +@overload +def imap(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[_S]: ... + +@overload +def imap(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[_S]: ... + +@overload +def imap(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[_S]: ... + +@overload +def imap(func: Callable[[_T1, _T2, _T3, _T4, _T5, _T6], _S], + iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5], + iter6: Iterable[_T6]) -> Iterator[_S]: ... + +@overload +def imap(func: Callable[..., _S], + iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + iter7: Iterable[Any], *iterables: Iterable[Any]) -> Iterator[_S]: ... + +def starmap(func: Any, iterable: Iterable[Any]) -> Iterator[Any]: ... +def takewhile(predicate: Callable[[_T], Any], + iterable: Iterable[_T]) -> Iterator[_T]: ... +def tee(iterable: Iterable[_T], n: int = ...) -> Tuple[Iterator[_T], ...]: ... + +@overload +def izip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... +@overload +def izip(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... +@overload +def izip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... +@overload +def izip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4]]: ... +@overload +def izip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3], iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... +@overload +def izip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3], iter4: Iterable[_T4], + iter5: Iterable[_T5], iter6: Iterable[_T6]) -> Iterator[Tuple[_T1, _T2, _T3, + _T4, _T5, _T6]]: ... +@overload +def izip(iter1: Iterable[Any], iter2: Iterable[Any], + iter3: Iterable[Any], iter4: Iterable[Any], + iter5: Iterable[Any], iter6: Iterable[Any], + iter7: Iterable[Any], *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... + +def izip_longest(*p: Iterable[Any], + fillvalue: Any = ...) -> Iterator[Any]: ... + +@overload +def product(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, _T3, _T4]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5], + iter6: Iterable[_T6]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ... +@overload +def product(iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + iter7: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +@overload +def product(*iterables: Iterable[Any], repeat: int) -> Iterator[Tuple[Any, ...]]: ... + +def permutations(iterable: Iterable[_T], + r: int = ...) -> Iterator[Sequence[_T]]: ... +def combinations(iterable: Iterable[_T], + r: int) -> Iterator[Sequence[_T]]: ... +def combinations_with_replacement(iterable: Iterable[_T], + r: int) -> Iterator[Sequence[_T]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/json.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/json.pyi new file mode 100644 index 000000000..44a206782 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/json.pyi @@ -0,0 +1,97 @@ +from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Text + +class JSONDecodeError(ValueError): + def dumps(self, obj: Any) -> str: ... + def dump(self, obj: Any, fp: IO[str], *args: Any, **kwds: Any) -> None: ... + def loads(self, s: str) -> Any: ... + def load(self, fp: IO[str]) -> Any: ... + +def dumps(obj: Any, + skipkeys: bool = ..., + ensure_ascii: bool = ..., + check_circular: bool = ..., + allow_nan: bool = ..., + cls: Any = ..., + indent: Optional[int] = ..., + separators: Optional[Tuple[str, str]] = ..., + encoding: str = ..., + default: Optional[Callable[[Any], Any]] = ..., + sort_keys: bool = ..., + **kwds: Any) -> str: ... + +def dump(obj: Any, + fp: IO[str], + skipkeys: bool = ..., + ensure_ascii: bool = ..., + check_circular: bool = ..., + allow_nan: bool = ..., + cls: Any = ..., + indent: Optional[int] = ..., + separators: Optional[Tuple[str, str]] = ..., + encoding: str = ..., + default: Optional[Callable[[Any], Any]] = ..., + sort_keys: bool = ..., + **kwds: Any) -> None: ... + +def loads(s: Union[Text, bytes], + encoding: Any = ..., + cls: Any = ..., + object_hook: Optional[Callable[[Dict], Any]] = ..., + parse_float: Optional[Callable[[str], Any]] = ..., + parse_int: Optional[Callable[[str], Any]] = ..., + parse_constant: Optional[Callable[[str], Any]] = ..., + object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., + **kwds: Any) -> Any: ... + +def load(fp: IO[str], + encoding: Optional[str] = ..., + cls: Any = ..., + object_hook: Optional[Callable[[Dict], Any]] = ..., + parse_float: Optional[Callable[[str], Any]] = ..., + parse_int: Optional[Callable[[str], Any]] = ..., + parse_constant: Optional[Callable[[str], Any]] = ..., + object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., + **kwds: Any) -> Any: ... + +class JSONDecoder(object): + def __init__(self, + encoding: Union[Text, bytes] = ..., + object_hook: Callable[..., Any] = ..., + parse_float: Callable[[str], float] = ..., + parse_int: Callable[[str], int] = ..., + parse_constant: Callable[[str], Any] = ..., + strict: bool = ..., + object_pairs_hook: Callable[..., Any] = ...) -> None: ... + + def decode(self, s: Union[Text, bytes], _w: Any = ...) -> Any: ... + + def raw_decode(self, + s: Union[Text, bytes], + idx: int = ...) -> Tuple[Any, Any]: ... + +class JSONEncoder(object): + item_separator = ... # type: str + key_separator = ... # type: str + skipkeys = ... # type: bool + ensure_ascii = ... # type: bool + check_circular = ... # type: bool + allow_nan = ... # type: bool + sort_keys = ... # type: bool + indent = ... # type: int + + def __init__(self, + skipkeys: bool = ..., + ensure_ascii: bool = ..., + check_circular: bool = ..., + allow_nan: bool = ..., + sort_keys: bool = ..., + indent: int = ..., + separators: Tuple[Union[Text, bytes], Union[Text, bytes]] = ..., + encoding: Union[Text, bytes] = ..., + default: Callable[..., Any] = ...) -> None: ... + + def default(self, o: Any) -> Any: ... + + def encode(self, o: Any) -> str: ... + + def iterencode(self, o: Any, _one_shot: bool = ...) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/macpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/macpath.pyi new file mode 100644 index 000000000..fc5c173ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/macpath.pyi @@ -0,0 +1,37 @@ +# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +from typing import Any +from genericpath import * # noqa: F403 + +curdir = ... # type: Any +pardir = ... # type: Any +extsep = ... # type: Any +sep = ... # type: Any +pathsep = ... # type: Any +defpath = ... # type: Any +altsep = ... # type: Any +devnull = ... # type: Any + +def normcase(s): ... +def isabs(s): ... +def join(a, *p): ... +def split(p): ... +def splitext(p): ... +def splitdrive(p): ... +def basename(p): ... +def dirname(p): ... +def islink(path): ... +def lexists(path): ... +def samefile(f1, f2): ... +def sameopenfile(fp1, fp2): ... +def samestat(s1, s2): ... +def ismount(path): ... +def walk(top, func, arg): ... +def expanduser(path): ... +def expandvars(path): ... +def normpath(path): ... +def abspath(path): ... +def realpath(filename): ... + +supports_unicode_filenames = ... # type: Any + +def relpath(path, start=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/markupbase.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/markupbase.pyi new file mode 100644 index 000000000..129b49b90 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/markupbase.pyi @@ -0,0 +1,9 @@ +from typing import Tuple + +class ParserBase(object): + def __init__(self) -> None: ... + def error(self, message: str) -> None: ... + def reset(self) -> None: ... + def getpos(self) -> Tuple[int, int]: ... + + def unkown_decl(self, data: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/md5.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/md5.pyi new file mode 100644 index 000000000..fe6ad719d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/md5.pyi @@ -0,0 +1,6 @@ +# Stubs for Python 2.7 md5 stdlib module + +from hashlib import md5 as md5, md5 as new + +blocksize = 0 +digest_size = 0 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/mimetools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/mimetools.pyi new file mode 100644 index 000000000..a2651318c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/mimetools.pyi @@ -0,0 +1,27 @@ +from typing import Any +import rfc822 + +class Message(rfc822.Message): + encodingheader = ... # type: Any + typeheader = ... # type: Any + def __init__(self, fp, seekable=1): ... + plisttext = ... # type: Any + type = ... # type: Any + maintype = ... # type: Any + subtype = ... # type: Any + def parsetype(self): ... + plist = ... # type: Any + def parseplist(self): ... + def getplist(self): ... + def getparam(self, name): ... + def getparamnames(self): ... + def getencoding(self): ... + def gettype(self): ... + def getmaintype(self): ... + def getsubtype(self): ... + +def choose_boundary(): ... +def decode(input, output, encoding): ... +def encode(input, output, encoding): ... +def copyliteral(input, output): ... +def copybinary(input, output): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/__init__.pyi new file mode 100644 index 000000000..d5c93250f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/__init__.pyi @@ -0,0 +1,50 @@ +from typing import Any, Callable, Optional, TypeVar, Iterable + +from multiprocessing import pool +from multiprocessing.process import Process as Process, current_process as current_process, active_children as active_children +from multiprocessing.util import SUBDEBUG as SUBDEBUG, SUBWARNING as SUBWARNING +from Queue import Queue as _BaseQueue + +class ProcessError(Exception): ... +class BufferTooShort(ProcessError): ... +class TimeoutError(ProcessError): ... +class AuthenticationError(ProcessError): ... + +_T = TypeVar('_T') + +class Queue(_BaseQueue[_T]): + def __init__(self, maxsize: int = ...) -> None: ... + def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... + def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... + def qsize(self) -> int: ... + def empty(self) -> bool: ... + def full(self) -> bool: ... + def put_nowait(self, item: _T) -> None: ... + def get_nowait(self) -> _T: ... + def close(self) -> None: ... + def join_thread(self) -> None: ... + def cancel_join_thread(self) -> None: ... + +def Manager(): ... +def Pipe(duplex=True): ... +def cpu_count() -> int: ... +def freeze_support(): ... +def get_logger(): ... +def log_to_stderr(level=None): ... +def allow_connection_pickling(): ... +def Lock(): ... +def RLock(): ... +def Condition(lock=None): ... +def Semaphore(value=1): ... +def BoundedSemaphore(value=1): ... +def Event(): ... +def JoinableQueue(maxsize=0): ... +def RawValue(typecode_or_type, *args): ... +def RawArray(typecode_or_type, size_or_initializer): ... +def Value(typecode_or_type, *args, **kwds): ... +def Array(typecode_or_type, size_or_initializer, **kwds): ... + +def Pool(processes: Optional[int] = ..., + initializer: Optional[Callable[..., Any]] = ..., + initargs: Iterable[Any] = ..., + maxtasksperchild: Optional[int] = ...) -> pool.Pool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/dummy/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/dummy/__init__.pyi new file mode 100644 index 000000000..aee95b3fc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/dummy/__init__.pyi @@ -0,0 +1,51 @@ +from typing import Any, Optional, List, Type + +import threading +import sys +import weakref +import array +import itertools + +from multiprocessing import TimeoutError, cpu_count +from multiprocessing.dummy.connection import Pipe +from threading import Lock, RLock, Semaphore, BoundedSemaphore +from threading import Event +from Queue import Queue + + +class DummyProcess(threading.Thread): + _children = ... # type: weakref.WeakKeyDictionary + _parent = ... # type: threading.Thread + _pid = ... # type: None + _start_called = ... # type: bool + def __init__(self, group=..., target=..., name=..., args=..., kwargs=...) -> None: ... + @property + def exitcode(self) -> Optional[int]: ... + + +Process = DummyProcess + +# This should be threading._Condition but threading.pyi exports it as Condition +class Condition(threading.Condition): + notify_all = ... # type: Any + +class Namespace(object): + def __init__(self, **kwds) -> None: ... + +class Value(object): + _typecode = ... # type: Any + _value = ... # type: Any + value = ... # type: Any + def __init__(self, typecode, value, lock=...) -> None: ... + def _get(self) -> Any: ... + def _set(self, value) -> None: ... + +JoinableQueue = Queue + +def Array(typecode, sequence, lock=...) -> array.array: ... +def Manager() -> Any: ... +def Pool(processes=..., initializer=..., initargs=...) -> Any: ... +def active_children() -> List: ... +def current_process() -> threading.Thread: ... +def freeze_support() -> None: ... +def shutdown() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/dummy/connection.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/dummy/connection.pyi new file mode 100644 index 000000000..2db5bea3d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/dummy/connection.pyi @@ -0,0 +1,26 @@ +from Queue import Queue +from typing import Any, List, Optional, Tuple, Type + +families = ... # type: List[None] + +class Connection(object): + _in = ... # type: Any + _out = ... # type: Any + recv = ... # type: Any + recv_bytes = ... # type: Any + send = ... # type: Any + send_bytes = ... # type: Any + def __init__(self, _in, _out) -> None: ... + def close(self) -> None: ... + def poll(self, timeout=...) -> Any: ... + +class Listener(object): + _backlog_queue = ... # type: Optional[Queue] + address = ... # type: Any + def __init__(self, address=..., family=..., backlog=...) -> None: ... + def accept(self) -> Connection: ... + def close(self) -> None: ... + + +def Client(address) -> Connection: ... +def Pipe(duplex=...) -> Tuple[Connection, Connection]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/pool.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/pool.pyi new file mode 100644 index 000000000..ac8ec4216 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/pool.pyi @@ -0,0 +1,57 @@ +from typing import ( + Any, Callable, ContextManager, Iterable, Optional, Dict, List, + TypeVar, Iterator, +) + +_T = TypeVar('_T', bound=Pool) + +class AsyncResult(): + def get(self, timeout: Optional[float] = ...) -> Any: ... + def wait(self, timeout: Optional[float] = ...) -> None: ... + def ready(self) -> bool: ... + def successful(self) -> bool: ... + +class IMapIterator(Iterable[Any]): + def __iter__(self) -> Iterator[Any]: ... + def next(self, timeout: Optional[float] = ...) -> Any: ... + +class Pool(ContextManager[Pool]): + def __init__(self, processes: Optional[int] = ..., + initializer: Optional[Callable[..., None]] = ..., + initargs: Iterable[Any] = ..., + maxtasksperchild: Optional[int] = ...) -> None: ... + def apply(self, + func: Callable[..., Any], + args: Iterable[Any] = ..., + kwds: Dict[str, Any] = ...) -> Any: ... + def apply_async(self, + func: Callable[..., Any], + args: Iterable[Any] = ..., + kwds: Dict[str, Any] = ..., + callback: Optional[Callable[..., None]] = ...) -> AsyncResult: ... + def map(self, + func: Callable[..., Any], + iterable: Iterable[Any] = ..., + chunksize: Optional[int] = ...) -> List[Any]: ... + def map_async(self, func: Callable[..., Any], + iterable: Iterable[Any] = ..., + chunksize: Optional[int] = ..., + callback: Optional[Callable[..., None]] = ...) -> AsyncResult: ... + def imap(self, + func: Callable[..., Any], + iterable: Iterable[Any] = ..., + chunksize: Optional[int] = ...) -> IMapIterator: ... + def imap_unordered(self, + func: Callable[..., Any], + iterable: Iterable[Any] = ..., + chunksize: Optional[int] = ...) -> IMapIterator: ... + def close(self) -> None: ... + def terminate(self) -> None: ... + def join(self) -> None: ... + def __enter__(self: _T) -> _T: ... + +class ThreadPool(Pool, ContextManager[ThreadPool]): + + def __init__(self, processes: Optional[int] = ..., + initializer: Optional[Callable[..., Any]] = ..., + initargs: Iterable[Any] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/process.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/process.pyi new file mode 100644 index 000000000..c4a84a421 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/process.pyi @@ -0,0 +1,35 @@ +from typing import Any + +def current_process(): ... +def active_children(): ... + +class Process: + def __init__(self, group=None, target=None, name=None, args=..., kwargs=...): ... + def run(self): ... + def start(self): ... + def terminate(self): ... + def join(self, timeout=None): ... + def is_alive(self): ... + @property + def name(self): ... + @name.setter + def name(self, name): ... + @property + def daemon(self): ... + @daemon.setter + def daemon(self, daemonic): ... + @property + def authkey(self): ... + @authkey.setter + def authkey(self, authkey): ... + @property + def exitcode(self): ... + @property + def ident(self): ... + pid = ... # type: Any + +class AuthenticationString(bytes): + def __reduce__(self): ... + +class _MainProcess(Process): + def __init__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/util.pyi new file mode 100644 index 000000000..7d116273d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/multiprocessing/util.pyi @@ -0,0 +1,29 @@ +from typing import Any +import threading + +SUBDEBUG = ... # type: Any +SUBWARNING = ... # type: Any + +def sub_debug(msg, *args): ... +def debug(msg, *args): ... +def info(msg, *args): ... +def sub_warning(msg, *args): ... +def get_logger(): ... +def log_to_stderr(level=None): ... +def get_temp_dir(): ... +def register_after_fork(obj, func): ... + +class Finalize: + def __init__(self, obj, callback, args=..., kwargs=None, exitpriority=None): ... + def __call__(self, wr=None): ... + def cancel(self): ... + def still_active(self): ... + +def is_exiting(): ... + +class ForkAwareThreadLock: + def __init__(self): ... + +class ForkAwareLocal(threading.local): + def __init__(self): ... + def __reduce__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/mutex.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/mutex.pyi new file mode 100644 index 000000000..df1e71cc1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/mutex.pyi @@ -0,0 +1,15 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/mutex.py + +from collections import deque +from typing import Any, Callable, TypeVar + +_ArgType = TypeVar('_ArgType') + +class mutex: + locked = ... # type: bool + queue = ... # type: deque + def __init__(self) -> None: ... + def test(self) -> bool: ... + def testandset(self) -> bool: ... + def lock(self, function: Callable[[_ArgType], Any], argument: _ArgType) -> None: ... + def unlock(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ntpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ntpath.pyi new file mode 100644 index 000000000..fc5c173ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/ntpath.pyi @@ -0,0 +1,37 @@ +# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +from typing import Any +from genericpath import * # noqa: F403 + +curdir = ... # type: Any +pardir = ... # type: Any +extsep = ... # type: Any +sep = ... # type: Any +pathsep = ... # type: Any +defpath = ... # type: Any +altsep = ... # type: Any +devnull = ... # type: Any + +def normcase(s): ... +def isabs(s): ... +def join(a, *p): ... +def split(p): ... +def splitext(p): ... +def splitdrive(p): ... +def basename(p): ... +def dirname(p): ... +def islink(path): ... +def lexists(path): ... +def samefile(f1, f2): ... +def sameopenfile(fp1, fp2): ... +def samestat(s1, s2): ... +def ismount(path): ... +def walk(top, func, arg): ... +def expanduser(path): ... +def expandvars(path): ... +def normpath(path): ... +def abspath(path): ... +def realpath(filename): ... + +supports_unicode_filenames = ... # type: Any + +def relpath(path, start=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/nturl2path.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/nturl2path.pyi new file mode 100644 index 000000000..b87b008e4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/nturl2path.pyi @@ -0,0 +1,4 @@ +from typing import AnyStr + +def url2pathname(url: AnyStr) -> AnyStr: ... +def pathname2url(p: AnyStr) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os/__init__.pyi new file mode 100644 index 000000000..43e1cf23e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os/__init__.pyi @@ -0,0 +1,350 @@ +# Stubs for os +# Ron Murawski + +from builtins import OSError as error +from io import TextIOWrapper as _TextIOWrapper +from posix import stat_result as stat_result # TODO: use this, see https://github.com/python/mypy/issues/3078 +import sys +from typing import ( + Mapping, MutableMapping, Dict, List, Any, Tuple, Iterator, overload, Union, AnyStr, + Optional, Generic, Set, Callable, Text, Sequence, IO, NamedTuple, NoReturn, TypeVar +) +from . import path as path + +_T = TypeVar('_T') + +# ----- os variables ----- + +if sys.version_info >= (3, 2): + supports_bytes_environ: bool + +if sys.version_info >= (3, 3): + supports_dir_fd: Set[Callable[..., Any]] + supports_fd: Set[Callable[..., Any]] + supports_effective_ids: Set[Callable[..., Any]] + supports_follow_symlinks: Set[Callable[..., Any]] + +SEEK_SET: int +SEEK_CUR: int +SEEK_END: int + +O_RDONLY: int +O_WRONLY: int +O_RDWR: int +O_APPEND: int +O_CREAT: int +O_EXCL: int +O_TRUNC: int +O_DSYNC: int # Unix only +O_RSYNC: int # Unix only +O_SYNC: int # Unix only +O_NDELAY: int # Unix only +O_NONBLOCK: int # Unix only +O_NOCTTY: int # Unix only +O_SHLOCK: int # Unix only +O_EXLOCK: int # Unix only +O_BINARY: int # Windows only +O_NOINHERIT: int # Windows only +O_SHORT_LIVED: int # Windows only +O_TEMPORARY: int # Windows only +O_RANDOM: int # Windows only +O_SEQUENTIAL: int # Windows only +O_TEXT: int # Windows only +O_ASYNC: int # Gnu extension if in C library +O_DIRECT: int # Gnu extension if in C library +O_DIRECTORY: int # Gnu extension if in C library +O_NOFOLLOW: int # Gnu extension if in C library +O_NOATIME: int # Gnu extension if in C library +O_LARGEFILE: int # Gnu extension if in C library + +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +linesep: str +devnull: str +name: str + +F_OK: int +R_OK: int +W_OK: int +X_OK: int + +class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): + def copy(self) -> Dict[AnyStr, AnyStr]: ... + def __delitem__(self, key: AnyStr) -> None: ... + def __getitem__(self, key: AnyStr) -> AnyStr: ... + def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ... + def __iter__(self) -> Iterator[AnyStr]: ... + def __len__(self) -> int: ... + +environ: _Environ[str] +if sys.version_info >= (3, 2): + environb: _Environ[bytes] + +confstr_names: Dict[str, int] # Unix only +pathconf_names: Dict[str, int] # Unix only +sysconf_names: Dict[str, int] # Unix only + +EX_OK: int # Unix only +EX_USAGE: int # Unix only +EX_DATAERR: int # Unix only +EX_NOINPUT: int # Unix only +EX_NOUSER: int # Unix only +EX_NOHOST: int # Unix only +EX_UNAVAILABLE: int # Unix only +EX_SOFTWARE: int # Unix only +EX_OSERR: int # Unix only +EX_OSFILE: int # Unix only +EX_CANTCREAT: int # Unix only +EX_IOERR: int # Unix only +EX_TEMPFAIL: int # Unix only +EX_PROTOCOL: int # Unix only +EX_NOPERM: int # Unix only +EX_CONFIG: int # Unix only +EX_NOTFOUND: int # Unix only + +P_NOWAIT: int +P_NOWAITO: int +P_WAIT: int +if sys.platform == 'win32': + P_DETACH: int # Windows only + P_OVERLAY: int # Windows only + +# wait()/waitpid() options +WNOHANG: int # Unix only +WCONTINUED: int # some Unix systems +WUNTRACED: int # Unix only + +TMP_MAX: int # Undocumented, but used by tempfile + +# ----- os classes (structures) ----- +if sys.version_info >= (3, 6): + from builtins import _PathLike as PathLike # See comment in builtins + +_PathType = path._PathType + +_StatVFS = NamedTuple('_StatVFS', [('f_bsize', int), ('f_frsize', int), ('f_blocks', int), + ('f_bfree', int), ('f_bavail', int), ('f_files', int), + ('f_ffree', int), ('f_favail', int), ('f_flag', int), + ('f_namemax', int)]) + +def ctermid() -> str: ... # Unix only +def getegid() -> int: ... # Unix only +def geteuid() -> int: ... # Unix only +def getgid() -> int: ... # Unix only +def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac +def initgroups(username: str, gid: int) -> None: ... # Unix only +def getlogin() -> str: ... +def getpgid(pid: int) -> int: ... # Unix only +def getpgrp() -> int: ... # Unix only +def getpid() -> int: ... +def getppid() -> int: ... +def getresuid() -> Tuple[int, int, int]: ... # Unix only +def getresgid() -> Tuple[int, int, int]: ... # Unix only +def getuid() -> int: ... # Unix only +def setegid(egid: int) -> None: ... # Unix only +def seteuid(euid: int) -> None: ... # Unix only +def setgid(gid: int) -> None: ... # Unix only +def setgroups(groups: Sequence[int]) -> None: ... # Unix only +def setpgrp() -> None: ... # Unix only +def setpgid(pid: int, pgrp: int) -> None: ... # Unix only +def setregid(rgid: int, egid: int) -> None: ... # Unix only +def setresgid(rgid: int, egid: int, sgid: int) -> None: ... # Unix only +def setresuid(ruid: int, euid: int, suid: int) -> None: ... # Unix only +def setreuid(ruid: int, euid: int) -> None: ... # Unix only +def getsid(pid: int) -> int: ... # Unix only +def setsid() -> None: ... # Unix only +def setuid(uid: int) -> None: ... # Unix only +def strerror(code: int) -> str: ... +def umask(mask: int) -> int: ... +def uname() -> Tuple[str, str, str, str, str]: ... # Unix only + +@overload +def getenv(key: Text) -> Optional[str]: ... +@overload +def getenv(key: Text, default: _T) -> Union[str, _T]: ... +def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ... +def unsetenv(key: Union[bytes, Text]) -> None: ... + +def fdopen(fd: int, *args, **kwargs) -> IO[Any]: ... +def close(fd: int) -> None: ... +def closerange(fd_low: int, fd_high: int) -> None: ... +def dup(fd: int) -> int: ... +def dup2(fd: int, fd2: int) -> None: ... +def fchmod(fd: int, mode: int) -> None: ... # Unix only +def fchown(fd: int, uid: int, gid: int) -> None: ... # Unix only +def fdatasync(fd: int) -> None: ... # Unix only, not Mac +def fpathconf(fd: int, name: Union[str, int]) -> int: ... # Unix only +def fstat(fd: int) -> Any: ... +def fstatvfs(fd: int) -> _StatVFS: ... # Unix only +def fsync(fd: int) -> None: ... +def ftruncate(fd: int, length: int) -> None: ... # Unix only +def isatty(fd: int) -> bool: ... # Unix only +def lseek(fd: int, pos: int, how: int) -> int: ... +def open(file: _PathType, flags: int, mode: int = ...) -> int: ... +def openpty() -> Tuple[int, int]: ... # some flavors of Unix +def pipe() -> Tuple[int, int]: ... +def read(fd: int, n: int) -> bytes: ... +def tcgetpgrp(fd: int) -> int: ... # Unix only +def tcsetpgrp(fd: int, pg: int) -> None: ... # Unix only +def ttyname(fd: int) -> str: ... # Unix only +def write(fd: int, string: bytes) -> int: ... +def access(path: _PathType, mode: int) -> bool: ... +def chdir(path: _PathType) -> None: ... +def fchdir(fd: int) -> None: ... +def getcwd() -> str: ... +def getcwdu() -> unicode: ... +def chflags(path: _PathType, flags: int) -> None: ... # Unix only +def chroot(path: _PathType) -> None: ... # Unix only +def chmod(path: _PathType, mode: int) -> None: ... +def chown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only +def lchflags(path: _PathType, flags: int) -> None: ... # Unix only +def lchmod(path: _PathType, mode: int) -> None: ... # Unix only +def lchown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only +def link(src: _PathType, link_name: _PathType) -> None: ... +def listdir(path: AnyStr) -> List[AnyStr]: ... +def lstat(path: _PathType) -> Any: ... +def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only +def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... +def major(device: int) -> int: ... +def minor(device: int) -> int: ... +def makedev(major: int, minor: int) -> int: ... +def mkdir(path: _PathType, mode: int = ...) -> None: ... +def makedirs(path: _PathType, mode: int = ...) -> None: ... +def pathconf(path: _PathType, name: Union[str, int]) -> int: ... # Unix only +def readlink(path: AnyStr) -> AnyStr: ... +def remove(path: _PathType) -> None: ... +def removedirs(path: _PathType) -> None: ... +def rename(src: _PathType, dst: _PathType) -> None: ... +def renames(old: _PathType, new: _PathType) -> None: ... +def rmdir(path: _PathType) -> None: ... +def stat(path: _PathType) -> Any: ... +@overload +def stat_float_times() -> bool: ... +@overload +def stat_float_times(newvalue: bool) -> None: ... +def statvfs(path: _PathType) -> _StatVFS: ... # Unix only +def symlink(source: _PathType, link_name: _PathType) -> None: ... +def unlink(path: _PathType) -> None: ... +# TODO: add ns, dir_fd, follow_symlinks argument +if sys.version_info >= (3, 0): + def utime(path: _PathType, times: Optional[Tuple[float, float]] = ...) -> None: ... +else: + def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ... + +if sys.version_info >= (3, 6): + def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ..., + onerror: Optional[Callable[[OSError], Any]] = ..., + followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[AnyStr]]]: ... +else: + def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ..., + followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[AnyStr]]]: ... + +def abort() -> NoReturn: ... +# These are defined as execl(file, *args) but the first *arg is mandatory. +def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ... +def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ... + +# These are: execle(file, *args, env) but env is pulled from the last element of the args. +def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ... +def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ... + +# The docs say `args: tuple or list of strings` +# The implementation enforces tuple or list so we can't use Sequence. +_ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]] +def execv(path: _PathType, args: _ExecVArgs) -> NoReturn: ... +def execve(path: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ... +def execvp(file: _PathType, args: _ExecVArgs) -> NoReturn: ... +def execvpe(file: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ... + +def _exit(n: int) -> NoReturn: ... +def fork() -> int: ... # Unix only +def forkpty() -> Tuple[int, int]: ... # some flavors of Unix +def kill(pid: int, sig: int) -> None: ... +def killpg(pgid: int, sig: int) -> None: ... # Unix only +def nice(increment: int) -> int: ... # Unix only +def plock(op: int) -> None: ... # Unix only ???op is int? + +if sys.version_info >= (3, 0): + class popen(_TextIOWrapper): + # TODO 'b' modes or bytes command not accepted? + def __init__(self, command: str, mode: str = ..., + bufsize: int = ...) -> None: ... + def close(self) -> Any: ... # may return int +else: + def popen(command: str, *args, **kwargs) -> IO[Any]: ... + def popen2(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ... + def popen3(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any], IO[Any]]: ... + def popen4(cmd: str, *args, **kwargs) -> Tuple[IO[Any], IO[Any]]: ... + +def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ... +def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text], + *args: Any) -> int: ... # Imprecise sig +def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text], + *args: Union[bytes, Text]) -> int: ... # Unix only TODO +def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: + ... # Imprecise signature; Unix only TODO +def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ... +def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], + env: Mapping[str, str]) -> int: ... +def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ... # Unix only +def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], + env: Mapping[str, str]) -> int: + ... # Unix only +def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only +def system(command: _PathType) -> int: ... +def times() -> Tuple[float, float, float, float, float]: ... +def wait() -> Tuple[int, int]: ... # Unix only +def waitpid(pid: int, options: int) -> Tuple[int, int]: ... +def wait3(options: int) -> Tuple[int, int, Any]: ... # Unix only +def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ... # Unix only +def WCOREDUMP(status: int) -> bool: ... # Unix only +def WIFCONTINUED(status: int) -> bool: ... # Unix only +def WIFSTOPPED(status: int) -> bool: ... # Unix only +def WIFSIGNALED(status: int) -> bool: ... # Unix only +def WIFEXITED(status: int) -> bool: ... # Unix only +def WEXITSTATUS(status: int) -> int: ... # Unix only +def WSTOPSIG(status: int) -> int: ... # Unix only +def WTERMSIG(status: int) -> int: ... # Unix only +def confstr(name: Union[str, int]) -> Optional[str]: ... # Unix only +def getloadavg() -> Tuple[float, float, float]: ... # Unix only +def sysconf(name: Union[str, int]) -> int: ... # Unix only +def urandom(n: int) -> bytes: ... + +if sys.version_info >= (3, 0): + def sched_getaffinity(id: int) -> Set[int]: ... +if sys.version_info >= (3, 3): + class waitresult: + si_pid: int + def waitid(idtype: int, id: int, options: int) -> waitresult: ... + +if sys.version_info < (3, 0): + def tmpfile() -> IO[Any]: ... + def tmpnam() -> str: ... + def tempnam(dir: str = ..., prefix: str = ...) -> str: ... + +P_ALL: int +WEXITED: int +WNOWAIT: int + +if sys.version_info >= (3, 3): + def sync() -> None: ... # Unix only + + def truncate(path: Union[_PathType, int], length: int) -> None: ... # Unix only up to version 3.4 + + def fwalk(top: AnyStr = ..., topdown: bool = ..., + onerror: Callable = ..., *, follow_symlinks: bool = ..., + dir_fd: int = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[AnyStr], int]]: ... # Unix only + + terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)]) + def get_terminal_size(fd: int = ...) -> terminal_size: ... + +if sys.version_info >= (3, 4): + def cpu_count() -> Optional[int]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os/path.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os/path.pyi new file mode 100644 index 000000000..56106428b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os/path.pyi @@ -0,0 +1,173 @@ +# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent! +# Stubs for os.path +# Ron Murawski + +from posix import stat_result +import sys +from typing import ( + overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO, + TypeVar, Union, Text, Callable, Optional +) + +_T = TypeVar('_T') + +if sys.version_info >= (3, 6): + from builtins import _PathLike + _PathType = Union[bytes, Text, _PathLike] + _StrPath = Union[Text, _PathLike[Text]] + _BytesPath = Union[bytes, _PathLike[bytes]] +else: + _PathType = Union[bytes, Text] + _StrPath = Text + _BytesPath = bytes + +# ----- os.path variables ----- +supports_unicode_filenames: bool +# aliases (also in os) +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +devnull: str + +# ----- os.path function stubs ----- +if sys.version_info >= (3, 6): + # Overloads are necessary to work around python/mypy#3644. + @overload + def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def abspath(path: AnyStr) -> AnyStr: ... + @overload + def basename(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(path: AnyStr) -> AnyStr: ... + @overload + def dirname(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(path: AnyStr) -> AnyStr: ... + @overload + def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expanduser(path: AnyStr) -> AnyStr: ... + @overload + def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expandvars(path: AnyStr) -> AnyStr: ... + @overload + def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + @overload + def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + else: + @overload + def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(filename: AnyStr) -> AnyStr: ... + +else: + def abspath(path: AnyStr) -> AnyStr: ... + def basename(path: AnyStr) -> AnyStr: ... + def dirname(path: AnyStr) -> AnyStr: ... + def expanduser(path: AnyStr) -> AnyStr: ... + def expandvars(path: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + def realpath(path: AnyStr) -> AnyStr: ... + else: + def realpath(filename: AnyStr) -> AnyStr: ... + +if sys.version_info >= (3, 6): + # In reality it returns str for sequences of _StrPath and bytes for sequences + # of _BytesPath, but mypy does not accept such a signature. + def commonpath(paths: Sequence[_PathType]) -> Any: ... +elif sys.version_info >= (3, 5): + def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ... + +# NOTE: Empty lists results in '' (str) regardless of contained type. +# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes +# So, fall back to Any +def commonprefix(list: Sequence[_PathType]) -> Any: ... + +def exists(path: _PathType) -> bool: ... +def lexists(path: _PathType) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(path: _PathType) -> float: ... +def getmtime(path: _PathType) -> float: ... +def getctime(path: _PathType) -> float: ... + +def getsize(path: _PathType) -> int: ... +def isabs(path: _PathType) -> bool: ... +def isfile(path: _PathType) -> bool: ... +def isdir(path: _PathType) -> bool: ... +def islink(path: _PathType) -> bool: ... +def ismount(path: _PathType) -> bool: ... + +if sys.version_info < (3, 0): + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: Text, *p: _PathType) -> Text: ... +elif sys.version_info >= (3, 6): + # Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway. + @overload + def join(path: _StrPath, *paths: _StrPath) -> Text: ... # type: ignore + @overload + def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ... +else: + def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ... + +@overload +def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... # type: ignore +@overload +def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ... + +def samefile(path1: _PathType, path2: _PathType) -> bool: ... +def sameopenfile(fp1: int, fp2: int) -> bool: ... +def samestat(stat1: stat_result, stat2: stat_result) -> bool: ... + +if sys.version_info >= (3, 6): + @overload + def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +else: + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # Windows only, deprecated + +if sys.version_info < (3,): + def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os2emxpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os2emxpath.pyi new file mode 100644 index 000000000..fc5c173ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/os2emxpath.pyi @@ -0,0 +1,37 @@ +# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +from typing import Any +from genericpath import * # noqa: F403 + +curdir = ... # type: Any +pardir = ... # type: Any +extsep = ... # type: Any +sep = ... # type: Any +pathsep = ... # type: Any +defpath = ... # type: Any +altsep = ... # type: Any +devnull = ... # type: Any + +def normcase(s): ... +def isabs(s): ... +def join(a, *p): ... +def split(p): ... +def splitext(p): ... +def splitdrive(p): ... +def basename(p): ... +def dirname(p): ... +def islink(path): ... +def lexists(path): ... +def samefile(f1, f2): ... +def sameopenfile(fp1, fp2): ... +def samestat(s1, s2): ... +def ismount(path): ... +def walk(top, func, arg): ... +def expanduser(path): ... +def expandvars(path): ... +def normpath(path): ... +def abspath(path): ... +def realpath(filename): ... + +supports_unicode_filenames = ... # type: Any + +def relpath(path, start=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/pipes.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/pipes.pyi new file mode 100644 index 000000000..d5f5291e3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/pipes.pyi @@ -0,0 +1,13 @@ +from typing import Any, IO + +class Template: + def __init__(self) -> None: ... + def reset(self) -> None: ... + def clone(self) -> Template: ... + def debug(self, flag: bool) -> None: ... + def append(self, cmd: str, kind: str) -> None: ... + def prepend(self, cmd: str, kind: str) -> None: ... + def open(self, file: str, mode: str) -> IO[Any]: ... + def copy(self, infile: str, outfile: str) -> None: ... + +def quote(s: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/platform.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/platform.pyi new file mode 100644 index 000000000..75125f876 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/platform.pyi @@ -0,0 +1,45 @@ +# Stubs for platform (Python 2) +# +# Based on stub generated by stubgen. + +from typing import Any + +__copyright__ = ... # type: Any +DEV_NULL = ... # type: Any + +def libc_ver(executable=..., lib=..., version=..., chunksize=2048): ... +def linux_distribution(distname=..., version=..., id=..., supported_dists=..., full_distribution_name=1): ... +def dist(distname=..., version=..., id=..., supported_dists=...): ... + +class _popen: + tmpfile = ... # type: Any + pipe = ... # type: Any + bufsize = ... # type: Any + mode = ... # type: Any + def __init__(self, cmd, mode=..., bufsize=None): ... + def read(self): ... + def readlines(self): ... + def close(self, remove=..., error=...): ... + __del__ = ... # type: Any + +def popen(cmd, mode=..., bufsize=None): ... +def win32_ver(release=..., version=..., csd=..., ptype=...): ... +def mac_ver(release=..., versioninfo=..., machine=...): ... +def java_ver(release=..., vendor=..., vminfo=..., osinfo=...): ... +def system_alias(system, release, version): ... +def architecture(executable=..., bits=..., linkage=...): ... +def uname(): ... +def system(): ... +def node(): ... +def release(): ... +def version(): ... +def machine(): ... +def processor(): ... +def python_implementation(): ... +def python_version(): ... +def python_version_tuple(): ... +def python_branch(): ... +def python_revision(): ... +def python_build(): ... +def python_compiler(): ... +def platform(aliased=0, terse=0): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/popen2.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/popen2.pyi new file mode 100644 index 000000000..a71e78e57 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/popen2.pyi @@ -0,0 +1,28 @@ +from typing import Any, Iterable, List, Optional, Union, TextIO, Tuple, TypeVar + +_T = TypeVar('_T') + + +class Popen3: + sts = ... # type: int + cmd = ... # type: Iterable + pid = ... # type: int + tochild = ... # type: TextIO + fromchild = ... # type: TextIO + childerr = ... # type: Optional[TextIO] + def __init__(self, cmd: Iterable = ..., capturestderr: bool = ..., bufsize: int = ...) -> None: ... + def __del__(self) -> None: ... + def poll(self, _deadstate: _T = ...) -> Union[int, _T]: ... + def wait(self) -> int: ... + +class Popen4(Popen3): + childerr = ... # type: None + cmd = ... # type: Iterable + pid = ... # type: int + tochild = ... # type: TextIO + fromchild = ... # type: TextIO + def __init__(self, cmd: Iterable = ..., bufsize: int = ...) -> None: ... + +def popen2(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... +def popen3(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO, TextIO]: ... +def popen4(cmd: Iterable = ..., bufsize: int = ..., mode: str = ...) -> Tuple[TextIO, TextIO]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/posix.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/posix.pyi new file mode 100644 index 000000000..ba01df0b7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/posix.pyi @@ -0,0 +1,205 @@ +from typing import Dict, List, Mapping, Tuple, Union, Sequence, IO, Optional, TypeVar + +error = OSError + +confstr_names = ... # type: Dict[str, int] +environ = ... # type: Dict[str, str] +pathconf_names = ... # type: Dict[str, int] +sysconf_names = ... # type: Dict[str, int] + +EX_CANTCREAT = ... # type: int +EX_CONFIG = ... # type: int +EX_DATAERR = ... # type: int +EX_IOERR = ... # type: int +EX_NOHOST = ... # type: int +EX_NOINPUT = ... # type: int +EX_NOPERM = ... # type: int +EX_NOUSER = ... # type: int +EX_OK = ... # type: int +EX_OSERR = ... # type: int +EX_OSFILE = ... # type: int +EX_PROTOCOL = ... # type: int +EX_SOFTWARE = ... # type: int +EX_TEMPFAIL = ... # type: int +EX_UNAVAILABLE = ... # type: int +EX_USAGE = ... # type: int +F_OK = ... # type: int +NGROUPS_MAX = ... # type: int +O_APPEND = ... # type: int +O_ASYNC = ... # type: int +O_CREAT = ... # type: int +O_DIRECT = ... # type: int +O_DIRECTORY = ... # type: int +O_DSYNC = ... # type: int +O_EXCL = ... # type: int +O_LARGEFILE = ... # type: int +O_NDELAY = ... # type: int +O_NOATIME = ... # type: int +O_NOCTTY = ... # type: int +O_NOFOLLOW = ... # type: int +O_NONBLOCK = ... # type: int +O_RDONLY = ... # type: int +O_RDWR = ... # type: int +O_RSYNC = ... # type: int +O_SYNC = ... # type: int +O_TRUNC = ... # type: int +O_WRONLY = ... # type: int +R_OK = ... # type: int +TMP_MAX = ... # type: int +WCONTINUED = ... # type: int +WNOHANG = ... # type: int +WUNTRACED = ... # type: int +W_OK = ... # type: int +X_OK = ... # type: int + +def WCOREDUMP(status: int) -> bool: ... +def WEXITSTATUS(status: int) -> bool: ... +def WIFCONTINUED(status: int) -> bool: ... +def WIFEXITED(status: int) -> bool: ... +def WIFSIGNALED(status: int) -> bool: ... +def WIFSTOPPED(status: int) -> bool: ... +def WSTOPSIG(status: int) -> bool: ... +def WTERMSIG(status: int) -> bool: ... + +class stat_result(object): + n_fields = ... # type: int + n_sequence_fields = ... # type: int + n_unnamed_fields = ... # type: int + st_mode = ... # type: int + st_ino = ... # type: int + st_dev = ... # type: int + st_nlink = ... # type: int + st_uid = ... # type: int + st_gid = ... # type: int + st_size = ... # type: int + st_atime = ... # type: int + st_mtime = ... # type: int + st_ctime = ... # type: int + +class statvfs_result(object): + n_fields = ... # type: int + n_sequence_fields = ... # type: int + n_unnamed_fields = ... # type: int + f_bsize = ... # type: int + f_frsize = ... # type: int + f_blocks = ... # type: int + f_bfree = ... # type: int + f_bavail = ... # type: int + f_files = ... # type: int + f_ffree = ... # type: int + f_favail = ... # type: int + f_flag = ... # type: int + f_namemax = ... # type: int + +def _exit(status: int) -> None: ... +def abort() -> None: ... +def access(path: unicode, mode: int) -> bool: ... +def chdir(path: unicode) -> None: ... +def chmod(path: unicode, mode: int) -> None: ... +def chown(path: unicode, uid: int, gid: int) -> None: ... +def chroot(path: unicode) -> None: ... +def close(fd: int) -> None: ... +def closerange(fd_low: int, fd_high: int) -> None: ... +def confstr(name: Union[str, int]) -> str: ... +def ctermid() -> str: ... +def dup(fd: int) -> int: ... +def dup2(fd: int, fd2: int) -> None: ... +def execv(path: str, args: Sequence[str], env: Mapping[str, str]) -> None: ... +def execve(path: str, args: Sequence[str], env: Mapping[str, str]) -> None: ... +def fchdir(fd: int) -> None: ... +def fchmod(fd: int, mode: int) -> None: ... +def fchown(fd: int, uid: int, gid: int) -> None: ... +def fdatasync(fd: int) -> None: ... +def fdopen(fd: int, mode: str = ..., bufsize: int = ...) -> IO[str]: ... +def fork() -> int: + raise OSError() +def forkpty() -> Tuple[int, int]: + raise OSError() +def fpathconf(fd: int, name: str) -> None: ... +def fstat(fd: int) -> stat_result: ... +def fstatvfs(fd: int) -> statvfs_result: ... +def fsync(fd: int) -> None: ... +def ftruncate(fd: int, length: int) -> None: ... +def getcwd() -> str: ... +def getcwdu() -> unicode: ... +def getegid() -> int: ... +def geteuid() -> int: ... +def getgid() -> int: ... +def getgroups() -> List[int]: ... +def getloadavg() -> Tuple[float, float, float]: + raise OSError() +def getlogin() -> str: ... +def getpgid(pid: int) -> int: ... +def getpgrp() -> int: ... +def getpid() -> int: ... +def getppid() -> int: ... +def getresgid() -> Tuple[int, int, int]: ... +def getresuid() -> Tuple[int, int, int]: ... +def getsid(pid: int) -> int: ... +def getuid() -> int: ... +def initgroups(username: str, gid: int) -> None: ... +def isatty(fd: int) -> bool: ... +def kill(pid: int, sig: int) -> None: ... +def killpg(pgid: int, sig: int) -> None: ... +def lchown(path: unicode, uid: int, gid: int) -> None: ... +def link(source: unicode, link_name: str) -> None: ... +_T = TypeVar("_T") +def listdir(path: _T) -> List[_T]: ... +def lseek(fd: int, pos: int, how: int) -> None: ... +def lstat(path: unicode) -> stat_result: ... +def major(device: int) -> int: ... +def makedev(major: int, minor: int) -> int: ... +def minor(device: int) -> int: ... +def mkdir(path: unicode, mode: int = ...) -> None: ... +def mkfifo(path: unicode, mode: int = ...) -> None: ... +def mknod(filename: unicode, mode: int = ..., device: int = ...) -> None: ... +def nice(increment: int) -> int: ... +def open(file: unicode, flags: int, mode: int = ...) -> int: ... +def openpty() -> Tuple[int, int]: ... +def pathconf(path: unicode, name: str) -> str: ... +def pipe() -> Tuple[int, int]: ... +def popen(command: str, mode: str = ..., bufsize: int = ...) -> IO[str]: ... +def putenv(varname: str, value: str) -> None: ... +def read(fd: int, n: int) -> str: ... +def readlink(path: _T) -> _T: ... +def remove(path: unicode) -> None: ... +def rename(src: unicode, dst: unicode) -> None: ... +def rmdir(path: unicode) -> None: ... +def setegid(egid: int) -> None: ... +def seteuid(euid: int) -> None: ... +def setgid(gid: int) -> None: ... +def setgroups(groups: Sequence[int]) -> None: ... +def setpgid(pid: int, pgrp: int) -> None: ... +def setpgrp() -> None: ... +def setregid(rgid: int, egid: int) -> None: ... +def setresgid(rgid: int, egid: int, sgid: int) -> None: ... +def setresuid(ruid: int, euid: int, suid: int) -> None: ... +def setreuid(ruid: int, euid: int) -> None: ... +def setsid() -> None: ... +def setuid(pid: int) -> None: ... +def stat(path: unicode) -> stat_result: ... +def statvfs(path: unicode) -> statvfs_result: ... +def stat_float_times(fd: int) -> None: ... +def strerror(code: int) -> str: ... +def symlink(source: unicode, link_name: unicode) -> None: ... +def sysconf(name: Union[str, int]) -> int: ... +def system(command: unicode) -> int: ... +def tcgetpgrp(fd: int) -> int: ... +def tcsetpgrp(fd: int, pg: int) -> None: ... +def times() -> Tuple[float, float, float, float, float]: ... +def tmpfile() -> IO[str]: ... +def ttyname(fd: int) -> str: ... +def umask(mask: int) -> int: ... +def uname() -> Tuple[str, str, str, str, str]: ... +def unlink(path: unicode) -> None: ... +def unsetenv(varname: str) -> None: ... +def urandom(n: int) -> str: ... +def utime(path: unicode, times: Optional[Tuple[int, int]]) -> None: + raise OSError +def wait() -> int: ... +_r = Tuple[float, float, int, int, int, int, int, int, int, int, int, int, int, int, int, int] +def wait3(options: int) -> Tuple[int, int, _r]: ... +def wait4(pid: int, options: int) -> Tuple[int, int, _r]: ... +def waitpid(pid: int, options: int) -> int: + raise OSError() +def write(fd: int, str: str) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/posixpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/posixpath.pyi new file mode 100644 index 000000000..fc5c173ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/posixpath.pyi @@ -0,0 +1,37 @@ +# NB: os2emxpath.pyi, posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +from typing import Any +from genericpath import * # noqa: F403 + +curdir = ... # type: Any +pardir = ... # type: Any +extsep = ... # type: Any +sep = ... # type: Any +pathsep = ... # type: Any +defpath = ... # type: Any +altsep = ... # type: Any +devnull = ... # type: Any + +def normcase(s): ... +def isabs(s): ... +def join(a, *p): ... +def split(p): ... +def splitext(p): ... +def splitdrive(p): ... +def basename(p): ... +def dirname(p): ... +def islink(path): ... +def lexists(path): ... +def samefile(f1, f2): ... +def sameopenfile(fp1, fp2): ... +def samestat(s1, s2): ... +def ismount(path): ... +def walk(top, func, arg): ... +def expanduser(path): ... +def expandvars(path): ... +def normpath(path): ... +def abspath(path): ... +def realpath(filename): ... + +supports_unicode_filenames = ... # type: Any + +def relpath(path, start=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/pydoc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/pydoc.pyi new file mode 100644 index 000000000..41505e6b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/pydoc.pyi @@ -0,0 +1,176 @@ +from typing import Any, AnyStr, Callable, Container, Dict, IO, List, Mapping, MutableMapping, NoReturn, Optional, Tuple, Type, Union +from repr import Repr + +from types import FunctionType, MethodType, ModuleType, TracebackType +# the return type of sys.exc_info(), used by ErrorDuringImport.__init__ +_Exc_Info = Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]] + +__author__ = ... # type: str +__date__ = ... # type: str +__version__ = ... # type: str +__credits__ = ... # type: str + +def pathdirs() -> List[str]: ... +def getdoc(object: object) -> Union[str, unicode]: ... +def splitdoc(doc: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +def classname(object: object, modname: str) -> str: ... +def isdata(object: object) -> bool: ... +def replace(text: AnyStr, *pairs: AnyStr) -> AnyStr: ... +def cram(text: str, maxlen: int) -> str: ... +def stripid(text: str) -> str: ... +def allmethods(cl: type) -> MutableMapping[str, MethodType]: ... +def visiblename(name: str, all: Optional[Container[str]] = ..., obj: Optional[object] = ...) -> bool: ... +def classify_class_attrs(object: object) -> List[Tuple[str, str, type, str]]: ... + +def ispackage(path: str) -> bool: ... +def source_synopsis(file: IO[AnyStr]) -> Optional[AnyStr]: ... +def synopsis(filename: str, cache: MutableMapping[str, Tuple[int, str]] = ...) -> Optional[str]: ... + +class ErrorDuringImport(Exception): + filename = ... # type: str + exc = ... # type: Optional[Type[BaseException]] + value = ... # type: Optional[BaseException] + tb = ... # type: Optional[TracebackType] + def __init__(self, filename: str, exc_info: _Exc_Info) -> None: ... + +def importfile(path: str) -> ModuleType: ... +def safeimport(path: str, forceload: bool = ..., cache: MutableMapping[str, ModuleType] = ...) -> ModuleType: ... + +class Doc: + def document(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def fail(self, object: object, name: Optional[str] = ..., *args: Any) -> NoReturn: ... + def docmodule(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def docclass(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def docroutine(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def docother(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def docproperty(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def docdata(self, object: object, name: Optional[str] = ..., *args: Any) -> str: ... + def getdocloc(self, object: object) -> Optional[str]: ... + +class HTMLRepr(Repr): + maxlist = ... # type: int + maxtuple = ... # type: int + maxdict = ... # type: int + maxstring = ... # type: int + maxother = ... # type: int + def __init__(self) -> None: ... + def escape(self, text: str) -> str: ... + def repr(self, object: object) -> str: ... + def repr1(self, x: object, level: complex) -> str: ... + def repr_string(self, x: Union[str, unicode], level: complex) -> str: ... + def repr_str(self, x: Union[str, unicode], level: complex) -> str: ... + def repr_instance(self, x: object, level: complex) -> str: ... + def repr_unicode(self, x: AnyStr, level: complex) -> str: ... + +class HTMLDoc(Doc): + def repr(self, object: object) -> str: ... + def escape(self, test: str) -> str: ... + def page(self, title: str, contents: str) -> str: ... + def heading(self, title: str, fgcol: str, bgcol: str, extras: str = ...) -> str: ... + def section(self, title: str, fgcol: str, bgcol: str, contents: str, width: int = ..., prelude: str = ..., marginalia: Optional[str] = ..., gap: str = ...) -> str: ... + def bigsection(self, title: str, *args) -> str: ... + def preformat(self, text: str) -> str: ... + def multicolumn(self, list: List[Any], format: Callable[[Any], str], cols: int = ...) -> str: ... + def grey(self, text: str) -> str: ... + def namelink(self, name: str, *dicts: MutableMapping[str, str]) -> str: ... + def classlink(self, object: object, modname: str) -> str: ... + def modulelink(self, object: object) -> str: ... + def modpkglink(self, data: Tuple[str, str, bool, bool]) -> str: ... + def markup(self, text: str, escape: Optional[Callable[[str], str]] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ...) -> str: ... + def formattree(self, tree: List[Union[Tuple[type, Tuple[type, ...]], list]], modname: str, parent: Optional[type] = ...) -> str: ... + def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored) -> str: ... + def docclass(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., *ignored) -> str: ... + def formatvalue(self, object: object) -> str: ... + def docroutine(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., funcs: Mapping[str, str] = ..., classes: Mapping[str, str] = ..., methods: Mapping[str, str] = ..., cl: Optional[type] = ..., *ignored) -> str: ... + def docproperty(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored) -> str: ... + def docother(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored) -> str: ... + def docdata(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., cl: Optional[Any] = ..., *ignored) -> str: ... + def index(self, dir: str, shadowed: Optional[MutableMapping[str, bool]] = ...) -> str: ... + +class TextRepr(Repr): + maxlist = ... # type: int + maxtuple = ... # type: int + maxdict = ... # type: int + maxstring = ... # type: int + maxother = ... # type: int + def __init__(self) -> None: ... + def repr1(self, x: object, level: complex) -> str: ... + def repr_string(self, x: str, level: complex) -> str: ... + def repr_str(self, x: str, level: complex) -> str: ... + def repr_instance(self, x: object, level: complex) -> str: ... + +class TextDoc(Doc): + def repr(self, object: object) -> str: ... + def bold(self, text: str) -> str: ... + def indent(self, text: str, prefix: str = ...) -> str: ... + def section(self, title: str, contents: str) -> str: ... + def formattree(self, tree: List[Union[Tuple[type, Tuple[type, ...]], list]], modname: str, parent: Optional[type] = ..., prefix: str = ...) -> str: ... + def docmodule(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., *ignored) -> str: ... + def docclass(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., *ignored) -> str: ... + def formatvalue(self, object: object) -> str: ... + def docroutine(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored) -> str: ... + def docproperty(self, object: object, name: Optional[str] = ..., mod: Optional[Any] = ..., cl: Optional[Any] = ..., *ignored) -> str: ... + def docdata(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., cl: Optional[Any] = ..., *ignored) -> str: ... + def docother(self, object: object, name: Optional[str] = ..., mod: Optional[str] = ..., parent: Optional[str] = ..., maxlen: Optional[int] = ..., doc: Optional[Any] = ..., *ignored) -> str: ... + +def pager(text: str) -> None: ... +def getpager() -> Callable[[str], None]: ... +def plain(text: str) -> str: ... +def pipepager(text: str, cmd: str) -> None: ... +def tempfilepager(text: str, cmd: str) -> None: ... +def ttypager(text: str) -> None: ... +def plainpager(text: str) -> None: ... +def describe(thing: Any) -> str: ... +def locate(path: str, forceload: bool = ...) -> object: ... + +text = ... # type: TextDoc +html = ... # type: HTMLDoc + +class _OldStyleClass: ... + +def resolve(thing: Union[str, object], forceload: bool = ...) -> Optional[Tuple[object, str]]: ... +def render_doc(thing: Union[str, object], title: str = ..., forceload: bool = ...) -> str: ... +def doc(thing: Union[str, object], title: str = ..., forceload: bool = ...) -> None: ... +def writedoc(thing: Union[str, object], forceload: bool = ...) -> None: ... +def writedocs(dir: str, pkgpath: str = ..., done: Optional[Any] = ...) -> None: ... + +class Helper: + keywords = ... # type: Dict[str, Union[str, Tuple[str, str]]] + symbols = ... # type: Dict[str, str] + topics = ... # type: Dict[str, Union[str, Tuple[str, ...]]] + def __init__(self, input: Optional[IO[str]] = ..., output: Optional[IO[str]] = ...) -> None: ... + input = ... # type: IO[str] + output = ... # type: IO[str] + def __call__(self, request: Union[str, Helper, object] = ...) -> None: ... + def interact(self) -> None: ... + def getline(self, prompt: str) -> str: ... + def help(self, request: Any) -> None: ... + def intro(self) -> None: ... + def list(self, items: List[str], columns: int = ..., width: int = ...) -> None: ... + def listkeywords(self) -> None: ... + def listsymbols(self) -> None: ... + def listtopics(self) -> None: ... + def showtopic(self, topic: str, more_xrefs: str = ...) -> None: ... + def showsymbol(self, symbol: str) -> None: ... + def listmodules(self, key: str = ...) -> None: ... + +help = ... # type: Helper + +# See Python issue #11182: "remove the unused and undocumented pydoc.Scanner class" +# class Scanner: +# roots = ... # type: Any +# state = ... # type: Any +# children = ... # type: Any +# descendp = ... # type: Any +# def __init__(self, roots, children, descendp) -> None: ... +# def next(self): ... + +class ModuleScanner: + quit = ... # type: bool + def run(self, callback: Callable[[Optional[str], str, str], None], key: Optional[Any] = ..., completer: Optional[Callable[[], None]] = ..., onerror: Optional[Callable] = ...) -> None: ... + +def apropos(key: str) -> None: ... +def serve(port: int, callback: Optional[Callable[[Any], None]] = ..., completer: Optional[Callable[[], None]] = ...) -> None: ... +def gui() -> None: ... +def ispath(x: Any) -> bool: ... +def cli() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/random.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/random.pyi new file mode 100644 index 000000000..9aa2ddbac --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/random.pyi @@ -0,0 +1,76 @@ +# Stubs for random +# Ron Murawski +# Updated by Jukka Lehtosalo + +# based on https://docs.python.org/2/library/random.html + +# ----- random classes ----- + +import _random +from typing import ( + Any, TypeVar, Sequence, List, Callable, AbstractSet, Union, + overload +) + +_T = TypeVar('_T') + +class Random(_random.Random): + def __init__(self, x: object = ...) -> None: ... + def seed(self, x: object = ...) -> None: ... + def getstate(self) -> _random._State: ... + def setstate(self, state: _random._State) -> None: ... + def jumpahead(self, n: int) -> None: ... + def getrandbits(self, k: int) -> int: ... + @overload + def randrange(self, stop: int) -> int: ... + @overload + def randrange(self, start: int, stop: int, step: int = ...) -> int: ... + def randint(self, a: int, b: int) -> int: ... + def choice(self, seq: Sequence[_T]) -> _T: ... + def shuffle(self, x: List[Any], random: Callable[[], None] = ...) -> None: ... + def sample(self, population: Union[Sequence[_T], AbstractSet[_T]], k: int) -> List[_T]: ... + def random(self) -> float: ... + def uniform(self, a: float, b: float) -> float: ... + def triangular(self, low: float = ..., high: float = ..., + mode: float = ...) -> float: ... + def betavariate(self, alpha: float, beta: float) -> float: ... + def expovariate(self, lambd: float) -> float: ... + def gammavariate(self, alpha: float, beta: float) -> float: ... + def gauss(self, mu: float, sigma: float) -> float: ... + def lognormvariate(self, mu: float, sigma: float) -> float: ... + def normalvariate(self, mu: float, sigma: float) -> float: ... + def vonmisesvariate(self, mu: float, kappa: float) -> float: ... + def paretovariate(self, alpha: float) -> float: ... + def weibullvariate(self, alpha: float, beta: float) -> float: ... + +# SystemRandom is not implemented for all OS's; good on Windows & Linux +class SystemRandom(Random): + ... + +# ----- random function stubs ----- +def seed(x: object = ...) -> None: ... +def getstate() -> object: ... +def setstate(state: object) -> None: ... +def jumpahead(n: int) -> None: ... +def getrandbits(k: int) -> int: ... +@overload +def randrange(stop: int) -> int: ... +@overload +def randrange(start: int, stop: int, step: int = ...) -> int: ... +def randint(a: int, b: int) -> int: ... +def choice(seq: Sequence[_T]) -> _T: ... +def shuffle(x: List[Any], random: Callable[[], float] = ...) -> None: ... +def sample(population: Union[Sequence[_T], AbstractSet[_T]], k: int) -> List[_T]: ... +def random() -> float: ... +def uniform(a: float, b: float) -> float: ... +def triangular(low: float = ..., high: float = ..., + mode: float = ...) -> float: ... +def betavariate(alpha: float, beta: float) -> float: ... +def expovariate(lambd: float) -> float: ... +def gammavariate(alpha: float, beta: float) -> float: ... +def gauss(mu: float, sigma: float) -> float: ... +def lognormvariate(mu: float, sigma: float) -> float: ... +def normalvariate(mu: float, sigma: float) -> float: ... +def vonmisesvariate(mu: float, kappa: float) -> float: ... +def paretovariate(alpha: float) -> float: ... +def weibullvariate(alpha: float, beta: float) -> float: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/re.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/re.pyi new file mode 100644 index 000000000..2a2c2cb03 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/re.pyi @@ -0,0 +1,100 @@ +# Stubs for re +# Ron Murawski +# 'bytes' support added by Jukka Lehtosalo + +# based on: http: //docs.python.org/2.7/library/re.html + +from typing import ( + List, Iterator, overload, Callable, Tuple, Sequence, Dict, + Generic, AnyStr, Match, Pattern, Any, Optional, Union +) + +# ----- re variables and constants ----- +DEBUG = 0 +I = 0 +IGNORECASE = 0 +L = 0 +LOCALE = 0 +M = 0 +MULTILINE = 0 +S = 0 +DOTALL = 0 +X = 0 +VERBOSE = 0 +U = 0 +UNICODE = 0 +T = 0 +TEMPLATE = 0 + +class error(Exception): ... + +@overload +def compile(pattern: AnyStr, flags: int = ...) -> Pattern[AnyStr]: ... +@overload +def compile(pattern: Pattern[AnyStr], flags: int = ...) -> Pattern[AnyStr]: ... + +@overload +def search(pattern: Union[str, unicode], string: AnyStr, flags: int = ...) -> Optional[Match[AnyStr]]: ... +@overload +def search(pattern: Union[Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> Optional[Match[AnyStr]]: ... + +@overload +def match(pattern: Union[str, unicode], string: AnyStr, flags: int = ...) -> Optional[Match[AnyStr]]: ... +@overload +def match(pattern: Union[Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> Optional[Match[AnyStr]]: ... + +@overload +def split(pattern: Union[str, unicode], string: AnyStr, + maxsplit: int = ..., flags: int = ...) -> List[AnyStr]: ... +@overload +def split(pattern: Union[Pattern[str], Pattern[unicode]], string: AnyStr, + maxsplit: int = ..., flags: int = ...) -> List[AnyStr]: ... + +@overload +def findall(pattern: Union[str, unicode], string: AnyStr, flags: int = ...) -> List[Any]: ... +@overload +def findall(pattern: Union[Pattern[str], Pattern[unicode]], string: AnyStr, flags: int = ...) -> List[Any]: ... + +# Return an iterator yielding match objects over all non-overlapping matches +# for the RE pattern in string. The string is scanned left-to-right, and +# matches are returned in the order found. Empty matches are included in the +# result unless they touch the beginning of another match. +@overload +def finditer(pattern: Union[str, unicode], string: AnyStr, + flags: int = ...) -> Iterator[Match[AnyStr]]: ... +@overload +def finditer(pattern: Union[Pattern[str], Pattern[unicode]], string: AnyStr, + flags: int = ...) -> Iterator[Match[AnyStr]]: ... + +@overload +def sub(pattern: Union[str, unicode], repl: AnyStr, string: AnyStr, count: int = ..., + flags: int = ...) -> AnyStr: ... +@overload +def sub(pattern: Union[str, unicode], repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., flags: int = ...) -> AnyStr: ... +@overload +def sub(pattern: Union[Pattern[str], Pattern[unicode]], repl: AnyStr, string: AnyStr, count: int = ..., + flags: int = ...) -> AnyStr: ... +@overload +def sub(pattern: Union[Pattern[str], Pattern[unicode]], repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., flags: int = ...) -> AnyStr: ... + +@overload +def subn(pattern: Union[str, unicode], repl: AnyStr, string: AnyStr, count: int = ..., + flags: int = ...) -> Tuple[AnyStr, int]: ... +@overload +def subn(pattern: Union[str, unicode], repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., + flags: int = ...) -> Tuple[AnyStr, int]: ... +@overload +def subn(pattern: Union[Pattern[str], Pattern[unicode]], repl: AnyStr, string: AnyStr, count: int = ..., + flags: int = ...) -> Tuple[AnyStr, int]: ... +@overload +def subn(pattern: Union[Pattern[str], Pattern[unicode]], repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., + flags: int = ...) -> Tuple[AnyStr, int]: ... + +def escape(string: AnyStr) -> AnyStr: ... + +def purge() -> None: ... +def template(pattern: Union[AnyStr, Pattern[AnyStr]], flags: int = ...) -> Pattern[AnyStr]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/repr.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/repr.pyi new file mode 100644 index 000000000..5e54f6961 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/repr.pyi @@ -0,0 +1,31 @@ +class Repr: + maxarray = ... # type: int + maxdeque = ... # type: int + maxdict = ... # type: int + maxfrozenset = ... # type: int + maxlevel = ... # type: int + maxlist = ... # type: int + maxlong = ... # type: int + maxother = ... # type: int + maxset = ... # type: int + maxstring = ... # type: int + maxtuple = ... # type: int + def __init__(self) -> None: ... + def _repr_iterable(self, x, level: complex, left, right, maxiter, trail=...) -> str: ... + def repr(self, x) -> str: ... + def repr1(self, x, level: complex) -> str: ... + def repr_array(self, x, level: complex) -> str: ... + def repr_deque(self, x, level: complex) -> str: ... + def repr_dict(self, x, level: complex) -> str: ... + def repr_frozenset(self, x, level: complex) -> str: ... + def repr_instance(self, x, level: complex) -> str: ... + def repr_list(self, x, level: complex) -> str: ... + def repr_long(self, x, level: complex) -> str: ... + def repr_set(self, x, level: complex) -> str: ... + def repr_str(self, x, level: complex) -> str: ... + def repr_tuple(self, x, level: complex) -> str: ... + +def _possibly_sorted(x) -> list: ... + +aRepr = ... # type: Repr +def repr(x) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/resource.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/resource.pyi new file mode 100644 index 000000000..92654a9c5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/resource.pyi @@ -0,0 +1,33 @@ +from typing import Tuple, NamedTuple + +class error(Exception): ... + +RLIM_INFINITY = ... # type: int +def getrlimit(resource: int) -> Tuple[int, int]: ... +def setrlimit(resource: int, limits: Tuple[int, int]) -> None: ... + +RLIMIT_CORE = ... # type: int +RLIMIT_CPU = ... # type: int +RLIMIT_FSIZE = ... # type: int +RLIMIT_DATA = ... # type: int +RLIMIT_STACK = ... # type: int +RLIMIT_RSS = ... # type: int +RLIMIT_NPROC = ... # type: int +RLIMIT_NOFILE = ... # type: int +RLIMIT_OFILE = ... # type: int +RLIMIT_MEMLOCK = ... # type: int +RLIMIT_VMEM = ... # type: int +RLIMIT_AS = ... # type: int + +_RUsage = NamedTuple('_RUsage', [('ru_utime', float), ('ru_stime', float), ('ru_maxrss', int), + ('ru_ixrss', int), ('ru_idrss', int), ('ru_isrss', int), + ('ru_minflt', int), ('ru_majflt', int), ('ru_nswap', int), + ('ru_inblock', int), ('ru_oublock', int), ('ru_msgsnd', int), + ('ru_msgrcv', int), ('ru_nsignals', int), ('ru_nvcsw', int), + ('ru_nivcsw', int)]) +def getrusage(who: int) -> _RUsage: ... +def getpagesize() -> int: ... + +RUSAGE_SELF = ... # type: int +RUSAGE_CHILDREN = ... # type: int +RUSAGE_BOTH = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/rfc822.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/rfc822.pyi new file mode 100644 index 000000000..28ba75942 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/rfc822.pyi @@ -0,0 +1,79 @@ +# Stubs for rfc822 (Python 2) +# +# Based on stub generated by stubgen. + +from typing import Any + +class Message: + fp = ... # type: Any + seekable = ... # type: Any + startofheaders = ... # type: Any + startofbody = ... # type: Any + def __init__(self, fp, seekable=1): ... + def rewindbody(self): ... + dict = ... # type: Any + unixfrom = ... # type: Any + headers = ... # type: Any + status = ... # type: Any + def readheaders(self): ... + def isheader(self, line): ... + def islast(self, line): ... + def iscomment(self, line): ... + def getallmatchingheaders(self, name): ... + def getfirstmatchingheader(self, name): ... + def getrawheader(self, name): ... + def getheader(self, name, default=None): ... + get = ... # type: Any + def getheaders(self, name): ... + def getaddr(self, name): ... + def getaddrlist(self, name): ... + def getdate(self, name): ... + def getdate_tz(self, name): ... + def __len__(self): ... + def __getitem__(self, name): ... + def __setitem__(self, name, value): ... + def __delitem__(self, name): ... + def setdefault(self, name, default=...): ... + def has_key(self, name): ... + def __contains__(self, name): ... + def __iter__(self): ... + def keys(self): ... + def values(self): ... + def items(self): ... + +class AddrlistClass: + specials = ... # type: Any + pos = ... # type: Any + LWS = ... # type: Any + CR = ... # type: Any + atomends = ... # type: Any + phraseends = ... # type: Any + field = ... # type: Any + commentlist = ... # type: Any + def __init__(self, field): ... + def gotonext(self): ... + def getaddrlist(self): ... + def getaddress(self): ... + def getrouteaddr(self): ... + def getaddrspec(self): ... + def getdomain(self): ... + def getdelimited(self, beginchar, endchars, allowcomments=1): ... + def getquote(self): ... + def getcomment(self): ... + def getdomainliteral(self): ... + def getatom(self, atomends=None): ... + def getphraselist(self): ... + +class AddressList(AddrlistClass): + addresslist = ... # type: Any + def __init__(self, field): ... + def __len__(self): ... + def __add__(self, other): ... + def __iadd__(self, other): ... + def __sub__(self, other): ... + def __isub__(self, other): ... + def __getitem__(self, index): ... + +def parsedate_tz(data): ... +def parsedate(data): ... +def mktime_tz(data): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/robotparser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/robotparser.pyi new file mode 100644 index 000000000..403039ae9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/robotparser.pyi @@ -0,0 +1,7 @@ +class RobotFileParser: + def set_url(self, url: str): ... + def read(self): ... + def parse(self, lines: str): ... + def can_fetch(self, user_agent: str, url: str): ... + def mtime(self): ... + def modified(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/runpy.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/runpy.pyi new file mode 100644 index 000000000..193a320eb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/runpy.pyi @@ -0,0 +1,17 @@ +from typing import Any + +class _TempModule: + mod_name = ... # type: Any + module = ... # type: Any + def __init__(self, mod_name): ... + def __enter__(self): ... + def __exit__(self, *args): ... + +class _ModifiedArgv0: + value = ... # type: Any + def __init__(self, value): ... + def __enter__(self): ... + def __exit__(self, *args): ... + +def run_module(mod_name, init_globals=None, run_name=None, alter_sys=False): ... +def run_path(path_name, init_globals=None, run_name=None): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sets.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sets.pyi new file mode 100644 index 000000000..a68994f2f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sets.pyi @@ -0,0 +1,61 @@ +# Stubs for sets (Python 2) +from typing import Any, Callable, Hashable, Iterable, Iterator, MutableMapping, Optional, TypeVar, Union + +_T = TypeVar('_T') +_Setlike = Union[BaseSet[_T], Iterable[_T]] +_SelfT = TypeVar('_SelfT', bound=BaseSet) + +class BaseSet(Iterable[_T]): + def __init__(self) -> None: ... + def __len__(self) -> int: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __iter__(self) -> Iterator[_T]: ... + def __cmp__(self, other: Any) -> int: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + def copy(self: _SelfT) -> _SelfT: ... + def __copy__(self: _SelfT) -> _SelfT: ... + def __deepcopy__(self: _SelfT, memo: MutableMapping[int, BaseSet[_T]]) -> _SelfT: ... + def __or__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def union(self: _SelfT, other: _Setlike) -> _SelfT: ... + def __and__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def intersection(self: _SelfT, other: _Setlike) -> _SelfT: ... + def __xor__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def symmetric_difference(self: _SelfT, other: _Setlike) -> _SelfT: ... + def __sub__(self: _SelfT, other: BaseSet[_T]) -> _SelfT: ... + def difference(self: _SelfT, other: _Setlike) -> _SelfT: ... + def __contains__(self, element: Any) -> bool: ... + def issubset(self, other: BaseSet[_T]) -> bool: ... + def issuperset(self, other: BaseSet[_T]) -> bool: ... + def __le__(self, other: BaseSet[_T]) -> bool: ... + def __ge__(self, other: BaseSet[_T]) -> bool: ... + def __lt__(self, other: BaseSet[_T]) -> bool: ... + def __gt__(self, other: BaseSet[_T]) -> bool: ... + +class ImmutableSet(BaseSet[_T], Hashable): + def __init__(self, iterable: Optional[_Setlike] = ...) -> None: ... + def __hash__(self) -> int: ... + +class Set(BaseSet[_T]): + def __init__(self, iterable: Optional[_Setlike] = ...) -> None: ... + def __ior__(self, other: BaseSet[_T]) -> Set: ... + def union_update(self, other: _Setlike) -> None: ... + def __iand__(self, other: BaseSet[_T]) -> Set: ... + def intersection_update(self, other: _Setlike) -> None: ... + def __ixor__(self, other: BaseSet[_T]) -> Set: ... + def symmetric_difference_update(self, other: _Setlike) -> None: ... + def __isub__(self, other: BaseSet[_T]) -> Set: ... + def difference_update(self, other: _Setlike) -> None: ... + def update(self, iterable: _Setlike) -> None: ... + def clear(self) -> None: ... + def add(self, element: _T) -> None: ... + def remove(self, element: _T) -> None: ... + def discard(self, element: _T) -> None: ... + def pop(self) -> _T: ... + def __as_immutable__(self) -> ImmutableSet[_T]: ... + def __as_temporarily_immutable__(self) -> _TemporarilyImmutableSet[_T]: ... + +class _TemporarilyImmutableSet(BaseSet[_T]): + def __init__(self, set: BaseSet[_T]) -> None: ... + def __hash__(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sha.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sha.pyi new file mode 100644 index 000000000..f1606fa8d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sha.pyi @@ -0,0 +1,11 @@ +# Stubs for Python 2.7 sha stdlib module + +class sha(object): + def update(self, arg: str) -> None: ... + def digest(self) -> str: ... + def hexdigest(self) -> str: ... + def copy(self) -> sha: ... + +def new(string: str = ...) -> sha: ... +blocksize = 0 +digest_size = 0 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/shelve.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/shelve.pyi new file mode 100644 index 000000000..d7d9b8c60 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/shelve.pyi @@ -0,0 +1,33 @@ +from typing import Any, Dict, Iterator, List, Optional, Tuple +import collections + + +class Shelf(collections.MutableMapping): + def __init__(self, dict: Dict[Any, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def keys(self) -> List[Any]: ... + def __len__(self) -> int: ... + def has_key(self, key: Any) -> bool: ... + def __contains__(self, key: Any) -> bool: ... + def get(self, key: Any, default: Any = ...) -> Any: ... + def __getitem__(self, key: Any) -> Any: ... + def __setitem__(self, key: Any, value: Any) -> None: ... + def __delitem__(self, key: Any) -> None: ... + def __enter__(self) -> Shelf: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... + def close(self) -> None: ... + def __del__(self) -> None: ... + def sync(self) -> None: ... + +class BsdDbShelf(Shelf): + def __init__(self, dict: Dict[Any, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... + def set_location(self, key: Any) -> Tuple[str, Any]: ... + def next(self) -> Tuple[str, Any]: ... + def previous(self) -> Tuple[str, Any]: ... + def first(self) -> Tuple[str, Any]: ... + def last(self) -> Tuple[str, Any]: ... + +class DbfilenameShelf(Shelf): + def __init__(self, filename: str, flag: str = ..., protocol: Optional[int] = ..., writeback: bool = ...) -> None: ... + +def open(filename: str, flag: str = ..., protocol: Optional[int] = ..., writeback: bool = ...) -> DbfilenameShelf: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/shlex.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/shlex.pyi new file mode 100644 index 000000000..4b80fb641 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/shlex.pyi @@ -0,0 +1,27 @@ +from typing import Optional, List, Any, IO + +def split(s: Optional[str], comments: bool = ..., posix: bool = ...) -> List[str]: ... + +class shlex: + def __init__(self, instream: IO[Any] = ..., infile: IO[Any] = ..., posix: bool = ...) -> None: ... + def get_token(self) -> Optional[str]: ... + def push_token(self, _str: str) -> None: ... + def read_token(self) -> str: ... + def sourcehook(self, filename: str) -> None: ... + def push_source(self, stream: IO[Any], filename: str = ...) -> None: ... + def pop_source(self) -> IO[Any]: ... + def error_leader(self, file: str = ..., line: int = ...) -> str: ... + + commenters = ... # type: str + wordchars = ... # type: str + whitespace = ... # type: str + escape = ... # type: str + quotes = ... # type: str + escapedquotes = ... # type: str + whitespace_split = ... # type: bool + infile = ... # type: IO[Any] + source = ... # type: Optional[str] + debug = ... # type: int + lineno = ... # type: int + token = ... # type: Any + eof = ... # type: Optional[str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/signal.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/signal.pyi new file mode 100644 index 000000000..cda4c65ec --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/signal.pyi @@ -0,0 +1,71 @@ +from typing import Callable, Any, Tuple, Union +from types import FrameType + +SIG_DFL: int = ... +SIG_IGN: int = ... + +ITIMER_REAL: int = ... +ITIMER_VIRTUAL: int = ... +ITIMER_PROF: int = ... + +NSIG: int = ... + +SIGABRT: int = ... +SIGALRM: int = ... +SIGBREAK: int = ... # Windows +SIGBUS: int = ... +SIGCHLD: int = ... +SIGCLD: int = ... +SIGCONT: int = ... +SIGEMT: int = ... +SIGFPE: int = ... +SIGHUP: int = ... +SIGILL: int = ... +SIGINFO: int = ... +SIGINT: int = ... +SIGIO: int = ... +SIGIOT: int = ... +SIGKILL: int = ... +SIGPIPE: int = ... +SIGPOLL: int = ... +SIGPROF: int = ... +SIGPWR: int = ... +SIGQUIT: int = ... +SIGRTMAX: int = ... +SIGRTMIN: int = ... +SIGSEGV: int = ... +SIGSTOP: int = ... +SIGSYS: int = ... +SIGTERM: int = ... +SIGTRAP: int = ... +SIGTSTP: int = ... +SIGTTIN: int = ... +SIGTTOU: int = ... +SIGURG: int = ... +SIGUSR1: int = ... +SIGUSR2: int = ... +SIGVTALRM: int = ... +SIGWINCH: int = ... +SIGXCPU: int = ... +SIGXFSZ: int = ... + +# Windows +CTRL_C_EVENT: int = ... +CTRL_BREAK_EVENT: int = ... + +class ItimerError(IOError): ... + +_HANDLER = Union[Callable[[int, FrameType], None], int, None] + +def alarm(time: int) -> int: ... +def getsignal(signalnum: int) -> _HANDLER: ... +def pause() -> None: ... +def setitimer(which: int, seconds: float, interval: float = ...) -> Tuple[float, float]: ... +def getitimer(which: int) -> Tuple[float, float]: ... +def set_wakeup_fd(fd: int) -> int: ... +def siginterrupt(signalnum: int, flag: bool) -> None: + raise RuntimeError() +def signal(signalnum: int, handler: _HANDLER) -> _HANDLER: + raise RuntimeError() +def default_int_handler(signum: int, frame: FrameType) -> None: + raise KeyboardInterrupt() diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/smtplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/smtplib.pyi new file mode 100644 index 000000000..76bdcb459 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/smtplib.pyi @@ -0,0 +1,86 @@ +from typing import Any + +class SMTPException(Exception): ... +class SMTPServerDisconnected(SMTPException): ... + +class SMTPResponseException(SMTPException): + smtp_code = ... # type: Any + smtp_error = ... # type: Any + args = ... # type: Any + def __init__(self, code, msg) -> None: ... + +class SMTPSenderRefused(SMTPResponseException): + smtp_code = ... # type: Any + smtp_error = ... # type: Any + sender = ... # type: Any + args = ... # type: Any + def __init__(self, code, msg, sender) -> None: ... + +class SMTPRecipientsRefused(SMTPException): + recipients = ... # type: Any + args = ... # type: Any + def __init__(self, recipients) -> None: ... + +class SMTPDataError(SMTPResponseException): ... +class SMTPConnectError(SMTPResponseException): ... +class SMTPHeloError(SMTPResponseException): ... +class SMTPAuthenticationError(SMTPResponseException): ... + +def quoteaddr(addr): ... +def quotedata(data): ... + +class SSLFakeFile: + sslobj = ... # type: Any + def __init__(self, sslobj) -> None: ... + def readline(self, size=...): ... + def close(self): ... + +class SMTP: + debuglevel = ... # type: Any + file = ... # type: Any + helo_resp = ... # type: Any + ehlo_msg = ... # type: Any + ehlo_resp = ... # type: Any + does_esmtp = ... # type: Any + default_port = ... # type: Any + timeout = ... # type: Any + esmtp_features = ... # type: Any + local_hostname = ... # type: Any + def __init__(self, host: str = ..., port: int = ..., local_hostname=..., timeout=...) -> None: ... + def set_debuglevel(self, debuglevel): ... + sock = ... # type: Any + def connect(self, host=..., port=...): ... + def send(self, str): ... + def putcmd(self, cmd, args=...): ... + def getreply(self): ... + def docmd(self, cmd, args=...): ... + def helo(self, name=...): ... + def ehlo(self, name=...): ... + def has_extn(self, opt): ... + def help(self, args=...): ... + def rset(self): ... + def noop(self): ... + def mail(self, sender, options=...): ... + def rcpt(self, recip, options=...): ... + def data(self, msg): ... + def verify(self, address): ... + vrfy = ... # type: Any + def expn(self, address): ... + def ehlo_or_helo_if_needed(self): ... + def login(self, user, password): ... + def starttls(self, keyfile=..., certfile=...): ... + def sendmail(self, from_addr, to_addrs, msg, mail_options=..., rcpt_options=...): ... + def close(self): ... + def quit(self): ... + +class SMTP_SSL(SMTP): + default_port = ... # type: Any + keyfile = ... # type: Any + certfile = ... # type: Any + def __init__(self, host=..., port=..., local_hostname=..., keyfile=..., certfile=..., timeout=...) -> None: ... + +class LMTP(SMTP): + ehlo_msg = ... # type: Any + def __init__(self, host=..., port=..., local_hostname=...) -> None: ... + sock = ... # type: Any + def connect(self, host=..., port=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/spwd.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/spwd.pyi new file mode 100644 index 000000000..1d5899031 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/spwd.pyi @@ -0,0 +1,14 @@ +from typing import List, NamedTuple + +struct_spwd = NamedTuple("struct_spwd", [("sp_nam", str), + ("sp_pwd", str), + ("sp_lstchg", int), + ("sp_min", int), + ("sp_max", int), + ("sp_warn", int), + ("sp_inact", int), + ("sp_expire", int), + ("sp_flag", int)]) + +def getspall() -> List[struct_spwd]: ... +def getspnam(name: str) -> struct_spwd: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sre_constants.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sre_constants.pyi new file mode 100644 index 000000000..4404873f6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sre_constants.pyi @@ -0,0 +1,94 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/sre_constants.py + +from typing import Dict, List, TypeVar + +MAGIC = ... # type: int +MAXREPEAT = ... # type: int + +class error(Exception): ... + +FAILURE = ... # type: str +SUCCESS = ... # type: str +ANY = ... # type: str +ANY_ALL = ... # type: str +ASSERT = ... # type: str +ASSERT_NOT = ... # type: str +AT = ... # type: str +BIGCHARSET = ... # type: str +BRANCH = ... # type: str +CALL = ... # type: str +CATEGORY = ... # type: str +CHARSET = ... # type: str +GROUPREF = ... # type: str +GROUPREF_IGNORE = ... # type: str +GROUPREF_EXISTS = ... # type: str +IN = ... # type: str +IN_IGNORE = ... # type: str +INFO = ... # type: str +JUMP = ... # type: str +LITERAL = ... # type: str +LITERAL_IGNORE = ... # type: str +MARK = ... # type: str +MAX_REPEAT = ... # type: str +MAX_UNTIL = ... # type: str +MIN_REPEAT = ... # type: str +MIN_UNTIL = ... # type: str +NEGATE = ... # type: str +NOT_LITERAL = ... # type: str +NOT_LITERAL_IGNORE = ... # type: str +RANGE = ... # type: str +REPEAT = ... # type: str +REPEAT_ONE = ... # type: str +SUBPATTERN = ... # type: str +MIN_REPEAT_ONE = ... # type: str +AT_BEGINNING = ... # type: str +AT_BEGINNING_LINE = ... # type: str +AT_BEGINNING_STRING = ... # type: str +AT_BOUNDARY = ... # type: str +AT_NON_BOUNDARY = ... # type: str +AT_END = ... # type: str +AT_END_LINE = ... # type: str +AT_END_STRING = ... # type: str +AT_LOC_BOUNDARY = ... # type: str +AT_LOC_NON_BOUNDARY = ... # type: str +AT_UNI_BOUNDARY = ... # type: str +AT_UNI_NON_BOUNDARY = ... # type: str +CATEGORY_DIGIT = ... # type: str +CATEGORY_NOT_DIGIT = ... # type: str +CATEGORY_SPACE = ... # type: str +CATEGORY_NOT_SPACE = ... # type: str +CATEGORY_WORD = ... # type: str +CATEGORY_NOT_WORD = ... # type: str +CATEGORY_LINEBREAK = ... # type: str +CATEGORY_NOT_LINEBREAK = ... # type: str +CATEGORY_LOC_WORD = ... # type: str +CATEGORY_LOC_NOT_WORD = ... # type: str +CATEGORY_UNI_DIGIT = ... # type: str +CATEGORY_UNI_NOT_DIGIT = ... # type: str +CATEGORY_UNI_SPACE = ... # type: str +CATEGORY_UNI_NOT_SPACE = ... # type: str +CATEGORY_UNI_WORD = ... # type: str +CATEGORY_UNI_NOT_WORD = ... # type: str +CATEGORY_UNI_LINEBREAK = ... # type: str +CATEGORY_UNI_NOT_LINEBREAK = ... # type: str + +_T = TypeVar('_T') +def makedict(list: List[_T]) -> Dict[_T, int]: ... + +OP_IGNORE = ... # type: Dict[str, str] +AT_MULTILINE = ... # type: Dict[str, str] +AT_LOCALE = ... # type: Dict[str, str] +AT_UNICODE = ... # type: Dict[str, str] +CH_LOCALE = ... # type: Dict[str, str] +CH_UNICODE = ... # type: Dict[str, str] +SRE_FLAG_TEMPLATE = ... # type: int +SRE_FLAG_IGNORECASE = ... # type: int +SRE_FLAG_LOCALE = ... # type: int +SRE_FLAG_MULTILINE = ... # type: int +SRE_FLAG_DOTALL = ... # type: int +SRE_FLAG_UNICODE = ... # type: int +SRE_FLAG_VERBOSE = ... # type: int +SRE_FLAG_DEBUG = ... # type: int +SRE_INFO_PREFIX = ... # type: int +SRE_INFO_LITERAL = ... # type: int +SRE_INFO_CHARSET = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sre_parse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sre_parse.pyi new file mode 100644 index 000000000..544a6182d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sre_parse.pyi @@ -0,0 +1,63 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/sre_parse.py + +from typing import Any, Dict, Iterable, List, Match, Optional, Pattern as _Pattern, Set, Tuple, Union + +SPECIAL_CHARS = ... # type: str +REPEAT_CHARS = ... # type: str +DIGITS = ... # type: Set +OCTDIGITS = ... # type: Set +HEXDIGITS = ... # type: Set +WHITESPACE = ... # type: Set +ESCAPES = ... # type: Dict[str, Tuple[str, int]] +CATEGORIES = ... # type: Dict[str, Union[Tuple[str, str], Tuple[str, List[Tuple[str, str]]]]] +FLAGS = ... # type: Dict[str, int] + +class Pattern: + flags = ... # type: int + open = ... # type: List[int] + groups = ... # type: int + groupdict = ... # type: Dict[str, int] + lookbehind = ... # type: int + def __init__(self) -> None: ... + def opengroup(self, name: str = ...) -> int: ... + def closegroup(self, gid: int) -> None: ... + def checkgroup(self, gid: int) -> bool: ... + + +_OpSubpatternType = Tuple[Optional[int], int, int, SubPattern] +_OpGroupRefExistsType = Tuple[int, SubPattern, SubPattern] +_OpInType = List[Tuple[str, int]] +_OpBranchType = Tuple[None, List[SubPattern]] +_AvType = Union[_OpInType, _OpBranchType, Iterable[SubPattern], _OpGroupRefExistsType, _OpSubpatternType] +_CodeType = Union[str, _AvType] + +class SubPattern: + pattern = ... # type: str + data = ... # type: List[_CodeType] + width = ... # type: Optional[int] + def __init__(self, pattern, data: List[_CodeType] = ...) -> None: ... + def dump(self, level: int = ...) -> None: ... + def __len__(self) -> int: ... + def __delitem__(self, index: Union[int, slice]) -> None: ... + def __getitem__(self, index: Union[int, slice]) -> Union[SubPattern, _CodeType]: ... + def __setitem__(self, index: Union[int, slice], code: _CodeType): ... + def insert(self, index, code: _CodeType) -> None: ... + def append(self, code: _CodeType) -> None: ... + def getwidth(self) -> int: ... + +class Tokenizer: + string = ... # type: str + index = ... # type: int + def __init__(self, string: str) -> None: ... + def match(self, char: str, skip: int = ...) -> int: ... + def get(self) -> Optional[str]: ... + def tell(self) -> Tuple[int, Optional[str]]: ... + def seek(self, index: int) -> None: ... + +def isident(char: str) -> bool: ... +def isdigit(char: str) -> bool: ... +def isname(name: str) -> bool: ... +def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ... +_Template = Tuple[List[Tuple[int, int]], List[Optional[int]]] +def parse_template(source: str, pattern: _Pattern) -> _Template: ... +def expand_template(template: _Template, match: Match) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/stat.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/stat.pyi new file mode 100644 index 000000000..dd3418db9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/stat.pyi @@ -0,0 +1,59 @@ +def S_ISDIR(mode: int) -> bool: ... +def S_ISCHR(mode: int) -> bool: ... +def S_ISBLK(mode: int) -> bool: ... +def S_ISREG(mode: int) -> bool: ... +def S_ISFIFO(mode: int) -> bool: ... +def S_ISLNK(mode: int) -> bool: ... +def S_ISSOCK(mode: int) -> bool: ... + +def S_IMODE(mode: int) -> int: ... +def S_IFMT(mode: int) -> int: ... + +ST_MODE = 0 +ST_INO = 0 +ST_DEV = 0 +ST_NLINK = 0 +ST_UID = 0 +ST_GID = 0 +ST_SIZE = 0 +ST_ATIME = 0 +ST_MTIME = 0 +ST_CTIME = 0 +S_IFSOCK = 0 +S_IFLNK = 0 +S_IFREG = 0 +S_IFBLK = 0 +S_IFDIR = 0 +S_IFCHR = 0 +S_IFIFO = 0 +S_ISUID = 0 +S_ISGID = 0 +S_ISVTX = 0 +S_IRWXU = 0 +S_IRUSR = 0 +S_IWUSR = 0 +S_IXUSR = 0 +S_IRWXG = 0 +S_IRGRP = 0 +S_IWGRP = 0 +S_IXGRP = 0 +S_IRWXO = 0 +S_IROTH = 0 +S_IWOTH = 0 +S_IXOTH = 0 +S_ENFMT = 0 +S_IREAD = 0 +S_IWRITE = 0 +S_IEXEC = 0 +UF_NODUMP = 0 +UF_IMMUTABLE = 0 +UF_APPEND = 0 +UF_OPAQUE = 0 +UF_NOUNLINK = 0 +UF_COMPRESSED = 0 +UF_HIDDEN = 0 +SF_ARCHIVED = 0 +SF_IMMUTABLE = 0 +SF_APPEND = 0 +SF_NOUNLINK = 0 +SF_SNAPSHOT = 0 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/string.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/string.pyi new file mode 100644 index 000000000..751fd28a0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/string.pyi @@ -0,0 +1,74 @@ +# Stubs for string + +# Based on http://docs.python.org/3.2/library/string.html + +from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable, AnyStr + +ascii_letters = ... # type: str +ascii_lowercase = ... # type: str +ascii_uppercase = ... # type: str +digits = ... # type: str +hexdigits = ... # type: str +letters = ... # type: str +lowercase = ... # type: str +octdigits = ... # type: str +punctuation = ... # type: str +printable = ... # type: str +uppercase = ... # type: str +whitespace = ... # type: str + +def capwords(s: AnyStr, sep: AnyStr = ...) -> AnyStr: ... +# TODO: originally named 'from' +def maketrans(_from: str, to: str) -> str: ... +def atof(s: unicode) -> float: ... +def atoi(s: unicode, base: int = ...) -> int: ... +def atol(s: unicode, base: int = ...) -> int: ... +def capitalize(word: AnyStr) -> AnyStr: ... +def find(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def rfind(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def index(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def rindex(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def count(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def lower(s: AnyStr) -> AnyStr: ... +def split(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def rsplit(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def splitfields(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def join(words: Iterable[AnyStr], sep: AnyStr = ...) -> AnyStr: ... +def joinfields(word: Iterable[AnyStr], sep: AnyStr = ...) -> AnyStr: ... +def lstrip(s: AnyStr, chars: AnyStr = ...) -> AnyStr: ... +def rstrip(s: AnyStr, chars: AnyStr = ...) -> AnyStr: ... +def strip(s: AnyStr, chars: AnyStr = ...) -> AnyStr: ... +def swapcase(s: AnyStr) -> AnyStr: ... +def translate(s: str, table: str, deletechars: str = ...) -> str: ... +def upper(s: AnyStr) -> AnyStr: ... +def ljust(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def rjust(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def center(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def zfill(s: AnyStr, width: int) -> AnyStr: ... +def replace(s: AnyStr, old: AnyStr, new: AnyStr, maxreplace: int = ...) -> AnyStr: ... + +class Template(object): + # TODO: Unicode support? + template = ... # type: str + + def __init__(self, template: str) -> None: ... + def substitute(self, mapping: Mapping[str, str] = ..., **kwds: str) -> str: ... + def safe_substitute(self, mapping: Mapping[str, str] = ..., + **kwds: str) -> str: ... + +# TODO(MichalPokorny): This is probably badly and/or loosely typed. +class Formatter(object): + def format(self, format_string: str, *args, **kwargs) -> str: ... + def vformat(self, format_string: str, args: Sequence[Any], + kwargs: Mapping[str, Any]) -> str: ... + def parse(self, format_string: str) -> Iterable[Tuple[str, str, str, str]]: ... + def get_field(self, field_name: str, args: Sequence[Any], + kwargs: Mapping[str, Any]) -> Any: ... + def get_value(self, key: Union[int, str], args: Sequence[Any], + kwargs: Mapping[str, Any]) -> Any: + raise IndexError() + raise KeyError() + def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], + kwargs: Mapping[str, Any]) -> None: ... + def format_field(self, value: Any, format_spec: str) -> Any: ... + def convert_field(self, value: Any, conversion: str) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/stringold.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/stringold.pyi new file mode 100644 index 000000000..7d31ebe5b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/stringold.pyi @@ -0,0 +1,46 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/stringold.py +from typing import AnyStr, Iterable, List, Optional, Type + +whitespace = ... # type: str +lowercase = ... # type: str +uppercase = ... # type: str +letters = ... # type: str +digits = ... # type: str +hexdigits = ... # type: str +octdigits = ... # type: str +_idmap = ... # type: str +_idmapL = ... # type: Optional[List[str]] +index_error = ValueError +atoi_error = ValueError +atof_error = ValueError +atol_error = ValueError + + +def lower(s: AnyStr) -> AnyStr: ... +def upper(s: AnyStr) -> AnyStr: ... +def swapcase(s: AnyStr) -> AnyStr: ... +def strip(s: AnyStr) -> AnyStr: ... +def lstrip(s: AnyStr) -> AnyStr: ... +def rstrip(s: AnyStr) -> AnyStr: ... +def split(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def splitfields(s: AnyStr, sep: AnyStr = ..., maxsplit: int = ...) -> List[AnyStr]: ... +def join(words: Iterable[AnyStr], sep: AnyStr = ...) -> AnyStr: ... +def joinfields(words: Iterable[AnyStr], sep: AnyStr = ...) -> AnyStr: ... +def index(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def rindex(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def count(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def find(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def rfind(s: unicode, sub: unicode, start: int = ..., end: int = ...) -> int: ... +def atof(s: unicode) -> float: ... +def atoi(s: unicode, base: int = ...) -> int: ... +def atol(s: unicode, base: int = ...) -> long: ... +def ljust(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def rjust(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def center(s: AnyStr, width: int, fillchar: AnyStr = ...) -> AnyStr: ... +def zfill(s: AnyStr, width: int) -> AnyStr: ... +def expandtabs(s: AnyStr, tabsize: int = ...) -> AnyStr: ... +def translate(s: str, table: str, deletions: str = ...) -> str: ... +def capitalize(s: AnyStr) -> AnyStr: ... +def capwords(s: AnyStr, sep: AnyStr = ...) -> AnyStr: ... +def maketrans(fromstr: str, tostr: str) -> str: ... +def replace(s: AnyStr, old: AnyStr, new: AnyStr, maxreplace: int = ...) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/strop.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/strop.pyi new file mode 100644 index 000000000..736c716a3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/strop.pyi @@ -0,0 +1,72 @@ +"""Stub file for the 'strop' module.""" + +from typing import List, Sequence + +lowercase = ... # type: str +uppercase = ... # type: str +whitespace = ... # type: str + +def atof(a: str) -> float: + raise DeprecationWarning() + +def atoi(a: str, base: int = ...) -> int: + raise DeprecationWarning() + +def atol(a: str, base: int = ...) -> long: + raise DeprecationWarning() + +def capitalize(s: str) -> str: + raise DeprecationWarning() + +def count(s: str, sub: str, start: int = ..., end: int = ...) -> int: + raise DeprecationWarning() + +def expandtabs(string: str, tabsize: int = ...) -> str: + raise DeprecationWarning() + raise OverflowError() + +def find(s: str, sub: str, start: int = ..., end: int = ...) -> int: + raise DeprecationWarning() + +def join(list: Sequence[str], sep: str = ...) -> str: + raise DeprecationWarning() + raise OverflowError() + +def joinfields(list: Sequence[str], sep: str = ...) -> str: + raise DeprecationWarning() + raise OverflowError() + +def lower(s: str) -> str: + raise DeprecationWarning() + +def lstrip(s: str) -> str: + raise DeprecationWarning() + +def maketrans(frm: str, to: str) -> str: ... + +def replace(s: str, old: str, new: str, maxsplit: int = ...) -> str: + raise DeprecationWarning() + +def rfind(s: str, sub: str, start: int = ..., end: int = ...) -> int: + raise DeprecationWarning() + +def rstrip(s: str) -> str: + raise DeprecationWarning() + +def split(s: str, sep: str, maxsplit: int = ...) -> List[str]: + raise DeprecationWarning() + +def splitfields(s: str, sep: str, maxsplit: int = ...) -> List[str]: + raise DeprecationWarning() + +def strip(s: str) -> str: + raise DeprecationWarning() + +def swapcase(s: str) -> str: + raise DeprecationWarning() + +def translate(s: str, table: str, deletechars: str = ...) -> str: + raise DeprecationWarning() + +def upper(s: str) -> str: + raise DeprecationWarning() diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/subprocess.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/subprocess.pyi new file mode 100644 index 000000000..047b6bd72 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/subprocess.pyi @@ -0,0 +1,115 @@ +# Stubs for subprocess + +# Based on http://docs.python.org/2/library/subprocess.html and Python 3 stub + +from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Union, Optional, List, Text + +_FILE = Union[None, int, IO[Any]] +_TXT = Union[bytes, Text] +_CMD = Union[_TXT, Sequence[_TXT]] +_ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] + +# Same args as Popen.__init__ +def call(args: _CMD, + bufsize: int = ..., + executable: _TXT = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: _TXT = ..., + env: _ENV = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ...) -> int: ... + +def check_call(args: _CMD, + bufsize: int = ..., + executable: _TXT = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: _TXT = ..., + env: _ENV = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ...) -> int: ... + +# Same args as Popen.__init__ except for stdout +def check_output(args: _CMD, + bufsize: int = ..., + executable: _TXT = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: _TXT = ..., + env: _ENV = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ...) -> bytes: ... + +PIPE = ... # type: int +STDOUT = ... # type: int + +class CalledProcessError(Exception): + returncode = 0 + # morally: _CMD + cmd = ... # type: Any + # morally: Optional[bytes] + output = ... # type: Any + + def __init__(self, + returncode: int, + cmd: _CMD, + output: Optional[bytes] = ...) -> None: ... + +class Popen: + stdin = ... # type: Optional[IO[Any]] + stdout = ... # type: Optional[IO[Any]] + stderr = ... # type: Optional[IO[Any]] + pid = 0 + returncode = 0 + + def __init__(self, + args: _CMD, + bufsize: int = ..., + executable: Optional[_TXT] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_TXT] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ...) -> None: ... + + def poll(self) -> int: ... + def wait(self) -> int: ... + # morally: -> Tuple[Optional[bytes], Optional[bytes]] + def communicate(self, input: Optional[_TXT] = ...) -> Tuple[Any, Any]: ... + def send_signal(self, signal: int) -> None: ... + def terminate(self) -> None: ... + def kill(self) -> None: ... + def __enter__(self) -> 'Popen': ... + def __exit__(self, type, value, traceback) -> bool: ... + +# Windows-only: STARTUPINFO etc. + +STD_INPUT_HANDLE = ... # type: Any +STD_OUTPUT_HANDLE = ... # type: Any +STD_ERROR_HANDLE = ... # type: Any +SW_HIDE = ... # type: Any +STARTF_USESTDHANDLES = ... # type: Any +STARTF_USESHOWWINDOW = ... # type: Any +CREATE_NEW_CONSOLE = ... # type: Any +CREATE_NEW_PROCESS_GROUP = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/symbol.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/symbol.pyi new file mode 100644 index 000000000..ef41c8129 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/symbol.pyi @@ -0,0 +1,91 @@ +# Stubs for symbol (Python 2) + +from typing import Dict + +single_input = ... # type: int +file_input = ... # type: int +eval_input = ... # type: int +decorator = ... # type: int +decorators = ... # type: int +decorated = ... # type: int +funcdef = ... # type: int +parameters = ... # type: int +varargslist = ... # type: int +fpdef = ... # type: int +fplist = ... # type: int +stmt = ... # type: int +simple_stmt = ... # type: int +small_stmt = ... # type: int +expr_stmt = ... # type: int +augassign = ... # type: int +print_stmt = ... # type: int +del_stmt = ... # type: int +pass_stmt = ... # type: int +flow_stmt = ... # type: int +break_stmt = ... # type: int +continue_stmt = ... # type: int +return_stmt = ... # type: int +yield_stmt = ... # type: int +raise_stmt = ... # type: int +import_stmt = ... # type: int +import_name = ... # type: int +import_from = ... # type: int +import_as_name = ... # type: int +dotted_as_name = ... # type: int +import_as_names = ... # type: int +dotted_as_names = ... # type: int +dotted_name = ... # type: int +global_stmt = ... # type: int +exec_stmt = ... # type: int +assert_stmt = ... # type: int +compound_stmt = ... # type: int +if_stmt = ... # type: int +while_stmt = ... # type: int +for_stmt = ... # type: int +try_stmt = ... # type: int +with_stmt = ... # type: int +with_item = ... # type: int +except_clause = ... # type: int +suite = ... # type: int +testlist_safe = ... # type: int +old_test = ... # type: int +old_lambdef = ... # type: int +test = ... # type: int +or_test = ... # type: int +and_test = ... # type: int +not_test = ... # type: int +comparison = ... # type: int +comp_op = ... # type: int +expr = ... # type: int +xor_expr = ... # type: int +and_expr = ... # type: int +shift_expr = ... # type: int +arith_expr = ... # type: int +term = ... # type: int +factor = ... # type: int +power = ... # type: int +atom = ... # type: int +listmaker = ... # type: int +testlist_comp = ... # type: int +lambdef = ... # type: int +trailer = ... # type: int +subscriptlist = ... # type: int +subscript = ... # type: int +sliceop = ... # type: int +exprlist = ... # type: int +testlist = ... # type: int +dictorsetmaker = ... # type: int +classdef = ... # type: int +arglist = ... # type: int +argument = ... # type: int +list_iter = ... # type: int +list_for = ... # type: int +list_if = ... # type: int +comp_iter = ... # type: int +comp_for = ... # type: int +comp_if = ... # type: int +testlist1 = ... # type: int +encoding_decl = ... # type: int +yield_expr = ... # type: int + +sym_name = ... # type: Dict[int, str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sys.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sys.pyi new file mode 100644 index 000000000..48c3436d6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/sys.pyi @@ -0,0 +1,137 @@ +"""Stubs for the 'sys' module.""" + +from typing import ( + IO, NoReturn, Union, List, Sequence, Any, Dict, Tuple, BinaryIO, Optional, + Callable, overload, Text, Type, +) +from types import FrameType, ModuleType, TracebackType, ClassType + +class _flags: + bytes_warning = ... # type: int + debug = ... # type: int + division_new = ... # type: int + division_warning = ... # type: int + dont_write_bytecode = ... # type: int + hash_randomization = ... # type: int + ignore_environment = ... # type: int + inspect = ... # type: int + interactive = ... # type: int + no_site = ... # type: int + no_user_site = ... # type: int + optimize = ... # type: int + py3k_warning = ... # type: int + tabcheck = ... # type: int + unicode = ... # type: int + verbose = ... # type: int + +class _float_info: + max = ... # type: float + max_exp = ... # type: int + max_10_exp = ... # type: int + min = ... # type: float + min_exp = ... # type: int + min_10_exp = ... # type: int + dig = ... # type: int + mant_dig = ... # type: int + epsilon = ... # type: float + radix = ... # type: int + rounds = ... # type: int + +class _version_info(Tuple[int, int, int, str, int]): + major = 0 + minor = 0 + micro = 0 + releaselevel = ... # type: str + serial = 0 + +_mercurial = ... # type: Tuple[str, str, str] +api_version = ... # type: int +argv = ... # type: List[str] +builtin_module_names = ... # type: Tuple[str, ...] +byteorder = ... # type: str +copyright = ... # type: str +dont_write_bytecode = ... # type: bool +exec_prefix = ... # type: str +executable = ... # type: str +flags = ... # type: _flags +float_repr_style = ... # type: str +hexversion = ... # type: int +long_info = ... # type: object +maxint = ... # type: int +maxsize = ... # type: int +maxunicode = ... # type: int +modules = ... # type: Dict[str, Any] +path = ... # type: List[str] +platform = ... # type: str +prefix = ... # type: str +py3kwarning = ... # type: bool +__stderr__ = ... # type: IO[str] +__stdin__ = ... # type: IO[str] +__stdout__ = ... # type: IO[str] +stderr = ... # type: IO[str] +stdin = ... # type: IO[str] +stdout = ... # type: IO[str] +subversion = ... # type: Tuple[str, str, str] +version = ... # type: str +warnoptions = ... # type: object +float_info = ... # type: _float_info +version_info = ... # type: _version_info +ps1 = ... # type: str +ps2 = ... # type: str +last_type = ... # type: type +last_value = ... # type: BaseException +last_traceback = ... # type: TracebackType +# TODO precise types +meta_path = ... # type: List[Any] +path_hooks = ... # type: List[Any] +path_importer_cache = ... # type: Dict[str, Any] +displayhook = ... # type: Optional[Callable[[int], None]] +excepthook = ... # type: Optional[Callable[[type, BaseException, TracebackType], None]] +exc_type = ... # type: Optional[type] +exc_value = ... # type: Union[BaseException, ClassType] +exc_traceback = ... # type: TracebackType + +class _WindowsVersionType: + major = ... # type: Any + minor = ... # type: Any + build = ... # type: Any + platform = ... # type: Any + service_pack = ... # type: Any + service_pack_major = ... # type: Any + service_pack_minor = ... # type: Any + suite_mask = ... # type: Any + product_type = ... # type: Any + +def getwindowsversion() -> _WindowsVersionType: ... + +def _clear_type_cache() -> None: ... +def _current_frames() -> Dict[int, FrameType]: ... +def _getframe(depth: int = ...) -> FrameType: ... +def call_tracing(fn: Any, args: Any) -> Any: ... +def __displayhook__(value: int) -> None: ... +def __excepthook__(type_: type, value: BaseException, traceback: TracebackType) -> None: ... +def exc_clear() -> None: + raise DeprecationWarning() +# TODO should be a union of tuple, see mypy#1178 +def exc_info() -> Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]]: ... + +# sys.exit() accepts an optional argument of anything printable +def exit(arg: Any = ...) -> NoReturn: + raise SystemExit() +def getcheckinterval() -> int: ... # deprecated +def getdefaultencoding() -> str: ... +def getdlopenflags() -> int: ... +def getfilesystemencoding() -> str: ... # In practice, never returns None +def getrefcount(arg: Any) -> int: ... +def getrecursionlimit() -> int: ... +def getsizeof(obj: object, default: int = ...) -> int: ... +def getprofile() -> Optional[Any]: ... +def gettrace() -> Optional[Any]: ... +def setcheckinterval(interval: int) -> None: ... # deprecated +def setdlopenflags(n: int) -> None: ... +def setdefaultencoding(encoding: Text) -> None: ... # only exists after reload(sys) +def setprofile(profilefunc: Any) -> None: ... # TODO type +def setrecursionlimit(limit: int) -> None: ... +def settrace(tracefunc: Any) -> None: ... # TODO type diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/tempfile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/tempfile.pyi new file mode 100644 index 000000000..c19dbf179 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/tempfile.pyi @@ -0,0 +1,111 @@ +from typing import Tuple, IO, Union, AnyStr, Any, overload, Iterator, List, Iterable, Optional +from thread import LockType +from random import Random + +TMP_MAX = ... # type: int +tempdir = ... # type: str +template = ... # type: str +_name_sequence = ... # type: Optional[_RandomNameSequence] + +class _RandomNameSequence: + characters: str = ... + mutex: LockType + @property + def rng(self) -> Random: ... + def __iter__(self) -> _RandomNameSequence: ... + def next(self) -> str: ... + # from os.path: + def normcase(self, path: AnyStr) -> AnyStr: ... + +class _TemporaryFileWrapper(IO[str]): + delete: bool + file: IO + name: Any + def __init__(self, file: IO, name: Any, delete: bool = ...) -> None: ... + def __del__(self) -> None: ... + def __enter__(self) -> _TemporaryFileWrapper: ... + def __exit__(self, exc, value, tb) -> bool: ... + def __getattr__(self, name: unicode) -> Any: ... + def close(self) -> None: ... + def unlink(self, path: unicode) -> None: ... + # These methods don't exist directly on this object, but + # are delegated to the underlying IO object through __getattr__. + # We need to add them here so that this class is concrete. + def __iter__(self) -> Iterator[str]: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def readable(self) -> bool: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def write(self, s: str) -> int: ... + def writelines(self, lines: Iterable[str]) -> None: ... + + +# TODO text files + +def TemporaryFile( + mode: Union[bytes, unicode] = ..., + bufsize: int = ..., + suffix: Union[bytes, unicode] = ..., + prefix: Union[bytes, unicode] = ..., + dir: Union[bytes, unicode] = ... +) -> _TemporaryFileWrapper: + ... + +def NamedTemporaryFile( + mode: Union[bytes, unicode] = ..., + bufsize: int = ..., + suffix: Union[bytes, unicode] = ..., + prefix: Union[bytes, unicode] = ..., + dir: Union[bytes, unicode] = ..., + delete: bool = ... +) -> _TemporaryFileWrapper: + ... + +def SpooledTemporaryFile( + max_size: int = ..., + mode: Union[bytes, unicode] = ..., + buffering: int = ..., + suffix: Union[bytes, unicode] = ..., + prefix: Union[bytes, unicode] = ..., + dir: Union[bytes, unicode] = ... +) -> _TemporaryFileWrapper: + ... + +class TemporaryDirectory: + name = ... # type: Any # Can be str or unicode + def __init__(self, + suffix: Union[bytes, unicode] = ..., + prefix: Union[bytes, unicode] = ..., + dir: Union[bytes, unicode] = ...) -> None: ... + def cleanup(self) -> None: ... + def __enter__(self) -> Any: ... # Can be str or unicode + def __exit__(self, type, value, traceback) -> bool: ... + +@overload +def mkstemp() -> Tuple[int, str]: ... +@overload +def mkstemp(suffix: AnyStr = ..., prefix: AnyStr = ..., dir: Optional[AnyStr] = ..., + text: bool = ...) -> Tuple[int, AnyStr]: ... +@overload +def mkdtemp() -> str: ... +@overload +def mkdtemp(suffix: AnyStr = ..., prefix: AnyStr = ..., dir: Optional[AnyStr] = ...) -> AnyStr: ... +@overload +def mktemp() -> str: ... +@overload +def mktemp(suffix: AnyStr = ..., prefix: AnyStr = ..., dir: Optional[AnyStr] = ...) -> AnyStr: ... +def gettempdir() -> str: ... +def gettempprefix() -> str: ... + +def _candidate_tempdir_list() -> List[str]: ... +def _get_candidate_names() -> Optional[_RandomNameSequence]: ... +def _get_default_tempdir() -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/textwrap.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/textwrap.pyi new file mode 100644 index 000000000..4cae3a1bc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/textwrap.pyi @@ -0,0 +1,65 @@ +from typing import AnyStr, List, Dict, Pattern + +class TextWrapper(object): + width: int = ... + initial_indent: str = ... + subsequent_indent: str = ... + expand_tabs: bool = ... + replace_whitespace: bool = ... + fix_sentence_endings: bool = ... + drop_whitespace: bool = ... + break_long_words: bool = ... + break_on_hyphens: bool = ... + + # Attributes not present in documentation + sentence_end_re: Pattern[str] = ... + wordsep_re: Pattern[str] = ... + wordsep_simple_re: Pattern[str] = ... + whitespace_trans: str = ... + unicode_whitespace_trans: Dict[int, int] = ... + uspace: int = ... + x: int = ... + + def __init__( + self, + width: int = ..., + initial_indent: str = ..., + subsequent_indent: str = ..., + expand_tabs: bool = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + drop_whitespace: bool = ..., + break_on_hyphens: bool = ...) -> None: + ... + + def wrap(self, text: AnyStr) -> List[AnyStr]: ... + def fill(self, text: AnyStr) -> AnyStr: ... + +def wrap( + text: AnyStr, + width: int = ..., + initial_indent: AnyStr = ..., + subsequent_indent: AnyStr = ..., + expand_tabs: bool = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + drop_whitespace: bool = ..., + break_on_hyphens: bool = ...) -> List[AnyStr]: + ... + +def fill( + text: AnyStr, + width: int =..., + initial_indent: AnyStr = ..., + subsequent_indent: AnyStr = ..., + expand_tabs: bool = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + drop_whitespace: bool = ..., + break_on_hyphens: bool = ...) -> AnyStr: + ... + +def dedent(text: AnyStr) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/thread.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/thread.pyi new file mode 100644 index 000000000..eb4e6d6d3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/thread.pyi @@ -0,0 +1,30 @@ +"""Stubs for the "thread" module.""" +from typing import Callable, Any + +def _count() -> int: ... + +class error(Exception): ... + +class LockType: + def acquire(self, waitflag: int = ...) -> bool: ... + def acquire_lock(self, waitflag: int = ...) -> bool: ... + def release(self) -> None: ... + def release_lock(self) -> None: ... + def locked(self) -> bool: ... + def locked_lock(self) -> bool: ... + def __enter__(self) -> LockType: ... + def __exit__(self, typ: Any, value: Any, traceback: Any) -> None: ... + +class _local(object): ... +class _localdummy(object): ... + +def start_new(function: Callable[..., Any], args: Any, kwargs: Any = ...) -> int: ... +def start_new_thread(function: Callable[..., Any], args: Any, kwargs: Any = ...) -> int: ... +def interrupt_main() -> None: ... +def exit() -> None: + raise SystemExit() +def exit_thread() -> Any: + raise SystemExit() +def allocate_lock() -> LockType: ... +def get_ident() -> int: ... +def stack_size(size: int = ...) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/toaiff.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/toaiff.pyi new file mode 100644 index 000000000..77334c7f5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/toaiff.pyi @@ -0,0 +1,16 @@ +# Stubs for toaiff (Python 2) + +# Source: https://hg.python.org/cpython/file/2.7/Lib/toaiff.py +from pipes import Template +from typing import Dict, List + + +__all__: List[str] +table: Dict[str, Template] +t: Template +uncompress: Template + +class error(Exception): ... + +def toaiff(filename: str) -> str: ... +def _toaiff(filename: str, temps: List[str]) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/tokenize.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/tokenize.pyi new file mode 100644 index 000000000..c7ee7dba7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/tokenize.pyi @@ -0,0 +1,136 @@ +# Automatically generated by pytype, manually fixed up. May still contain errors. + +from typing import Any, Callable, Dict, Generator, Iterator, List, Tuple, Union, Iterable + +__author__ = ... # type: str +__credits__ = ... # type: str + +AMPER = ... # type: int +AMPEREQUAL = ... # type: int +AT = ... # type: int +BACKQUOTE = ... # type: int +Binnumber = ... # type: str +Bracket = ... # type: str +CIRCUMFLEX = ... # type: int +CIRCUMFLEXEQUAL = ... # type: int +COLON = ... # type: int +COMMA = ... # type: int +COMMENT = ... # type: int +Comment = ... # type: str +ContStr = ... # type: str +DEDENT = ... # type: int +DOT = ... # type: int +DOUBLESLASH = ... # type: int +DOUBLESLASHEQUAL = ... # type: int +DOUBLESTAR = ... # type: int +DOUBLESTAREQUAL = ... # type: int +Decnumber = ... # type: str +Double = ... # type: str +Double3 = ... # type: str +ENDMARKER = ... # type: int +EQEQUAL = ... # type: int +EQUAL = ... # type: int +ERRORTOKEN = ... # type: int +Expfloat = ... # type: str +Exponent = ... # type: str +Floatnumber = ... # type: str +Funny = ... # type: str +GREATER = ... # type: int +GREATEREQUAL = ... # type: int +Hexnumber = ... # type: str +INDENT = ... # type: int + +def ISEOF(x: int) -> bool: ... +def ISNONTERMINAL(x: int) -> bool: ... +def ISTERMINAL(x: int) -> bool: ... + +Ignore = ... # type: str +Imagnumber = ... # type: str +Intnumber = ... # type: str +LBRACE = ... # type: int +LEFTSHIFT = ... # type: int +LEFTSHIFTEQUAL = ... # type: int +LESS = ... # type: int +LESSEQUAL = ... # type: int +LPAR = ... # type: int +LSQB = ... # type: int +MINEQUAL = ... # type: int +MINUS = ... # type: int +NAME = ... # type: int +NEWLINE = ... # type: int +NL = ... # type: int +NOTEQUAL = ... # type: int +NT_OFFSET = ... # type: int +NUMBER = ... # type: int +N_TOKENS = ... # type: int +Name = ... # type: str +Number = ... # type: str +OP = ... # type: int +Octnumber = ... # type: str +Operator = ... # type: str +PERCENT = ... # type: int +PERCENTEQUAL = ... # type: int +PLUS = ... # type: int +PLUSEQUAL = ... # type: int +PlainToken = ... # type: str +Pointfloat = ... # type: str +PseudoExtras = ... # type: str +PseudoToken = ... # type: str +RBRACE = ... # type: int +RIGHTSHIFT = ... # type: int +RIGHTSHIFTEQUAL = ... # type: int +RPAR = ... # type: int +RSQB = ... # type: int +SEMI = ... # type: int +SLASH = ... # type: int +SLASHEQUAL = ... # type: int +STAR = ... # type: int +STAREQUAL = ... # type: int +STRING = ... # type: int +Single = ... # type: str +Single3 = ... # type: str +Special = ... # type: str +String = ... # type: str +TILDE = ... # type: int +Token = ... # type: str +Triple = ... # type: str +VBAR = ... # type: int +VBAREQUAL = ... # type: int +Whitespace = ... # type: str +chain = ... # type: type +double3prog = ... # type: type +endprogs = ... # type: Dict[str, Any] +pseudoprog = ... # type: type +single3prog = ... # type: type +single_quoted = ... # type: Dict[str, str] +t = ... # type: str +tabsize = ... # type: int +tok_name = ... # type: Dict[int, str] +tokenprog = ... # type: type +triple_quoted = ... # type: Dict[str, str] +x = ... # type: str + +_Pos = Tuple[int, int] +_TokenType = Tuple[int, str, _Pos, _Pos, str] + +def any(*args, **kwargs) -> str: ... +def generate_tokens(readline: Callable[[], str]) -> Generator[_TokenType, None, None]: ... +def group(*args: str) -> str: ... +def maybe(*args: str) -> str: ... +def printtoken(type: int, token: str, srow_scol: _Pos, erow_ecol: _Pos, line: str) -> None: ... +def tokenize(readline: Callable[[], str], tokeneater: Callable[[Tuple[int, str, _Pos, _Pos, str]], None]) -> None: ... +def tokenize_loop(readline: Callable[[], str], tokeneater: Callable[[Tuple[int, str, _Pos, _Pos, str]], None]) -> None: ... +def untokenize(iterable: Iterable[_TokenType]) -> str: ... + +class StopTokenizing(Exception): ... + +class TokenError(Exception): ... + +class Untokenizer: + prev_col = ... # type: int + prev_row = ... # type: int + tokens = ... # type: List[str] + def __init__(self) -> None: ... + def add_whitespace(self, _Pos) -> None: ... + def compat(self, token: Tuple[int, Any], iterable: Iterator[_TokenType]) -> None: ... + def untokenize(self, iterable: Iterable[_TokenType]) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/types.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/types.pyi new file mode 100644 index 000000000..87380b324 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/types.pyi @@ -0,0 +1,170 @@ +# Stubs for types +# Note, all classes "defined" here require special handling. + +from typing import ( + Any, Callable, Dict, Iterable, Iterator, List, Optional, + Tuple, Type, TypeVar, Union, overload, +) + +_T = TypeVar('_T') + +class NoneType: ... +TypeType = type +ObjectType = object + +IntType = int +LongType = int # Really long, but can't reference that due to a mypy import cycle +FloatType = float +BooleanType = bool +ComplexType = complex +StringType = str +UnicodeType = unicode +StringTypes = ... # type: Tuple[Type[StringType], Type[UnicodeType]] +BufferType = buffer +TupleType = tuple +ListType = list +DictType = dict +DictionaryType = dict + +class _Cell: + cell_contents = ... # type: Any + +class FunctionType: + func_closure = ... # type: Optional[Tuple[_Cell, ...]] + func_code = ... # type: CodeType + func_defaults = ... # type: Optional[Tuple[Any, ...]] + func_dict = ... # type: Dict[str, Any] + func_doc = ... # type: Optional[str] + func_globals = ... # type: Dict[str, Any] + func_name = ... # type: str + __closure__ = func_closure + __code__ = func_code + __defaults__ = func_defaults + __dict__ = func_dict + __globals__ = func_globals + __name__ = func_name + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Optional[object], type: Optional[type]) -> 'UnboundMethodType': ... + +LambdaType = FunctionType + +class CodeType: + co_argcount = ... # type: int + co_cellvars = ... # type: Tuple[str, ...] + co_code = ... # type: str + co_consts = ... # type: Tuple[Any, ...] + co_filename = ... # type: Optional[str] + co_firstlineno = ... # type: int + co_flags = ... # type: int + co_freevars = ... # type: Tuple[str, ...] + co_lnotab = ... # type: str + co_name = ... # type: str + co_names = ... # type: Tuple[str, ...] + co_nlocals = ... # type: int + co_stacksize = ... # type: int + co_varnames = ... # type: Tuple[str, ...] + +class GeneratorType: + gi_code = ... # type: CodeType + gi_frame = ... # type: FrameType + gi_running = ... # type: int + def __iter__(self) -> 'GeneratorType': ... + def close(self) -> None: ... + def next(self) -> Any: ... + def send(self, arg: Any) -> Any: ... + @overload + def throw(self, val: BaseException) -> Any: ... + @overload + def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... + +class ClassType: ... +class UnboundMethodType: + im_class = ... # type: type + im_func = ... # type: FunctionType + im_self = ... # type: object + __name__ = ... # type: str + __func__ = im_func + __self__ = im_self + def __init__(self, func: Callable, obj: object) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + +class InstanceType: + __doc__ = ... # type: Optional[str] + __class__ = ... # type: type + __module__ = ... # type: Any + +MethodType = UnboundMethodType + +class BuiltinFunctionType: + __self__ = ... # type: Optional[object] + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +BuiltinMethodType = BuiltinFunctionType + +class ModuleType: + __doc__ = ... # type: Optional[str] + __file__ = ... # type: Optional[str] + __name__ = ... # type: str + __package__ = ... # type: Optional[str] + __path__ = ... # type: Optional[Iterable[str]] + __dict__ = ... # type: Dict[str, Any] + def __init__(self, name: str, doc: Optional[str] = ...) -> None: ... +FileType = file +XRangeType = xrange + +class TracebackType: + tb_frame = ... # type: FrameType + tb_lasti = ... # type: int + tb_lineno = ... # type: int + tb_next = ... # type: TracebackType + +class FrameType: + f_back = ... # type: FrameType + f_builtins = ... # type: Dict[str, Any] + f_code = ... # type: CodeType + f_exc_type = ... # type: None + f_exc_value = ... # type: None + f_exc_traceback = ... # type: None + f_globals = ... # type: Dict[str, Any] + f_lasti = ... # type: int + f_lineno = ... # type: int + f_locals = ... # type: Dict[str, Any] + f_restricted = ... # type: bool + f_trace = ... # type: Callable[[], None] + + def clear(self) -> None: ... + +SliceType = slice +class EllipsisType: ... + +class DictProxyType: + # TODO is it possible to have non-string keys? + # no __init__ + def copy(self) -> dict: ... + def get(self, key: str, default: _T = ...) -> Union[Any, _T]: ... + def has_key(self, key: str) -> bool: ... + def items(self) -> List[Tuple[str, Any]]: ... + def iteritems(self) -> Iterator[Tuple[str, Any]]: ... + def iterkeys(self) -> Iterator[str]: ... + def itervalues(self) -> Iterator[Any]: ... + def keys(self) -> List[str]: ... + def values(self) -> List[Any]: ... + def __contains__(self, key: str) -> bool: ... + def __getitem__(self, key: str) -> Any: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + +class NotImplementedType: ... + +class GetSetDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = ...) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... +# Same type on Jython, different on CPython and PyPy, unknown on IronPython. +class MemberDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = ...) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/typing.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/typing.pyi new file mode 100644 index 000000000..519a96d9d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/typing.pyi @@ -0,0 +1,436 @@ +# Stubs for typing (Python 2.7) + +from abc import abstractmethod, ABCMeta +from types import CodeType, FrameType, TracebackType +import collections # Needed by aliases like DefaultDict, see mypy issue 2986 + +# Definitions of special type checking related constructs. Their definitions +# are not used, so their value does not matter. + +overload = object() +Any = object() +TypeVar = object() +_promote = object() +no_type_check = object() + +class _SpecialForm(object): + def __getitem__(self, typeargs: Any) -> object: ... + +Tuple: _SpecialForm = ... +Generic: _SpecialForm = ... +Protocol: _SpecialForm = ... +Callable: _SpecialForm = ... +Type: _SpecialForm = ... +ClassVar: _SpecialForm = ... + +class GenericMeta(type): ... + +# Return type that indicates a function does not return. +# This type is equivalent to the None type, but the no-op Union is necessary to +# distinguish the None type from the None value. +NoReturn = Union[None] + +# Type aliases and type constructors + +class TypeAlias: + # Class for defining generic aliases for library types. + def __init__(self, target_type: type) -> None: ... + def __getitem__(self, typeargs: Any) -> Any: ... + +Union = TypeAlias(object) +Optional = TypeAlias(object) +List = TypeAlias(object) +Dict = TypeAlias(object) +DefaultDict = TypeAlias(object) +Set = TypeAlias(object) +FrozenSet = TypeAlias(object) +Counter = TypeAlias(object) +Deque = TypeAlias(object) + +# Predefined type variables. +AnyStr = TypeVar('AnyStr', str, unicode) + +# Abstract base classes. + +# These type variables are used by the container types. +_T = TypeVar('_T') +_S = TypeVar('_S') +_KT = TypeVar('_KT') # Key type. +_VT = TypeVar('_VT') # Value type. +_T_co = TypeVar('_T_co', covariant=True) # Any type covariant containers. +_V_co = TypeVar('_V_co', covariant=True) # Any type covariant containers. +_KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers. +_VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers. +_T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. +_TC = TypeVar('_TC', bound=Type[object]) + +def runtime(cls: _TC) -> _TC: ... + +@runtime +class SupportsInt(Protocol, metaclass=ABCMeta): + @abstractmethod + def __int__(self) -> int: ... + +@runtime +class SupportsFloat(Protocol, metaclass=ABCMeta): + @abstractmethod + def __float__(self) -> float: ... + +@runtime +class SupportsComplex(Protocol, metaclass=ABCMeta): + @abstractmethod + def __complex__(self) -> complex: ... + +@runtime +class SupportsAbs(Protocol[_T_co]): + @abstractmethod + def __abs__(self) -> _T_co: ... + +@runtime +class SupportsRound(Protocol[_T_co]): + @abstractmethod + def __round__(self, ndigits: int = ...) -> _T_co: ... + +@runtime +class Reversible(Protocol[_T_co]): + @abstractmethod + def __reversed__(self) -> Iterator[_T_co]: ... + +@runtime +class Sized(Protocol, metaclass=ABCMeta): + @abstractmethod + def __len__(self) -> int: ... + +@runtime +class Hashable(Protocol, metaclass=ABCMeta): + # TODO: This is special, in that a subclass of a hashable class may not be hashable + # (for example, list vs. object). It's not obvious how to represent this. This class + # is currently mostly useless for static checking. + @abstractmethod + def __hash__(self) -> int: ... + +@runtime +class Iterable(Protocol[_T_co]): + @abstractmethod + def __iter__(self) -> Iterator[_T_co]: ... + +@runtime +class Iterator(Iterable[_T_co], Protocol[_T_co]): + @abstractmethod + def next(self) -> _T_co: ... + def __iter__(self) -> Iterator[_T_co]: ... + +class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): + @abstractmethod + def next(self) -> _T_co: ... + + @abstractmethod + def send(self, value: _T_contra) -> _T_co: ... + + @abstractmethod + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., + tb: TracebackType = ...) -> _T_co: ... + @abstractmethod + def close(self) -> None: ... + @property + def gi_code(self) -> CodeType: ... + @property + def gi_frame(self) -> FrameType: ... + @property + def gi_running(self) -> bool: ... + +@runtime +class Container(Protocol[_T_co]): + @abstractmethod + def __contains__(self, x: object) -> bool: ... + +class Sequence(Iterable[_T_co], Container[_T_co], Sized, Reversible[_T_co], Generic[_T_co]): + @overload + @abstractmethod + def __getitem__(self, i: int) -> _T_co: ... + @overload + @abstractmethod + def __getitem__(self, s: slice) -> Sequence[_T_co]: ... + # Mixin methods + def index(self, x: Any) -> int: ... + def count(self, x: Any) -> int: ... + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __reversed__(self) -> Iterator[_T_co]: ... + +class MutableSequence(Sequence[_T], Generic[_T]): + @abstractmethod + def insert(self, index: int, object: _T) -> None: ... + @overload + @abstractmethod + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + @abstractmethod + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... + @overload + @abstractmethod + def __delitem__(self, i: int) -> None: ... + @overload + @abstractmethod + def __delitem__(self, i: slice) -> None: ... + # Mixin methods + def append(self, object: _T) -> None: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def reverse(self) -> None: ... + def pop(self, index: int = ...) -> _T: ... + def remove(self, object: _T) -> None: ... + def __iadd__(self, x: Iterable[_T]) -> MutableSequence[_T]: ... + +class AbstractSet(Sized, Iterable[_T_co], Container[_T_co], Generic[_T_co]): + @abstractmethod + def __contains__(self, x: object) -> bool: ... + # Mixin methods + def __le__(self, s: AbstractSet[Any]) -> bool: ... + def __lt__(self, s: AbstractSet[Any]) -> bool: ... + def __gt__(self, s: AbstractSet[Any]) -> bool: ... + def __ge__(self, s: AbstractSet[Any]) -> bool: ... + def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ... + def __or__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ... + def __sub__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ... + def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ... + # TODO: argument can be any container? + def isdisjoint(self, s: AbstractSet[Any]) -> bool: ... + +class MutableSet(AbstractSet[_T], Generic[_T]): + @abstractmethod + def add(self, x: _T) -> None: ... + @abstractmethod + def discard(self, x: _T) -> None: ... + # Mixin methods + def clear(self) -> None: ... + def pop(self) -> _T: ... + def remove(self, element: _T) -> None: ... + def __ior__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ... + def __iand__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ... + def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ... + def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ... + +class MappingView(Sized): + def __len__(self) -> int: ... + +class ItemsView(AbstractSet[Tuple[_KT_co, _VT_co]], MappingView, Generic[_KT_co, _VT_co]): + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ... + +class KeysView(AbstractSet[_KT_co], MappingView, Generic[_KT_co]): + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_KT_co]: ... + +class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]): + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_VT_co]: ... + +@runtime +class ContextManager(Protocol[_T_co]): + def __enter__(self) -> _T_co: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType]) -> Optional[bool]: ... + +class Mapping(Iterable[_KT], Container[_KT], Sized, Generic[_KT, _VT_co]): + # TODO: We wish the key type could also be covariant, but that doesn't work, + # see discussion in https: //github.com/python/typing/pull/273. + @abstractmethod + def __getitem__(self, k: _KT) -> _VT_co: + ... + # Mixin methods + @overload + def get(self, k: _KT) -> Optional[_VT_co]: ... + @overload + def get(self, k: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]: ... + def keys(self) -> list[_KT]: ... + def values(self) -> list[_VT_co]: ... + def items(self) -> list[Tuple[_KT, _VT_co]]: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT_co]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT_co]]: ... + def __contains__(self, o: object) -> bool: ... + +class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]): + @abstractmethod + def __setitem__(self, k: _KT, v: _VT) -> None: ... + @abstractmethod + def __delitem__(self, v: _KT) -> None: ... + + def clear(self) -> None: ... + @overload + def pop(self, k: _KT) -> _VT: ... + @overload + def pop(self, k: _KT, default: Union[_VT, _T] = ...) -> Union[_VT, _T]: ... + def popitem(self) -> Tuple[_KT, _VT]: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + @overload + def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + @overload + def update(self, **kwargs: _VT) -> None: ... + +Text = unicode + +TYPE_CHECKING = True + +class IO(Iterator[AnyStr], Generic[AnyStr]): + # TODO detach + # TODO use abstract properties + @property + def mode(self) -> str: ... + @property + def name(self) -> str: ... + @abstractmethod + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + @abstractmethod + def fileno(self) -> int: ... + @abstractmethod + def flush(self) -> None: ... + @abstractmethod + def isatty(self) -> bool: ... + # TODO what if n is None? + @abstractmethod + def read(self, n: int = ...) -> AnyStr: ... + @abstractmethod + def readable(self) -> bool: ... + @abstractmethod + def readline(self, limit: int = ...) -> AnyStr: ... + @abstractmethod + def readlines(self, hint: int = ...) -> list[AnyStr]: ... + @abstractmethod + def seek(self, offset: int, whence: int = ...) -> int: ... + @abstractmethod + def seekable(self) -> bool: ... + @abstractmethod + def tell(self) -> int: ... + @abstractmethod + def truncate(self, size: Optional[int] = ...) -> int: ... + @abstractmethod + def writable(self) -> bool: ... + # TODO buffer objects + @abstractmethod + def write(self, s: AnyStr) -> int: ... + @abstractmethod + def writelines(self, lines: Iterable[AnyStr]) -> None: ... + + @abstractmethod + def next(self) -> AnyStr: ... + @abstractmethod + def __iter__(self) -> Iterator[AnyStr]: ... + @abstractmethod + def __enter__(self) -> IO[AnyStr]: ... + @abstractmethod + def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], + traceback: Optional[TracebackType]) -> bool: ... + +class BinaryIO(IO[str]): + # TODO readinto + # TODO read1? + # TODO peek? + @abstractmethod + def __enter__(self) -> BinaryIO: ... + +class TextIO(IO[unicode]): + # TODO use abstractproperty + @property + def buffer(self) -> BinaryIO: ... + @property + def encoding(self) -> str: ... + @property + def errors(self) -> Optional[str]: ... + @property + def line_buffering(self) -> bool: ... + @property + def newlines(self) -> Any: ... # None, str or tuple + @abstractmethod + def __enter__(self) -> TextIO: ... + +class ByteString(Sequence[int], metaclass=ABCMeta): ... + +class Match(Generic[AnyStr]): + pos = 0 + endpos = 0 + lastindex = 0 + lastgroup = ... # type: AnyStr + string = ... # type: AnyStr + + # The regular expression object whose match() or search() method produced + # this match instance. + re = ... # type: 'Pattern[AnyStr]' + + def expand(self, template: AnyStr) -> AnyStr: ... + + @overload + def group(self, group1: int = ...) -> AnyStr: ... + @overload + def group(self, group1: str) -> AnyStr: ... + @overload + def group(self, group1: int, group2: int, + *groups: int) -> Sequence[AnyStr]: ... + @overload + def group(self, group1: str, group2: str, + *groups: str) -> Sequence[AnyStr]: ... + + def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ... + def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ... + def start(self, group: Union[int, str] = ...) -> int: ... + def end(self, group: Union[int, str] = ...) -> int: ... + def span(self, group: Union[int, str] = ...) -> Tuple[int, int]: ... + +class Pattern(Generic[AnyStr]): + flags = 0 + groupindex = 0 + groups = 0 + pattern = ... # type: AnyStr + + def search(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Optional[Match[AnyStr]]: ... + def match(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Optional[Match[AnyStr]]: ... + def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ... + def findall(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> list[Any]: ... + def finditer(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Iterator[Match[AnyStr]]: ... + + @overload + def sub(self, repl: AnyStr, string: AnyStr, + count: int = ...) -> AnyStr: ... + @overload + def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, + count: int = ...) -> AnyStr: ... + + @overload + def subn(self, repl: AnyStr, string: AnyStr, + count: int = ...) -> Tuple[AnyStr, int]: ... + @overload + def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, + count: int = ...) -> Tuple[AnyStr, int]: ... + +# Functions + +def get_type_hints(obj: Callable, globalns: Optional[dict[Text, Any]] = ..., + localns: Optional[dict[Text, Any]] = ...) -> None: ... + +def cast(tp: Type[_T], obj: Any) -> _T: ... + +# Type constructors + +# NamedTuple is special-cased in the type checker +class NamedTuple(tuple): + _fields = ... # type: Tuple[str, ...] + + def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., *, + verbose: bool = ..., rename: bool = ..., **kwargs: Any) -> None: ... + + @classmethod + def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ... + + def _asdict(self) -> dict: ... + def _replace(self: _T, **kwargs: Any) -> _T: ... + +def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/unittest.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/unittest.pyi new file mode 100644 index 000000000..8e8665034 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/unittest.pyi @@ -0,0 +1,247 @@ +# Stubs for unittest + +# Based on http://docs.python.org/2.7/library/unittest.html + +from typing import (Any, Callable, Dict, FrozenSet, Iterable, Iterator, + List, NoReturn, Optional, overload, Pattern, Sequence, Set, + Text, TextIO, Tuple, Type, TypeVar, Union) +from abc import abstractmethod, ABCMeta +import types + +_T = TypeVar('_T') +_FT = TypeVar('_FT') + +_ExceptionType = Union[Type[BaseException], Tuple[Type[BaseException], ...]] +_Regexp = Union[Text, Pattern[Text]] + +class Testable(metaclass=ABCMeta): + @abstractmethod + def run(self, result: 'TestResult') -> None: ... + @abstractmethod + def debug(self) -> None: ... + @abstractmethod + def countTestCases(self) -> int: ... + +# TODO ABC for test runners? + +class TestResult: + errors = ... # type: List[Tuple[Testable, str]] + failures = ... # type: List[Tuple[Testable, str]] + skipped = ... # type: List[Tuple[Testable, str]] + expectedFailures = ... # type: List[Tuple[Testable, str]] + unexpectedSuccesses = ... # type: List[Testable] + shouldStop = ... # type: bool + testsRun = ... # type: int + buffer = ... # type: bool + failfast = ... # type: bool + + def wasSuccessful(self) -> bool: ... + def stop(self) -> None: ... + def startTest(self, test: Testable) -> None: ... + def stopTest(self, test: Testable) -> None: ... + def startTestRun(self) -> None: ... + def stopTestRun(self) -> None: ... + def addError(self, test: Testable, + err: Tuple[type, Any, Any]) -> None: ... # TODO + def addFailure(self, test: Testable, + err: Tuple[type, Any, Any]) -> None: ... # TODO + def addSuccess(self, test: Testable) -> None: ... + def addSkip(self, test: Testable, reason: str) -> None: ... + def addExpectedFailure(self, test: Testable, err: str) -> None: ... + def addUnexpectedSuccess(self, test: Testable) -> None: ... + +class _AssertRaisesBaseContext: + expected = ... # type: Any + failureException = ... # type: Type[BaseException] + obj_name = ... # type: str + expected_regex = ... # type: Pattern[str] + +class _AssertRaisesContext(_AssertRaisesBaseContext): + exception = ... # type: Any # TODO precise type + def __enter__(self) -> _AssertRaisesContext: ... + def __exit__(self, exc_type, exc_value, tb) -> bool: ... + +class TestCase(Testable): + failureException = ... # type: Type[BaseException] + longMessage = ... # type: bool + maxDiff = ... # type: Optional[int] + def __init__(self, methodName: str = ...) -> None: ... + def setUp(self) -> None: ... + def tearDown(self) -> None: ... + @classmethod + def setUpClass(cls) -> None: ... + @classmethod + def tearDownClass(cls) -> None: ... + def run(self, result: TestResult = ...) -> None: ... + def debug(self) -> None: ... + def assert_(self, expr: Any, msg: object = ...) -> None: ... + def failUnless(self, expr: Any, msg: object = ...) -> None: ... + def assertTrue(self, expr: Any, msg: object = ...) -> None: ... + def assertEqual(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertEquals(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def failUnlessEqual(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertNotEqual(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertNotEquals(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def failIfEqual(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertAlmostEqual(self, first: float, second: float, places: int = ..., + msg: object = ..., + delta: float = ...) -> None: ... + def assertAlmostEquals(self, first: float, second: float, places: int = ..., + msg: object = ..., + delta: float = ...) -> None: ... + def failUnlessAlmostEqual(self, first: float, second: float, places: int = ..., + msg: object = ...) -> None: ... + def assertNotAlmostEqual(self, first: float, second: float, places: int = ..., + msg: object = ..., + delta: float = ...) -> None: ... + def assertNotAlmostEquals(self, first: float, second: float, places: int = ..., + msg: object = ..., + delta: float = ...) -> None: ... + def failIfAlmostEqual(self, first: float, second: float, places: int = ..., + msg: object = ..., + delta: float = ...) -> None: ... + def assertGreater(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertGreaterEqual(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertMultiLineEqual(self, first: str, second: str, + msg: object = ...) -> None: ... + def assertSequenceEqual(self, first: Sequence[Any], second: Sequence[Any], + msg: object = ..., seq_type: type = ...) -> None: ... + def assertListEqual(self, first: List[Any], second: List[Any], + msg: object = ...) -> None: ... + def assertTupleEqual(self, first: Tuple[Any, ...], second: Tuple[Any, ...], + msg: object = ...) -> None: ... + def assertSetEqual(self, first: Union[Set[Any], FrozenSet[Any]], + second: Union[Set[Any], FrozenSet[Any]], msg: object = ...) -> None: ... + def assertDictEqual(self, first: Dict[Any, Any], second: Dict[Any, Any], + msg: object = ...) -> None: ... + def assertLess(self, first: Any, second: Any, + msg: object = ...) -> None: ... + def assertLessEqual(self, first: Any, second: Any, + msg: object = ...) -> None: ... + @overload + def assertRaises(self, exception: _ExceptionType, callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + @overload + def assertRaises(self, exception: _ExceptionType) -> _AssertRaisesContext: ... + @overload + def assertRaisesRegexp(self, exception: _ExceptionType, regexp: _Regexp, callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + @overload + def assertRaisesRegexp(self, exception: _ExceptionType, regexp: _Regexp) -> _AssertRaisesContext: ... + def assertRegexpMatches(self, text: Text, regexp: _Regexp, msg: object = ...) -> None: ... + def assertNotRegexpMatches(self, text: Text, regexp: _Regexp, msg: object = ...) -> None: ... + def assertItemsEqual(self, first: Iterable[Any], second: Iterable[Any], msg: object = ...) -> None: ... + def assertDictContainsSubset(self, expected: Dict[Any, Any], actual: Dict[Any, Any], msg: object = ...) -> None: ... + def addTypeEqualityFunc(self, typeobj: type, function: Callable[..., None]) -> None: ... + @overload + def failUnlessRaises(self, exception: _ExceptionType, callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None: ... + @overload + def failUnlessRaises(self, exception: _ExceptionType) -> _AssertRaisesContext: ... + def failIf(self, expr: Any, msg: object = ...) -> None: ... + def assertFalse(self, expr: Any, msg: object = ...) -> None: ... + def assertIs(self, first: object, second: object, + msg: object = ...) -> None: ... + def assertIsNot(self, first: object, second: object, + msg: object = ...) -> None: ... + def assertIsNone(self, expr: Any, msg: object = ...) -> None: ... + def assertIsNotNone(self, expr: Any, msg: object = ...) -> None: ... + def assertIn(self, first: _T, second: Iterable[_T], + msg: object = ...) -> None: ... + def assertNotIn(self, first: _T, second: Iterable[_T], + msg: object = ...) -> None: ... + def assertIsInstance(self, obj: Any, cls: Union[type, Tuple[type, ...]], + msg: object = ...) -> None: ... + def assertNotIsInstance(self, obj: Any, cls: Union[type, Tuple[type, ...]], + msg: object = ...) -> None: ... + def fail(self, msg: object = ...) -> NoReturn: ... + def countTestCases(self) -> int: ... + def defaultTestResult(self) -> TestResult: ... + def id(self) -> str: ... + def shortDescription(self) -> str: ... # May return None + def addCleanup(function: Any, *args: Any, **kwargs: Any) -> None: ... + def doCleanups(self) -> bool: ... + def skipTest(self, reason: Any) -> None: ... + +class FunctionTestCase(Testable): + def __init__(self, testFunc: Callable[[], None], + setUp: Optional[Callable[[], None]] = ..., + tearDown: Optional[Callable[[], None]] = ..., + description: Optional[str] = ...) -> None: ... + def run(self, result: TestResult) -> None: ... + def debug(self) -> None: ... + def countTestCases(self) -> int: ... + +class TestSuite(Testable): + def __init__(self, tests: Iterable[Testable] = ...) -> None: ... + def addTest(self, test: Testable) -> None: ... + def addTests(self, tests: Iterable[Testable]) -> None: ... + def run(self, result: TestResult) -> None: ... + def debug(self) -> None: ... + def countTestCases(self) -> int: ... + def __iter__(self) -> Iterator[Testable]: ... + +class TestLoader: + testMethodPrefix = ... # type: str + sortTestMethodsUsing = ... # type: Optional[Callable[[str, str], int]] + suiteClass = ... # type: Callable[[List[TestCase]], TestSuite] + def loadTestsFromTestCase(self, + testCaseClass: Type[TestCase]) -> TestSuite: ... + def loadTestsFromModule(self, module: types.ModuleType = ..., + use_load_tests: bool = ...) -> TestSuite: ... + def loadTestsFromName(self, name: str = ..., + module: Optional[types.ModuleType] = ...) -> TestSuite: ... + def loadTestsFromNames(self, names: List[str] = ..., + module: Optional[types.ModuleType] = ...) -> TestSuite: ... + def discover(self, start_dir: str, pattern: str = ..., + top_level_dir: Optional[str] = ...) -> TestSuite: ... + def getTestCaseNames(self, testCaseClass: Type[TestCase] = ...) -> List[str]: ... + +defaultTestLoader = ... # type: TestLoader + +class TextTestResult(TestResult): + def __init__(self, stream: TextIO, descriptions: bool, verbosity: int) -> None: ... + +class TextTestRunner: + def __init__(self, stream: Optional[TextIO] = ..., descriptions: bool = ..., + verbosity: int = ..., failfast: bool = ..., buffer: bool = ..., + resultclass: Optional[Type[TestResult]] = ...) -> None: ... + def _makeResult(self) -> TestResult: ... + +class SkipTest(Exception): + ... + +# TODO precise types +def skipUnless(condition: Any, reason: Union[str, unicode]) -> Any: ... +def skipIf(condition: Any, reason: Union[str, unicode]) -> Any: ... +def expectedFailure(func: _FT) -> _FT: ... +def skip(reason: Union[str, unicode]) -> Any: ... + +# not really documented +class TestProgram: + result = ... # type: TestResult + +def main(module: str = ..., defaultTest: Optional[str] = ..., + argv: Optional[Sequence[str]] = ..., + testRunner: Union[Type[TextTestRunner], TextTestRunner, None] = ..., + testLoader: TestLoader = ..., exit: bool = ..., verbosity: int = ..., + failfast: Optional[bool] = ..., catchbreak: Optional[bool] = ..., + buffer: Optional[bool] = ...) -> TestProgram: ... + +def load_tests(loader: TestLoader, tests: TestSuite, pattern: Optional[Text]) -> TestSuite: ... + +def installHandler() -> None: ... +def registerResult(result: TestResult) -> None: ... +def removeResult(result: TestResult) -> bool: ... +@overload +def removeHandler() -> None: ... +@overload +def removeHandler(function: Callable[..., Any]) -> Callable[..., Any]: ... + +# private but occasionally used +util = ... # type: types.ModuleType diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urllib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urllib.pyi new file mode 100644 index 000000000..fde604f29 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urllib.pyi @@ -0,0 +1,132 @@ +from typing import Any, AnyStr, IO, Mapping, Sequence, Text, Tuple, Union + +def url2pathname(pathname: str) -> str: ... +def pathname2url(pathname: str) -> str: ... +def urlopen(url: str, data=..., proxies: Mapping[str, str] = ..., context=...) -> IO[Any]: ... +def urlretrieve(url, filename=..., reporthook=..., data=..., context=...): ... +def urlcleanup() -> None: ... + +class ContentTooShortError(IOError): + content = ... # type: Any + def __init__(self, message, content) -> None: ... + +class URLopener: + version = ... # type: Any + proxies = ... # type: Any + key_file = ... # type: Any + cert_file = ... # type: Any + context = ... # type: Any + addheaders = ... # type: Any + tempcache = ... # type: Any + ftpcache = ... # type: Any + def __init__(self, proxies: Mapping[str, str] = ..., context=..., **x509) -> None: ... + def __del__(self): ... + def close(self): ... + def cleanup(self): ... + def addheader(self, *args): ... + type = ... # type: Any + def open(self, fullurl: str, data=...): ... + def open_unknown(self, fullurl, data=...): ... + def open_unknown_proxy(self, proxy, fullurl, data=...): ... + def retrieve(self, url, filename=..., reporthook=..., data=...): ... + def open_http(self, url, data=...): ... + def http_error(self, url, fp, errcode, errmsg, headers, data=...): ... + def http_error_default(self, url, fp, errcode, errmsg, headers): ... + def open_https(self, url, data=...): ... + def open_file(self, url): ... + def open_local_file(self, url): ... + def open_ftp(self, url): ... + def open_data(self, url, data=...): ... + +class FancyURLopener(URLopener): + auth_cache = ... # type: Any + tries = ... # type: Any + maxtries = ... # type: Any + def __init__(self, *args, **kwargs) -> None: ... + def http_error_default(self, url, fp, errcode, errmsg, headers): ... + def http_error_302(self, url, fp, errcode, errmsg, headers, data=...): ... + def redirect_internal(self, url, fp, errcode, errmsg, headers, data): ... + def http_error_301(self, url, fp, errcode, errmsg, headers, data=...): ... + def http_error_303(self, url, fp, errcode, errmsg, headers, data=...): ... + def http_error_307(self, url, fp, errcode, errmsg, headers, data=...): ... + def http_error_401(self, url, fp, errcode, errmsg, headers, data=...): ... + def http_error_407(self, url, fp, errcode, errmsg, headers, data=...): ... + def retry_proxy_http_basic_auth(self, url, realm, data=...): ... + def retry_proxy_https_basic_auth(self, url, realm, data=...): ... + def retry_http_basic_auth(self, url, realm, data=...): ... + def retry_https_basic_auth(self, url, realm, data=...): ... + def get_user_passwd(self, host, realm, clear_cache=...): ... + def prompt_user_passwd(self, host, realm): ... + +class ftpwrapper: + user = ... # type: Any + passwd = ... # type: Any + host = ... # type: Any + port = ... # type: Any + dirs = ... # type: Any + timeout = ... # type: Any + refcount = ... # type: Any + keepalive = ... # type: Any + def __init__(self, user, passwd, host, port, dirs, timeout=..., persistent=...) -> None: ... + busy = ... # type: Any + ftp = ... # type: Any + def init(self): ... + def retrfile(self, file, type): ... + def endtransfer(self): ... + def close(self): ... + def file_close(self): ... + def real_close(self): ... + +class addbase: + fp = ... # type: Any + read = ... # type: Any + readline = ... # type: Any + readlines = ... # type: Any + fileno = ... # type: Any + __iter__ = ... # type: Any + next = ... # type: Any + def __init__(self, fp) -> None: ... + def close(self): ... + +class addclosehook(addbase): + closehook = ... # type: Any + hookargs = ... # type: Any + def __init__(self, fp, closehook, *hookargs) -> None: ... + def close(self): ... + +class addinfo(addbase): + headers = ... # type: Any + def __init__(self, fp, headers) -> None: ... + def info(self): ... + +class addinfourl(addbase): + headers = ... # type: Any + url = ... # type: Any + code = ... # type: Any + def __init__(self, fp, headers, url, code=...) -> None: ... + def info(self): ... + def getcode(self): ... + def geturl(self): ... + +def unwrap(url): ... +def splittype(url): ... +def splithost(url): ... +def splituser(host): ... +def splitpasswd(user): ... +def splitport(host): ... +def splitnport(host, defport=...): ... +def splitquery(url): ... +def splittag(url): ... +def splitattr(url): ... +def splitvalue(attr): ... +def unquote(s: AnyStr) -> AnyStr: ... +def unquote_plus(s: AnyStr) -> AnyStr: ... +def quote(s: AnyStr, safe: Text = ...) -> AnyStr: ... +def quote_plus(s: AnyStr, safe: Text = ...) -> AnyStr: ... +def urlencode(query: Union[Sequence[Tuple[Any, Any]], Mapping[Any, Any]], doseq=...) -> str: ... + +def getproxies() -> Mapping[str, str]: ... +def proxy_bypass(host): ... + +# Names in __all__ with no definition: +# basejoin diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urllib2.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urllib2.pyi new file mode 100644 index 000000000..e15289738 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urllib2.pyi @@ -0,0 +1,169 @@ + +import ssl +from typing import Any, AnyStr, Dict, List, Union, Optional, Mapping, Callable, Sequence, Tuple, Type +from urllib import addinfourl +from httplib import HTTPResponse + +_string = Union[str, unicode] + +class URLError(IOError): + reason = ... # type: Union[str, BaseException] + +class HTTPError(URLError, addinfourl): + code = ... # type: int + headers = ... # type: Dict[str, str] + +class Request(object): + host = ... # type: str + port = ... # type: str + data = ... # type: str + headers = ... # type: Dict[str, str] + unverifiable = ... # type: bool + type = ... # type: Optional[str] + origin_req_host = ... + unredirected_hdrs = ... + + def __init__(self, url: str, data: Optional[str] = ..., headers: Dict[str, str] = ..., + origin_req_host: Optional[str] = ..., unverifiable: bool = ...) -> None: ... + def __getattr__(self, attr): ... + def get_method(self) -> str: ... + def add_data(self, data) -> None: ... + def has_data(self) -> bool: ... + def get_data(self) -> str: ... + def get_full_url(self) -> str: ... + def get_type(self): ... + def get_host(self) -> str: ... + def get_selector(self): ... + def set_proxy(self, host, type) -> None: ... + def has_proxy(self) -> bool: ... + def get_origin_req_host(self) -> str: ... + def is_unverifiable(self) -> bool: ... + def add_header(self, key: str, val: str) -> None: ... + def add_unredirected_header(self, key: str, val: str) -> None: ... + def has_header(self, header_name: str) -> bool: ... + def get_header(self, header_name: str, default: Optional[str] = ...) -> str: ... + def header_items(self): ... + +class OpenerDirector(object): + def add_handler(self, handler: BaseHandler) -> None: ... + def open(self, url: Union[Request, _string], data: Optional[_string] = ..., timeout: int = ...): ... + def error(self, proto: _string, *args: Any): ... + +def urlopen(url: Union[Request, _string], data: Optional[_string] = ..., timeout: int = ..., + cafile: Optional[_string] = ..., capath: Optional[_string] = ..., cadefault: bool = ..., + context: Optional[ssl.SSLContext] = ...): ... +def install_opener(opener: OpenerDirector) -> None: ... +def build_opener(*handlers: Union[BaseHandler, Type[BaseHandler]]) -> OpenerDirector: ... + +class BaseHandler: + handler_order = ... # type: int + parent = ... # type: OpenerDirector + + def add_parent(self, parent: OpenerDirector) -> None: ... + def close(self) -> None: ... + def __lt__(self, other: Any) -> bool: ... + +class HTTPErrorProcessor(BaseHandler): + def http_response(self, request, response): ... + +class HTTPDefaultErrorHandler(BaseHandler): + def http_error_default(self, req, fp, code, msg, hdrs): ... + +class HTTPRedirectHandler(BaseHandler): + max_repeats = ... # type: int + max_redirections = ... # type: int + def redirect_request(self, req, fp, code, msg, headers, newurl): ... + def http_error_301(self, req, fp, code, msg, headers): ... + def http_error_302(self, req, fp, code, msg, headers): ... + def http_error_303(self, req, fp, code, msg, headers): ... + def http_error_307(self, req, fp, code, msg, headers): ... + inf_msg = ... # type: str + + +class ProxyHandler(BaseHandler): + def __init__(self, proxies=None): ... + def proxy_open(self, req, proxy, type): ... + +class HTTPPasswordMgr: + def __init__(self) -> None: ... + def add_password(self, realm: _string, uri: Union[_string, Sequence[_string]], user: _string, passwd: _string) -> None: ... + def find_user_password(self, realm: _string, authuri: _string) -> Tuple[Any, Any]: ... + def reduce_uri(self, uri: _string, default_port: bool = ...) -> Tuple[Any, Any]: ... + def is_suburi(self, base: _string, test: _string) -> bool: ... + +class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): ... + +class AbstractBasicAuthHandler: + def __init__(self, password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ... + def http_error_auth_reqed(self, authreq, host, req, headers): ... + def retry_http_basic_auth(self, host, req, realm): ... + +class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + auth_header = ... # type: str + def http_error_401(self, req, fp, code, msg, headers): ... + +class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + auth_header = ... # type: str + def http_error_407(self, req, fp, code, msg, headers): ... + +class AbstractDigestAuthHandler: + def __init__(self, passwd: Optional[HTTPPasswordMgr] = ...) -> None: ... + def reset_retry_count(self) -> None: ... + def http_error_auth_reqed(self, auth_header: str, host: str, req: Request, + headers: Mapping[str, str]) -> None: ... + def retry_http_digest_auth(self, req: Request, auth: str) -> Optional[HTTPResponse]: ... + def get_cnonce(self, nonce: str) -> str: ... + def get_authorization(self, req: Request, chal: Mapping[str, str]) -> str: ... + def get_algorithm_impls(self, algorithm: str) -> Tuple[Callable[[str], str], Callable[[str, str], str]]: ... + def get_entity_digest(self, data: Optional[bytes], chal: Mapping[str, str]) -> Optional[str]: ... + +class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + auth_header = ... # type: str + handler_order = ... # type: int + def http_error_401(self, req, fp, code, msg, headers): ... + +class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + auth_header = ... # type: str + handler_order = ... # type: int + def http_error_407(self, req, fp, code, msg, headers): ... + +class AbstractHTTPHandler(BaseHandler): + def __init__(self, debuglevel: int = ...) -> None: ... + def do_request_(self, request): ... + def do_open(self, http_class, req): ... + +class HTTPHandler(AbstractHTTPHandler): + def http_open(self, req): ... + def http_request(self, request): ... + +class HTTPSHandler(AbstractHTTPHandler): + def __init__(self, debuglevel=0, context=None): ... + def https_open(self, req): ... + def https_request(self, request): ... + +class HTTPCookieProcessor(BaseHandler): + def __init__(self, cookiejar=None): ... + def http_request(self, request): ... + def http_response(self, request, response): ... + +class UnknownHandler(BaseHandler): + def unknown_open(self, req): ... + +class FileHandler(BaseHandler): + def file_open(self, req): ... + def get_names(self): ... + def open_local_file(self, req): ... + +class FTPHandler(BaseHandler): + def ftp_open(self, req): ... + def connect_ftp(self, user, passwd, host, port, dirs, timeout): ... + +class CacheFTPHandler(FTPHandler): + def __init__(self) -> None: ... + def setTimeout(self, t): ... + def setMaxConns(self, m): ... + def check_cache(self): ... + def clear_cache(self): ... + +def parse_http_list(s: AnyStr) -> List[AnyStr]: ... +def parse_keqv_list(l: List[AnyStr]) -> Dict[AnyStr, AnyStr]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urlparse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urlparse.pyi new file mode 100644 index 000000000..169de2ff0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/urlparse.pyi @@ -0,0 +1,70 @@ +# Stubs for urlparse (Python 2) + +from typing import AnyStr, Dict, List, NamedTuple, Tuple, Sequence, Union, overload + +_String = Union[str, unicode] + +uses_relative = ... # type: List[str] +uses_netloc = ... # type: List[str] +uses_params = ... # type: List[str] +non_hierarchical = ... # type: List[str] +uses_query = ... # type: List[str] +uses_fragment = ... # type: List[str] +scheme_chars = ... # type: str +MAX_CACHE_SIZE = 0 + +def clear_cache() -> None: ... + +class ResultMixin(object): + @property + def username(self) -> str: ... + @property + def password(self) -> str: ... + @property + def hostname(self) -> str: ... + @property + def port(self) -> int: ... + +class SplitResult( + NamedTuple( + 'SplitResult', + [ + ('scheme', str), ('netloc', str), ('path', str), ('query', str), ('fragment', str) + ] + ), + ResultMixin +): + def geturl(self) -> str: ... + +class ParseResult( + NamedTuple( + 'ParseResult', + [ + ('scheme', str), ('netloc', str), ('path', str), ('params', str), ('query', str), + ('fragment', str) + ] + ), + ResultMixin +): + def geturl(self) -> str: ... + +def urlparse(url: _String, scheme: _String = ..., + allow_fragments: bool = ...) -> ParseResult: ... +def urlsplit(url: _String, scheme: _String = ..., + allow_fragments: bool = ...) -> SplitResult: ... +@overload +def urlunparse(data: Tuple[_String, _String, _String, _String, _String, _String]) -> str: ... +@overload +def urlunparse(data: Sequence[_String]) -> str: ... +@overload +def urlunsplit(data: Tuple[_String, _String, _String, _String, _String]) -> str: ... +@overload +def urlunsplit(data: Sequence[_String]) -> str: ... +def urljoin(base: _String, url: _String, + allow_fragments: bool = ...) -> str: ... +def urldefrag(url: AnyStr) -> Tuple[AnyStr, str]: ... +def unquote(s: AnyStr) -> AnyStr: ... +def parse_qs(qs: AnyStr, keep_blank_values: bool = ..., + strict_parsing: bool = ...) -> Dict[AnyStr, List[AnyStr]]: ... +def parse_qsl(qs: AnyStr, keep_blank_values: int = ..., + strict_parsing: bool = ...) -> List[Tuple[AnyStr, AnyStr]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/user.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/user.pyi new file mode 100644 index 000000000..e6beaa919 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/user.pyi @@ -0,0 +1,9 @@ +# Stubs for user (Python 2) + +# Docs: https://docs.python.org/2/library/user.html +# Source: https://hg.python.org/cpython/file/2.7/Lib/user.py +from typing import Any + +def __getattr__(name) -> Any: ... # type: ignore +home: str +pythonrc: str diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/whichdb.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/whichdb.pyi new file mode 100644 index 000000000..b1a69f481 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/whichdb.pyi @@ -0,0 +1,5 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/whichdb.py + +from typing import Optional, Text + +def whichdb(filename: Text) -> Optional[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2/xmlrpclib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/xmlrpclib.pyi new file mode 100644 index 000000000..9f6fb9858 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2/xmlrpclib.pyi @@ -0,0 +1,199 @@ +# Stubs for xmlrpclib (Python 2) + +from typing import Any, AnyStr, Callable, IO, Iterable, List, Mapping, MutableMapping, Optional, Tuple, Type, TypeVar, Union +from types import InstanceType +from datetime import datetime +from time import struct_time +from httplib import HTTPConnection, HTTPResponse, HTTPSConnection +from ssl import SSLContext +from StringIO import StringIO +from gzip import GzipFile + +_Unmarshaller = Any +_timeTuple = Tuple[int, int, int, int, int, int, int, int, int] +# Represents types that can be compared against a DateTime object +_dateTimeComp = Union[AnyStr, DateTime, datetime, _timeTuple] +# A "host description" used by Transport factories +_hostDesc = Union[str, Tuple[str, Mapping[Any, Any]]] + +def escape(s: AnyStr, replace: Callable[[AnyStr, AnyStr, AnyStr], AnyStr] = ...) -> AnyStr: ... + +MAXINT = ... # type: int +MININT = ... # type: int +PARSE_ERROR = ... # type: int +SERVER_ERROR = ... # type: int +APPLICATION_ERROR = ... # type: int +SYSTEM_ERROR = ... # type: int +TRANSPORT_ERROR = ... # type: int +NOT_WELLFORMED_ERROR = ... # type: int +UNSUPPORTED_ENCODING = ... # type: int +INVALID_ENCODING_CHAR = ... # type: int +INVALID_XMLRPC = ... # type: int +METHOD_NOT_FOUND = ... # type: int +INVALID_METHOD_PARAMS = ... # type: int +INTERNAL_ERROR = ... # type: int + +class Error(Exception): ... + +class ProtocolError(Error): + url = ... # type: str + errcode = ... # type: int + errmsg = ... # type: str + headers = ... # type: Any + def __init__(self, url: str, errcode: int, errmsg: str, headers: Any) -> None: ... + +class ResponseError(Error): ... + +class Fault(Error): + faultCode = ... # type: Any + faultString = ... # type: str + def __init__(self, faultCode: Any, faultString: str, **extra: Any) -> None: ... + +boolean = ... # type: Type[bool] +Boolean = ... # type: Type[bool] + +class DateTime: + value = ... # type: str + def __init__(self, value: Union[str, unicode, datetime, float, int, _timeTuple, struct_time] = ...) -> None: ... + def make_comparable(self, other: _dateTimeComp) -> Tuple[_dateTimeComp, _dateTimeComp]: ... + def __lt__(self, other: _dateTimeComp) -> bool: ... + def __le__(self, other: _dateTimeComp) -> bool: ... + def __gt__(self, other: _dateTimeComp) -> bool: ... + def __ge__(self, other: _dateTimeComp) -> bool: ... + def __eq__(self, other: _dateTimeComp) -> bool: ... + def __ne__(self, other: _dateTimeComp) -> bool: ... + def timetuple(self) -> struct_time: ... + def __cmp__(self, other: _dateTimeComp) -> int: ... + def decode(self, data: Any) -> None: ... + def encode(self, out: IO) -> None: ... + +class Binary: + data = ... # type: str + def __init__(self, data: Optional[str] = ...) -> None: ... + def __cmp__(self, other: Any) -> int: ... + def decode(self, data: str) -> None: ... + def encode(self, out: IO) -> None: ... + +WRAPPERS = ... # type: tuple + +# Still part of the public API, but see http://bugs.python.org/issue1773632 +FastParser = ... # type: None +FastUnmarshaller = ... # type: None +FastMarshaller = ... # type: None + +# xmlrpclib.py will leave ExpatParser undefined if it can't import expat from +# xml.parsers. Because this is Python 2.7, the import will succeed. +class ExpatParser: + def __init__(self, target: _Unmarshaller) -> None: ... + def feed(self, data: str): ... + def close(self): ... + +# TODO: Add xmllib.XMLParser as base class +class SlowParser: + handle_xml = ... # type: Callable[[str, bool], None] + unknown_starttag = ... # type: Callable[[str, Any], None] + handle_data = ... # type: Callable[[str], None] + handle_cdata = ... # type: Callable[[str], None] + unknown_endtag = ... # type: Callable[[str, Callable[[Iterable[str], str], str]], None] + def __init__(self, target: _Unmarshaller) -> None: ... + +class Marshaller: + memo = ... # type: MutableMapping[int, Any] + data = ... # type: Optional[str] + encoding = ... # type: Optional[str] + allow_none = ... # type: bool + def __init__(self, encoding: Optional[str] = ..., allow_none: bool = ...) -> None: ... + dispatch = ... # type: Mapping[type, Callable[[Marshaller, str, Callable[[str], None]], None]] + def dumps(self, values: Union[Iterable[Union[None, int, bool, long, float, str, unicode, List, Tuple, Mapping, datetime, InstanceType]], Fault]) -> str: ... + def dump_nil(self, value: None, write: Callable[[str], None]) -> None: ... + def dump_int(self, value: int, write: Callable[[str], None]) -> None: ... + def dump_bool(self, value: bool, write: Callable[[str], None]) -> None: ... + def dump_long(self, value: long, write: Callable[[str], None]) -> None: ... + def dump_double(self, value: float, write: Callable[[str], None]) -> None: ... + def dump_string(self, value: str, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... + def dump_unicode(self, value: unicode, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... + def dump_array(self, value: Union[List, Tuple], write: Callable[[str], None]) -> None: ... + def dump_struct(self, value: Mapping, write: Callable[[str], None], escape: Callable[[AnyStr, Callable[[AnyStr, AnyStr, AnyStr], AnyStr]], AnyStr] = ...) -> None: ... + def dump_datetime(self, value: datetime, write: Callable[[str], None]) -> None: ... + def dump_instance(self, value: InstanceType, write: Callable[[str], None]) -> None: ... + +class Unmarshaller: + def append(self, object: Any) -> None: ... + def __init__(self, use_datetime: bool = ...) -> None: ... + def close(self) -> tuple: ... + def getmethodname(self) -> Optional[str]: ... + def xml(self, encoding: str, standalone: bool) -> None: ... + def start(self, tag: str, attrs: Any) -> None: ... + def data(self, text: str) -> None: ... + def end(self, tag: str, join: Callable[[Iterable[str], str], str] = ...) -> None: ... + def end_dispatch(self, tag: str, data: str) -> None: ... + dispatch = ... # type: Mapping[str, Callable[[Unmarshaller, str], None]] + def end_nil(self, data: str): ... + def end_boolean(self, data: str) -> None: ... + def end_int(self, data: str) -> None: ... + def end_double(self, data: str) -> None: ... + def end_string(self, data: str) -> None: ... + def end_array(self, data: str) -> None: ... + def end_struct(self, data: str) -> None: ... + def end_base64(self, data: str) -> None: ... + def end_dateTime(self, data: str) -> None: ... + def end_value(self, data: str) -> None: ... + def end_params(self, data: str) -> None: ... + def end_fault(self, data: str) -> None: ... + def end_methodName(self, data: str) -> None: ... + +class _MultiCallMethod: + def __init__(self, call_list: List[Tuple[str, tuple]], name: str) -> None: ... +class MultiCallIterator: + def __init__(self, results: List) -> None: ... + +class MultiCall: + def __init__(self, server: ServerProxy) -> None: ... + def __getattr__(self, name: str) -> _MultiCallMethod: ... + def __call__(self) -> MultiCallIterator: ... + +def getparser(use_datetime: bool = ...) -> Tuple[Union[ExpatParser, SlowParser], Unmarshaller]: ... +def dumps(params: Union[tuple, Fault], methodname: Optional[str] = ..., methodresponse: Optional[bool] = ..., encoding: Optional[str] = ..., allow_none: bool = ...) -> str: ... +def loads(data: str, use_datetime: bool = ...) -> Tuple[tuple, Optional[str]]: ... + +def gzip_encode(data: str) -> str: ... +def gzip_decode(data: str, max_decode: int = ...) -> str: ... + +class GzipDecodedResponse(GzipFile): + stringio = ... # type: StringIO + def __init__(self, response: HTTPResponse) -> None: ... + def close(self): ... + +class _Method: + def __init__(self, send: Callable[[str, tuple], Any], name: str) -> None: ... + def __getattr__(self, name: str) -> _Method: ... + def __call__(self, *args: Any) -> Any: ... + +class Transport: + user_agent = ... # type: str + accept_gzip_encoding = ... # type: bool + encode_threshold = ... # type: Optional[int] + def __init__(self, use_datetime: bool = ...) -> None: ... + def request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> tuple: ... + verbose = ... # type: bool + def single_request(self, host: _hostDesc, handler: str, request_body: str, verbose: bool = ...) -> tuple: ... + def getparser(self) -> Tuple[Union[ExpatParser, SlowParser], Unmarshaller]: ... + def get_host_info(self, host: _hostDesc) -> Tuple[str, Optional[List[Tuple[str, str]]], Optional[Mapping[Any, Any]]]: ... + def make_connection(self, host: _hostDesc) -> HTTPConnection: ... + def close(self) -> None: ... + def send_request(self, connection: HTTPConnection, handler: str, request_body: str) -> None: ... + def send_host(self, connection: HTTPConnection, host: str) -> None: ... + def send_user_agent(self, connection: HTTPConnection) -> None: ... + def send_content(self, connection: HTTPConnection, request_body: str) -> None: ... + def parse_response(self, response: HTTPResponse) -> tuple: ... + +class SafeTransport(Transport): + def __init__(self, use_datetime: bool = ..., context: Optional[SSLContext] = ...) -> None: ... + def make_connection(self, host: _hostDesc) -> HTTPSConnection: ... + +class ServerProxy: + def __init__(self, uri: str, transport: Optional[Transport] = ..., encoding: Optional[str] = ..., verbose: bool = ..., allow_none: bool = ..., use_datetime: bool = ..., context: Optional[SSLContext] = ...) -> None: ... + def __getattr__(self, name: str) -> _Method: ... + def __call__(self, attr: str) -> Optional[Transport]: ... + +Server = ServerProxy diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/__future__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/__future__.pyi new file mode 100644 index 000000000..13db2dc6b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/__future__.pyi @@ -0,0 +1,24 @@ +import sys +from typing import List + +class _Feature: + def getOptionalRelease(self) -> sys._version_info: ... + def getMandatoryRelease(self) -> sys._version_info: ... + +absolute_import: _Feature +division: _Feature +generators: _Feature +nested_scopes: _Feature +print_function: _Feature +unicode_literals: _Feature +with_statement: _Feature +if sys.version_info >= (3, 0): + barry_as_FLUFL: _Feature + +if sys.version_info >= (3, 5): + generator_stop: _Feature + +if sys.version_info >= (3, 7): + annotations: _Feature + +all_feature_names: List[str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_bisect.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_bisect.pyi new file mode 100644 index 000000000..62335472f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_bisect.pyi @@ -0,0 +1,11 @@ +"""Stub file for the '_bisect' module.""" + +from typing import Sequence, TypeVar + +_T = TypeVar('_T') +def bisect(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +def insort(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... +def insort_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... +def insort_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_codecs.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_codecs.pyi new file mode 100644 index 000000000..32163eb91 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_codecs.pyi @@ -0,0 +1,74 @@ +"""Stub file for the '_codecs' module.""" + +import sys +from typing import Any, Callable, Tuple, Optional, Dict, Text, Union + +import codecs + +# For convenience: +_Handler = Callable[[Exception], Tuple[Text, int]] +_String = Union[bytes, str] +_Errors = Union[str, Text, None] +if sys.version_info < (3, 0): + _Decodable = Union[bytes, Text] + _Encodable = Union[bytes, Text] +else: + _Decodable = bytes + _Encodable = str + +# This type is not exposed; it is defined in unicodeobject.c +class _EncodingMap(object): + def size(self) -> int: ... +_MapT = Union[Dict[int, int], _EncodingMap] + +def register(search_function: Callable[[str], Any]) -> None: ... +def register_error(errors: Union[str, Text], handler: _Handler) -> None: ... +def lookup(encoding: Union[str, Text]) -> codecs.CodecInfo: ... +def lookup_error(name: Union[str, Text]) -> _Handler: ... +def decode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ... +def encode(obj: Any, encoding: Union[str, Text] = ..., errors: _Errors = ...) -> Any: ... +def charmap_build(map: Text) -> _MapT: ... + +def ascii_decode(data: _Decodable, errors: _Errors = ...) -> Tuple[Text, int]: ... +def ascii_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def charbuffer_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def charmap_decode(data: _Decodable, errors: _Errors = ..., mapping: Optional[_MapT] = ...) -> Tuple[Text, int]: ... +def charmap_encode(data: _Encodable, errors: _Errors, mapping: Optional[_MapT] = ...) -> Tuple[bytes, int]: ... +def escape_decode(data: _String, errors: _Errors = ...) -> Tuple[str, int]: ... +def escape_encode(data: bytes, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def latin_1_decode(data: _Decodable, errors: _Errors = ...) -> Tuple[Text, int]: ... +def latin_1_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def raw_unicode_escape_decode(data: _String, errors: _Errors = ...) -> Tuple[Text, int]: ... +def raw_unicode_escape_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def readbuffer_encode(data: _String, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def unicode_escape_decode(data: _String, errors: _Errors = ...) -> Tuple[Text, int]: ... +def unicode_escape_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def unicode_internal_decode(data: _String, errors: _Errors = ...) -> Tuple[Text, int]: ... +def unicode_internal_encode(data: _String, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def utf_16_be_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_16_be_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def utf_16_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_16_encode(data: _Encodable, errors: _Errors = ..., byteorder: int = ...) -> Tuple[bytes, int]: ... +def utf_16_ex_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int, int]: ... +def utf_16_le_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_16_le_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def utf_32_be_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_32_be_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def utf_32_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_32_encode(data: _Encodable, errors: _Errors = ..., byteorder: int = ...) -> Tuple[bytes, int]: ... +def utf_32_ex_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int, int]: ... +def utf_32_le_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_32_le_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def utf_7_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_7_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... +def utf_8_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... +def utf_8_encode(data: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... + +if sys.platform == 'win32': + def mbcs_decode(data: _Decodable, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... + def mbcs_encode(str: _Encodable, errors: _Errors = ...) -> Tuple[bytes, int]: ... + if sys.version_info >= (3, 0): + def oem_decode(data: bytes, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... + def code_page_decode(codepage: int, data: bytes, errors: _Errors = ..., final: int = ...) -> Tuple[Text, int]: ... + def oem_encode(str: Text, errors: _Errors = ...) -> Tuple[bytes, int]: ... + def code_page_encode(code_page: int, str: Text, errors: _Errors = ...) -> Tuple[bytes, int]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_csv.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_csv.pyi new file mode 100644 index 000000000..9f6a9e86e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_csv.pyi @@ -0,0 +1,49 @@ +import sys + +from typing import Any, Iterable, Iterator, List, Optional, Sequence + +QUOTE_ALL = ... # type: int +QUOTE_MINIMAL = ... # type: int +QUOTE_NONE = ... # type: int +QUOTE_NONNUMERIC = ... # type: int + +class Error(Exception): ... + +class Dialect: + delimiter = ... # type: str + quotechar = ... # type: Optional[str] + escapechar = ... # type: Optional[str] + doublequote = ... # type: bool + skipinitialspace = ... # type: bool + lineterminator = ... # type: str + quoting = ... # type: int + strict = ... # type: int + def __init__(self) -> None: ... + +class _reader(Iterator[List[str]]): + dialect = ... # type: Dialect + line_num = ... # type: int + if sys.version_info >= (3, 0): + def __next__(self) -> List[str]: ... + else: + def next(self) -> List[str]: ... + +class _writer: + dialect = ... # type: Dialect + + if sys.version_info >= (3, 5): + def writerow(self, row: Iterable[Any]) -> None: ... + def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ... + else: + def writerow(self, row: Sequence[Any]) -> None: ... + def writerows(self, rows: Iterable[Sequence[Any]]) -> None: ... + + +# TODO: precise type +def writer(csvfile: Any, dialect: Any = ..., **fmtparams: Any) -> _writer: ... +def reader(csvfile: Iterable[str], dialect: Any = ..., **fmtparams: Any) -> _reader: ... +def register_dialect(name: str, dialect: Any = ..., **fmtparams: Any) -> None: ... +def unregister_dialect(name: str) -> None: ... +def get_dialect(name: str) -> Dialect: ... +def list_dialects() -> List[str]: ... +def field_size_limit(new_limit: int = ...) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_heapq.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_heapq.pyi new file mode 100644 index 000000000..8b7f6eac0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_heapq.pyi @@ -0,0 +1,15 @@ +"""Stub file for the '_heapq' module.""" + +from typing import TypeVar, List + +_T = TypeVar("_T") + +def heapify(heap: List[_T]) -> None: ... +def heappop(heap: List[_T]) -> _T: + raise IndexError() # if list is empty +def heappush(heap: List[_T], item: _T) -> None: ... +def heappushpop(heap: List[_T], item: _T) -> _T: ... +def heapreplace(heap: List[_T], item: _T) -> _T: + raise IndexError() # if list is empty +def nlargest(a: int, b: List[_T]) -> List[_T]: ... +def nsmallest(a: int, b: List[_T]) -> List[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_random.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_random.pyi new file mode 100644 index 000000000..a37149da0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_random.pyi @@ -0,0 +1,17 @@ +# Stubs for _random + +import sys +from typing import Tuple + +# Actually Tuple[(int,) * 625] +_State = Tuple[int, ...] + +class Random(object): + def __init__(self, seed: object = ...) -> None: ... + def seed(self, x: object = ...) -> None: ... + def getstate(self) -> _State: ... + def setstate(self, state: _State) -> None: ... + def random(self) -> float: ... + def getrandbits(self, k: int) -> int: ... + if sys.version_info < (3,): + def jumpahead(self, i: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_weakref.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_weakref.pyi new file mode 100644 index 000000000..76c97df54 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_weakref.pyi @@ -0,0 +1,24 @@ +import sys +from typing import Any, Callable, Generic, Optional, TypeVar + +_T = TypeVar('_T') + +class CallableProxyType(object): # "weakcallableproxy" + def __getattr__(self, attr: str) -> Any: ... + +class ProxyType(object): # "weakproxy" + def __getattr__(self, attr: str) -> Any: ... + +class ReferenceType(Generic[_T]): + if sys.version_info >= (3, 4): + __callback__: Callable[[ReferenceType[_T]], Any] + def __init__(self, o: _T, callback: Callable[[ReferenceType[_T]], + Any] = ...) -> None: ... + def __call__(self) -> Optional[_T]: ... + def __hash__(self) -> int: ... + +ref = ReferenceType + +def getweakrefcount(object: Any) -> int: ... +def getweakrefs(object: Any) -> int: ... +def proxy(object: _T, callback: Callable[[_T], Any] = ...) -> ref[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_weakrefset.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_weakrefset.pyi new file mode 100644 index 000000000..950d3fe64 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/_weakrefset.pyi @@ -0,0 +1,43 @@ +from typing import Iterator, Any, Iterable, MutableSet, Optional, TypeVar, Generic, Union + +_S = TypeVar('_S') +_T = TypeVar('_T') +_SelfT = TypeVar('_SelfT', bound=WeakSet) + +class WeakSet(MutableSet[_T], Generic[_T]): + def __init__(self, data: Optional[Iterable[_T]] = ...) -> None: ... + + def add(self, item: _T) -> None: ... + def clear(self) -> None: ... + def discard(self, item: _T) -> None: ... + def copy(self: _SelfT) -> _SelfT: ... + def pop(self) -> _T: ... + def remove(self, item: _T) -> None: ... + def update(self, other: Iterable[_T]) -> None: ... + def __contains__(self, item: object) -> bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + + def __ior__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def difference(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def __sub__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def difference_update(self: _SelfT, other: Iterable[_T]) -> None: ... + def __isub__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def intersection(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def __and__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def intersection_update(self, other: Iterable[_T]) -> None: ... + def __iand__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def issubset(self, other: Iterable[_T]) -> bool: ... + def __le__(self, other: Iterable[_T]) -> bool: ... + def __lt__(self, other: Iterable[_T]) -> bool: ... + def issuperset(self, other: Iterable[_T]) -> bool: ... + def __ge__(self, other: Iterable[_T]) -> bool: ... + def __gt__(self, other: Iterable[_T]) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def __xor__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def symmetric_difference_update(self, other: Iterable[_S]) -> None: ... + def __ixor__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def union(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def __or__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def isdisjoint(self, other: Iterable[_T]) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/argparse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/argparse.pyi new file mode 100644 index 000000000..88b909793 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/argparse.pyi @@ -0,0 +1,380 @@ +# Stubs for argparse (Python 2.7 and 3.4) + +from typing import ( + Any, Callable, Dict, Generator, Iterable, List, IO, NoReturn, Optional, + Pattern, Sequence, Tuple, Type, Union, TypeVar, overload +) +import sys + +_T = TypeVar('_T') +_ActionT = TypeVar('_ActionT', bound='Action') + +if sys.version_info >= (3,): + _Text = str +else: + _Text = Union[str, unicode] + +ONE_OR_MORE: str +OPTIONAL: str +PARSER: str +REMAINDER: str +SUPPRESS: str +ZERO_OR_MORE: str +_UNRECOGNIZED_ARGS_ATTR: str # undocumented + +class ArgumentError(Exception): ... + +# undocumented +class _AttributeHolder: + def _get_kwargs(self) -> List[Tuple[str, Any]]: ... + def _get_args(self) -> List[Any]: ... + +# undocumented +class _ActionsContainer: + description: Optional[_Text] + prefix_chars: _Text + argument_default: Optional[_Text] + conflict_handler: _Text + + _registries: Dict[_Text, Dict[Any, Any]] + _actions: List[Action] + _option_string_actions: Dict[_Text, Action] + _action_groups: List[_ArgumentGroup] + _mutually_exclusive_groups: List[_MutuallyExclusiveGroup] + _defaults: Dict[str, Any] + _negative_number_matcher: Pattern[str] + _has_negative_number_optionals: List[bool] + + def __init__(self, description: Optional[_Text], prefix_chars: _Text, + argument_default: Optional[_Text], conflict_handler: _Text) -> None: ... + def register(self, registry_name: _Text, value: Any, object: Any) -> None: ... + def _registry_get(self, registry_name: _Text, value: Any, default: Any = ...) -> Any: ... + def set_defaults(self, **kwargs: Any) -> None: ... + def get_default(self, dest: _Text) -> Any: ... + def add_argument(self, + *name_or_flags: _Text, + action: Union[_Text, Type[Action]] = ..., + nargs: Union[int, _Text] = ..., + const: Any = ..., + default: Any = ..., + type: Union[Callable[[str], _T], FileType] = ..., + choices: Iterable[_T] = ..., + required: bool = ..., + help: Optional[_Text] = ..., + metavar: Union[_Text, Tuple[_Text, ...]] = ..., + dest: Optional[_Text] = ..., + version: _Text = ...) -> Action: ... + def add_argument_group(self, *args: Any, **kwargs: Any) -> _ArgumentGroup: ... + def add_mutually_exclusive_group(self, **kwargs: Any) -> _MutuallyExclusiveGroup: ... + def _add_action(self, action: _ActionT) -> _ActionT: ... + def _remove_action(self, action: Action) -> None: ... + def _add_container_actions(self, container: _ActionsContainer) -> None: ... + def _get_positional_kwargs(self, dest: _Text, **kwargs: Any) -> Dict[str, Any]: ... + def _get_optional_kwargs(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: ... + def _pop_action_class(self, kwargs: Any, default: Optional[Type[Action]] = ...) -> Type[Action]: ... + def _get_handler(self) -> Callable[[Action, Iterable[Tuple[_Text, Action]]], Any]: ... + def _check_conflict(self, action: Action) -> None: ... + def _handle_conflict_error(self, action: Action, conflicting_actions: Iterable[Tuple[_Text, Action]]) -> NoReturn: ... + def _handle_conflict_resolve(self, action: Action, conflicting_actions: Iterable[Tuple[_Text, Action]]) -> None: ... + +class ArgumentParser(_AttributeHolder, _ActionsContainer): + prog: _Text + usage: Optional[_Text] + epilog: Optional[_Text] + formatter_class: Type[HelpFormatter] + fromfile_prefix_chars: Optional[_Text] + add_help: bool + + if sys.version_info >= (3, 5): + allow_abbrev: bool + + # undocumented + _positionals: _ArgumentGroup + _optionals: _ArgumentGroup + _subparsers: Optional[_ArgumentGroup] + + if sys.version_info >= (3, 5): + def __init__(self, + prog: Optional[str] = ..., + usage: Optional[str] = ..., + description: Optional[str] = ..., + epilog: Optional[str] = ..., + parents: Sequence[ArgumentParser] = ..., + formatter_class: Type[HelpFormatter] = ..., + prefix_chars: _Text = ..., + fromfile_prefix_chars: Optional[str] = ..., + argument_default: Optional[str] = ..., + conflict_handler: _Text = ..., + add_help: bool = ..., + allow_abbrev: bool = ...) -> None: ... + else: + def __init__(self, + prog: Optional[_Text] = ..., + usage: Optional[_Text] = ..., + description: Optional[_Text] = ..., + epilog: Optional[_Text] = ..., + parents: Sequence[ArgumentParser] = ..., + formatter_class: Type[HelpFormatter] = ..., + prefix_chars: _Text = ..., + fromfile_prefix_chars: Optional[_Text] = ..., + argument_default: Optional[_Text] = ..., + conflict_handler: _Text = ..., + add_help: bool = ...) -> None: ... + def parse_args(self, args: Optional[Sequence[_Text]] = ..., + namespace: Optional[Namespace] = ...) -> Namespace: ... + def add_subparsers(self, title: _Text = ..., + description: Optional[_Text] = ..., + prog: _Text = ..., + parser_class: Type[ArgumentParser] = ..., + action: Type[Action] = ..., + option_string: _Text = ..., + dest: Optional[_Text] = ..., + help: Optional[_Text] = ..., + metavar: Optional[_Text] = ...) -> _SubParsersAction: ... + def print_usage(self, file: Optional[IO[str]] = ...) -> None: ... + def print_help(self, file: Optional[IO[str]] = ...) -> None: ... + def format_usage(self) -> str: ... + def format_help(self) -> str: ... + def parse_known_args(self, args: Optional[Sequence[_Text]] = ..., + namespace: Optional[Namespace] = ...) -> Tuple[Namespace, List[str]]: ... + def convert_arg_line_to_args(self, arg_line: _Text) -> List[str]: ... + def exit(self, status: int = ..., message: Optional[_Text] = ...) -> NoReturn: ... + def error(self, message: _Text) -> NoReturn: ... + if sys.version_info >= (3, 7): + def parse_intermixed_args(self, args: Optional[Sequence[_Text]] = ..., + namespace: Optional[Namespace] = ...) -> Namespace: ... + def parse_known_intermixed_args(self, + args: Optional[Sequence[_Text]] = ..., + namespace: Optional[Namespace] = ...) -> Tuple[Namespace, List[str]]: ... + # undocumented + def _get_optional_actions(self) -> List[Action]: ... + def _get_positional_actions(self) -> List[Action]: ... + def _parse_known_args(self, arg_strings: List[_Text], namespace: Namespace) -> Tuple[Namespace, List[str]]: ... + def _read_args_from_files(self, arg_strings: List[_Text]) -> List[_Text]: ... + def _match_argument(self, action: Action, arg_strings_pattern: _Text) -> int: ... + def _match_arguments_partial(self, actions: Sequence[Action], arg_strings_pattern: _Text) -> List[int]: ... + def _parse_optional(self, arg_string: _Text) -> Optional[Tuple[Optional[Action], _Text, Optional[_Text]]]: ... + def _get_option_tuples(self, option_string: _Text) -> List[Tuple[Action, _Text, Optional[_Text]]]: ... + def _get_nargs_pattern(self, action: Action) -> _Text: ... + def _get_values(self, action: Action, arg_strings: List[_Text]) -> Any: ... + def _get_value(self, action: Action, arg_string: _Text) -> Any: ... + def _check_value(self, action: Action, value: Any) -> None: ... + def _get_formatter(self) -> HelpFormatter: ... + def _print_message(self, message: str, file: Optional[IO[str]] = ...) -> None: ... + +class HelpFormatter: + # undocumented + _prog: _Text + _indent_increment: int + _max_help_position: int + _width: int + _current_indent: int + _level: int + _action_max_length: int + _root_section: Any + _current_section: Any + _whitespace_matcher: Pattern[str] + _long_break_matcher: Pattern[str] + _Section: Type[Any] # Nested class + def __init__(self, prog: _Text, indent_increment: int = ..., + max_help_position: int = ..., + width: Optional[int] = ...) -> None: ... + def _indent(self) -> None: ... + def _dedent(self) -> None: ... + def _add_item(self, func: Callable[..., _Text], args: Iterable[Any]) -> None: ... + def start_section(self, heading: Optional[_Text]) -> None: ... + def end_section(self) -> None: ... + def add_text(self, text: Optional[_Text]) -> None: ... + def add_usage(self, usage: _Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[_Text] = ...) -> None: ... + def add_argument(self, action: Action) -> None: ... + def add_arguments(self, actions: Iterable[Action]) -> None: ... + def format_help(self) -> _Text: ... + def _join_parts(self, part_strings: Iterable[_Text]) -> _Text: ... + def _format_usage(self, usage: _Text, actions: Iterable[Action], groups: Iterable[_ArgumentGroup], prefix: Optional[_Text]) -> _Text: ... + def _format_actions_usage(self, actions: Iterable[Action], groups: Iterable[_ArgumentGroup]) -> _Text: ... + def _format_text(self, text: _Text) -> _Text: ... + def _format_action(self, action: Action) -> _Text: ... + def _format_action_invocation(self, action: Action) -> _Text: ... + def _metavar_formatter(self, action: Action, default_metavar: _Text) -> Callable[[int], Tuple[_Text, ...]]: ... + def _format_args(self, action: Action, default_metavar: _Text) -> _Text: ... + def _expand_help(self, action: Action) -> _Text: ... + def _iter_indented_subactions(self, action: Action) -> Generator[Action, None, None]: ... + def _split_lines(self, text: _Text, width: int) -> List[_Text]: ... + def _fill_text(self, text: _Text, width: int, indent: int) -> _Text: ... + def _get_help_string(self, action: Action) -> Optional[_Text]: ... + def _get_default_metavar_for_optional(self, action: Action) -> _Text: ... + def _get_default_metavar_for_positional(self, action: Action) -> _Text: ... + +class RawDescriptionHelpFormatter(HelpFormatter): ... +class RawTextHelpFormatter(HelpFormatter): ... +class ArgumentDefaultsHelpFormatter(HelpFormatter): ... +if sys.version_info >= (3,): + class MetavarTypeHelpFormatter(HelpFormatter): ... + +class Action(_AttributeHolder): + option_strings: Sequence[_Text] + dest: _Text + nargs: Optional[Union[int, _Text]] + const: Any + default: Any + type: Union[Callable[[str], Any], FileType, None] + choices: Optional[Iterable[Any]] + required: bool + help: Optional[_Text] + metavar: Union[_Text, Tuple[_Text, ...]] + + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text, + nargs: Optional[Union[int, _Text]] = ..., + const: Any = ..., + default: Any = ..., + type: Optional[Union[Callable[[str], _T], FileType]] = ..., + choices: Optional[Iterable[_T]] = ..., + required: bool = ..., + help: Optional[_Text] = ..., + metavar: Optional[Union[_Text, Tuple[_Text, ...]]] = ...) -> None: ... + def __call__(self, parser: ArgumentParser, namespace: Namespace, + values: Union[_Text, Sequence[Any], None], + option_string: Optional[_Text] = ...) -> None: ... + +class Namespace(_AttributeHolder): + def __init__(self, **kwargs: Any) -> None: ... + def __getattr__(self, name: _Text) -> Any: ... + def __setattr__(self, name: _Text, value: Any) -> None: ... + def __contains__(self, key: str) -> bool: ... + +class FileType: + # undocumented + _mode: _Text + _bufsize: int + if sys.version_info >= (3, 4): + _encoding: Optional[_Text] + _errors: Optional[_Text] + if sys.version_info >= (3, 4): + def __init__(self, mode: _Text = ..., bufsize: int = ..., + encoding: Optional[_Text] = ..., + errors: Optional[_Text] = ...) -> None: ... + elif sys.version_info >= (3,): + def __init__(self, + mode: _Text = ..., bufsize: int = ...) -> None: ... + else: + def __init__(self, + mode: _Text = ..., bufsize: Optional[int] = ...) -> None: ... + def __call__(self, string: _Text) -> IO[Any]: ... + +# undocumented +class _ArgumentGroup(_ActionsContainer): + title: Optional[_Text] + _group_actions: List[Action] + def __init__(self, container: _ActionsContainer, + title: Optional[_Text] = ..., + description: Optional[_Text] = ..., **kwargs: Any) -> None: ... + +# undocumented +class _MutuallyExclusiveGroup(_ArgumentGroup): + required: bool + _container: _ActionsContainer + def __init__(self, container: _ActionsContainer, required: bool = ...) -> None: ... + +# undocumented +class _StoreAction(Action): ... + +# undocumented +class _StoreConstAction(Action): + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text, + const: Any, + default: Any = ..., + required: bool = ..., + help: Optional[_Text] = ..., + metavar: Optional[Union[_Text, Tuple[_Text, ...]]] = ...) -> None: ... + +# undocumented +class _StoreTrueAction(_StoreConstAction): + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text, + default: bool = ..., + required: bool = ..., + help: Optional[_Text] = ...) -> None: ... + +# undocumented +class _StoreFalseAction(_StoreConstAction): + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text, + default: bool = ..., + required: bool = ..., + help: Optional[_Text] = ...) -> None: ... + +# undocumented +class _AppendAction(Action): ... + +# undocumented +class _AppendConstAction(Action): + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text, + const: Any, + default: Any = ..., + required: bool = ..., + help: Optional[_Text] = ..., + metavar: Optional[Union[_Text, Tuple[_Text, ...]]] = ...) -> None: ... + +# undocumented +class _CountAction(Action): + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text, + default: Any = ..., + required: bool = ..., + help: Optional[_Text] = ...) -> None: ... + +# undocumented +class _HelpAction(Action): + def __init__(self, + option_strings: Sequence[_Text], + dest: _Text = ..., + default: _Text = ..., + help: Optional[_Text] = ...) -> None: ... + +# undocumented +class _VersionAction(Action): + version: Optional[_Text] + def __init__(self, + option_strings: Sequence[_Text], + version: Optional[_Text] = ..., + dest: _Text = ..., + default: _Text = ..., + help: _Text = ...) -> None: ... + +# undocumented +class _SubParsersAction(Action): + _ChoicesPseudoAction: Type[Any] # nested class + _prog_prefix: _Text + _parser_class: Type[ArgumentParser] + _name_parser_map: Dict[_Text, ArgumentParser] + _choices_actions: List[Action] + def __init__(self, + option_strings: Sequence[_Text], + prog: _Text, + parser_class: Type[ArgumentParser], + dest: _Text = ..., + required: bool = ..., + help: Optional[_Text] = ..., + metavar: Optional[Union[_Text, Tuple[_Text, ...]]] = ...) -> None: ... + # TODO: Type keyword args properly. + def add_parser(self, name: _Text, **kwargs: Any) -> ArgumentParser: ... + def _get_subactions(self) -> List[Action]: ... + +# undocumented +class ArgumentTypeError(Exception): ... + +if sys.version_info < (3, 7): + # undocumented + def _ensure_value(namespace: Namespace, name: _Text, value: Any) -> Any: ... + +# undocumented +def _get_action_name(argument: Optional[Action]) -> Optional[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/array.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/array.pyi new file mode 100644 index 000000000..84e7e5ef4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/array.pyi @@ -0,0 +1,73 @@ +# Stubs for array + +# Based on http://docs.python.org/3.6/library/array.html + +import sys +from typing import (Any, BinaryIO, Generic, Iterable, Iterator, List, MutableSequence, + overload, Text, Tuple, TypeVar, Union) + +_T = TypeVar('_T', int, float, Text) + +if sys.version_info >= (3,): + typecodes = ... # type: str + +class array(MutableSequence[_T], Generic[_T]): + typecode = ... # type: str + itemsize = ... # type: int + def __init__(self, typecode: str, + __initializer: Union[bytes, Iterable[_T]] = ...) -> None: ... + def append(self, x: _T) -> None: ... + def buffer_info(self) -> Tuple[int, int]: ... + def byteswap(self) -> None: ... + def count(self, x: Any) -> int: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + if sys.version_info >= (3, 2): + def frombytes(self, s: bytes) -> None: ... + def fromfile(self, f: BinaryIO, n: int) -> None: ... + def fromlist(self, list: List[_T]) -> None: ... + def fromstring(self, s: bytes) -> None: ... + def fromunicode(self, s: str) -> None: ... + def index(self, x: _T) -> int: ... # type: ignore # Overrides Sequence + def insert(self, i: int, x: _T) -> None: ... + def pop(self, i: int = ...) -> _T: ... + if sys.version_info < (3,): + def read(self, f: BinaryIO, n: int) -> None: ... + def remove(self, x: Any) -> None: ... + def reverse(self) -> None: ... + if sys.version_info >= (3, 2): + def tobytes(self) -> bytes: ... + def tofile(self, f: BinaryIO) -> None: ... + def tolist(self) -> List[_T]: ... + def tostring(self) -> bytes: ... + def tounicode(self) -> str: ... + if sys.version_info < (3,): + def write(self, f: BinaryIO) -> None: ... + + def __len__(self) -> int: ... + + @overload + def __getitem__(self, i: int) -> _T: ... + @overload + def __getitem__(self, s: slice) -> array[_T]: ... + + @overload # type: ignore # Overrides MutableSequence + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + def __setitem__(self, s: slice, o: array[_T]) -> None: ... + + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __add__(self, x: array[_T]) -> array[_T]: ... + def __ge__(self, other: array[_T]) -> bool: ... + def __gt__(self, other: array[_T]) -> bool: ... + def __iadd__(self, x: array[_T]) -> array[_T]: ... # type: ignore # Overrides MutableSequence + def __imul__(self, n: int) -> array[_T]: ... + def __le__(self, other: array[_T]) -> bool: ... + def __lt__(self, other: array[_T]) -> bool: ... + def __mul__(self, n: int) -> array[_T]: ... + def __rmul__(self, n: int) -> array[_T]: ... + if sys.version_info < (3,): + def __delslice__(self, i: int, j: int) -> None: ... + def __getslice__(self, i: int, j: int) -> array[_T]: ... + def __setslice__(self, i: int, j: int, y: array[_T]) -> None: ... + +ArrayType = array diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/asynchat.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/asynchat.pyi new file mode 100644 index 000000000..0e6ca7eb8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/asynchat.pyi @@ -0,0 +1,41 @@ +from abc import abstractmethod +import asyncore +import socket +import sys +from typing import Optional, Sequence, Tuple, Union + + +class simple_producer: + def __init__(self, data: bytes, buffer_size: int = ...) -> None: ... + def more(self) -> bytes: ... + +class async_chat(asyncore.dispatcher): + ac_in_buffer_size = ... # type: int + ac_out_buffer_size = ... # type: int + def __init__(self, sock: Optional[socket.socket] = ..., map: Optional[asyncore._maptype] = ...) -> None: ... + + @abstractmethod + def collect_incoming_data(self, data: bytes) -> None: ... + @abstractmethod + def found_terminator(self) -> None: ... + def set_terminator(self, term: Union[bytes, int, None]) -> None: ... + def get_terminator(self) -> Union[bytes, int, None]: ... + def handle_read(self) -> None: ... + def handle_write(self) -> None: ... + def handle_close(self) -> None: ... + def push(self, data: bytes) -> None: ... + def push_with_producer(self, producer: simple_producer) -> None: ... + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def close_when_done(self) -> None: ... + def initiate_send(self) -> None: ... + def discard_buffers(self) -> None: ... + +if sys.version_info < (3, 0): + class fifo: + def __init__(self, list: Sequence[Union[bytes, simple_producer]] = ...) -> None: ... + def __len__(self) -> int: ... + def is_empty(self) -> bool: ... + def first(self) -> bytes: ... + def push(self, data: Union[bytes, simple_producer]) -> None: ... + def pop(self) -> Tuple[int, bytes]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/asyncore.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/asyncore.pyi new file mode 100644 index 000000000..a5126ccb3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/asyncore.pyi @@ -0,0 +1,144 @@ +from typing import Tuple, Union, Optional, Any, Dict, overload + +import os +import select +import sys +import time +import warnings +from socket import SocketType +from typing import Optional + +from errno import (EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, + ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, + EPIPE, EAGAIN, errorcode) + +# cyclic dependence with asynchat +_maptype = Dict[str, Any] + + +class ExitNow(Exception): ... + +def read(obj: Any) -> None: ... +def write(obj: Any) -> None: ... +def readwrite(obj: Any, flags: int) -> None: ... +def poll(timeout: float = ..., map: _maptype = ...) -> None: ... +def poll2(timeout: float = ..., map: _maptype = ...) -> None: ... + +poll3 = poll2 + +def loop(timeout: float = ..., use_poll: bool = ..., map: _maptype = ..., count: Optional[int] = ...) -> None: ... + + +# Not really subclass of socket.socket; it's only delegation. +# It is not covariant to it. +class dispatcher: + + debug = ... # type: bool + connected = ... # type: bool + accepting = ... # type: bool + connecting = ... # type: bool + closing = ... # type: bool + ignore_log_types = ... # type: frozenset[str] + socket = ... # type: Optional[SocketType] # undocumented + + def __init__(self, sock: Optional[SocketType] = ..., map: _maptype = ...) -> None: ... + def add_channel(self, map: _maptype = ...) -> None: ... + def del_channel(self, map: _maptype = ...) -> None: ... + def create_socket(self, family: int, type: int) -> None: ... + def set_socket(self, sock: SocketType, map: _maptype = ...) -> None: ... + def set_reuse_addr(self) -> None: ... + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def listen(self, backlog: int) -> None: ... + def bind(self, address: Union[tuple, str]) -> None: ... + def connect(self, address: Union[tuple, str]) -> None: ... + def accept(self) -> Optional[Tuple[SocketType, Any]]: ... + def send(self, data: bytes) -> int: ... + def recv(self, buffer_size: int) -> bytes: ... + def close(self) -> None: ... + + def log(self, message: Any) -> None: ... + def log_info(self, message: Any, type: str = ...) -> None: ... + def handle_read_event(self) -> None: ... + def handle_connect_event(self) -> None: ... + def handle_write_event(self) -> None: ... + def handle_expt_event(self) -> None: ... + def handle_error(self) -> None: ... + def handle_expt(self) -> None: ... + def handle_read(self) -> None: ... + def handle_write(self) -> None: ... + def handle_connect(self) -> None: ... + def handle_accept(self) -> None: ... + def handle_close(self) -> None: ... + + if sys.version_info < (3, 5): + # Historically, some methods were "imported" from `self.socket` by + # means of `__getattr__`. This was long deprecated, and as of Python + # 3.5 has been removed; simply call the relevant methods directly on + # self.socket if necessary. + + def detach(self) -> int: ... + def fileno(self) -> int: ... + + # return value is an address + def getpeername(self) -> Any: ... + def getsockname(self) -> Any: ... + + @overload + def getsockopt(self, level: int, optname: int) -> int: ... + @overload + def getsockopt(self, level: int, optname: int, buflen: int) -> bytes: ... + + def gettimeout(self) -> float: ... + def ioctl(self, control: object, + option: Tuple[int, int, int]) -> None: ... + # TODO the return value may be BinaryIO or TextIO, depending on mode + def makefile(self, mode: str = ..., buffering: int = ..., + encoding: str = ..., errors: str = ..., + newline: str = ...) -> Any: + ... + + # return type is an address + def recvfrom(self, bufsize: int, flags: int = ...) -> Any: ... + def recvfrom_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ... + def recv_into(self, buffer: bytes, nbytes: int, flags: int = ...) -> Any: ... + def sendall(self, data: bytes, flags: int = ...) -> None: ... + def sendto(self, data: bytes, address: Union[tuple, str], flags: int = ...) -> int: ... + def setblocking(self, flag: bool) -> None: ... + def settimeout(self, value: Union[float, None]) -> None: ... + def setsockopt(self, level: int, optname: int, value: Union[int, bytes]) -> None: ... + def shutdown(self, how: int) -> None: ... + +class dispatcher_with_send(dispatcher): + def __init__(self, sock: SocketType = ..., map: _maptype = ...) -> None: ... + def initiate_send(self) -> None: ... + def handle_write(self) -> None: ... + # incompatible signature: + # def send(self, data: bytes) -> Optional[int]: ... + +def compact_traceback() -> Tuple[Tuple[str, str, str], type, type, str]: ... +def close_all(map: _maptype = ..., ignore_all: bool = ...) -> None: ... + +# if os.name == 'posix': +# import fcntl +class file_wrapper: + fd = ... # type: int + + def __init__(self, fd: int) -> None: ... + def recv(self, bufsize: int, flags: int = ...) -> bytes: ... + def send(self, data: bytes, flags: int = ...) -> int: ... + + @overload + def getsockopt(self, level: int, optname: int) -> int: ... + @overload + def getsockopt(self, level: int, optname: int, buflen: int) -> bytes: ... + + def read(self, bufsize: int, flags: int = ...) -> bytes: ... + def write(self, data: bytes, flags: int = ...) -> int: ... + + def close(self) -> None: ... + def fileno(self) -> int: ... + +class file_dispatcher(dispatcher): + def __init__(self, fd: int, map: _maptype = ...) -> None: ... + def set_file(self, fd: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/base64.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/base64.pyi new file mode 100644 index 000000000..70db6ad80 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/base64.pyi @@ -0,0 +1,44 @@ +# Stubs for base64 + +from typing import IO, Union, Text +import sys + +if sys.version_info < (3,): + _encodable = Union[bytes, Text] + _decodable = Union[bytes, Text] +elif sys.version_info < (3, 3): + _encodable = bytes + _decodable = bytes +elif sys.version_info[:2] == (3, 3): + _encodable = bytes + _decodable = Union[bytes, str] +elif sys.version_info >= (3, 4): + _encodable = Union[bytes, bytearray, memoryview] + _decodable = Union[bytes, bytearray, memoryview, str] + +def b64encode(s: _encodable, altchars: bytes = ...) -> bytes: ... +def b64decode(s: _decodable, altchars: bytes = ..., + validate: bool = ...) -> bytes: ... +def standard_b64encode(s: _encodable) -> bytes: ... +def standard_b64decode(s: _decodable) -> bytes: ... +def urlsafe_b64encode(s: _encodable) -> bytes: ... +def urlsafe_b64decode(s: _decodable) -> bytes: ... +def b32encode(s: _encodable) -> bytes: ... +def b32decode(s: _decodable, casefold: bool = ..., + map01: bytes = ...) -> bytes: ... +def b16encode(s: _encodable) -> bytes: ... +def b16decode(s: _decodable, casefold: bool = ...) -> bytes: ... +if sys.version_info >= (3, 4): + def a85encode(b: _encodable, *, foldspaces: bool = ..., wrapcol: int = ..., + pad: bool = ..., adobe: bool = ...) -> bytes: ... + def a85decode(b: _decodable, *, foldspaces: bool = ..., + adobe: bool = ..., ignorechars: Union[str, bytes] = ...) -> bytes: ... + def b85encode(b: _encodable, pad: bool = ...) -> bytes: ... + def b85decode(b: _decodable) -> bytes: ... + +def decode(input: IO[bytes], output: IO[bytes]) -> None: ... +def decodebytes(s: bytes) -> bytes: ... +def decodestring(s: bytes) -> bytes: ... +def encode(input: IO[bytes], output: IO[bytes]) -> None: ... +def encodebytes(s: bytes) -> bytes: ... +def encodestring(s: bytes) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/binascii.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/binascii.pyi new file mode 100644 index 000000000..9c6515ef4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/binascii.pyi @@ -0,0 +1,48 @@ +# Stubs for binascii + +# Based on http://docs.python.org/3.2/library/binascii.html + +import sys +from typing import Union, Text + + +if sys.version_info < (3,): + # Python 2 accepts unicode ascii pretty much everywhere. + _Bytes = Union[bytes, Text] + _Ascii = Union[bytes, Text] +elif sys.version_info < (3, 3): + # Python 3.2 and below only accepts bytes. + _Bytes = bytes + _Ascii = bytes +else: + # But since Python 3.3 ASCII-only unicode strings are accepted by the + # a2b_* functions. + _Bytes = bytes + _Ascii = Union[bytes, Text] + +def a2b_uu(string: _Ascii) -> bytes: ... +if sys.version_info >= (3, 7): + def b2a_uu(data: _Bytes, *, backtick: bool = ...) -> bytes: ... +else: + def b2a_uu(data: _Bytes) -> bytes: ... +def a2b_base64(string: _Ascii) -> bytes: ... +if sys.version_info >= (3, 6): + def b2a_base64(data: _Bytes, *, newline: bool = ...) -> bytes: ... +else: + def b2a_base64(data: _Bytes) -> bytes: ... +def a2b_qp(string: _Ascii, header: bool = ...) -> bytes: ... +def b2a_qp(data: _Bytes, quotetabs: bool = ..., istext: bool = ..., + header: bool = ...) -> bytes: ... +def a2b_hqx(string: _Ascii) -> bytes: ... +def rledecode_hqx(data: _Bytes) -> bytes: ... +def rlecode_hqx(data: _Bytes) -> bytes: ... +def b2a_hqx(data: _Bytes) -> bytes: ... +def crc_hqx(data: _Bytes, crc: int) -> int: ... +def crc32(data: _Bytes, crc: int = ...) -> int: ... +def b2a_hex(data: _Bytes) -> bytes: ... +def hexlify(data: _Bytes) -> bytes: ... +def a2b_hex(hexstr: _Ascii) -> bytes: ... +def unhexlify(hexlify: _Ascii) -> bytes: ... + +class Error(Exception): ... +class Incomplete(Exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/binhex.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/binhex.pyi new file mode 100644 index 000000000..40ead7668 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/binhex.pyi @@ -0,0 +1,48 @@ +from typing import ( + Any, + IO, + Tuple, + Union, +) + + +class Error(Exception): ... + +REASONABLY_LARGE = ... # type: int +LINELEN = ... # type: int +RUNCHAR = ... # type: bytes + +class FInfo: + def __init__(self) -> None: ... + Type = ... # type: str + Creator = ... # type: str + Flags = ... # type: int + +_FileInfoTuple = Tuple[str, FInfo, int, int] +_FileHandleUnion = Union[str, IO[bytes]] + +def getfileinfo(name: str) -> _FileInfoTuple: ... + +class openrsrc: + def __init__(self, *args: Any) -> None: ... + def read(self, *args: Any) -> bytes: ... + def write(self, *args: Any) -> None: ... + def close(self) -> None: ... + +class BinHex: + def __init__(self, name_finfo_dlen_rlen: _FileInfoTuple, ofp: _FileHandleUnion) -> None: ... + def write(self, data: bytes) -> None: ... + def close_data(self) -> None: ... + def write_rsrc(self, data: bytes) -> None: ... + def close(self) -> None: ... + +def binhex(inp: str, out: str) -> None: ... + +class HexBin: + def __init__(self, ifp: _FileHandleUnion) -> None: ... + def read(self, *n: int) -> bytes: ... + def close_data(self) -> None: ... + def read_rsrc(self, *n: int) -> bytes: ... + def close(self) -> None: ... + +def hexbin(inp: str, out: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/bisect.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/bisect.pyi new file mode 100644 index 000000000..5c541124a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/bisect.pyi @@ -0,0 +1,22 @@ +# Stubs for bisect + +from typing import Any, Sequence, TypeVar + +_T = TypeVar('_T') + +# TODO uncomment when mypy# 2035 is fixed +# def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +# def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +# def bisect(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +# +# def insort_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +# def insort_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... +# def insort(a: Sequence[_T], x: _T, lo: int = ..., hi: int = ...) -> int: ... + +def bisect_left(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def bisect_right(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def bisect(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... + +def insort_left(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def insort_right(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... +def insort(a: Sequence, x: Any, lo: int = ..., hi: int = ...) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/bz2.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/bz2.pyi new file mode 100644 index 000000000..2cb329ce9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/bz2.pyi @@ -0,0 +1,48 @@ +import io +import sys +from typing import Any, IO, Optional, Union + +if sys.version_info >= (3, 6): + from os import PathLike + _PathOrFile = Union[str, bytes, IO[Any], PathLike[Any]] +elif sys.version_info >= (3, 3): + _PathOrFile = Union[str, bytes, IO[Any]] +else: + _PathOrFile = str + +def compress(data: bytes, compresslevel: int = ...) -> bytes: ... +def decompress(data: bytes) -> bytes: ... + +if sys.version_info >= (3, 3): + def open(filename: _PathOrFile, + mode: str = ..., + compresslevel: int = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + newline: Optional[str] = ...) -> IO[Any]: ... + +class BZ2File(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#5027 + def __init__(self, + filename: _PathOrFile, + mode: str = ..., + buffering: Optional[Any] = ..., + compresslevel: int = ...) -> None: ... + +class BZ2Compressor(object): + def __init__(self, compresslevel: int = ...) -> None: ... + def compress(self, data: bytes) -> bytes: ... + def flush(self) -> bytes: ... + +class BZ2Decompressor(object): + if sys.version_info >= (3, 5): + def decompress(self, data: bytes, max_length: int = ...) -> bytes: ... + else: + def decompress(self, data: bytes) -> bytes: ... + if sys.version_info >= (3, 3): + @property + def eof(self) -> bool: ... + if sys.version_info >= (3, 5): + @property + def needs_input(self) -> bool: ... + @property + def unused_data(self) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cProfile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cProfile.pyi new file mode 100644 index 000000000..b31ea0337 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cProfile.pyi @@ -0,0 +1,18 @@ +from typing import Any, Callable, Dict, Optional, TypeVar + +def run(statement: str, filename: Optional[str] = ..., sort: int = ...) -> None: ... +def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: int = ...) -> None: ... + +_SelfT = TypeVar('_SelfT', bound='Profile') +_T = TypeVar('_T') + +class Profile: + def __init__(self, custom_timer: Callable[[], float] = ..., time_unit: float = ..., subcalls: bool = ..., builtins: bool = ...) -> None: ... + def enable(self) -> None: ... + def disable(self) -> None: ... + def print_stats(self, sort: int = ...) -> None: ... + def dump_stats(self, file: str) -> None: ... + def create_stats(self) -> None: ... + def run(self: _SelfT, cmd: str) -> _SelfT: ... + def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ... + def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/calendar.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/calendar.pyi new file mode 100644 index 000000000..b792eb644 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/calendar.pyi @@ -0,0 +1,119 @@ +import datetime +import sys +from time import struct_time +from typing import Any, Iterable, List, Optional, Sequence, Tuple, Union + + +_LocaleType = Tuple[Optional[str], Optional[str]] + +class IllegalMonthError(ValueError): + def __init__(self, month: int) -> None: ... + def __str__(self) -> str: ... + +class IllegalWeekdayError(ValueError): + def __init__(self, weekday: int) -> None: ... + def __str__(self) -> str: ... + +def isleap(year: int) -> bool: ... +def leapdays(y1: int, y2: int) -> int: ... +def weekday(year: int, month: int, day: int) -> int: ... +def monthrange(year: int, month: int) -> Tuple[int, int]: ... + +class Calendar: + def __init__(self, firstweekday: int = ...) -> None: ... + def getfirstweekday(self) -> int: ... + def setfirstweekday(self, firstweekday: int) -> None: ... + def iterweekdays(self) -> Iterable[int]: ... + def itermonthdates(self, year: int, month: int) -> Iterable[datetime.date]: ... + def itermonthdays2(self, year: int, month: int) -> Iterable[Tuple[int, int]]: ... + def itermonthdays(self, year: int, month: int) -> Iterable[int]: ... + def monthdatescalendar(self, year: int, month: int) -> List[List[datetime.date]]: ... + def monthdays2calendar(self, year: int, month: int) -> List[List[Tuple[int, int]]]: ... + def monthdayscalendar(self, year: int, month: int) -> List[List[int]]: ... + def yeardatescalendar(self, year: int, width: int = ...) -> List[List[int]]: ... + def yeardays2calendar(self, year: int, width: int = ...) -> List[List[Tuple[int, int]]]: ... + def yeardayscalendar(self, year: int, width: int = ...) -> List[List[int]]: ... + +class TextCalendar(Calendar): + def prweek(self, theweek: int, width: int) -> None: ... + def formatday(self, day: int, weekday: int, width: int) -> str: ... + def formatweek(self, theweek: int, width: int) -> str: ... + def formatweekday(self, day: int, width: int) -> str: ... + def formatweekheader(self, width: int) -> str: ... + def formatmonthname(self, theyear: int, themonth: int, width: int, withyear: bool = ...) -> str: ... + def prmonth(self, theyear: int, themonth: int, w: int = ..., l: int = ...) -> None: ... + def formatmonth(self, theyear: int, themonth: int, w: int = ..., l: int = ...) -> str: ... + def formatyear(self, theyear: int, w: int = ..., l: int = ..., c: int = ..., m: int = ...) -> str: ... + def pryear(self, theyear: int, w: int = ..., l: int = ..., c: int = ..., m: int = ...) -> None: ... + +def firstweekday() -> int: ... +def monthcalendar(year: int, month: int) -> List[List[int]]: ... +def prweek(theweek: int, width: int) -> None: ... +def week(theweek: int, width: int) -> str: ... +def weekheader(width: int) -> str: ... +def prmonth(theyear: int, themonth: int, w: int = ..., l: int = ...) -> None: ... +def month(theyear: int, themonth: int, w: int = ..., l: int = ...) -> str: ... +def calendar(theyear: int, w: int = ..., l: int = ..., c: int = ..., m: int = ...) -> str: ... +def prcal(theyear: int, w: int = ..., l: int = ..., c: int = ..., m: int = ...) -> None: ... + +class HTMLCalendar(Calendar): + def formatday(self, day: int, weekday: int) -> str: ... + def formatweek(self, theweek: int) -> str: ... + def formatweekday(self, day: int) -> str: ... + def formatweekheader(self) -> str: ... + def formatmonthname(self, theyear: int, themonth: int, withyear: bool = ...) -> str: ... + def formatmonth(self, theyear: int, themonth: int, withyear: bool = ...) -> str: ... + def formatyear(self, theyear: int, width: int = ...) -> str: ... + def formatyearpage(self, theyear: int, width: int = ..., css: Optional[str] = ..., encoding: Optional[str] = ...) -> str: ... + if sys.version_info >= (3, 7): + cssclasses: List[str] + cssclass_today: str + cssclasses_weekday_head: List[str] + cssclass_month_head: str + cssclass_month: str + cssclass_year: str + cssclass_year_head: str + +if sys.version_info < (3, 0): + class TimeEncoding: + def __init__(self, locale: _LocaleType) -> None: ... + def __enter__(self) -> _LocaleType: ... + def __exit__(self, *args: Any) -> None: ... +else: + class different_locale: + def __init__(self, locale: _LocaleType) -> None: ... + def __enter__(self) -> _LocaleType: ... + def __exit__(self, *args: Any) -> None: ... + +class LocaleTextCalendar(TextCalendar): + def __init__(self, firstweekday: int = ..., locale: Optional[_LocaleType] = ...) -> None: ... + def formatweekday(self, day: int, width: int) -> str: ... + def formatmonthname(self, theyear: int, themonth: int, width: int, withyear: bool = ...) -> str: ... + +class LocaleHTMLCalendar(HTMLCalendar): + def __init__(self, firstweekday: int = ..., locale: Optional[_LocaleType] = ...) -> None: ... + def formatweekday(self, day: int) -> str: ... + def formatmonthname(self, theyear: int, themonth: int, withyear: bool = ...) -> str: ... + +c = ... # type: TextCalendar +def setfirstweekday(firstweekday: int) -> None: ... +def format(cols: int, colwidth: int = ..., spacing: int = ...) -> str: ... +def formatstring(cols: int, colwidth: int = ..., spacing: int = ...) -> str: ... +def timegm(tuple: Union[Tuple[int, ...], struct_time]) -> int: ... + +# Data attributes +day_name = ... # type: Sequence[str] +day_abbr = ... # type: Sequence[str] +month_name = ... # type: Sequence[str] +month_abbr = ... # type: Sequence[str] + +# Below constants are not in docs or __all__, but enough people have used them +# they are now effectively public. + +MONDAY = ... # type: int +TUESDAY = ... # type: int +WEDNESDAY = ... # type: int +THURSDAY = ... # type: int +FRIDAY = ... # type: int +SATURDAY = ... # type: int +SUNDAY = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cgi.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cgi.pyi new file mode 100644 index 000000000..e8a9fd924 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cgi.pyi @@ -0,0 +1,119 @@ +import sys +from typing import Any, AnyStr, Dict, IO, Iterable, List, Mapping, Optional, Tuple, TypeVar, Union + +_T = TypeVar('_T', bound=FieldStorage) + +def parse(fp: IO[Any] = ..., environ: Mapping[str, str] = ..., + keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[str, List[str]]: ... +def parse_qs(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[str, List[str]]: ... +def parse_qsl(qs: str, keep_blank_values: bool = ..., strict_parsing: bool = ...) -> Dict[str, List[str]]: ... +def parse_multipart(fp: IO[Any], pdict: Mapping[str, bytes]) -> Dict[str, List[bytes]]: ... +def parse_header(s: str) -> Tuple[str, Dict[str, str]]: ... +def test(environ: Mapping[str, str] = ...) -> None: ... +def print_environ(environ: Mapping[str, str] = ...) -> None: ... +def print_form(form: Dict[str, Any]) -> None: ... +def print_directory() -> None: ... +def print_environ_usage() -> None: ... +if sys.version_info >= (3, 0): + def escape(s: str, quote: bool = ...) -> str: ... +else: + def escape(s: AnyStr, quote: bool = ...) -> AnyStr: ... + + +class MiniFieldStorage: + # The first five "Any" attributes here are always None, but mypy doesn't support that + filename = ... # type: Any + list = ... # type: Any + type = ... # type: Any + file = ... # type: Optional[IO[bytes]] # Always None + type_options = ... # type: Dict[Any, Any] + disposition = ... # type: Any + disposition_options = ... # type: Dict[Any, Any] + headers = ... # type: Dict[Any, Any] + name = ... # type: Any + value = ... # type: Any + + def __init__(self, name: Any, value: Any) -> None: ... + def __repr__(self) -> str: ... + + +class FieldStorage(object): + FieldStorageClass = ... # type: Optional[type] + keep_blank_values = ... # type: int + strict_parsing = ... # type: int + qs_on_post = ... # type: Optional[str] + headers = ... # type: Mapping[str, str] + fp = ... # type: IO[bytes] + encoding = ... # type: str + errors = ... # type: str + outerboundary = ... # type: bytes + bytes_read = ... # type: int + limit = ... # type: Optional[int] + disposition = ... # type: str + disposition_options = ... # type: Dict[str, str] + filename = ... # type: Optional[str] + file = ... # type: Optional[IO[bytes]] + type = ... # type: str + type_options = ... # type: Dict[str, str] + innerboundary = ... # type: bytes + length = ... # type: int + done = ... # type: int + list = ... # type: Optional[List[Any]] + value = ... # type: Union[None, bytes, List[Any]] + + if sys.version_info >= (3, 0): + def __init__(self, fp: IO[Any] = ..., headers: Mapping[str, str] = ..., outerboundary: bytes = ..., + environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ..., + limit: int = ..., encoding: str = ..., errors: str = ...) -> None: ... + else: + def __init__(self, fp: IO[Any] = ..., headers: Mapping[str, str] = ..., outerboundary: bytes = ..., + environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ...) -> None: ... + + if sys.version_info >= (3, 0): + def __enter__(self: _T) -> _T: ... + def __exit__(self, *args: Any) -> None: ... + def __repr__(self) -> str: ... + def __iter__(self) -> Iterable[str]: ... + def __getitem__(self, key: str) -> Any: ... + def getvalue(self, key: str, default: Any = ...) -> Any: ... + def getfirst(self, key: str, default: Any = ...) -> Any: ... + def getlist(self, key: str) -> List[Any]: ... + def keys(self) -> List[str]: ... + if sys.version_info < (3, 0): + def has_key(self, key: str) -> bool: ... + def __contains__(self, key: str) -> bool: ... + def __len__(self) -> int: ... + if sys.version_info >= (3, 0): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... + if sys.version_info >= (3, 0): + # In Python 3 it returns bytes or str IO depending on an internal flag + def make_file(self) -> IO[Any]: ... + else: + # In Python 2 it always returns bytes and ignores the "binary" flag + def make_file(self, binary: Any = ...) -> IO[bytes]: ... + + +if sys.version_info < (3, 0): + from UserDict import UserDict + + class FormContentDict(UserDict): + query_string = ... # type: str + def __init__(self, environ: Mapping[str, str] = ..., keep_blank_values: int = ..., strict_parsing: int = ...) -> None: ... + + class SvFormContentDict(FormContentDict): + def getlist(self, key: Any) -> Any: ... + + class InterpFormContentDict(SvFormContentDict): ... + + class FormContent(FormContentDict): + # TODO this should have + # def values(self, key: Any) -> Any: ... + # but this is incompatible with the supertype, and adding '# type: ignore' triggers + # a parse error in pytype (https://github.com/google/pytype/issues/53) + def indexed_value(self, key: Any, location: int) -> Any: ... + def value(self, key: Any) -> Any: ... + def length(self, key: Any) -> int: ... + def stripped(self, key: Any) -> Any: ... + def pars(self) -> Dict[Any, Any]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/chunk.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/chunk.pyi new file mode 100644 index 000000000..79255c22f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/chunk.pyi @@ -0,0 +1,23 @@ +# Source(py2): https://hg.python.org/cpython/file/2.7/Lib/chunk.py +# Source(py3): https://github.com/python/cpython/blob/master/Lib/chunk.py + +from typing import IO + +class Chunk: + closed = ... # type: bool + align = ... # type: bool + file = ... # type: IO[bytes] + chunkname = ... # type: bytes + chunksize = ... # type: int + size_read = ... # type: int + offset = ... # type: int + seekable = ... # type: bool + def __init__(self, file: IO[bytes], align: bool = ..., bigendian: bool = ..., inclheader: bool = ...) -> None: ... + def getname(self) -> bytes: ... + def getsize(self) -> int: ... + def close(self) -> None: ... + def isatty(self) -> bool: ... + def seek(self, pos: int, whence: int = ...) -> None: ... + def tell(self) -> int: ... + def read(self, size: int = ...) -> bytes: ... + def skip(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cmath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cmath.pyi new file mode 100644 index 000000000..ada931c23 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cmath.pyi @@ -0,0 +1,34 @@ +"""Stub file for the 'cmath' module.""" + +import sys +from typing import Union, Tuple + +e = ... # type: float +pi = ... # type: float + +_C = Union[float, complex] + +def acos(x: _C) -> complex: ... +def acosh(x: _C) -> complex: ... +def asin(x: _C) -> complex: ... +def asinh(x: _C) -> complex: ... +def atan(x: _C) -> complex: ... +def atanh(x: _C) -> complex: ... +def cos(x: _C) -> complex: ... +def cosh(x: _C) -> complex: ... +def exp(x: _C) -> complex: ... +def isinf(z: _C) -> bool: ... +def isnan(z: _C) -> bool: ... +def log(x: _C, base: _C = ...) -> complex: ... +def log10(x: _C) -> complex: ... +def phase(z: _C) -> float: ... +def polar(z: _C) -> Tuple[float, float]: ... +def rect(r: float, phi: float) -> complex: ... +def sin(x: _C) -> complex: ... +def sinh(x: _C) -> complex: ... +def sqrt(x: _C) -> complex: ... +def tan(x: _C) -> complex: ... +def tanh(x: _C) -> complex: ... + +if sys.version_info >= (3,): + def isfinite(z: _C) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cmd.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cmd.pyi new file mode 100644 index 000000000..dc305c95c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/cmd.pyi @@ -0,0 +1,41 @@ +# Stubs for cmd (Python 2/3) + +from typing import Any, Optional, Text, IO, List, Callable, Tuple + +class Cmd: + prompt = ... # type: str + identchars = ... # type: str + ruler = ... # type: str + lastcmd = ... # type: str + intro = ... # type: Optional[Any] + doc_leader = ... # type: str + doc_header = ... # type: str + misc_header = ... # type: str + undoc_header = ... # type: str + nohelp = ... # type: str + use_rawinput = ... # type: bool + stdin = ... # type: IO[str] + stdout = ... # type: IO[str] + cmdqueue = ... # type: List[str] + completekey = ... # type: str + def __init__(self, completekey: str = ..., stdin: Optional[IO[str]] = ..., stdout: Optional[IO[str]] = ...) -> None: ... + old_completer = ... # type: Optional[Callable[[str, int], Optional[str]]] + def cmdloop(self, intro: Optional[Any] = ...) -> None: ... + def precmd(self, line: str) -> str: ... + def postcmd(self, stop: bool, line: str) -> bool: ... + def preloop(self) -> None: ... + def postloop(self) -> None: ... + def parseline(self, line: str) -> Tuple[Optional[str], Optional[str], str]: ... + def onecmd(self, line: str) -> bool: ... + def emptyline(self) -> bool: ... + def default(self, line: str) -> bool: ... + def completedefault(self, *ignored: Any) -> List[str]: ... + def completenames(self, text: str, *ignored: Any) -> List[str]: ... + completion_matches = ... # type: Optional[List[str]] + def complete(self, text: str, state: int) -> Optional[List[str]]: ... + def get_names(self) -> List[str]: ... + # Only the first element of args matters. + def complete_help(self, *args: Any) -> List[str]: ... + def do_help(self, arg: Optional[str]) -> None: ... + def print_topics(self, header: str, cmds: Optional[List[str]], cmdlen: Any, maxcol: int) -> None: ... + def columnize(self, list: Optional[List[str]], displaywidth: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/code.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/code.pyi new file mode 100644 index 000000000..293ab9b98 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/code.pyi @@ -0,0 +1,38 @@ +# Stubs for code + +import sys +from typing import Any, Callable, Mapping, Optional +from types import CodeType + +class InteractiveInterpreter: + def __init__(self, locals: Optional[Mapping[str, Any]] = ...) -> None: ... + def runsource(self, source: str, filename: str = ..., + symbol: str = ...) -> bool: ... + def runcode(self, code: CodeType) -> None: ... + def showsyntaxerror(self, filename: Optional[str] = ...) -> None: ... + def showtraceback(self) -> None: ... + def write(self, data: str) -> None: ... + +class InteractiveConsole(InteractiveInterpreter): + def __init__(self, locals: Optional[Mapping[str, Any]] = ..., + filename: str = ...) -> None: ... + if sys.version_info >= (3, 6): + def interact(self, banner: Optional[str] = ..., + exitmsg: Optional[str] = ...) -> None: ... + else: + def interact(self, banner: Optional[str] = ...) -> None: ... + def push(self, line: str) -> bool: ... + def resetbuffer(self) -> None: ... + def raw_input(self, prompt: str = ...) -> str: ... + +if sys.version_info >= (3, 6): + def interact(banner: Optional[str] = ..., + readfunc: Optional[Callable[[str], str]] = ..., + local: Optional[Mapping[str, Any]] = ..., + exitmsg: Optional[str] = ...) -> None: ... +else: + def interact(banner: Optional[str] = ..., + readfunc: Optional[Callable[[str], str]] = ..., + local: Optional[Mapping[str, Any]] = ...) -> None: ... +def compile_command(source: str, filename: str = ..., + symbol: str = ...) -> Optional[CodeType]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/codecs.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/codecs.pyi new file mode 100644 index 000000000..8b6830adf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/codecs.pyi @@ -0,0 +1,220 @@ +import sys +from typing import Any, BinaryIO, Callable, Generator, IO, Iterable, List, Optional, Text, TextIO, Tuple, Type, TypeVar, Union + +from abc import abstractmethod +import types + +# TODO: this only satisfies the most common interface, where +# bytes (py2 str) is the raw form and str (py2 unicode) is the cooked form. +# In the long run, both should become template parameters maybe? +# There *are* bytes->bytes and str->str encodings in the standard library. +# They are much more common in Python 2 than in Python 3. + +_Decoded = Text +_Encoded = bytes + +# TODO: It is not possible to specify these signatures correctly, because +# they have an optional positional or keyword argument for errors=. +_Encoder = Callable[[_Decoded], Tuple[_Encoded, int]] # signature of Codec().encode +_Decoder = Callable[[_Encoded], Tuple[_Decoded, int]] # signature of Codec().decode +_StreamReader = Callable[[IO[_Encoded]], StreamReader] # signature of StreamReader __init__ +_StreamWriter = Callable[[IO[_Encoded]], StreamWriter] # signature of StreamWriter __init__ +_IncrementalEncoder = Callable[[], IncrementalEncoder] # signature of IncrementalEncoder __init__ +_IncrementalDecoder = Callable[[], IncrementalDecoder] # signature of IncrementalDecoder __init__ +def encode(obj: _Decoded, encoding: str = ..., errors: str = ...) -> _Encoded: ... +def decode(obj: _Encoded, encoding: str = ..., errors: str = ...) -> _Decoded: ... +def lookup(encoding: str) -> CodecInfo: ... + +class CodecInfo(Tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): + @property + def encode(self) -> _Encoder: ... + @property + def decode(self) -> _Decoder: ... + @property + def streamreader(self) -> _StreamReader: ... + @property + def streamwriter(self) -> _StreamWriter: ... + @property + def incrementalencoder(self) -> _IncrementalEncoder: ... + @property + def incrementaldecoder(self) -> _IncrementalDecoder: ... + name: str + def __init__( + self, + encode: _Encoder, + decode: _Decoder, + streamreader: _StreamReader = ..., + streamwriter: _StreamWriter = ..., + incrementalencoder: _IncrementalEncoder = ..., + incrementaldecoder: _IncrementalDecoder = ..., + name: str = ..., + ) -> None: ... + +def getencoder(encoding: str) -> _Encoder: ... +def getdecoder(encoding: str) -> _Decoder: ... +def getincrementalencoder(encoding: str) -> _IncrementalEncoder: ... +def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ... +def getreader(encoding: str) -> _StreamReader: ... +def getwriter(encoding: str) -> _StreamWriter: ... +def register(search_function: Callable[[str], CodecInfo]) -> None: ... +def open(filename: str, mode: str = ..., encoding: str = ..., errors: str = ..., buffering: int = ...) -> StreamReaderWriter: ... +def EncodedFile(file: IO[_Encoded], data_encoding: str, file_encoding: str = ..., errors: str = ...) -> StreamRecoder: ... +def iterencode(iterator: Iterable[_Decoded], encoding: str, errors: str = ...) -> Generator[_Encoded, None, None]: ... +def iterdecode(iterator: Iterable[_Encoded], encoding: str, errors: str = ...) -> Generator[_Decoded, None, None]: ... + +BOM: bytes +BOM_BE: bytes +BOM_LE: bytes +BOM_UTF8: bytes +BOM_UTF16: bytes +BOM_UTF16_BE: bytes +BOM_UTF16_LE: bytes +BOM_UTF32: bytes +BOM_UTF32_BE: bytes +BOM_UTF32_LE: bytes + +# It is expected that different actions be taken depending on which of the +# three subclasses of `UnicodeError` is actually ...ed. However, the Union +# is still needed for at least one of the cases. +def register_error(name: str, error_handler: Callable[[UnicodeError], Tuple[Union[str, bytes], int]]) -> None: ... +def lookup_error(name: str) -> Callable[[UnicodeError], Tuple[Union[str, bytes], int]]: ... +def strict_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ... +def replace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ... +def ignore_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ... +def xmlcharrefreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ... +def backslashreplace_errors(exception: UnicodeError) -> Tuple[Union[str, bytes], int]: ... + +class Codec: + # These are sort of @abstractmethod but sort of not. + # The StreamReader and StreamWriter subclasses only implement one. + def encode(self, input: _Decoded, errors: str = ...) -> Tuple[_Encoded, int]: ... + def decode(self, input: _Encoded, errors: str = ...) -> Tuple[_Decoded, int]: ... + +class IncrementalEncoder: + errors: str + def __init__(self, errors: str = ...) -> None: ... + @abstractmethod + def encode(self, object: _Decoded, final: bool = ...) -> _Encoded: ... + def reset(self) -> None: ... + # documentation says int but str is needed for the subclass. + def getstate(self) -> Union[int, _Decoded]: ... + def setstate(self, state: Union[int, _Decoded]) -> None: ... + +class IncrementalDecoder: + errors: str + def __init__(self, errors: str = ...) -> None: ... + @abstractmethod + def decode(self, object: _Encoded, final: bool = ...) -> _Decoded: ... + def reset(self) -> None: ... + def getstate(self) -> Tuple[_Encoded, int]: ... + def setstate(self, state: Tuple[_Encoded, int]) -> None: ... + +# These are not documented but used in encodings/*.py implementations. +class BufferedIncrementalEncoder(IncrementalEncoder): + buffer: str + def __init__(self, errors: str = ...) -> None: ... + @abstractmethod + def _buffer_encode(self, input: _Decoded, errors: str, final: bool) -> _Encoded: ... + def encode(self, input: _Decoded, final: bool = ...) -> _Encoded: ... + +class BufferedIncrementalDecoder(IncrementalDecoder): + buffer: bytes + def __init__(self, errors: str = ...) -> None: ... + @abstractmethod + def _buffer_decode(self, input: _Encoded, errors: str, final: bool) -> Tuple[_Decoded, int]: ... + def decode(self, object: _Encoded, final: bool = ...) -> _Decoded: ... + +# TODO: it is not possible to specify the requirement that all other +# attributes and methods are passed-through from the stream. +class StreamWriter(Codec): + errors: str + def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ... + def write(self, obj: _Decoded) -> None: ... + def writelines(self, list: Iterable[_Decoded]) -> None: ... + def reset(self) -> None: ... + +class StreamReader(Codec): + errors: str + def __init__(self, stream: IO[_Encoded], errors: str = ...) -> None: ... + def read(self, size: int = ..., chars: int = ..., firstline: bool = ...) -> _Decoded: ... + def readline(self, size: int = ..., keepends: bool = ...) -> _Decoded: ... + def readlines(self, sizehint: int = ..., keepends: bool = ...) -> List[_Decoded]: ... + def reset(self) -> None: ... + +_T = TypeVar("_T", bound=StreamReaderWriter) + +# Doesn't actually inherit from TextIO, but wraps a BinaryIO to provide text reading and writing +# and delegates attributes to the underlying binary stream with __getattr__. +class StreamReaderWriter(TextIO): + def __init__(self, stream: IO[_Encoded], Reader: _StreamReader, Writer: _StreamWriter, errors: str = ...) -> None: ... + def read(self, size: int = ...) -> _Decoded: ... + def readline(self, size: Optional[int] = ...) -> _Decoded: ... + def readlines(self, sizehint: Optional[int] = ...) -> List[_Decoded]: ... + if sys.version_info >= (3,): + def __next__(self) -> Text: ... + else: + def next(self) -> Text: ... + def __iter__(self: _T) -> _T: ... + # This actually returns None, but that's incompatible with the supertype + def write(self, data: _Decoded) -> int: ... + def writelines(self, list: Iterable[_Decoded]) -> None: ... + def reset(self) -> None: ... + # Same as write() + def seek(self, offset: int, whence: int = ...) -> int: ... + def __enter__(self: _T) -> _T: ... + def __exit__( + self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType] + ) -> bool: ... + def __getattr__(self, name: str) -> Any: ... + # These methods don't actually exist directly, but they are needed to satisfy the TextIO + # interface. At runtime, they are delegated through __getattr__. + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def readable(self) -> bool: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def writable(self) -> bool: ... + +_SRT = TypeVar("_SRT", bound=StreamRecoder) + +class StreamRecoder(BinaryIO): + def __init__( + self, + stream: IO[_Encoded], + encode: _Encoder, + decode: _Decoder, + Reader: _StreamReader, + Writer: _StreamWriter, + errors: str = ..., + ) -> None: ... + def read(self, size: int = ...) -> bytes: ... + def readline(self, size: Optional[int] = ...) -> bytes: ... + def readlines(self, sizehint: Optional[int] = ...) -> List[bytes]: ... + if sys.version_info >= (3,): + def __next__(self) -> bytes: ... + else: + def next(self) -> bytes: ... + def __iter__(self: _SRT) -> _SRT: ... + def write(self, data: bytes) -> int: ... + def writelines(self, list: Iterable[bytes]) -> int: ... # type: ignore # it's supposed to return None + def reset(self) -> None: ... + def __getattr__(self, name: str) -> Any: ... + def __enter__(self: _SRT) -> _SRT: ... + def __exit__( + self, type: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] + ) -> bool: ... + # These methods don't actually exist directly, but they are needed to satisfy the BinaryIO + # interface. At runtime, they are delegated through __getattr__. + def seek(self, offset: int, whence: int = ...) -> int: ... + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def readable(self) -> bool: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def writable(self) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/codeop.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/codeop.pyi new file mode 100644 index 000000000..826e40882 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/codeop.pyi @@ -0,0 +1,17 @@ +# Source(py2): https://hg.python.org/cpython/file/2.7/Lib/codeop.py +# Source(py3): https://github.com/python/cpython/blob/master/Lib/codeop.py + +from types import CodeType +from typing import Optional + +def compile_command(source: str, filename: str = ..., symbol: str = ...) -> Optional[CodeType]: ... + +class Compile: + flags = ... # type: int + def __init__(self) -> None: ... + def __call__(self, source: str, filename: str, symbol: str) -> CodeType: ... + +class CommandCompiler: + compiler = ... # type: Compile + def __init__(self) -> None: ... + def __call__(self, source: str, filename: str = ..., symbol: str = ...) -> Optional[CodeType]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/colorsys.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/colorsys.pyi new file mode 100644 index 000000000..ee17ba9a2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/colorsys.pyi @@ -0,0 +1,15 @@ +# Stubs for colorsys + +from typing import Tuple + +def rgb_to_yiq(r: float, g: float, b: float) -> Tuple[float, float, float]: ... +def yiq_to_rgb(y: float, i: float, q: float) -> Tuple[float, float, float]: ... +def rgb_to_hls(r: float, g: float, b: float) -> Tuple[float, float, float]: ... +def hls_to_rgb(h: float, l: float, s: float) -> Tuple[float, float, float]: ... +def rgb_to_hsv(r: float, g: float, b: float) -> Tuple[float, float, float]: ... +def hsv_to_rgb(h: float, s: float, v: float) -> Tuple[float, float, float]: ... + +# TODO undocumented +ONE_SIXTH = ... # type: float +ONE_THIRD = ... # type: float +TWO_THIRD = ... # type: float diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/contextlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/contextlib.pyi new file mode 100644 index 000000000..aaad35c24 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/contextlib.pyi @@ -0,0 +1,93 @@ +# Stubs for contextlib + +from typing import ( + Any, Callable, Generator, IO, Iterable, Iterator, Optional, Type, + Generic, TypeVar +) +from types import TracebackType +import sys +# Aliased here for backwards compatibility; TODO eventually remove this +from typing import ContextManager as ContextManager + +if sys.version_info >= (3, 5): + from typing import AsyncContextManager, AsyncIterator + +if sys.version_info >= (3, 6): + from typing import ContextManager as AbstractContextManager +if sys.version_info >= (3, 7): + from typing import AsyncContextManager as AbstractAsyncContextManager + +_T = TypeVar('_T') + +_ExitFunc = Callable[[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]], bool] +_CM_EF = TypeVar('_CM_EF', ContextManager, _ExitFunc) + +if sys.version_info >= (3, 2): + class GeneratorContextManager(ContextManager[_T], Generic[_T]): + def __call__(self, func: Callable[..., _T]) -> Callable[..., _T]: ... + def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., GeneratorContextManager[_T]]: ... +else: + def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ... + +if sys.version_info >= (3, 7): + def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ... + +if sys.version_info < (3,): + def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ... + +class closing(ContextManager[_T], Generic[_T]): + def __init__(self, thing: _T) -> None: ... + +if sys.version_info >= (3, 4): + class suppress(ContextManager[None]): + def __init__(self, *exceptions: Type[BaseException]) -> None: ... + + class redirect_stdout(ContextManager[None]): + def __init__(self, new_target: IO[str]) -> None: ... + +if sys.version_info >= (3, 5): + class redirect_stderr(ContextManager[None]): + def __init__(self, new_target: IO[str]) -> None: ... + +if sys.version_info >= (3,): + class ContextDecorator: + def __call__(self, func: Callable[..., None]) -> Callable[..., ContextManager[None]]: ... + + _U = TypeVar('_U', bound='ExitStack') + + class ExitStack(ContextManager[ExitStack]): + def __init__(self) -> None: ... + def enter_context(self, cm: ContextManager[_T]) -> _T: ... + def push(self, exit: _CM_EF) -> _CM_EF: ... + def callback(self, callback: Callable[..., Any], + *args: Any, **kwds: Any) -> Callable[..., Any]: ... + def pop_all(self: _U) -> _U: ... + def close(self) -> None: ... + def __enter__(self: _U) -> _U: ... + +if sys.version_info >= (3, 7): + from typing import Awaitable + + _S = TypeVar('_S', bound='AsyncExitStack') + + _ExitCoroFunc = Callable[[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]], Awaitable[bool]] + _CallbackCoroFunc = Callable[..., Awaitable[Any]] + _ACM_EF = TypeVar('_ACM_EF', AsyncContextManager, _ExitCoroFunc) + + class AsyncExitStack(AsyncContextManager[AsyncExitStack]): + def __init__(self) -> None: ... + def enter_context(self, cm: ContextManager[_T]) -> _T: ... + def enter_async_context(self, cm: AsyncContextManager[_T]) -> Awaitable[_T]: ... + def push(self, exit: _CM_EF) -> _CM_EF: ... + def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ... + def callback(self, callback: Callable[..., Any], + *args: Any, **kwds: Any) -> Callable[..., Any]: ... + def push_async_callback(self, callback: _CallbackCoroFunc, + *args: Any, **kwds: Any) -> _CallbackCoroFunc: ... + def pop_all(self: _S) -> _S: ... + def aclose(self) -> Awaitable[None]: ... + def __aenter__(self: _S) -> Awaitable[_S]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/copy.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/copy.pyi new file mode 100644 index 000000000..523802a84 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/copy.pyi @@ -0,0 +1,14 @@ +# Stubs for copy + +from typing import TypeVar, Optional, Dict, Any + +_T = TypeVar('_T') + +# None in CPython but non-None in Jython +PyStringMap: Any + +# Note: memo and _nil are internal kwargs. +def deepcopy(x: _T, memo: Optional[Dict[int, _T]] = ..., _nil: Any = ...) -> _T: ... +def copy(x: _T) -> _T: ... +class Error(Exception): ... +error = Error diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/crypt.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/crypt.pyi new file mode 100644 index 000000000..d55fc263e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/crypt.pyi @@ -0,0 +1,23 @@ +import sys +from typing import List, NamedTuple, Optional, Union + + +if sys.version_info >= (3, 3): + class _Method: ... + + METHOD_CRYPT: _Method + METHOD_MD5: _Method + METHOD_SHA256: _Method + METHOD_SHA512: _Method + if sys.version_info >= (3, 7): + METHOD_BLOWFISH: _Method + + methods: List[_Method] + + if sys.version_info >= (3, 7): + def mksalt(method: Optional[_Method] = ..., *, rounds: Optional[int] = ...) -> str: ... + else: + def mksalt(method: Optional[_Method] = ...) -> str: ... + def crypt(word: str, salt: Optional[Union[str, _Method]] = ...) -> str: ... +else: + def crypt(word: str, salt: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/csv.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/csv.pyi new file mode 100644 index 000000000..8f6b57ddd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/csv.pyi @@ -0,0 +1,93 @@ +from collections import OrderedDict +import sys +from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Union + +from _csv import (_reader, + _writer, + reader as reader, + writer as writer, + register_dialect as register_dialect, + unregister_dialect as unregister_dialect, + get_dialect as get_dialect, + list_dialects as list_dialects, + field_size_limit as field_size_limit, + QUOTE_ALL as QUOTE_ALL, + QUOTE_MINIMAL as QUOTE_MINIMAL, + QUOTE_NONE as QUOTE_NONE, + QUOTE_NONNUMERIC as QUOTE_NONNUMERIC, + Error as Error, + ) + +_Dialect = Union[str, Dialect] +_DictRow = Dict[str, Any] + +class Dialect(object): + delimiter = ... # type: str + quotechar = ... # type: Optional[str] + escapechar = ... # type: Optional[str] + doublequote = ... # type: bool + skipinitialspace = ... # type: bool + lineterminator = ... # type: str + quoting = ... # type: int + def __init__(self) -> None: ... + +class excel(Dialect): + delimiter = ... # type: str + quotechar = ... # type: str + doublequote = ... # type: bool + skipinitialspace = ... # type: bool + lineterminator = ... # type: str + quoting = ... # type: int + +class excel_tab(excel): + delimiter = ... # type: str + +if sys.version_info >= (3,): + class unix_dialect(Dialect): + delimiter = ... # type: str + quotechar = ... # type: str + doublequote = ... # type: bool + skipinitialspace = ... # type: bool + lineterminator = ... # type: str + quoting = ... # type: int + +if sys.version_info >= (3, 6): + _DRMapping = OrderedDict[str, str] +else: + _DRMapping = Dict[str, str] + + +class DictReader(Iterator[_DRMapping]): + restkey = ... # type: Optional[str] + restval = ... # type: Optional[str] + reader = ... # type: _reader + dialect = ... # type: _Dialect + line_num = ... # type: int + fieldnames = ... # type: Sequence[str] + def __init__(self, f: Iterable[str], fieldnames: Sequence[str] = ..., + restkey: Optional[str] = ..., restval: Optional[str] = ..., dialect: _Dialect = ..., + *args: Any, **kwds: Any) -> None: ... + def __iter__(self) -> 'DictReader': ... + if sys.version_info >= (3,): + def __next__(self) -> _DRMapping: ... + else: + def next(self) -> _DRMapping: ... + + +class DictWriter(object): + fieldnames = ... # type: Sequence[str] + restval = ... # type: Optional[Any] + extrasaction = ... # type: str + writer = ... # type: _writer + def __init__(self, f: Any, fieldnames: Sequence[str], + restval: Optional[Any] = ..., extrasaction: str = ..., dialect: _Dialect = ..., + *args: Any, **kwds: Any) -> None: ... + def writeheader(self) -> None: ... + def writerow(self, rowdict: _DictRow) -> None: ... + def writerows(self, rowdicts: Iterable[_DictRow]) -> None: ... + +class Sniffer(object): + preferred = ... # type: List[str] + def __init__(self) -> None: ... + def sniff(self, sample: str, delimiters: Optional[str] = ...) -> Dialect: ... + def has_header(self, sample: str) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/__init__.pyi new file mode 100644 index 000000000..8bd538af6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/__init__.pyi @@ -0,0 +1,277 @@ +# Stubs for ctypes + +from typing import ( + Any, Callable, ClassVar, Iterator, Iterable, List, Mapping, Optional, Sequence, Sized, Text, + Tuple, Type, Generic, TypeVar, overload, +) +from typing import Union as _UnionT +import sys + +_T = TypeVar('_T') +_DLLT = TypeVar('_DLLT', bound=CDLL) +_CT = TypeVar('_CT', bound=_CData) + + +RTLD_GLOBAL: int = ... +RTLD_LOCAL: int = ... +DEFAULT_MODE: int = ... + + +class CDLL(object): + _func_flags_: ClassVar[int] = ... + _func_restype_: ClassVar[_CData] = ... + _name: str = ... + _handle: int = ... + _FuncPtr: Type[_FuncPointer] = ... + def __init__(self, name: str, mode: int = ..., handle: Optional[int] = ..., + use_errno: bool = ..., use_last_error: bool = ...) -> None: ... + def __getattr__(self, name: str) -> _FuncPointer: ... + def __getitem__(self, name: str) -> _FuncPointer: ... +if sys.platform == 'win32': + class OleDLL(CDLL): ... + class WinDLL(CDLL): ... +class PyDLL(CDLL): ... + +class LibraryLoader(Generic[_DLLT]): + def __init__(self, dlltype: Type[_DLLT]) -> None: ... + def __getattr__(self, name: str) -> _DLLT: ... + def __getitem__(self, name: str) -> _DLLT: ... + def LoadLibrary(self, name: str) -> _DLLT: ... + +cdll: LibraryLoader[CDLL] = ... +if sys.platform == 'win32': + windll: LibraryLoader[WinDLL] = ... + oledll: LibraryLoader[OleDLL] = ... +pydll: LibraryLoader[PyDLL] = ... +pythonapi: PyDLL = ... + +class _CDataMeta(type): + # By default mypy complains about the following two methods, because strictly speaking cls + # might not be a Type[_CT]. However this can never actually happen, because the only class that + # uses _CDataMeta as its metaclass is _CData. So it's safe to ignore the errors here. + def __mul__(cls: Type[_CT], other: int) -> Type[Array[_CT]]: ... # type: ignore + def __rmul__(cls: Type[_CT], other: int) -> Type[Array[_CT]]: ... # type: ignore +class _CData(metaclass=_CDataMeta): + _b_base: int = ... + _b_needsfree_: bool = ... + _objects: Optional[Mapping[Any, int]] = ... + @classmethod + def from_buffer(cls: Type[_CT], source: bytearray, offset: int = ...) -> _CT: ... + @classmethod + def from_buffer_copy(cls: Type[_CT], source: bytearray, offset: int = ...) -> _CT: ... + @classmethod + def from_address(cls: Type[_CT], address: int) -> _CT: ... + @classmethod + def from_param(cls: Type[_CT], obj: Any) -> _UnionT[_CT, _CArgObject]: ... + @classmethod + def in_dll(cls: Type[_CT], library: CDLL, name: str) -> _CT: ... + +class _PointerLike(_CData): ... + +_ECT = Callable[[Optional[Type[_CData]], + _FuncPointer, + Tuple[_CData, ...]], + _CData] +_PF = _UnionT[ + Tuple[int], + Tuple[int, str], + Tuple[int, str, Any] +] +class _FuncPointer(_PointerLike, _CData): + restype: _UnionT[Type[_CData], Callable[[int], None], None] = ... + argtypes: Sequence[Type[_CData]] = ... + errcheck: _ECT = ... + @overload + def __init__(self, address: int) -> None: ... + @overload + def __init__(self, callable: Callable[..., Any]) -> None: ... + @overload + def __init__(self, func_spec: Tuple[_UnionT[str, int], CDLL], + paramflags: Tuple[_PF, ...] = ...) -> None: ... + @overload + def __init__(self, vtlb_index: int, name: str, + paramflags: Tuple[_PF, ...] = ..., + iid: pointer[c_int] = ...) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + +class ArgumentError(Exception): ... + + +def CFUNCTYPE(restype: Optional[Type[_CData]], + *argtypes: Type[_CData], + use_errno: bool = ..., + use_last_error: bool = ...) -> Type[_FuncPointer]: ... +if sys.platform == 'win32': + def WINFUNCTYPE(restype: Optional[Type[_CData]], + *argtypes: Type[_CData], + use_errno: bool = ..., + use_last_error: bool = ...) -> Type[_FuncPointer]: ... +def PYFUNCTYPE(restype: Optional[Type[_CData]], + *argtypes: Type[_CData]) -> Type[_FuncPointer]: ... + +class _CArgObject: ... + +# Any type that can be implicitly converted to c_void_p when passed as a C function argument. +# (bytes is not included here, see below.) +_CVoidPLike = _UnionT[_PointerLike, Array[Any], _CArgObject, int] +# Same as above, but including types known to be read-only (i. e. bytes). +# This distinction is not strictly necessary (ctypes doesn't differentiate between const +# and non-const pointers), but it catches errors like memmove(b'foo', buf, 4) +# when memmove(buf, b'foo', 4) was intended. +_CVoidConstPLike = _UnionT[_CVoidPLike, bytes] + +def addressof(obj: _CData) -> int: ... +def alignment(obj_or_type: _UnionT[_CData, Type[_CData]]) -> int: ... +def byref(obj: _CData, offset: int = ...) -> _CArgObject: ... +_PT = TypeVar('_PT', bound=_PointerLike) +def cast(obj: _UnionT[_CData, _CArgObject], type: Type[_PT]) -> _PT: ... +def create_string_buffer(init_or_size: _UnionT[int, bytes], + size: Optional[int] = ...) -> Array[c_char]: ... +c_buffer = create_string_buffer +def create_unicode_buffer(init_or_size: _UnionT[int, Text], + size: Optional[int] = ...) -> Array[c_wchar]: ... +if sys.platform == 'win32': + def DllCanUnloadNow() -> int: ... + def DllGetClassObject(rclsid: Any, riid: Any, ppv: Any) -> int: ... # TODO not documented + def FormatError(code: int) -> str: ... + def GetLastError() -> int: ... +def get_errno() -> int: ... +if sys.platform == 'win32': + def get_last_error() -> int: ... +def memmove(dst: _CVoidPLike, src: _CVoidConstPLike, count: int) -> None: ... +def memset(dst: _CVoidPLike, c: int, count: int) -> None: ... +def POINTER(type: Type[_CT]) -> Type[pointer[_CT]]: ... + +# The real ctypes.pointer is a function, not a class. The stub version of pointer behaves like +# ctypes._Pointer in that it is the base class for all pointer types. Unlike the real _Pointer, +# it can be instantiated directly (to mimic the behavior of the real pointer function). +class pointer(Generic[_CT], _PointerLike, _CData): + _type_: ClassVar[Type[_CT]] = ... + contents: _CT = ... + def __init__(self, arg: _CT = ...) -> None: ... + @overload + def __getitem__(self, i: int) -> _CT: ... + @overload + def __getitem__(self, s: slice) -> List[_CT]: ... + @overload + def __setitem__(self, i: int, o: _CT) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[_CT]) -> None: ... + +def resize(obj: _CData, size: int) -> None: ... +if sys.version_info < (3,): + def set_conversion_mode(encoding: str, errors: str) -> Tuple[str, str]: ... +def set_errno(value: int) -> int: ... +if sys.platform == 'win32': + def set_last_error(value: int) -> int: ... +def sizeof(obj_or_type: _UnionT[_CData, Type[_CData]]) -> int: ... +def string_at(address: _CVoidConstPLike, size: int = ...) -> bytes: ... +if sys.platform == 'win32': + def WinError(code: Optional[int] = ..., + desc: Optional[str] = ...) -> WindowsError: ... +def wstring_at(address: _CVoidConstPLike, size: int = ...) -> str: ... + +class _SimpleCData(Generic[_T], _CData): + value: _T = ... + def __init__(self, value: _T = ...) -> None: ... + +class c_byte(_SimpleCData[int]): ... + +class c_char(_SimpleCData[bytes]): + def __init__(self, value: _UnionT[int, bytes] = ...) -> None: ... +class c_char_p(_PointerLike, _SimpleCData[Optional[bytes]]): + def __init__(self, value: Optional[_UnionT[int, bytes]] = ...) -> None: ... + +class c_double(_SimpleCData[float]): ... +class c_longdouble(_SimpleCData[float]): ... +class c_float(_SimpleCData[float]): ... + +class c_int(_SimpleCData[int]): ... +class c_int8(_SimpleCData[int]): ... +class c_int16(_SimpleCData[int]): ... +class c_int32(_SimpleCData[int]): ... +class c_int64(_SimpleCData[int]): ... + +class c_long(_SimpleCData[int]): ... +class c_longlong(_SimpleCData[int]): ... + +class c_short(_SimpleCData[int]): ... + +class c_size_t(_SimpleCData[int]): ... +class c_ssize_t(_SimpleCData[int]): ... + +class c_ubyte(_SimpleCData[int]): ... + +class c_uint(_SimpleCData[int]): ... +class c_uint8(_SimpleCData[int]): ... +class c_uint16(_SimpleCData[int]): ... +class c_uint32(_SimpleCData[int]): ... +class c_uint64(_SimpleCData[int]): ... + +class c_ulong(_SimpleCData[int]): ... +class c_ulonglong(_SimpleCData[int]): ... + +class c_ushort(_SimpleCData[int]): ... + +class c_void_p(_PointerLike, _SimpleCData[Optional[int]]): ... + +class c_wchar(_SimpleCData[Text]): ... +class c_wchar_p(_PointerLike, _SimpleCData[Optional[Text]]): + def __init__(self, value: Optional[_UnionT[int, Text]] = ...) -> None: ... + +class c_bool(_SimpleCData[bool]): + def __init__(self, value: bool) -> None: ... + +if sys.platform == 'win32': + class HRESULT(_SimpleCData[int]): ... # TODO undocumented + +class py_object(_SimpleCData[_T]): ... + +class _CField: + offset: int = ... + size: int = ... +class _StructUnionMeta(_CDataMeta): + _fields_: Sequence[_UnionT[Tuple[str, Type[_CData]], Tuple[str, Type[_CData], int]]] = ... + _pack_: int = ... + _anonymous_: Sequence[str] = ... + def __getattr__(self, name: str) -> _CField: ... +class _StructUnionBase(_CData, metaclass=_StructUnionMeta): + def __init__(self, *args: Any, **kw: Any) -> None: ... + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + +class Union(_StructUnionBase): ... +class Structure(_StructUnionBase): ... +class BigEndianStructure(Structure): ... +class LittleEndianStructure(Structure): ... + +class Array(Generic[_T], _CData): + _length_: ClassVar[int] = ... + _type_: ClassVar[Type[_T]] = ... + raw: bytes = ... # TODO only available with _T == c_char + value: bytes = ... # TODO only available with _T == c_char + # TODO These methods cannot be annotated correctly at the moment. + # All of these "Any"s stand for the array's element type, but it's not possible to use _T here, + # because of a special feature of ctypes. + # By default, when accessing an element of an Array[_T], the returned object has type _T. + # However, when _T is a "simple type" like c_int, ctypes automatically "unboxes" the object + # and converts it to the corresponding Python primitive. For example, when accessing an element + # of an Array[c_int], a Python int object is returned, not a c_int. + # This behavior does *not* apply to subclasses of "simple types". + # If MyInt is a subclass of c_int, then accessing an element of an Array[MyInt] returns + # a MyInt, not an int. + # This special behavior is not easy to model in a stub, so for now all places where + # the array element type would belong are annotated with Any instead. + def __init__(self, *args: Any) -> None: ... + @overload + def __getitem__(self, i: int) -> Any: ... + @overload + def __getitem__(self, s: slice) -> List[Any]: ... + @overload + def __setitem__(self, i: int, o: Any) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[Any]) -> None: ... + def __iter__(self) -> Iterator[Any]: ... + # Can't inherit from Sized because the metaclass conflict between + # Sized and _CData prevents using _CDataMeta. + def __len__(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/util.pyi new file mode 100644 index 000000000..7077d9d2f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/util.pyi @@ -0,0 +1,8 @@ +# Stubs for ctypes.util + +from typing import Optional +import sys + +def find_library(name: str) -> Optional[str]: ... +if sys.platform == 'win32': + def find_msvcrt() -> Optional[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/wintypes.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/wintypes.pyi new file mode 100644 index 000000000..c5a6226b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ctypes/wintypes.pyi @@ -0,0 +1,209 @@ +from ctypes import ( + _SimpleCData, Array, Structure, c_byte, c_char, c_char_p, c_double, c_float, c_int, c_long, + c_longlong, c_short, c_uint, c_ulong, c_ulonglong, c_ushort, c_void_p, c_wchar, c_wchar_p, + pointer, +) + +BYTE = c_byte +WORD = c_ushort +DWORD = c_ulong +CHAR = c_char +WCHAR = c_wchar +UINT = c_uint +INT = c_int +DOUBLE = c_double +FLOAT = c_float +BOOLEAN = BYTE +BOOL = c_long +class VARIANT_BOOL(_SimpleCData[bool]): ... +ULONG = c_ulong +LONG = c_long +USHORT = c_ushort +SHORT = c_short +LARGE_INTEGER = c_longlong +_LARGE_INTEGER = c_longlong +ULARGE_INTEGER = c_ulonglong +_ULARGE_INTEGER = c_ulonglong + +OLESTR = c_wchar_p +LPOLESTR = c_wchar_p +LPCOLESTR = c_wchar_p +LPWSTR = c_wchar_p +LPCWSTR = c_wchar_p +LPSTR = c_char_p +LPCSTR = c_char_p +LPVOID = c_void_p +LPCVOID = c_void_p + +# These two types are pointer-sized unsigned and signed ints, respectively. +# At runtime, they are either c_[u]long or c_[u]longlong, depending on the host's pointer size +# (they are not really separate classes). +class WPARAM(_SimpleCData[int]): ... +class LPARAM(_SimpleCData[int]): ... + +ATOM = WORD +LANGID = WORD +COLORREF = DWORD +LGRPID = DWORD +LCTYPE = DWORD +LCID = DWORD + +HANDLE = c_void_p +HACCEL = HANDLE +HBITMAP = HANDLE +HBRUSH = HANDLE +HCOLORSPACE = HANDLE +HDC = HANDLE +HDESK = HANDLE +HDWP = HANDLE +HENHMETAFILE = HANDLE +HFONT = HANDLE +HGDIOBJ = HANDLE +HGLOBAL = HANDLE +HHOOK = HANDLE +HICON = HANDLE +HINSTANCE = HANDLE +HKEY = HANDLE +HKL = HANDLE +HLOCAL = HANDLE +HMENU = HANDLE +HMETAFILE = HANDLE +HMODULE = HANDLE +HMONITOR = HANDLE +HPALETTE = HANDLE +HPEN = HANDLE +HRGN = HANDLE +HRSRC = HANDLE +HSTR = HANDLE +HTASK = HANDLE +HWINSTA = HANDLE +HWND = HANDLE +SC_HANDLE = HANDLE +SERVICE_STATUS_HANDLE = HANDLE + +class RECT(Structure): + left: LONG + top: LONG + right: LONG + bottom: LONG +RECTL = RECT +_RECTL = RECT +tagRECT = RECT + +class _SMALL_RECT(Structure): + Left: SHORT + Top: SHORT + Right: SHORT + Bottom: SHORT +SMALL_RECT = _SMALL_RECT + +class _COORD(Structure): + X: SHORT + Y: SHORT + +class POINT(Structure): + x: LONG + y: LONG +POINTL = POINT +_POINTL = POINT +tagPOINT = POINT + +class SIZE(Structure): + cx: LONG + cy: LONG +SIZEL = SIZE +tagSIZE = SIZE + +def RGB(red: int, green: int, blue: int) -> int: ... + +class FILETIME(Structure): + dwLowDateTime: DWORD + dwHighDateTime: DWORD +_FILETIME = FILETIME + +class MSG(Structure): + hWnd: HWND + message: UINT + wParam: WPARAM + lParam: LPARAM + time: DWORD + pt: POINT +tagMSG = MSG +MAX_PATH: int + +class WIN32_FIND_DATAA(Structure): + dwFileAttributes: DWORD + ftCreationTime: FILETIME + ftLastAccessTime: FILETIME + ftLastWriteTime: FILETIME + nFileSizeHigh: DWORD + nFileSizeLow: DWORD + dwReserved0: DWORD + dwReserved1: DWORD + cFileName: Array[CHAR] + cAlternateFileName: Array[CHAR] + +class WIN32_FIND_DATAW(Structure): + dwFileAttributes: DWORD + ftCreationTime: FILETIME + ftLastAccessTime: FILETIME + ftLastWriteTime: FILETIME + nFileSizeHigh: DWORD + nFileSizeLow: DWORD + dwReserved0: DWORD + dwReserved1: DWORD + cFileName: Array[WCHAR] + cAlternateFileName: Array[WCHAR] + +# These pointer type definitions use pointer[...] instead of POINTER(...), to allow them +# to be used in type annotations. +PBOOL = pointer[BOOL] +LPBOOL = pointer[BOOL] +PBOOLEAN = pointer[BOOLEAN] +PBYTE = pointer[BYTE] +LPBYTE = pointer[BYTE] +PCHAR = pointer[CHAR] +LPCOLORREF = pointer[COLORREF] +PDWORD = pointer[DWORD] +LPDWORD = pointer[DWORD] +PFILETIME = pointer[FILETIME] +LPFILETIME = pointer[FILETIME] +PFLOAT = pointer[FLOAT] +PHANDLE = pointer[HANDLE] +LPHANDLE = pointer[HANDLE] +PHKEY = pointer[HKEY] +LPHKL = pointer[HKL] +PINT = pointer[INT] +LPINT = pointer[INT] +PLARGE_INTEGER = pointer[LARGE_INTEGER] +PLCID = pointer[LCID] +PLONG = pointer[LONG] +LPLONG = pointer[LONG] +PMSG = pointer[MSG] +LPMSG = pointer[MSG] +PPOINT = pointer[POINT] +LPPOINT = pointer[POINT] +PPOINTL = pointer[POINTL] +PRECT = pointer[RECT] +LPRECT = pointer[RECT] +PRECTL = pointer[RECTL] +LPRECTL = pointer[RECTL] +LPSC_HANDLE = pointer[SC_HANDLE] +PSHORT = pointer[SHORT] +PSIZE = pointer[SIZE] +LPSIZE = pointer[SIZE] +PSIZEL = pointer[SIZEL] +LPSIZEL = pointer[SIZEL] +PSMALL_RECT = pointer[SMALL_RECT] +PUINT = pointer[UINT] +LPUINT = pointer[UINT] +PULARGE_INTEGER = pointer[ULARGE_INTEGER] +PULONG = pointer[ULONG] +PUSHORT = pointer[USHORT] +PWCHAR = pointer[WCHAR] +PWIN32_FIND_DATAA = pointer[WIN32_FIND_DATAA] +LPWIN32_FIND_DATAA = pointer[WIN32_FIND_DATAA] +PWIN32_FIND_DATAW = pointer[WIN32_FIND_DATAW] +LPWIN32_FIND_DATAW = pointer[WIN32_FIND_DATAW] +PWORD = pointer[WORD] +LPWORD = pointer[WORD] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/datetime.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/datetime.pyi new file mode 100644 index 000000000..25f128f97 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/datetime.pyi @@ -0,0 +1,276 @@ +import sys +from time import struct_time +from typing import ( + AnyStr, Optional, SupportsAbs, Tuple, Union, overload, + ClassVar, +) + +if sys.version_info >= (3,): + _Text = str +else: + _Text = Union[str, unicode] + +MINYEAR: int +MAXYEAR: int + +class tzinfo: + def tzname(self, dt: Optional[datetime]) -> Optional[str]: ... + def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def fromutc(self, dt: datetime) -> datetime: ... + +if sys.version_info >= (3, 2): + class timezone(tzinfo): + utc: ClassVar[timezone] + min: ClassVar[timezone] + max: ClassVar[timezone] + + def __init__(self, offset: timedelta, name: str = ...) -> None: ... + def __hash__(self) -> int: ... + +_tzinfo = tzinfo + +class date: + min: ClassVar[date] + max: ClassVar[date] + resolution: ClassVar[timedelta] + + def __init__(self, year: int, month: int, day: int) -> None: ... + + @classmethod + def fromtimestamp(cls, t: float) -> date: ... + @classmethod + def today(cls) -> date: ... + @classmethod + def fromordinal(cls, n: int) -> date: ... + + @property + def year(self) -> int: ... + @property + def month(self) -> int: ... + @property + def day(self) -> int: ... + + def ctime(self) -> str: ... + def strftime(self, fmt: _Text) -> str: ... + if sys.version_info >= (3,): + def __format__(self, fmt: str) -> str: ... + else: + def __format__(self, fmt: AnyStr) -> AnyStr: ... + def isoformat(self) -> str: ... + def timetuple(self) -> struct_time: ... + def toordinal(self) -> int: ... + def replace(self, year: int = ..., month: int = ..., day: int = ...) -> date: ... + def __le__(self, other: date) -> bool: ... + def __lt__(self, other: date) -> bool: ... + def __ge__(self, other: date) -> bool: ... + def __gt__(self, other: date) -> bool: ... + def __add__(self, other: timedelta) -> date: ... + @overload + def __sub__(self, other: timedelta) -> date: ... + @overload + def __sub__(self, other: date) -> timedelta: ... + def __hash__(self) -> int: ... + def weekday(self) -> int: ... + def isoweekday(self) -> int: ... + def isocalendar(self) -> Tuple[int, int, int]: ... + +class time: + min: ClassVar[time] + max: ClassVar[time] + resolution: ClassVar[timedelta] + + def __init__(self, hour: int = ..., minute: int = ..., second: int = ..., microsecond: int = ..., + tzinfo: Optional[tzinfo] = ...) -> None: ... + + @property + def hour(self) -> int: ... + @property + def minute(self) -> int: ... + @property + def second(self) -> int: ... + @property + def microsecond(self) -> int: ... + @property + def tzinfo(self) -> Optional[_tzinfo]: ... + if sys.version_info >= (3, 6): + @property + def fold(self) -> int: ... + + def __le__(self, other: time) -> bool: ... + def __lt__(self, other: time) -> bool: ... + def __ge__(self, other: time) -> bool: ... + def __gt__(self, other: time) -> bool: ... + def __hash__(self) -> int: ... + def isoformat(self) -> str: ... + def strftime(self, fmt: _Text) -> str: ... + if sys.version_info >= (3,): + def __format__(self, fmt: str) -> str: ... + else: + def __format__(self, fmt: AnyStr) -> AnyStr: ... + def utcoffset(self) -> Optional[timedelta]: ... + def tzname(self) -> Optional[str]: ... + def dst(self) -> Optional[int]: ... + if sys.version_info >= (3, 6): + def replace(self, hour: int = ..., minute: int = ..., second: int = ..., + microsecond: int = ..., tzinfo: Optional[_tzinfo] = ..., + *, fold: int = ...) -> time: ... + else: + def replace(self, hour: int = ..., minute: int = ..., second: int = ..., + microsecond: int = ..., tzinfo: Optional[_tzinfo] = ...) -> time: ... + +_date = date +_time = time + +class timedelta(SupportsAbs[timedelta]): + min: ClassVar[timedelta] + max: ClassVar[timedelta] + resolution: ClassVar[timedelta] + + def __init__(self, days: float = ..., seconds: float = ..., microseconds: float = ..., + milliseconds: float = ..., minutes: float = ..., hours: float = ..., + weeks: float = ...) -> None: ... + + @property + def days(self) -> int: ... + @property + def seconds(self) -> int: ... + @property + def microseconds(self) -> int: ... + + def total_seconds(self) -> float: ... + def __add__(self, other: timedelta) -> timedelta: ... + def __radd__(self, other: timedelta) -> timedelta: ... + def __sub__(self, other: timedelta) -> timedelta: ... + def __rsub__(self, other: timedelta) -> timedelta: ... + def __neg__(self) -> timedelta: ... + def __pos__(self) -> timedelta: ... + def __abs__(self) -> timedelta: ... + def __mul__(self, other: float) -> timedelta: ... + def __rmul__(self, other: float) -> timedelta: ... + @overload + def __floordiv__(self, other: timedelta) -> int: ... + @overload + def __floordiv__(self, other: int) -> timedelta: ... + if sys.version_info >= (3,): + @overload + def __truediv__(self, other: timedelta) -> float: ... + @overload + def __truediv__(self, other: float) -> timedelta: ... + def __mod__(self, other: timedelta) -> timedelta: ... + def __divmod__(self, other: timedelta) -> Tuple[int, timedelta]: ... + else: + @overload + def __div__(self, other: timedelta) -> float: ... + @overload + def __div__(self, other: float) -> timedelta: ... + def __le__(self, other: timedelta) -> bool: ... + def __lt__(self, other: timedelta) -> bool: ... + def __ge__(self, other: timedelta) -> bool: ... + def __gt__(self, other: timedelta) -> bool: ... + def __hash__(self) -> int: ... + +class datetime: + # TODO: Is a subclass of date, but this would make some types incompatible. + min: ClassVar[datetime] + max: ClassVar[datetime] + resolution: ClassVar[timedelta] + + if sys.version_info >= (3, 6): + def __init__(self, year: int, month: int, day: int, hour: int = ..., + minute: int = ..., second: int = ..., microsecond: int = ..., + tzinfo: Optional[tzinfo] = ..., *, fold: int = ...) -> None: ... + else: + def __init__(self, year: int, month: int, day: int, hour: int = ..., + minute: int = ..., second: int = ..., microsecond: int = ..., + tzinfo: Optional[tzinfo] = ...) -> None: ... + + @property + def year(self) -> int: ... + @property + def month(self) -> int: ... + @property + def day(self) -> int: ... + @property + def hour(self) -> int: ... + @property + def minute(self) -> int: ... + @property + def second(self) -> int: ... + @property + def microsecond(self) -> int: ... + @property + def tzinfo(self) -> Optional[_tzinfo]: ... + if sys.version_info >= (3, 6): + @property + def fold(self) -> int: ... + + @classmethod + def fromtimestamp(cls, t: float, tz: Optional[_tzinfo] = ...) -> datetime: ... + @classmethod + def utcfromtimestamp(cls, t: float) -> datetime: ... + @classmethod + def today(cls) -> datetime: ... + @classmethod + def fromordinal(cls, n: int) -> datetime: ... + @classmethod + def now(cls, tz: Optional[_tzinfo] = ...) -> datetime: ... + @classmethod + def utcnow(cls) -> datetime: ... + if sys.version_info >= (3, 6): + @classmethod + def combine(cls, date: date, time: time, tzinfo: Optional[_tzinfo] = ...) -> datetime: ... + else: + @classmethod + def combine(cls, date: date, time: time) -> datetime: ... + if sys.version_info >= (3, 7): + @classmethod + def fromisoformat(cls, date_string: str) -> datetime: ... + def strftime(self, fmt: _Text) -> str: ... + if sys.version_info >= (3,): + def __format__(self, fmt: str) -> str: ... + else: + def __format__(self, fmt: AnyStr) -> AnyStr: ... + def toordinal(self) -> int: ... + def timetuple(self) -> struct_time: ... + if sys.version_info >= (3, 3): + def timestamp(self) -> float: ... + def utctimetuple(self) -> struct_time: ... + def date(self) -> _date: ... + def time(self) -> _time: ... + def timetz(self) -> _time: ... + if sys.version_info >= (3, 6): + def replace(self, year: int = ..., month: int = ..., day: int = ..., hour: int = ..., + minute: int = ..., second: int = ..., microsecond: int = ..., tzinfo: + Optional[_tzinfo] = ..., *, fold: int = ...) -> datetime: ... + else: + def replace(self, year: int = ..., month: int = ..., day: int = ..., hour: int = ..., + minute: int = ..., second: int = ..., microsecond: int = ..., tzinfo: + Optional[_tzinfo] = ...) -> datetime: ... + if sys.version_info >= (3, 3): + def astimezone(self, tz: Optional[_tzinfo] = ...) -> datetime: ... + else: + def astimezone(self, tz: _tzinfo) -> datetime: ... + def ctime(self) -> str: ... + if sys.version_info >= (3, 6): + def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... + else: + def isoformat(self, sep: str = ...) -> str: ... + @classmethod + def strptime(cls, date_string: _Text, format: _Text) -> datetime: ... + def utcoffset(self) -> Optional[timedelta]: ... + def tzname(self) -> Optional[str]: ... + def dst(self) -> Optional[int]: ... + def __le__(self, other: datetime) -> bool: ... + def __lt__(self, other: datetime) -> bool: ... + def __ge__(self, other: datetime) -> bool: ... + def __gt__(self, other: datetime) -> bool: ... + def __add__(self, other: timedelta) -> datetime: ... + @overload + def __sub__(self, other: datetime) -> timedelta: ... + @overload + def __sub__(self, other: timedelta) -> datetime: ... + def __hash__(self) -> int: ... + def weekday(self) -> int: ... + def isoweekday(self) -> int: ... + def isocalendar(self) -> Tuple[int, int, int]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/difflib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/difflib.pyi new file mode 100644 index 000000000..a6a4a893d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/difflib.pyi @@ -0,0 +1,87 @@ +# Based on https://docs.python.org/2.7/library/difflib.html and https://docs.python.org/3.2/library/difflib.html + +import sys +from typing import ( + TypeVar, Callable, Iterable, Iterator, List, NamedTuple, Sequence, Tuple, + Generic, Optional, Text, Union, AnyStr +) + +_T = TypeVar('_T') + +if sys.version_info >= (3,): + _StrType = Text +else: + # Aliases can't point to type vars, so we need to redeclare AnyStr + _StrType = TypeVar('_StrType', str, bytes) + +_JunkCallback = Union[Callable[[Text], bool], Callable[[str], bool]] + +Match = NamedTuple('Match', [ + ('a', int), + ('b', int), + ('size', int), +]) + +class SequenceMatcher(Generic[_T]): + def __init__(self, isjunk: Optional[Callable[[_T], bool]] = ..., + a: Sequence[_T] = ..., b: Sequence[_T] = ..., + autojunk: bool = ...) -> None: ... + def set_seqs(self, a: Sequence[_T], b: Sequence[_T]) -> None: ... + def set_seq1(self, a: Sequence[_T]) -> None: ... + def set_seq2(self, b: Sequence[_T]) -> None: ... + def find_longest_match(self, alo: int, ahi: int, blo: int, + bhi: int) -> Match: ... + def get_matching_blocks(self) -> List[Match]: ... + def get_opcodes(self) -> List[Tuple[str, int, int, int, int]]: ... + def get_grouped_opcodes(self, n: int = ... + ) -> Iterable[List[Tuple[str, int, int, int, int]]]: ... + def ratio(self) -> float: ... + def quick_ratio(self) -> float: ... + def real_quick_ratio(self) -> float: ... + +def get_close_matches(word: Sequence[_T], possibilities: Iterable[Sequence[_T]], + n: int = ..., cutoff: float = ...) -> List[Sequence[_T]]: ... + +class Differ: + def __init__(self, linejunk: _JunkCallback = ..., charjunk: _JunkCallback = ...) -> None: ... + def compare(self, a: Sequence[_StrType], b: Sequence[_StrType]) -> Iterator[_StrType]: ... + +def IS_LINE_JUNK(line: _StrType) -> bool: ... +def IS_CHARACTER_JUNK(line: _StrType) -> bool: ... +def unified_diff(a: Sequence[_StrType], b: Sequence[_StrType], fromfile: _StrType = ..., + tofile: _StrType = ..., fromfiledate: _StrType = ..., tofiledate: _StrType = ..., + n: int = ..., lineterm: _StrType = ...) -> Iterator[_StrType]: ... +def context_diff(a: Sequence[_StrType], b: Sequence[_StrType], fromfile: _StrType =..., + tofile: _StrType = ..., fromfiledate: _StrType = ..., tofiledate: _StrType = ..., + n: int = ..., lineterm: _StrType = ...) -> Iterator[_StrType]: ... +def ndiff(a: Sequence[_StrType], b: Sequence[_StrType], + linejunk: _JunkCallback = ..., + charjunk: _JunkCallback = ... + ) -> Iterator[_StrType]: ... + +class HtmlDiff(object): + def __init__(self, tabsize: int = ..., wrapcolumn: int = ..., + linejunk: _JunkCallback = ..., + charjunk: _JunkCallback = ... + ) -> None: ... + def make_file(self, fromlines: Sequence[_StrType], tolines: Sequence[_StrType], + fromdesc: _StrType = ..., todesc: _StrType = ..., context: bool = ..., + numlines: int = ...) -> _StrType: ... + def make_table(self, fromlines: Sequence[_StrType], tolines: Sequence[_StrType], + fromdesc: _StrType = ..., todesc: _StrType = ..., context: bool = ..., + numlines: int = ...) -> _StrType: ... + +def restore(delta: Iterable[_StrType], which: int) -> Iterator[_StrType]: ... + +if sys.version_info >= (3, 5): + def diff_bytes( + dfunc: Callable[[Sequence[str], Sequence[str], str, str, str, str, int, str], Iterator[str]], + a: Sequence[bytes], + b: Sequence[bytes], + fromfile: bytes = ..., + tofile: bytes = ..., + fromfiledate: bytes = ..., + tofiledate: bytes = ..., + n: int = ..., + lineterm: bytes = ... + ) -> Iterator[bytes]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/dis.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/dis.pyi new file mode 100644 index 000000000..9aeb7dd8a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/dis.pyi @@ -0,0 +1,75 @@ +from typing import List, Union, Iterator, Tuple, Optional, Any, IO, NamedTuple, Dict + +import sys +import types + +from opcode import (hasconst as hasconst, hasname as hasname, hasjrel as hasjrel, + hasjabs as hasjabs, haslocal as haslocal, hascompare as hascompare, + hasfree as hasfree, cmp_op as cmp_op, opname as opname, opmap as opmap, + HAVE_ARGUMENT as HAVE_ARGUMENT, EXTENDED_ARG as EXTENDED_ARG) + +if sys.version_info >= (3, 4): + from opcode import stack_effect as stack_effect + +if sys.version_info >= (3, 6): + from opcode import hasnargs as hasnargs + +_have_code = Union[types.MethodType, types.FunctionType, types.CodeType, type] +_have_code_or_string = Union[_have_code, str, bytes] + + +if sys.version_info >= (3, 4): + Instruction = NamedTuple( + "Instruction", + [ + ('opname', str), + ('opcode', int), + ('arg', Optional[int]), + ('argval', Any), + ('argrepr', str), + ('offset', int), + ('starts_line', Optional[int]), + ('is_jump_target', bool) + ] + ) + + class Bytecode: + codeobj = ... # type: types.CodeType + first_line = ... # type: int + def __init__(self, x: _have_code_or_string, *, first_line: Optional[int] = ..., + current_offset: Optional[int] = ...) -> None: ... + def __iter__(self) -> Iterator[Instruction]: ... + def __repr__(self) -> str: ... + def info(self) -> str: ... + def dis(self) -> str: ... + + @classmethod + def from_traceback(cls, tb: types.TracebackType) -> Bytecode: ... + + +COMPILER_FLAG_NAMES = ... # type: Dict[int, str] + + +def findlabels(code: _have_code) -> List[int]: ... +def findlinestarts(code: _have_code) -> Iterator[Tuple[int, int]]: ... + +if sys.version_info >= (3, 0): + def pretty_flags(flags: int) -> str: ... + def code_info(x: _have_code_or_string) -> str: ... + +if sys.version_info >= (3, 4): + def dis(x: _have_code_or_string = ..., *, file: Optional[IO[str]] = ...) -> None: ... + def distb(tb: Optional[types.TracebackType] = ..., *, file: Optional[IO[str]] = ...) -> None: ... + def disassemble(co: _have_code, lasti: int = ..., *, file: Optional[IO[str]] = ...) -> None: ... + def disco(co: _have_code, lasti: int = ..., *, file: Optional[IO[str]] = ...) -> None: ... + def show_code(co: _have_code, *, file: Optional[IO[str]] = ...) -> None: ... + + def get_instructions(x: _have_code, *, first_line: Optional[int] = ...) -> Iterator[Instruction]: ... +else: + def dis(x: _have_code_or_string = ...) -> None: ... + def distb(tb: types.TracebackType = ...) -> None: ... + def disassemble(co: _have_code, lasti: int = ...) -> None: ... + def disco(co: _have_code, lasti: int = ...) -> None: ... + + if sys.version_info >= (3, 0): + def show_code(co: _have_code) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/archive_util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/archive_util.pyi new file mode 100644 index 000000000..12172f3f2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/archive_util.pyi @@ -0,0 +1,12 @@ +# Stubs for distutils.archive_util + +from typing import Optional + + +def make_archive(base_name: str, format: str, root_dir: Optional[str] = ..., + base_dir: Optional[str] = ..., verbose: int = ..., + dry_run: int = ...) -> str: ... +def make_tarball(base_name: str, base_dir: str, compress: Optional[str] = ..., + verbose: int = ..., dry_run: int = ...) -> str: ... +def make_zipfile(base_name: str, base_dir: str, verbose: int = ..., + dry_run: int = ...) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/bcppcompiler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/bcppcompiler.pyi new file mode 100644 index 000000000..9f27a0ae0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/bcppcompiler.pyi @@ -0,0 +1,6 @@ +# Stubs for distutils.bcppcompiler + +from distutils.ccompiler import CCompiler + + +class BCPPCompiler(CCompiler): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/ccompiler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/ccompiler.pyi new file mode 100644 index 000000000..94fad8bac --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/ccompiler.pyi @@ -0,0 +1,119 @@ +# Stubs for distutils.ccompiler + +from typing import Any, Callable, List, Optional, Tuple, Union + + +_Macro = Union[Tuple[str], Tuple[str, str]] + + +def gen_lib_options(compiler: CCompiler, library_dirs: List[str], + runtime_library_dirs: List[str], + libraries: List[str]) -> List[str]: ... +def gen_preprocess_options(macros: List[_Macro], + include_dirs: List[str]) -> List[str]: ... +def get_default_compiler(osname: Optional[str] = ..., + platform: Optional[str] = ...) -> str: ... +def new_compiler(plat: Optional[str] = ..., compiler: Optional[str] = ..., + verbose: int = ..., dry_run: int = ..., + force: int = ...) -> CCompiler: ... +def show_compilers() -> None: ... + +class CCompiler: + def __init__(self, verbose: int = ..., dry_run: int = ..., + force: int = ...) -> None: ... + def add_include_dir(self, dir: str) -> None: ... + def set_include_dirs(self, dirs: List[str]) -> None: ... + def add_library(self, libname: str) -> None: ... + def set_libraries(self, libnames: List[str]) -> None: ... + def add_library_dir(self, dir: str) -> None: ... + def set_library_dirs(self, dirs: List[str]) -> None: ... + def add_runtime_library_dir(self, dir: str) -> None: ... + def set_runtime_library_dirs(self, dirs: List[str]) -> None: ... + def define_macro(self, name: str, value: Optional[str] = ...) -> None: ... + def undefine_macro(self, name: str) -> None: ... + def add_link_object(self, object: str) -> None: ... + def set_link_objects(self, objects: List[str]) -> None: ... + def detect_language(self, sources: Union[str, List[str]]) -> Optional[str]: ... + def find_library_file(self, dirs: List[str], lib: str, + debug: bool = ...) -> Optional[str]: ... + def has_function(self, funcname: str, includes: Optional[List[str]] = ..., + include_dirs: Optional[List[str]] = ..., + libraries: Optional[List[str]] = ..., + library_dirs: Optional[List[str]] = ...) -> bool: ... + def library_dir_option(self, dir: str) -> str: ... + def library_option(self, lib: str) -> str: ... + def runtime_library_dir_option(self, dir: str) -> str: ... + def set_executables(self, **args: str) -> None: ... + def compile(self, sources: List[str], output_dir: Optional[str] = ..., + macros: Optional[_Macro] = ..., + include_dirs: Optional[List[str]] = ..., debug: bool = ..., + extra_preargs: Optional[List[str]] = ..., + extra_postargs: Optional[List[str]] = ..., + depends: Optional[List[str]] = ...) -> List[str]: ... + def create_static_lib(self, objects: List[str], output_libname: str, + output_dir: Optional[str] = ..., debug: bool = ..., + target_lang: Optional[str] = ...) -> None: ... + def link(self, target_desc: str, objects: List[str], output_filename: str, + output_dir: Optional[str] = ..., + libraries: Optional[List[str]] = ..., + library_dirs: Optional[List[str]] = ..., + runtime_library_dirs: Optional[List[str]] = ..., + export_symbols: Optional[List[str]] = ..., debug: bool = ..., + extra_preargs: Optional[List[str]] = ..., + extra_postargs: Optional[List[str]] = ..., + build_temp: Optional[str] = ..., + target_lang: Optional[str] = ...) -> None: ... + def link_executable(self, objects: List[str], output_progname: str, + output_dir: Optional[str] = ..., + libraries: Optional[List[str]] = ..., + library_dirs: Optional[List[str]] = ..., + runtime_library_dirs: Optional[List[str]] = ..., + debug: bool = ..., + extra_preargs: Optional[List[str]] = ..., + extra_postargs: Optional[List[str]] = ..., + target_lang: Optional[str] = ...) -> None: ... + def link_shared_lib(self, objects: List[str], output_libname: str, + output_dir: Optional[str] = ..., + libraries: Optional[List[str]] = ..., + library_dirs: Optional[List[str]] = ..., + runtime_library_dirs: Optional[List[str]] = ..., + export_symbols: Optional[List[str]] = ..., + debug: bool = ..., + extra_preargs: Optional[List[str]] = ..., + extra_postargs: Optional[List[str]] = ..., + build_temp: Optional[str] = ..., + target_lang: Optional[str] = ...) -> None: ... + def link_shared_object(self, objects: List[str], output_filename: str, + output_dir: Optional[str] = ..., + libraries: Optional[List[str]] = ..., + library_dirs: Optional[List[str]] = ..., + runtime_library_dirs: Optional[List[str]] = ..., + export_symbols: Optional[List[str]] = ..., + debug: bool = ..., + extra_preargs: Optional[List[str]] = ..., + extra_postargs: Optional[List[str]] = ..., + build_temp: Optional[str] = ..., + target_lang: Optional[str] = ...) -> None: ... + def preprocess(self, source: str, output_file: Optional[str] = ..., + macros: Optional[List[_Macro]] = ..., + include_dirs: Optional[List[str]] = ..., + extra_preargs: Optional[List[str]] = ..., + extra_postargs: Optional[List[str]] = ...) -> None: ... + def executable_filename(self, basename: str, strip_dir: int = ..., + output_dir: str = ...) -> str: ... + def library_filename(self, libname: str, lib_type: str = ..., + strip_dir: int = ..., + output_dir: str = ...) -> str: ... + def object_filenames(self, source_filenames: List[str], + strip_dir: int = ..., + output_dir: str = ...) -> List[str]: ... + def shared_object_filename(self, basename: str, strip_dir: int = ..., + output_dir: str = ...) -> str: ... + def execute(self, func: Callable[..., None], args: Tuple[Any, ...], + msg: Optional[str] = ..., level: int = ...) -> None: ... + def spawn(self, cmd: List[str]) -> None: ... + def mkpath(self, name: str, mode: int = ...) -> None: ... + def move_file(self, src: str, dst: str) -> str: ... + def announce(self, msg: str, level: int = ...) -> None: ... + def warn(self, msg: str) -> None: ... + def debug_print(self, msg: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/cmd.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/cmd.pyi new file mode 100644 index 000000000..07e4989e6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/cmd.pyi @@ -0,0 +1,40 @@ +# Stubs for distutils.cmd + +from typing import Callable, List, Tuple, Union, Optional, Iterable, Any, Text +from abc import abstractmethod +from distutils.dist import Distribution + +class Command: + sub_commands = ... # type: List[Tuple[str, Union[Callable[[], bool], str, None]]] + def __init__(self, dist: Distribution) -> None: ... + @abstractmethod + def initialize_options(self) -> None: ... + @abstractmethod + def finalize_options(self) -> None: ... + @abstractmethod + def run(self) -> None: ... + + def announce(self, msg: Text, level: int = ...) -> None: ... + def debug_print(self, msg: Text) -> None: ... + + def ensure_string(self, option: str, default: Optional[str] = ...) -> None: ... + def ensure_string_list(self, option: Union[str, List[str]]) -> None: ... + def ensure_filename(self, option: str) -> None: ... + def ensure_dirname(self, option: str) -> None: ... + + def get_command_name(self) -> str: ... + def set_undefined_options(self, src_cmd: Text, *option_pairs: Tuple[str, str]) -> None: ... + def get_finalized_command(self, command: Text, create: int = ...) -> Command: ... + def reinitialize_command(self, command: Union[Command, Text], reinit_subcommands: int = ...) -> Command: ... + def run_command(self, command: Text) -> None: ... + def get_sub_commands(self) -> List[str]: ... + + def warn(self, msg: Text) -> None: ... + def execute(self, func: Callable[..., Any], args: Iterable[Any], msg: Optional[Text] = ..., level: int = ...) -> None: ... + def mkpath(self, name: str, mode: int = ...) -> None: ... + def copy_file(self, infile: str, outfile: str, preserve_mode: int = ..., preserve_times: int = ..., link: Optional[str] = ..., level: Any = ...) -> Tuple[str, bool]: ... # level is not used + def copy_tree(self, infile: str, outfile: str, preserve_mode: int = ..., preserve_times: int = ..., preserve_symlinks: int = ..., level: Any = ...) -> List[str]: ... # level is not used + def move_file(self, src: str, dest: str, level: Any = ...) -> str: ... # level is not used + def spawn(self, cmd: Iterable[str], search_path: int = ..., level: Any = ...) -> None: ... # level is not used + def make_archive(self, base_name: str, format: str, root_dir: Optional[str] = ..., base_dir: Optional[str] = ..., owner: Optional[str] = ..., group: Optional[str] = ...) -> str: ... + def make_file(self, infiles: Union[str, List[str], Tuple[str]], outfile: str, func: Callable[..., Any], args: List[Any], exec_msg: Optional[str] = ..., skip_msg: Optional[str] = ..., level: Any = ...) -> None: ... # level is not used diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_dumb.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_dumb.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_msi.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_msi.pyi new file mode 100644 index 000000000..a76179201 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_msi.pyi @@ -0,0 +1,6 @@ +from distutils.cmd import Command + +class bdist_msi(Command): + def initialize_options(self) -> None: ... + def finalize_options(self) -> None: ... + def run(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_packager.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_packager.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_rpm.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_rpm.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_wininst.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/bdist_wininst.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_clib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_clib.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_ext.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_ext.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_py.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_py.pyi new file mode 100644 index 000000000..34753e4a7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_py.pyi @@ -0,0 +1,10 @@ +from distutils.cmd import Command +import sys + +if sys.version_info >= (3,): + class build_py(Command): + def initialize_options(self) -> None: ... + def finalize_options(self) -> None: ... + def run(self) -> None: ... + + class build_py_2to3(build_py): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_scripts.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/build_scripts.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/check.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/check.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/clean.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/clean.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/config.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/config.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_data.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_data.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_headers.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_headers.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_lib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_lib.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_scripts.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/install_scripts.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/register.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/register.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/sdist.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/command/sdist.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/core.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/core.pyi new file mode 100644 index 000000000..125b79992 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/core.pyi @@ -0,0 +1,50 @@ +# Stubs for distutils.core + +from typing import Any, List, Mapping, Optional, Tuple, Type, Union +from distutils.cmd import Command as Command +from distutils.dist import Distribution as Distribution +from distutils.extension import Extension as Extension + +def setup(name: str = ..., + version: str = ..., + description: str = ..., + long_description: str = ..., + author: str = ..., + author_email: str = ..., + maintainer: str = ..., + maintainer_email: str = ..., + url: str = ..., + download_url: str = ..., + packages: List[str] = ..., + py_modules: List[str] = ..., + scripts: List[str] = ..., + ext_modules: List[Extension] = ..., + classifiers: List[str] = ..., + distclass: Type[Distribution] = ..., + script_name: str = ..., + script_args: List[str] = ..., + options: Mapping[str, Any] = ..., + license: str = ..., + keywords: Union[List[str], str] = ..., + platforms: Union[List[str], str] = ..., + cmdclass: Mapping[str, Type[Command]] = ..., + data_files: List[Tuple[str, List[str]]] = ..., + package_dir: Mapping[str, str] = ..., + obsoletes: List[str] = ..., + provides: List[str] = ..., + requires: List[str] = ..., + command_packages: List[str] = ..., + command_options: Mapping[str, Mapping[str, Tuple[Any, Any]]] = ..., + package_data: Mapping[str, List[str]] = ..., + include_package_data: bool = ..., + libraries: List[str] = ..., + headers: List[str] = ..., + ext_package: str = ..., + include_dirs: List[str] = ..., + password: str = ..., + fullname: str = ..., + **attrs: Any) -> None: ... + +def run_setup(script_name: str, + script_args: Optional[List[str]] = ..., + stop_after: str = ...) -> Distribution: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/cygwinccompiler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/cygwinccompiler.pyi new file mode 100644 index 000000000..1bfab90ea --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/cygwinccompiler.pyi @@ -0,0 +1,7 @@ +# Stubs for distutils.cygwinccompiler + +from distutils.unixccompiler import UnixCCompiler + + +class CygwinCCompiler(UnixCCompiler): ... +class Mingw32CCompiler(CygwinCCompiler): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/debug.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/debug.pyi new file mode 100644 index 000000000..c3a184999 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/debug.pyi @@ -0,0 +1,3 @@ +# Stubs for distutils.debug + +DEBUG = ... # type: bool diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dep_util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dep_util.pyi new file mode 100644 index 000000000..7df584781 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dep_util.pyi @@ -0,0 +1,8 @@ +# Stubs for distutils.dep_util + +from typing import List, Tuple + +def newer(source: str, target: str) -> bool: ... +def newer_pairwise(sources: List[str], + targets: List[str]) -> List[Tuple[str, str]]: ... +def newer_group(sources: List[str], target: str, missing: str = ...) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dir_util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dir_util.pyi new file mode 100644 index 000000000..667ac2fe7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dir_util.pyi @@ -0,0 +1,15 @@ +# Stubs for distutils.dir_util + +from typing import List + + +def mkpath(name: str, mode: int = ..., verbose: int = ..., + dry_run: int = ...) -> List[str]: ... +def create_tree(base_dir: str, files: List[str], mode: int = ..., + verbose: int = ..., dry_run: int = ...) -> None: ... +def copy_tree(src: str, dst: str, preserve_mode: int = ..., + preserve_times: int = ..., preserve_symlinks: int = ..., + update: int = ..., verbose: int = ..., + dry_run: int = ...) -> List[str]: ... +def remove_tree(directory: str, verbose: int = ..., + dry_run: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dist.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dist.pyi new file mode 100644 index 000000000..2d9c16265 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/dist.pyi @@ -0,0 +1,7 @@ +# Stubs for distutils.dist + +from typing import Any, Mapping, Optional + + +class Distribution: + def __init__(self, attrs: Optional[Mapping[str, Any]] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/errors.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/errors.pyi new file mode 100644 index 000000000..e483362bf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/errors.pyi @@ -0,0 +1,19 @@ +class DistutilsError(Exception): ... +class DistutilsModuleError(DistutilsError): ... +class DistutilsClassError(DistutilsError): ... +class DistutilsGetoptError(DistutilsError): ... +class DistutilsArgError(DistutilsError): ... +class DistutilsFileError(DistutilsError): ... +class DistutilsOptionError(DistutilsError): ... +class DistutilsSetupError(DistutilsError): ... +class DistutilsPlatformError(DistutilsError): ... +class DistutilsExecError(DistutilsError): ... +class DistutilsInternalError(DistutilsError): ... +class DistutilsTemplateError(DistutilsError): ... +class DistutilsByteCompileError(DistutilsError): ... +class CCompilerError(Exception): ... +class PreprocessError(CCompilerError): ... +class CompileError(CCompilerError): ... +class LibError(CCompilerError): ... +class LinkError(CCompilerError): ... +class UnknownFileError(CCompilerError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/extension.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/extension.pyi new file mode 100644 index 000000000..5aa070e43 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/extension.pyi @@ -0,0 +1,39 @@ +# Stubs for distutils.extension + +from typing import List, Optional, Tuple +import sys + +class Extension: + if sys.version_info >= (3,): + def __init__(self, + name: str, + sources: List[str], + include_dirs: List[str] = ..., + define_macros: List[Tuple[str, Optional[str]]] = ..., + undef_macros: List[str] = ..., + library_dirs: List[str] = ..., + libraries: List[str] = ..., + runtime_library_dirs: List[str] = ..., + extra_objects: List[str] = ..., + extra_compile_args: List[str] = ..., + extra_link_args: List[str] = ..., + export_symbols: List[str] = ..., + depends: List[str] = ..., + language: str = ..., + optional: bool = ...) -> None: ... + else: + def __init__(self, + name: str, + sources: List[str], + include_dirs: List[str] = ..., + define_macros: List[Tuple[str, Optional[str]]] = ..., + undef_macros: List[str] = ..., + library_dirs: List[str] = ..., + libraries: List[str] = ..., + runtime_library_dirs: List[str] = ..., + extra_objects: List[str] = ..., + extra_compile_args: List[str] = ..., + extra_link_args: List[str] = ..., + export_symbols: List[str] = ..., + depends: List[str] = ..., + language: str = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/fancy_getopt.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/fancy_getopt.pyi new file mode 100644 index 000000000..aa7e964b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/fancy_getopt.pyi @@ -0,0 +1,27 @@ +# Stubs for distutils.fancy_getopt + +from typing import ( + Any, List, Mapping, Optional, Tuple, Union, + TypeVar, overload, +) + +_Option = Tuple[str, str, str] +_GR = Tuple[List[str], OptionDummy] + +def fancy_getopt(options: List[_Option], + negative_opt: Mapping[_Option, _Option], + object: Any, + args: Optional[List[str]]) -> Union[List[str], _GR]: ... +def wrap_text(text: str, width: int) -> List[str]: ... + +class FancyGetopt: + def __init__(self, option_table: Optional[List[_Option]] = ...) -> None: ... + # TODO kinda wrong, `getopt(object=object())` is invalid + @overload + def getopt(self, args: Optional[List[str]] = ...) -> _GR: ... + @overload + def getopt(self, args: Optional[List[str]], object: Any) -> List[str]: ... + def get_option_order(self) -> List[Tuple[str, str]]: ... + def generate_help(self, header: Optional[str] = ...) -> List[str]: ... + +class OptionDummy: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/file_util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/file_util.pyi new file mode 100644 index 000000000..6324d63d4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/file_util.pyi @@ -0,0 +1,12 @@ +# Stubs for distutils.file_util + +from typing import Optional, Sequence, Tuple + + +def copy_file(src: str, dst: str, preserve_mode: bool = ..., + preserve_times: bool = ..., update: bool = ..., + link: Optional[str] = ..., verbose: bool = ..., + dry_run: bool = ...) -> Tuple[str, str]: ... +def move_file(src: str, dst: str, verbose: bool = ..., + dry_run: bool = ...) -> str: ... +def write_file(filename: str, contents: Sequence[str]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/filelist.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/filelist.pyi new file mode 100644 index 000000000..4ecaebaf7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/filelist.pyi @@ -0,0 +1,3 @@ +# Stubs for distutils.filelist + +class FileList: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/log.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/log.pyi new file mode 100644 index 000000000..6c37cc503 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/log.pyi @@ -0,0 +1,28 @@ +from typing import Any, Callable, Iterable, Text + +DEBUG: int +INFO: int +WARN: int +ERROR: int +FATAL: int + +class Log: + def __init__(self, threshold: int = ...) -> None: ... + def log(self, level: int, msg: Text, *args: Any) -> None: ... + def debug(self, msg: Text, *args: Any) -> None: ... + def info(self, msg: Text, *args: Any) -> None: ... + def warn(self, msg: Text, *args: Any) -> None: ... + def error(self, msg: Text, *args: Any) -> None: ... + def fatal(self, msg: Text, *args: Any) -> None: ... + +_LogFunc = Callable[[Text, Iterable[Any]], None] + +log: Callable[[int, Text, Iterable[Any]], None] +debug: _LogFunc +info: _LogFunc +warn: _LogFunc +error: _LogFunc +fatal: _LogFunc + +def set_threshold(level: int) -> int: ... +def set_verbosity(v: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/msvccompiler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/msvccompiler.pyi new file mode 100644 index 000000000..ffc9e4490 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/msvccompiler.pyi @@ -0,0 +1,6 @@ +# Stubs for distutils.msvccompiler + +from distutils.ccompiler import CCompiler + + +class MSVCCompiler(CCompiler): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/spawn.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/spawn.pyi new file mode 100644 index 000000000..8df9ebab7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/spawn.pyi @@ -0,0 +1,8 @@ +# Stubs for distutils.spawn + +from typing import List, Optional + +def spawn(cmd: List[str], search_path: bool = ..., + verbose: bool = ..., dry_run: bool = ...) -> None: ... +def find_executable(executable: str, + path: Optional[str] = ...) -> Optional[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/sysconfig.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/sysconfig.pyi new file mode 100644 index 000000000..f87cd462b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/sysconfig.pyi @@ -0,0 +1,19 @@ +# Stubs for distutils.sysconfig + +from typing import Mapping, Optional, Union +from distutils.ccompiler import CCompiler + +PREFIX = ... # type: str +EXEC_PREFIX = ... # type: str + +def get_config_var(name: str) -> Union[int, str, None]: ... +def get_config_vars(*args: str) -> Mapping[str, Union[int, str]]: ... +def get_config_h_filename() -> str: ... +def get_makefile_filename() -> str: ... +def get_python_inc(plat_specific: bool = ..., + prefix: Optional[str] = ...) -> str: ... +def get_python_lib(plat_specific: bool = ..., standard_lib: bool = ..., + prefix: Optional[str] = ...) -> str: ... + +def customize_compiler(compiler: CCompiler) -> None: ... +def set_python_build() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/text_file.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/text_file.pyi new file mode 100644 index 000000000..8f90d41d1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/text_file.pyi @@ -0,0 +1,18 @@ +# Stubs for distutils.text_file + +from typing import IO, List, Optional, Tuple, Union + +class TextFile: + def __init__(self, filename: Optional[str] = ..., + file: Optional[IO[str]] = ..., + *, strip_comments: bool = ..., + lstrip_ws: bool = ..., rstrip_ws: bool = ..., + skip_blanks: bool = ..., join_lines: bool = ..., + collapse_join: bool = ...) -> None: ... + def open(self, filename: str) -> None: ... + def close(self) -> None: ... + def warn(self, msg: str, + line: Union[List[int], Tuple[int, int], int] = ...) -> None: ... + def readline(self) -> Optional[str]: ... + def readlines(self) -> List[str]: ... + def unreadline(self, line: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/unixccompiler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/unixccompiler.pyi new file mode 100644 index 000000000..7ab7298bf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/unixccompiler.pyi @@ -0,0 +1,6 @@ +# Stubs for distutils.unixccompiler + +from distutils.ccompiler import CCompiler + + +class UnixCCompiler(CCompiler): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/util.pyi new file mode 100644 index 000000000..942886d77 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/util.pyi @@ -0,0 +1,20 @@ +# Stubs for distutils.util + +from typing import Any, Callable, List, Mapping, Optional, Tuple + + +def get_platform() -> str: ... +def convert_path(pathname: str) -> str: ... +def change_root(new_root: str, pathname: str) -> str: ... +def check_environ() -> None: ... +def subst_vars(s: str, local_vars: Mapping[str, str]) -> None: ... +def split_quoted(s: str) -> List[str]: ... +def execute(func: Callable[..., None], args: Tuple[Any, ...], + msg: Optional[str] = ..., verbose: bool = ..., + dry_run: bool = ...) -> None: ... +def strtobool(val: str) -> bool: ... +def byte_compile(py_files: List[str], optimize: int = ..., force: bool = ..., + prefix: Optional[str] = ..., base_dir: Optional[str] = ..., + verbose: bool = ..., dry_run: bool = ..., + direct: Optional[bool] = ...) -> None: ... +def rfc822_escape(header: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/version.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/version.pyi new file mode 100644 index 000000000..cb636b4d9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/distutils/version.pyi @@ -0,0 +1,54 @@ +import sys +from abc import abstractmethod +from typing import Any, Optional, TypeVar, Union, Pattern, Text, Tuple + +_T = TypeVar('_T', bound='Version') + +class Version: + def __repr__(self) -> str: ... + + if sys.version_info >= (3,): + def __eq__(self, other: object) -> bool: ... + def __lt__(self: _T, other: Union[_T, str]) -> bool: ... + def __le__(self: _T, other: Union[_T, str]) -> bool: ... + def __gt__(self: _T, other: Union[_T, str]) -> bool: ... + def __ge__(self: _T, other: Union[_T, str]) -> bool: ... + + @abstractmethod + def __init__(self, vstring: Optional[Text] = ...) -> None: ... + @abstractmethod + def parse(self: _T, vstring: Text) -> _T: ... + @abstractmethod + def __str__(self) -> str: ... + if sys.version_info >= (3,): + @abstractmethod + def _cmp(self: _T, other: Union[_T, str]) -> bool: ... + else: + @abstractmethod + def __cmp__(self: _T, other: Union[_T, str]) -> bool: ... + +class StrictVersion(Version): + version_re: Pattern[str] + version: Tuple[int, int, int] + prerelease: Optional[Tuple[Text, int]] + + def __init__(self, vstring: Optional[Text] = ...) -> None: ... + def parse(self: _T, vstring: Text) -> _T: ... + def __str__(self) -> str: ... + if sys.version_info >= (3,): + def _cmp(self: _T, other: Union[_T, str]) -> bool: ... + else: + def __cmp__(self: _T, other: Union[_T, str]) -> bool: ... + +class LooseVersion(Version): + component_re: Pattern[str] + vstring: Text + version: Tuple[Union[Text, int], ...] + + def __init__(self, vstring: Optional[Text] = ...) -> None: ... + def parse(self: _T, vstring: Text) -> _T: ... + def __str__(self) -> str: ... + if sys.version_info >= (3,): + def _cmp(self: _T, other: Union[_T, str]) -> bool: ... + else: + def __cmp__(self: _T, other: Union[_T, str]) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/doctest.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/doctest.pyi new file mode 100644 index 000000000..8151fb572 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/doctest.pyi @@ -0,0 +1,161 @@ +from typing import Any, Callable, Dict, List, NamedTuple, Optional, Tuple, Type, Union + +import sys +import types +import unittest + +TestResults = NamedTuple('TestResults', [ + ('failed', int), + ('attempted', int), +]) + +OPTIONFLAGS_BY_NAME: Dict[str, int] +def register_optionflag(name: str) -> int: ... +DONT_ACCEPT_TRUE_FOR_1: int +DONT_ACCEPT_BLANKLINE: int +NORMALIZE_WHITESPACE: int +ELLIPSIS: int +SKIP: int +IGNORE_EXCEPTION_DETAIL: int + +COMPARISON_FLAGS: int + +REPORT_UDIFF: int +REPORT_CDIFF: int +REPORT_NDIFF: int +REPORT_ONLY_FIRST_FAILURE: int +if sys.version_info >= (3, 4): + FAIL_FAST: int + +REPORTING_FLAGS: int + +BLANKLINE_MARKER: str +ELLIPSIS_MARKER: str + +class Example: + source: str + want: str + exc_msg: Optional[str] + lineno: int + indent: int + options: Dict[int, bool] + def __init__(self, source: str, want: str, exc_msg: Optional[str] = ..., lineno: int = ..., indent: int = ..., + options: Optional[Dict[int, bool]] = ...) -> None: ... + def __hash__(self) -> int: ... + +class DocTest: + examples: List[Example] + globs: Dict[str, Any] + name: str + filename: Optional[str] + lineno: Optional[int] + docstring: Optional[str] + def __init__(self, examples: List[Example], globs: Dict[str, Any], name: str, filename: Optional[str], lineno: Optional[int], docstring: Optional[str]) -> None: ... + def __hash__(self) -> int: ... + def __lt__(self, other: DocTest) -> bool: ... + +class DocTestParser: + def parse(self, string: str, name: str = ...) -> List[Union[str, Example]]: ... + def get_doctest(self, string: str, globs: Dict[str, Any], name: str, filename: Optional[str], lineno: Optional[str]) -> DocTest: ... + def get_examples(self, strin: str, name: str = ...) -> List[Example]: ... + +class DocTestFinder: + def __init__(self, verbose: bool = ..., parser: DocTestParser = ..., + recurse: bool = ..., exclude_empty: bool = ...) -> None: ... + def find(self, obj: object, name: Optional[str] = ..., module: Union[None, bool, types.ModuleType] = ..., + globs: Optional[Dict[str, Any]] = ..., extraglobs: Optional[Dict[str, Any]] = ...) -> List[DocTest]: ... + +_Out = Callable[[str], Any] +_ExcInfo = Tuple[Type[BaseException], BaseException, types.TracebackType] + +class DocTestRunner: + DIVIDER: str + optionflags: int + original_optionflags: int + tries: int + failures: int + test: DocTest + + def __init__(self, checker: Optional[OutputChecker] = ..., verbose: Optional[bool] = ..., optionflags: int = ...) -> None: ... + def report_start(self, out: _Out, test: DocTest, example: Example) -> None: ... + def report_success(self, out: _Out, test: DocTest, example: Example, got: str) -> None: ... + def report_failure(self, out: _Out, test: DocTest, example: Example, got: str) -> None: ... + def report_unexpected_exception(self, out: _Out, test: DocTest, example: Example, exc_info: _ExcInfo) -> None: ... + def run(self, test: DocTest, compileflags: Optional[int] = ..., out: Optional[_Out] = ..., clear_globs: bool = ...) -> TestResults: ... + def summarize(self, verbose: Optional[bool] = ...) -> TestResults: ... + def merge(self, other: DocTestRunner) -> None: ... + +class OutputChecker: + def check_output(self, want: str, got: str, optionflags: int) -> bool: ... + def output_difference(self, example: Example, got: str, optionflags: int) -> str: ... + +class DocTestFailure(Exception): + test: DocTest + example: Example + got: str + + def __init__(self, test: DocTest, example: Example, got: str) -> None: ... + +class UnexpectedException(Exception): + test: DocTest + example: Example + exc_info: _ExcInfo + + def __init__(self, test: DocTest, example: Example, exc_info: _ExcInfo) -> None: ... + +class DebugRunner(DocTestRunner): ... + +master: Optional[DocTestRunner] + +def testmod(m: Optional[types.ModuleType] = ..., name: Optional[str] = ..., globs: Dict[str, Any] = ..., verbose: Optional[bool] = ..., + report: bool = ..., optionflags: int = ..., extraglobs: Dict[str, Any] = ..., + raise_on_error: bool = ..., exclude_empty: bool = ...) -> TestResults: ... +def testfile(filename: str, module_relative: bool = ..., name: Optional[str] = ..., package: Union[None, str, types.ModuleType] = ..., + globs: Optional[Dict[str, Any]] = ..., verbose: Optional[bool] = ..., report: bool = ..., optionflags: int = ..., + extraglobs: Optional[Dict[str, Any]] = ..., raise_on_error: bool = ..., parser: DocTestParser = ..., + encoding: Optional[str] = ...) -> TestResults: ... +def run_docstring_examples(f: object, globs: Dict[str, Any], verbose: bool = ..., name: str = ..., + compileflags: Optional[int] = ..., optionflags: int = ...) -> None: ... +def set_unittest_reportflags(flags: int) -> int: ... + +class DocTestCase(unittest.TestCase): + def __init__(self, test: DocTest, optionflags: int = ..., setUp: Optional[Callable[[DocTest], Any]] = ..., + tearDown: Optional[Callable[[DocTest], Any]] = ..., + checker: Optional[OutputChecker] = ...) -> None: ... + def setUp(self) -> None: ... + def tearDown(self) -> None: ... + def runTest(self) -> None: ... + def format_failure(self, err: str) -> str: ... + def debug(self) -> None: ... + def id(self) -> str: ... + def __hash__(self) -> int: ... + def shortDescription(self) -> str: ... + +class SkipDocTestCase(DocTestCase): + def __init__(self, module: types.ModuleType) -> None: ... + def setUp(self) -> None: ... + def test_skip(self) -> None: ... + def shortDescription(self) -> str: ... + +if sys.version_info >= (3, 4): + class _DocTestSuite(unittest.TestSuite): ... +else: + _DocTestSuite = unittest.TestSuite + +def DocTestSuite(module: Union[None, str, types.ModuleType] = ..., globs: Optional[Dict[str, Any]] = ..., + extraglobs: Optional[Dict[str, Any]] = ..., test_finder: Optional[DocTestFinder] = ..., + **options: Any) -> _DocTestSuite: ... + +class DocFileCase(DocTestCase): + def id(self) -> str: ... + def format_failure(self, err: str) -> str: ... + +def DocFileTest(path: str, module_relative: bool = ..., package: Union[None, str, types.ModuleType] = ..., + globs: Optional[Dict[str, Any]] = ..., parser: DocTestParser = ..., + encoding: Optional[str] = ..., **options: Any) -> DocFileCase: ... +def DocFileSuite(*paths: str, **kw: Any) -> _DocTestSuite: ... +def script_from_examples(s: str) -> str: ... +def testsource(module: Union[None, str, types.ModuleType], name: str) -> str: ... +def debug_src(src: str, pm: bool = ..., globs: Optional[Dict[str, Any]] = ...) -> None: ... +def debug_script(src: str, pm: bool = ..., globs: Optional[Dict[str, Any]] = ...) -> None: ... +def debug(module: Union[None, str, types.ModuleType], name: str, pm: bool = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/errno.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/errno.pyi new file mode 100644 index 000000000..d24f2e435 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/errno.pyi @@ -0,0 +1,129 @@ +# Stubs for errno + +from typing import Mapping +import sys + +errorcode = ... # type: Mapping[int, str] + +EPERM = ... # type: int +ENOENT = ... # type: int +ESRCH = ... # type: int +EINTR = ... # type: int +EIO = ... # type: int +ENXIO = ... # type: int +E2BIG = ... # type: int +ENOEXEC = ... # type: int +EBADF = ... # type: int +ECHILD = ... # type: int +EAGAIN = ... # type: int +ENOMEM = ... # type: int +EACCES = ... # type: int +EFAULT = ... # type: int +ENOTBLK = ... # type: int +EBUSY = ... # type: int +EEXIST = ... # type: int +EXDEV = ... # type: int +ENODEV = ... # type: int +ENOTDIR = ... # type: int +EISDIR = ... # type: int +EINVAL = ... # type: int +ENFILE = ... # type: int +EMFILE = ... # type: int +ENOTTY = ... # type: int +ETXTBSY = ... # type: int +EFBIG = ... # type: int +ENOSPC = ... # type: int +ESPIPE = ... # type: int +EROFS = ... # type: int +EMLINK = ... # type: int +EPIPE = ... # type: int +EDOM = ... # type: int +ERANGE = ... # type: int +EDEADLCK = ... # type: int +ENAMETOOLONG = ... # type: int +ENOLCK = ... # type: int +ENOSYS = ... # type: int +ENOTEMPTY = ... # type: int +ELOOP = ... # type: int +EWOULDBLOCK = ... # type: int +ENOMSG = ... # type: int +EIDRM = ... # type: int +ECHRNG = ... # type: int +EL2NSYNC = ... # type: int +EL3HLT = ... # type: int +EL3RST = ... # type: int +ELNRNG = ... # type: int +EUNATCH = ... # type: int +ENOCSI = ... # type: int +EL2HLT = ... # type: int +EBADE = ... # type: int +EBADR = ... # type: int +EXFULL = ... # type: int +ENOANO = ... # type: int +EBADRQC = ... # type: int +EBADSLT = ... # type: int +EDEADLOCK = ... # type: int +EBFONT = ... # type: int +ENOSTR = ... # type: int +ENODATA = ... # type: int +ETIME = ... # type: int +ENOSR = ... # type: int +ENONET = ... # type: int +ENOPKG = ... # type: int +EREMOTE = ... # type: int +ENOLINK = ... # type: int +EADV = ... # type: int +ESRMNT = ... # type: int +ECOMM = ... # type: int +EPROTO = ... # type: int +EMULTIHOP = ... # type: int +EDOTDOT = ... # type: int +EBADMSG = ... # type: int +EOVERFLOW = ... # type: int +ENOTUNIQ = ... # type: int +EBADFD = ... # type: int +EREMCHG = ... # type: int +ELIBACC = ... # type: int +ELIBBAD = ... # type: int +ELIBSCN = ... # type: int +ELIBMAX = ... # type: int +ELIBEXEC = ... # type: int +EILSEQ = ... # type: int +ERESTART = ... # type: int +ESTRPIPE = ... # type: int +EUSERS = ... # type: int +ENOTSOCK = ... # type: int +EDESTADDRREQ = ... # type: int +EMSGSIZE = ... # type: int +EPROTOTYPE = ... # type: int +ENOPROTOOPT = ... # type: int +EPROTONOSUPPORT = ... # type: int +ESOCKTNOSUPPORT = ... # type: int +EOPNOTSUPP = ... # type: int +EPFNOSUPPORT = ... # type: int +EAFNOSUPPORT = ... # type: int +EADDRINUSE = ... # type: int +EADDRNOTAVAIL = ... # type: int +ENETDOWN = ... # type: int +ENETUNREACH = ... # type: int +ENETRESET = ... # type: int +ECONNABORTED = ... # type: int +ECONNRESET = ... # type: int +ENOBUFS = ... # type: int +EISCONN = ... # type: int +ENOTCONN = ... # type: int +ESHUTDOWN = ... # type: int +ETOOMANYREFS = ... # type: int +ETIMEDOUT = ... # type: int +ECONNREFUSED = ... # type: int +EHOSTDOWN = ... # type: int +EHOSTUNREACH = ... # type: int +EALREADY = ... # type: int +EINPROGRESS = ... # type: int +ESTALE = ... # type: int +EUCLEAN = ... # type: int +ENOTNAM = ... # type: int +ENAVAIL = ... # type: int +EISNAM = ... # type: int +EREMOTEIO = ... # type: int +EDQUOT = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/filecmp.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/filecmp.pyi new file mode 100644 index 000000000..cc0a621a0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/filecmp.pyi @@ -0,0 +1,48 @@ +# Stubs for filecmp (Python 2/3) +import sys +from typing import AnyStr, Callable, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, Union, Text + +DEFAULT_IGNORES = ... # type: List[str] + +def cmp(f1: Union[bytes, Text], f2: Union[bytes, Text], shallow: Union[int, bool] = ...) -> bool: ... +def cmpfiles(a: AnyStr, b: AnyStr, common: Iterable[AnyStr], + shallow: Union[int, bool] = ...) -> Tuple[List[AnyStr], List[AnyStr], List[AnyStr]]: ... + +class dircmp(Generic[AnyStr]): + def __init__(self, a: AnyStr, b: AnyStr, + ignore: Optional[Sequence[AnyStr]] = ..., + hide: Optional[Sequence[AnyStr]] = ...) -> None: ... + + left = ... # type: AnyStr + right = ... # type: AnyStr + hide = ... # type: Sequence[AnyStr] + ignore = ... # type: Sequence[AnyStr] + + # These properties are created at runtime by __getattr__ + subdirs = ... # type: Dict[AnyStr, dircmp[AnyStr]] + same_files = ... # type: List[AnyStr] + diff_files = ... # type: List[AnyStr] + funny_files = ... # type: List[AnyStr] + common_dirs = ... # type: List[AnyStr] + common_files = ... # type: List[AnyStr] + common_funny = ... # type: List[AnyStr] + common = ... # type: List[AnyStr] + left_only = ... # type: List[AnyStr] + right_only = ... # type: List[AnyStr] + left_list = ... # type: List[AnyStr] + right_list = ... # type: List[AnyStr] + + def report(self) -> None: ... + def report_partial_closure(self) -> None: ... + def report_full_closure(self) -> None: ... + + methodmap = ... # type: Dict[str, Callable[[], None]] + def phase0(self) -> None: ... + def phase1(self) -> None: ... + def phase2(self) -> None: ... + def phase3(self) -> None: ... + def phase4(self) -> None: ... + def phase4_closure(self) -> None: ... + +if sys.version_info >= (3,): + def clear_cache() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/fileinput.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/fileinput.pyi new file mode 100644 index 000000000..0eb8ca9d8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/fileinput.pyi @@ -0,0 +1,62 @@ +from typing import Iterable, Callable, IO, AnyStr, Generic, Any, Text, Union, Iterator, Optional + +import os +import sys + +if sys.version_info >= (3, 6): + _Path = Union[Text, bytes, os.PathLike[Any]] +else: + _Path = Union[Text, bytes] + + +def input( + files: Union[_Path, Iterable[_Path], None] = ..., + inplace: bool = ..., + backup: str = ..., + bufsize: int = ..., + mode: str = ..., + openhook: Callable[[_Path, str], IO[AnyStr]] = ...) -> FileInput[AnyStr]: ... + + +def close() -> None: ... +def nextfile() -> None: ... +def filename() -> str: ... +def lineno() -> int: ... +def filelineno() -> int: ... +def fileno() -> int: ... +def isfirstline() -> bool: ... +def isstdin() -> bool: ... + +class FileInput(Iterable[AnyStr], Generic[AnyStr]): + def __init__( + self, + files: Union[None, _Path, Iterable[_Path]] = ..., + inplace: bool = ..., + backup: str = ..., + bufsize: int = ..., + mode: str = ..., + openhook: Callable[[_Path, str], IO[AnyStr]] = ... + ) -> None: ... + + def __del__(self) -> None: ... + def close(self) -> None: ... + if sys.version_info >= (3, 2): + def __enter__(self) -> FileInput[AnyStr]: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... + def __iter__(self) -> Iterator[AnyStr]: ... + def __next__(self) -> AnyStr: ... + def __getitem__(self, i: int) -> AnyStr: ... + def nextfile(self) -> None: ... + def readline(self) -> AnyStr: ... + def filename(self) -> str: ... + def lineno(self) -> int: ... + def filelineno(self) -> int: ... + def fileno(self) -> int: ... + def isfirstline(self) -> bool: ... + def isstdin(self) -> bool: ... + +def hook_compressed(filename: _Path, mode: str) -> IO[Any]: ... +if sys.version_info >= (3, 6): + def hook_encoded(encoding: str, errors: Optional[str] = ...) -> Callable[[_Path, str], IO[Any]]: ... +else: + def hook_encoded(encoding: str) -> Callable[[_Path, str], IO[Any]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/formatter.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/formatter.pyi new file mode 100644 index 000000000..9ad2978b5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/formatter.pyi @@ -0,0 +1,105 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/formatter.py +# and https://github.com/python/cpython/blob/master/Lib/formatter.py +from typing import Any, IO, List, Optional, Tuple + +AS_IS = None +_FontType = Tuple[str, bool, bool, bool] +_StylesType = Tuple[Any, ...] + +class NullFormatter: + writer = ... # type: Optional[NullWriter] + def __init__(self, writer: Optional[NullWriter] = ...) -> None: ... + def end_paragraph(self, blankline: int) -> None: ... + def add_line_break(self) -> None: ... + def add_hor_rule(self, *args, **kw) -> None: ... + def add_label_data(self, format, counter: int, blankline: Optional[int] = ...) -> None: ... + def add_flowing_data(self, data: str) -> None: ... + def add_literal_data(self, data: str) -> None: ... + def flush_softspace(self) -> None: ... + def push_alignment(self, align: Optional[str]) -> None: ... + def pop_alignment(self) -> None: ... + def push_font(self, x: _FontType) -> None: ... + def pop_font(self) -> None: ... + def push_margin(self, margin: int) -> None: ... + def pop_margin(self) -> None: ... + def set_spacing(self, spacing: Optional[str]) -> None: ... + def push_style(self, *styles: _StylesType) -> None: ... + def pop_style(self, n: int = ...) -> None: ... + def assert_line_data(self, flag: int = ...) -> None: ... + +class AbstractFormatter: + writer = ... # type: NullWriter + align = ... # type: Optional[str] + align_stack = ... # type: List[Optional[str]] + font_stack = ... # type: List[_FontType] + margin_stack = ... # type: List[int] + spacing = ... # type: Optional[str] + style_stack = ... # type: Any + nospace = ... # type: int + softspace = ... # type: int + para_end = ... # type: int + parskip = ... # type: int + hard_break = ... # type: int + have_label = ... # type: int + def __init__(self, writer: NullWriter) -> None: ... + def end_paragraph(self, blankline: int) -> None: ... + def add_line_break(self) -> None: ... + def add_hor_rule(self, *args, **kw) -> None: ... + def add_label_data(self, format, counter: int, blankline: Optional[int] = ...) -> None: ... + def format_counter(self, format, counter: int) -> str: ... + def format_letter(self, case: str, counter: int) -> str: ... + def format_roman(self, case: str, counter: int) -> str: ... + def add_flowing_data(self, data: str) -> None: ... + def add_literal_data(self, data: str) -> None: ... + def flush_softspace(self) -> None: ... + def push_alignment(self, align: Optional[str]) -> None: ... + def pop_alignment(self) -> None: ... + def push_font(self, font: _FontType) -> None: ... + def pop_font(self) -> None: ... + def push_margin(self, margin: int) -> None: ... + def pop_margin(self) -> None: ... + def set_spacing(self, spacing: Optional[str]) -> None: ... + def push_style(self, *styles: _StylesType) -> None: ... + def pop_style(self, n: int = ...) -> None: ... + def assert_line_data(self, flag: int = ...) -> None: ... + +class NullWriter: + def __init__(self) -> None: ... + def flush(self) -> None: ... + def new_alignment(self, align: Optional[str]) -> None: ... + def new_font(self, font: _FontType) -> None: ... + def new_margin(self, margin: int, level: int) -> None: ... + def new_spacing(self, spacing: Optional[str]) -> None: ... + def new_styles(self, styles) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args, **kw) -> None: ... + def send_label_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + def send_literal_data(self, data: str) -> None: ... + +class AbstractWriter(NullWriter): + def new_alignment(self, align: Optional[str]) -> None: ... + def new_font(self, font: _FontType) -> None: ... + def new_margin(self, margin: int, level: int) -> None: ... + def new_spacing(self, spacing: Optional[str]) -> None: ... + def new_styles(self, styles) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args, **kw) -> None: ... + def send_label_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + def send_literal_data(self, data: str) -> None: ... + +class DumbWriter(NullWriter): + file = ... # type: IO + maxcol = ... # type: int + def __init__(self, file: Optional[IO] = ..., maxcol: int = ...) -> None: ... + def reset(self) -> None: ... + def send_paragraph(self, blankline: int) -> None: ... + def send_line_break(self) -> None: ... + def send_hor_rule(self, *args, **kw) -> None: ... + def send_literal_data(self, data: str) -> None: ... + def send_flowing_data(self, data: str) -> None: ... + +def test(file: Optional[str] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/fractions.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/fractions.pyi new file mode 100644 index 000000000..783a001e1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/fractions.pyi @@ -0,0 +1,96 @@ +# Stubs for fractions +# See https://docs.python.org/3/library/fractions.html +# +# Note: these stubs are incomplete. The more complex type +# signatures are currently omitted. Also see numbers.pyi. + +from typing import Optional, TypeVar, Union, overload +from numbers import Real, Integral, Rational +from decimal import Decimal +import sys + +_ComparableNum = Union[int, float, Decimal, Real] + + +@overload +def gcd(a: int, b: int) -> int: ... +@overload +def gcd(a: Integral, b: int) -> Integral: ... +@overload +def gcd(a: int, b: Integral) -> Integral: ... +@overload +def gcd(a: Integral, b: Integral) -> Integral: ... + + +class Fraction(Rational): + @overload + def __init__(self, + numerator: Union[int, Rational] = ..., + denominator: Optional[Union[int, Rational]] = ..., + *, + _normalize: bool = ...) -> None: ... + @overload + def __init__(self, value: float, *, _normalize: bool = ...) -> None: ... + @overload + def __init__(self, value: Decimal, *, _normalize: bool = ...) -> None: ... + @overload + def __init__(self, value: str, *, _normalize: bool = ...) -> None: ... + + @classmethod + def from_float(cls, f: float) -> 'Fraction': ... + @classmethod + def from_decimal(cls, dec: Decimal) -> 'Fraction': ... + def limit_denominator(self, max_denominator: int = ...) -> 'Fraction': ... + + @property + def numerator(self) -> int: ... + @property + def denominator(self) -> int: ... + + def __add__(self, other): ... + def __radd__(self, other): ... + def __sub__(self, other): ... + def __rsub__(self, other): ... + def __mul__(self, other): ... + def __rmul__(self, other): ... + def __truediv__(self, other): ... + def __rtruediv__(self, other): ... + if sys.version_info < (3, 0): + def __div__(self, other): ... + def __rdiv__(self, other): ... + def __floordiv__(self, other) -> int: ... + def __rfloordiv__(self, other) -> int: ... + def __mod__(self, other): ... + def __rmod__(self, other): ... + def __divmod__(self, other): ... + def __rdivmod__(self, other): ... + def __pow__(self, other): ... + def __rpow__(self, other): ... + + def __pos__(self) -> 'Fraction': ... + def __neg__(self) -> 'Fraction': ... + def __abs__(self) -> 'Fraction': ... + def __trunc__(self) -> int: ... + if sys.version_info >= (3, 0): + def __floor__(self) -> int: ... + def __ceil__(self) -> int: ... + def __round__(self, ndigits=None): ... + + def __hash__(self) -> int: ... + def __eq__(self, other: object) -> bool: ... + def __lt__(self, other: _ComparableNum) -> bool: ... + def __gt__(self, other: _ComparableNum) -> bool: ... + def __le__(self, other: _ComparableNum) -> bool: ... + def __ge__(self, other: _ComparableNum) -> bool: ... + if sys.version_info >= (3, 0): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... + + # Not actually defined within fractions.py, but provides more useful + # overrides + @property + def real(self) -> 'Fraction': ... + @property + def imag(self) -> 'Fraction': ... + def conjugate(self) -> 'Fraction': ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ftplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ftplib.pyi new file mode 100644 index 000000000..010961313 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ftplib.pyi @@ -0,0 +1,134 @@ +# Stubs for ftplib (Python 2.7/3) +import sys +from typing import Optional, BinaryIO, Tuple, TextIO, Iterable, Callable, List, Union, Iterator, Dict, Text, Type, TypeVar, Generic, Any +from types import TracebackType +from socket import socket +from ssl import SSLContext + +_T = TypeVar('_T') +_IntOrStr = Union[int, Text] + +MSG_OOB = ... # type: int +FTP_PORT = ... # type: int +MAXLINE = ... # type: int +CRLF = ... # type: str +if sys.version_info >= (3,): + B_CRLF = ... # type: bytes + +class Error(Exception): ... +class error_reply(Error): ... +class error_temp(Error): ... +class error_perm(Error): ... +class error_proto(Error): ... + +all_errors = Tuple[Exception, ...] + +class FTP: + debugging = ... # type: int + + # Note: This is technically the type that's passed in as the host argument. But to make it easier in Python 2 we + # accept Text but return str. + host = ... # type: str + + port = ... # type: int + maxline = ... # type: int + sock = ... # type: Optional[socket] + welcome = ... # type: Optional[str] + passiveserver = ... # type: int + timeout = ... # type: int + af = ... # type: int + lastresp = ... # type: str + + if sys.version_info >= (3,): + file = ... # type: Optional[TextIO] + encoding = ... # type: str + def __enter__(self: _T) -> _T: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + else: + file = ... # type: Optional[BinaryIO] + + if sys.version_info >= (3, 3): + source_address = ... # type: Optional[Tuple[str, int]] + def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., + timeout: float = ..., source_address: Optional[Tuple[str, int]] = ...) -> None: ... + def connect(self, host: Text = ..., port: int = ..., timeout: float = ..., + source_address: Optional[Tuple[str, int]] = ...) -> str: ... + else: + def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., + timeout: float = ...) -> None: ... + def connect(self, host: Text = ..., port: int = ..., timeout: float = ...) -> str: ... + + def getwelcome(self) -> str: ... + def set_debuglevel(self, level: int) -> None: ... + def debug(self, level: int) -> None: ... + def set_pasv(self, val: Union[bool, int]) -> None: ... + def sanitize(self, s: Text) -> str: ... + def putline(self, line: Text) -> None: ... + def putcmd(self, line: Text) -> None: ... + def getline(self) -> str: ... + def getmultiline(self) -> str: ... + def getresp(self) -> str: ... + def voidresp(self) -> str: ... + def abort(self) -> str: ... + def sendcmd(self, cmd: Text) -> str: ... + def voidcmd(self, cmd: Text) -> str: ... + def sendport(self, host: Text, port: int) -> str: ... + def sendeprt(self, host: Text, port: int) -> str: ... + def makeport(self) -> socket: ... + def makepasv(self) -> Tuple[str, int]: ... + def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ...) -> str: ... + + # In practice, `rest` rest can actually be anything whose str() is an integer sequence, so to make it simple we allow integers. + def ntransfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> Tuple[socket, int]: ... + def transfercmd(self, cmd: Text, rest: Optional[_IntOrStr] = ...) -> socket: ... + def retrbinary(self, cmd: Text, callback: Callable[[bytes], Any], blocksize: int = ..., rest: Optional[_IntOrStr] = ...) -> str: ... + def storbinary(self, cmd: Text, fp: BinaryIO, blocksize: int = ..., callback: Optional[Callable[[bytes], Any]] = ..., rest: Optional[_IntOrStr] = ...) -> str: ... + + def retrlines(self, cmd: Text, callback: Optional[Callable[[str], Any]] = ...) -> str: ... + def storlines(self, cmd: Text, fp: BinaryIO, callback: Optional[Callable[[bytes], Any]] = ...) -> str: ... + + def acct(self, password: Text) -> str: ... + def nlst(self, *args: Text) -> List[str]: ... + + # Technically only the last arg can be a Callable but ... + def dir(self, *args: Union[str, Callable[[str], None]]) -> None: ... + + if sys.version_info >= (3, 3): + def mlsd(self, path: Text = ..., facts: Iterable[str] = ...) -> Iterator[Tuple[str, Dict[str, str]]]: ... + def rename(self, fromname: Text, toname: Text) -> str: ... + def delete(self, filename: Text) -> str: ... + def cwd(self, dirname: Text) -> str: ... + def size(self, filename: Text) -> str: ... + def mkd(self, dirname: Text) -> str: ... + def rmd(self, dirname: Text) -> str: ... + def pwd(self) -> str: ... + def quit(self) -> str: ... + def close(self) -> None: ... + +class FTP_TLS(FTP): + def __init__(self, host: Text = ..., user: Text = ..., passwd: Text = ..., acct: Text = ..., + keyfile: Optional[str] = ..., certfile: Optional[str] = ..., + context: Optional[SSLContext] = ..., timeout: float = ..., + source_address: Optional[Tuple[str, int]] = ...) -> None: ... + + ssl_version = ... # type: int + keyfile = ... # type: Optional[str] + certfile = ... # type: Optional[str] + context = ... # type: SSLContext + + def login(self, user: Text = ..., passwd: Text = ..., acct: Text = ..., secure: bool = ...) -> str: ... + def auth(self) -> str: ... + def prot_p(self) -> str: ... + def prot_c(self) -> str: ... + + if sys.version_info >= (3, 3): + def ccc(self) -> str: ... + +if sys.version_info < (3,): + class Netrc: + def __init__(self, filename: Optional[Text] = ...) -> None: ... + def get_hosts(self) -> List[str]: ... + def get_account(self, host: Text) -> Tuple[Optional[str], Optional[str], Optional[str]]: ... + def get_macros(self) -> List[str]: ... + def get_macro(self, macro: Text) -> Tuple[str, ...]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/grp.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/grp.pyi new file mode 100644 index 000000000..605472721 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/grp.pyi @@ -0,0 +1,10 @@ +from typing import List, NamedTuple, Optional + +struct_group = NamedTuple("struct_group", [("gr_name", str), + ("gr_passwd", Optional[str]), + ("gr_gid", int), + ("gr_mem", List[str])]) + +def getgrall() -> List[struct_group]: ... +def getgrgid(gid: int) -> struct_group: ... +def getgrnam(name: str) -> struct_group: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/hmac.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/hmac.pyi new file mode 100644 index 000000000..fb5029c59 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/hmac.pyi @@ -0,0 +1,38 @@ +# Stubs for hmac + +from typing import Any, Callable, Optional, Union, overload, AnyStr +from types import ModuleType +import sys + +_B = Union[bytes, bytearray] + +# TODO more precise type for object of hashlib +_Hash = Any + +digest_size: None + +if sys.version_info >= (3, 4): + def new(key: _B, msg: Optional[_B] = ..., + digestmod: Optional[Union[str, Callable[[], _Hash], ModuleType]] = ...) -> HMAC: ... +else: + def new(key: _B, msg: Optional[_B] = ..., + digestmod: Optional[Union[Callable[[], _Hash], ModuleType]] = ...) -> HMAC: ... + +class HMAC: + if sys.version_info >= (3,): + digest_size = ... # type: int + if sys.version_info >= (3, 4): + block_size = ... # type: int + name = ... # type: str + def update(self, msg: _B) -> None: ... + def digest(self) -> bytes: ... + def hexdigest(self) -> str: ... + def copy(self) -> HMAC: ... + +@overload +def compare_digest(a: bytearray, b: bytearray) -> bool: ... +@overload +def compare_digest(a: AnyStr, b: AnyStr) -> bool: ... + +if sys.version_info >= (3, 7): + def digest(key: _B, msg: _B, digest: str) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/imaplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/imaplib.pyi new file mode 100644 index 000000000..ecf80c0ff --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/imaplib.pyi @@ -0,0 +1,133 @@ +# Stubs for imaplib (Python 2) + +import imaplib +import subprocess +import sys +import time +from socket import socket as _socket +from ssl import SSLSocket +from typing import Any, Callable, Dict, IO, List, Optional, Pattern, Text, Tuple, Type, Union + +CommandResults = Tuple[str, List[Any]] + + +class IMAP4: + error: Type[Exception] = ... + abort: Type[Exception] = ... + readonly: Type[Exception] = ... + mustquote: Pattern[Text] = ... + debug: int = ... + state: str = ... + literal: Optional[Text] = ... + tagged_commands: Dict[str, str] = ... + untagged_responses: Dict[str, str] = ... + continuation_response: str = ... + is_readonly: bool = ... + tagnum: int = ... + tagpre: str = ... + tagre: Pattern[Text] = ... + welcome: bytes = ... + capabilities: Tuple[str] = ... + PROTOCOL_VERSION: str = ... + def __init__(self, host: str, port: int) -> None: ... + def __getattr__(self, attr: str) -> Any: ... + host: str = ... + port: int = ... + sock: _socket = ... + file: Union[IO[Text], IO[bytes]] = ... + def open(self, host: str = ..., port: int = ...) -> None: ... + def read(self, size: int) -> bytes: ... + def readline(self) -> bytes: ... + def send(self, data: bytes) -> None: ... + def shutdown(self) -> None: ... + def socket(self) -> _socket: ... + def recent(self) -> CommandResults: ... + def response(self, code: str) -> CommandResults: ... + def append(self, mailbox: str, flags: str, date_time: str, message: str) -> str: ... + def authenticate(self, mechanism: str, authobject: Callable) -> Tuple[str, str]: ... + def capability(self) -> CommandResults: ... + def check(self) -> CommandResults: ... + def close(self) -> CommandResults: ... + def copy(self, message_set: str, new_mailbox: str) -> CommandResults: ... + def create(self, mailbox: str) -> CommandResults: ... + def delete(self, mailbox: str) -> CommandResults: ... + def deleteacl(self, mailbox: str, who: str) -> CommandResults: ... + def expunge(self) -> CommandResults: ... + def fetch(self, message_set: str, message_parts: str) -> CommandResults: ... + def getacl(self, mailbox: str) -> CommandResults: ... + def getannotation(self, mailbox: str, entry: str, attribute: str) -> CommandResults: ... + def getquota(self, root: str) -> CommandResults: ... + def getquotaroot(self, mailbox: str) -> CommandResults: ... + def list(self, directory: str = ..., pattern: str = ...) -> CommandResults: ... + def login(self, user: str, password: str) -> CommandResults: ... + def login_cram_md5(self, user: str, password: str) -> CommandResults: ... + def logout(self) -> CommandResults: ... + def lsub(self, directory: str = ..., pattern: str = ...) -> CommandResults: ... + def myrights(self, mailbox: str) -> CommandResults: ... + def namespace(self) -> CommandResults: ... + def noop(self) -> CommandResults: ... + def partial(self, message_num: str, message_part: str, start: str, length: str) -> CommandResults: ... + def proxyauth(self, user: str) -> CommandResults: ... + def rename(self, oldmailbox: str, newmailbox: str) -> CommandResults: ... + def search(self, charset: str, *criteria: str) -> CommandResults: ... + def select(self, mailbox: str = ..., readonly: bool = ...) -> CommandResults: ... + def setacl(self, mailbox: str, who: str, what: str) -> CommandResults: ... + def setannotation(self, *args: List[str]) -> CommandResults: ... + def setquota(self, root: str, limits: str) -> CommandResults: ... + def sort(self, sort_criteria: str, charset: str, *search_criteria: List[str]) -> CommandResults: ... + if sys.version_info >= (3,): + def starttls(self, ssl_context: Optional[Any] = ...) -> CommandResults: ... + def status(self, mailbox: str, names: str) -> CommandResults: ... + def store(self, message_set: str, command: str, flags: str) -> CommandResults: ... + def subscribe(self, mailbox: str) -> CommandResults: ... + def thread(self, threading_algorithm: str, charset: str, *search_criteria: List[str]) -> CommandResults: ... + def uid(self, command: str, *args: List[str]) -> CommandResults: ... + def unsubscribe(self, mailbox: str) -> CommandResults: ... + def xatom(self, name: str, *args: List[str]) -> CommandResults: ... + def print_log(self) -> None: ... + +class IMAP4_SSL(IMAP4): + keyfile: str = ... + certfile: str = ... + def __init__(self, host: str = ..., port: int = ..., keyfile: Optional[str] = ..., certfile: Optional[str] = ...) -> None: ... + host: str = ... + port: int = ... + sock: _socket = ... + sslobj: SSLSocket = ... + file: IO[Any] = ... + def open(self, host: str = ..., port: Optional[int] = ...) -> None: ... + def read(self, size: int) -> bytes: ... + def readline(self) -> bytes: ... + def send(self, data: bytes) -> None: ... + def shutdown(self) -> None: ... + def socket(self) -> _socket: ... + def ssl(self) -> SSLSocket: ... + + +class IMAP4_stream(IMAP4): + command: str = ... + def __init__(self, command: str) -> None: ... + host: str = ... + port: int = ... + sock: _socket = ... + file: IO[Any] = ... + process: subprocess.Popen = ... + writefile: IO[Any] = ... + readfile: IO[Any] = ... + def open(self, host: str = ..., port: Optional[int] = ...) -> None: ... + def read(self, size: int) -> bytes: ... + def readline(self) -> bytes: ... + def send(self, data: bytes) -> None: ... + def shutdown(self) -> None: ... + +class _Authenticator: + mech: Callable = ... + def __init__(self, mechinst: Callable) -> None: ... + def process(self, data: str) -> str: ... + def encode(self, inp: bytes) -> str: ... + def decode(self, inp: str) -> bytes: ... + +def Internaldate2tuple(resp: str) -> time.struct_time: ... +def Int2AP(num: int) -> str: ... +def ParseFlags(resp: str) -> Tuple[str]: ... +def Time2Internaldate(date_time: Union[float, time.struct_time, str]) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/keyword.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/keyword.pyi new file mode 100644 index 000000000..6e0fb5f14 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/keyword.pyi @@ -0,0 +1,6 @@ +# Stubs for keyword + +from typing import Sequence, Text, Union + +def iskeyword(s: Union[Text, bytes]) -> bool: ... +kwlist = ... # type: Sequence[str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/__init__.pyi new file mode 100644 index 000000000..145e31b1d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/__init__.pyi @@ -0,0 +1 @@ +# Stubs for lib2to3 (Python 3.6) diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/__init__.pyi new file mode 100644 index 000000000..1adc82a6e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/__init__.pyi @@ -0,0 +1,10 @@ +# Stubs for lib2to3.pgen2 (Python 3.6) + +import os +import sys +from typing import Text, Union + +if sys.version_info >= (3, 6): + _Path = Union[Text, os.PathLike] +else: + _Path = Text diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/driver.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/driver.pyi new file mode 100644 index 000000000..56785f087 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/driver.pyi @@ -0,0 +1,24 @@ +# Stubs for lib2to3.pgen2.driver (Python 3.6) + +import os +import sys +from typing import Any, Callable, IO, Iterable, List, Optional, Text, Tuple, Union + +from logging import Logger +from lib2to3.pytree import _Convert, _NL +from lib2to3.pgen2 import _Path +from lib2to3.pgen2.grammar import Grammar + + +class Driver: + grammar: Grammar + logger: Logger + convert: _Convert + def __init__(self, grammar: Grammar, convert: Optional[_Convert] = ..., logger: Optional[Logger] = ...) -> None: ... + def parse_tokens(self, tokens: Iterable[Any], debug: bool = ...) -> _NL: ... + def parse_stream_raw(self, stream: IO[Text], debug: bool = ...) -> _NL: ... + def parse_stream(self, stream: IO[Text], debug: bool = ...) -> _NL: ... + def parse_file(self, filename: _Path, encoding: Optional[Text] = ..., debug: bool = ...) -> _NL: ... + def parse_string(self, text: Text, debug: bool = ...) -> _NL: ... + +def load_grammar(gt: Text = ..., gp: Optional[Text] = ..., save: bool = ..., force: bool = ..., logger: Optional[Logger] = ...) -> Grammar: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/grammar.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/grammar.pyi new file mode 100644 index 000000000..122d771db --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/grammar.pyi @@ -0,0 +1,29 @@ +# Stubs for lib2to3.pgen2.grammar (Python 3.6) + +from lib2to3.pgen2 import _Path + +from typing import Any, Dict, List, Optional, Text, Tuple, TypeVar + +_P = TypeVar('_P') +_Label = Tuple[int, Optional[Text]] +_DFA = List[List[Tuple[int, int]]] +_DFAS = Tuple[_DFA, Dict[int, int]] + +class Grammar: + symbol2number: Dict[Text, int] + number2symbol: Dict[int, Text] + states: List[_DFA] + dfas: Dict[int, _DFAS] + labels: List[_Label] + keywords: Dict[Text, int] + tokens: Dict[int, int] + symbol2label: Dict[Text, int] + start: int + def __init__(self) -> None: ... + def dump(self, filename: _Path) -> None: ... + def load(self, filename: _Path) -> None: ... + def copy(self: _P) -> _P: ... + def report(self) -> None: ... + +opmap_raw: Text +opmap: Dict[Text, Text] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/literals.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/literals.pyi new file mode 100644 index 000000000..8719500da --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/literals.pyi @@ -0,0 +1,9 @@ +# Stubs for lib2to3.pgen2.literals (Python 3.6) + +from typing import Dict, Match, Text + +simple_escapes: Dict[Text, Text] + +def escape(m: Match) -> Text: ... +def evalString(s: Text) -> Text: ... +def test() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/parse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/parse.pyi new file mode 100644 index 000000000..101d4760a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/parse.pyi @@ -0,0 +1,29 @@ +# Stubs for lib2to3.pgen2.parse (Python 3.6) + +from typing import Any, Dict, List, Optional, Sequence, Set, Text, Tuple + +from lib2to3.pgen2.grammar import Grammar, _DFAS +from lib2to3.pytree import _NL, _Convert, _RawNode + +_Context = Sequence[Any] + +class ParseError(Exception): + msg: Text + type: int + value: Optional[Text] + context: _Context + def __init__(self, msg: Text, type: int, value: Optional[Text], context: _Context) -> None: ... + +class Parser: + grammar: Grammar + convert: _Convert + stack: List[Tuple[_DFAS, int, _RawNode]] + rootnode: Optional[_NL] + used_names: Set[Text] + def __init__(self, grammar: Grammar, convert: Optional[_Convert] = ...) -> None: ... + def setup(self, start: Optional[int] = ...) -> None: ... + def addtoken(self, type: int, value: Optional[Text], context: _Context) -> bool: ... + def classify(self, type: int, value: Optional[Text], context: _Context) -> int: ... + def shift(self, type: int, value: Optional[Text], newstate: int, context: _Context) -> None: ... + def push(self, type: int, newdfa: _DFAS, newstate: int, context: _Context) -> None: ... + def pop(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/pgen.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/pgen.pyi new file mode 100644 index 000000000..42d503b4d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/pgen.pyi @@ -0,0 +1,50 @@ +# Stubs for lib2to3.pgen2.pgen (Python 3.6) + +from typing import ( + Any, Dict, IO, Iterable, Iterator, List, NoReturn, Optional, Text, Tuple +) + +from lib2to3.pgen2 import _Path, grammar +from lib2to3.pgen2.tokenize import _TokenInfo + +class PgenGrammar(grammar.Grammar): ... + +class ParserGenerator: + filename: _Path + stream: IO[Text] + generator: Iterator[_TokenInfo] + first: Dict[Text, Dict[Text, int]] + def __init__(self, filename: _Path, stream: Optional[IO[Text]] = ...) -> None: ... + def make_grammar(self) -> PgenGrammar: ... + def make_first(self, c: PgenGrammar, name: Text) -> Dict[int, int]: ... + def make_label(self, c: PgenGrammar, label: Text) -> int: ... + def addfirstsets(self) -> None: ... + def calcfirst(self, name: Text) -> None: ... + def parse(self) -> Tuple[Dict[Text, List[DFAState]], Text]: ... + def make_dfa(self, start: NFAState, finish: NFAState) -> List[DFAState]: ... + def dump_nfa(self, name: Text, start: NFAState, finish: NFAState) -> List[DFAState]: ... + def dump_dfa(self, name: Text, dfa: Iterable[DFAState]) -> None: ... + def simplify_dfa(self, dfa: List[DFAState]) -> None: ... + def parse_rhs(self) -> Tuple[NFAState, NFAState]: ... + def parse_alt(self) -> Tuple[NFAState, NFAState]: ... + def parse_item(self) -> Tuple[NFAState, NFAState]: ... + def parse_atom(self) -> Tuple[NFAState, NFAState]: ... + def expect(self, type: int, value: Optional[Any] = ...) -> Text: ... + def gettoken(self) -> None: ... + def raise_error(self, msg: str, *args: Any) -> NoReturn: ... + +class NFAState: + arcs: List[Tuple[Optional[Text], NFAState]] + def __init__(self) -> None: ... + def addarc(self, next: NFAState, label: Optional[Text] = ...) -> None: ... + +class DFAState: + nfaset: Dict[NFAState, Any] + isfinal: bool + arcs: Dict[Text, DFAState] + def __init__(self, nfaset: Dict[NFAState, Any], final: NFAState) -> None: ... + def addarc(self, next: DFAState, label: Text) -> None: ... + def unifystate(self, old: DFAState, new: DFAState) -> None: ... + def __eq__(self, other: Any) -> bool: ... + +def generate_grammar(filename: _Path = ...) -> PgenGrammar: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/token.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/token.pyi new file mode 100644 index 000000000..c256af8f2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/token.pyi @@ -0,0 +1,73 @@ +# Stubs for lib2to3.pgen2.token (Python 3.6) + +import sys +from typing import Dict, Text + +ENDMARKER: int +NAME: int +NUMBER: int +STRING: int +NEWLINE: int +INDENT: int +DEDENT: int +LPAR: int +RPAR: int +LSQB: int +RSQB: int +COLON: int +COMMA: int +SEMI: int +PLUS: int +MINUS: int +STAR: int +SLASH: int +VBAR: int +AMPER: int +LESS: int +GREATER: int +EQUAL: int +DOT: int +PERCENT: int +BACKQUOTE: int +LBRACE: int +RBRACE: int +EQEQUAL: int +NOTEQUAL: int +LESSEQUAL: int +GREATEREQUAL: int +TILDE: int +CIRCUMFLEX: int +LEFTSHIFT: int +RIGHTSHIFT: int +DOUBLESTAR: int +PLUSEQUAL: int +MINEQUAL: int +STAREQUAL: int +SLASHEQUAL: int +PERCENTEQUAL: int +AMPEREQUAL: int +VBAREQUAL: int +CIRCUMFLEXEQUAL: int +LEFTSHIFTEQUAL: int +RIGHTSHIFTEQUAL: int +DOUBLESTAREQUAL: int +DOUBLESLASH: int +DOUBLESLASHEQUAL: int +OP: int +COMMENT: int +NL: int +if sys.version_info >= (3,): + RARROW: int +if sys.version_info >= (3, 5): + AT: int + ATEQUAL: int + AWAIT: int + ASYNC: int +ERRORTOKEN: int +N_TOKENS: int +NT_OFFSET: int +tok_name: Dict[int, Text] + +def ISTERMINAL(x: int) -> bool: ... +def ISNONTERMINAL(x: int) -> bool: ... +def ISEOF(x: int) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/tokenize.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/tokenize.pyi new file mode 100644 index 000000000..c10305ffd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pgen2/tokenize.pyi @@ -0,0 +1,30 @@ +# Stubs for lib2to3.pgen2.tokenize (Python 3.6) +# NOTE: Only elements from __all__ are present. + +from typing import Callable, Iterable, Iterator, List, Text, Tuple +from lib2to3.pgen2.token import * # noqa + + +_Coord = Tuple[int, int] +_TokenEater = Callable[[int, Text, _Coord, _Coord, Text], None] +_TokenInfo = Tuple[int, Text, _Coord, _Coord, Text] + + +class TokenError(Exception): ... +class StopTokenizing(Exception): ... + +def tokenize(readline: Callable[[], Text], tokeneater: _TokenEater = ...) -> None: ... + +class Untokenizer: + tokens: List[Text] + prev_row: int + prev_col: int + def __init__(self) -> None: ... + def add_whitespace(self, start: _Coord) -> None: ... + def untokenize(self, iterable: Iterable[_TokenInfo]) -> Text: ... + def compat(self, token: Tuple[int, Text], iterable: Iterable[_TokenInfo]) -> None: ... + +def untokenize(iterable: Iterable[_TokenInfo]) -> Text: ... +def generate_tokens( + readline: Callable[[], Text] +) -> Iterator[_TokenInfo]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pygram.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pygram.pyi new file mode 100644 index 000000000..aeb7b93bf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pygram.pyi @@ -0,0 +1,116 @@ +# Stubs for lib2to3.pygram (Python 3.6) + +from typing import Any +from lib2to3.pgen2.grammar import Grammar + +class Symbols: + def __init__(self, grammar: Grammar) -> None: ... + +class python_symbols(Symbols): + and_expr: int + and_test: int + annassign: int + arglist: int + argument: int + arith_expr: int + assert_stmt: int + async_funcdef: int + async_stmt: int + atom: int + augassign: int + break_stmt: int + classdef: int + comp_for: int + comp_if: int + comp_iter: int + comp_op: int + comparison: int + compound_stmt: int + continue_stmt: int + decorated: int + decorator: int + decorators: int + del_stmt: int + dictsetmaker: int + dotted_as_name: int + dotted_as_names: int + dotted_name: int + encoding_decl: int + eval_input: int + except_clause: int + exec_stmt: int + expr: int + expr_stmt: int + exprlist: int + factor: int + file_input: int + flow_stmt: int + for_stmt: int + funcdef: int + global_stmt: int + if_stmt: int + import_as_name: int + import_as_names: int + import_from: int + import_name: int + import_stmt: int + lambdef: int + listmaker: int + not_test: int + old_lambdef: int + old_test: int + or_test: int + parameters: int + pass_stmt: int + power: int + print_stmt: int + raise_stmt: int + return_stmt: int + shift_expr: int + simple_stmt: int + single_input: int + sliceop: int + small_stmt: int + star_expr: int + stmt: int + subscript: int + subscriptlist: int + suite: int + term: int + test: int + testlist: int + testlist1: int + testlist_gexp: int + testlist_safe: int + testlist_star_expr: int + tfpdef: int + tfplist: int + tname: int + trailer: int + try_stmt: int + typedargslist: int + varargslist: int + vfpdef: int + vfplist: int + vname: int + while_stmt: int + with_item: int + with_stmt: int + with_var: int + xor_expr: int + yield_arg: int + yield_expr: int + yield_stmt: int + +class pattern_symbols(Symbols): + Alternative: int + Alternatives: int + Details: int + Matcher: int + NegatedUnit: int + Repeater: int + Unit: int + +python_grammar: Grammar +python_grammar_no_print_statement: Grammar +pattern_grammar: Grammar diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pytree.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pytree.pyi new file mode 100644 index 000000000..06a7c1229 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/lib2to3/pytree.pyi @@ -0,0 +1,86 @@ +# Stubs for lib2to3.pytree (Python 3.6) + +import sys +from typing import Any, Callable, Dict, Iterator, List, Optional, Text, Tuple, TypeVar, Union + +from lib2to3.pgen2.grammar import Grammar + +_P = TypeVar('_P') +_NL = Union[Node, Leaf] +_Context = Tuple[Text, int, int] +_Results = Dict[Text, _NL] +_RawNode = Tuple[int, Text, _Context, Optional[List[_NL]]] +_Convert = Callable[[Grammar, _RawNode], Any] + +HUGE: int + +def type_repr(type_num: int) -> Text: ... + +class Base: + type: int + parent: Optional[Node] + prefix: Text + children: List[_NL] + was_changed: bool + was_checked: bool + def __eq__(self, other: Any) -> bool: ... + def _eq(self: _P, other: _P) -> bool: ... + def clone(self: _P) -> _P: ... + def post_order(self) -> Iterator[_NL]: ... + def pre_order(self) -> Iterator[_NL]: ... + def replace(self, new: Union[_NL, List[_NL]]) -> None: ... + def get_lineno(self) -> int: ... + def changed(self) -> None: ... + def remove(self) -> Optional[int]: ... + @property + def next_sibling(self) -> Optional[_NL]: ... + @property + def prev_sibling(self) -> Optional[_NL]: ... + def leaves(self) -> Iterator[Leaf]: ... + def depth(self) -> int: ... + def get_suffix(self) -> Text: ... + if sys.version_info < (3,): + def get_prefix(self) -> Text: ... + def set_prefix(self, prefix: Text) -> None: ... + +class Node(Base): + fixers_applied: List[Any] + def __init__(self, type: int, children: List[_NL], context: Optional[Any] = ..., prefix: Optional[Text] = ..., fixers_applied: Optional[List[Any]] = ...) -> None: ... + def set_child(self, i: int, child: _NL) -> None: ... + def insert_child(self, i: int, child: _NL) -> None: ... + def append_child(self, child: _NL) -> None: ... + +class Leaf(Base): + lineno: int + column: int + value: Text + fixers_applied: List[Any] + def __init__(self, type: int, value: Text, context: Optional[_Context] = ..., prefix: Optional[Text] = ..., fixers_applied: List[Any] = ...) -> None: ... + +def convert(gr: Grammar, raw_node: _RawNode) -> _NL: ... + +class BasePattern: + type: int + content: Optional[Text] + name: Optional[Text] + def optimize(self) -> BasePattern: ... # sic, subclasses are free to optimize themselves into different patterns + def match(self, node: _NL, results: Optional[_Results] = ...) -> bool: ... + def match_seq(self, nodes: List[_NL], results: Optional[_Results] = ...) -> bool: ... + def generate_matches(self, nodes: List[_NL]) -> Iterator[Tuple[int, _Results]]: ... + +class LeafPattern(BasePattern): + def __init__(self, type: Optional[int] = ..., content: Optional[Text] = ..., name: Optional[Text] = ...) -> None: ... + +class NodePattern(BasePattern): + wildcards: bool + def __init__(self, type: Optional[int] = ..., content: Optional[Text] = ..., name: Optional[Text] = ...) -> None: ... + +class WildcardPattern(BasePattern): + min: int + max: int + def __init__(self, content: Optional[Text] = ..., min: int = ..., max: int = ..., name: Optional[Text] = ...) -> None: ... + +class NegatedPattern(BasePattern): + def __init__(self, content: Optional[Text] = ...) -> None: ... + +def generate_matches(patterns: List[BasePattern], nodes: List[_NL]) -> Iterator[Tuple[int, _Results]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/linecache.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/linecache.pyi new file mode 100644 index 000000000..3f35f469e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/linecache.pyi @@ -0,0 +1,12 @@ +import sys +from typing import Any, Dict, List, Optional, Text + +_ModuleGlobals = Dict[str, Any] + +def getline(filename: Text, lineno: int, module_globals: Optional[_ModuleGlobals] = ...) -> str: ... +def clearcache() -> None: ... +def getlines(filename: Text, module_globals: Optional[_ModuleGlobals] = ...) -> List[str]: ... +def checkcache(filename: Optional[Text] = ...) -> None: ... +def updatecache(filename: Text, module_globals: Optional[_ModuleGlobals] = ...) -> List[str]: ... +if sys.version_info >= (3, 5): + def lazycache(filename: Text, module_globals: _ModuleGlobals) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/locale.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/locale.pyi new file mode 100644 index 000000000..431c87cd4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/locale.pyi @@ -0,0 +1,113 @@ +# Stubs for locale + +from decimal import Decimal +from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple, Union +import sys + +# workaround for mypy#2010 +if sys.version_info < (3,): + from __builtin__ import str as _str +else: + from builtins import str as _str + +CODESET = ... # type: int +D_T_FMT = ... # type: int +D_FMT = ... # type: int +T_FMT = ... # type: int +T_FMT_AMPM = ... # type: int + +DAY_1 = ... # type: int +DAY_2 = ... # type: int +DAY_3 = ... # type: int +DAY_4 = ... # type: int +DAY_5 = ... # type: int +DAY_6 = ... # type: int +DAY_7 = ... # type: int +ABDAY_1 = ... # type: int +ABDAY_2 = ... # type: int +ABDAY_3 = ... # type: int +ABDAY_4 = ... # type: int +ABDAY_5 = ... # type: int +ABDAY_6 = ... # type: int +ABDAY_7 = ... # type: int + +MON_1 = ... # type: int +MON_2 = ... # type: int +MON_3 = ... # type: int +MON_4 = ... # type: int +MON_5 = ... # type: int +MON_6 = ... # type: int +MON_7 = ... # type: int +MON_8 = ... # type: int +MON_9 = ... # type: int +MON_10 = ... # type: int +MON_11 = ... # type: int +MON_12 = ... # type: int +ABMON_1 = ... # type: int +ABMON_2 = ... # type: int +ABMON_3 = ... # type: int +ABMON_4 = ... # type: int +ABMON_5 = ... # type: int +ABMON_6 = ... # type: int +ABMON_7 = ... # type: int +ABMON_8 = ... # type: int +ABMON_9 = ... # type: int +ABMON_10 = ... # type: int +ABMON_11 = ... # type: int +ABMON_12 = ... # type: int + +RADIXCHAR = ... # type: int +THOUSEP = ... # type: int +YESEXPR = ... # type: int +NOEXPR = ... # type: int +CRNCYSTR = ... # type: int + +ERA = ... # type: int +ERA_D_T_FMT = ... # type: int +ERA_D_FMT = ... # type: int +ERA_T_FMT = ... # type: int + +ALT_DIGITS = ... # type: int + +LC_CTYPE = ... # type: int +LC_COLLATE = ... # type: int +LC_TIME = ... # type: int +LC_MONETARY = ... # type: int +LC_MESSAGES = ... # type: int +LC_NUMERIC = ... # type: int +LC_ALL = ... # type: int + +CHAR_MAX = ... # type: int + +class Error(Exception): ... + +def setlocale(category: int, + locale: Union[_str, Iterable[_str], None] = ...) -> _str: ... +def localeconv() -> Mapping[_str, Union[int, _str, List[int]]]: ... +def nl_langinfo(option: int) -> _str: ... +def getdefaultlocale(envvars: Tuple[_str, ...] = ...) -> Tuple[Optional[_str], Optional[_str]]: ... +def getlocale(category: int = ...) -> Sequence[_str]: ... +def getpreferredencoding(do_setlocale: bool = ...) -> _str: ... +def normalize(localename: _str) -> _str: ... +def resetlocale(category: int = ...) -> None: ... +def strcoll(string1: _str, string2: _str) -> int: ... +def strxfrm(string: _str) -> _str: ... +def format(format: _str, val: Union[float, Decimal], grouping: bool = ..., + monetary: bool = ...) -> _str: ... +if sys.version_info >= (3, 7): + def format_string(format: _str, val: Sequence[Any], + grouping: bool = ..., monetary: bool = ...) -> _str: ... +else: + def format_string(format: _str, val: Sequence[Any], + grouping: bool = ...) -> _str: ... +def currency(val: Union[int, float, Decimal], symbol: bool = ..., grouping: bool = ..., + international: bool = ...) -> _str: ... +if sys.version_info >= (3, 5): + def delocalize(string: _str) -> None: ... +def atof(string: _str) -> float: ... +def atoi(string: _str) -> int: ... +def str(float: float) -> _str: ... + +locale_alias: Dict[_str, _str] # undocumented +locale_encoding_alias: Dict[_str, _str] # undocumented +windows_locale: Dict[int, _str] # undocumented diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/__init__.pyi new file mode 100644 index 000000000..e840c2d57 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/__init__.pyi @@ -0,0 +1,419 @@ +# Stubs for logging (Python 3.4) + +from typing import ( + Any, Callable, Dict, Iterable, List, Mapping, MutableMapping, Optional, IO, + Tuple, Text, Union, overload, +) +from string import Template +from time import struct_time +from types import TracebackType +import sys +import threading + +_SysExcInfoType = Union[Tuple[type, BaseException, Optional[TracebackType]], + Tuple[None, None, None]] +if sys.version_info >= (3, 5): + _ExcInfoType = Union[None, bool, _SysExcInfoType, BaseException] +else: + _ExcInfoType = Union[None, bool, _SysExcInfoType] +_ArgsType = Union[Tuple[Any, ...], Dict[str, Any]] +_FilterType = Union['Filter', Callable[['LogRecord'], int]] +_Level = Union[int, Text] + +raiseExceptions: bool + +if sys.version_info >= (3,): + _levelToName = ... # type: Dict[int, str] + _nameToLevel = ... # type: Dict[str, int] +else: + _levelNames = ... # type: dict + +class Filterer(object): + filters = ... # type: List[Filter] + def __init__(self) -> None: ... + def addFilter(self, filter: Filter) -> None: ... + def removeFilter(self, filter: Filter) -> None: ... + def filter(self, record: 'LogRecord') -> bool: ... + +class Logger(Filterer): + name = ... # type: str + level = ... # type: int + parent = ... # type: Union[Logger, PlaceHolder] + propagate = ... # type: bool + handlers = ... # type: List[Handler] + disabled = ... # type: int + def __init__(self, name: str, level: _Level = ...) -> None: ... + def setLevel(self, lvl: Union[int, str]) -> None: ... + def isEnabledFor(self, lvl: int) -> bool: ... + def getEffectiveLevel(self) -> int: ... + def getChild(self, suffix: str) -> 'Logger': ... + if sys.version_info >= (3,): + def debug(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def info(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def warning(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def warn(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def error(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def critical(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def log(self, lvl: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def exception(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + else: + def debug(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def info(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def warning(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def warn(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def error(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def critical(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def log(self, + lvl: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def exception(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def addFilter(self, filt: _FilterType) -> None: ... + def removeFilter(self, filt: _FilterType) -> None: ... + def filter(self, record: 'LogRecord') -> bool: ... + def addHandler(self, hdlr: 'Handler') -> None: ... + def removeHandler(self, hdlr: 'Handler') -> None: ... + if sys.version_info >= (3,): + def findCaller(self, stack_info: bool = ...) -> Tuple[str, int, str, Optional[str]]: ... + else: + def findCaller(self) -> Tuple[str, int, str]: ... + def handle(self, record: 'LogRecord') -> None: ... + if sys.version_info >= (3,): + def makeRecord(self, name: str, lvl: int, fn: str, lno: int, msg: Any, + args: Mapping[str, Any], + exc_info: Optional[_SysExcInfoType], + func: Optional[str] = ..., + extra: Optional[Mapping[str, Any]] = ..., + sinfo: Optional[str] = ...) -> LogRecord: ... + else: + def makeRecord(self, + name: str, lvl: int, fn: str, lno: int, msg: Any, + args: Mapping[str, Any], + exc_info: Optional[_SysExcInfoType], + func: Optional[str] = ..., + extra: Optional[Mapping[str, Any]] = ...) -> LogRecord: ... + if sys.version_info >= (3,): + def hasHandlers(self) -> bool: ... + + +CRITICAL = ... # type: int +FATAL = ... # type: int +ERROR = ... # type: int +WARNING = ... # type: int +WARN = ... # type: int +INFO = ... # type: int +DEBUG = ... # type: int +NOTSET = ... # type: int + + +class Handler(Filterer): + level = ... # type: int + formatter = ... # type: Optional[Formatter] + lock = ... # type: Optional[threading.Lock] + def __init__(self, level: _Level = ...) -> None: ... + def createLock(self) -> None: ... + def acquire(self) -> None: ... + def release(self) -> None: ... + def setLevel(self, lvl: Union[int, str]) -> None: ... + def setFormatter(self, form: 'Formatter') -> None: ... + def addFilter(self, filt: _FilterType) -> None: ... + def removeFilter(self, filt: _FilterType) -> None: ... + def filter(self, record: 'LogRecord') -> bool: ... + def flush(self) -> None: ... + def close(self) -> None: ... + def handle(self, record: 'LogRecord') -> None: ... + def handleError(self, record: 'LogRecord') -> None: ... + def format(self, record: 'LogRecord') -> str: ... + def emit(self, record: 'LogRecord') -> None: ... + + +class Formatter: + converter = ... # type: Callable[[Optional[float]], struct_time] + _fmt = ... # type: Optional[str] + datefmt = ... # type: Optional[str] + if sys.version_info >= (3,): + _style = ... # type: PercentStyle + default_time_format = ... # type: str + default_msec_format = ... # type: str + + if sys.version_info >= (3,): + def __init__(self, fmt: Optional[str] = ..., + datefmt: Optional[str] =..., + style: str = ...) -> None: ... + else: + def __init__(self, + fmt: Optional[str] = ..., + datefmt: Optional[str] =...) -> None: ... + + def format(self, record: 'LogRecord') -> str: ... + def formatTime(self, record: 'LogRecord', datefmt: str = ...) -> str: ... + def formatException(self, exc_info: _SysExcInfoType) -> str: ... + if sys.version_info >= (3,): + def formatStack(self, stack_info: str) -> str: ... + + +class Filter: + def __init__(self, name: str = ...) -> None: ... + def filter(self, record: 'LogRecord') -> int: ... + + +class LogRecord: + args = ... # type: _ArgsType + asctime = ... # type: str + created = ... # type: int + exc_info = ... # type: Optional[_SysExcInfoType] + filename = ... # type: str + funcName = ... # type: str + levelname = ... # type: str + levelno = ... # type: int + lineno = ... # type: int + module = ... # type: str + msecs = ... # type: int + message = ... # type: str + msg = ... # type: str + name = ... # type: str + pathname = ... # type: str + process = ... # type: int + processName = ... # type: str + relativeCreated = ... # type: int + if sys.version_info >= (3,): + stack_info = ... # type: Optional[str] + thread = ... # type: int + threadName = ... # type: str + if sys.version_info >= (3,): + def __init__(self, name: str, level: int, pathname: str, lineno: int, + msg: Any, args: _ArgsType, + exc_info: Optional[_SysExcInfoType], + func: Optional[str] = ..., + sinfo: Optional[str] = ...) -> None: ... + else: + def __init__(self, + name: str, level: int, pathname: str, lineno: int, + msg: Any, args: _ArgsType, + exc_info: Optional[_SysExcInfoType], + func: Optional[str] = ...) -> None: ... + def getMessage(self) -> str: ... + + +class LoggerAdapter: + def __init__(self, logger: Logger, extra: Mapping[str, Any]) -> None: ... + def process(self, msg: Any, kwargs: MutableMapping[str, Any]) -> Tuple[Any, MutableMapping[str, Any]]: ... + if sys.version_info >= (3,): + def debug(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def info(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def warning(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def error(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def exception(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def critical(self, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def log(self, lvl: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + else: + def debug(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def info(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def warning(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def error(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def exception(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def critical(self, + msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def log(self, + lvl: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def isEnabledFor(self, lvl: int) -> bool: ... + if sys.version_info >= (3,): + def getEffectiveLevel(self) -> int: ... + def setLevel(self, lvl: Union[int, str]) -> None: ... + def hasHandlers(self) -> bool: ... + + +if sys.version_info >= (3,): + def getLogger(name: Optional[str] = ...) -> Logger: ... +else: + @overload + def getLogger() -> Logger: ... + @overload + def getLogger(name: Union[Text, str]) -> Logger: ... +def getLoggerClass() -> type: ... +if sys.version_info >= (3,): + def getLogRecordFactory() -> Callable[..., LogRecord]: ... + +if sys.version_info >= (3,): + def debug(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def info(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def warning(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def warn(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def error(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def critical(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def exception(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... + def log(lvl: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + stack_info: bool = ..., extra: Optional[Dict[str, Any]] = ..., + **kwargs: Any) -> None: ... +else: + def debug(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def info(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def warning(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def warn(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def error(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def critical(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def exception(msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... + def log(lvl: int, msg: Any, *args: Any, exc_info: _ExcInfoType = ..., + extra: Optional[Dict[str, Any]] = ..., **kwargs: Any) -> None: ... +fatal = critical + +def disable(lvl: int) -> None: ... +def addLevelName(lvl: int, levelName: str) -> None: ... +def getLevelName(lvl: int) -> str: ... + +def makeLogRecord(attrdict: Mapping[str, Any]) -> LogRecord: ... + +if sys.version_info >= (3,): + def basicConfig(*, filename: str = ..., filemode: str = ..., + format: str = ..., datefmt: str = ..., style: str = ..., + level: _Level = ..., stream: IO[str] = ..., + handlers: Iterable[Handler] = ...) -> None: ... +else: + @overload + def basicConfig() -> None: ... + @overload + def basicConfig(*, filename: str = ..., filemode: str = ..., + format: str = ..., datefmt: str = ..., + level: _Level = ..., stream: IO[str] = ...) -> None: ... +def shutdown() -> None: ... + +def setLoggerClass(klass: type) -> None: ... + +def captureWarnings(capture: bool) -> None: ... + +if sys.version_info >= (3,): + def setLogRecordFactory(factory: Callable[..., LogRecord]) -> None: ... + + +if sys.version_info >= (3,): + lastResort = ... # type: Optional['StreamHandler'] + + +class StreamHandler(Handler): + stream = ... # type: IO[str] + if sys.version_info >= (3,): + terminator = ... # type: str + def __init__(self, stream: Optional[IO[str]] = ...) -> None: ... + + +class FileHandler(Handler): + baseFilename = ... # type: str + mode = ... # type: str + encoding = ... # type: Optional[str] + delay = ... # type: bool + def __init__(self, filename: str, mode: str = ..., + encoding: Optional[str] = ..., delay: bool = ...) -> None: ... + + +class NullHandler(Handler): ... + + +class PlaceHolder: + def __init__(self, alogger: Logger) -> None: ... + def append(self, alogger: Logger) -> None: ... + + +# Below aren't in module docs but still visible + +class RootLogger(Logger): ... + +root = ... # type: RootLogger + + +if sys.version_info >= (3,): + class PercentStyle(object): + default_format = ... # type: str + asctime_format = ... # type: str + asctime_search = ... # type: str + _fmt = ... # type: str + + def __init__(self, fmt: str) -> None: ... + def usesTime(self) -> bool: ... + def format(self, record: Any) -> str: ... + + class StrFormatStyle(PercentStyle): + ... + + class StringTemplateStyle(PercentStyle): + _tpl = ... # type: Template + + _STYLES = ... # type: Dict[str, Tuple[PercentStyle, str]] + + +BASIC_FORMAT = ... # type: str diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/config.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/config.pyi new file mode 100644 index 000000000..dc5e19e02 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/config.pyi @@ -0,0 +1,23 @@ +# Stubs for logging.config (Python 3.4) + +from typing import Any, Callable, Dict, Optional, IO, Union +import sys +if sys.version_info >= (3,): + from configparser import RawConfigParser +else: + from ConfigParser import RawConfigParser + + +def dictConfig(config: Dict[str, Any]) -> None: ... +if sys.version_info >= (3, 4): + def fileConfig(fname: Union[str, IO[str], RawConfigParser], + defaults: Optional[Dict[str, str]] = ..., + disable_existing_loggers: bool = ...) -> None: ... + def listen(port: int = ..., + verify: Optional[Callable[[bytes], Optional[bytes]]] = ...) -> None: ... +else: + def fileConfig(fname: Union[str, IO[str]], + defaults: Optional[Dict[str, str]] = ..., + disable_existing_loggers: bool = ...) -> None: ... + def listen(port: int = ...) -> None: ... +def stopListening() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/handlers.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/handlers.pyi new file mode 100644 index 000000000..92fb3baf7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/logging/handlers.pyi @@ -0,0 +1,201 @@ +# Stubs for logging.handlers (Python 2.4) + +import datetime +from logging import Handler, FileHandler, LogRecord +from socket import SocketType +import ssl +import sys +from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload +if sys.version_info >= (3,): + from queue import Queue +else: + from Queue import Queue +# TODO update socket stubs to add SocketKind +_SocketKind = int + + +class WatchedFileHandler(Handler): + @overload + def __init__(self, filename: str) -> None: ... + @overload + def __init__(self, filename: str, mode: str) -> None: ... + @overload + def __init__(self, filename: str, mode: str, + encoding: Optional[str]) -> None: ... + @overload + def __init__(self, filename: str, mode: str, encoding: Optional[str], + delay: bool) -> None: ... + + +if sys.version_info >= (3,): + class BaseRotatingHandler(FileHandler): + terminator = ... # type: str + namer = ... # type: Optional[Callable[[str], str]] + rotator = ... # type: Optional[Callable[[str, str], None]] + def __init__(self, filename: str, mode: str, + encoding: Optional[str] = ..., + delay: bool = ...) -> None: ... + def rotation_filename(self, default_name: str) -> None: ... + def rotate(self, source: str, dest: str) -> None: ... + + +if sys.version_info >= (3,): + class RotatingFileHandler(BaseRotatingHandler): + def __init__(self, filename: str, mode: str = ..., maxBytes: int = ..., + backupCount: int = ..., encoding: Optional[str] = ..., + delay: bool = ...) -> None: ... + def doRollover(self) -> None: ... +else: + class RotatingFileHandler(Handler): + def __init__(self, filename: str, mode: str = ..., maxBytes: int = ..., + backupCount: int = ..., encoding: Optional[str] = ..., + delay: bool = ...) -> None: ... + def doRollover(self) -> None: ... + + +if sys.version_info >= (3,): + class TimedRotatingFileHandler(BaseRotatingHandler): + if sys.version_info >= (3, 4): + def __init__(self, filename: str, when: str = ..., + interval: int = ..., + backupCount: int = ..., encoding: Optional[str] = ..., + delay: bool = ..., utc: bool = ..., + atTime: Optional[datetime.datetime] = ...) -> None: ... + else: + def __init__(self, + filename: str, when: str = ..., interval: int = ..., + backupCount: int = ..., encoding: Optional[str] = ..., + delay: bool = ..., utc: bool = ...) -> None: ... + def doRollover(self) -> None: ... +else: + class TimedRotatingFileHandler: + def __init__(self, + filename: str, when: str = ..., interval: int = ..., + backupCount: int = ..., encoding: Optional[str] = ..., + delay: bool = ..., utc: bool = ...) -> None: ... + def doRollover(self) -> None: ... + + +class SocketHandler(Handler): + retryStart = ... # type: float + retryFactor = ... # type: float + retryMax = ... # type: float + if sys.version_info >= (3, 4): + def __init__(self, host: str, port: Optional[int]) -> None: ... + else: + def __init__(self, host: str, port: int) -> None: ... + def makeSocket(self) -> SocketType: ... + def makePickle(self, record: LogRecord) -> bytes: ... + def send(self, packet: bytes) -> None: ... + def createSocket(self) -> None: ... + + +class DatagramHandler(SocketHandler): ... + + +class SysLogHandler(Handler): + LOG_ALERT = ... # type: int + LOG_CRIT = ... # type: int + LOG_DEBUG = ... # type: int + LOG_EMERG = ... # type: int + LOG_ERR = ... # type: int + LOG_INFO = ... # type: int + LOG_NOTICE = ... # type: int + LOG_WARNING = ... # type: int + LOG_AUTH = ... # type: int + LOG_AUTHPRIV = ... # type: int + LOG_CRON = ... # type: int + LOG_DAEMON = ... # type: int + LOG_FTP = ... # type: int + LOG_KERN = ... # type: int + LOG_LPR = ... # type: int + LOG_MAIL = ... # type: int + LOG_NEWS = ... # type: int + LOG_SYSLOG = ... # type: int + LOG_USER = ... # type: int + LOG_UUCP = ... # type: int + LOG_LOCAL0 = ... # type: int + LOG_LOCAL1 = ... # type: int + LOG_LOCAL2 = ... # type: int + LOG_LOCAL3 = ... # type: int + LOG_LOCAL4 = ... # type: int + LOG_LOCAL5 = ... # type: int + LOG_LOCAL6 = ... # type: int + LOG_LOCAL7 = ... # type: int + def __init__(self, address: Union[Tuple[str, int], str] = ..., + facility: int = ..., socktype: _SocketKind = ...) -> None: ... + def encodePriority(self, facility: Union[int, str], + priority: Union[int, str]) -> int: ... + def mapPriority(self, levelName: int) -> str: ... + + +class NTEventLogHandler(Handler): + def __init__(self, appname: str, dllname: str = ..., + logtype: str = ...) -> None: ... + def getEventCategory(self, record: LogRecord) -> int: ... + # TODO correct return value? + def getEventType(self, record: LogRecord) -> int: ... + def getMessageID(self, record: LogRecord) -> int: ... + + +class SMTPHandler(Handler): + # TODO `secure` can also be an empty tuple + if sys.version_info >= (3,): + def __init__(self, mailhost: Union[str, Tuple[str, int]], fromaddr: str, + toaddrs: List[str], subject: str, + credentials: Optional[Tuple[str, str]] = ..., + secure: Union[Tuple[str], Tuple[str, str], None] =..., + timeout: float = ...) -> None: ... + else: + def __init__(self, + mailhost: Union[str, Tuple[str, int]], fromaddr: str, + toaddrs: List[str], subject: str, + credentials: Optional[Tuple[str, str]] = ..., + secure: Union[Tuple[str], Tuple[str, str], None] =...) -> None: ... + def getSubject(self, record: LogRecord) -> str: ... + + +class BufferingHandler(Handler): + def __init__(self, capacity: int) -> None: ... + def shouldFlush(self, record: LogRecord) -> bool: ... + +class MemoryHandler(BufferingHandler): + def __init__(self, capacity: int, flushLevel: int = ..., + target: Optional[Handler] =...) -> None: ... + def setTarget(self, target: Handler) -> None: ... + + +class HTTPHandler(Handler): + if sys.version_info >= (3, 5): + def __init__(self, host: str, url: str, method: str = ..., + secure: bool = ..., + credentials: Optional[Tuple[str, str]] = ..., + context: Optional[ssl.SSLContext] = ...) -> None: ... + elif sys.version_info >= (3,): + def __init__(self, + host: str, url: str, method: str = ..., secure: bool = ..., + credentials: Optional[Tuple[str, str]] = ...) -> None: ... + else: + def __init__(self, + host: str, url: str, method: str = ...) -> None: ... + def mapLogRecord(self, record: LogRecord) -> Dict[str, Any]: ... + + +if sys.version_info >= (3,): + class QueueHandler(Handler): + def __init__(self, queue: Queue) -> None: ... + def prepare(self, record: LogRecord) -> Any: ... + def enqueue(self, record: LogRecord) -> None: ... + + class QueueListener: + if sys.version_info >= (3, 5): + def __init__(self, queue: Queue, *handlers: Handler, + respect_handler_level: bool = ...) -> None: ... + else: + def __init__(self, + queue: Queue, *handlers: Handler) -> None: ... + def dequeue(self, block: bool) -> LogRecord: ... + def prepare(self, record: LogRecord) -> Any: ... + def start(self) -> None: ... + def stop(self) -> None: ... + def enqueue_sentinel(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/marshal.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/marshal.pyi new file mode 100644 index 000000000..eb2d57abd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/marshal.pyi @@ -0,0 +1,8 @@ +from typing import Any, IO + +version = ... # type: int + +def dump(value: Any, file: IO[Any], version: int = ...) -> None: ... +def load(file: IO[Any]) -> Any: ... +def dumps(value: Any, version: int = ...) -> str: ... +def loads(string: str) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/math.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/math.pyi new file mode 100644 index 000000000..6703fc5b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/math.pyi @@ -0,0 +1,71 @@ +# Stubs for math +# See: http://docs.python.org/2/library/math.html + +from typing import Tuple, Iterable, SupportsFloat, SupportsInt + +import sys + +e = ... # type: float +pi = ... # type: float +if sys.version_info >= (3, 5): + inf = ... # type: float + nan = ... # type: float +if sys.version_info >= (3, 6): + tau = ... # type: float + +def acos(x: SupportsFloat) -> float: ... +def acosh(x: SupportsFloat) -> float: ... +def asin(x: SupportsFloat) -> float: ... +def asinh(x: SupportsFloat) -> float: ... +def atan(x: SupportsFloat) -> float: ... +def atan2(y: SupportsFloat, x: SupportsFloat) -> float: ... +def atanh(x: SupportsFloat) -> float: ... +if sys.version_info >= (3,): + def ceil(x: SupportsFloat) -> int: ... +else: + def ceil(x: SupportsFloat) -> float: ... +def copysign(x: SupportsFloat, y: SupportsFloat) -> float: ... +def cos(x: SupportsFloat) -> float: ... +def cosh(x: SupportsFloat) -> float: ... +def degrees(x: SupportsFloat) -> float: ... +def erf(x: SupportsFloat) -> float: ... +def erfc(x: SupportsFloat) -> float: ... +def exp(x: SupportsFloat) -> float: ... +def expm1(x: SupportsFloat) -> float: ... +def fabs(x: SupportsFloat) -> float: ... +def factorial(x: SupportsInt) -> int: ... +if sys.version_info >= (3,): + def floor(x: SupportsFloat) -> int: ... +else: + def floor(x: SupportsFloat) -> float: ... +def fmod(x: SupportsFloat, y: SupportsFloat) -> float: ... +def frexp(x: SupportsFloat) -> Tuple[float, int]: ... +def fsum(iterable: Iterable) -> float: ... +def gamma(x: SupportsFloat) -> float: ... +if sys.version_info >= (3, 5): + def gcd(a: int, b: int) -> int: ... +def hypot(x: SupportsFloat, y: SupportsFloat) -> float: ... +if sys.version_info >= (3, 5): + def isclose(a: SupportsFloat, b: SupportsFloat, rel_tol: SupportsFloat = ..., abs_tol: SupportsFloat = ...) -> bool: ... +def isinf(x: SupportsFloat) -> bool: ... +if sys.version_info >= (3,): + def isfinite(x: SupportsFloat) -> bool: ... +def isnan(x: SupportsFloat) -> bool: ... +def ldexp(x: SupportsFloat, i: int) -> float: ... +def lgamma(x: SupportsFloat) -> float: ... +def log(x: SupportsFloat, base: SupportsFloat = ...) -> float: ... +def log10(x: SupportsFloat) -> float: ... +def log1p(x: SupportsFloat) -> float: ... +if sys.version_info >= (3, 3): + def log2(x: SupportsFloat) -> float: ... +def modf(x: SupportsFloat) -> Tuple[float, float]: ... +def pow(x: SupportsFloat, y: SupportsFloat) -> float: ... +def radians(x: SupportsFloat) -> float: ... +if sys.version_info >= (3, 7): + def remainder(x: SupportsFloat, y: SupportsFloat) -> float: ... +def sin(x: SupportsFloat) -> float: ... +def sinh(x: SupportsFloat) -> float: ... +def sqrt(x: SupportsFloat) -> float: ... +def tan(x: SupportsFloat) -> float: ... +def tanh(x: SupportsFloat) -> float: ... +def trunc(x: SupportsFloat) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/mimetypes.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/mimetypes.pyi new file mode 100644 index 000000000..493e612d2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/mimetypes.pyi @@ -0,0 +1,38 @@ +# Stubs for mimetypes + +from typing import Dict, IO, List, Optional, Sequence, Text, Tuple +import sys + +def guess_type(url: Text, + strict: bool = ...) -> Tuple[Optional[str], Optional[str]]: ... +def guess_all_extensions(type: str, strict: bool = ...) -> List[str]: ... +def guess_extension(type: str, strict: bool = ...) -> Optional[str]: ... + +def init(files: Optional[Sequence[str]] = ...) -> None: ... +def read_mime_types(filename: str) -> Optional[Dict[str, str]]: ... +def add_type(type: str, ext: str, strict: bool = ...) -> None: ... + +inited = ... # type: bool +knownfiles = ... # type: List[str] +suffix_map = ... # type: Dict[str, str] +encodings_map = ... # type: Dict[str, str] +types_map = ... # type: Dict[str, str] +common_types = ... # type: Dict[str, str] + +class MimeTypes: + suffix_map = ... # type: Dict[str, str] + encodings_map = ... # type: Dict[str, str] + types_map = ... # type: Tuple[Dict[str, str], Dict[str, str]] + types_map_inv = ... # type: Tuple[Dict[str, str], Dict[str, str]] + def __init__(self, filenames: Tuple[str, ...] = ..., + strict: bool = ...) -> None: ... + def guess_extension(self, type: str, + strict: bool = ...) -> Optional[str]: ... + def guess_type(self, url: str, + strict: bool = ...) -> Tuple[Optional[str], Optional[str]]: ... + def guess_all_extensions(self, type: str, + strict: bool = ...) -> List[str]: ... + def read(self, filename: str, strict: bool = ...) -> None: ... + def readfp(self, fp: IO[str], strict: bool = ...) -> None: ... + if sys.platform == 'win32': + def read_windows_registry(self, strict: bool = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/mmap.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/mmap.pyi new file mode 100644 index 000000000..bf5dafe19 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/mmap.pyi @@ -0,0 +1,67 @@ +import sys +from typing import (Optional, Sequence, Union, Generic, overload, + Iterable, Iterator, Sized, ContextManager, AnyStr) + +ACCESS_READ = ... # type: int +ACCESS_WRITE = ... # type: int +ACCESS_COPY = ... # type: int + +ALLOCATIONGRANULARITY = ... # type: int + +if sys.platform != 'win32': + MAP_PRIVATE = ... # type: int + MAP_SHARED = ... # type: int + PROT_READ = ... # type: int + PROT_WRITE = ... # type: int + + PAGESIZE = ... # type: int + +class _mmap(Generic[AnyStr]): + if sys.platform == 'win32': + def __init__(self, fileno: int, length: int, + tagname: Optional[str] = ..., access: int = ..., + offset: int = ...) -> None: ... + else: + def __init__(self, + fileno: int, length: int, flags: int = ..., + prot: int = ..., access: int = ..., + offset: int = ...) -> None: ... + def close(self) -> None: ... + def find(self, sub: AnyStr, + start: int = ..., end: int = ...) -> int: ... + def flush(self, offset: int = ..., size: int = ...) -> int: ... + def move(self, dest: int, src: int, count: int) -> None: ... + def read(self, n: int = ...) -> AnyStr: ... + def read_byte(self) -> AnyStr: ... + def readline(self) -> AnyStr: ... + def resize(self, newsize: int) -> None: ... + def seek(self, pos: int, whence: int = ...) -> None: ... + def size(self) -> int: ... + def tell(self) -> int: ... + def write(self, bytes: AnyStr) -> None: ... + def write_byte(self, byte: AnyStr) -> None: ... + def __len__(self) -> int: ... + +if sys.version_info >= (3,): + class mmap(_mmap, ContextManager[mmap], Iterable[bytes], Sized): + closed = ... # type: bool + def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ... + @overload + def __getitem__(self, index: int) -> int: ... + @overload + def __getitem__(self, index: slice) -> bytes: ... + def __delitem__(self, index: Union[int, slice]) -> None: ... + @overload + def __setitem__(self, index: int, object: int) -> None: ... + @overload + def __setitem__(self, index: slice, object: bytes) -> None: ... + # Doesn't actually exist, but the object is actually iterable because it has __getitem__ and + # __len__, so we claim that there is also an __iter__ to help type checkers. + def __iter__(self) -> Iterator[bytes]: ... +else: + class mmap(_mmap, Sequence[bytes]): + def rfind(self, string: bytes, start: int = ..., stop: int = ...) -> int: ... + def __getitem__(self, index: Union[int, slice]) -> bytes: ... + def __getslice__(self, i: Optional[int], j: Optional[int]) -> bytes: ... + def __delitem__(self, index: Union[int, slice]) -> None: ... + def __setitem__(self, index: Union[int, slice], object: bytes) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/netrc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/netrc.pyi new file mode 100644 index 000000000..3ceae8899 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/netrc.pyi @@ -0,0 +1,19 @@ +from typing import AnyStr, Dict, List, Optional, Tuple, overload + + +class NetrcParseError(Exception): + filename: Optional[str] + lineno: Optional[int] + msg: str + + +# (login, account, password) tuple +_NetrcTuple = Tuple[str, Optional[str], Optional[str]] + + +class netrc: + hosts: Dict[str, _NetrcTuple] + macros: Dict[str, List[str]] + + def __init__(self, file: str = ...) -> None: ... + def authenticators(self, host: str) -> Optional[_NetrcTuple]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/nis.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/nis.pyi new file mode 100644 index 000000000..87223caf2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/nis.pyi @@ -0,0 +1,10 @@ +import sys +from typing import Dict, List + +if sys.platform != 'win32': + def cat(map: str, domain: str = ...) -> Dict[str, str]: ... + def get_default_domain() -> str: ... + def maps(domain: str = ...) -> List[str]: ... + def match(key: str, map: str, domain: str = ...) -> str: ... + + class error(Exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/numbers.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/numbers.pyi new file mode 100644 index 000000000..b5fc580be --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/numbers.pyi @@ -0,0 +1,140 @@ +# Stubs for numbers (Python 3.5) +# See https://docs.python.org/2.7/library/numbers.html +# and https://docs.python.org/3/library/numbers.html +# +# Note: these stubs are incomplete. The more complex type +# signatures are currently omitted. + +from typing import Optional, SupportsFloat +from abc import ABCMeta, abstractmethod +import sys + +class Number(metaclass=ABCMeta): + @abstractmethod + def __hash__(self) -> int: ... + +class Complex(Number): + @abstractmethod + def __complex__(self) -> complex: ... + if sys.version_info >= (3, 0): + def __bool__(self) -> bool: ... + else: + def __nonzero__(self) -> bool: ... + @property + @abstractmethod + def real(self): ... + @property + @abstractmethod + def imag(self): ... + @abstractmethod + def __add__(self, other): ... + @abstractmethod + def __radd__(self, other): ... + @abstractmethod + def __neg__(self): ... + @abstractmethod + def __pos__(self): ... + def __sub__(self, other): ... + def __rsub__(self, other): ... + @abstractmethod + def __mul__(self, other): ... + @abstractmethod + def __rmul__(self, other): ... + if sys.version_info < (3, 0): + @abstractmethod + def __div__(self, other): ... + @abstractmethod + def __rdiv__(self, other): ... + @abstractmethod + def __truediv__(self, other): ... + @abstractmethod + def __rtruediv__(self, other): ... + @abstractmethod + def __pow__(self, exponent): ... + @abstractmethod + def __rpow__(self, base): ... + def __abs__(self): ... + def conjugate(self): ... + def __eq__(self, other: object) -> bool: ... + if sys.version_info < (3, 0): + def __ne__(self, other: object) -> bool: ... + +class Real(Complex, SupportsFloat): + @abstractmethod + def __float__(self) -> float: ... + @abstractmethod + def __trunc__(self) -> int: ... + if sys.version_info >= (3, 0): + @abstractmethod + def __floor__(self) -> int: ... + @abstractmethod + def __ceil__(self) -> int: ... + @abstractmethod + def __round__(self, ndigits: Optional[int] = ...): ... + def __divmod__(self, other): ... + def __rdivmod__(self, other): ... + @abstractmethod + def __floordiv__(self, other): ... + @abstractmethod + def __rfloordiv__(self, other): ... + @abstractmethod + def __mod__(self, other): ... + @abstractmethod + def __rmod__(self, other): ... + @abstractmethod + def __lt__(self, other) -> bool: ... + @abstractmethod + def __le__(self, other) -> bool: ... + def __complex__(self) -> complex: ... + @property + def real(self): ... + @property + def imag(self): ... + def conjugate(self): ... + +class Rational(Real): + @property + @abstractmethod + def numerator(self) -> int: ... + @property + @abstractmethod + def denominator(self) -> int: ... + def __float__(self) -> float: ... + +class Integral(Rational): + if sys.version_info >= (3, 0): + @abstractmethod + def __int__(self) -> int: ... + else: + @abstractmethod + def __long__(self) -> long: ... + def __index__(self) -> int: ... + @abstractmethod + def __pow__(self, exponent, modulus=None): ... + @abstractmethod + def __lshift__(self, other): ... + @abstractmethod + def __rlshift__(self, other): ... + @abstractmethod + def __rshift__(self, other): ... + @abstractmethod + def __rrshift__(self, other): ... + @abstractmethod + def __and__(self, other): ... + @abstractmethod + def __rand__(self, other): ... + @abstractmethod + def __xor__(self, other): ... + @abstractmethod + def __rxor__(self, other): ... + @abstractmethod + def __or__(self, other): ... + @abstractmethod + def __ror__(self, other): ... + @abstractmethod + def __invert__(self): ... + def __float__(self) -> float: ... + @property + def numerator(self) -> int: ... + @property + def denominator(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/opcode.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/opcode.pyi new file mode 100644 index 000000000..4cc1ab03d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/opcode.pyi @@ -0,0 +1,23 @@ +from typing import List, Dict, Optional, Sequence + +import sys + +cmp_op = ... # type: Sequence[str] +hasconst = ... # type: List[int] +hasname = ... # type: List[int] +hasjrel = ... # type: List[int] +hasjabs = ... # type: List[int] +haslocal = ... # type: List[int] +hascompare = ... # type: List[int] +hasfree = ... # type: List[int] +opname = ... # type: List[str] + +opmap = ... # type: Dict[str, int] +HAVE_ARGUMENT = ... # type: int +EXTENDED_ARG = ... # type: int + +if sys.version_info >= (3, 4): + def stack_effect(opcode: int, oparg: Optional[int] = ...) -> int: ... + +if sys.version_info >= (3, 6): + hasnargs = ... # type: List[int] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/operator.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/operator.pyi new file mode 100644 index 000000000..eafc37cb3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/operator.pyi @@ -0,0 +1,227 @@ +# Stubs for operator + +from typing import ( + Any, Callable, Container, Mapping, MutableMapping, MutableSequence, Sequence, SupportsAbs, Tuple, + TypeVar, overload, +) +import sys + + +_T = TypeVar('_T') +_K = TypeVar('_K') +_V = TypeVar('_V') + + +def lt(a: Any, b: Any) -> Any: ... +def le(a: Any, b: Any) -> Any: ... +def eq(a: Any, b: Any) -> Any: ... +def ne(a: Any, b: Any) -> Any: ... +def ge(a: Any, b: Any) -> Any: ... +def gt(a: Any, b: Any) -> Any: ... +def __lt__(a: Any, b: Any) -> Any: ... +def __le__(a: Any, b: Any) -> Any: ... +def __eq__(a: Any, b: Any) -> Any: ... +def __ne__(a: Any, b: Any) -> Any: ... +def __ge__(a: Any, b: Any) -> Any: ... +def __gt__(a: Any, b: Any) -> Any: ... + +def not_(obj: Any) -> bool: ... +def __not__(obj: Any) -> bool: ... + +def truth(x: Any) -> bool: ... + +def is_(a: Any, b: Any) -> bool: ... + +def is_not(a: Any, b: Any) -> bool: ... + +def abs(x: SupportsAbs) -> Any: ... +def __abs__(a: SupportsAbs) -> Any: ... + +def add(a: Any, b: Any) -> Any: ... +def __add__(a: Any, b: Any) -> Any: ... + +def and_(a: Any, b: Any) -> Any: ... +def __and__(a: Any, b: Any) -> Any: ... + +if sys.version_info < (3, ): + def div(a: Any, b: Any) -> Any: ... + def __div__(a: Any, b: Any) -> Any: ... + +def floordiv(a: Any, b: Any) -> Any: ... +def __floordiv__(a: Any, b: Any) -> Any: ... + +def index(a: Any) -> int: ... +def __index__(a: Any) -> int: ... + +def inv(obj: Any) -> Any: ... +def invert(obj: Any) -> Any: ... +def __inv__(obj: Any) -> Any: ... +def __invert__(obj: Any) -> Any: ... + +def lshift(a: Any, b: Any) -> Any: ... +def __lshift__(a: Any, b: Any) -> Any: ... + +def mod(a: Any, b: Any) -> Any: ... +def __mod__(a: Any, b: Any) -> Any: ... + +def mul(a: Any, b: Any) -> Any: ... +def __mul__(a: Any, b: Any) -> Any: ... + +if sys.version_info >= (3, 5): + def matmul(a: Any, b: Any) -> Any: ... + def __matmul__(a: Any, b: Any) -> Any: ... + +def neg(obj: Any) -> Any: ... +def __neg__(obj: Any) -> Any: ... + +def or_(a: Any, b: Any) -> Any: ... +def __or__(a: Any, b: Any) -> Any: ... + +def pos(obj: Any) -> Any: ... +def __pos__(obj: Any) -> Any: ... + +def pow(a: Any, b: Any) -> Any: ... +def __pow__(a: Any, b: Any) -> Any: ... + +def rshift(a: Any, b: Any) -> Any: ... +def __rshift__(a: Any, b: Any) -> Any: ... + +def sub(a: Any, b: Any) -> Any: ... +def __sub__(a: Any, b: Any) -> Any: ... + +def truediv(a: Any, b: Any) -> Any: ... +def __truediv__(a: Any, b: Any) -> Any: ... + +def xor(a: Any, b: Any) -> Any: ... +def __xor__(a: Any, b: Any) -> Any: ... + +def concat(a: Sequence[_T], b: Sequence[_T]) -> Sequence[_T]: ... +def __concat__(a: Sequence[_T], b: Sequence[_T]) -> Sequence[_T]: ... + +def contains(a: Container[Any], b: Any) -> bool: ... +def __contains__(a: Container[Any], b: Any) -> bool: ... + +def countOf(a: Container[Any], b: Any) -> int: ... + +@overload +def delitem(a: MutableSequence[_T], b: int) -> None: ... +@overload +def delitem(a: MutableMapping[_K, _V], b: _K) -> None: ... +@overload +def __delitem__(a: MutableSequence[_T], b: int) -> None: ... +@overload +def __delitem__(a: MutableMapping[_K, _V], b: _K) -> None: ... + +if sys.version_info < (3, ): + def delslice(a: MutableSequence[Any], b: int, c: int) -> None: ... + def __delslice__(a: MutableSequence[Any], b: int, c: int) -> None: ... + +@overload +def getitem(a: Sequence[_T], b: int) -> _T: ... +@overload +def getitem(a: Mapping[_K, _V], b: _K) -> _V: ... +@overload +def __getitem__(a: Sequence[_T], b: int) -> _T: ... +@overload +def __getitem__(a: Mapping[_K, _V], b: _K) -> _V: ... + +if sys.version_info < (3, ): + def getslice(a: Sequence[_T], b: int, c: int) -> Sequence[_T]: ... + def __getslice__(a: Sequence[_T], b: int, c: int) -> Sequence[_T]: ... + +def indexOf(a: Sequence[_T], b: _T) -> int: ... + +if sys.version_info < (3, ): + def repeat(a: Any, b: int) -> Any: ... + def __repeat__(a: Any, b: int) -> Any: ... + +if sys.version_info < (3, ): + def sequenceIncludes(a: Container[Any], b: Any) -> bool: ... + +@overload +def setitem(a: MutableSequence[_T], b: int, c: _T) -> None: ... +@overload +def setitem(a: MutableMapping[_K, _V], b: _K, c: _V) -> None: ... +@overload +def __setitem__(a: MutableSequence[_T], b: int, c: _T) -> None: ... +@overload +def __setitem__(a: MutableMapping[_K, _V], b: _K, c: _V) -> None: ... + +if sys.version_info < (3, ): + def setslice(a: MutableSequence[_T], b: int, c: int, v: Sequence[_T]) -> None: ... + def __setslice__(a: MutableSequence[_T], b: int, c: int, v: Sequence[_T]) -> None: ... + + +if sys.version_info >= (3, 4): + def length_hint(obj: Any, default: int = ...) -> int: ... + +@overload +def attrgetter(attr: str) -> Callable[[Any], Any]: ... +@overload +def attrgetter(*attrs: str) -> Callable[[Any], Tuple[Any, ...]]: ... + +@overload +def itemgetter(item: Any) -> Callable[[Any], Any]: ... +@overload +def itemgetter(*items: Any) -> Callable[[Any], Tuple[Any, ...]]: ... + +def methodcaller(name: str, *args: Any, **kwargs: Any) -> Callable[..., Any]: ... + + +def iadd(a: Any, b: Any) -> Any: ... +def __iadd__(a: Any, b: Any) -> Any: ... + +def iand(a: Any, b: Any) -> Any: ... +def __iand__(a: Any, b: Any) -> Any: ... + +def iconcat(a: Any, b: Any) -> Any: ... +def __iconcat__(a: Any, b: Any) -> Any: ... + +if sys.version_info < (3, ): + def idiv(a: Any, b: Any) -> Any: ... + def __idiv__(a: Any, b: Any) -> Any: ... + +def ifloordiv(a: Any, b: Any) -> Any: ... +def __ifloordiv__(a: Any, b: Any) -> Any: ... + +def ilshift(a: Any, b: Any) -> Any: ... +def __ilshift__(a: Any, b: Any) -> Any: ... + +def imod(a: Any, b: Any) -> Any: ... +def __imod__(a: Any, b: Any) -> Any: ... + +def imul(a: Any, b: Any) -> Any: ... +def __imul__(a: Any, b: Any) -> Any: ... + +if sys.version_info >= (3, 5): + def imatmul(a: Any, b: Any) -> Any: ... + def __imatmul__(a: Any, b: Any) -> Any: ... + +def ior(a: Any, b: Any) -> Any: ... +def __ior__(a: Any, b: Any) -> Any: ... + +def ipow(a: Any, b: Any) -> Any: ... +def __ipow__(a: Any, b: Any) -> Any: ... + +if sys.version_info < (3, ): + def irepeat(a: Any, b: int) -> Any: ... + def __irepeat__(a: Any, b: int) -> Any: ... + +def irshift(a: Any, b: Any) -> Any: ... +def __irshift__(a: Any, b: Any) -> Any: ... + +def isub(a: Any, b: Any) -> Any: ... +def __isub__(a: Any, b: Any) -> Any: ... + +def itruediv(a: Any, b: Any) -> Any: ... +def __itruediv__(a: Any, b: Any) -> Any: ... + +def ixor(a: Any, b: Any) -> Any: ... +def __ixor__(a: Any, b: Any) -> Any: ... + + +if sys.version_info < (3, ): + def isCallable(x: Any) -> bool: ... + def isMappingType(x: Any) -> bool: ... + def isNumberType(x: Any) -> bool: ... + def isSequenceType(x: Any) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/optparse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/optparse.pyi new file mode 100644 index 000000000..03532d910 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/optparse.pyi @@ -0,0 +1,227 @@ +# Generated by pytype, with only minor tweaks. Might be incomplete. +import sys +from typing import Any, Callable, Dict, IO, Iterable, List, Mapping, Optional, Sequence, Tuple, Union + +# See https://groups.google.com/forum/#!topic/python-ideas/gA1gdj3RZ5g +if sys.version_info >= (3,): + _Text = str +else: + _Text = Union[str, unicode] + +NO_DEFAULT = ... # type: Tuple[_Text, ...] +SUPPRESS_HELP = ... # type: _Text +SUPPRESS_USAGE = ... # type: _Text + +def check_builtin(option: Option, opt: Any, value: _Text) -> Any: ... +def check_choice(option: Option, opt: Any, value: _Text) -> Any: ... +if sys.version_info < (3,): + def isbasestring(x: Any) -> bool: ... + +class OptParseError(Exception): + msg = ... # type: _Text + def __init__(self, msg: _Text) -> None: ... + +class BadOptionError(OptParseError): + opt_str = ... # type: _Text + def __init__(self, opt_str: _Text) -> None: ... + +class AmbiguousOptionError(BadOptionError): + possibilities = ... # type: Iterable[_Text] + def __init__(self, opt_str: _Text, possibilities: Sequence[_Text]) -> None: ... + +class OptionError(OptParseError): + msg = ... # type: _Text + option_id = ... # type: _Text + def __init__(self, msg: _Text, option: Option) -> None: ... + +class OptionConflictError(OptionError): ... + +class OptionValueError(OptParseError): ... + + +class HelpFormatter: + NO_DEFAULT_VALUE = ... # type: _Text + _long_opt_fmt = ... # type: _Text + _short_opt_fmt = ... # type: _Text + current_indent = ... # type: int + default_tag = ... # type: _Text + help_position = ... # type: Any + help_width = ... # type: Any + indent_increment = ... # type: int + level = ... # type: int + max_help_position = ... # type: int + option_strings = ... # type: Dict[Option, _Text] + parser = ... # type: OptionParser + short_first = ... # type: Any + width = ... # type: int + def __init__(self, indent_increment: int, max_help_position: int, width: Optional[int], short_first: int) -> None: ... + def _format__Text(self, _Text: _Text) -> _Text: ... + def dedent(self) -> None: ... + def expand_default(self, option: Option) -> _Text: ... + def format_description(self, description: _Text) -> _Text: ... + def format_epilog(self, epilog) -> _Text: ... + def format_heading(self, heading: Any) -> _Text: ... + def format_option(self, option: OptionParser) -> _Text: ... + def format_option_strings(self, option: OptionParser) -> Any: ... + def format_usage(self, usage: Any) -> _Text: ... + def indent(self) -> None: ... + def set_long_opt_delimiter(self, delim: _Text) -> None: ... + def set_parser(self, parser: OptionParser) -> None: ... + def set_short_opt_delimiter(self, delim: _Text) -> None: ... + def store_option_strings(self, parser: OptionParser) -> None: ... + +class IndentedHelpFormatter(HelpFormatter): + def __init__(self, + indent_increment: int = ..., + max_help_position: int = ..., + width: Optional[int] = ..., + short_first: int = ...) -> None: ... + def format_heading(self, heading: _Text) -> _Text: ... + def format_usage(self, usage: _Text) -> _Text: ... + +class TitledHelpFormatter(HelpFormatter): + def __init__(self, + indent_increment: int = ..., + max_help_position: int = ..., + width: Optional[int] = ..., + short_first: int = ...) -> None: ... + def format_heading(self, heading: _Text) -> _Text: ... + def format_usage(self, usage: _Text) -> _Text: ... + +class Option: + ACTIONS = ... # type: Tuple[_Text, ...] + ALWAYS_TYPED_ACTIONS = ... # type: Tuple[_Text, ...] + ATTRS = ... # type: List[_Text] + CHECK_METHODS = ... # type: Optional[List[Callable]] + CONST_ACTIONS = ... # type: Tuple[_Text, ...] + STORE_ACTIONS = ... # type: Tuple[_Text, ...] + TYPED_ACTIONS = ... # type: Tuple[_Text, ...] + TYPES = ... # type: Tuple[_Text, ...] + TYPE_CHECKER = ... # type: Dict[_Text, Callable] + _long_opts = ... # type: List[_Text] + _short_opts = ... # type: List[_Text] + action = ... # type: _Text + dest = ... # type: Any + nargs = ... # type: int + type = ... # type: Any + def __init__(self, *opts, **attrs) -> None: ... + def _check_action(self) -> None: ... + def _check_callback(self) -> None: ... + def _check_choice(self) -> None: ... + def _check_const(self) -> None: ... + def _check_dest(self) -> None: ... + def _check_nargs(self) -> None: ... + def _check_opt_strings(self, opts: Optional[_Text]) -> Any: ... + def _check_type(self) -> None: ... + def _set_attrs(self, attrs: Dict[_Text, Any]) -> None: ... + def _set_opt_strings(self, opts: _Text) -> None: ... + def check_value(self, opt: Any, value: Any) -> Any: ... + def convert_value(self, opt: Any, value: Any) -> Any: ... + def get_opt_string(self) -> _Text: ... + def process(self, opt: Any, value: Any, values: Any, parser: OptionParser) -> int: ... + def take_action(self, action: _Text, dest: _Text, opt: Any, value: Any, values: Any, parser: OptionParser) -> int: ... + def takes_value(self) -> bool: ... + +make_option = Option + +class OptionContainer: + _long_opt = ... # type: Dict[_Text, Option] + _short_opt = ... # type: Dict[_Text, Option] + conflict_handler = ... # type: _Text + defaults = ... # type: Dict[_Text, Any] + description = ... # type: Any + option_class = ... # type: Any + def __init__(self, option_class: Option, conflict_handler: Any, description: Any) -> None: ... + def _check_conflict(self, option: Any) -> None: ... + def _create_option_mappings(self) -> None: ... + def _share_option_mappings(self, parser: OptionParser) -> None: ... + def add_option(self, *args, **kwargs) -> Any: ... + def add_options(self, option_list: Iterable[Option]) -> None: ... + def destroy(self) -> None: ... + def format_description(self, formatter: Optional[HelpFormatter]) -> Any: ... + def format_help(self, formatter: Optional[HelpFormatter]) -> _Text: ... + def format_option_help(self, formatter: Optional[HelpFormatter]) -> _Text: ... + def get_description(self) -> Any: ... + def get_option(self, opt_str: _Text) -> Optional[Option]: ... + def has_option(self, opt_str: _Text) -> bool: ... + def remove_option(self, opt_str: _Text) -> None: ... + def set_conflict_handler(self, handler: Any) -> None: ... + def set_description(self, description: Any) -> None: ... + +class OptionGroup(OptionContainer): + option_list = ... # type: List[Option] + parser = ... # type: OptionParser + title = ... # type: _Text + def __init__(self, parser: OptionParser, title: _Text, description: Optional[_Text] = ...) -> None: ... + def _create_option_list(self) -> None: ... + def set_title(self, title: _Text) -> None: ... + +class OptionParser(OptionContainer): + allow_interspersed_args = ... # type: bool + epilog = ... # type: Any + formatter = ... # type: HelpFormatter + largs = ... # type: Optional[List[_Text]] + option_groups = ... # type: List[OptionParser] + option_list = ... # type: List[Any] + process_default_values = ... # type: Any + prog = ... # type: Any + rargs = ... # type: Optional[List[Any]] + standard_option_list = ... # type: List + usage = ... # type: Optional[_Text] + values = ... # type: Any + version = ... # type: _Text + def __init__(self, usage: Optional[_Text] = ..., + option_list: Iterable[Option] = ..., + option_class: Option = ..., + version: Optional[_Text] = ..., + conflict_handler: _Text = ..., + description: Optional[_Text] = ..., + formatter: Optional[HelpFormatter] = ..., + add_help_option: bool = ..., + prog: Optional[_Text] = ..., + epilog: Optional[_Text] = ...) -> None: ... + def _add_help_option(self) -> None: ... + def _add_version_option(self) -> None: ... + def _create_option_list(self) -> None: ... + def _get_all_options(self) -> List[Any]: ... + def _get_args(self, args: Iterable) -> List[Any]: ... + def _init_parsing_state(self) -> None: ... + def _match_long_opt(self, opt: _Text) -> _Text: ... + def _populate_option_list(self, option_list: Iterable[Option], add_help: bool = ...) -> None: ... + def _process_args(self, largs: List, rargs: List, values: Values) -> None: ... + def _process_long_opt(self, rargs: List, values: Any) -> None: ... + def _process_short_opts(self, rargs: List, values: Any) -> None: ... + def add_option_group(self, *args, **kwargs) -> OptionParser: ... + def check_values(self, values: Any, args) -> Tuple[Any, ...]: ... + def disable_interspersed_args(self) -> None: ... + def enable_interspersed_args(self) -> None: ... + def error(self, msg: _Text) -> None: ... + def exit(self, status: int = ..., msg: Optional[str] = ...) -> None: ... + def expand_prog_name(self, s: Optional[_Text]) -> Any: ... + def format_epilog(self, formatter: HelpFormatter) -> Any: ... + def format_help(self, formatter: Optional[HelpFormatter] = ...) -> _Text: ... + def format_option_help(self, formatter: Optional[HelpFormatter] = ...) -> _Text: ... + def get_default_values(self) -> Values: ... + def get_option_group(self, opt_str: _Text) -> Any: ... + def get_prog_name(self) -> _Text: ... + def get_usage(self) -> _Text: ... + def get_version(self) -> _Text: ... + def parse_args(self, args: Optional[Sequence[_Text]] = ..., values: Optional[Values] = ...) -> Tuple[Any, ...]: ... + def print_usage(self, file: Optional[IO[str]] = ...) -> None: ... + def print_help(self, file: Optional[IO[str]] = ...) -> None: ... + def print_version(self, file: Optional[IO[str]] = ...) -> None: ... + def set_default(self, dest: Any, value: Any) -> None: ... + def set_defaults(self, **kwargs) -> None: ... + def set_process_default_values(self, process: Any) -> None: ... + def set_usage(self, usage: _Text) -> None: ... + + +class Values: + def __init__(self, defaults: Optional[Mapping[str, Any]] = ...) -> None: ... + def _update(self, dict: Dict[_Text, Any], mode: Any) -> None: ... + def _update_careful(self, dict: Dict[_Text, Any]) -> None: ... + def _update_loose(self, dict: Dict[_Text, Any]) -> None: ... + def ensure_value(self, attr: Any, value: Any) -> Any: ... + def read_file(self, filename: _Text, mode: _Text) -> None: ... + def read_module(self, modname: _Text, mode: _Text) -> None: ... + def __getattr__(self, name: str) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pdb.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pdb.pyi new file mode 100644 index 000000000..f70a9a439 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pdb.pyi @@ -0,0 +1,19 @@ +# NOTE: This stub is incomplete - only contains some global functions + +import sys +from typing import Any, Dict, Optional + +def run(statement: str, globals: Optional[Dict[str, Any]] = ..., + locals: Optional[Dict[str, Any]] = ...) -> None: ... +def runeval(expression: str, globals: Optional[Dict[str, Any]] = ..., + locals: Optional[Dict[str, Any]] = ...) -> Any: ... +def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> None: ... +def runcall(*args: Any, **kwds: Any) -> Any: ... + +if sys.version_info >= (3, 7): + def set_trace(*, header: Optional[str] = ...) -> None: ... +else: + def set_trace() -> None: ... + +def post_mortem(t: Optional[Any] = ...) -> None: ... +def pm() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pickle.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pickle.pyi new file mode 100644 index 000000000..7bfad8f3b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pickle.pyi @@ -0,0 +1,140 @@ +import sys +from typing import Any, IO, Mapping, Union, Tuple, Callable, Optional, Iterator + +HIGHEST_PROTOCOL: int +if sys.version_info >= (3, 0): + DEFAULT_PROTOCOL: int + + +if sys.version_info >= (3, 0): + def dump(obj: Any, file: IO[bytes], protocol: Optional[int] = ..., *, + fix_imports: bool = ...) -> None: ... + def dumps(obj: Any, protocol: Optional[int] = ..., *, + fix_imports: bool = ...) -> bytes: ... + def loads(bytes_object: bytes, *, fix_imports: bool = ..., + encoding: str = ..., errors: str = ...) -> Any: ... + def load(file: IO[bytes], *, fix_imports: bool = ..., encoding: str = ..., + errors: str = ...) -> Any: ... +else: + def dump(obj: Any, file: IO[bytes], protocol: Optional[int] = ...) -> None: ... + def dumps(obj: Any, protocol: Optional[int] = ...) -> bytes: ... + def load(file: IO[bytes]) -> Any: ... + def loads(string: bytes) -> Any: ... + +class PickleError(Exception): ... +class PicklingError(PickleError): ... +class UnpicklingError(PickleError): ... + +_reducedtype = Union[str, + Tuple[Callable[..., Any], Tuple], + Tuple[Callable[..., Any], Tuple, Any], + Tuple[Callable[..., Any], Tuple, Any, + Optional[Iterator]], + Tuple[Callable[..., Any], Tuple, Any, + Optional[Iterator], Optional[Iterator]]] + + +class Pickler: + fast: bool + if sys.version_info >= (3, 3): + dispatch_table: Mapping[type, Callable[[Any], _reducedtype]] + + if sys.version_info >= (3, 0): + def __init__(self, file: IO[bytes], protocol: Optional[int] = ..., *, + fix_imports: bool = ...) -> None: ... + else: + def __init__(self, file: IO[bytes], protocol: Optional[int] = ...) -> None: ... + + def dump(self, obj: Any) -> None: ... + def clear_memo(self) -> None: ... + def persistent_id(self, obj: Any) -> Any: ... + + +class Unpickler: + if sys.version_info >= (3, 0): + def __init__(self, file: IO[bytes], *, fix_imports: bool = ..., + encoding: str = ..., errors: str = ...) -> None: ... + else: + def __init__(self, file: IO[bytes]) -> None: ... + + def load(self) -> Any: ... + def find_class(self, module: str, name: str) -> Any: ... + if sys.version_info >= (3, 0): + def persistent_load(self, pid: Any) -> Any: ... + +MARK: bytes +STOP: bytes +POP: bytes +POP_MARK: bytes +DUP: bytes +FLOAT: bytes +INT: bytes +BININT: bytes +BININT1: bytes +LONG: bytes +BININT2: bytes +NONE: bytes +PERSID: bytes +BINPERSID: bytes +REDUCE: bytes +STRING: bytes +BINSTRING: bytes +SHORT_BINSTRING: bytes +UNICODE: bytes +BINUNICODE: bytes +APPEND: bytes +BUILD: bytes +GLOBAL: bytes +DICT: bytes +EMPTY_DICT: bytes +APPENDS: bytes +GET: bytes +BINGET: bytes +INST: bytes +LONG_BINGET: bytes +LIST: bytes +EMPTY_LIST: bytes +OBJ: bytes +PUT: bytes +BINPUT: bytes +LONG_BINPUT: bytes +SETITEM: bytes +TUPLE: bytes +EMPTY_TUPLE: bytes +SETITEMS: bytes +BINFLOAT: bytes + +TRUE: bytes +FALSE: bytes + +# protocol 2 +PROTO: bytes +NEWOBJ: bytes +EXT1: bytes +EXT2: bytes +EXT4: bytes +TUPLE1: bytes +TUPLE2: bytes +TUPLE3: bytes +NEWTRUE: bytes +NEWFALSE: bytes +LONG1: bytes +LONG4: bytes + +if sys.version_info >= (3, 0): + # protocol 3 + BINBYTES: bytes + SHORT_BINBYTES: bytes + +if sys.version_info >= (3, 4): + # protocol 4 + SHORT_BINUNICODE: bytes + BINUNICODE8: bytes + BINBYTES8: bytes + EMPTY_SET: bytes + ADDITEMS: bytes + FROZENSET: bytes + NEWOBJ_EX: bytes + STACK_GLOBAL: bytes + MEMOIZE: bytes + FRAME: bytes diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pickletools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pickletools.pyi new file mode 100644 index 000000000..c03664697 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pickletools.pyi @@ -0,0 +1,145 @@ +# Stubs for pickletools (Python 2 and 3) +import sys +from typing import Any, Callable, IO, Iterator, List, MutableMapping, Optional, Text, Tuple, Type, Union + +_Reader = Callable[[IO[bytes]], Any] + +if sys.version_info >= (3, 0): + bytes_types: Tuple[Type[Any], ...] + +UP_TO_NEWLINE: int +TAKEN_FROM_ARGUMENT1: int +TAKEN_FROM_ARGUMENT4: int +if sys.version_info >= (3, 3): + TAKEN_FROM_ARGUMENT4U: int +if sys.version_info >= (3, 4): + TAKEN_FROM_ARGUMENT8U: int + +class ArgumentDescriptor(object): + name: str + n: int + reader: _Reader + doc: str + def __init__(self, name: str, n: int, reader: _Reader, doc: str) -> None: ... + +def read_uint1(f: IO[bytes]) -> int: ... +uint1: ArgumentDescriptor + +def read_uint2(f: IO[bytes]) -> int: ... +uint2: ArgumentDescriptor + +def read_int4(f: IO[bytes]) -> int: ... +int4: ArgumentDescriptor + +if sys.version_info >= (3, 3): + def read_uint4(f: IO[bytes]) -> int: ... + uint4: ArgumentDescriptor + +if sys.version_info >= (3, 5): + def read_uint8(f: IO[bytes]) -> int: ... + uint8: ArgumentDescriptor + +def read_stringnl(f: IO[bytes], decode: bool = ..., stripquotes: bool = ...) -> Union[bytes, Text]: ... +stringnl: ArgumentDescriptor + +def read_stringnl_noescape(f: IO[bytes]) -> str: ... +stringnl_noescape: ArgumentDescriptor + +def read_stringnl_noescape_pair(f: IO[bytes]) -> Text: ... +stringnl_noescape_pair: ArgumentDescriptor + +def read_string1(f: IO[bytes]) -> str: ... +string1: ArgumentDescriptor + +def read_string4(f: IO[bytes]) -> str: ... +string4: ArgumentDescriptor + +if sys.version_info >= (3, 3): + def read_bytes1(f: IO[bytes]) -> bytes: ... + bytes1: ArgumentDescriptor + + def read_bytes4(f: IO[bytes]) -> bytes: ... + bytes4: ArgumentDescriptor + +if sys.version_info >= (3, 4): + def read_bytes8(f: IO[bytes]) -> bytes: ... + bytes8: ArgumentDescriptor + +def read_unicodestringnl(f: IO[bytes]) -> Text: ... +unicodestringnl: ArgumentDescriptor + +if sys.version_info >= (3, 4): + def read_unicodestring1(f: IO[bytes]) -> Text: ... + unicodestring1: ArgumentDescriptor + +def read_unicodestring4(f: IO[bytes]) -> Text: ... +unicodestring4: ArgumentDescriptor + +if sys.version_info >= (3, 4): + def read_unicodestring8(f: IO[bytes]) -> Text: ... + unicodestring8: ArgumentDescriptor + +def read_decimalnl_short(f: IO[bytes]) -> int: ... +def read_decimalnl_long(f: IO[bytes]) -> int: ... +decimalnl_short: ArgumentDescriptor +decimalnl_long: ArgumentDescriptor + +def read_floatnl(f: IO[bytes]) -> float: ... +floatnl: ArgumentDescriptor + +def read_float8(f: IO[bytes]) -> float: ... +float8: ArgumentDescriptor + +def read_long1(f: IO[bytes]) -> int: ... +long1: ArgumentDescriptor + +def read_long4(f: IO[bytes]) -> int: ... +long4: ArgumentDescriptor + +class StackObject(object): + name: str + obtype: Union[Type[Any], Tuple[Type[Any], ...]] + doc: str + def __init__(self, name: str, obtype: Union[Type[Any], Tuple[Type[Any], ...]], doc: str) -> None: ... + +pyint: StackObject +pylong: StackObject +pyinteger_or_bool: StackObject +pybool: StackObject +pyfloat: StackObject +if sys.version_info >= (3, 4): + pybytes_or_str: StackObject +pystring: StackObject +if sys.version_info >= (3, 0): + pybytes: StackObject +pyunicode: StackObject +pynone: StackObject +pytuple: StackObject +pylist: StackObject +pydict: StackObject +if sys.version_info >= (3, 4): + pyset: StackObject + pyfrozenset: StackObject +anyobject: StackObject +markobject: StackObject +stackslice: StackObject + +class OpcodeInfo(object): + name: str + code: str + arg: Optional[ArgumentDescriptor] + stack_before: List[StackObject] + stack_after: List[StackObject] + proto: int + doc: str + def __init__(self, name: str, code: str, arg: Optional[ArgumentDescriptor], + stack_before: List[StackObject], stack_after: List[StackObject], proto: int, doc: str) -> None: ... + +opcodes: List[OpcodeInfo] + +def genops(pickle: Union[bytes, IO[bytes]]) -> Iterator[Tuple[OpcodeInfo, Optional[Any], Optional[int]]]: ... +def optimize(p: Union[bytes, IO[bytes]]) -> bytes: ... +if sys.version_info >= (3, 2): + def dis(pickle: Union[bytes, IO[bytes]], out: Optional[IO[str]] = ..., memo: Optional[MutableMapping[int, Any]] = ..., indentlevel: int = ..., annotate: int = ...) -> None: ... +else: + def dis(pickle: Union[bytes, IO[bytes]], out: Optional[IO[str]] = ..., memo: Optional[MutableMapping[int, Any]] = ..., indentlevel: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pkgutil.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pkgutil.pyi new file mode 100644 index 000000000..c7bad4221 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pkgutil.pyi @@ -0,0 +1,35 @@ +# Stubs for pkgutil + +from typing import Any, Callable, Generator, IO, Iterable, Optional, Tuple, NamedTuple +import sys + +if sys.version_info >= (3,): + from importlib.abc import Loader +else: + Loader = Any + +if sys.version_info >= (3, 6): + ModuleInfo = NamedTuple('ModuleInfo', [('module_finder', Any), ('name', str), ('ispkg', bool)]) + _YMFNI = Generator[ModuleInfo, None, None] +else: + _YMFNI = Generator[Tuple[Any, str, bool], None, None] + + +def extend_path(path: Iterable[str], name: str) -> Iterable[str]: ... + +class ImpImporter: + def __init__(self, dirname: Optional[str] = ...) -> None: ... + +class ImpLoader: + def __init__(self, fullname: str, file: IO[str], filename: str, + etc: Tuple[str, str, int]) -> None: ... + +def find_loader(fullname: str) -> Loader: ... +def get_importer(path_item: str) -> Any: ... # TODO precise type +def get_loader(module_or_name: str) -> Loader: ... +def iter_importers(fullname: str = ...) -> Generator[Any, None, None]: ... # TODO precise type +def iter_modules(path: Optional[Iterable[str]] = ..., + prefix: str = ...) -> _YMFNI: ... # TODO precise type +def walk_packages(path: Optional[Iterable[str]] = ..., prefix: str = ..., + onerror: Optional[Callable[[str], None]] = ...) -> _YMFNI: ... +def get_data(package: str, resource: str) -> Optional[bytes]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/plistlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/plistlib.pyi new file mode 100644 index 000000000..df8cdb7db --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/plistlib.pyi @@ -0,0 +1,57 @@ +# Stubs for plistlib + +from typing import ( + Any, IO, Mapping, MutableMapping, Optional, Union, + Type, TypeVar, +) +from typing import Dict as DictT +import sys +if sys.version_info >= (3,): + from enum import Enum + + class PlistFormat(Enum): + FMT_XML = ... # type: PlistFormat + FMT_BINARY = ... # type: PlistFormat + FMT_XML = PlistFormat.FMT_XML + FMT_BINARY = PlistFormat.FMT_BINARY + +mm = MutableMapping[str, Any] +_D = TypeVar('_D', bound=mm) +if sys.version_info >= (3,): + _Path = str +else: + _Path = Union[str, unicode] + +if sys.version_info >= (3, 4): + def load(fp: IO[bytes], *, fmt: Optional[PlistFormat] = ..., + use_builtin_types: bool = ..., dict_type: Type[_D] = ...) -> _D: ... + def loads(data: bytes, *, fmt: Optional[PlistFormat] = ..., + use_builtin_types: bool = ..., dict_type: Type[_D] = ...) -> _D: ... + def dump(value: Mapping[str, Any], fp: IO[bytes], *, + fmt: PlistFormat =..., sort_keys: bool = ..., + skipkeys: bool = ...) -> None: ... + def dumps(value: Mapping[str, Any], *, fmt: PlistFormat = ..., + skipkeys: bool = ..., sort_keys: bool = ...) -> bytes: ... + +def readPlist(pathOrFile: Union[_Path, IO[bytes]]) -> DictT[str, Any]: ... +def writePlist(value: Mapping[str, Any], pathOrFile: Union[_Path, IO[bytes]]) -> None: ... +def readPlistFromBytes(data: bytes) -> DictT[str, Any]: ... +def writePlistToBytes(value: Mapping[str, Any]) -> bytes: ... +if sys.version_info < (3,): + def readPlistFromResource(path: _Path, restype: str = ..., + resid: int = ...) -> DictT[str, Any]: ... + def writePlistToResource(rootObject: Mapping[str, Any], path: _Path, + restype: str = ..., + resid: int = ...) -> None: ... + def readPlistFromString(data: str) -> DictT[str, Any]: ... + def writePlistToString(rootObject: Mapping[str, Any]) -> str: ... + +if sys.version_info < (3, 7): + class Dict(dict): + def __getattr__(self, attr: str) -> Any: ... + def __setattr__(self, attr: str, value: Any) -> None: ... + def __delattr__(self, attr: str) -> None: ... + +class Data: + data = ... # type: bytes + def __init__(self, data: bytes) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/poplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/poplib.pyi new file mode 100644 index 000000000..d2b7dab6c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/poplib.pyi @@ -0,0 +1,77 @@ +# Stubs for poplib (Python 2 and 3) + +import socket +import ssl +import sys +from typing import ( + Any, BinaryIO, Dict, List, NoReturn, Optional, overload, Pattern, Text, + Tuple, +) + +_LongResp = Tuple[bytes, List[bytes], int] + +class error_proto(Exception): ... + +POP3_PORT: int +POP3_SSL_PORT: int +CR: bytes +LF: bytes +CRLF: bytes + + +class POP3: + if sys.version_info >= (3, 0): + encoding: Text + + host: Text + port: int + sock: socket.socket + file: BinaryIO + welcome: bytes + + def __init__(self, host: Text, port: int = ..., timeout: float = ...) -> None: ... + def getwelcome(self) -> bytes: ... + def set_debuglevel(self, level: int) -> None: ... + def user(self, user: Text) -> bytes: ... + def pass_(self, pswd: Text) -> bytes: ... + def stat(self) -> Tuple[int, int]: ... + def list(self, which: Optional[Any] = ...) -> _LongResp: ... + def retr(self, which: Any) -> _LongResp: ... + def dele(self, which: Any) -> bytes: ... + def noop(self) -> bytes: ... + def rset(self) -> bytes: ... + def quit(self) -> bytes: ... + def close(self) -> None: ... + def rpop(self, user: Text) -> bytes: ... + + timestamp: Pattern[Text] + + if sys.version_info < (3, 0): + def apop(self, user: Text, secret: Text) -> bytes: ... + else: + def apop(self, user: Text, password: Text) -> bytes: ... + def top(self, which: Any, howmuch: int) -> _LongResp: ... + + @overload + def uidl(self) -> _LongResp: ... + @overload + def uidl(self, which: Any) -> bytes: ... + + if sys.version_info >= (3, 5): + def utf8(self) -> bytes: ... + if sys.version_info >= (3, 4): + def capa(self) -> Dict[Text, List[Text]]: ... + def stls(self, context: Optional[ssl.SSLContext] = ...) -> bytes: ... + + +class POP3_SSL(POP3): + if sys.version_info >= (3, 0): + def __init__(self, host: Text, port: int = ..., keyfile: Optional[Text] = ..., certfile: Optional[Text] = ..., + timeout: float = ..., context: Optional[ssl.SSLContext] = ...) -> None: ... + else: + def __init__(self, host: Text, port: int = ..., keyfile: Optional[Text] = ..., certfile: Optional[Text] = ..., + timeout: float = ...) -> None: ... + + if sys.version_info >= (3, 4): + # "context" is actually the last argument, but that breaks LSP and it doesn't really matter because all the arguments are ignored + def stls(self, context: Any = ..., keyfile: Any = ..., certfile: Any = ...) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pprint.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pprint.pyi new file mode 100644 index 000000000..90a87ab0f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pprint.pyi @@ -0,0 +1,40 @@ +# Stubs for pprint + +# Based on http://docs.python.org/2/library/pprint.html +# Based on http://docs.python.org/3/library/pprint.html + +import sys +from typing import Any, Dict, Tuple, IO + +if sys.version_info >= (3, 4): + def pformat(o: object, indent: int = ..., width: int = ..., + depth: int = ..., compact: bool = ...) -> str: ... +else: + def pformat(o: object, indent: int = ..., width: int = ..., + depth: int = ...) -> str: ... + +if sys.version_info >= (3, 4): + def pprint(o: object, stream: IO[str] = ..., indent: int = ..., width: int = ..., + depth: int = ..., compact: bool = ...) -> None: ... +else: + def pprint(o: object, stream: IO[str] = ..., indent: int = ..., width: int = ..., + depth: int = ...) -> None: ... + +def isreadable(o: object) -> bool: ... +def isrecursive(o: object) -> bool: ... +def saferepr(o: object) -> str: ... + +class PrettyPrinter: + if sys.version_info >= (3, 4): + def __init__(self, indent: int = ..., width: int = ..., depth: int = ..., + stream: IO[str] = ..., compact: bool = ...) -> None: ... + else: + def __init__(self, indent: int = ..., width: int = ..., depth: int = ..., + stream: IO[str] = ...) -> None: ... + + def pformat(self, o: object) -> str: ... + def pprint(self, o: object) -> None: ... + def isreadable(self, o: object) -> bool: ... + def isrecursive(self, o: object) -> bool: ... + def format(self, o: object, context: Dict[int, Any], maxlevels: int, + level: int) -> Tuple[str, bool, bool]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/profile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/profile.pyi new file mode 100644 index 000000000..21a7c8fd4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/profile.pyi @@ -0,0 +1,21 @@ +from typing import Any, Callable, Dict, Optional, TypeVar + +def run(statement: str, filename: Optional[str] = ..., sort: int = ...) -> None: ... +def runctx(statement: str, globals: Dict[str, Any], locals: Dict[str, Any], filename: Optional[str] = ..., sort: int = ...) -> None: ... + +_SelfT = TypeVar('_SelfT', bound='Profile') +_T = TypeVar('_T') + +class Profile: + def __init__(self, timer: Optional[Callable[[], float]] = ..., bias: Optional[int] = ...) -> None: ... + def set_cmd(self, cmd: str) -> None: ... + def simulate_call(self, name: str) -> None: ... + def simulate_cmd_complete(self) -> None: ... + def print_stats(self, sort: int = ...) -> None: ... + def dump_stats(self, file: str) -> None: ... + def create_stats(self) -> None: ... + def snapshot_stats(self) -> None: ... + def run(self: _SelfT, cmd: str) -> _SelfT: ... + def runctx(self: _SelfT, cmd: str, globals: Dict[str, Any], locals: Dict[str, Any]) -> _SelfT: ... + def runcall(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ... + def calibrate(self, m: int, verbose: int = ...) -> float: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pstats.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pstats.pyi new file mode 100644 index 000000000..8bf1b0dae --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pstats.pyi @@ -0,0 +1,39 @@ +from profile import Profile +from cProfile import Profile as _cProfile +import os +import sys +from typing import Any, Dict, IO, Iterable, List, Text, Tuple, TypeVar, Union, overload + +_Selector = Union[str, float, int] +_T = TypeVar('_T', bound='Stats') +if sys.version_info >= (3, 6): + _Path = Union[bytes, Text, os.PathLike[Any]] +else: + _Path = Union[bytes, Text] + +class Stats: + def __init__(self: _T, __arg: Union[None, str, Text, Profile, _cProfile] = ..., + *args: Union[None, str, Text, Profile, _cProfile, _T], + stream: IO[Any] = ...) -> None: ... + def init(self, arg: Union[None, str, Text, Profile, _cProfile]) -> None: ... + def load_stats(self, arg: Union[None, str, Text, Profile, _cProfile]) -> None: ... + def get_top_level_stats(self) -> None: ... + def add(self: _T, *arg_list: Union[None, str, Text, Profile, _cProfile, _T]) -> _T: ... + def dump_stats(self, filename: _Path) -> None: ... + def get_sort_arg_defs(self) -> Dict[str, Tuple[Tuple[Tuple[int, int], ...], str]]: ... + @overload + def sort_stats(self: _T, field: int) -> _T: ... + @overload + def sort_stats(self: _T, *field: str) -> _T: ... + def reverse_order(self: _T) -> _T: ... + def strip_dirs(self: _T) -> _T: ... + def calc_callees(self) -> None: ... + def eval_print_amount(self, sel: _Selector, list: List[str], msg: str) -> Tuple[List[str], str]: ... + def get_print_list(self, sel_list: Iterable[_Selector]) -> Tuple[int, List[str]]: ... + def print_stats(self: _T, *amount: _Selector) -> _T: ... + def print_callees(self: _T, *amount: _Selector) -> _T: ... + def print_callers(self: _T, *amount: _Selector) -> _T: ... + def print_call_heading(self, name_size: int, column_title: str) -> None: ... + def print_call_line(self, name_size: int, source: str, call_dict: Dict[str, Any], arrow: str = ...) -> None: ... + def print_title(self) -> None: ... + def print_line(self, func: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pty.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pty.pyi new file mode 100644 index 000000000..3931bb0a9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pty.pyi @@ -0,0 +1,20 @@ +# Stubs for pty (Python 2 and 3) +import sys +from typing import Callable, Iterable, Tuple, Union + +_Reader = Callable[[int], bytes] + +STDIN_FILENO: int +STDOUT_FILENO: int +STDERR_FILENO: int + +CHILD: int + +def openpty() -> Tuple[int, int]: ... +def master_open() -> Tuple[int, str]: ... +def slave_open(tty_name: str) -> int: ... +def fork() -> Tuple[int, int]: ... +if sys.version_info >= (3, 4): + def spawn(argv: Union[str, Iterable[str]], master_read: _Reader = ..., stdin_read: _Reader = ...) -> int: ... +else: + def spawn(argv: Union[str, Iterable[str]], master_read: _Reader = ..., stdin_read: _Reader = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pwd.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pwd.pyi new file mode 100644 index 000000000..5bd0bbb64 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pwd.pyi @@ -0,0 +1,13 @@ +from typing import List, NamedTuple + +struct_passwd = NamedTuple("struct_passwd", [("pw_name", str), + ("pw_passwd", str), + ("pw_uid", int), + ("pw_gid", int), + ("pw_gecos", str), + ("pw_dir", str), + ("pw_shell", str)]) + +def getpwall() -> List[struct_passwd]: ... +def getpwuid(uid: int) -> struct_passwd: ... +def getpwnam(name: str) -> struct_passwd: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/py_compile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/py_compile.pyi new file mode 100644 index 000000000..ad8e8c8a3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/py_compile.pyi @@ -0,0 +1,20 @@ +# Stubs for py_compile (Python 2 and 3) +import sys + +from typing import Optional, List, Text, AnyStr, Union + +_EitherStr = Union[bytes, Text] + +class PyCompileError(Exception): + exc_type_name = ... # type: str + exc_value = ... # type: BaseException + file = ... # type: str + msg = ... # type: str + def __init__(self, exc_type: str, exc_value: BaseException, file: str, msg: str = ...) -> None: ... + +if sys.version_info >= (3, 2): + def compile(file: AnyStr, cfile: Optional[AnyStr] = ..., dfile: Optional[AnyStr] = ..., doraise: bool = ..., optimize: int = ...) -> Optional[AnyStr]: ... +else: + def compile(file: _EitherStr, cfile: Optional[_EitherStr] = ..., dfile: Optional[_EitherStr] = ..., doraise: bool = ...) -> None: ... + +def main(args: Optional[List[Text]] = ...) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyclbr.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyclbr.pyi new file mode 100644 index 000000000..8dad523fb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyclbr.pyi @@ -0,0 +1,40 @@ +from typing import List, Union, Sequence, Optional, Dict + + +class Class: + module = ... # type: str + name = ... # type: str + super = ... # type: Optional[List[Union["Class", str]]] + methods = ... # type: Dict[str, int] + file = ... # type: int + lineno = ... # type: int + + def __init__(self, + module: str, + name: str, + super: Optional[List[Union["Class", str]]], + file: str, + lineno: int) -> None: ... + + +class Function: + module = ... # type: str + name = ... # type: str + file = ... # type: int + lineno = ... # type: int + + def __init__(self, + module: str, + name: str, + file: str, + lineno: int) -> None: ... + + +def readmodule(module: str, + path: Optional[Sequence[str]] = ... + ) -> Dict[str, Class]: ... + + +def readmodule_ex(module: str, + path: Optional[Sequence[str]] = ... + ) -> Dict[str, Union[Class, Function, List[str]]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/__init__.pyi new file mode 100644 index 000000000..670e56106 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/__init__.pyi @@ -0,0 +1,75 @@ +from typing import List, Tuple, Optional, Callable, Any, Protocol, Union, Dict, Text + +import pyexpat.errors as errors +import pyexpat.model as model + +EXPAT_VERSION: str # undocumented +version_info: Tuple[int, int, int] # undocumented +native_encoding: str # undocumented +features: List[Tuple[str, int]] # undocumented + +class ExpatError(Exception): + code: int + lineno: int + offset: int + +error = ExpatError + +class _Reader(Protocol): + def read(self, length: int) -> bytes: ... + +XML_PARAM_ENTITY_PARSING_NEVER: int +XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: int +XML_PARAM_ENTITY_PARSING_ALWAYS: int + +_Model = Tuple[int, int, Optional[str], tuple] + +class XMLParserType(object): + def Parse(self, data: Union[Text, bytes], isfinal: bool = ...) -> int: ... + def ParseFile(self, file: _Reader) -> int: ... + def SetBase(self, base: Text) -> None: ... + def GetBase(self) -> Optional[str]: ... + def GetInputContext(self) -> Optional[bytes]: ... + def ExternalEntityParserCreate(self, context: Optional[Text], encoding: Text = ...) -> XMLParserType: ... + def SetParamEntityParsing(self, flag: int) -> int: ... + def UseForeignDTD(self, flag: bool = ...) -> None: ... + buffer_size: int + buffer_text: bool + buffer_used: int + namespace_prefixes: bool # undocumented + ordered_attributes: bool + specified_attributes: bool + ErrorByteIndex: int + ErrorCode: int + ErrorColumnNumber: int + ErrorLineNumber: int + CurrentByteIndex: int + CurrentColumnNumber: int + CurrentLineNumber: int + XmlDeclHandler: Optional[Callable[[str, Optional[str], int], Any]] + StartDoctypeDeclHandler: Optional[Callable[[str, Optional[str], Optional[str], bool], Any]] + EndDoctypeDeclHandler: Optional[Callable[[], Any]] + ElementDeclHandler: Optional[Callable[[str, _Model], Any]] + AttlistDeclHandler: Optional[Callable[[str, str, str, Optional[str], bool], Any]] + StartElementHandler: Optional[Union[ + Callable[[str, Dict[str, str]], Any], + Callable[[str, List[str]], Any], + Callable[[str, Union[Dict[str, str]], List[str]], Any]]] + EndElementHandler: Optional[Callable[[str], Any]] + ProcessingInstructionHandler: Optional[Callable[[str, str], Any]] + CharacterDataHandler: Optional[Callable[[str], Any]] + UnparsedEntityDeclHandler: Optional[Callable[[str, Optional[str], str, Optional[str], str], Any]] + EntityDeclHandler: Optional[Callable[[str, bool, Optional[str], Optional[str], str, Optional[str], Optional[str]], Any]] + NotationDeclHandler: Optional[Callable[[str, Optional[str], str, Optional[str]], Any]] + StartNamespaceDeclHandler: Optional[Callable[[str, str], Any]] + EndNamespaceDeclHandler: Optional[Callable[[str], Any]] + CommentHandler: Optional[Callable[[str], Any]] + StartCdataSectionHandler: Optional[Callable[[], Any]] + EndCdataSectionHandler: Optional[Callable[[], Any]] + DefaultHandler: Optional[Callable[[str], Any]] + DefaultHandlerExpand: Optional[Callable[[str], Any]] + NotStandaloneHandler: Optional[Callable[[], int]] + ExternalEntityRefHandler: Optional[Callable[[str, Optional[str], Optional[str], Optional[str]], int]] + +def ErrorString(errno: int) -> str: ... +def ParserCreate(encoding: Optional[Text] = ..., namespace_separator: Optional[Text] = ...) -> XMLParserType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/errors.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/errors.pyi new file mode 100644 index 000000000..6cde43e3b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/errors.pyi @@ -0,0 +1,44 @@ +import sys +from typing import Dict + +if sys.version_info >= (3, 2): + codes: Dict[str, int] + messages: Dict[int, str] + +XML_ERROR_ABORTED: str +XML_ERROR_ASYNC_ENTITY: str +XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF: str +XML_ERROR_BAD_CHAR_REF: str +XML_ERROR_BINARY_ENTITY_REF: str +XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING: str +XML_ERROR_DUPLICATE_ATTRIBUTE: str +XML_ERROR_ENTITY_DECLARED_IN_PE: str +XML_ERROR_EXTERNAL_ENTITY_HANDLING: str +XML_ERROR_FEATURE_REQUIRES_XML_DTD: str +XML_ERROR_FINISHED: str +XML_ERROR_INCOMPLETE_PE: str +XML_ERROR_INCORRECT_ENCODING: str +XML_ERROR_INVALID_TOKEN: str +XML_ERROR_JUNK_AFTER_DOC_ELEMENT: str +XML_ERROR_MISPLACED_XML_PI: str +XML_ERROR_NOT_STANDALONE: str +XML_ERROR_NOT_SUSPENDED: str +XML_ERROR_NO_ELEMENTS: str +XML_ERROR_NO_MEMORY: str +XML_ERROR_PARAM_ENTITY_REF: str +XML_ERROR_PARTIAL_CHAR: str +XML_ERROR_PUBLICID: str +XML_ERROR_RECURSIVE_ENTITY_REF: str +XML_ERROR_SUSPENDED: str +XML_ERROR_SUSPEND_PE: str +XML_ERROR_SYNTAX: str +XML_ERROR_TAG_MISMATCH: str +XML_ERROR_TEXT_DECL: str +XML_ERROR_UNBOUND_PREFIX: str +XML_ERROR_UNCLOSED_CDATA_SECTION: str +XML_ERROR_UNCLOSED_TOKEN: str +XML_ERROR_UNDECLARING_PREFIX: str +XML_ERROR_UNDEFINED_ENTITY: str +XML_ERROR_UNEXPECTED_STATE: str +XML_ERROR_UNKNOWN_ENCODING: str +XML_ERROR_XML_DECL: str diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/model.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/model.pyi new file mode 100644 index 000000000..f357cf651 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/pyexpat/model.pyi @@ -0,0 +1,11 @@ +XML_CTYPE_ANY: int +XML_CTYPE_CHOICE: int +XML_CTYPE_EMPTY: int +XML_CTYPE_MIXED: int +XML_CTYPE_NAME: int +XML_CTYPE_SEQ: int + +XML_CQUANT_NONE: int +XML_CQUANT_OPT: int +XML_CQUANT_PLUS: int +XML_CQUANT_REP: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/quopri.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/quopri.pyi new file mode 100644 index 000000000..2823f8c40 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/quopri.pyi @@ -0,0 +1,8 @@ +# Stubs for quopri (Python 2 and 3) + +from typing import BinaryIO + +def encode(input: BinaryIO, output: BinaryIO, quotetabs: int, header: int = ...) -> None: ... +def encodestring(s: bytes, quotetabs: int = ..., header: int = ...) -> bytes: ... +def decode(input: BinaryIO, output: BinaryIO, header: int = ...) -> None: ... +def decodestring(s: bytes, header: int = ...) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/readline.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/readline.pyi new file mode 100644 index 000000000..aff2debf2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/readline.pyi @@ -0,0 +1,41 @@ +# Stubs for readline + +from typing import Callable, Optional, Sequence +import sys + +_CompleterT = Optional[Callable[[str, int], Optional[str]]] +_CompDispT = Optional[Callable[[str, Sequence[str], int], None]] + + +def parse_and_bind(string: str) -> None: ... +def read_init_file(filename: str = ...) -> None: ... + +def get_line_buffer() -> str: ... +def insert_text(string: str) -> None: ... +def redisplay() -> None: ... + +def read_history_file(filename: str = ...) -> None: ... +def write_history_file(filename: str = ...) -> None: ... +if sys.version_info >= (3, 5): + def append_history_file(nelements: int, filename: str = ...) -> None: ... +def get_history_length() -> int: ... +def set_history_length(length: int) -> None: ... + +def clear_history() -> None: ... +def get_current_history_length() -> int: ... +def get_history_item(index: int) -> str: ... +def remove_history_item(pos: int) -> None: ... +def replace_history_item(pos: int, line: str) -> None: ... +def add_history(string: str) -> None: ... + +def set_startup_hook(function: Optional[Callable[[], None]] = ...) -> None: ... +def set_pre_input_hook(function: Optional[Callable[[], None]] = ...) -> None: ... + +def set_completer(function: _CompleterT = ...) -> None: ... +def get_completer() -> _CompleterT: ... +def get_completion_type() -> int: ... +def get_begidx() -> int: ... +def get_endidx() -> int: ... +def set_completer_delims(string: str) -> None: ... +def get_completer_delims() -> str: ... +def set_completion_display_matches_hook(function: _CompDispT = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/rlcompleter.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/rlcompleter.pyi new file mode 100644 index 000000000..3db9d0c40 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/rlcompleter.pyi @@ -0,0 +1,14 @@ +# Stubs for rlcompleter + +from typing import Any, Dict, Optional, Union +import sys + +if sys.version_info >= (3,): + _Text = str +else: + _Text = Union[str, unicode] + + +class Completer: + def __init__(self, namespace: Optional[Dict[str, Any]] = ...) -> None: ... + def complete(self, text: _Text, state: int) -> Optional[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sched.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sched.pyi new file mode 100644 index 000000000..5d5cf33d2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sched.pyi @@ -0,0 +1,27 @@ +import sys +from typing import Any, Callable, Dict, List, NamedTuple, Optional, Text, Tuple + +Event = NamedTuple('Event', [ + ('time', float), + ('priority', Any), + ('action', Callable[..., Any]), + ('argument', Tuple[Any, ...]), + ('kwargs', Dict[Text, Any]), +]) + +class scheduler: + if sys.version_info >= (3, 3): + def __init__(self, timefunc: Callable[[], float] = ..., delayfunc: Callable[[float], None] = ...) -> None: ... + def enterabs(self, time: float, priority: Any, action: Callable[..., Any], argument: Tuple[Any, ...] = ..., kwargs: Dict[str, Any] = ...) -> Event: ... + def enter(self, delay: float, priority: Any, action: Callable[..., Any], argument: Tuple[Any, ...] = ..., kwargs: Dict[str, Any] = ...) -> Event: ... + def run(self, blocking: bool = ...) -> Optional[float]: ... + else: + def __init__(self, timefunc: Callable[[], float], delayfunc: Callable[[float], None]) -> None: ... + def enterabs(self, time: float, priority: Any, action: Callable[..., Any], argument: Tuple[Any, ...]) -> Event: ... + def enter(self, delay: float, priority: Any, action: Callable[..., Any], argument: Tuple[Any, ...]) -> Event: ... + def run(self) -> None: ... + + def cancel(self, event: Event) -> None: ... + def empty(self) -> bool: ... + @property + def queue(self) -> List[Event]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/select.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/select.pyi new file mode 100644 index 000000000..ab9ffc636 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/select.pyi @@ -0,0 +1,137 @@ +import sys +from typing import Any, Optional, Sequence, Tuple, Iterable, List, Union + +# When we have protocols, this should change to a protocol with a fileno method +# See https://docs.python.org/3/c-api/file.html#c.PyObject_AsFileDescriptor +_FileDescriptor = Union[int, Any] + +EPOLLERR: int +EPOLLET: int +EPOLLHUP: int +EPOLLIN: int +EPOLLMSG: int +EPOLLONESHOT: int +EPOLLOUT: int +EPOLLPRI: int +EPOLLRDBAND: int +EPOLLRDNORM: int +EPOLLWRBAND: int +EPOLLWRNORM: int +EPOLL_RDHUP: int +KQ_EV_ADD: int +KQ_EV_CLEAR: int +KQ_EV_DELETE: int +KQ_EV_DISABLE: int +KQ_EV_ENABLE: int +KQ_EV_EOF: int +KQ_EV_ERROR: int +KQ_EV_FLAG1: int +KQ_EV_ONESHOT: int +KQ_EV_SYSFLAGS: int +KQ_FILTER_AIO: int +KQ_FILTER_NETDEV: int +KQ_FILTER_PROC: int +KQ_FILTER_READ: int +KQ_FILTER_SIGNAL: int +KQ_FILTER_TIMER: int +KQ_FILTER_VNODE: int +KQ_FILTER_WRITE: int +KQ_NOTE_ATTRIB: int +KQ_NOTE_CHILD: int +KQ_NOTE_DELETE: int +KQ_NOTE_EXEC: int +KQ_NOTE_EXIT: int +KQ_NOTE_EXTEND: int +KQ_NOTE_FORK: int +KQ_NOTE_LINK: int +KQ_NOTE_LINKDOWN: int +KQ_NOTE_LINKINV: int +KQ_NOTE_LINKUP: int +KQ_NOTE_LOWAT: int +KQ_NOTE_PCTRLMASK: int +KQ_NOTE_PDATAMASK: int +KQ_NOTE_RENAME: int +KQ_NOTE_REVOKE: int +KQ_NOTE_TRACK: int +KQ_NOTE_TRACKERR: int +KQ_NOTE_WRITE: int +PIPE_BUF: int +POLLERR: int +POLLHUP: int +POLLIN: int +POLLMSG: int +POLLNVAL: int +POLLOUT: int +POLLPRI: int +POLLRDBAND: int +POLLRDNORM: int +POLLWRBAND: int +POLLWRNORM: int + +class poll: + def __init__(self) -> None: ... + def register(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ... + def modify(self, fd: _FileDescriptor, eventmask: int) -> None: ... + def unregister(self, fd: _FileDescriptor) -> None: ... + def poll(self, timeout: Optional[float] = ...) -> List[Tuple[int, int]]: ... + +def select(rlist: Sequence[Any], wlist: Sequence[Any], xlist: Sequence[Any], + timeout: Optional[float] = ...) -> Tuple[List[Any], + List[Any], + List[Any]]: ... + +if sys.version_info >= (3, 3): + error = OSError +else: + class error(Exception): ... + +# BSD only +class kevent(object): + data: Any + fflags: int + filter: int + flags: int + ident: int + udata: Any + def __init__(self, ident: _FileDescriptor, filter: int = ..., flags: int = ..., fflags: int = ..., data: Any = ..., udata: Any = ...) -> None: ... + +# BSD only +class kqueue(object): + closed: bool + def __init__(self) -> None: ... + def close(self) -> None: ... + def control(self, changelist: Optional[Iterable[kevent]], max_events: int, timeout: float = ...) -> List[kevent]: ... + def fileno(self) -> int: ... + @classmethod + def fromfd(cls, fd: _FileDescriptor) -> kqueue: ... + +# Linux only +class epoll(object): + if sys.version_info >= (3, 3): + def __init__(self, sizehint: int = ..., flags: int = ...) -> None: ... + else: + def __init__(self, sizehint: int = ...) -> None: ... + if sys.version_info >= (3, 4): + def __enter__(self) -> epoll: ... + def __exit__(self, *args: Any) -> None: ... + def close(self) -> None: ... + closed: bool + def fileno(self) -> int: ... + def register(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ... + def modify(self, fd: _FileDescriptor, eventmask: int) -> None: ... + def unregister(self, fd: _FileDescriptor) -> None: ... + def poll(self, timeout: float = ..., maxevents: int = ...) -> List[Tuple[int, int]]: ... + @classmethod + def fromfd(cls, fd: _FileDescriptor) -> epoll: ... + +if sys.version_info >= (3, 3): + # Solaris only + class devpoll: + if sys.version_info >= (3, 4): + def close(self) -> None: ... + closed: bool + def fileno(self) -> int: ... + def register(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ... + def modify(self, fd: _FileDescriptor, eventmask: int = ...) -> None: ... + def unregister(self, fd: _FileDescriptor) -> None: ... + def poll(self, timeout: Optional[float] = ...) -> List[Tuple[int, int]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/shutil.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/shutil.pyi new file mode 100644 index 000000000..07f9f4bf4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/shutil.pyi @@ -0,0 +1,135 @@ +import os +import sys + +# 'bytes' paths are not properly supported: they don't work with all functions, +# sometimes they only work partially (broken exception messages), and the test +# cases don't use them. + +from typing import ( + List, Iterable, Callable, Any, Tuple, Sequence, NamedTuple, IO, + AnyStr, Optional, Union, Set, TypeVar, overload, Type, Protocol +) + +if sys.version_info >= (3, 6): + _Path = Union[str, os.PathLike[str]] + _AnyStr = str + _AnyPath = TypeVar("_AnyPath", str, os.PathLike[str]) + # Return value of some functions that may either return a path-like object that was passed in or + # a string + _PathReturn = Any +elif sys.version_info >= (3,): + _Path = str + _AnyStr = str + _AnyPath = str + _PathReturn = str +else: + _Path = unicode + _AnyStr = TypeVar("_AnyStr", str, unicode) + _AnyPath = TypeVar("_AnyPath", str, unicode) + _PathReturn = Type[None] + +if sys.version_info >= (3,): + class Error(OSError): ... + class SameFileError(Error): ... + class SpecialFileError(OSError): ... + class ExecError(OSError): ... + class ReadError(OSError): ... + class RegistryError(Exception): ... +else: + class Error(EnvironmentError): ... + class SpecialFileError(EnvironmentError): ... + class ExecError(EnvironmentError): ... + +_S_co = TypeVar("_S_co", covariant=True) +_S_contra = TypeVar("_S_contra", contravariant=True) + +class _Reader(Protocol[_S_co]): + def read(self, length: int) -> _S_co: ... + +class _Writer(Protocol[_S_contra]): + def write(self, data: _S_contra) -> Any: ... + +def copyfileobj(fsrc: _Reader[AnyStr], fdst: _Writer[AnyStr], + length: int = ...) -> None: ... + +if sys.version_info >= (3,): + def copyfile(src: _Path, dst: _AnyPath, *, + follow_symlinks: bool = ...) -> _AnyPath: ... + def copymode(src: _Path, dst: _Path, *, + follow_symlinks: bool = ...) -> None: ... + def copystat(src: _Path, dst: _Path, *, + follow_symlinks: bool = ...) -> None: ... + def copy(src: _Path, dst: _Path, *, + follow_symlinks: bool = ...) -> _PathReturn: ... + def copy2(src: _Path, dst: _Path, *, + follow_symlinks: bool = ...) -> _PathReturn: ... +else: + def copyfile(src: _Path, dst: _Path) -> None: ... + def copymode(src: _Path, dst: _Path) -> None: ... + def copystat(src: _Path, dst: _Path) -> None: ... + def copy(src: _Path, dst: _Path) -> _PathReturn: ... + def copy2(src: _Path, dst: _Path) -> _PathReturn: ... + +def ignore_patterns(*patterns: _Path) -> Callable[[Any, List[_AnyStr]], Set[_AnyStr]]: ... + +if sys.version_info >= (3,): + _IgnoreFn = Union[None, Callable[[str, List[str]], Iterable[str]], Callable[[_Path, List[str]], Iterable[str]]] + def copytree(src: _Path, dst: _Path, symlinks: bool = ..., + ignore: _IgnoreFn = ..., + copy_function: Callable[[str, str], None] = ..., + ignore_dangling_symlinks: bool = ...) -> _PathReturn: ... +else: + _IgnoreFn = Union[None, Callable[[AnyStr, List[AnyStr]], Iterable[AnyStr]]] + def copytree(src: AnyStr, dst: AnyStr, symlinks: bool = ..., + ignore: _IgnoreFn = ...) -> _PathReturn: ... + +if sys.version_info >= (3,): + @overload + def rmtree(path: bytes, ignore_errors: bool = ..., + onerror: Optional[Callable[[Any, str, Any], Any]] = ...) -> None: ... + @overload + def rmtree(path: _AnyPath, ignore_errors: bool = ..., + onerror: Optional[Callable[[Any, _AnyPath, Any], Any]] = ...) -> None: ... +else: + def rmtree(path: _AnyPath, ignore_errors: bool = ..., + onerror: Optional[Callable[[Any, _AnyPath, Any], Any]] = ...) -> None: ... + +if sys.version_info >= (3, 5): + _CopyFn = Union[Callable[[str, str], None], Callable[[_Path, _Path], None]] + def move(src: _Path, dst: _Path, + copy_function: _CopyFn = ...) -> _PathReturn: ... +else: + def move(src: _Path, dst: _Path) -> _PathReturn: ... + +if sys.version_info >= (3,): + _ntuple_diskusage = NamedTuple('usage', [('total', int), + ('used', int), + ('free', int)]) + def disk_usage(path: _Path) -> _ntuple_diskusage: ... + def chown(path: _Path, user: Optional[str] = ..., + group: Optional[str] = ...) -> None: ... + def which(cmd: _Path, mode: int = ..., + path: Optional[_Path] = ...) -> Optional[str]: ... + +def make_archive(base_name: _AnyStr, format: str, root_dir: Optional[_Path] = ..., + base_dir: Optional[_Path] = ..., verbose: bool = ..., + dry_run: bool = ..., owner: Optional[str] = ..., group: Optional[str] = ..., + logger: Optional[Any] = ...) -> _AnyStr: ... +def get_archive_formats() -> List[Tuple[str, str]]: ... + +def register_archive_format(name: str, function: Callable[..., Any], + extra_args: Optional[Sequence[Union[Tuple[str, Any], List[Any]]]] = ..., + description: str = ...) -> None: ... +def unregister_archive_format(name: str) -> None: ... + +if sys.version_info >= (3,): + # Should be _Path once http://bugs.python.org/issue30218 is fixed + def unpack_archive(filename: str, extract_dir: Optional[_Path] = ..., + format: Optional[str] = ...) -> None: ... + def register_unpack_format(name: str, extensions: List[str], function: Any, + extra_args: Sequence[Tuple[str, Any]] = ..., + description: str = ...) -> None: ... + def unregister_unpack_format(name: str) -> None: ... + def get_unpack_formats() -> List[Tuple[str, List[str], str]]: ... + + def get_terminal_size(fallback: Tuple[int, int] = ...) -> os.terminal_size: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/site.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/site.pyi new file mode 100644 index 000000000..411677ae2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/site.pyi @@ -0,0 +1,17 @@ +# Stubs for site + +from typing import List, Iterable, Optional +import sys + +PREFIXES = ... # type: List[str] +ENABLE_USER_SITE = ... # type: Optional[bool] +USER_SITE = ... # type: Optional[str] +USER_BASE = ... # type: Optional[str] + +if sys.version_info < (3,): + def main() -> None: ... +def addsitedir(sitedir: str, + known_paths: Optional[Iterable[str]] = ...) -> None: ... +def getsitepackages(prefixes: Optional[Iterable[str]] = ...) -> List[str]: ... +def getuserbase() -> str: ... +def getusersitepackages() -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/smtpd.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/smtpd.pyi new file mode 100644 index 000000000..923b8bc65 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/smtpd.pyi @@ -0,0 +1,87 @@ +# Stubs for smtpd (Python 2 and 3) +import sys +import socket +import asyncore +import asynchat + +from typing import Any, DefaultDict, List, Optional, Text, Tuple, Type + +_Address = Tuple[str, int] # (host, port) + + +class SMTPChannel(asynchat.async_chat): + COMMAND: int + DATA: int + + if sys.version_info >= (3, 3): + command_size_limits: DefaultDict[str, int] + + if sys.version_info >= (3,): + smtp_server: SMTPServer + conn: socket.socket + addr: Any + received_lines: List[Text] + smtp_state: int + seen_greeting: str + mailfrom: str + rcpttos: List[str] + received_data: str + fqdn: str + peer: str + + command_size_limit: int + data_size_limit: int + + if sys.version_info >= (3, 5): + enable_SMTPUTF8: bool + + if sys.version_info >= (3, 3): + @property + def max_command_size_limit(self) -> int: ... + + if sys.version_info >= (3, 5): + def __init__(self, server: SMTPServer, conn: socket.socket, addr: Any, data_size_limit: int = ..., + map: Optional[asyncore._maptype] = ..., enable_SMTPUTF8: bool = ..., decode_data: bool = ...) -> None: ... + elif sys.version_info >= (3, 4): + def __init__(self, server: SMTPServer, conn: socket.socket, addr: Any, data_size_limit: int = ..., + map: Optional[asyncore._maptype] = ...) -> None: ... + else: + def __init__(self, server: SMTPServer, conn: socket.socket, addr: Any, data_size_limit: int = ...) -> None: ... + def push(self, msg: bytes) -> None: ... + def collect_incoming_data(self, data: bytes) -> None: ... + def found_terminator(self) -> None: ... + def smtp_HELO(self, arg: str) -> None: ... + def smtp_NOOP(self, arg: str) -> None: ... + def smtp_QUIT(self, arg: str) -> None: ... + def smtp_MAIL(self, arg: str) -> None: ... + def smtp_RCPT(self, arg: str) -> None: ... + def smtp_RSET(self, arg: str) -> None: ... + def smtp_DATA(self, arg: str) -> None: ... + if sys.version_info >= (3, 3): + def smtp_EHLO(self, arg: str) -> None: ... + def smtp_HELP(self, arg: str) -> None: ... + def smtp_VRFY(self, arg: str) -> None: ... + def smtp_EXPN(self, arg: str) -> None: ... + +class SMTPServer(asyncore.dispatcher): + channel_class: Type[SMTPChannel] + + data_size_limit: int + enable_SMTPUTF8: bool + + if sys.version_info >= (3, 5): + def __init__(self, localaddr: _Address, remoteaddr: _Address, + data_size_limit: int = ..., map: Optional[asyncore._maptype] = ..., + enable_SMTPUTF8: bool = ..., decode_data: bool = ...) -> None: ... + elif sys.version_info >= (3, 4): + def __init__(self, localaddr: _Address, remoteaddr: _Address, + data_size_limit: int = ..., map: Optional[asyncore._maptype] = ...) -> None: ... + else: + def __init__(self, localaddr: _Address, remoteaddr: _Address, + data_size_limit: int = ...) -> None: ... + def handle_accepted(self, conn: socket.socket, addr: Any) -> None: ... + def process_message(self, peer: _Address, mailfrom: str, rcpttos: List[Text], data: str, **kwargs: Any) -> Optional[str]: ... + +class DebuggingServer(SMTPServer): ... +class PureProxy(SMTPServer): ... +class MailmanProxy(PureProxy): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sndhdr.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sndhdr.pyi new file mode 100644 index 000000000..aecd70b46 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sndhdr.pyi @@ -0,0 +1,25 @@ +# Stubs for sndhdr (Python 2 and 3) + +import os +import sys +from typing import Any, NamedTuple, Optional, Tuple, Union + +if sys.version_info >= (3, 5): + SndHeaders = NamedTuple('SndHeaders', [ + ('filetype', str), + ('framerate', int), + ('nchannels', int), + ('nframes', int), + ('sampwidth', Union[int, str]), + ]) + _SndHeaders = SndHeaders +else: + _SndHeaders = Tuple[str, int, int, int, Union[int, str]] + +if sys.version_info >= (3, 6): + _Path = Union[str, bytes, os.PathLike[Any]] +else: + _Path = Union[str, bytes] + +def what(filename: _Path) -> Optional[_SndHeaders]: ... +def whathdr(filename: _Path) -> Optional[_SndHeaders]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/socket.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/socket.pyi new file mode 100644 index 000000000..1ed9093f2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/socket.pyi @@ -0,0 +1,623 @@ +# Stubs for socket +# Ron Murawski + +# based on: http://docs.python.org/3.2/library/socket.html +# see: http://hg.python.org/cpython/file/3d0686d90f55/Lib/socket.py +# see: http://nullege.com/codes/search/socket +# adapted for Python 2.7 by Michal Pokorny +import sys +from typing import Any, Iterable, Tuple, List, Optional, Union, overload, TypeVar + +_WriteBuffer = Union[bytearray, memoryview] + +# ----- variables and constants ----- + +AF_UNIX: AddressFamily +AF_INET: AddressFamily +AF_INET6: AddressFamily +SOCK_STREAM: SocketKind +SOCK_DGRAM: SocketKind +SOCK_RAW: SocketKind +SOCK_RDM: SocketKind +SOCK_SEQPACKET: SocketKind +SOCK_CLOEXEC: SocketKind +SOCK_NONBLOCK: SocketKind +SOMAXCONN: int +has_ipv6: bool +_GLOBAL_DEFAULT_TIMEOUT: Any +SocketType: Any +SocketIO: Any + +# These are flags that may exist on Python 3.6. Many don't exist on all platforms. +AF_AAL5: AddressFamily +AF_APPLETALK: AddressFamily +AF_ASH: AddressFamily +AF_ATMPVC: AddressFamily +AF_ATMSVC: AddressFamily +AF_AX25: AddressFamily +AF_BLUETOOTH: AddressFamily +AF_BRIDGE: AddressFamily +AF_CAN: AddressFamily +AF_DECnet: AddressFamily +AF_ECONET: AddressFamily +AF_IPX: AddressFamily +AF_IRDA: AddressFamily +AF_KEY: AddressFamily +AF_LLC: AddressFamily +AF_NETBEUI: AddressFamily +AF_NETLINK: AddressFamily +AF_NETROM: AddressFamily +AF_PACKET: AddressFamily +AF_PPPOX: AddressFamily +AF_RDS: AddressFamily +AF_ROSE: AddressFamily +AF_ROUTE: AddressFamily +AF_SECURITY: AddressFamily +AF_SNA: AddressFamily +AF_SYSTEM: AddressFamily +AF_TIPC: AddressFamily +AF_UNSPEC: AddressFamily +AF_WANPIPE: AddressFamily +AF_X25: AddressFamily +AI_ADDRCONFIG: AddressInfo +AI_ALL: AddressInfo +AI_CANONNAME: AddressInfo +AI_DEFAULT: AddressInfo +AI_MASK: AddressInfo +AI_NUMERICHOST: AddressInfo +AI_NUMERICSERV: AddressInfo +AI_PASSIVE: AddressInfo +AI_V4MAPPED: AddressInfo +AI_V4MAPPED_CFG: AddressInfo +BDADDR_ANY: str +BDADDR_LOCAL: str +BTPROTO_HCI: int +BTPROTO_L2CAP: int +BTPROTO_RFCOMM: int +BTPROTO_SCO: int +CAN_EFF_FLAG: int +CAN_EFF_MASK: int +CAN_ERR_FLAG: int +CAN_ERR_MASK: int +CAN_RAW: int +CAN_RAW_ERR_FILTER: int +CAN_RAW_FILTER: int +CAN_RAW_LOOPBACK: int +CAN_RAW_RECV_OWN_MSGS: int +CAN_RTR_FLAG: int +CAN_SFF_MASK: int +CAPI: int +EAGAIN: int +EAI_ADDRFAMILY: int +EAI_AGAIN: int +EAI_BADFLAGS: int +EAI_BADHINTS: int +EAI_FAIL: int +EAI_FAMILY: int +EAI_MAX: int +EAI_MEMORY: int +EAI_NODATA: int +EAI_NONAME: int +EAI_OVERFLOW: int +EAI_PROTOCOL: int +EAI_SERVICE: int +EAI_SOCKTYPE: int +EAI_SYSTEM: int +EBADF: int +EINTR: int +EWOULDBLOCK: int +HCI_DATA_DIR: int +HCI_FILTER: int +HCI_TIME_STAMP: int +INADDR_ALLHOSTS_GROUP: int +INADDR_ANY: int +INADDR_BROADCAST: int +INADDR_LOOPBACK: int +INADDR_MAX_LOCAL_GROUP: int +INADDR_NONE: int +INADDR_UNSPEC_GROUP: int +IPPORT_RESERVED: int +IPPORT_USERRESERVED: int +IPPROTO_AH: int +IPPROTO_BIP: int +IPPROTO_DSTOPTS: int +IPPROTO_EGP: int +IPPROTO_EON: int +IPPROTO_ESP: int +IPPROTO_FRAGMENT: int +IPPROTO_GGP: int +IPPROTO_GRE: int +IPPROTO_HELLO: int +IPPROTO_HOPOPTS: int +IPPROTO_ICMP: int +IPPROTO_ICMPV6: int +IPPROTO_IDP: int +IPPROTO_IGMP: int +IPPROTO_IP: int +IPPROTO_IPCOMP: int +IPPROTO_IPIP: int +IPPROTO_IPV4: int +IPPROTO_IPV6: int +IPPROTO_MAX: int +IPPROTO_MOBILE: int +IPPROTO_ND: int +IPPROTO_NONE: int +IPPROTO_PIM: int +IPPROTO_PUP: int +IPPROTO_RAW: int +IPPROTO_ROUTING: int +IPPROTO_RSVP: int +IPPROTO_SCTP: int +IPPROTO_TCP: int +IPPROTO_TP: int +IPPROTO_UDP: int +IPPROTO_VRRP: int +IPPROTO_XTP: int +IPV6_CHECKSUM: int +IPV6_DONTFRAG: int +IPV6_DSTOPTS: int +IPV6_HOPLIMIT: int +IPV6_HOPOPTS: int +IPV6_JOIN_GROUP: int +IPV6_LEAVE_GROUP: int +IPV6_MULTICAST_HOPS: int +IPV6_MULTICAST_IF: int +IPV6_MULTICAST_LOOP: int +IPV6_NEXTHOP: int +IPV6_PATHMTU: int +IPV6_PKTINFO: int +IPV6_RECVDSTOPTS: int +IPV6_RECVHOPLIMIT: int +IPV6_RECVHOPOPTS: int +IPV6_RECVPATHMTU: int +IPV6_RECVPKTINFO: int +IPV6_RECVRTHDR: int +IPV6_RECVTCLASS: int +IPV6_RTHDR: int +IPV6_RTHDR_TYPE_0: int +IPV6_RTHDRDSTOPTS: int +IPV6_TCLASS: int +IPV6_UNICAST_HOPS: int +IPV6_USE_MIN_MTU: int +IPV6_V6ONLY: int +IP_ADD_MEMBERSHIP: int +IP_DEFAULT_MULTICAST_LOOP: int +IP_DEFAULT_MULTICAST_TTL: int +IP_DROP_MEMBERSHIP: int +IP_HDRINCL: int +IP_MAX_MEMBERSHIPS: int +IP_MULTICAST_IF: int +IP_MULTICAST_LOOP: int +IP_MULTICAST_TTL: int +IP_OPTIONS: int +IP_RECVDSTADDR: int +IP_RECVOPTS: int +IP_RECVRETOPTS: int +IP_RETOPTS: int +IP_TOS: int +IP_TRANSPARENT: int +IP_TTL: int +IPX_TYPE: int +LOCAL_PEERCRED: int +MSG_BCAST: MsgFlag +MSG_BTAG: MsgFlag +MSG_CMSG_CLOEXEC: MsgFlag +MSG_CONFIRM: MsgFlag +MSG_CTRUNC: MsgFlag +MSG_DONTROUTE: MsgFlag +MSG_DONTWAIT: MsgFlag +MSG_EOF: MsgFlag +MSG_EOR: MsgFlag +MSG_ERRQUEUE: MsgFlag +MSG_ETAG: MsgFlag +MSG_FASTOPEN: MsgFlag +MSG_MCAST: MsgFlag +MSG_MORE: MsgFlag +MSG_NOSIGNAL: MsgFlag +MSG_NOTIFICATION: MsgFlag +MSG_OOB: MsgFlag +MSG_PEEK: MsgFlag +MSG_TRUNC: MsgFlag +MSG_WAITALL: MsgFlag +NETLINK_ARPD: int +NETLINK_CRYPTO: int +NETLINK_DNRTMSG: int +NETLINK_FIREWALL: int +NETLINK_IP6_FW: int +NETLINK_NFLOG: int +NETLINK_ROUTE6: int +NETLINK_ROUTE: int +NETLINK_SKIP: int +NETLINK_TAPBASE: int +NETLINK_TCPDIAG: int +NETLINK_USERSOCK: int +NETLINK_W1: int +NETLINK_XFRM: int +NI_DGRAM: int +NI_MAXHOST: int +NI_MAXSERV: int +NI_NAMEREQD: int +NI_NOFQDN: int +NI_NUMERICHOST: int +NI_NUMERICSERV: int +PACKET_BROADCAST: int +PACKET_FASTROUTE: int +PACKET_HOST: int +PACKET_LOOPBACK: int +PACKET_MULTICAST: int +PACKET_OTHERHOST: int +PACKET_OUTGOING: int +PF_CAN: int +PF_PACKET: int +PF_RDS: int +PF_SYSTEM: int +SCM_CREDENTIALS: int +SCM_CREDS: int +SCM_RIGHTS: int +SHUT_RD: int +SHUT_RDWR: int +SHUT_WR: int +SOL_ATALK: int +SOL_AX25: int +SOL_CAN_BASE: int +SOL_CAN_RAW: int +SOL_HCI: int +SOL_IP: int +SOL_IPX: int +SOL_NETROM: int +SOL_RDS: int +SOL_ROSE: int +SOL_SOCKET: int +SOL_TCP: int +SOL_TIPC: int +SOL_UDP: int +SO_ACCEPTCONN: int +SO_BINDTODEVICE: int +SO_BROADCAST: int +SO_DEBUG: int +SO_DONTROUTE: int +SO_ERROR: int +SO_EXCLUSIVEADDRUSE: int +SO_KEEPALIVE: int +SO_LINGER: int +SO_MARK: int +SO_OOBINLINE: int +SO_PASSCRED: int +SO_PEERCRED: int +SO_PRIORITY: int +SO_RCVBUF: int +SO_RCVLOWAT: int +SO_RCVTIMEO: int +SO_REUSEADDR: int +SO_REUSEPORT: int +SO_SETFIB: int +SO_SNDBUF: int +SO_SNDLOWAT: int +SO_SNDTIMEO: int +SO_TYPE: int +SO_USELOOPBACK: int +SYSPROTO_CONTROL: int +TCP_CORK: int +TCP_DEFER_ACCEPT: int +TCP_FASTOPEN: int +TCP_INFO: int +TCP_KEEPCNT: int +TCP_KEEPIDLE: int +TCP_KEEPINTVL: int +TCP_LINGER2: int +TCP_MAXSEG: int +TCP_NODELAY: int +TCP_NOTSENT_LOWAT: int +TCP_QUICKACK: int +TCP_SYNCNT: int +TCP_WINDOW_CLAMP: int +TIPC_ADDR_ID: int +TIPC_ADDR_NAME: int +TIPC_ADDR_NAMESEQ: int +TIPC_CFG_SRV: int +TIPC_CLUSTER_SCOPE: int +TIPC_CONN_TIMEOUT: int +TIPC_CRITICAL_IMPORTANCE: int +TIPC_DEST_DROPPABLE: int +TIPC_HIGH_IMPORTANCE: int +TIPC_IMPORTANCE: int +TIPC_LOW_IMPORTANCE: int +TIPC_MEDIUM_IMPORTANCE: int +TIPC_NODE_SCOPE: int +TIPC_PUBLISHED: int +TIPC_SRC_DROPPABLE: int +TIPC_SUB_CANCEL: int +TIPC_SUB_PORTS: int +TIPC_SUB_SERVICE: int +TIPC_SUBSCR_TIMEOUT: int +TIPC_TOP_SRV: int +TIPC_WAIT_FOREVER: int +TIPC_WITHDRAWN: int +TIPC_ZONE_SCOPE: int + +if sys.version_info >= (3, 3): + RDS_CANCEL_SENT_TO: int + RDS_CMSG_RDMA_ARGS: int + RDS_CMSG_RDMA_DEST: int + RDS_CMSG_RDMA_MAP: int + RDS_CMSG_RDMA_STATUS: int + RDS_CMSG_RDMA_UPDATE: int + RDS_CONG_MONITOR: int + RDS_FREE_MR: int + RDS_GET_MR: int + RDS_GET_MR_FOR_DEST: int + RDS_RDMA_DONTWAIT: int + RDS_RDMA_FENCE: int + RDS_RDMA_INVALIDATE: int + RDS_RDMA_NOTIFY_ME: int + RDS_RDMA_READWRITE: int + RDS_RDMA_SILENT: int + RDS_RDMA_USE_ONCE: int + RDS_RECVERR: int + +if sys.version_info >= (3, 4): + CAN_BCM: int + CAN_BCM_TX_SETUP: int + CAN_BCM_TX_DELETE: int + CAN_BCM_TX_READ: int + CAN_BCM_TX_SEND: int + CAN_BCM_RX_SETUP: int + CAN_BCM_RX_DELETE: int + CAN_BCM_RX_READ: int + CAN_BCM_TX_STATUS: int + CAN_BCM_TX_EXPIRED: int + CAN_BCM_RX_STATUS: int + CAN_BCM_RX_TIMEOUT: int + CAN_BCM_RX_CHANGED: int + AF_LINK: AddressFamily + +if sys.version_info >= (3, 5): + CAN_RAW_FD_FRAMES: int + +if sys.version_info >= (3, 6): + SO_DOMAIN: int + SO_PROTOCOL: int + SO_PEERSEC: int + SO_PASSSEC: int + TCP_USER_TIMEOUT: int + TCP_CONGESTION: int + AF_ALG: AddressFamily + SOL_ALG: int + ALG_SET_KEY: int + ALG_SET_IV: int + ALG_SET_OP: int + ALG_SET_AEAD_ASSOCLEN: int + ALG_SET_AEAD_AUTHSIZE: int + ALG_SET_PUBKEY: int + ALG_OP_DECRYPT: int + ALG_OP_ENCRYPT: int + ALG_OP_SIGN: int + ALG_OP_VERIFY: int + +if sys.platform == 'win32': + SIO_RCVALL: int + SIO_KEEPALIVE_VALS: int + RCVALL_IPLEVEL: int + RCVALL_MAX: int + RCVALL_OFF: int + RCVALL_ON: int + RCVALL_SOCKETLEVELONLY: int + + if sys.version_info >= (3, 6): + SIO_LOOPBACK_FAST_PATH: int + +# enum versions of above flags py 3.4+ +if sys.version_info >= (3, 4): + from enum import IntEnum + + class AddressFamily(IntEnum): + AF_UNIX = ... + AF_INET = ... + AF_INET6 = ... + AF_APPLETALK = ... + AF_ASH = ... + AF_ATMPVC = ... + AF_ATMSVC = ... + AF_AX25 = ... + AF_BLUETOOTH = ... + AF_BRIDGE = ... + AF_DECnet = ... + AF_ECONET = ... + AF_IPX = ... + AF_IRDA = ... + AF_KEY = ... + AF_LLC = ... + AF_NETBEUI = ... + AF_NETLINK = ... + AF_NETROM = ... + AF_PACKET = ... + AF_PPPOX = ... + AF_ROSE = ... + AF_ROUTE = ... + AF_SECURITY = ... + AF_SNA = ... + AF_TIPC = ... + AF_UNSPEC = ... + AF_WANPIPE = ... + AF_X25 = ... + AF_LINK = ... + + class SocketKind(IntEnum): + SOCK_STREAM = ... + SOCK_DGRAM = ... + SOCK_RAW = ... + SOCK_RDM = ... + SOCK_SEQPACKET = ... + SOCK_CLOEXEC = ... + SOCK_NONBLOCK = ... +else: + AddressFamily = int + SocketKind = int + +if sys.version_info >= (3, 6): + from enum import IntFlag + + class AddressInfo(IntFlag): + AI_ADDRCONFIG = ... + AI_ALL = ... + AI_CANONNAME = ... + AI_NUMERICHOST = ... + AI_NUMERICSERV = ... + AI_PASSIVE = ... + AI_V4MAPPED = ... + + class MsgFlag(IntFlag): + MSG_CTRUNC = ... + MSG_DONTROUTE = ... + MSG_DONTWAIT = ... + MSG_EOR = ... + MSG_OOB = ... + MSG_PEEK = ... + MSG_TRUNC = ... + MSG_WAITALL = ... +else: + AddressInfo = int + MsgFlag = int + + +# ----- exceptions ----- +class error(IOError): + ... + +class herror(error): + def __init__(self, herror: int, string: str) -> None: ... + +class gaierror(error): + def __init__(self, error: int, string: str) -> None: ... + +class timeout(error): + ... + + +# Addresses can be either tuples of varying lengths (AF_INET, AF_INET6, +# AF_NETLINK, AF_TIPC) or strings (AF_UNIX). + +# TODO AF_PACKET and AF_BLUETOOTH address objects + +_CMSG = Tuple[int, int, bytes] +_SelfT = TypeVar('_SelfT', bound=socket) + +# ----- classes ----- +class socket: + family: int + type: int + proto: int + + if sys.version_info < (3,): + def __init__(self, family: int = ..., type: int = ..., + proto: int = ...) -> None: ... + else: + def __init__(self, family: int = ..., type: int = ..., + proto: int = ..., fileno: Optional[int] = ...) -> None: ... + + if sys.version_info >= (3, 2): + def __enter__(self: _SelfT) -> _SelfT: ... + def __exit__(self, *args: Any) -> None: ... + + # --- methods --- + # second tuple item is an address + def accept(self) -> Tuple['socket', Any]: ... + def bind(self, address: Union[tuple, str, bytes]) -> None: ... + def close(self) -> None: ... + def connect(self, address: Union[tuple, str, bytes]) -> None: ... + def connect_ex(self, address: Union[tuple, str, bytes]) -> int: ... + def detach(self) -> int: ... + def fileno(self) -> int: ... + + # return value is an address + def getpeername(self) -> Any: ... + def getsockname(self) -> Any: ... + + @overload + def getsockopt(self, level: int, optname: int) -> int: ... + @overload + def getsockopt(self, level: int, optname: int, buflen: int) -> bytes: ... + + def gettimeout(self) -> float: ... + def ioctl(self, control: object, + option: Tuple[int, int, int]) -> None: ... + def listen(self, backlog: int) -> None: ... + # TODO the return value may be BinaryIO or TextIO, depending on mode + def makefile(self, mode: str = ..., buffering: int = ..., + encoding: str = ..., errors: str = ..., + newline: str = ...) -> Any: + ... + def recv(self, bufsize: int, flags: int = ...) -> bytes: ... + + # return type is an address + def recvfrom(self, bufsize: int, flags: int = ...) -> Any: ... + def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int, + flags: int = ...) -> Any: ... + def recv_into(self, buffer: _WriteBuffer, nbytes: int, + flags: int = ...) -> Any: ... + def send(self, data: bytes, flags: int = ...) -> int: ... + def sendall(self, data: bytes, flags: int =...) -> None: + ... # return type: None on success + @overload + def sendto(self, data: bytes, address: Union[tuple, str]) -> int: ... + @overload + def sendto(self, data: bytes, flags: int, address: Union[tuple, str]) -> int: ... + def setblocking(self, flag: bool) -> None: ... + def settimeout(self, value: Optional[float]) -> None: ... + def setsockopt(self, level: int, optname: int, value: Union[int, bytes]) -> None: ... + def shutdown(self, how: int) -> None: ... + + if sys.version_info >= (3, 3): + def recvmsg(self, __bufsize: int, __ancbufsize: int = ..., + __flags: int = ...) -> Tuple[bytes, List[_CMSG], int, Any]: ... + def recvmsg_into(self, __buffers: Iterable[_WriteBuffer], __ancbufsize: int = ..., + __flags: int = ...) -> Tuple[int, List[_CMSG], int, Any]: ... + def sendmsg(self, __buffers: Iterable[bytes], __ancdata: Iterable[_CMSG] = ..., + __flags: int = ..., __address: Any = ...) -> int: ... + + +# ----- functions ----- +def create_connection(address: Tuple[Optional[str], int], + timeout: float = ..., + source_address: Tuple[str, int] = ...) -> socket: ... + +# the 5th tuple item is an address +# TODO the "Tuple[Any, ...]" should be "Union[Tuple[str, int], Tuple[str, int, int, int]]" but that triggers +# https://github.com/python/mypy/issues/2509 +def getaddrinfo( + host: Optional[str], port: Union[str, int, None], family: int = ..., + socktype: int = ..., proto: int = ..., + flags: int = ...) -> List[Tuple[int, int, int, str, Tuple[Any, ...]]]: + ... + +def getfqdn(name: str = ...) -> str: ... +def gethostbyname(hostname: str) -> str: ... +def gethostbyname_ex(hostname: str) -> Tuple[str, List[str], List[str]]: ... +def gethostname() -> str: ... +def gethostbyaddr(ip_address: str) -> Tuple[str, List[str], List[str]]: ... +def getnameinfo(sockaddr: tuple, flags: int) -> Tuple[str, int]: ... +def getprotobyname(protocolname: str) -> int: ... +def getservbyname(servicename: str, protocolname: str = ...) -> int: ... +def getservbyport(port: int, protocolname: str = ...) -> str: ... +def socketpair(family: int = ..., + type: int = ..., + proto: int = ...) -> Tuple[socket, socket]: ... +def fromfd(fd: int, family: int, type: int, proto: int = ...) -> socket: ... +def ntohl(x: int) -> int: ... # param & ret val are 32-bit ints +def ntohs(x: int) -> int: ... # param & ret val are 16-bit ints +def htonl(x: int) -> int: ... # param & ret val are 32-bit ints +def htons(x: int) -> int: ... # param & ret val are 16-bit ints +def inet_aton(ip_string: str) -> bytes: ... # ret val 4 bytes in length +def inet_ntoa(packed_ip: bytes) -> str: ... +def inet_pton(address_family: int, ip_string: str) -> bytes: ... +def inet_ntop(address_family: int, packed_ip: bytes) -> str: ... +def getdefaulttimeout() -> Optional[float]: ... +def setdefaulttimeout(timeout: Optional[float]) -> None: ... + +if sys.version_info >= (3, 3): + def CMSG_LEN(length: int) -> int: ... + def CMSG_SPACE(length: int) -> int: ... + def sethostname(name: str) -> None: ... + def if_nameindex() -> List[Tuple[int, str]]: ... + def if_nametoindex(name: str) -> int: ... + def if_indextoname(index: int) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sqlite3/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sqlite3/__init__.pyi new file mode 100644 index 000000000..d5d20d67b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sqlite3/__init__.pyi @@ -0,0 +1 @@ +from sqlite3.dbapi2 import * # noqa: F403 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sqlite3/dbapi2.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sqlite3/dbapi2.pyi new file mode 100644 index 000000000..a131fc27e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sqlite3/dbapi2.pyi @@ -0,0 +1,275 @@ +# Filip Hron +# based heavily on Andrey Vlasovskikh's python-skeletons https://github.com/JetBrains/python-skeletons/blob/master/sqlite3.py + +import sys +from typing import Any, Callable, Iterable, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union +from datetime import date, time, datetime + +_T = TypeVar('_T') + +paramstyle: str +threadsafety: int +apilevel: str +Date = date +Time = time +Timestamp = datetime + +def DateFromTicks(ticks): ... +def TimeFromTicks(ticks): ... +def TimestampFromTicks(ticks): ... + +version_info: str +sqlite_version_info: Tuple[int, int, int] +if sys.version_info >= (3,): + Binary = memoryview +else: + Binary = buffer + +def register_adapters_and_converters(): ... + +# The remaining definitions are imported from _sqlite3. + +PARSE_COLNAMES = ... # type: int +PARSE_DECLTYPES = ... # type: int +SQLITE_ALTER_TABLE = ... # type: int +SQLITE_ANALYZE = ... # type: int +SQLITE_ATTACH = ... # type: int +SQLITE_CREATE_INDEX = ... # type: int +SQLITE_CREATE_TABLE = ... # type: int +SQLITE_CREATE_TEMP_INDEX = ... # type: int +SQLITE_CREATE_TEMP_TABLE = ... # type: int +SQLITE_CREATE_TEMP_TRIGGER = ... # type: int +SQLITE_CREATE_TEMP_VIEW = ... # type: int +SQLITE_CREATE_TRIGGER = ... # type: int +SQLITE_CREATE_VIEW = ... # type: int +SQLITE_DELETE = ... # type: int +SQLITE_DENY = ... # type: int +SQLITE_DETACH = ... # type: int +SQLITE_DROP_INDEX = ... # type: int +SQLITE_DROP_TABLE = ... # type: int +SQLITE_DROP_TEMP_INDEX = ... # type: int +SQLITE_DROP_TEMP_TABLE = ... # type: int +SQLITE_DROP_TEMP_TRIGGER = ... # type: int +SQLITE_DROP_TEMP_VIEW = ... # type: int +SQLITE_DROP_TRIGGER = ... # type: int +SQLITE_DROP_VIEW = ... # type: int +SQLITE_IGNORE = ... # type: int +SQLITE_INSERT = ... # type: int +SQLITE_OK = ... # type: int +SQLITE_PRAGMA = ... # type: int +SQLITE_READ = ... # type: int +SQLITE_REINDEX = ... # type: int +SQLITE_SELECT = ... # type: int +SQLITE_TRANSACTION = ... # type: int +SQLITE_UPDATE = ... # type: int +adapters = ... # type: Any +converters = ... # type: Any +sqlite_version = ... # type: str +version = ... # type: str + +# TODO: adapt needs to get probed +def adapt(obj, protocol, alternate): ... +def complete_statement(sql: str) -> bool: ... +if sys.version_info >= (3, 4): + def connect(database: Union[bytes, Text], + timeout: float = ..., + detect_types: int = ..., + isolation_level: Optional[str] = ..., + check_same_thread: bool = ..., + factory: Optional[Type[Connection]] = ..., + cached_statements: int = ..., + uri: bool = ...) -> Connection: ... +else: + def connect(database: Union[bytes, Text], + timeout: float = ..., + detect_types: int = ..., + isolation_level: Optional[str] = ..., + check_same_thread: bool = ..., + factory: Optional[Type[Connection]] = ..., + cached_statements: int = ...) -> Connection: ... +def enable_callback_tracebacks(flag: bool) -> None: ... +def enable_shared_cache(do_enable: int) -> None: ... +def register_adapter(type: Type[_T], callable: Callable[[_T], Union[int, float, str, bytes]]) -> None: ... +def register_converter(typename: str, callable: Callable[[bytes], Any]) -> None: ... + +class Cache(object): + def __init__(self, *args, **kwargs) -> None: ... + def display(self, *args, **kwargs) -> None: ... + def get(self, *args, **kwargs) -> None: ... + +class Connection(object): + DataError = ... # type: Any + DatabaseError = ... # type: Any + Error = ... # type: Any + IntegrityError = ... # type: Any + InterfaceError = ... # type: Any + InternalError = ... # type: Any + NotSupportedError = ... # type: Any + OperationalError = ... # type: Any + ProgrammingError = ... # type: Any + Warning = ... # type: Any + in_transaction = ... # type: Any + isolation_level = ... # type: Any + row_factory = ... # type: Any + text_factory = ... # type: Any + total_changes = ... # type: Any + def __init__(self, *args, **kwargs): ... + def close(self) -> None: ... + def commit(self) -> None: ... + def create_aggregate(self, name: str, num_params: int, aggregate_class: type) -> None: ... + def create_collation(self, name: str, callable: Any) -> None: ... + def create_function(self, name: str, num_params: int, func: Any) -> None: ... + def cursor(self, cursorClass: Optional[type] = ...) -> Cursor: ... + def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ... + # TODO: please check in executemany() if seq_of_parameters type is possible like this + def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]) -> Cursor: ... + def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ... + def interrupt(self, *args, **kwargs) -> None: ... + def iterdump(self, *args, **kwargs) -> None: ... + def rollback(self, *args, **kwargs) -> None: ... + # TODO: set_authorizer(authorzer_callback) + # see https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.set_authorizer + # returns [SQLITE_OK, SQLITE_DENY, SQLITE_IGNORE] so perhaps int + def set_authorizer(self, *args, **kwargs) -> None: ... + # set_progress_handler(handler, n) -> see https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.set_progress_handler + def set_progress_handler(self, *args, **kwargs) -> None: ... + def set_trace_callback(self, *args, **kwargs): ... + if sys.version_info >= (3, 7): + def backup(self, target: Connection, *, pages: int = ..., + progress: Optional[Callable[[int, int, int], object]] = ..., name: str = ..., + sleep: float = ...) -> None: ... + def __call__(self, *args, **kwargs): ... + def __enter__(self, *args, **kwargs): ... + def __exit__(self, *args, **kwargs): ... + +class Cursor(Iterator[Any]): + arraysize = ... # type: Any + connection = ... # type: Any + description = ... # type: Any + lastrowid = ... # type: Any + row_factory = ... # type: Any + rowcount = ... # type: Any + # TODO: Cursor class accepts exactly 1 argument + # required type is sqlite3.Connection (which is imported as _Connection) + # however, the name of the __init__ variable is unknown + def __init__(self, *args, **kwargs): ... + def close(self, *args, **kwargs): ... + def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ... + def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]): ... + def executescript(self, sql_script: Union[bytes, Text]) -> Cursor: ... + def fetchall(self) -> List[Any]: ... + def fetchmany(self, size: Optional[int] = ...) -> List[Any]: ... + def fetchone(self) -> Any: ... + def setinputsizes(self, *args, **kwargs): ... + def setoutputsize(self, *args, **kwargs): ... + def __iter__(self) -> Cursor: ... + if sys.version_info >= (3, 0): + def __next__(self) -> Any: ... + else: + def next(self) -> Any: ... + + +class DataError(DatabaseError): ... + +class DatabaseError(Error): ... + +class Error(Exception): ... + +class IntegrityError(DatabaseError): ... + +class InterfaceError(Error): ... + +class InternalError(DatabaseError): ... + +class NotSupportedError(DatabaseError): ... + +class OperationalError(DatabaseError): ... + +class OptimizedUnicode(object): + maketrans = ... # type: Any + def __init__(self, *args, **kwargs): ... + def capitalize(self, *args, **kwargs): ... + def casefold(self, *args, **kwargs): ... + def center(self, *args, **kwargs): ... + def count(self, *args, **kwargs): ... + def encode(self, *args, **kwargs): ... + def endswith(self, *args, **kwargs): ... + def expandtabs(self, *args, **kwargs): ... + def find(self, *args, **kwargs): ... + def format(self, *args, **kwargs): ... + def format_map(self, *args, **kwargs): ... + def index(self, *args, **kwargs): ... + def isalnum(self, *args, **kwargs): ... + def isalpha(self, *args, **kwargs): ... + def isdecimal(self, *args, **kwargs): ... + def isdigit(self, *args, **kwargs): ... + def isidentifier(self, *args, **kwargs): ... + def islower(self, *args, **kwargs): ... + def isnumeric(self, *args, **kwargs): ... + def isprintable(self, *args, **kwargs): ... + def isspace(self, *args, **kwargs): ... + def istitle(self, *args, **kwargs): ... + def isupper(self, *args, **kwargs): ... + def join(self, *args, **kwargs): ... + def ljust(self, *args, **kwargs): ... + def lower(self, *args, **kwargs): ... + def lstrip(self, *args, **kwargs): ... + def partition(self, *args, **kwargs): ... + def replace(self, *args, **kwargs): ... + def rfind(self, *args, **kwargs): ... + def rindex(self, *args, **kwargs): ... + def rjust(self, *args, **kwargs): ... + def rpartition(self, *args, **kwargs): ... + def rsplit(self, *args, **kwargs): ... + def rstrip(self, *args, **kwargs): ... + def split(self, *args, **kwargs): ... + def splitlines(self, *args, **kwargs): ... + def startswith(self, *args, **kwargs): ... + def strip(self, *args, **kwargs): ... + def swapcase(self, *args, **kwargs): ... + def title(self, *args, **kwargs): ... + def translate(self, *args, **kwargs): ... + def upper(self, *args, **kwargs): ... + def zfill(self, *args, **kwargs): ... + def __add__(self, other): ... + def __contains__(self, *args, **kwargs): ... + def __eq__(self, other): ... + def __format__(self, *args, **kwargs): ... + def __ge__(self, other): ... + def __getitem__(self, index): ... + def __getnewargs__(self, *args, **kwargs): ... + def __gt__(self, other): ... + def __hash__(self): ... + def __iter__(self): ... + def __le__(self, other): ... + def __len__(self, *args, **kwargs): ... + def __lt__(self, other): ... + def __mod__(self, other): ... + def __mul__(self, other): ... + def __ne__(self, other): ... + def __rmod__(self, other): ... + def __rmul__(self, other): ... + +class PrepareProtocol(object): + def __init__(self, *args, **kwargs): ... + +class ProgrammingError(DatabaseError): ... + +class Row(object): + def __init__(self, *args, **kwargs): ... + def keys(self, *args, **kwargs): ... + def __eq__(self, other): ... + def __ge__(self, other): ... + def __getitem__(self, index): ... + def __gt__(self, other): ... + def __hash__(self): ... + def __iter__(self): ... + def __le__(self, other): ... + def __len__(self, *args, **kwargs): ... + def __lt__(self, other): ... + def __ne__(self, other): ... + +class Statement(object): + def __init__(self, *args, **kwargs): ... + +class Warning(Exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sre_compile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sre_compile.pyi new file mode 100644 index 000000000..c74bd85f3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sre_compile.pyi @@ -0,0 +1,18 @@ +# Source: https://hg.python.org/cpython/file/2.7/Lib/sre_compile.py +# and https://github.com/python/cpython/blob/master/Lib/sre_compile.py + +import sys +from sre_parse import SubPattern +from typing import Any, List, Pattern, Tuple, Type, TypeVar, Union + +MAXCODE = ... # type: int +if sys.version_info < (3, 0): + STRING_TYPES: Tuple[Type[str], Type[unicode]] + _IsStringType = int +else: + from sre_constants import _NamedIntConstant + def dis(code: List[_NamedIntConstant]) -> None: ... + _IsStringType = bool + +def isstring(obj: Any) -> _IsStringType: ... +def compile(p: Union[str, bytes, SubPattern], flags: int = ...) -> Pattern: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ssl.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ssl.pyi new file mode 100644 index 000000000..1399f1272 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/ssl.pyi @@ -0,0 +1,307 @@ +# Stubs for ssl + +from typing import ( + Any, Dict, Callable, List, NamedTuple, Optional, Set, Tuple, Union, +) +import socket +import sys + +_PCTRTT = Tuple[Tuple[str, str], ...] +_PCTRTTT = Tuple[_PCTRTT, ...] +_PeerCertRetDictType = Dict[str, Union[str, _PCTRTTT, _PCTRTT]] +_PeerCertRetType = Union[_PeerCertRetDictType, bytes, None] +_EnumRetType = List[Tuple[bytes, str, Union[Set[str], bool]]] +_PasswordType = Union[Callable[[], Union[str, bytes]], str, bytes] + +if sys.version_info >= (3, 5): + _SC1ArgT = Union[SSLSocket, SSLObject] +else: + _SC1ArgT = SSLSocket +_SrvnmeCbType = Callable[[_SC1ArgT, Optional[str], SSLSocket], Optional[int]] + +class SSLError(OSError): + library: str + reason: str +class SSLZeroReturnError(SSLError): ... +class SSLWantReadError(SSLError): ... +class SSLWantWriteError(SSLError): ... +class SSLSyscallError(SSLError): ... +class SSLEOFError(SSLError): ... +class CertificateError(Exception): ... + + +def wrap_socket(sock: socket.socket, keyfile: Optional[str] = ..., + certfile: Optional[str] = ..., server_side: bool = ..., + cert_reqs: int = ..., ssl_version: int = ..., + ca_certs: Optional[str] = ..., + do_handshake_on_connect: bool = ..., + suppress_ragged_eofs: bool = ..., + ciphers: Optional[str] = ...) -> SSLSocket: ... + + +if sys.version_info < (3,) or sys.version_info >= (3, 4): + def create_default_context(purpose: Any = ..., *, + cafile: Optional[str] = ..., + capath: Optional[str] = ..., + cadata: Optional[str] = ...) -> SSLContext: ... + +if sys.version_info >= (3, 4): + def _create_unverified_context(protocol: int = ..., *, + cert_reqs: int = ..., + check_hostname: bool = ..., + purpose: Any = ..., + certfile: Optional[str] = ..., + keyfile: Optional[str] = ..., + cafile: Optional[str] = ..., + capath: Optional[str] = ..., + cadata: Optional[str] = ...) -> SSLContext: ... + _create_default_https_context: Callable[..., SSLContext] + +if sys.version_info >= (3, 3): + def RAND_bytes(num: int) -> bytes: ... + def RAND_pseudo_bytes(num: int) -> Tuple[bytes, bool]: ... +def RAND_status() -> bool: ... +def RAND_egd(path: str) -> None: ... +def RAND_add(bytes: bytes, entropy: float) -> None: ... + + +def match_hostname(cert: _PeerCertRetType, hostname: str) -> None: ... +def cert_time_to_seconds(cert_time: str) -> int: ... +def get_server_certificate(addr: Tuple[str, int], ssl_version: int = ..., + ca_certs: Optional[str] = ...) -> str: ... +def DER_cert_to_PEM_cert(der_cert_bytes: bytes) -> str: ... +def PEM_cert_to_DER_cert(pem_cert_string: str) -> bytes: ... +if sys.version_info < (3,) or sys.version_info >= (3, 4): + DefaultVerifyPaths = NamedTuple('DefaultVerifyPaths', + [('cafile', str), ('capath', str), + ('openssl_cafile_env', str), + ('openssl_cafile', str), + ('openssl_capath_env', str), + ('openssl_capath', str)]) + def get_default_verify_paths() -> DefaultVerifyPaths: ... + +if sys.platform == 'win32': + if sys.version_info < (3,) or sys.version_info >= (3, 4): + def enum_certificates(store_name: str) -> _EnumRetType: ... + def enum_crls(store_name: str) -> _EnumRetType: ... + + +CERT_NONE: int +CERT_OPTIONAL: int +CERT_REQUIRED: int + +if sys.version_info < (3,) or sys.version_info >= (3, 4): + VERIFY_DEFAULT: int + VERIFY_CRL_CHECK_LEAF: int + VERIFY_CRL_CHECK_CHAIN: int + VERIFY_X509_STRICT: int + VERIFY_X509_TRUSTED_FIRST: int + +PROTOCOL_SSLv23: int +PROTOCOL_SSLv2: int +PROTOCOL_SSLv3: int +PROTOCOL_TLSv1: int +if sys.version_info < (3,) or sys.version_info >= (3, 4): + PROTOCOL_TLSv1_1: int + PROTOCOL_TLSv1_2: int +if sys.version_info >= (3, 5): + PROTOCOL_TLS: int +if sys.version_info >= (3, 6): + PROTOCOL_TLS_CLIENT: int + PROTOCOL_TLS_SERVER: int + +OP_ALL: int +OP_NO_SSLv2: int +OP_NO_SSLv3: int +OP_NO_TLSv1: int +if sys.version_info < (3,) or sys.version_info >= (3, 4): + OP_NO_TLSv1_1: int + OP_NO_TLSv1_2: int +OP_CIPHER_SERVER_PREFERENCE: int +OP_SINGLE_DH_USE: int +OP_SINGLE_ECDH_USE: int +OP_NO_COMPRESSION: int +if sys.version_info >= (3, 6): + OP_NO_TICKET: int + +if sys.version_info < (3,) or sys.version_info >= (3, 5): + HAS_ALPN: int +HAS_ECDH: bool +HAS_SNI: bool +HAS_NPN: bool +CHANNEL_BINDING_TYPES: List[str] + +OPENSSL_VERSION: str +OPENSSL_VERSION_INFO: Tuple[int, int, int, int, int] +OPENSSL_VERSION_NUMBER: int + +if sys.version_info < (3,) or sys.version_info >= (3, 4): + ALERT_DESCRIPTION_HANDSHAKE_FAILURE: int + ALERT_DESCRIPTION_INTERNAL_ERROR: int + ALERT_DESCRIPTION_ACCESS_DENIED: int + ALERT_DESCRIPTION_BAD_CERTIFICATE: int + ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: int + ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: int + ALERT_DESCRIPTION_BAD_RECORD_MAC: int + ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: int + ALERT_DESCRIPTION_CERTIFICATE_REVOKED: int + ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: int + ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: int + ALERT_DESCRIPTION_CLOSE_NOTIFY: int + ALERT_DESCRIPTION_DECODE_ERROR: int + ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: int + ALERT_DESCRIPTION_DECRYPT_ERROR: int + ALERT_DESCRIPTION_ILLEGAL_PARAMETER: int + ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: int + ALERT_DESCRIPTION_NO_RENEGOTIATION: int + ALERT_DESCRIPTION_PROTOCOL_VERSION: int + ALERT_DESCRIPTION_RECORD_OVERFLOW: int + ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: int + ALERT_DESCRIPTION_UNKNOWN_CA: int + ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: int + ALERT_DESCRIPTION_UNRECOGNIZED_NAME: int + ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int + ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int + ALERT_DESCRIPTION_USER_CANCELLED: int + +if sys.version_info < (3,) or sys.version_info >= (3, 4): + _PurposeType = NamedTuple('_PurposeType', + [('nid', int), ('shortname', str), + ('longname', str), ('oid', str)]) + class Purpose: + SERVER_AUTH: _PurposeType + CLIENT_AUTH: _PurposeType + + +class SSLSocket(socket.socket): + context: SSLContext + server_side: bool + server_hostname: Optional[str] + if sys.version_info >= (3, 6): + session: Optional[SSLSession] + session_reused: Optional[bool] + + def read(self, len: int = ..., + buffer: Optional[bytearray] = ...) -> bytes: ... + def write(self, buf: bytes) -> int: ... + def do_handshake(self) -> None: ... + def getpeercert(self, binary_form: bool = ...) -> _PeerCertRetType: ... + def cipher(self) -> Tuple[str, int, int]: ... + if sys.version_info >= (3, 5): + def shared_cipher(self) -> Optional[List[Tuple[str, int, int]]]: ... + def compression(self) -> Optional[str]: ... + def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ... + if sys.version_info < (3,) or sys.version_info >= (3, 5): + def selected_alpn_protocol(self) -> Optional[str]: ... + def selected_npn_protocol(self) -> Optional[str]: ... + def unwrap(self) -> socket.socket: ... + if sys.version_info < (3,) or sys.version_info >= (3, 5): + def version(self) -> Optional[str]: ... + def pending(self) -> int: ... + + +class SSLContext: + if sys.version_info < (3,) or sys.version_info >= (3, 4): + check_hostname: bool + options: int + @property + def protocol(self) -> int: ... + if sys.version_info < (3,) or sys.version_info >= (3, 4): + verify_flags: int + verify_mode: int + if sys.version_info >= (3, 5): + def __init__(self, protocol: int = ...) -> None: ... + else: + def __init__(self, protocol: int) -> None: ... + if sys.version_info < (3,) or sys.version_info >= (3, 4): + def cert_store_stats(self) -> Dict[str, int]: ... + def load_cert_chain(self, certfile: str, keyfile: Optional[str] = ..., + password: _PasswordType = ...) -> None: ... + if sys.version_info < (3,) or sys.version_info >= (3, 4): + def load_default_certs(self, purpose: _PurposeType = ...) -> None: ... + def load_verify_locations(self, cafile: Optional[str] = ..., + capath: Optional[str] = ..., + cadata: Union[str, bytes, None] = ...) -> None: ... + def get_ca_certs(self, + binary_form: bool = ...) -> Union[List[_PeerCertRetDictType], List[bytes]]: ... + else: + def load_verify_locations(self, + cafile: Optional[str] = ..., + capath: Optional[str] = ...) -> None: ... + def set_default_verify_paths(self) -> None: ... + def set_ciphers(self, ciphers: str) -> None: ... + if sys.version_info < (3,) or sys.version_info >= (3, 5): + def set_alpn_protocols(self, protocols: List[str]) -> None: ... + def set_npn_protocols(self, protocols: List[str]) -> None: ... + def set_servername_callback(self, + server_name_callback: Optional[_SrvnmeCbType]) -> None: ... + def load_dh_params(self, dhfile: str) -> None: ... + def set_ecdh_curve(self, curve_name: str) -> None: ... + def wrap_socket(self, sock: socket.socket, server_side: bool = ..., + do_handshake_on_connect: bool = ..., + suppress_ragged_eofs: bool = ..., + server_hostname: Optional[str] = ...) -> SSLSocket: ... + if sys.version_info >= (3, 5): + def wrap_bio(self, incoming: MemoryBIO, outgoing: MemoryBIO, + server_side: bool = ..., + server_hostname: Optional[str] = ...) -> SSLObject: ... + def session_stats(self) -> Dict[str, int]: ... + + +if sys.version_info >= (3, 5): + class SSLObject: + context: SSLContext + server_side: bool + server_hostname: Optional[str] + if sys.version_info >= (3, 6): + session: Optional[SSLSession] + session_reused: bool + def read(self, len: int = ..., + buffer: Optional[bytearray] = ...) -> bytes: ... + def write(self, buf: bytes) -> int: ... + def getpeercert(self, binary_form: bool = ...) -> _PeerCertRetType: ... + def selected_npn_protocol(self) -> Optional[str]: ... + def cipher(self) -> Tuple[str, int, int]: ... + def shared_cipher(self) -> Optional[List[Tuple[str, int, int]]]: ... + def compression(self) -> Optional[str]: ... + def pending(self) -> int: ... + def do_handshake(self) -> None: ... + def unwrap(self) -> None: ... + def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ... + + class MemoryBIO: + pending: int + eof: bool + def read(self, n: int = ...) -> bytes: ... + def write(self, buf: bytes) -> int: ... + def write_eof(self) -> None: ... + +if sys.version_info >= (3, 6): + class SSLSession: + id: bytes + time: int + timeout: int + ticket_lifetime_hint: int + has_ticket: bool + + +# TODO below documented in cpython but not in docs.python.org +# taken from python 3.4 +SSL_ERROR_EOF: int +SSL_ERROR_INVALID_ERROR_CODE: int +SSL_ERROR_SSL: int +SSL_ERROR_SYSCALL: int +SSL_ERROR_WANT_CONNECT: int +SSL_ERROR_WANT_READ: int +SSL_ERROR_WANT_WRITE: int +SSL_ERROR_WANT_X509_LOOKUP: int +SSL_ERROR_ZERO_RETURN: int + +def get_protocol_name(protocol_code: int) -> str: ... + +AF_INET: int +PEM_FOOTER: str +PEM_HEADER: str +SOCK_STREAM: int +SOL_SOCKET: int +SO_TYPE: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/stringprep.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/stringprep.pyi new file mode 100644 index 000000000..e3b7e9dc2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/stringprep.pyi @@ -0,0 +1,23 @@ +# Stubs for stringprep (Python 2 and 3) + +from typing import Text + +def in_table_a1(code: Text) -> bool: ... +def in_table_b1(code: Text) -> bool: ... +def map_table_b3(code: Text) -> Text: ... +def map_table_b2(a: Text) -> Text: ... +def in_table_c11(code: Text) -> bool: ... +def in_table_c12(code: Text) -> bool: ... +def in_table_c11_c12(code: Text) -> bool: ... +def in_table_c21(code: Text) -> bool: ... +def in_table_c22(code: Text) -> bool: ... +def in_table_c21_c22(code: Text) -> bool: ... +def in_table_c3(code: Text) -> bool: ... +def in_table_c4(code: Text) -> bool: ... +def in_table_c5(code: Text) -> bool: ... +def in_table_c6(code: Text) -> bool: ... +def in_table_c7(code: Text) -> bool: ... +def in_table_c8(code: Text) -> bool: ... +def in_table_c9(code: Text) -> bool: ... +def in_table_d1(code: Text) -> bool: ... +def in_table_d2(code: Text) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/struct.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/struct.pyi new file mode 100644 index 000000000..cbc5e8315 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/struct.pyi @@ -0,0 +1,43 @@ +# Stubs for struct + +# Based on http://docs.python.org/3.2/library/struct.html +# Based on http://docs.python.org/2/library/struct.html + +import sys +from typing import Any, Tuple, Text, Union, Iterator +from array import array + +class error(Exception): ... + +_FmtType = Union[bytes, Text] +if sys.version_info >= (3,): + _BufferType = Union[bytes, bytearray, memoryview] + _WriteBufferType = Union[array, bytearray, memoryview] +else: + _BufferType = Union[bytes, bytearray, buffer, memoryview] + _WriteBufferType = Union[array[Any], bytearray, buffer, memoryview] + +def pack(fmt: _FmtType, *v: Any) -> bytes: ... +def pack_into(fmt: _FmtType, buffer: _WriteBufferType, offset: int, *v: Any) -> None: ... +def unpack(fmt: _FmtType, buffer: _BufferType) -> Tuple[Any, ...]: ... +def unpack_from(fmt: _FmtType, buffer: _BufferType, offset: int = ...) -> Tuple[Any, ...]: ... +if sys.version_info >= (3, 4): + def iter_unpack(fmt: _FmtType, buffer: _BufferType) -> Iterator[Tuple[Any, ...]]: ... + +def calcsize(fmt: _FmtType) -> int: ... + +class Struct: + if sys.version_info >= (3, 7): + format: str + else: + format: bytes + size = ... # type: int + + def __init__(self, format: _FmtType) -> None: ... + + def pack(self, *v: Any) -> bytes: ... + def pack_into(self, buffer: _WriteBufferType, offset: int, *v: Any) -> None: ... + def unpack(self, buffer: _BufferType) -> Tuple[Any, ...]: ... + def unpack_from(self, buffer: _BufferType, offset: int = ...) -> Tuple[Any, ...]: ... + if sys.version_info >= (3, 4): + def iter_unpack(self, buffer: _BufferType) -> Iterator[Tuple[Any, ...]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sunau.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sunau.pyi new file mode 100644 index 000000000..829fbe6db --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sunau.pyi @@ -0,0 +1,87 @@ +# Stubs for sunau (Python 2 and 3) + +import sys +from typing import Any, NamedTuple, NoReturn, Optional, Text, IO, Union, Tuple + +_File = Union[Text, IO[bytes]] + +class Error(Exception): ... + +AUDIO_FILE_MAGIC = ... # type: int +AUDIO_FILE_ENCODING_MULAW_8 = ... # type: int +AUDIO_FILE_ENCODING_LINEAR_8 = ... # type: int +AUDIO_FILE_ENCODING_LINEAR_16 = ... # type: int +AUDIO_FILE_ENCODING_LINEAR_24 = ... # type: int +AUDIO_FILE_ENCODING_LINEAR_32 = ... # type: int +AUDIO_FILE_ENCODING_FLOAT = ... # type: int +AUDIO_FILE_ENCODING_DOUBLE = ... # type: int +AUDIO_FILE_ENCODING_ADPCM_G721 = ... # type: int +AUDIO_FILE_ENCODING_ADPCM_G722 = ... # type: int +AUDIO_FILE_ENCODING_ADPCM_G723_3 = ... # type: int +AUDIO_FILE_ENCODING_ADPCM_G723_5 = ... # type: int +AUDIO_FILE_ENCODING_ALAW_8 = ... # type: int +AUDIO_UNKNOWN_SIZE = ... # type: int + +if sys.version_info < (3, 0): + _sunau_params = Tuple[int, int, int, int, str, str] +else: + _sunau_params = NamedTuple('_sunau_params', [ + ('nchannels', int), + ('sampwidth', int), + ('framerate', int), + ('nframes', int), + ('comptype', str), + ('compname', str), + ]) + +class Au_read: + def __init__(self, f: _File) -> None: ... + if sys.version_info >= (3, 3): + def __enter__(self) -> Au_read: ... + def __exit__(self, *args: Any) -> None: ... + def getfp(self) -> Optional[IO[bytes]]: ... + def rewind(self) -> None: ... + def close(self) -> None: ... + def tell(self) -> int: ... + def getnchannels(self) -> int: ... + def getnframes(self) -> int: ... + def getsampwidth(self) -> int: ... + def getframerate(self) -> int: ... + def getcomptype(self) -> str: ... + def getcompname(self) -> str: ... + def getparams(self) -> _sunau_params: ... + def getmarkers(self) -> None: ... + def getmark(self, id: Any) -> NoReturn: ... + def setpos(self, pos: int) -> None: ... + def readframes(self, nframes: int) -> Optional[bytes]: ... + +class Au_write: + def __init__(self, f: _File) -> None: ... + if sys.version_info >= (3, 3): + def __enter__(self) -> Au_write: ... + def __exit__(self, *args: Any) -> None: ... + def setnchannels(self, nchannels: int) -> None: ... + def getnchannels(self) -> int: ... + def setsampwidth(self, sampwidth: int) -> None: ... + def getsampwidth(self) -> int: ... + def setframerate(self, framerate: float) -> None: ... + def getframerate(self) -> int: ... + def setnframes(self, nframes: int) -> None: ... + def getnframes(self) -> int: ... + def setcomptype(self, comptype: str, compname: str) -> None: ... + def getcomptype(self) -> str: ... + def getcompname(self) -> str: ... + def setparams(self, params: _sunau_params) -> None: ... + def getparams(self) -> _sunau_params: ... + def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... + def getmark(self, id: Any) -> NoReturn: ... + def getmarkers(self) -> None: ... + def tell(self) -> int: ... + # should be any bytes-like object after 3.4, but we don't have a type for that + def writeframesraw(self, data: bytes) -> None: ... + def writeframes(self, data: bytes) -> None: ... + def close(self) -> None: ... + +# Returns a Au_read if mode is rb and Au_write if mode is wb +def open(f: _File, mode: Optional[str] = ...) -> Any: ... +openfp = open diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/symtable.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/symtable.pyi new file mode 100644 index 000000000..fd8b9ad79 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/symtable.pyi @@ -0,0 +1,45 @@ +import sys +from typing import List, Sequence, Tuple, Text + +def symtable(code: Text, filename: Text, compile_type: Text) -> SymbolTable: ... + +class SymbolTable(object): + def get_type(self) -> str: ... + def get_id(self) -> int: ... + def get_name(self) -> str: ... + def get_lineno(self) -> int: ... + def is_optimized(self) -> bool: ... + def is_nested(self) -> bool: ... + def has_children(self) -> bool: ... + def has_exec(self) -> bool: ... + if sys.version_info < (3, 0): + def has_import_star(self) -> bool: ... + def get_identifiers(self) -> Sequence[str]: ... + def lookup(self, name: str) -> Symbol: ... + def get_symbols(self) -> List[Symbol]: ... + def get_children(self) -> List[SymbolTable]: ... + +class Function(SymbolTable): + def get_parameters(self) -> Tuple[str, ...]: ... + def get_locals(self) -> Tuple[str, ...]: ... + def get_globals(self) -> Tuple[str, ...]: ... + def get_frees(self) -> Tuple[str, ...]: ... + +class Class(SymbolTable): + def get_methods(self) -> Tuple[str, ...]: ... + +class Symbol(object): + def get_name(self) -> str: ... + def is_referenced(self) -> bool: ... + def is_parameter(self) -> bool: ... + def is_global(self) -> bool: ... + def is_declared_global(self) -> bool: ... + def is_local(self) -> bool: ... + if sys.version_info >= (3, 6): + def is_annotated(self) -> bool: ... + def is_free(self) -> bool: ... + def is_imported(self) -> bool: ... + def is_assigned(self) -> bool: ... + def is_namespace(self) -> bool: ... + def get_namespaces(self) -> Sequence[SymbolTable]: ... + def get_namespace(self) -> SymbolTable: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sysconfig.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sysconfig.pyi new file mode 100644 index 000000000..5d6c9cb19 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/sysconfig.pyi @@ -0,0 +1,19 @@ +# Stubs for sysconfig + +from typing import overload, Any, Dict, IO, List, Optional, Tuple, Union + +@overload +def get_config_vars() -> Dict[str, Any]: ... +@overload +def get_config_vars(arg: str, *args: str) -> List[Any]: ... +def get_config_var(name: str) -> Optional[str]: ... +def get_scheme_names() -> Tuple[str, ...]: ... +def get_path_names() -> Tuple[str, ...]: ... +def get_path(name: str, scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> Optional[str]: ... +def get_paths(scheme: str = ..., vars: Optional[Dict[str, Any]] = ..., expand: bool = ...) -> Dict[str, str]: ... +def get_python_version() -> str: ... +def get_platform() -> str: ... +def is_python_build() -> bool: ... +def parse_config_h(fp: IO[Any], vars: Optional[Dict[str, Any]]) -> Dict[str, Any]: ... +def get_config_h_filename() -> str: ... +def get_makefile_filename() -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/syslog.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/syslog.pyi new file mode 100644 index 000000000..15534e7cb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/syslog.pyi @@ -0,0 +1,44 @@ +from typing import overload + +LOG_ALERT = ... # type: int +LOG_AUTH = ... # type: int +LOG_CONS = ... # type: int +LOG_CRIT = ... # type: int +LOG_CRON = ... # type: int +LOG_DAEMON = ... # type: int +LOG_DEBUG = ... # type: int +LOG_EMERG = ... # type: int +LOG_ERR = ... # type: int +LOG_INFO = ... # type: int +LOG_KERN = ... # type: int +LOG_LOCAL0 = ... # type: int +LOG_LOCAL1 = ... # type: int +LOG_LOCAL2 = ... # type: int +LOG_LOCAL3 = ... # type: int +LOG_LOCAL4 = ... # type: int +LOG_LOCAL5 = ... # type: int +LOG_LOCAL6 = ... # type: int +LOG_LOCAL7 = ... # type: int +LOG_LPR = ... # type: int +LOG_MAIL = ... # type: int +LOG_NDELAY = ... # type: int +LOG_NEWS = ... # type: int +LOG_NOTICE = ... # type: int +LOG_NOWAIT = ... # type: int +LOG_PERROR = ... # type: int +LOG_PID = ... # type: int +LOG_SYSLOG = ... # type: int +LOG_USER = ... # type: int +LOG_UUCP = ... # type: int +LOG_WARNING = ... # type: int + +def LOG_MASK(a: int) -> int: ... +def LOG_UPTO(a: int) -> int: ... +def closelog() -> None: ... +def openlog(ident: str = ..., logoption: int = ..., facility: int = ...) -> None: ... +def setlogmask(x: int) -> int: ... + +@overload +def syslog(priority: int, message: str) -> None: ... +@overload +def syslog(message: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tabnanny.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tabnanny.pyi new file mode 100644 index 000000000..5209ef8f4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tabnanny.pyi @@ -0,0 +1,22 @@ +# Stubs for tabnanny (Python 2 and 3) + +import os +import sys +from typing import Iterable, Tuple, Union + +if sys.version_info >= (3, 6): + _Path = Union[str, bytes, os.PathLike] +else: + _Path = Union[str, bytes] + +verbose = ... # type: int +filename_only = ... # type: int + +class NannyNag(Exception): + def __init__(self, lineno: int, msg: str, line: str) -> None: ... + def get_lineno(self) -> int: ... + def get_msg(self) -> str: ... + def get_line(self) -> str: ... + +def check(file: _Path) -> None: ... +def process_tokens(tokens: Iterable[Tuple[int, str, Tuple[int, int], Tuple[int, int], str]]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tarfile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tarfile.pyi new file mode 100644 index 000000000..02cb57970 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tarfile.pyi @@ -0,0 +1,192 @@ +# Stubs for tarfile + +from typing import ( + Callable, IO, Iterable, Iterator, List, Mapping, Optional, Type, + Union, +) +import os +import sys +from types import TracebackType + + +if sys.version_info >= (3, 6): + _Path = Union[bytes, str, os.PathLike] +elif sys.version_info >= (3,): + _Path = Union[bytes, str] +else: + _Path = Union[str, unicode] + +ENCODING = ... # type: str + +USTAR_FORMAT = ... # type: int +GNU_FORMAT = ... # type: int +PAX_FORMAT = ... # type: int +DEFAULT_FORMAT = ... # type: int + +REGTYPE = ... # type: bytes +AREGTYPE = ... # type: bytes +LNKTYPE = ... # type: bytes +SYMTYPE = ... # type: bytes +DIRTYPE = ... # type: bytes +FIFOTYPE = ... # type: bytes +CONTTYPE = ... # type: bytes +CHRTYPE = ... # type: bytes +BLKTYPE = ... # type: bytes +GNUTYPE_SPARSE = ... # type: bytes + +if sys.version_info < (3,): + TAR_PLAIN = ... # type: int + TAR_GZIPPED = ... # type: int + +def open(name: Optional[_Path] = ..., mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., bufsize: int = ..., + *, format: Optional[int] = ..., tarinfo: Optional[TarInfo] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., errors: str = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ..., + compresslevel: Optional[int] = ...) -> TarFile: ... + + +class TarFile(Iterable[TarInfo]): + name = ... # type: Optional[_Path] + mode = ... # type: str + fileobj = ... # type: Optional[IO[bytes]] + format = ... # type: Optional[int] + tarinfo = ... # type: Optional[TarInfo] + dereference = ... # type: Optional[bool] + ignore_zeros = ... # type: Optional[bool] + encoding = ... # type: Optional[str] + errors = ... # type: str + pax_headers = ... # type: Optional[Mapping[str, str]] + debug = ... # type: Optional[int] + errorlevel = ... # type: Optional[int] + if sys.version_info < (3,): + posix = ... # type: bool + def __init__(self, name: Optional[_Path] = ..., mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., + format: Optional[int] = ..., tarinfo: Optional[TarInfo] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., errors: str = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ..., + compresslevel: Optional[int] = ...) -> None: ... + def __enter__(self) -> TarFile: ... + def __exit__(self, + exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... + def __iter__(self) -> Iterator[TarInfo]: ... + @classmethod + def open(cls, name: Optional[_Path] = ..., mode: str = ..., + fileobj: Optional[IO[bytes]] = ..., bufsize: int = ..., + *, format: Optional[int] = ..., tarinfo: Optional[TarInfo] = ..., + dereference: Optional[bool] = ..., + ignore_zeros: Optional[bool] = ..., + encoding: Optional[str] = ..., errors: str = ..., + pax_headers: Optional[Mapping[str, str]] = ..., + debug: Optional[int] = ..., + errorlevel: Optional[int] = ...) -> TarFile: ... + def getmember(self, name: str) -> TarInfo: ... + def getmembers(self) -> List[TarInfo]: ... + def getnames(self) -> List[str]: ... + if sys.version_info >= (3, 5): + def list(self, verbose: bool = ..., + *, members: Optional[List[TarInfo]] = ...) -> None: ... + else: + def list(self, verbose: bool = ...) -> None: ... + def next(self) -> Optional[TarInfo]: ... + if sys.version_info >= (3, 5): + def extractall(self, path: _Path = ..., + members: Optional[List[TarInfo]] = ..., + *, numeric_owner: bool = ...) -> None: ... + else: + def extractall(self, path: _Path = ..., + members: Optional[List[TarInfo]] = ...) -> None: ... + if sys.version_info >= (3, 5): + def extract(self, member: Union[str, TarInfo], path: _Path = ..., + set_attrs: bool = ..., + *, numeric_owner: bool = ...) -> None: ... + elif sys.version_info >= (3,): + def extract(self, member: Union[str, TarInfo], path: _Path = ..., + set_attrs: bool = ...) -> None: ... + else: + def extract(self, member: Union[str, TarInfo], + path: _Path = ...) -> None: ... + def extractfile(self, + member: Union[str, TarInfo]) -> Optional[IO[bytes]]: ... + if sys.version_info >= (3, 7): + def add(self, name: str, arcname: Optional[str] = ..., + recursive: bool = ..., *, + filter: Optional[Callable[[TarInfo], Optional[TarInfo]]] = ...) -> None: ... + elif sys.version_info >= (3,): + def add(self, name: str, arcname: Optional[str] = ..., + recursive: bool = ..., + exclude: Optional[Callable[[str], bool]] = ..., *, + filter: Optional[Callable[[TarInfo], Optional[TarInfo]]] = ...) -> None: ... + else: + def add(self, name: str, arcname: Optional[str] = ..., + recursive: bool = ..., + exclude: Optional[Callable[[str], bool]] = ..., + filter: Optional[Callable[[TarInfo], Optional[TarInfo]]] = ...) -> None: ... + def addfile(self, tarinfo: TarInfo, + fileobj: Optional[IO[bytes]] = ...) -> None: ... + def gettarinfo(self, name: Optional[str] = ..., + arcname: Optional[str] = ..., + fileobj: Optional[IO[bytes]] = ...) -> TarInfo: ... + def close(self) -> None: ... + + +def is_tarfile(name: str) -> bool: ... + + +if sys.version_info < (3,): + class TarFileCompat: + def __init__(self, filename: str, mode: str = ..., + compression: int = ...) -> None: ... + + +class TarError(Exception): ... +class ReadError(TarError): ... +class CompressionError(TarError): ... +class StreamError(TarError): ... +class ExtractError(TarError): ... +class HeaderError(TarError): ... + + +class TarInfo: + name = ... # type: str + size = ... # type: int + mtime = ... # type: int + mode = ... # type: int + type = ... # type: bytes + linkname = ... # type: str + uid = ... # type: int + gid = ... # type: int + uname = ... # type: str + gname = ... # type: str + pax_headers = ... # type: Mapping[str, str] + def __init__(self, name: str = ...) -> None: ... + if sys.version_info >= (3,): + @classmethod + def frombuf(cls, buf: bytes, encoding: str, errors: str) -> TarInfo: ... + else: + @classmethod + def frombuf(cls, buf: bytes) -> TarInfo: ... + @classmethod + def fromtarfile(cls, tarfile: TarFile) -> TarInfo: ... + def tobuf(self, format: Optional[int] = ..., + encoding: Optional[str] = ..., errors: str = ...) -> bytes: ... + def isfile(self) -> bool: ... + def isreg(self) -> bool: ... + def isdir(self) -> bool: ... + def issym(self) -> bool: ... + def islnk(self) -> bool: ... + def ischr(self) -> bool: ... + def isblk(self) -> bool: ... + def isfifo(self) -> bool: ... + def isdev(self) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/telnetlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/telnetlib.pyi new file mode 100644 index 000000000..e4e5dea26 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/telnetlib.pyi @@ -0,0 +1,115 @@ +# Stubs for telnetlib (Python 2 and 3) + +import socket +import sys +from typing import Any, Callable, Match, Optional, Pattern, Sequence, Tuple, Union + +DEBUGLEVEL = ... # type: int +TELNET_PORT = ... # type: int + +IAC = ... # type: bytes +DONT = ... # type: bytes +DO = ... # type: bytes +WONT = ... # type: bytes +WILL = ... # type: bytes +theNULL = ... # type: bytes + +SE = ... # type: bytes +NOP = ... # type: bytes +DM = ... # type: bytes +BRK = ... # type: bytes +IP = ... # type: bytes +AO = ... # type: bytes +AYT = ... # type: bytes +EC = ... # type: bytes +EL = ... # type: bytes +GA = ... # type: bytes +SB = ... # type: bytes + +BINARY = ... # type: bytes +ECHO = ... # type: bytes +RCP = ... # type: bytes +SGA = ... # type: bytes +NAMS = ... # type: bytes +STATUS = ... # type: bytes +TM = ... # type: bytes +RCTE = ... # type: bytes +NAOL = ... # type: bytes +NAOP = ... # type: bytes +NAOCRD = ... # type: bytes +NAOHTS = ... # type: bytes +NAOHTD = ... # type: bytes +NAOFFD = ... # type: bytes +NAOVTS = ... # type: bytes +NAOVTD = ... # type: bytes +NAOLFD = ... # type: bytes +XASCII = ... # type: bytes +LOGOUT = ... # type: bytes +BM = ... # type: bytes +DET = ... # type: bytes +SUPDUP = ... # type: bytes +SUPDUPOUTPUT = ... # type: bytes +SNDLOC = ... # type: bytes +TTYPE = ... # type: bytes +EOR = ... # type: bytes +TUID = ... # type: bytes +OUTMRK = ... # type: bytes +TTYLOC = ... # type: bytes +VT3270REGIME = ... # type: bytes +X3PAD = ... # type: bytes +NAWS = ... # type: bytes +TSPEED = ... # type: bytes +LFLOW = ... # type: bytes +LINEMODE = ... # type: bytes +XDISPLOC = ... # type: bytes +OLD_ENVIRON = ... # type: bytes +AUTHENTICATION = ... # type: bytes +ENCRYPT = ... # type: bytes +NEW_ENVIRON = ... # type: bytes + +TN3270E = ... # type: bytes +XAUTH = ... # type: bytes +CHARSET = ... # type: bytes +RSP = ... # type: bytes +COM_PORT_OPTION = ... # type: bytes +SUPPRESS_LOCAL_ECHO = ... # type: bytes +TLS = ... # type: bytes +KERMIT = ... # type: bytes +SEND_URL = ... # type: bytes +FORWARD_X = ... # type: bytes +PRAGMA_LOGON = ... # type: bytes +SSPI_LOGON = ... # type: bytes +PRAGMA_HEARTBEAT = ... # type: bytes +EXOPL = ... # type: bytes +NOOPT = ... # type: bytes + +class Telnet: + def __init__(self, host: Optional[str] = ..., port: int = ..., + timeout: int = ...) -> None: ... + def open(self, host: str, port: int = ..., timeout: int = ...) -> None: ... + def msg(self, msg: str, *args: Any) -> None: ... + def set_debuglevel(self, debuglevel: int) -> None: ... + def close(self) -> None: ... + def get_socket(self) -> socket.socket: ... + def fileno(self) -> int: ... + def write(self, buffer: bytes) -> None: ... + def read_until(self, match: bytes, timeout: Optional[int] = ...) -> bytes: ... + def read_all(self) -> bytes: ... + def read_some(self) -> bytes: ... + def read_very_eager(self) -> bytes: ... + def read_eager(self) -> bytes: ... + def read_lazy(self) -> bytes: ... + def read_very_lazy(self) -> bytes: ... + def read_sb_data(self) -> bytes: ... + def set_option_negotiation_callback(self, callback: Optional[Callable[[socket.socket, bytes, bytes], Any]]) -> None: ... + def process_rawq(self) -> None: ... + def rawq_getchar(self) -> bytes: ... + def fill_rawq(self) -> None: ... + def sock_avail(self) -> bool: ... + def interact(self) -> None: ... + def mt_interact(self) -> None: ... + def listener(self) -> None: ... + def expect(self, list: Sequence[Union[Pattern[bytes], bytes]], timeout: Optional[int] = ...) -> Tuple[int, Optional[Match[bytes]], bytes]: ... + if sys.version_info >= (3, 6): + def __enter__(self) -> Telnet: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/termios.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/termios.pyi new file mode 100644 index 000000000..2e800d4fd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/termios.pyi @@ -0,0 +1,246 @@ +# Stubs for termios + +from typing import IO, List, Union + +_FD = Union[int, IO[str]] +_Attr = List[Union[int, List[bytes]]] + +# TODO constants not really documented +B0 = ... # type: int +B1000000 = ... # type: int +B110 = ... # type: int +B115200 = ... # type: int +B1152000 = ... # type: int +B1200 = ... # type: int +B134 = ... # type: int +B150 = ... # type: int +B1500000 = ... # type: int +B1800 = ... # type: int +B19200 = ... # type: int +B200 = ... # type: int +B2000000 = ... # type: int +B230400 = ... # type: int +B2400 = ... # type: int +B2500000 = ... # type: int +B300 = ... # type: int +B3000000 = ... # type: int +B3500000 = ... # type: int +B38400 = ... # type: int +B4000000 = ... # type: int +B460800 = ... # type: int +B4800 = ... # type: int +B50 = ... # type: int +B500000 = ... # type: int +B57600 = ... # type: int +B576000 = ... # type: int +B600 = ... # type: int +B75 = ... # type: int +B921600 = ... # type: int +B9600 = ... # type: int +BRKINT = ... # type: int +BS0 = ... # type: int +BS1 = ... # type: int +BSDLY = ... # type: int +CBAUD = ... # type: int +CBAUDEX = ... # type: int +CDSUSP = ... # type: int +CEOF = ... # type: int +CEOL = ... # type: int +CEOT = ... # type: int +CERASE = ... # type: int +CFLUSH = ... # type: int +CIBAUD = ... # type: int +CINTR = ... # type: int +CKILL = ... # type: int +CLNEXT = ... # type: int +CLOCAL = ... # type: int +CQUIT = ... # type: int +CR0 = ... # type: int +CR1 = ... # type: int +CR2 = ... # type: int +CR3 = ... # type: int +CRDLY = ... # type: int +CREAD = ... # type: int +CRPRNT = ... # type: int +CRTSCTS = ... # type: int +CS5 = ... # type: int +CS6 = ... # type: int +CS7 = ... # type: int +CS8 = ... # type: int +CSIZE = ... # type: int +CSTART = ... # type: int +CSTOP = ... # type: int +CSTOPB = ... # type: int +CSUSP = ... # type: int +CWERASE = ... # type: int +ECHO = ... # type: int +ECHOCTL = ... # type: int +ECHOE = ... # type: int +ECHOK = ... # type: int +ECHOKE = ... # type: int +ECHONL = ... # type: int +ECHOPRT = ... # type: int +EXTA = ... # type: int +EXTB = ... # type: int +FF0 = ... # type: int +FF1 = ... # type: int +FFDLY = ... # type: int +FIOASYNC = ... # type: int +FIOCLEX = ... # type: int +FIONBIO = ... # type: int +FIONCLEX = ... # type: int +FIONREAD = ... # type: int +FLUSHO = ... # type: int +HUPCL = ... # type: int +ICANON = ... # type: int +ICRNL = ... # type: int +IEXTEN = ... # type: int +IGNBRK = ... # type: int +IGNCR = ... # type: int +IGNPAR = ... # type: int +IMAXBEL = ... # type: int +INLCR = ... # type: int +INPCK = ... # type: int +IOCSIZE_MASK = ... # type: int +IOCSIZE_SHIFT = ... # type: int +ISIG = ... # type: int +ISTRIP = ... # type: int +IUCLC = ... # type: int +IXANY = ... # type: int +IXOFF = ... # type: int +IXON = ... # type: int +NCC = ... # type: int +NCCS = ... # type: int +NL0 = ... # type: int +NL1 = ... # type: int +NLDLY = ... # type: int +NOFLSH = ... # type: int +N_MOUSE = ... # type: int +N_PPP = ... # type: int +N_SLIP = ... # type: int +N_STRIP = ... # type: int +N_TTY = ... # type: int +OCRNL = ... # type: int +OFDEL = ... # type: int +OFILL = ... # type: int +OLCUC = ... # type: int +ONLCR = ... # type: int +ONLRET = ... # type: int +ONOCR = ... # type: int +OPOST = ... # type: int +PARENB = ... # type: int +PARMRK = ... # type: int +PARODD = ... # type: int +PENDIN = ... # type: int +TAB0 = ... # type: int +TAB1 = ... # type: int +TAB2 = ... # type: int +TAB3 = ... # type: int +TABDLY = ... # type: int +TCFLSH = ... # type: int +TCGETA = ... # type: int +TCGETS = ... # type: int +TCIFLUSH = ... # type: int +TCIOFF = ... # type: int +TCIOFLUSH = ... # type: int +TCION = ... # type: int +TCOFLUSH = ... # type: int +TCOOFF = ... # type: int +TCOON = ... # type: int +TCSADRAIN = ... # type: int +TCSAFLUSH = ... # type: int +TCSANOW = ... # type: int +TCSBRK = ... # type: int +TCSBRKP = ... # type: int +TCSETA = ... # type: int +TCSETAF = ... # type: int +TCSETAW = ... # type: int +TCSETS = ... # type: int +TCSETSF = ... # type: int +TCSETSW = ... # type: int +TCXONC = ... # type: int +TIOCCONS = ... # type: int +TIOCEXCL = ... # type: int +TIOCGETD = ... # type: int +TIOCGICOUNT = ... # type: int +TIOCGLCKTRMIOS = ... # type: int +TIOCGPGRP = ... # type: int +TIOCGSERIAL = ... # type: int +TIOCGSOFTCAR = ... # type: int +TIOCGWINSZ = ... # type: int +TIOCINQ = ... # type: int +TIOCLINUX = ... # type: int +TIOCMBIC = ... # type: int +TIOCMBIS = ... # type: int +TIOCMGET = ... # type: int +TIOCMIWAIT = ... # type: int +TIOCMSET = ... # type: int +TIOCM_CAR = ... # type: int +TIOCM_CD = ... # type: int +TIOCM_CTS = ... # type: int +TIOCM_DSR = ... # type: int +TIOCM_DTR = ... # type: int +TIOCM_LE = ... # type: int +TIOCM_RI = ... # type: int +TIOCM_RNG = ... # type: int +TIOCM_RTS = ... # type: int +TIOCM_SR = ... # type: int +TIOCM_ST = ... # type: int +TIOCNOTTY = ... # type: int +TIOCNXCL = ... # type: int +TIOCOUTQ = ... # type: int +TIOCPKT = ... # type: int +TIOCPKT_DATA = ... # type: int +TIOCPKT_DOSTOP = ... # type: int +TIOCPKT_FLUSHREAD = ... # type: int +TIOCPKT_FLUSHWRITE = ... # type: int +TIOCPKT_NOSTOP = ... # type: int +TIOCPKT_START = ... # type: int +TIOCPKT_STOP = ... # type: int +TIOCSCTTY = ... # type: int +TIOCSERCONFIG = ... # type: int +TIOCSERGETLSR = ... # type: int +TIOCSERGETMULTI = ... # type: int +TIOCSERGSTRUCT = ... # type: int +TIOCSERGWILD = ... # type: int +TIOCSERSETMULTI = ... # type: int +TIOCSERSWILD = ... # type: int +TIOCSER_TEMT = ... # type: int +TIOCSETD = ... # type: int +TIOCSLCKTRMIOS = ... # type: int +TIOCSPGRP = ... # type: int +TIOCSSERIAL = ... # type: int +TIOCSSOFTCAR = ... # type: int +TIOCSTI = ... # type: int +TIOCSWINSZ = ... # type: int +TOSTOP = ... # type: int +VDISCARD = ... # type: int +VEOF = ... # type: int +VEOL = ... # type: int +VEOL2 = ... # type: int +VERASE = ... # type: int +VINTR = ... # type: int +VKILL = ... # type: int +VLNEXT = ... # type: int +VMIN = ... # type: int +VQUIT = ... # type: int +VREPRINT = ... # type: int +VSTART = ... # type: int +VSTOP = ... # type: int +VSUSP = ... # type: int +VSWTC = ... # type: int +VSWTCH = ... # type: int +VT0 = ... # type: int +VT1 = ... # type: int +VTDLY = ... # type: int +VTIME = ... # type: int +VWERASE = ... # type: int +XCASE = ... # type: int +XTABS = ... # type: int + +def tcgetattr(fd: _FD) -> _Attr: ... +def tcsetattr(fd: _FD, when: int, attributes: _Attr) -> None: ... +def tcsendbreak(fd: _FD, duration: int) -> None: ... +def tcdrain(fd: _FD) -> None: ... +def tcflush(fd: _FD, queue: int) -> None: ... +def tcflow(fd: _FD, action: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/threading.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/threading.pyi new file mode 100644 index 000000000..a5edf6a4a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/threading.pyi @@ -0,0 +1,189 @@ +# Stubs for threading + +from typing import ( + Any, Callable, Iterable, List, Mapping, Optional, Tuple, Type, Union, + TypeVar, +) +from types import FrameType, TracebackType +import sys + +# TODO recursive type +_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]] + +_PF = Callable[[FrameType, str, Any], None] +_T = TypeVar('_T') + + +def active_count() -> int: ... +if sys.version_info < (3,): + def activeCount() -> int: ... + +def current_thread() -> Thread: ... +if sys.version_info < (3,): + def currentThread() -> Thread: ... + +if sys.version_info >= (3,): + def get_ident() -> int: ... + +def enumerate() -> List[Thread]: ... + +if sys.version_info >= (3, 4): + def main_thread() -> Thread: ... + +def settrace(func: _TF) -> None: ... +def setprofile(func: _PF) -> None: ... +def stack_size(size: int = ...) -> int: ... + +if sys.version_info >= (3,): + TIMEOUT_MAX = ... # type: float + +class ThreadError(Exception): ... + + +class local(object): + def __getattribute__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __delattr__(self, name: str) -> None: ... + + +class Thread: + name = ... # type: str + ident = ... # type: Optional[int] + daemon = ... # type: bool + if sys.version_info >= (3,): + def __init__(self, group: None = ..., + target: Optional[Callable[..., Any]] = ..., + name: Optional[str] = ..., + args: Iterable = ..., + kwargs: Mapping[str, Any] = ..., + *, daemon: Optional[bool] = ...) -> None: ... + else: + def __init__(self, group: None = ..., + target: Optional[Callable[..., Any]] = ..., + name: Optional[str] = ..., + args: Iterable = ..., + kwargs: Mapping[str, Any] = ...) -> None: ... + def start(self) -> None: ... + def run(self) -> None: ... + def join(self, timeout: Optional[float] = ...) -> None: ... + def getName(self) -> str: ... + def setName(self, name: str) -> None: ... + def is_alive(self) -> bool: ... + if sys.version_info < (3,): + def isAlive(self) -> bool: ... + def isDaemon(self) -> bool: ... + def setDaemon(self, daemonic: bool) -> None: ... + + +class _DummyThread(Thread): ... + + +class Lock: + def __init__(self) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + def locked(self) -> bool: ... + + +class _RLock: + def __init__(self) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + + +RLock = _RLock + + +class Condition: + def __init__(self, lock: Union[Lock, _RLock, None] = ...) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> bool: ... + if sys.version_info >= (3,): + def wait_for(self, predicate: Callable[[], _T], + timeout: Optional[float] = ...) -> _T: ... + def notify(self, n: int = ...) -> None: ... + def notify_all(self) -> None: ... + def notifyAll(self) -> None: ... + + +class Semaphore: + def __init__(self, value: int = ...) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + +class BoundedSemaphore: + def __init__(self, value: int = ...) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + + +class Event: + def __init__(self) -> None: ... + def is_set(self) -> bool: ... + if sys.version_info < (3,): + def isSet(self) -> bool: ... + def set(self) -> None: ... + def clear(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> bool: ... + + +class Timer(Thread): + if sys.version_info >= (3,): + def __init__(self, interval: float, function: Callable[..., None], + args: Optional[List[Any]] = ..., + kwargs: Optional[Mapping[str, Any]] = ...) -> None: ... + else: + def __init__(self, interval: float, function: Callable[..., None], + args: List[Any] = ..., + kwargs: Mapping[str, Any] = ...) -> None: ... + def cancel(self) -> None: ... + + +if sys.version_info >= (3,): + class Barrier: + parties = ... # type: int + n_waiting = ... # type: int + broken = ... # type: bool + def __init__(self, parties: int, action: Optional[Callable[[], None]] = ..., + timeout: Optional[float] = ...) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> int: ... + def reset(self) -> None: ... + def abort(self) -> None: ... + + class BrokenBarrierError(RuntimeError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/time.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/time.pyi new file mode 100644 index 000000000..b04e6164b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/time.pyi @@ -0,0 +1,103 @@ +"""Stub file for the 'time' module.""" +# See https://docs.python.org/3/library/time.html + +import sys +from typing import Any, NamedTuple, Tuple, Union, Optional +if sys.version_info >= (3, 3): + from types import SimpleNamespace + +_TimeTuple = Tuple[int, int, int, int, int, int, int, int, int] + +if sys.version_info < (3, 3): + accept2dyear: bool +altzone: int +daylight: int +timezone: int +tzname: Tuple[str, str] + +if sys.version_info >= (3, 7) and sys.platform != 'win32': + CLOCK_BOOTTIME: int # Linux + CLOCK_PROF: int # FreeBSD, NetBSD, OpenBSD + CLOCK_UPTIME: int # FreeBSD, OpenBSD + +if sys.version_info >= (3, 3) and sys.platform != 'win32': + CLOCK_HIGHRES: int = ... # Solaris only + CLOCK_MONOTONIC: int = ... # Unix only + CLOCK_MONOTONIC_RAW: int = ... # Linux 2.6.28 or later + CLOCK_PROCESS_CPUTIME_ID: int = ... # Unix only + CLOCK_REALTIME: int = ... # Unix only + CLOCK_THREAD_CPUTIME_ID: int = ... # Unix only + + +if sys.version_info >= (3, 3): + class struct_time( + NamedTuple( + '_struct_time', + [('tm_year', int), ('tm_mon', int), ('tm_mday', int), + ('tm_hour', int), ('tm_min', int), ('tm_sec', int), + ('tm_wday', int), ('tm_yday', int), ('tm_isdst', int), + ('tm_zone', str), ('tm_gmtoff', int)] + ) + ): + def __init__( + self, + o: Union[ + Tuple[int, int, int, int, int, int, int, int, int], + Tuple[int, int, int, int, int, int, int, int, int, str], + Tuple[int, int, int, int, int, int, int, int, int, str, int] + ], + _arg: Any = ..., + ) -> None: ... + def __new__( + cls, + o: Union[ + Tuple[int, int, int, int, int, int, int, int, int], + Tuple[int, int, int, int, int, int, int, int, int, str], + Tuple[int, int, int, int, int, int, int, int, int, str, int] + ], + _arg: Any = ..., + ) -> struct_time: ... +else: + class struct_time( + NamedTuple( + '_struct_time', + [('tm_year', int), ('tm_mon', int), ('tm_mday', int), + ('tm_hour', int), ('tm_min', int), ('tm_sec', int), + ('tm_wday', int), ('tm_yday', int), ('tm_isdst', int)] + ) + ): + def __init__(self, o: _TimeTuple, _arg: Any = ...) -> None: ... + def __new__(cls, o: _TimeTuple, _arg: Any = ...) -> struct_time: ... + +def asctime(t: Union[_TimeTuple, struct_time] = ...) -> str: ... +def clock() -> float: ... +def ctime(secs: Optional[float] = ...) -> str: ... +def gmtime(secs: Optional[float] = ...) -> struct_time: ... +def localtime(secs: Optional[float] = ...) -> struct_time: ... +def mktime(t: Union[_TimeTuple, struct_time]) -> float: ... +def sleep(secs: float) -> None: ... +def strftime(format: str, t: Union[_TimeTuple, struct_time] = ...) -> str: ... +def strptime(string: str, format: str = ...) -> struct_time: ... +def time() -> float: ... +if sys.platform != 'win32': + def tzset() -> None: ... # Unix only + +if sys.version_info >= (3, 3): + def get_clock_info(name: str) -> SimpleNamespace: ... + def monotonic() -> float: ... + def perf_counter() -> float: ... + def process_time() -> float: ... + if sys.platform != 'win32': + def clock_getres(clk_id: int) -> float: ... # Unix only + def clock_gettime(clk_id: int) -> float: ... # Unix only + def clock_settime(clk_id: int, time: float) -> None: ... # Unix only + +if sys.version_info >= (3, 7): + def clock_gettime_ns(clock_id: int) -> int: ... + def clock_settime_ns(clock_id: int, time: int) -> int: ... + def monotonic_ns() -> int: ... + def perf_counter_ns() -> int: ... + def process_time_ns() -> int: ... + def time_ns() -> int: ... + def thread_time() -> float: ... + def thread_time_ns() -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/timeit.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/timeit.pyi new file mode 100644 index 000000000..4fbb27c16 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/timeit.pyi @@ -0,0 +1,33 @@ +# Stubs for timeit (Python 2 and 3) + +import sys +from typing import Any, Callable, Dict, IO, List, Optional, Text, Tuple, Union + +_str = Union[str, Text] +_Timer = Callable[[], float] +_stmt = Union[_str, Callable[[], Any]] + +default_timer = ... # type: _Timer + +class Timer: + if sys.version_info >= (3, 5): + def __init__(self, stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., + globals: Optional[Dict[str, Any]] =...) -> None: ... + else: + def __init__(self, stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ...) -> None: ... + def print_exc(self, file: Optional[IO[str]] = ...) -> None: ... + def timeit(self, number: int = ...) -> float: ... + def repeat(self, repeat: int = ..., number: int = ...) -> List[float]: ... + if sys.version_info >= (3, 6): + def autorange(self, callback: Optional[Callable[[int, float], Any]] = ...) -> Tuple[int, float]: ... + +if sys.version_info >= (3, 5): + def timeit(stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., + number: int = ..., globals: Optional[Dict[str, Any]] =...) -> float: ... + def repeat(stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., + repeat: int = ..., number: int = ..., globals: Optional[Dict[str, Any]] =...) -> List[float]: ... +else: + def timeit(stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., + number: int = ...) -> float: ... + def repeat(stmt: _stmt = ..., setup: _stmt = ..., timer: _Timer = ..., + repeat: int = ..., number: int = ...) -> List[float]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/token.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/token.pyi new file mode 100644 index 000000000..8d044bdc2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/token.pyi @@ -0,0 +1,71 @@ +import sys +from typing import Dict + +ENDMARKER = ... # type: int +NAME = ... # type: int +NUMBER = ... # type: int +STRING = ... # type: int +NEWLINE = ... # type: int +INDENT = ... # type: int +DEDENT = ... # type: int +LPAR = ... # type: int +RPAR = ... # type: int +LSQB = ... # type: int +RSQB = ... # type: int +COLON = ... # type: int +COMMA = ... # type: int +SEMI = ... # type: int +PLUS = ... # type: int +MINUS = ... # type: int +STAR = ... # type: int +SLASH = ... # type: int +VBAR = ... # type: int +AMPER = ... # type: int +LESS = ... # type: int +GREATER = ... # type: int +EQUAL = ... # type: int +DOT = ... # type: int +PERCENT = ... # type: int +if sys.version_info < (3,): + BACKQUOTE = ... # type: int +LBRACE = ... # type: int +RBRACE = ... # type: int +EQEQUAL = ... # type: int +NOTEQUAL = ... # type: int +LESSEQUAL = ... # type: int +GREATEREQUAL = ... # type: int +TILDE = ... # type: int +CIRCUMFLEX = ... # type: int +LEFTSHIFT = ... # type: int +RIGHTSHIFT = ... # type: int +DOUBLESTAR = ... # type: int +PLUSEQUAL = ... # type: int +MINEQUAL = ... # type: int +STAREQUAL = ... # type: int +SLASHEQUAL = ... # type: int +PERCENTEQUAL = ... # type: int +AMPEREQUAL = ... # type: int +VBAREQUAL = ... # type: int +CIRCUMFLEXEQUAL = ... # type: int +LEFTSHIFTEQUAL = ... # type: int +RIGHTSHIFTEQUAL = ... # type: int +DOUBLESTAREQUAL = ... # type: int +DOUBLESLASH = ... # type: int +DOUBLESLASHEQUAL = ... # type: int +AT = ... # type: int +if sys.version_info >= (3,): + RARROW = ... # type: int + ELLIPSIS = ... # type: int +if sys.version_info >= (3, 5): + ATEQUAL = ... # type: int + AWAIT = ... # type: int + ASYNC = ... # type: int +OP = ... # type: int +ERRORTOKEN = ... # type: int +N_TOKENS = ... # type: int +NT_OFFSET = ... # type: int +tok_name = ... # type: Dict[int, str] + +def ISTERMINAL(x: int) -> bool: ... +def ISNONTERMINAL(x: int) -> bool: ... +def ISEOF(x: int) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/trace.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/trace.pyi new file mode 100644 index 000000000..af06d39c0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/trace.pyi @@ -0,0 +1,35 @@ +# Stubs for trace (Python 2 and 3) + +import os +import sys +import types +from typing import Any, Callable, Mapping, Optional, Sequence, Text, Tuple, TypeVar, Union + +_T = TypeVar('_T') +_localtrace = Callable[[types.FrameType, str, Any], Callable[..., Any]] + +if sys.version_info >= (3, 6): + _Path = Union[Text, os.PathLike] +else: + _Path = Text + +class CoverageResults: + def update(self, other: CoverageResults) -> None: ... + def write_results(self, show_missing: bool = ..., summary: bool = ..., coverdir: Optional[_Path] = ...) -> None: ... + def write_results_file(self, path: _Path, lines: Sequence[str], lnotab: Any, lines_hit: Mapping[int, int], encoding: Optional[str] = ...) -> Tuple[int, int]: ... + +class Trace: + def __init__(self, count: int = ..., trace: int = ..., countfuncs: int = ..., countcallers: int = ..., + ignoremods: Sequence[str] = ..., ignoredirs: Sequence[str] = ..., infile: Optional[_Path] = ..., + outfile: Optional[_Path] = ..., timing: bool = ...) -> None: ... + def run(self, cmd: Union[str, types.CodeType]) -> None: ... + def runctx(self, cmd: Union[str, types.CodeType], globals: Optional[Mapping[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> None: ... + def runfunc(self, func: Callable[..., _T], *args: Any, **kw: Any) -> _T: ... + def file_module_function_of(self, frame: types.FrameType) -> Tuple[str, Optional[str], str]: ... + def globaltrace_trackcallers(self, frame: types.FrameType, why: str, arg: Any) -> None: ... + def globaltrace_countfuncs(self, frame: types.FrameType, why: str, arg: Any) -> None: ... + def globaltrace_lt(self, frame: types.FrameType, why: str, arg: Any) -> None: ... + def localtrace_trace_and_count(self, frame: types.FrameType, why: str, arg: Any) -> _localtrace: ... + def localtrace_trace(self, frame: types.FrameType, why: str, arg: Any) -> _localtrace: ... + def localtrace_count(self, frame: types.FrameType, why: str, arg: Any) -> _localtrace: ... + def results(self) -> CoverageResults: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/traceback.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/traceback.pyi new file mode 100644 index 000000000..94e4153fb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/traceback.pyi @@ -0,0 +1,118 @@ +# Stubs for traceback + +from typing import Any, Dict, Generator, IO, Iterator, List, Mapping, Optional, Tuple, Type, Iterable +from types import FrameType, TracebackType +import sys + +_PT = Tuple[str, int, str, Optional[str]] + + +def print_tb(tb: Optional[TracebackType], limit: Optional[int] = ..., + file: Optional[IO[str]] = ...) -> None: ... +if sys.version_info >= (3,): + def print_exception(etype: Optional[Type[BaseException]], + value: Optional[BaseException], + tb: Optional[TracebackType], limit: Optional[int] = ..., + file: Optional[IO[str]] = ..., + chain: bool = ...) -> None: ... + def print_exc(limit: Optional[int] = ..., file: Optional[IO[str]] = ..., + chain: bool = ...) -> None: ... + def print_last(limit: Optional[int] = ..., file: Optional[IO[str]] = ..., + chain: bool = ...) -> None: ... +else: + def print_exception(etype: Optional[Type[BaseException]], + value: Optional[BaseException], + tb: Optional[TracebackType], limit: Optional[int] = ..., + file: Optional[IO[str]] = ...) -> None: ... + def print_exc(limit: Optional[int] = ..., + file: Optional[IO[str]] = ...) -> None: ... + def print_last(limit: Optional[int] = ..., + file: Optional[IO[str]] = ...) -> None: ... +def print_stack(f: Optional[FrameType] = ..., limit: Optional[int] = ..., + file: Optional[IO[str]] = ...) -> None: ... + +if sys.version_info >= (3, 5): + def extract_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> StackSummary: ... + def extract_stack(f: Optional[FrameType] = ..., + limit: Optional[int] = ...) -> StackSummary: ... + def format_list(extracted_list: List[FrameSummary]) -> List[str]: ... +else: + def extract_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> List[_PT]: ... + def extract_stack(f: Optional[FrameType] = ..., + limit: Optional[int] = ...) -> List[_PT]: ... + def format_list(extracted_list: List[_PT]) -> List[str]: ... +def format_exception_only(etype: Optional[Type[BaseException]], + value: Optional[BaseException]) -> List[str]: ... +if sys.version_info >= (3,): + def format_exception(etype: Optional[Type[BaseException]], value: Optional[BaseException], + tb: Optional[TracebackType], limit: Optional[int] = ..., + chain: bool = ...) -> List[str]: ... + def format_exc(limit: Optional[int] = ..., chain: bool = ...) -> str: ... +else: + def format_exception(etype: Optional[Type[BaseException]], + value: Optional[BaseException], + tb: Optional[TracebackType], + limit: Optional[int] = ...) -> List[str]: ... + def format_exc(limit: Optional[int] = ...) -> str: ... +def format_tb(tb: Optional[TracebackType], limit: Optional[int] = ...) -> List[str]: ... +def format_stack(f: Optional[FrameType] = ..., + limit: Optional[int] = ...) -> List[str]: ... +if sys.version_info >= (3, 4): + def clear_frames(tb: TracebackType) -> None: ... +if sys.version_info >= (3, 5): + def walk_stack(f: Optional[FrameType]) -> Iterator[Tuple[FrameType, int]]: ... + def walk_tb(tb: Optional[TracebackType]) -> Iterator[Tuple[FrameType, int]]: ... +if sys.version_info < (3,): + def tb_lineno(tb: TracebackType) -> int: ... + + +if sys.version_info >= (3, 5): + class TracebackException: + __cause__ = ... # type:TracebackException + __context__ = ... # type:TracebackException + __suppress_context__ = ... # type: bool + stack = ... # type: StackSummary + exc_type = ... # type: Type[BaseException] + filename = ... # type: str + lineno = ... # type: int + text = ... # type: str + offset = ... # type: int + msg = ... # type: str + def __init__(self, exc_type: Type[BaseException], + exc_value: BaseException, exc_traceback: TracebackType, + *, limit: Optional[int] = ..., lookup_lines: bool = ..., + capture_locals: bool = ...) -> None: ... + @classmethod + def from_exception(cls, exc: BaseException, + *, limit: Optional[int] = ..., + lookup_lines: bool = ..., + capture_locals: bool = ...) -> TracebackException: ... + def format(self, *, chain: bool = ...) -> Generator[str, None, None]: ... + def format_exception_only(self) -> Generator[str, None, None]: ... + + +if sys.version_info >= (3, 5): + class FrameSummary(Iterable): + filename: str + lineno: int + name: str + line: str + locals: Optional[Dict[str, str]] + def __init__(self, filename: str, lineno: int, name: str, + lookup_line: bool = ..., + locals: Optional[Mapping[str, str]] = ..., + line: Optional[int] = ...) -> None: ... + # TODO: more precise typing for __getitem__ and __iter__, + # for a namedtuple-like view on (filename, lineno, name, str). + def __getitem__(self, i: int) -> Any: ... + def __iter__(self) -> Iterator[Any]: ... + + class StackSummary(List[FrameSummary]): + @classmethod + def extract(cls, + frame_gen: Generator[Tuple[FrameType, int], None, None], + *, limit: Optional[int] = ..., lookup_lines: bool = ..., + capture_locals: bool = ...) -> StackSummary: ... + @classmethod + def from_list(cls, a_list: List[_PT]) -> StackSummary: ... + def format(self) -> List[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tty.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tty.pyi new file mode 100644 index 000000000..18d8bcc3b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/tty.pyi @@ -0,0 +1,17 @@ +# Stubs for tty (Python 3.6) + +from typing import IO, Union + +_FD = Union[int, IO[str]] + +# XXX: Undocumented integer constants +IFLAG = ... # type: int +OFLAG = ... # type: int +CFLAG = ... # type: int +LFLAG = ... # type: int +ISPEED = ... # type: int +OSPEED = ... # type: int +CC = ... # type: int + +def setraw(fd: _FD, when: int = ...) -> None: ... +def setcbreak(fd: _FD, when: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/unicodedata.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/unicodedata.pyi new file mode 100644 index 000000000..6da12c331 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/unicodedata.pyi @@ -0,0 +1,38 @@ +# Stubs for unicodedata (Python 2.7 and 3.4) +from typing import Any, Text, TypeVar, Union + +ucd_3_2_0 = ... # type: UCD +ucnhash_CAPI = ... # type: Any +unidata_version = ... # type: str + +_default = TypeVar('_default') + +def bidirectional(__chr: Text) -> Text: ... +def category(__chr: Text) -> Text: ... +def combining(__chr: Text) -> int: ... +def decimal(__chr: Text, __default: _default=...) -> Union[int, _default]: ... +def decomposition(__chr: Text) -> Text: ... +def digit(__chr: Text, __default: _default=...) -> Union[int, _default]: ... +def east_asian_width(__chr: Text) -> Text: ... +def lookup(__name: Union[Text, bytes]) -> Text: ... +def mirrored(__chr: Text) -> int: ... +def name(__chr: Text, __default: _default=...) -> Union[Text, _default]: ... +def normalize(__form: Text, __unistr: Text) -> Text: ... +def numeric(__chr: Text, __default: _default=...) -> Union[float, _default]: ... + +class UCD(object): + # The methods below are constructed from the same array in C + # (unicodedata_functions) and hence identical to the methods above. + unidata_version = ... # type: str + def bidirectional(self, __chr: Text) -> str: ... + def category(self, __chr: Text) -> str: ... + def combining(self, __chr: Text) -> int: ... + def decimal(self, __chr: Text, __default: _default=...) -> Union[int, _default]: ... + def decomposition(self, __chr: Text) -> str: ... + def digit(self, __chr: Text, __default: _default=...) -> Union[int, _default]: ... + def east_asian_width(self, __chr: Text) -> str: ... + def lookup(self, __name: Union[Text, bytes]) -> Text: ... + def mirrored(self, __chr: Text) -> int: ... + def name(self, __chr: Text, __default: _default=...) -> Union[Text, _default]: ... + def normalize(self, __form: Text, __unistr: Text) -> Text: ... + def numeric(self, __chr: Text, __default: _default=...) -> Union[float, _default]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/uu.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/uu.pyi new file mode 100644 index 000000000..c926dbba2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/uu.pyi @@ -0,0 +1,13 @@ +# Stubs for uu (Python 2 and 3) +import sys +from typing import BinaryIO, Union, Optional, Text + +_File = Union[Text, BinaryIO] + +class Error(Exception): ... + +if sys.version_info >= (3, 7): + def encode(in_file: _File, out_file: _File, name: Optional[str] = ..., mode: Optional[int] = ..., backtick: bool = ...) -> None: ... +else: + def encode(in_file: _File, out_file: _File, name: Optional[str] = ..., mode: Optional[int] = ...) -> None: ... +def decode(in_file: _File, out_file: Optional[_File] = ..., mode: Optional[int] = ..., quiet: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/uuid.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/uuid.pyi new file mode 100644 index 000000000..354371a7c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/uuid.pyi @@ -0,0 +1,89 @@ +# Stubs for uuid + +import sys +from typing import Tuple, Optional, Any + +# Because UUID has properties called int and bytes we need to rename these temporarily. +_Int = int +_Bytes = bytes +_FieldsType = Tuple[int, int, int, int, int, int] + +class UUID: + def __init__(self, hex: Optional[str] = ..., bytes: Optional[_Bytes] = ..., + bytes_le: Optional[_Bytes] = ..., + fields: Optional[_FieldsType] = ..., + int: Optional[_Int] = ..., + version: Optional[_Int] = ...) -> None: ... + @property + def bytes(self) -> _Bytes: ... + @property + def bytes_le(self) -> _Bytes: ... + @property + def clock_seq(self) -> _Int: ... + @property + def clock_seq_hi_variant(self) -> _Int: ... + @property + def clock_seq_low(self) -> _Int: ... + @property + def fields(self) -> _FieldsType: ... + @property + def hex(self) -> str: ... + @property + def int(self) -> _Int: ... + @property + def node(self) -> _Int: ... + @property + def time(self) -> _Int: ... + @property + def time_hi_version(self) -> _Int: ... + @property + def time_low(self) -> _Int: ... + @property + def time_mid(self) -> _Int: ... + @property + def urn(self) -> str: ... + @property + def variant(self) -> str: ... + @property + def version(self) -> Optional[_Int]: ... + + def __int__(self) -> _Int: ... + + if sys.version_info >= (3,): + def __eq__(self, other: Any) -> bool: ... + def __lt__(self, other: Any) -> bool: ... + def __le__(self, other: Any) -> bool: ... + def __gt__(self, other: Any) -> bool: ... + def __ge__(self, other: Any) -> bool: ... + else: + def get_bytes(self) -> _Bytes: ... + def get_bytes_le(self) -> _Bytes: ... + def get_clock_seq(self) -> _Int: ... + def get_clock_seq_hi_variant(self) -> _Int: ... + def get_clock_seq_low(self) -> _Int: ... + def get_fields(self) -> _FieldsType: ... + def get_hex(self) -> str: ... + def get_node(self) -> _Int: ... + def get_time(self) -> _Int: ... + def get_time_hi_version(self) -> _Int: ... + def get_time_low(self) -> _Int: ... + def get_time_mid(self) -> _Int: ... + def get_urn(self) -> str: ... + def get_variant(self) -> str: ... + def get_version(self) -> Optional[_Int]: ... + def __cmp__(self, other: Any) -> _Int: ... + +def getnode() -> int: ... +def uuid1(node: Optional[_Int] = ..., clock_seq: Optional[_Int] = ...) -> UUID: ... +def uuid3(namespace: UUID, name: str) -> UUID: ... +def uuid4() -> UUID: ... +def uuid5(namespace: UUID, name: str) -> UUID: ... + +NAMESPACE_DNS = ... # type: UUID +NAMESPACE_URL = ... # type: UUID +NAMESPACE_OID = ... # type: UUID +NAMESPACE_X500 = ... # type: UUID +RESERVED_NCS = ... # type: str +RFC_4122 = ... # type: str +RESERVED_MICROSOFT = ... # type: str +RESERVED_FUTURE = ... # type: str diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/warnings.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/warnings.pyi new file mode 100644 index 000000000..67d2b813d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/warnings.pyi @@ -0,0 +1,39 @@ +# Stubs for warnings + +from typing import Any, Dict, List, NamedTuple, Optional, TextIO, Tuple, Type, Union +from types import ModuleType, TracebackType + +def warn(message: Union[str, Warning], category: Optional[Type[Warning]] = ..., + stacklevel: int = ...) -> None: ... +def warn_explicit(message: Union[str, Warning], category: Type[Warning], + filename: str, lineno: int, module: Optional[str] = ..., + registry: Optional[Dict[Union[str, Tuple[str, Type[Warning], int]], int]] = ..., + module_globals: Optional[Dict[str, Any]] = ...) -> None: ... +def showwarning(message: str, category: Type[Warning], filename: str, + lineno: int, file: Optional[TextIO] = ..., + line: Optional[str] = ...) -> None: ... +def formatwarning(message: str, category: Type[Warning], filename: str, + lineno: int, line: Optional[str] = ...) -> str: ... +def filterwarnings(action: str, message: str = ..., + category: Type[Warning] = ..., module: str = ..., + lineno: int = ..., append: bool = ...) -> None: ... +def simplefilter(action: str, category: Type[Warning] = ..., lineno: int = ..., + append: bool = ...) -> None: ... +def resetwarnings() -> None: ... + +_Record = NamedTuple('_Record', + [('message', str), + ('category', Type[Warning]), + ('filename', str), + ('lineno', int), + ('file', Optional[TextIO]), + ('line', Optional[str])] +) + +class catch_warnings: + def __init__(self, *, record: bool = ..., + module: Optional[ModuleType] = ...) -> None: ... + def __enter__(self) -> Optional[List[_Record]]: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wave.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wave.pyi new file mode 100644 index 000000000..672e94d29 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wave.pyi @@ -0,0 +1,76 @@ +# Stubs for wave (Python 2 and 3) + +import sys +from typing import ( + Any, NamedTuple, NoReturn, Optional, Text, BinaryIO, Union, Tuple +) + +_File = Union[Text, BinaryIO] + +class Error(Exception): ... + +WAVE_FORMAT_PCM = ... # type: int + +if sys.version_info < (3, 0): + _wave_params = Tuple[int, int, int, int, str, str] +else: + _wave_params = NamedTuple('_wave_params', [ + ('nchannels', int), + ('sampwidth', int), + ('framerate', int), + ('nframes', int), + ('comptype', str), + ('compname', str), + ]) + +class Wave_read: + def __init__(self, f: _File) -> None: ... + if sys.version_info >= (3, 0): + def __enter__(self) -> Wave_read: ... + def __exit__(self, *args: Any) -> None: ... + def getfp(self) -> Optional[BinaryIO]: ... + def rewind(self) -> None: ... + def close(self) -> None: ... + def tell(self) -> int: ... + def getnchannels(self) -> int: ... + def getnframes(self) -> int: ... + def getsampwidth(self) -> int: ... + def getframerate(self) -> int: ... + def getcomptype(self) -> str: ... + def getcompname(self) -> str: ... + def getparams(self) -> _wave_params: ... + def getmarkers(self) -> None: ... + def getmark(self, id: Any) -> NoReturn: ... + def setpos(self, pos: int) -> None: ... + def readframes(self, nframes: int) -> bytes: ... + +class Wave_write: + def __init__(self, f: _File) -> None: ... + if sys.version_info >= (3, 0): + def __enter__(self) -> Wave_write: ... + def __exit__(self, *args: Any) -> None: ... + def setnchannels(self, nchannels: int) -> None: ... + def getnchannels(self) -> int: ... + def setsampwidth(self, sampwidth: int) -> None: ... + def getsampwidth(self) -> int: ... + def setframerate(self, framerate: float) -> None: ... + def getframerate(self) -> int: ... + def setnframes(self, nframes: int) -> None: ... + def getnframes(self) -> int: ... + def setcomptype(self, comptype: str, compname: str) -> None: ... + def getcomptype(self) -> str: ... + def getcompname(self) -> str: ... + def setparams(self, params: _wave_params) -> None: ... + def getparams(self) -> _wave_params: ... + def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... + def getmark(self, id: Any) -> NoReturn: ... + def getmarkers(self) -> None: ... + def tell(self) -> int: ... + # should be any bytes-like object after 3.4, but we don't have a type for that + def writeframesraw(self, data: bytes) -> None: ... + def writeframes(self, data: bytes) -> None: ... + def close(self) -> None: ... + +# Returns a Wave_read if mode is rb and Wave_write if mode is wb +def open(f: _File, mode: Optional[str] = ...) -> Any: ... +openfp = open diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/weakref.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/weakref.pyi new file mode 100644 index 000000000..e3ddbf278 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/weakref.pyi @@ -0,0 +1,110 @@ +import sys +import types +from typing import ( + TypeVar, Generic, Any, Callable, overload, Mapping, Iterator, Tuple, + Iterable, Optional, Type, MutableMapping, Union, List, Dict +) + +from _weakref import ( + getweakrefcount as getweakrefcount, + getweakrefs as getweakrefs, + ref as ref, + proxy as proxy, + CallableProxyType as CallableProxyType, + ProxyType as ProxyType, + ReferenceType as ReferenceType) +from _weakrefset import WeakSet as WeakSet + +if sys.version_info < (3, 0): + from exceptions import ReferenceError as ReferenceError + +_S = TypeVar('_S') +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +ProxyTypes: Tuple[Type[Any], ...] + +if sys.version_info >= (3, 4): + class WeakMethod(ref[types.MethodType]): + def __new__(cls, meth: types.MethodType, callback: Optional[Callable[[types.MethodType], Any]] = ...) -> WeakMethod: ... + def __call__(self) -> Optional[types.MethodType]: ... + +class WeakValueDictionary(MutableMapping[_KT, _VT]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, __map: Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]], **kwargs: _VT) -> None: ... + + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + if sys.version_info < (3, 0): + def has_key(self, key: object) -> bool: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + + def copy(self) -> WeakValueDictionary[_KT, _VT]: ... + + if sys.version_info < (3, 0): + def keys(self) -> List[_KT]: ... + def values(self) -> List[_VT]: ... + def items(self) -> List[Tuple[_KT, _VT]]: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + else: + # These are incompatible with Mapping + def keys(self) -> Iterator[_KT]: ... # type: ignore + def values(self) -> Iterator[_VT]: ... # type: ignore + def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore + def itervaluerefs(self) -> Iterator[KeyedRef[_KT, _VT]]: ... + def valuerefs(self) -> List[KeyedRef[_KT, _VT]]: ... + +class KeyedRef(ref[_T], Generic[_KT, _T]): + key: _KT + def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ... + +class WeakKeyDictionary(MutableMapping[_KT, _VT]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, __map: Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]], **kwargs: _VT) -> None: ... + + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + if sys.version_info < (3, 0): + def has_key(self, key: object) -> bool: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + + def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... + + if sys.version_info < (3, 0): + def keys(self) -> List[_KT]: ... + def values(self) -> List[_VT]: ... + def items(self) -> List[Tuple[_KT, _VT]]: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def iterkeyrefs(self) -> Iterator[ref[_KT]]: ... + else: + # These are incompatible with Mapping + def keys(self) -> Iterator[_KT]: ... # type: ignore + def values(self) -> Iterator[_VT]: ... # type: ignore + def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore + def keyrefs(self) -> List[ref[_KT]]: ... + +if sys.version_info >= (3, 4): + class finalize: + def __init__(self, obj: _S, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, _: Any = ...) -> Optional[_T]: ... + def detach(self) -> Optional[Tuple[_S, _T, Tuple[Any, ...], Dict[str, Any]]]: ... + def peek(self) -> Optional[Tuple[_S, _T, Tuple[Any, ...], Dict[str, Any]]]: ... + alive: bool + atexit: bool diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/webbrowser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/webbrowser.pyi new file mode 100644 index 000000000..3d276c8c0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/webbrowser.pyi @@ -0,0 +1,96 @@ +import sys +from typing import Any, Optional, Callable, List, Text, Union, Sequence + +class Error(Exception): ... + +def register(name: Text, klass: Optional[Callable[[], BaseBrowser]], instance: BaseBrowser = ..., update_tryorder: int = ...) -> None: ... +def get(using: Optional[Text] = ...) -> BaseBrowser: ... +def open(url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... +def open_new(url: Text) -> bool: ... +def open_new_tab(url: Text) -> bool: ... + +class BaseBrowser: + args = ... # type: List[str] + name = ... # type: str + basename = ... # type: str + def __init__(self, name: Text = ...) -> None: ... + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + def open_new(self, url: Text) -> bool: ... + def open_new_tab(self, url: Text) -> bool: ... + +class GenericBrowser(BaseBrowser): + args = ... # type: List[str] + name = ... # type: str + basename = ... # type: str + def __init__(self, name: Union[Text, Sequence[Text]]) -> None: ... + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class BackgroundBrowser(GenericBrowser): + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class UnixBrowser(BaseBrowser): + raise_opts = ... # type: List[str] + background = ... # type: bool + redirect_stdout = ... # type: bool + remote_args = ... # type: List[str] + remote_action = ... # type: str + remote_action_newwin = ... # type: str + remote_action_newtab = ... # type: str + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class Mozilla(UnixBrowser): + raise_opts = ... # type: List[str] + remote_args = ... # type: List[str] + remote_action = ... # type: str + remote_action_newwin = ... # type: str + remote_action_newtab = ... # type: str + background = ... # type: bool + +class Galeon(UnixBrowser): + raise_opts = ... # type: List[str] + remote_args = ... # type: List[str] + remote_action = ... # type: str + remote_action_newwin = ... # type: str + background = ... # type: bool + +if sys.version_info[:2] == (2, 7) or sys.version_info >= (3, 3): + class Chrome(UnixBrowser): + remote_args = ... # type: List[str] + remote_action = ... # type: str + remote_action_newwin = ... # type: str + remote_action_newtab = ... # type: str + background = ... # type: bool + +class Opera(UnixBrowser): + raise_opts = ... # type: List[str] + remote_args = ... # type: List[str] + remote_action = ... # type: str + remote_action_newwin = ... # type: str + remote_action_newtab = ... # type: str + background = ... # type: bool + +class Elinks(UnixBrowser): + remote_args = ... # type: List[str] + remote_action = ... # type: str + remote_action_newwin = ... # type: str + remote_action_newtab = ... # type: str + background = ... # type: bool + redirect_stdout = ... # type: bool + +class Konqueror(BaseBrowser): + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class Grail(BaseBrowser): + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class WindowsDefault(BaseBrowser): + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class MacOSX(BaseBrowser): + name = ... # type: str + def __init__(self, name: Text) -> None: ... + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... + +class MacOSXOSAScript(BaseBrowser): + def __init__(self, name: Text) -> None: ... + def open(self, url: Text, new: int = ..., autoraise: bool = ...) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/handlers.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/handlers.pyi new file mode 100644 index 000000000..3271c881a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/handlers.pyi @@ -0,0 +1,87 @@ +import sys +from abc import abstractmethod +from types import TracebackType +from typing import Optional, Dict, MutableMapping, Type, Text, Callable, List, Tuple, IO + +from .headers import Headers +from .types import WSGIApplication, WSGIEnvironment, StartResponse, InputStream, ErrorStream +from .util import FileWrapper, guess_scheme + +_exc_info = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] + +def format_date_time(timestamp: Optional[float]) -> str: ... # undocumented +if sys.version_info >= (3, 2): + def read_environ() -> Dict[str, str]: ... + +class BaseHandler: + wsgi_version: Tuple[int, int] # undocumented + wsgi_multithread: bool + wsgi_multiprocess: bool + wsgi_run_once: bool + + origin_server: bool + http_version: str + server_software: Optional[str] + + os_environ: MutableMapping[str, str] + + wsgi_file_wrapper: Optional[Type[FileWrapper]] + headers_class: Type[Headers] # undocumented + + traceback_limit: Optional[int] + error_status: str + error_headers: List[Tuple[Text, Text]] + error_body: bytes + + def run(self, application: WSGIApplication) -> None: ... + + def setup_environ(self) -> None: ... + def finish_response(self) -> None: ... + def get_scheme(self) -> str: ... + def set_content_length(self) -> None: ... + def cleanup_headers(self) -> None: ... + def start_response(self, status: Text, headers: List[Tuple[Text, Text]], exc_info: Optional[_exc_info] = ...) -> Callable[[bytes], None]: ... + def send_preamble(self) -> None: ... + def write(self, data: bytes) -> None: ... + def sendfile(self) -> bool: ... + def finish_content(self) -> None: ... + def close(self) -> None: ... + def send_headers(self) -> None: ... + def result_is_file(self) -> bool: ... + def client_is_modern(self) -> bool: ... + def log_exception(self, exc_info: _exc_info) -> None: ... + def handle_error(self) -> None: ... + def error_output(self, environ: WSGIEnvironment, start_response: StartResponse) -> List[bytes]: ... + + @abstractmethod + def _write(self, data: bytes) -> None: ... + @abstractmethod + def _flush(self) -> None: ... + @abstractmethod + def get_stdin(self) -> InputStream: ... + @abstractmethod + def get_stderr(self) -> ErrorStream: ... + @abstractmethod + def add_cgi_vars(self) -> None: ... + +class SimpleHandler(BaseHandler): + stdin: InputStream + stdout: IO[bytes] + stderr: ErrorStream + base_env: MutableMapping[str, str] + def __init__(self, stdin: InputStream, stdout: IO[bytes], stderr: ErrorStream, environ: MutableMapping[str, str], multithread: bool = ..., multiprocess: bool = ...) -> None: ... + def get_stdin(self) -> InputStream: ... + def get_stderr(self) -> ErrorStream: ... + def add_cgi_vars(self) -> None: ... + def _write(self, data: bytes) -> None: ... + def _flush(self) -> None: ... + +class BaseCGIHandler(SimpleHandler): ... + +class CGIHandler(BaseCGIHandler): + def __init__(self) -> None: ... + +class IISCGIHandler(BaseCGIHandler): + def __init__(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/headers.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/headers.pyi new file mode 100644 index 000000000..853922527 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/headers.pyi @@ -0,0 +1,31 @@ +import sys +from typing import overload, Pattern, Optional, List, Tuple + +_HeaderList = List[Tuple[str, str]] + +tspecials: Pattern[str] # undocumented + +class Headers: + if sys.version_info < (3, 5): + def __init__(self, headers: _HeaderList) -> None: ... + else: + def __init__(self, headers: Optional[_HeaderList] = ...) -> None: ... + def __len__(self) -> int: ... + def __setitem__(self, name: str, val: str) -> None: ... + def __delitem__(self, name: str) -> None: ... + def __getitem__(self, name: str) -> Optional[str]: ... + if sys.version_info < (3,): + def has_key(self, name: str) -> bool: ... + def __contains__(self, name: str) -> bool: ... + def get_all(self, name: str) -> List[str]: ... + @overload + def get(self, name: str, default: str) -> str: ... + @overload + def get(self, name: str, default: Optional[str] = ...) -> Optional[str]: ... + def keys(self) -> List[str]: ... + def values(self) -> List[str]: ... + def items(self) -> _HeaderList: ... + if sys.version_info >= (3,): + def __bytes__(self) -> bytes: ... + def setdefault(self, name: str, value: str) -> str: ... + def add_header(self, _name: str, _value: Optional[str], **_params: Optional[str]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/simple_server.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/simple_server.pyi new file mode 100644 index 000000000..50b8377e5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/simple_server.pyi @@ -0,0 +1,40 @@ +import sys +from typing import Optional, List, Type, TypeVar, overload + +from .handlers import SimpleHandler +from .types import WSGIApplication, WSGIEnvironment, StartResponse, ErrorStream + +if sys.version_info < (3,): + from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +else: + from http.server import HTTPServer, BaseHTTPRequestHandler + +server_version: str # undocumented +sys_version: str # undocumented +software_version: str # undocumented + +class ServerHandler(SimpleHandler): # undocumented + server_software: str + def close(self) -> None: ... + +class WSGIServer(HTTPServer): + application: Optional[WSGIApplication] + base_environ: WSGIEnvironment # only available after call to setup_environ() + def setup_environ(self) -> None: ... + def get_app(self) -> Optional[WSGIApplication]: ... + def set_app(self, application: Optional[WSGIApplication]) -> None: ... + +class WSGIRequestHandler(BaseHTTPRequestHandler): + server_version: str + def get_environ(self) -> WSGIEnvironment: ... + def get_stderr(self) -> ErrorStream: ... + def handle(self) -> None: ... + +def demo_app(environ: WSGIEnvironment, start_response: StartResponse) -> List[bytes]: ... + +_S = TypeVar("_S", bound=WSGIServer) + +@overload +def make_server(host: str, port: int, app: WSGIApplication, *, handler_class: Type[WSGIRequestHandler] = ...) -> WSGIServer: ... +@overload +def make_server(host: str, port: int, app: WSGIApplication, server_class: Type[_S], handler_class: Type[WSGIRequestHandler] = ...) -> _S: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/types.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/types.pyi new file mode 100644 index 000000000..6db16b852 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/types.pyi @@ -0,0 +1,42 @@ +# Type declaration for a WSGI Function +# +# wsgiref/types.py doesn't exist and neither do the types defined in this +# file. They are provided for type checking purposes. +# +# This means you cannot simply import wsgiref.types in your code. Instead, +# use the `TYPE_CHECKING` flag from the typing module: +# +# from typing import TYPE_CHECKING +# +# if TYPE_CHECKING: +# from wsgiref.types import WSGIApplication +# +# This import is now only taken into account by the type checker. Consequently, +# you need to use 'WSGIApplication' and not simply WSGIApplication when type +# hinting your code. Otherwise Python will raise NameErrors. + +from typing import Callable, Dict, Iterable, List, Optional, Tuple, Type, Union, Any, Text, Protocol +from types import TracebackType + +_exc_info = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] +StartResponse = Union[ + Callable[[Text, List[Tuple[Text, Text]]], Callable[[bytes], None]], + Callable[[Text, List[Tuple[Text, Text]], _exc_info], Callable[[bytes], None]] +] +WSGIEnvironment = Dict[Text, Any] +WSGIApplication = Callable[[WSGIEnvironment, StartResponse], Iterable[bytes]] + +# WSGI input streams per PEP 3333 +class InputStream(Protocol): + def read(self, size: int = ...) -> bytes: ... + def readline(self, size: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def __iter__(self) -> Iterable[bytes]: ... + +# WSGI error streams per PEP 3333 +class ErrorStream(Protocol): + def flush(self) -> None: ... + def write(self, s: str) -> None: ... + def writelines(self, seq: List[str]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/util.pyi new file mode 100644 index 000000000..501ddcd5b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/util.pyi @@ -0,0 +1,23 @@ +import sys +from typing import IO, Any, Optional + +from .types import WSGIEnvironment + +class FileWrapper: + filelike: IO[bytes] + blksize: int + def __init__(self, filelike: IO[bytes], bklsize: int = ...) -> None: ... + def __getitem__(self, key: Any) -> bytes: ... + def __iter__(self) -> FileWrapper: ... + if sys.version_info < (3,): + def next(self) -> bytes: ... + else: + def __next__(self) -> bytes: ... + def close(self) -> None: ... # only exists if filelike.close exists + +def guess_scheme(environ: WSGIEnvironment) -> str: ... +def application_uri(environ: WSGIEnvironment) -> str: ... +def request_uri(environ: WSGIEnvironment, include_query: bool = ...) -> str: ... +def shift_path_info(environ: WSGIEnvironment) -> Optional[str]: ... +def setup_testing_defaults(environ: WSGIEnvironment) -> None: ... +def is_hop_by_hop(header_name: str) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/validate.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/validate.pyi new file mode 100644 index 000000000..c7fa699fc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/wsgiref/validate.pyi @@ -0,0 +1,53 @@ +import sys +from typing import Any, Iterable, Iterator, Optional, NoReturn, Callable + +from wsgiref.types import WSGIApplication, InputStream, ErrorStream + +class WSGIWarning(Warning): ... + +def validator(application: WSGIApplication) -> WSGIApplication: ... + +class InputWrapper: + input: InputStream + def __init__(self, wsgi_input: InputStream) -> None: ... + if sys.version_info < (3,): + def read(self, size: int = ...) -> bytes: ... + def readline(self) -> bytes: ... + else: + def read(self, size: int) -> bytes: ... + def readline(self, size: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> bytes: ... + def __iter__(self) -> Iterable[bytes]: ... + def close(self) -> NoReturn: ... + +class ErrorWrapper: + errors: ErrorStream + def __init__(self, wsgi_errors: ErrorStream) -> None: ... + def write(self, s: str) -> None: ... + def flush(self) -> None: ... + def writelines(self, seq: Iterable[str]) -> None: ... + def close(self) -> NoReturn: ... + +class WriteWrapper: + writer: Callable[[bytes], Any] + def __init__(self, wsgi_writer: Callable[[bytes], Any]) -> None: ... + def __call__(self, s: bytes) -> None: ... + +class PartialIteratorWrapper: + iterator: Iterator[bytes] + def __init__(self, wsgi_iterator: Iterator[bytes]) -> None: ... + def __iter__(self) -> IteratorWrapper: ... + +class IteratorWrapper: + original_iterator: Iterator[bytes] + iterator: Iterator[bytes] + closed: bool + check_start_response: Optional[bool] + def __init__(self, wsgi_iterator: Iterator[bytes], check_start_response: Optional[bool]) -> None: ... + def __iter__(self) -> IteratorWrapper: ... + if sys.version_info < (3,): + def next(self) -> bytes: ... + else: + def __next__(self) -> bytes: ... + def close(self) -> None: ... + def __del__(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xdrlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xdrlib.pyi new file mode 100644 index 000000000..bbdaa5802 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xdrlib.pyi @@ -0,0 +1,56 @@ +# Structs for xdrlib (Python 2 and 3) +from typing import Callable, List, Sequence, TypeVar + +_T = TypeVar('_T') + +class Error(Exception): + msg = ... # type: str + def __init__(self, msg: str) -> None: ... + +class ConversionError(Error): ... + +class Packer: + def __init__(self) -> None: ... + def reset(self) -> None: ... + def get_buffer(self) -> bytes: ... + def get_buf(self) -> bytes: ... + def pack_uint(self, x: int) -> None: ... + def pack_int(self, x: int) -> None: ... + def pack_enum(self, x: int) -> None: ... + def pack_bool(self, x: bool) -> None: ... + def pack_uhyper(self, x: int) -> None: ... + def pack_hyper(self, x: int) -> None: ... + def pack_float(self, x: float) -> None: ... + def pack_double(self, x: float) -> None: ... + def pack_fstring(self, n: int, s: bytes) -> None: ... + def pack_fopaque(self, n: int, s: bytes) -> None: ... + def pack_string(self, s: bytes) -> None: ... + def pack_opaque(self, s: bytes) -> None: ... + def pack_bytes(self, s: bytes) -> None: ... + def pack_list(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... + def pack_farray(self, n: int, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... + def pack_array(self, list: Sequence[_T], pack_item: Callable[[_T], None]) -> None: ... + +class Unpacker: + def __init__(self, data: bytes) -> None: ... + def reset(self, data: bytes) -> None: ... + def get_position(self) -> int: ... + def set_position(self, position: int) -> None: ... + def get_buffer(self) -> bytes: ... + def done(self) -> None: ... + def unpack_uint(self) -> int: ... + def unpack_int(self) -> int: ... + def unpack_enum(self) -> int: ... + def unpack_bool(self) -> bool: ... + def unpack_uhyper(self) -> int: ... + def unpack_hyper(self) -> int: ... + def unpack_float(self) -> float: ... + def unpack_double(self) -> float: ... + def unpack_fstring(self, n: int) -> bytes: ... + def unpack_fopaque(self, n: int) -> bytes: ... + def unpack_string(self) -> bytes: ... + def unpack_opaque(self) -> bytes: ... + def unpack_bytes(self) -> bytes: ... + def unpack_list(self, unpack_item: Callable[[], _T]) -> List[_T]: ... + def unpack_farray(self, n: int, unpack_item: Callable[[], _T]) -> List[_T]: ... + def unpack_array(self, unpack_item: Callable[[], _T]) -> List[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/__init__.pyi new file mode 100644 index 000000000..c524ac2b1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/__init__.pyi @@ -0,0 +1 @@ +import xml.parsers as parsers diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementInclude.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementInclude.pyi new file mode 100644 index 000000000..519506e66 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementInclude.pyi @@ -0,0 +1,17 @@ +# Stubs for xml.etree.ElementInclude (Python 3.4) + +from typing import Union, Optional, Callable +from xml.etree.ElementTree import Element + +XINCLUDE = ... # type: str +XINCLUDE_INCLUDE = ... # type: str +XINCLUDE_FALLBACK = ... # type: str + +class FatalIncludeError(SyntaxError): ... + +def default_loader(href: Union[str, bytes, int], parse: str, encoding: Optional[str]=...) -> Union[str, Element]: ... + +# TODO: loader is of type default_loader ie it takes a callable that has the +# same signature as default_loader. But default_loader has a keyword argument +# Which can't be represented using Callable... +def include(elem: Element, loader: Callable[..., Union[str, Element]]=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementPath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementPath.pyi new file mode 100644 index 000000000..91e85cd6c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementPath.pyi @@ -0,0 +1,33 @@ +# Stubs for xml.etree.ElementPath (Python 3.4) + +from typing import Pattern, Dict, Generator, Tuple, List, Union, TypeVar, Callable, Optional +from xml.etree.ElementTree import Element + +xpath_tokenizer_re = ... # type: Pattern + +_token = Tuple[str, str] +_next = Callable[[], _token] +_callback = Callable[['_SelectorContext', List[Element]], Generator[Element, None, None]] + +def xpath_tokenizer(pattern: str, namespaces: Dict[str, str]=...) -> Generator[_token, None, None]: ... +def get_parent_map(context: '_SelectorContext') -> Dict[Element, Element]: ... +def prepare_child(next: _next, token: _token) -> _callback: ... +def prepare_star(next: _next, token: _token) -> _callback: ... +def prepare_self(next: _next, token: _token) -> _callback: ... +def prepare_descendant(next: _next, token: _token) -> _callback: ... +def prepare_parent(next: _next, token: _token) -> _callback: ... +def prepare_predicate(next: _next, token: _token) -> _callback: ... + +ops = ... # type: Dict[str, Callable[[_next, _token], _callback]] + +class _SelectorContext: + parent_map = ... # type: Dict[Element, Element] + root = ... # type: Element + def __init__(self, root: Element) -> None: ... + +_T = TypeVar('_T') + +def iterfind(elem: Element, path: str, namespaces: Dict[str, str]=...) -> List[Element]: ... +def find(elem: Element, path: str, namespaces: Dict[str, str]=...) -> Optional[Element]: ... +def findall(elem: Element, path: str, namespaces: Dict[str, str]=...) -> List[Element]: ... +def findtext(elem: Element, path: str, default: _T=..., namespaces: Dict[str, str]=...) -> Union[_T, str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementTree.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementTree.pyi new file mode 100644 index 000000000..f79281917 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/ElementTree.pyi @@ -0,0 +1,167 @@ +# Stubs for xml.etree.ElementTree + +from typing import Any, Callable, Dict, Generator, IO, ItemsView, Iterable, Iterator, KeysView, List, MutableSequence, Optional, overload, Sequence, Text, Tuple, TypeVar, Union +import io +import sys + +VERSION = ... # type: str + +class ParseError(SyntaxError): ... + +def iselement(element: 'Element') -> bool: ... + +_T = TypeVar('_T') + +# Type for parser inputs. Parser will accept any unicode/str/bytes and coerce, +# and this is true in py2 and py3 (even fromstringlist() in python3 can be +# called with a heterogeneous list) +_parser_input_type = Union[bytes, Text] + +# Type for individual tag/attr/ns/text values in args to most functions. +# In py2, the library accepts str or unicode everywhere and coerces +# aggressively. +# In py3, bytes is not coerced to str and so use of bytes is probably an error, +# so we exclude it. (why? the parser never produces bytes when it parses XML, +# so e.g., element.get(b'name') will always return None for parsed XML, even if +# there is a 'name' attribute.) +_str_argument_type = Union[str, Text] + +# Type for return values from individual tag/attr/text values and serialization +if sys.version_info >= (3,): + # note: in python3, everything comes out as str, yay: + _str_result_type = str + # unfortunately, tostring and tostringlist can return either bytes or str + # depending on the value of `encoding` parameter. Client code knows best: + _tostring_result_type = Any +else: + # in python2, if the tag/attribute/text wasn't decode-able as ascii, it + # comes out as a unicode string; otherwise it comes out as str. (see + # _fixtext function in the source). Client code knows best: + _str_result_type = Any + # On the bright side, tostring and tostringlist always return bytes: + _tostring_result_type = bytes + +class Element(MutableSequence['Element']): + tag = ... # type: _str_result_type + attrib = ... # type: Dict[_str_result_type, _str_result_type] + text = ... # type: Optional[_str_result_type] + tail = ... # type: Optional[_str_result_type] + def __init__(self, tag: Union[_str_argument_type, Callable[..., 'Element']], attrib: Dict[_str_argument_type, _str_argument_type]=..., **extra: _str_argument_type) -> None: ... + def append(self, subelement: 'Element') -> None: ... + def clear(self) -> None: ... + def copy(self) -> 'Element': ... + def extend(self, elements: Iterable['Element']) -> None: ... + def find(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Optional['Element']: ... + def findall(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List['Element']: ... + def findtext(self, path: _str_argument_type, default: _T=..., namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Union[_T, _str_result_type]: ... + def get(self, key: _str_argument_type, default: _T=...) -> Union[_str_result_type, _T]: ... + def getchildren(self) -> List['Element']: ... + def getiterator(self, tag: _str_argument_type=...) -> List['Element']: ... + if sys.version_info >= (3, 2): + def insert(self, index: int, subelement: 'Element') -> None: ... + else: + def insert(self, index: int, element: 'Element') -> None: ... + def items(self) -> ItemsView[_str_result_type, _str_result_type]: ... + def iter(self, tag: _str_argument_type=...) -> Generator['Element', None, None]: ... + def iterfind(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List['Element']: ... + def itertext(self) -> Generator[_str_result_type, None, None]: ... + def keys(self) -> KeysView[_str_result_type]: ... + def makeelement(self, tag: _str_argument_type, attrib: Dict[_str_argument_type, _str_argument_type]) -> 'Element': ... + def remove(self, subelement: 'Element') -> None: ... + def set(self, key: _str_argument_type, value: _str_argument_type) -> None: ... + def __bool__(self) -> bool: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + @overload + def __getitem__(self, i: int) -> 'Element': ... + @overload + def __getitem__(self, s: slice) -> Sequence['Element']: ... + def __len__(self) -> int: ... + @overload + def __setitem__(self, i: int, o: 'Element') -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable['Element']) -> None: ... + + +def SubElement(parent: Element, tag: _str_argument_type, attrib: Dict[_str_argument_type, _str_argument_type]=..., **extra: _str_argument_type) -> Element: ... +def Comment(text: _str_argument_type=...) -> Element: ... +def ProcessingInstruction(target: _str_argument_type, text: _str_argument_type=...) -> Element: ... + +PI = ... # type: Callable[..., Element] + +class QName: + text = ... # type: str + def __init__(self, text_or_uri: _str_argument_type, tag: _str_argument_type=...) -> None: ... + + +_file_or_filename = Union[str, bytes, int, IO[Any]] + +class ElementTree: + def __init__(self, element: Element=..., file: _file_or_filename=...) -> None: ... + def getroot(self) -> Element: ... + def parse(self, source: _file_or_filename, parser: 'XMLParser'=...) -> Element: ... + def iter(self, tag: _str_argument_type=...) -> Generator[Element, None, None]: ... + def getiterator(self, tag: _str_argument_type=...) -> List[Element]: ... + def find(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Optional[Element]: ... + def findtext(self, path: _str_argument_type, default: _T=..., namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> Union[_T, _str_result_type]: ... + def findall(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List[Element]: ... + def iterfind(self, path: _str_argument_type, namespaces: Dict[_str_argument_type, _str_argument_type]=...) -> List[Element]: ... + if sys.version_info >= (3, 4): + def write(self, file_or_filename: _file_or_filename, encoding: str=..., xml_declaration: Optional[bool]=..., default_namespace: _str_argument_type=..., method: str=..., *, short_empty_elements: bool=...) -> None: ... + else: + def write(self, file_or_filename: _file_or_filename, encoding: str=..., xml_declaration: Optional[bool]=..., default_namespace: _str_argument_type=..., method: str=...) -> None: ... + def write_c14n(self, file: _file_or_filename) -> None: ... + +def register_namespace(prefix: _str_argument_type, uri: _str_argument_type) -> None: ... +if sys.version_info >= (3, 4): + def tostring(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> _tostring_result_type: ... + def tostringlist(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> List[_tostring_result_type]: ... +else: + def tostring(element: Element, encoding: str=..., method: str=...) -> _tostring_result_type: ... + def tostringlist(element: Element, encoding: str=..., method: str=...) -> List[_tostring_result_type]: ... +def dump(elem: Element) -> None: ... +def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ... +def iterparse(source: _file_or_filename, events: Sequence[str]=..., parser: 'XMLParser'=...) -> Iterator[Tuple[str, Any]]: ... + +if sys.version_info >= (3, 4): + class XMLPullParser: + def __init__(self, events: Sequence[str]=..., *, _parser: 'XMLParser'=...) -> None: ... + def feed(self, data: bytes) -> None: ... + def close(self) -> None: ... + def read_events(self) -> Iterator[Tuple[str, Element]]: ... + +def XML(text: _parser_input_type, parser: 'XMLParser'=...) -> Element: ... +def XMLID(text: _parser_input_type, parser: 'XMLParser'=...) -> Tuple[Element, Dict[_str_result_type, Element]]: ... + +# This is aliased to XML in the source. +fromstring = XML + +def fromstringlist(sequence: Sequence[_parser_input_type], parser: 'XMLParser'=...) -> Element: ... + +# This type is both not precise enough and too precise. The TreeBuilder +# requires the elementfactory to accept tag and attrs in its args and produce +# some kind of object that has .text and .tail properties. +# I've chosen to constrain the ElementFactory to always produce an Element +# because that is how almost everyone will use it. +# Unfortunately, the type of the factory arguments is dependent on how +# TreeBuilder is called by client code (they could pass strs, bytes or whatever); +# but we don't want to use a too-broad type, or it would be too hard to write +# elementfactories. +_ElementFactory = Callable[[Any, Dict[Any, Any]], Element] + +class TreeBuilder: + def __init__(self, element_factory: _ElementFactory=...) -> None: ... + def close(self) -> Element: ... + def data(self, data: _parser_input_type) -> None: ... + def start(self, tag: _parser_input_type, attrs: Dict[_parser_input_type, _parser_input_type]) -> Element: ... + def end(self, tag: _parser_input_type) -> Element: ... + +class XMLParser: + parser = ... # type: Any + target = ... # type: TreeBuilder + # TODO-what is entity used for??? + entity = ... # type: Any + version = ... # type: str + def __init__(self, html: int=..., target: TreeBuilder=..., encoding: str=...) -> None: ... + def doctype(self, name: str, pubid: str, system: str) -> None: ... + def close(self) -> Element: ... + def feed(self, data: _parser_input_type) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/cElementTree.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/cElementTree.pyi new file mode 100644 index 000000000..c384968d0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/etree/cElementTree.pyi @@ -0,0 +1,3 @@ +# Stubs for xml.etree.cElementTree (Python 3.4) + +from xml.etree.ElementTree import * # noqa: F403 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/__init__.pyi new file mode 100644 index 000000000..cac086235 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/__init__.pyi @@ -0,0 +1 @@ +import xml.parsers.expat as expat diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/__init__.pyi new file mode 100644 index 000000000..670e56106 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/__init__.pyi @@ -0,0 +1,75 @@ +from typing import List, Tuple, Optional, Callable, Any, Protocol, Union, Dict, Text + +import pyexpat.errors as errors +import pyexpat.model as model + +EXPAT_VERSION: str # undocumented +version_info: Tuple[int, int, int] # undocumented +native_encoding: str # undocumented +features: List[Tuple[str, int]] # undocumented + +class ExpatError(Exception): + code: int + lineno: int + offset: int + +error = ExpatError + +class _Reader(Protocol): + def read(self, length: int) -> bytes: ... + +XML_PARAM_ENTITY_PARSING_NEVER: int +XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: int +XML_PARAM_ENTITY_PARSING_ALWAYS: int + +_Model = Tuple[int, int, Optional[str], tuple] + +class XMLParserType(object): + def Parse(self, data: Union[Text, bytes], isfinal: bool = ...) -> int: ... + def ParseFile(self, file: _Reader) -> int: ... + def SetBase(self, base: Text) -> None: ... + def GetBase(self) -> Optional[str]: ... + def GetInputContext(self) -> Optional[bytes]: ... + def ExternalEntityParserCreate(self, context: Optional[Text], encoding: Text = ...) -> XMLParserType: ... + def SetParamEntityParsing(self, flag: int) -> int: ... + def UseForeignDTD(self, flag: bool = ...) -> None: ... + buffer_size: int + buffer_text: bool + buffer_used: int + namespace_prefixes: bool # undocumented + ordered_attributes: bool + specified_attributes: bool + ErrorByteIndex: int + ErrorCode: int + ErrorColumnNumber: int + ErrorLineNumber: int + CurrentByteIndex: int + CurrentColumnNumber: int + CurrentLineNumber: int + XmlDeclHandler: Optional[Callable[[str, Optional[str], int], Any]] + StartDoctypeDeclHandler: Optional[Callable[[str, Optional[str], Optional[str], bool], Any]] + EndDoctypeDeclHandler: Optional[Callable[[], Any]] + ElementDeclHandler: Optional[Callable[[str, _Model], Any]] + AttlistDeclHandler: Optional[Callable[[str, str, str, Optional[str], bool], Any]] + StartElementHandler: Optional[Union[ + Callable[[str, Dict[str, str]], Any], + Callable[[str, List[str]], Any], + Callable[[str, Union[Dict[str, str]], List[str]], Any]]] + EndElementHandler: Optional[Callable[[str], Any]] + ProcessingInstructionHandler: Optional[Callable[[str, str], Any]] + CharacterDataHandler: Optional[Callable[[str], Any]] + UnparsedEntityDeclHandler: Optional[Callable[[str, Optional[str], str, Optional[str], str], Any]] + EntityDeclHandler: Optional[Callable[[str, bool, Optional[str], Optional[str], str, Optional[str], Optional[str]], Any]] + NotationDeclHandler: Optional[Callable[[str, Optional[str], str, Optional[str]], Any]] + StartNamespaceDeclHandler: Optional[Callable[[str, str], Any]] + EndNamespaceDeclHandler: Optional[Callable[[str], Any]] + CommentHandler: Optional[Callable[[str], Any]] + StartCdataSectionHandler: Optional[Callable[[], Any]] + EndCdataSectionHandler: Optional[Callable[[], Any]] + DefaultHandler: Optional[Callable[[str], Any]] + DefaultHandlerExpand: Optional[Callable[[str], Any]] + NotStandaloneHandler: Optional[Callable[[], int]] + ExternalEntityRefHandler: Optional[Callable[[str, Optional[str], Optional[str], Optional[str]], int]] + +def ErrorString(errno: int) -> str: ... +def ParserCreate(encoding: Optional[Text] = ..., namespace_separator: Optional[Text] = ...) -> XMLParserType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/errors.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/errors.pyi new file mode 100644 index 000000000..6cde43e3b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/errors.pyi @@ -0,0 +1,44 @@ +import sys +from typing import Dict + +if sys.version_info >= (3, 2): + codes: Dict[str, int] + messages: Dict[int, str] + +XML_ERROR_ABORTED: str +XML_ERROR_ASYNC_ENTITY: str +XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF: str +XML_ERROR_BAD_CHAR_REF: str +XML_ERROR_BINARY_ENTITY_REF: str +XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING: str +XML_ERROR_DUPLICATE_ATTRIBUTE: str +XML_ERROR_ENTITY_DECLARED_IN_PE: str +XML_ERROR_EXTERNAL_ENTITY_HANDLING: str +XML_ERROR_FEATURE_REQUIRES_XML_DTD: str +XML_ERROR_FINISHED: str +XML_ERROR_INCOMPLETE_PE: str +XML_ERROR_INCORRECT_ENCODING: str +XML_ERROR_INVALID_TOKEN: str +XML_ERROR_JUNK_AFTER_DOC_ELEMENT: str +XML_ERROR_MISPLACED_XML_PI: str +XML_ERROR_NOT_STANDALONE: str +XML_ERROR_NOT_SUSPENDED: str +XML_ERROR_NO_ELEMENTS: str +XML_ERROR_NO_MEMORY: str +XML_ERROR_PARAM_ENTITY_REF: str +XML_ERROR_PARTIAL_CHAR: str +XML_ERROR_PUBLICID: str +XML_ERROR_RECURSIVE_ENTITY_REF: str +XML_ERROR_SUSPENDED: str +XML_ERROR_SUSPEND_PE: str +XML_ERROR_SYNTAX: str +XML_ERROR_TAG_MISMATCH: str +XML_ERROR_TEXT_DECL: str +XML_ERROR_UNBOUND_PREFIX: str +XML_ERROR_UNCLOSED_CDATA_SECTION: str +XML_ERROR_UNCLOSED_TOKEN: str +XML_ERROR_UNDECLARING_PREFIX: str +XML_ERROR_UNDEFINED_ENTITY: str +XML_ERROR_UNEXPECTED_STATE: str +XML_ERROR_UNKNOWN_ENCODING: str +XML_ERROR_XML_DECL: str diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/model.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/model.pyi new file mode 100644 index 000000000..f357cf651 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/parsers/expat/model.pyi @@ -0,0 +1,11 @@ +XML_CTYPE_ANY: int +XML_CTYPE_CHOICE: int +XML_CTYPE_EMPTY: int +XML_CTYPE_MIXED: int +XML_CTYPE_NAME: int +XML_CTYPE_SEQ: int + +XML_CQUANT_NONE: int +XML_CQUANT_OPT: int +XML_CQUANT_PLUS: int +XML_CQUANT_REP: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/__init__.pyi new file mode 100644 index 000000000..b694b43b8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/__init__.pyi @@ -0,0 +1,34 @@ +from typing import Any, List, NoReturn, Optional, Text, Union, IO + +import xml.sax +from xml.sax.xmlreader import InputSource, Locator +from xml.sax.handler import ContentHandler, ErrorHandler + +class SAXException(Exception): + def __init__(self, msg: str, exception: Optional[Exception] = ...) -> None: ... + def getMessage(self) -> str: ... + def getException(self) -> Exception: ... + def __getitem__(self, ix: Any) -> NoReturn: ... + +class SAXParseException(SAXException): + def __init__(self, msg: str, exception: Exception, locator: Locator) -> None: ... + def getColumnNumber(self) -> int: ... + def getLineNumber(self) -> int: ... + def getPublicId(self): ... + def getSystemId(self): ... + +class SAXNotRecognizedException(SAXException): ... +class SAXNotSupportedException(SAXException): ... +class SAXReaderNotAvailable(SAXNotSupportedException): ... + +default_parser_list = ... # type: List[str] + +def make_parser(parser_list: List[str] = ...) -> xml.sax.xmlreader.XMLReader: ... + +def parse(source: Union[str, IO[str]], handler: xml.sax.handler.ContentHandler, + errorHandler: xml.sax.handler.ErrorHandler = ...) -> None: ... + +def parseString(string: Union[bytes, Text], handler: xml.sax.handler.ContentHandler, + errorHandler: Optional[xml.sax.handler.ErrorHandler] = ...) -> None: ... + +def _create_parser(parser_name: str) -> xml.sax.xmlreader.XMLReader: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/handler.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/handler.pyi new file mode 100644 index 000000000..0b549b987 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/handler.pyi @@ -0,0 +1,46 @@ +from typing import Any + +version = ... # type: Any + +class ErrorHandler: + def error(self, exception): ... + def fatalError(self, exception): ... + def warning(self, exception): ... + +class ContentHandler: + def __init__(self) -> None: ... + def setDocumentLocator(self, locator): ... + def startDocument(self): ... + def endDocument(self): ... + def startPrefixMapping(self, prefix, uri): ... + def endPrefixMapping(self, prefix): ... + def startElement(self, name, attrs): ... + def endElement(self, name): ... + def startElementNS(self, name, qname, attrs): ... + def endElementNS(self, name, qname): ... + def characters(self, content): ... + def ignorableWhitespace(self, whitespace): ... + def processingInstruction(self, target, data): ... + def skippedEntity(self, name): ... + +class DTDHandler: + def notationDecl(self, name, publicId, systemId): ... + def unparsedEntityDecl(self, name, publicId, systemId, ndata): ... + +class EntityResolver: + def resolveEntity(self, publicId, systemId): ... + +feature_namespaces = ... # type: Any +feature_namespace_prefixes = ... # type: Any +feature_string_interning = ... # type: Any +feature_validation = ... # type: Any +feature_external_ges = ... # type: Any +feature_external_pes = ... # type: Any +all_features = ... # type: Any +property_lexical_handler = ... # type: Any +property_declaration_handler = ... # type: Any +property_dom_node = ... # type: Any +property_xml_string = ... # type: Any +property_encoding = ... # type: Any +property_interning_dict = ... # type: Any +all_properties = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/saxutils.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/saxutils.pyi new file mode 100644 index 000000000..80a497cd8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/saxutils.pyi @@ -0,0 +1,59 @@ +import sys +from typing import AnyStr, Mapping + +from xml.sax import handler +from xml.sax import xmlreader + +def escape(data: AnyStr, entities: Mapping[str, str] = ...) -> AnyStr: ... +def unescape(data: AnyStr, entities: Mapping[str, str] = ...) -> AnyStr: ... +def quoteattr(data: AnyStr, entities: Mapping[str, str] = ...) -> AnyStr: ... + +class XMLGenerator(handler.ContentHandler): + if sys.version_info >= (3, 0): + def __init__(self, out=..., encoding=..., + short_empty_elements: bool=...) -> None: ... + else: + def __init__(self, out=..., encoding=...) -> None: ... + def startDocument(self): ... + def endDocument(self): ... + def startPrefixMapping(self, prefix, uri): ... + def endPrefixMapping(self, prefix): ... + def startElement(self, name, attrs): ... + def endElement(self, name): ... + def startElementNS(self, name, qname, attrs): ... + def endElementNS(self, name, qname): ... + def characters(self, content): ... + def ignorableWhitespace(self, content): ... + def processingInstruction(self, target, data): ... + +class XMLFilterBase(xmlreader.XMLReader): + def __init__(self, parent=...) -> None: ... + def error(self, exception): ... + def fatalError(self, exception): ... + def warning(self, exception): ... + def setDocumentLocator(self, locator): ... + def startDocument(self): ... + def endDocument(self): ... + def startPrefixMapping(self, prefix, uri): ... + def endPrefixMapping(self, prefix): ... + def startElement(self, name, attrs): ... + def endElement(self, name): ... + def startElementNS(self, name, qname, attrs): ... + def endElementNS(self, name, qname): ... + def characters(self, content): ... + def ignorableWhitespace(self, chars): ... + def processingInstruction(self, target, data): ... + def skippedEntity(self, name): ... + def notationDecl(self, name, publicId, systemId): ... + def unparsedEntityDecl(self, name, publicId, systemId, ndata): ... + def resolveEntity(self, publicId, systemId): ... + def parse(self, source): ... + def setLocale(self, locale): ... + def getFeature(self, name): ... + def setFeature(self, name, state): ... + def getProperty(self, name): ... + def setProperty(self, name, value): ... + def getParent(self): ... + def setParent(self, parent): ... + +def prepare_input_source(source, base=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/xmlreader.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/xmlreader.pyi new file mode 100644 index 000000000..fbc1ac1ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/xml/sax/xmlreader.pyi @@ -0,0 +1,71 @@ +class XMLReader: + def __init__(self) -> None: ... + def parse(self, source): ... + def getContentHandler(self): ... + def setContentHandler(self, handler): ... + def getDTDHandler(self): ... + def setDTDHandler(self, handler): ... + def getEntityResolver(self): ... + def setEntityResolver(self, resolver): ... + def getErrorHandler(self): ... + def setErrorHandler(self, handler): ... + def setLocale(self, locale): ... + def getFeature(self, name): ... + def setFeature(self, name, state): ... + def getProperty(self, name): ... + def setProperty(self, name, value): ... + +class IncrementalParser(XMLReader): + def __init__(self, bufsize=...) -> None: ... + def parse(self, source): ... + def feed(self, data): ... + def prepareParser(self, source): ... + def close(self): ... + def reset(self): ... + +class Locator: + def getColumnNumber(self): ... + def getLineNumber(self): ... + def getPublicId(self): ... + def getSystemId(self): ... + +class InputSource: + def __init__(self, system_id=...) -> None: ... + def setPublicId(self, public_id): ... + def getPublicId(self): ... + def setSystemId(self, system_id): ... + def getSystemId(self): ... + def setEncoding(self, encoding): ... + def getEncoding(self): ... + def setByteStream(self, bytefile): ... + def getByteStream(self): ... + def setCharacterStream(self, charfile): ... + def getCharacterStream(self): ... + +class AttributesImpl: + def __init__(self, attrs) -> None: ... + def getLength(self): ... + def getType(self, name): ... + def getValue(self, name): ... + def getValueByQName(self, name): ... + def getNameByQName(self, name): ... + def getQNameByName(self, name): ... + def getNames(self): ... + def getQNames(self): ... + def __len__(self): ... + def __getitem__(self, name): ... + def keys(self): ... + def has_key(self, name): ... + def __contains__(self, name): ... + def get(self, name, alternative=...): ... + def copy(self): ... + def items(self): ... + def values(self): ... + +class AttributesNSImpl(AttributesImpl): + def __init__(self, attrs, qnames) -> None: ... + def getValueByQName(self, name): ... + def getNameByQName(self, name): ... + def getQNameByName(self, name): ... + def getQNames(self): ... + def copy(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zipfile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zipfile.pyi new file mode 100644 index 000000000..9ec363154 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zipfile.pyi @@ -0,0 +1,101 @@ +# Stubs for zipfile + +from typing import Callable, IO, Iterable, List, Optional, Text, Tuple, Type, Union +from types import TracebackType +import os +import sys + + +if sys.version_info >= (3, 6): + _Path = Union[os.PathLike[Text], Text] +else: + _Path = Text +_SZI = Union[Text, ZipInfo] +_DT = Tuple[int, int, int, int, int, int] + + +if sys.version_info >= (3,): + class BadZipFile(Exception): ... + BadZipfile = BadZipFile +else: + class BadZipfile(Exception): ... +error = BadZipfile + +class LargeZipFile(Exception): ... + +class ZipFile: + debug = ... # type: int + comment = ... # type: bytes + filelist = ... # type: List[ZipInfo] + def __init__(self, file: Union[_Path, IO[bytes]], mode: Text = ..., compression: int = ..., + allowZip64: bool = ...) -> None: ... + def __enter__(self) -> ZipFile: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + def close(self) -> None: ... + def getinfo(self, name: Text) -> ZipInfo: ... + def infolist(self) -> List[ZipInfo]: ... + def namelist(self) -> List[Text]: ... + def open(self, name: _SZI, mode: Text = ..., + pwd: Optional[bytes] = ...) -> IO[bytes]: ... + def extract(self, member: _SZI, path: Optional[_SZI] = ..., + pwd: bytes = ...) -> str: ... + def extractall(self, path: Optional[_Path] = ..., + members: Optional[Iterable[Text]] = ..., + pwd: Optional[bytes] = ...) -> None: ... + def printdir(self) -> None: ... + def setpassword(self, pwd: bytes) -> None: ... + def read(self, name: _SZI, pwd: Optional[bytes] = ...) -> bytes: ... + def testzip(self) -> Optional[str]: ... + def write(self, filename: _Path, arcname: Optional[_Path] = ..., + compress_type: Optional[int] = ...) -> None: ... + if sys.version_info >= (3,): + def writestr(self, zinfo_or_arcname: _SZI, data: Union[bytes, str], + compress_type: Optional[int] = ...) -> None: ... + else: + def writestr(self, + zinfo_or_arcname: _SZI, bytes: bytes, + compress_type: Optional[int] = ...) -> None: ... + +class PyZipFile(ZipFile): + if sys.version_info >= (3,): + def __init__(self, file: Union[str, IO[bytes]], mode: str = ..., + compression: int = ..., allowZip64: bool = ..., + opimize: int = ...) -> None: ... + def writepy(self, pathname: str, basename: str = ..., + filterfunc: Optional[Callable[[str], bool]] = ...) -> None: ... + else: + def writepy(self, + pathname: Text, basename: Text = ...) -> None: ... + +class ZipInfo: + filename = ... # type: Text + date_time = ... # type: _DT + compress_type = ... # type: int + comment = ... # type: bytes + extra = ... # type: bytes + create_system = ... # type: int + create_version = ... # type: int + extract_version = ... # type: int + reserved = ... # type: int + flag_bits = ... # type: int + volume = ... # type: int + internal_attr = ... # type: int + external_attr = ... # type: int + header_offset = ... # type: int + CRC = ... # type: int + compress_size = ... # type: int + file_size = ... # type: int + if sys.version_info < (3,): + def __init__(self, filename: Optional[Text] = ..., + date_time: Optional[_DT] = ...) -> None: ... + + +def is_zipfile(filename: Union[Text, IO[bytes]]) -> bool: ... + +ZIP_STORED = ... # type: int +ZIP_DEFLATED = ... # type: int +if sys.version_info >= (3, 3): + ZIP_BZIP2 = ... # type: int + ZIP_LZMA = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zipimport.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zipimport.pyi new file mode 100644 index 000000000..eb70eb307 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zipimport.pyi @@ -0,0 +1,18 @@ +"""Stub file for the 'zipimport' module.""" + +from typing import Optional +from types import CodeType, ModuleType + +class ZipImportError(ImportError): ... + +class zipimporter(object): + archive = ... # type: str + prefix = ... # type: str + def __init__(self, archivepath: str) -> None: ... + def find_module(self, fullname: str, path: str = ...) -> Optional[zipimporter]: ... + def get_code(self, fullname: str) -> CodeType: ... + def get_data(self, pathname: str) -> str: ... + def get_filename(self, fullname: str) -> str: ... + def get_source(self, fullname: str) -> Optional[str]: ... + def is_package(self, fullname: str) -> bool: ... + def load_module(self, fullname: str) -> ModuleType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zlib.pyi new file mode 100644 index 000000000..3300f5166 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/2and3/zlib.pyi @@ -0,0 +1,55 @@ +# Stubs for zlib +import sys + +DEFLATED = ... # type: int +DEF_MEM_LEVEL = ... # type: int +MAX_WBITS = ... # type: int +ZLIB_VERSION = ... # type: str +Z_BEST_COMPRESSION = ... # type: int +Z_BEST_SPEED = ... # type: int +Z_DEFAULT_COMPRESSION = ... # type: int +Z_DEFAULT_STRATEGY = ... # type: int +Z_FILTERED = ... # type: int +Z_FINISH = ... # type: int +Z_FULL_FLUSH = ... # type: int +Z_HUFFMAN_ONLY = ... # type: int +Z_NO_FLUSH = ... # type: int +Z_SYNC_FLUSH = ... # type: int +if sys.version_info >= (3,): + DEF_BUF_SIZE = ... # type: int + ZLIB_RUNTIME_VERSION = ... # type: str + +class error(Exception): ... + + +class _Compress: + def compress(self, data: bytes) -> bytes: ... + def flush(self, mode: int = ...) -> bytes: ... + def copy(self) -> _Compress: ... + + +class _Decompress: + unused_data = ... # type: bytes + unconsumed_tail = ... # type: bytes + if sys.version_info >= (3,): + eof = ... # type: bool + def decompress(self, data: bytes, max_length: int = ...) -> bytes: ... + def flush(self, length: int = ...) -> bytes: ... + def copy(self) -> _Decompress: ... + + +def adler32(data: bytes, value: int = ...) -> int: ... +def compress(data: bytes, level: int = ...) -> bytes: ... +if sys.version_info >= (3,): + def compressobj(level: int = ..., method: int = ..., wbits: int = ..., + memLevel: int = ..., strategy: int = ..., + zdict: bytes = ...) -> _Compress: ... +else: + def compressobj(level: int = ..., method: int = ..., wbits: int = ..., + memlevel: int = ..., strategy: int = ...) -> _Compress: ... +def crc32(data: bytes, value: int = ...) -> int: ... +def decompress(data: bytes, wbits: int = ..., bufsize: int = ...) -> bytes: ... +if sys.version_info >= (3,): + def decompressobj(wbits: int = ..., zdict: bytes = ...) -> _Decompress: ... +else: + def decompressobj(wbits: int = ...) -> _Decompress: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.3/ipaddress.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.3/ipaddress.pyi new file mode 100644 index 000000000..11079f734 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.3/ipaddress.pyi @@ -0,0 +1,150 @@ +import sys +from typing import (Any, Container, Generic, Iterable, Iterator, Optional, + overload, SupportsInt, Tuple, TypeVar, Union) + +# Undocumented length constants +IPV4LENGTH: int +IPV6LENGTH: int + +_A = TypeVar("_A", IPv4Address, IPv6Address) +_N = TypeVar("_N", IPv4Network, IPv6Network) +_T = TypeVar("_T") + +def ip_address(address: object) -> Union[IPv4Address, IPv6Address]: ... +def ip_network(address: object, strict: bool = ...) -> Union[IPv4Network, IPv6Network]: ... +def ip_interface(address: object) -> Union[IPv4Interface, IPv6Interface]: ... + +class _IPAddressBase: + def __eq__(self, other: Any) -> bool: ... + def __ge__(self: _T, other: _T) -> bool: ... + def __gt__(self: _T, other: _T) -> bool: ... + def __le__(self: _T, other: _T) -> bool: ... + def __lt__(self: _T, other: _T) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + @property + def compressed(self) -> str: ... + @property + def exploded(self) -> str: ... + if sys.version_info >= (3, 5): + @property + def reverse_pointer(self) -> str: ... + @property + def version(self) -> int: ... + +class _BaseAddress(_IPAddressBase, SupportsInt): + def __init__(self, address: object) -> None: ... + def __add__(self: _T, other: int) -> _T: ... + def __hash__(self) -> int: ... + def __int__(self) -> int: ... + def __sub__(self: _T, other: int) -> _T: ... + if sys.version_info >= (3, 4): + @property + def is_global(self) -> bool: ... + @property + def is_link_local(self) -> bool: ... + @property + def is_loopback(self) -> bool: ... + @property + def is_multicast(self) -> bool: ... + @property + def is_private(self) -> bool: ... + @property + def is_reserved(self) -> bool: ... + @property + def is_unspecified(self) -> bool: ... + @property + def max_prefixlen(self) -> int: ... + @property + def packed(self) -> bytes: ... + +class _BaseNetwork(_IPAddressBase, Container, Iterable[_A], Generic[_A]): + network_address: _A + netmask: _A + def __init__(self, address: object, strict: bool = ...) -> None: ... + def __contains__(self, other: Any) -> bool: ... + def __getitem__(self, n: int) -> _A: ... + def __iter__(self) -> Iterator[_A]: ... + def address_exclude(self: _T, other: _T) -> Iterator[_T]: ... + @property + def broadcast_address(self) -> _A: ... + def compare_networks(self: _T, other: _T) -> int: ... + def hosts(self) -> Iterator[_A]: ... + @property + def is_global(self) -> bool: ... + @property + def is_link_local(self) -> bool: ... + @property + def is_loopback(self) -> bool: ... + @property + def is_multicast(self) -> bool: ... + @property + def is_private(self) -> bool: ... + @property + def is_reserved(self) -> bool: ... + @property + def is_unspecified(self) -> bool: ... + @property + def max_prefixlen(self) -> int: ... + @property + def num_addresses(self) -> int: ... + def overlaps(self: _T, other: _T) -> bool: ... + @property + def prefixlen(self) -> int: ... + def subnets(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> Iterator[_T]: ... + def supernet(self: _T, prefixlen_diff: int = ..., new_prefix: Optional[int] = ...) -> _T: ... + @property + def with_hostmask(self) -> str: ... + @property + def with_netmask(self) -> str: ... + @property + def with_prefixlen(self) -> str: ... + +class _BaseInterface(_BaseAddress, Generic[_A, _N]): + hostmask: _A + netmask: _A + network: _N + @property + def ip(self) -> _A: ... + @property + def with_hostmask(self) -> str: ... + @property + def with_netmask(self) -> str: ... + @property + def with_prefixlen(self) -> str: ... + +class IPv4Address(_BaseAddress): ... +class IPv4Network(_BaseNetwork[IPv4Address]): ... +class IPv4Interface(IPv4Address, _BaseInterface[IPv4Address, IPv4Network]): ... + +class IPv6Address(_BaseAddress): + @property + def ipv4_mapped(self) -> Optional[IPv4Address]: ... + @property + def is_site_local(self) -> bool: ... + @property + def sixtofour(self) -> Optional[IPv4Address]: ... + @property + def teredo(self) -> Optional[Tuple[IPv4Address, IPv4Address]]: ... + +class IPv6Network(_BaseNetwork[IPv6Address]): + @property + def is_site_local(self) -> bool: ... + +class IPv6Interface(IPv6Address, _BaseInterface[IPv6Address, IPv6Network]): ... + +def v4_int_to_packed(address: int) -> bytes: ... +def v6_int_to_packed(address: int) -> bytes: ... +@overload +def summarize_address_range(first: IPv4Address, last: IPv4Address) -> Iterator[IPv4Network]: ... +@overload +def summarize_address_range(first: IPv6Address, last: IPv6Address) -> Iterator[IPv6Network]: ... +def collapse_addresses(addresses: Iterable[_N]) -> Iterator[_N]: ... +@overload +def get_mixed_type_key(obj: _A) -> Tuple[int, _A]: ... +@overload +def get_mixed_type_key(obj: IPv4Network) -> Tuple[int, IPv4Address, IPv4Address]: ... +@overload +def get_mixed_type_key(obj: IPv6Network) -> Tuple[int, IPv6Address, IPv6Address]: ... + +class AddressValueError(ValueError): ... +class NetmaskValueError(ValueError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.3/lzma.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.3/lzma.pyi new file mode 100644 index 000000000..cd0a088b4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.3/lzma.pyi @@ -0,0 +1,107 @@ +import io +import sys +from typing import Any, IO, Mapping, Optional, Sequence, Union + +if sys.version_info >= (3, 6): + from os import PathLike + _PathOrFile = Union[str, bytes, IO[Any], PathLike[Any]] +else: + _PathOrFile = Union[str, bytes, IO[Any]] + +_FilterChain = Sequence[Mapping[str, Any]] + +FORMAT_AUTO: int +FORMAT_XZ: int +FORMAT_ALONE: int +FORMAT_RAW: int +CHECK_NONE: int +CHECK_CRC32: int +CHECK_CRC64: int +CHECK_SHA256: int +CHECK_ID_MAX: int +CHECK_UNKNOWN: int +FILTER_LZMA1: int +FILTER_LZMA2: int +FILTER_DELTA: int +FILTER_X86: int +FILTER_IA64: int +FILTER_ARM: int +FILTER_ARMTHUMB: int +FILTER_SPARC: int +FILTER_POWERPC: int +MF_HC3: int +MF_HC4: int +MF_BT2: int +MF_BT3: int +MF_BT4: int +MODE_FAST: int +MODE_NORMAL: int +PRESET_DEFAULT: int +PRESET_EXTREME: int + +# from _lzma.c +class LZMADecompressor(object): + def __init__(self, format: Optional[int] = ..., memlimit: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> None: ... + def decompress(self, data: bytes, max_length: int = ...) -> bytes: ... + @property + def check(self) -> int: ... + @property + def eof(self) -> bool: ... + @property + def unused_data(self) -> bytes: ... + if sys.version_info >= (3, 5): + @property + def needs_input(self) -> bool: ... + +# from _lzma.c +class LZMACompressor(object): + def __init__(self, + format: Optional[int] = ..., + check: int = ..., + preset: Optional[int] = ..., + filters: Optional[_FilterChain] = ...) -> None: ... + def compress(self, data: bytes) -> bytes: ... + def flush(self) -> bytes: ... + + +class LZMAError(Exception): ... + + +class LZMAFile(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#5027 + def __init__(self, + filename: Optional[_PathOrFile] = ..., + mode: str = ..., + *, + format: Optional[int] = ..., + check: int = ..., + preset: Optional[int] = ..., + filters: Optional[_FilterChain] = ...) -> None: ... + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + def fileno(self) -> int: ... + def seekable(self) -> bool: ... + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def peek(self, size: int = ...) -> bytes: ... + def read(self, size: Optional[int] = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + def readline(self, size: int = ...) -> bytes: ... + def write(self, data: bytes) -> int: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + + +def open(filename: _PathOrFile, + mode: str = ..., + *, + format: Optional[int] = ..., + check: int = ..., + preset: Optional[int] = ..., + filters: Optional[_FilterChain] = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + newline: Optional[str] = ...) -> IO[Any]: ... +def compress(data: bytes, format: int = ..., check: int = ..., preset: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... +def decompress(data: bytes, format: int = ..., memlimit: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... +def is_check_supported(check: int) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/_stat.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/_stat.pyi new file mode 100644 index 000000000..867321a49 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/_stat.pyi @@ -0,0 +1,69 @@ +"""Stub file for the '_stat' module.""" + +SF_APPEND = ... # type: int +SF_ARCHIVED = ... # type: int +SF_IMMUTABLE = ... # type: int +SF_NOUNLINK = ... # type: int +SF_SNAPSHOT = ... # type: int +ST_ATIME = ... # type: int +ST_CTIME = ... # type: int +ST_DEV = ... # type: int +ST_GID = ... # type: int +ST_INO = ... # type: int +ST_MODE = ... # type: int +ST_MTIME = ... # type: int +ST_NLINK = ... # type: int +ST_SIZE = ... # type: int +ST_UID = ... # type: int +S_ENFMT = ... # type: int +S_IEXEC = ... # type: int +S_IFBLK = ... # type: int +S_IFCHR = ... # type: int +S_IFDIR = ... # type: int +S_IFDOOR = ... # type: int +S_IFIFO = ... # type: int +S_IFLNK = ... # type: int +S_IFPORT = ... # type: int +S_IFREG = ... # type: int +S_IFSOCK = ... # type: int +S_IFWHT = ... # type: int +S_IREAD = ... # type: int +S_IRGRP = ... # type: int +S_IROTH = ... # type: int +S_IRUSR = ... # type: int +S_IRWXG = ... # type: int +S_IRWXO = ... # type: int +S_IRWXU = ... # type: int +S_ISGID = ... # type: int +S_ISUID = ... # type: int +S_ISVTX = ... # type: int +S_IWGRP = ... # type: int +S_IWOTH = ... # type: int +S_IWRITE = ... # type: int +S_IWUSR = ... # type: int +S_IXGRP = ... # type: int +S_IXOTH = ... # type: int +S_IXUSR = ... # type: int +UF_APPEND = ... # type: int +UF_COMPRESSED = ... # type: int +UF_HIDDEN = ... # type: int +UF_IMMUTABLE = ... # type: int +UF_NODUMP = ... # type: int +UF_NOUNLINK = ... # type: int +UF_OPAQUE = ... # type: int + +def S_IMODE(mode: int) -> int: ... +def S_IFMT(mode: int) -> int: ... + +def S_ISBLK(mode: int) -> bool: ... +def S_ISCHR(mode: int) -> bool: ... +def S_ISDIR(mode: int) -> bool: ... +def S_ISDOOR(mode: int) -> bool: ... +def S_ISFIFO(mode: int) -> bool: ... +def S_ISLNK(mode: int) -> bool: ... +def S_ISPORT(mode: int) -> bool: ... +def S_ISREG(mode: int) -> bool: ... +def S_ISSOCK(mode: int) -> bool: ... +def S_ISWHT(mode: int) -> bool: ... + +def filemode(mode: int) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/_tracemalloc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/_tracemalloc.pyi new file mode 100644 index 000000000..21d00332a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/_tracemalloc.pyi @@ -0,0 +1,26 @@ +"""Stub file for the '_tracemalloc' module.""" +# This is an autogenerated file. It serves as a starting point +# for a more precise manual annotation of this module. +# Feel free to edit the source below, but remove this header when you do. + +from typing import Any + +def _get_object_traceback(*args, **kwargs) -> Any: ... + +def _get_traces() -> Any: + raise MemoryError() + +def clear_traces() -> None: ... + +def get_traceback_limit() -> int: ... + +def get_traced_memory() -> tuple: ... + +def get_tracemalloc_memory() -> Any: ... + +def is_tracing() -> bool: ... + +def start(*args, **kwargs) -> None: + raise ValueError() + +def stop() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/__init__.pyi new file mode 100644 index 000000000..ebd0bb289 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/__init__.pyi @@ -0,0 +1,111 @@ +import sys +from typing import List, Type + +from asyncio.coroutines import ( + coroutine as coroutine, + iscoroutinefunction as iscoroutinefunction, + iscoroutine as iscoroutine, +) +from asyncio.protocols import ( + BaseProtocol as BaseProtocol, + Protocol as Protocol, + DatagramProtocol as DatagramProtocol, + SubprocessProtocol as SubprocessProtocol, +) +from asyncio.streams import ( + StreamReader as StreamReader, + StreamWriter as StreamWriter, + StreamReaderProtocol as StreamReaderProtocol, + open_connection as open_connection, + start_server as start_server, + IncompleteReadError as IncompleteReadError, + LimitOverrunError as LimitOverrunError, +) +from asyncio.subprocess import ( + create_subprocess_exec as create_subprocess_exec, + create_subprocess_shell as create_subprocess_shell, +) +from asyncio.transports import ( + BaseTransport as BaseTransport, + ReadTransport as ReadTransport, + WriteTransport as WriteTransport, + Transport as Transport, + DatagramTransport as DatagramTransport, + SubprocessTransport as SubprocessTransport, +) +from asyncio.futures import ( + Future as Future, + CancelledError as CancelledError, + TimeoutError as TimeoutError, + InvalidStateError as InvalidStateError, + wrap_future as wrap_future, +) +from asyncio.tasks import ( + FIRST_COMPLETED as FIRST_COMPLETED, + FIRST_EXCEPTION as FIRST_EXCEPTION, + ALL_COMPLETED as ALL_COMPLETED, + as_completed as as_completed, + ensure_future as ensure_future, + async as async, + gather as gather, + run_coroutine_threadsafe as run_coroutine_threadsafe, + shield as shield, + sleep as sleep, + wait as wait, + wait_for as wait_for, + Task as Task, +) +from asyncio.events import ( + AbstractEventLoopPolicy as AbstractEventLoopPolicy, + AbstractEventLoop as AbstractEventLoop, + AbstractServer as AbstractServer, + Handle as Handle, + TimerHandle as TimerHandle, + get_event_loop_policy as get_event_loop_policy, + set_event_loop_policy as set_event_loop_policy, + get_event_loop as get_event_loop, + set_event_loop as set_event_loop, + new_event_loop as new_event_loop, + get_child_watcher as get_child_watcher, + set_child_watcher as set_child_watcher, +) +from asyncio.queues import ( + Queue as Queue, + PriorityQueue as PriorityQueue, + LifoQueue as LifoQueue, + QueueFull as QueueFull, + QueueEmpty as QueueEmpty, +) +from asyncio.locks import ( + Lock as Lock, + Event as Event, + Condition as Condition, + Semaphore as Semaphore, + BoundedSemaphore as BoundedSemaphore, +) + +if sys.version_info < (3, 5): + from asyncio.queues import JoinableQueue as JoinableQueue +else: + from asyncio.futures import isfuture as isfuture + from asyncio.events import ( + _set_running_loop as _set_running_loop, + _get_running_loop as _get_running_loop, + ) +if sys.platform != 'win32': + from asyncio.streams import ( + open_unix_connection as open_unix_connection, + start_unix_server as start_unix_server, + ) + +# TODO: It should be possible to instantiate these classes, but mypy +# currently disallows this. +# See https://github.com/python/mypy/issues/1843 +SelectorEventLoop = ... # type: Type[AbstractEventLoop] +if sys.platform == 'win32': + ProactorEventLoop = ... # type: Type[AbstractEventLoop] +DefaultEventLoopPolicy = ... # type: Type[AbstractEventLoopPolicy] + +# TODO: AbstractChildWatcher (UNIX only) + +__all__: List[str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/coroutines.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/coroutines.pyi new file mode 100644 index 000000000..981ccd5a0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/coroutines.pyi @@ -0,0 +1,9 @@ +from typing import Any, Callable, Generator, List, TypeVar + +__all__: List[str] + +_F = TypeVar('_F', bound=Callable[..., Any]) + +def coroutine(func: _F) -> _F: ... +def iscoroutinefunction(func: Callable[..., Any]) -> bool: ... +def iscoroutine(obj: Any) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/events.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/events.pyi new file mode 100644 index 000000000..b03d81432 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/events.pyi @@ -0,0 +1,224 @@ +import selectors +from socket import socket +import ssl +import sys +from typing import Any, Awaitable, Callable, Dict, Generator, List, Optional, Sequence, Tuple, TypeVar, Union, overload +from abc import ABCMeta, abstractmethod +from asyncio.futures import Future +from asyncio.coroutines import coroutine +from asyncio.protocols import BaseProtocol +from asyncio.tasks import Task +from asyncio.transports import BaseTransport + +__all__: List[str] + +_T = TypeVar('_T') +_Context = Dict[str, Any] +_ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] +_ProtocolFactory = Callable[[], BaseProtocol] +_SSLContext = Union[bool, None, ssl.SSLContext] +_TransProtPair = Tuple[BaseTransport, BaseProtocol] + +class Handle: + _cancelled = False + _args = ... # type: List[Any] + def __init__(self, callback: Callable[..., Any], args: List[Any], + loop: AbstractEventLoop) -> None: ... + def __repr__(self) -> str: ... + def cancel(self) -> None: ... + def _run(self) -> None: ... + +class TimerHandle(Handle): + def __init__(self, when: float, callback: Callable[..., Any], args: List[Any], + loop: AbstractEventLoop) -> None: ... + def __hash__(self) -> int: ... + +class AbstractServer: + def close(self) -> None: ... + @coroutine + def wait_closed(self) -> Generator[Any, None, None]: ... + +class AbstractEventLoop(metaclass=ABCMeta): + @abstractmethod + def run_forever(self) -> None: ... + + # Can't use a union, see mypy issue # 1873. + @overload + @abstractmethod + def run_until_complete(self, future: Generator[Any, None, _T]) -> _T: ... + @overload + @abstractmethod + def run_until_complete(self, future: Awaitable[_T]) -> _T: ... + + @abstractmethod + def stop(self) -> None: ... + @abstractmethod + def is_running(self) -> bool: ... + @abstractmethod + def is_closed(self) -> bool: ... + @abstractmethod + def close(self) -> None: ... + if sys.version_info >= (3, 6): + @abstractmethod + @coroutine + def shutdown_asyncgens(self) -> Generator[Any, None, None]: ... + # Methods scheduling callbacks. All these return Handles. + @abstractmethod + def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ... + @abstractmethod + def call_later(self, delay: Union[int, float], callback: Callable[..., Any], *args: Any) -> Handle: ... + @abstractmethod + def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> Handle: ... + @abstractmethod + def time(self) -> float: ... + # Future methods + if sys.version_info >= (3, 5): + @abstractmethod + def create_future(self) -> Future[Any]: ... + # Tasks methods + @abstractmethod + def create_task(self, coro: Union[Awaitable[_T], Generator[Any, None, _T]]) -> Task[_T]: ... + @abstractmethod + def set_task_factory(self, factory: Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]) -> None: ... + @abstractmethod + def get_task_factory(self) -> Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]: ... + # Methods for interacting with threads + @abstractmethod + def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ... + @abstractmethod + @coroutine + def run_in_executor(self, executor: Any, + func: Callable[..., _T], *args: Any) -> Generator[Any, None, _T]: ... + @abstractmethod + def set_default_executor(self, executor: Any) -> None: ... + # Network I/O methods returning Futures. + @abstractmethod + @coroutine + # TODO the "Tuple[Any, ...]" should be "Union[Tuple[str, int], Tuple[str, int, int, int]]" but that triggers + # https://github.com/python/mypy/issues/2509 + def getaddrinfo(self, host: Optional[str], port: Union[str, int, None], *, + family: int = ..., type: int = ..., proto: int = ..., flags: int = ...) -> Generator[Any, None, List[Tuple[int, int, int, str, Tuple[Any, ...]]]]: ... + @abstractmethod + @coroutine + def getnameinfo(self, sockaddr: tuple, flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... + @abstractmethod + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: Optional[socket] = ..., + local_addr: str = ..., server_hostname: str = ...) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def create_server(self, protocol_factory: _ProtocolFactory, host: Union[str, Sequence[str]] = ..., port: int = ..., *, + family: int = ..., flags: int = ..., + sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ..., + reuse_address: Optional[bool] = ..., + reuse_port: Optional[bool] = ...) -> Generator[Any, None, AbstractServer]: ... + @abstractmethod + @coroutine + def create_unix_connection(self, protocol_factory: _ProtocolFactory, path: str, *, + ssl: _SSLContext = ..., sock: Optional[socket] = ..., + server_hostname: str = ...) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def create_unix_server(self, protocol_factory: _ProtocolFactory, path: str, *, + sock: Optional[socket] = ..., backlog: int = ..., ssl: _SSLContext = ...) -> Generator[Any, None, AbstractServer]: ... + @abstractmethod + @coroutine + def create_datagram_endpoint(self, protocol_factory: _ProtocolFactory, + local_addr: Optional[Tuple[str, int]] = ..., remote_addr: Optional[Tuple[str, int]] = ..., *, + family: int = ..., proto: int = ..., flags: int = ..., + reuse_address: Optional[bool] = ..., reuse_port: Optional[bool] = ..., + allow_broadcast: Optional[bool] = ..., + sock: Optional[socket] = ...) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def connect_accepted_socket(self, protocol_factory: _ProtocolFactory, sock: socket, *, ssl: _SSLContext = ...) -> Generator[Any, None, _TransProtPair]: ... + # Pipes and subprocesses. + @abstractmethod + @coroutine + def connect_read_pipe(self, protocol_factory: _ProtocolFactory, pipe: Any) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def connect_write_pipe(self, protocol_factory: _ProtocolFactory, pipe: Any) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def subprocess_shell(self, protocol_factory: _ProtocolFactory, cmd: Union[bytes, str], *, stdin: Any = ..., + stdout: Any = ..., stderr: Any = ..., + **kwargs: Any) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + @coroutine + def subprocess_exec(self, protocol_factory: _ProtocolFactory, *args: Any, stdin: Any = ..., + stdout: Any = ..., stderr: Any = ..., + **kwargs: Any) -> Generator[Any, None, _TransProtPair]: ... + @abstractmethod + def add_reader(self, fd: selectors._FileObject, callback: Callable[..., Any], *args: Any) -> None: ... + @abstractmethod + def remove_reader(self, fd: selectors._FileObject) -> None: ... + @abstractmethod + def add_writer(self, fd: selectors._FileObject, callback: Callable[..., Any], *args: Any) -> None: ... + @abstractmethod + def remove_writer(self, fd: selectors._FileObject) -> None: ... + # Completion based I/O methods returning Futures. + @abstractmethod + @coroutine + def sock_recv(self, sock: socket, nbytes: int) -> Generator[Any, None, bytes]: ... + @abstractmethod + @coroutine + def sock_sendall(self, sock: socket, data: bytes) -> Generator[Any, None, None]: ... + @abstractmethod + @coroutine + def sock_connect(self, sock: socket, address: str) -> Generator[Any, None, None]: ... + @abstractmethod + @coroutine + def sock_accept(self, sock: socket) -> Generator[Any, None, Tuple[socket, Any]]: ... + # Signal handling. + @abstractmethod + def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... + @abstractmethod + def remove_signal_handler(self, sig: int) -> None: ... + # Error handlers. + @abstractmethod + def set_exception_handler(self, handler: _ExceptionHandler) -> None: ... + @abstractmethod + def get_exception_handler(self) -> _ExceptionHandler: ... + @abstractmethod + def default_exception_handler(self, context: _Context) -> None: ... + @abstractmethod + def call_exception_handler(self, context: _Context) -> None: ... + # Debug flag management. + @abstractmethod + def get_debug(self) -> bool: ... + @abstractmethod + def set_debug(self, enabled: bool) -> None: ... + +class AbstractEventLoopPolicy(metaclass=ABCMeta): + @abstractmethod + def get_event_loop(self) -> AbstractEventLoop: ... + @abstractmethod + def set_event_loop(self, loop: AbstractEventLoop) -> None: ... + @abstractmethod + def new_event_loop(self) -> AbstractEventLoop: ... + # Child processes handling (Unix only). + @abstractmethod + def get_child_watcher(self) -> Any: ... # TODO: unix_events.AbstractChildWatcher + @abstractmethod + def set_child_watcher(self, watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher + +class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta): + def __init__(self) -> None: ... + def get_event_loop(self) -> AbstractEventLoop: ... + def set_event_loop(self, loop: AbstractEventLoop) -> None: ... + def new_event_loop(self) -> AbstractEventLoop: ... + +def get_event_loop_policy() -> AbstractEventLoopPolicy: ... +def set_event_loop_policy(policy: AbstractEventLoopPolicy) -> None: ... + +def get_event_loop() -> AbstractEventLoop: ... +def set_event_loop(loop: AbstractEventLoop) -> None: ... +def new_event_loop() -> AbstractEventLoop: ... + +def get_child_watcher() -> Any: ... # TODO: unix_events.AbstractChildWatcher +def set_child_watcher(watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher + +def _set_running_loop(loop: AbstractEventLoop) -> None: ... +def _get_running_loop() -> AbstractEventLoop: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/futures.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/futures.pyi new file mode 100644 index 000000000..034a9c908 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/futures.pyi @@ -0,0 +1,52 @@ +import sys +from typing import Any, Union, Callable, TypeVar, Type, List, Generic, Iterable, Generator, Awaitable +from .events import AbstractEventLoop +from concurrent.futures import ( + CancelledError as CancelledError, + TimeoutError as TimeoutError, + Future as _ConcurrentFuture, + Error, +) + +__all__: List[str] + +_T = TypeVar('_T') +_S = TypeVar('_S', bound=Future) + +class InvalidStateError(Error): ... + +class _TracebackLogger: + exc = ... # type: BaseException + tb = ... # type: List[str] + def __init__(self, exc: Any, loop: AbstractEventLoop) -> None: ... + def activate(self) -> None: ... + def clear(self) -> None: ... + def __del__(self) -> None: ... + +if sys.version_info >= (3, 5): + def isfuture(obj: object) -> bool: ... + +class Future(Awaitable[_T], Iterable[_T]): + _state = ... # type: str + _exception = ... # type: BaseException + _blocking = False + _log_traceback = False + _tb_logger = ... # type: Type[_TracebackLogger] + def __init__(self, *, loop: AbstractEventLoop = ...) -> None: ... + def __repr__(self) -> str: ... + def __del__(self) -> None: ... + def cancel(self) -> bool: ... + def _schedule_callbacks(self) -> None: ... + def cancelled(self) -> bool: ... + def done(self) -> bool: ... + def result(self) -> _T: ... + def exception(self) -> BaseException: ... + def add_done_callback(self: _S, fn: Callable[[_S], Any]) -> None: ... + def remove_done_callback(self: _S, fn: Callable[[_S], Any]) -> int: ... + def set_result(self, result: _T) -> None: ... + def set_exception(self, exception: Union[type, BaseException]) -> None: ... + def _copy_state(self, other: Any) -> None: ... + def __iter__(self) -> Generator[Any, None, _T]: ... + def __await__(self) -> Generator[Any, None, _T]: ... + +def wrap_future(f: Union[_ConcurrentFuture[_T], Future[_T]]) -> Future[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/locks.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/locks.pyi new file mode 100644 index 000000000..56b8a6727 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/locks.pyi @@ -0,0 +1,60 @@ +from typing import Any, Callable, Generator, Iterable, Iterator, List, Type, TypeVar, Union, Optional, Awaitable + +from .coroutines import coroutine +from .events import AbstractEventLoop +from .futures import Future +from types import TracebackType + +_T = TypeVar('_T') + +__all__: List[str] + +class _ContextManager: + def __init__(self, lock: Union[Lock, Semaphore]) -> None: ... + def __enter__(self) -> object: ... + def __exit__(self, *args: Any) -> None: ... + +class _ContextManagerMixin(Future[_ContextManager]): + # Apparently this exists to *prohibit* use as a context manager. + def __enter__(self) -> object: ... + def __exit__(self, *args: Any) -> None: ... + def __aenter__(self) -> Awaitable[None]: ... + def __aexit__(self, exc_type: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[TracebackType]) -> Awaitable[None]: ... + +class Lock(_ContextManagerMixin): + def __init__(self, *, loop: Optional[AbstractEventLoop] = ...) -> None: ... + def locked(self) -> bool: ... + @coroutine + def acquire(self) -> Generator[Any, None, bool]: ... + def release(self) -> None: ... + +class Event: + def __init__(self, *, loop: Optional[AbstractEventLoop] = ...) -> None: ... + def is_set(self) -> bool: ... + def set(self) -> None: ... + def clear(self) -> None: ... + @coroutine + def wait(self) -> Generator[Any, None, bool]: ... + +class Condition(_ContextManagerMixin): + def __init__(self, lock: Optional[Lock] = ..., *, loop: Optional[AbstractEventLoop] = ...) -> None: ... + def locked(self) -> bool: ... + @coroutine + def acquire(self) -> Generator[Any, None, bool]: ... + def release(self) -> None: ... + @coroutine + def wait(self) -> Generator[Any, None, bool]: ... + @coroutine + def wait_for(self, predicate: Callable[[], _T]) -> Generator[Any, None, _T]: ... + def notify(self, n: int = ...) -> None: ... + def notify_all(self) -> None: ... + +class Semaphore(_ContextManagerMixin): + def __init__(self, value: int = ..., *, loop: Optional[AbstractEventLoop] = ...) -> None: ... + def locked(self) -> bool: ... + @coroutine + def acquire(self) -> Generator[Any, None, bool]: ... + def release(self) -> None: ... + +class BoundedSemaphore(Semaphore): + def __init__(self, value: int = ..., *, loop: Optional[AbstractEventLoop] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/protocols.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/protocols.pyi new file mode 100644 index 000000000..a716af7ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/protocols.pyi @@ -0,0 +1,24 @@ +from asyncio import transports +from typing import List, Text, Tuple, Union + +__all__: List[str] + + +class BaseProtocol: + def connection_made(self, transport: transports.BaseTransport) -> None: ... + def connection_lost(self, exc: Exception) -> None: ... + def pause_writing(self) -> None: ... + def resume_writing(self) -> None: ... + +class Protocol(BaseProtocol): + def data_received(self, data: bytes) -> None: ... + def eof_received(self) -> bool: ... + +class DatagramProtocol(BaseProtocol): + def datagram_received(self, data: Union[bytes, Text], addr: Tuple[str, int]) -> None: ... + def error_received(self, exc: Exception) -> None: ... + +class SubprocessProtocol(BaseProtocol): + def pipe_data_received(self, fd: int, data: Union[bytes, Text]) -> None: ... + def pipe_connection_lost(self, fd: int, exc: Exception) -> None: ... + def process_exited(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/queues.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/queues.pyi new file mode 100644 index 000000000..38baf669b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/queues.pyi @@ -0,0 +1,51 @@ +import sys +from asyncio.events import AbstractEventLoop +from .coroutines import coroutine +from .futures import Future +from typing import Any, Generator, Generic, List, TypeVar + +__all__: List[str] + + +class QueueEmpty(Exception): ... +class QueueFull(Exception): ... + +_T = TypeVar('_T') + +class Queue(Generic[_T]): + def __init__(self, maxsize: int = ..., *, loop: AbstractEventLoop = ...) -> None: ... + def _init(self, maxsize: int) -> None: ... + def _get(self) -> _T: ... + def _put(self, item: _T) -> None: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def _format(self) -> str: ... + def _consume_done_getters(self) -> None: ... + def _consume_done_putters(self) -> None: ... + def qsize(self) -> int: ... + @property + def maxsize(self) -> int: ... + def empty(self) -> bool: ... + def full(self) -> bool: ... + @coroutine + def put(self, item: _T) -> Generator[Any, None, None]: ... + def put_nowait(self, item: _T) -> None: ... + @coroutine + def get(self) -> Generator[Any, None, _T]: ... + def get_nowait(self) -> _T: ... + if sys.version_info >= (3, 4): + @coroutine + def join(self) -> Generator[Any, None, bool]: ... + def task_done(self) -> None: ... + + +class PriorityQueue(Queue[_T]): ... + + +class LifoQueue(Queue[_T]): ... + +if sys.version_info < (3, 5): + class JoinableQueue(Queue[_T]): + def task_done(self) -> None: ... + @coroutine + def join(self) -> Generator[Any, None, bool]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/streams.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/streams.pyi new file mode 100644 index 000000000..2892d95ab --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/streams.pyi @@ -0,0 +1,109 @@ +import sys +from typing import Any, Awaitable, Callable, Generator, Iterable, List, Optional, Tuple, Union + +from . import coroutines +from . import events +from . import protocols +from . import transports + +_ClientConnectedCallback = Callable[[StreamReader, StreamWriter], Optional[Awaitable[None]]] + + +__all__: List[str] + +class IncompleteReadError(EOFError): + expected = ... # type: Optional[int] + partial = ... # type: bytes + def __init__(self, partial: bytes, expected: Optional[int]) -> None: ... + +class LimitOverrunError(Exception): + consumed = ... # type: int + def __init__(self, message: str, consumed: int) -> None: ... + +@coroutines.coroutine +def open_connection( + host: str = ..., + port: Union[int, str] = ..., + *, + loop: Optional[events.AbstractEventLoop] = ..., + limit: int = ..., + **kwds: Any +) -> Generator[Any, None, Tuple[StreamReader, StreamWriter]]: ... + +@coroutines.coroutine +def start_server( + client_connected_cb: _ClientConnectedCallback, + host: Optional[str] = ..., + port: Optional[Union[int, str]] = ..., + *, + loop: Optional[events.AbstractEventLoop] = ..., + limit: int = ..., + **kwds: Any +) -> Generator[Any, None, events.AbstractServer]: ... + +if sys.platform != 'win32': + @coroutines.coroutine + def open_unix_connection( + path: str = ..., + *, + loop: Optional[events.AbstractEventLoop] = ..., + limit: int = ..., + **kwds: Any + ) -> Generator[Any, None, Tuple[StreamReader, StreamWriter]]: ... + + @coroutines.coroutine + def start_unix_server( + client_connected_cb: _ClientConnectedCallback, + path: str = ..., + *, + loop: Optional[events.AbstractEventLoop] = ..., + limit: int = ..., + **kwds: Any) -> Generator[Any, None, events.AbstractServer]: ... + +class FlowControlMixin(protocols.Protocol): ... + +class StreamReaderProtocol(FlowControlMixin, protocols.Protocol): + def __init__(self, + stream_reader: StreamReader, + client_connected_cb: _ClientConnectedCallback = ..., + loop: Optional[events.AbstractEventLoop] = ...) -> None: ... + def connection_made(self, transport: transports.BaseTransport) -> None: ... + def connection_lost(self, exc: Exception) -> None: ... + def data_received(self, data: bytes) -> None: ... + def eof_received(self) -> bool: ... + +class StreamWriter: + def __init__(self, + transport: transports.BaseTransport, + protocol: protocols.BaseProtocol, + reader: StreamReader, + loop: events.AbstractEventLoop) -> None: ... + @property + def transport(self) -> transports.BaseTransport: ... + def write(self, data: bytes) -> None: ... + def writelines(self, data: Iterable[bytes]) -> None: ... + def write_eof(self) -> None: ... + def can_write_eof(self) -> bool: ... + def close(self) -> None: ... + def get_extra_info(self, name: str, default: Any = ...) -> Any: ... + @coroutines.coroutine + def drain(self) -> Generator[Any, None, None]: ... + +class StreamReader: + def __init__(self, + limit: int = ..., + loop: Optional[events.AbstractEventLoop] = ...) -> None: ... + def exception(self) -> Exception: ... + def set_exception(self, exc: Exception) -> None: ... + def set_transport(self, transport: transports.BaseTransport) -> None: ... + def feed_eof(self) -> None: ... + def at_eof(self) -> bool: ... + def feed_data(self, data: bytes) -> None: ... + @coroutines.coroutine + def readline(self) -> Generator[Any, None, bytes]: ... + @coroutines.coroutine + def readuntil(self, separator: bytes = ...) -> Generator[Any, None, bytes]: ... + @coroutines.coroutine + def read(self, n: int = ...) -> Generator[Any, None, bytes]: ... + @coroutines.coroutine + def readexactly(self, n: int) -> Generator[Any, None, bytes]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/subprocess.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/subprocess.pyi new file mode 100644 index 000000000..ab2ecd8d8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/subprocess.pyi @@ -0,0 +1,67 @@ +from asyncio import events +from asyncio import protocols +from asyncio import streams +from asyncio import transports +from asyncio.coroutines import coroutine +from typing import Any, Generator, List, Optional, Text, Tuple, Union, IO + +__all__: List[str] + +PIPE = ... # type: int +STDOUT = ... # type: int +DEVNULL = ... # type: int + +class SubprocessStreamProtocol(streams.FlowControlMixin, + protocols.SubprocessProtocol): + stdin = ... # type: Optional[streams.StreamWriter] + stdout = ... # type: Optional[streams.StreamReader] + stderr = ... # type: Optional[streams.StreamReader] + def __init__(self, limit: int, loop: events.AbstractEventLoop) -> None: ... + def connection_made(self, transport: transports.BaseTransport) -> None: ... + def pipe_data_received(self, fd: int, data: Union[bytes, Text]) -> None: ... + def pipe_connection_lost(self, fd: int, exc: Exception) -> None: ... + def process_exited(self) -> None: ... + + +class Process: + stdin = ... # type: Optional[streams.StreamWriter] + stdout = ... # type: Optional[streams.StreamReader] + stderr = ... # type: Optional[streams.StreamReader] + pid = ... # type: int + def __init__(self, + transport: transports.BaseTransport, + protocol: protocols.BaseProtocol, + loop: events.AbstractEventLoop) -> None: ... + @property + def returncode(self) -> int: ... + @coroutine + def wait(self) -> Generator[Any, None, int]: ... + def send_signal(self, signal: int) -> None: ... + def terminate(self) -> None: ... + def kill(self) -> None: ... + @coroutine + def communicate(self, input: Optional[bytes] = ...) -> Generator[Any, None, Tuple[bytes, bytes]]: ... + + +@coroutine +def create_subprocess_shell( + *Args: Union[str, bytes], # Union used instead of AnyStr due to mypy issue #1236 + stdin: Union[int, IO[Any], None] = ..., + stdout: Union[int, IO[Any], None] = ..., + stderr: Union[int, IO[Any], None] = ..., + loop: events.AbstractEventLoop = ..., + limit: int = ..., + **kwds: Any +) -> Generator[Any, None, Process]: ... + +@coroutine +def create_subprocess_exec( + program: Union[str, bytes], # Union used instead of AnyStr due to mypy issue #1236 + *args: Any, + stdin: Union[int, IO[Any], None] = ..., + stdout: Union[int, IO[Any], None] = ..., + stderr: Union[int, IO[Any], None] = ..., + loop: events.AbstractEventLoop = ..., + limit: int = ..., + **kwds: Any +) -> Generator[Any, None, Process]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/tasks.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/tasks.pyi new file mode 100644 index 000000000..12bba7e80 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/tasks.pyi @@ -0,0 +1,71 @@ +from typing import (Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, + Coroutine, Generator, Iterable, Awaitable, overload, Sequence, Iterator, + Optional) +from types import FrameType +import concurrent.futures +from .events import AbstractEventLoop +from .futures import Future + +__all__: List[str] + +_T = TypeVar('_T') +_T1 = TypeVar('_T1') +_T2 = TypeVar('_T2') +_T3 = TypeVar('_T3') +_T4 = TypeVar('_T4') +_T5 = TypeVar('_T5') +_FutureT = Union[Future[_T], Generator[Any, None, _T], Awaitable[_T]] + +FIRST_EXCEPTION: str +FIRST_COMPLETED: str +ALL_COMPLETED: str + +def as_completed(fs: Sequence[_FutureT[_T]], *, loop: AbstractEventLoop = ..., + timeout: Optional[float] = ...) -> Iterator[Generator[Any, None, _T]]: ... +def ensure_future(coro_or_future: _FutureT[_T], + *, loop: AbstractEventLoop = ...) -> Future[_T]: ... +async = ensure_future +@overload +def gather(coro_or_future1: _FutureT[_T1], + *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], + *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], + *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2, _T3]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], + coro_or_future4: _FutureT[_T4], + *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2, _T3, _T4]]: ... +@overload +def gather(coro_or_future1: _FutureT[_T1], coro_or_future2: _FutureT[_T2], coro_or_future3: _FutureT[_T3], + coro_or_future4: _FutureT[_T4], coro_or_future5: _FutureT[_T5], + *, loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... +@overload +def gather(coro_or_future1: _FutureT[Any], coro_or_future2: _FutureT[Any], coro_or_future3: _FutureT[Any], + coro_or_future4: _FutureT[Any], coro_or_future5: _FutureT[Any], coro_or_future6: _FutureT[Any], + *coros_or_futures: _FutureT[Any], + loop: AbstractEventLoop = ..., return_exceptions: bool = ...) -> Future[Tuple[Any, ...]]: ... +def run_coroutine_threadsafe(coro: _FutureT[_T], + loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ... +def shield(arg: _FutureT[_T], *, loop: AbstractEventLoop = ...) -> Future[_T]: ... +def sleep(delay: float, result: _T = ..., loop: AbstractEventLoop = ...) -> Future[_T]: ... +def wait(fs: Iterable[_FutureT[_T]], *, loop: AbstractEventLoop = ..., + timeout: Optional[float] = ..., + return_when: str = ...) -> Future[Tuple[Set[Future[_T]], Set[Future[_T]]]]: ... +def wait_for(fut: _FutureT[_T], timeout: Optional[float], + *, loop: AbstractEventLoop = ...) -> Future[_T]: ... + +class Task(Future[_T], Generic[_T]): + @classmethod + def current_task(cls, loop: AbstractEventLoop = ...) -> Task: ... + @classmethod + def all_tasks(cls, loop: AbstractEventLoop = ...) -> Set[Task]: ... + def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ... + def __repr__(self) -> str: ... + def get_stack(self, *, limit: int = ...) -> List[FrameType]: ... + def print_stack(self, *, limit: int = ..., file: TextIO = ...) -> None: ... + def cancel(self) -> bool: ... + def _step(self, value: Any = ..., exc: Exception = ...) -> None: ... + def _wakeup(self, future: Future[Any]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/transports.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/transports.pyi new file mode 100644 index 000000000..9ea6688d7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/asyncio/transports.pyi @@ -0,0 +1,38 @@ +from typing import Dict, Any, TypeVar, Mapping, List, Optional, Tuple + +__all__: List[str] + +class BaseTransport: + def __init__(self, extra: Mapping[Any, Any] = ...) -> None: ... + def get_extra_info(self, name: Any, default: Any = ...) -> Any: ... + def is_closing(self) -> bool: ... + def close(self) -> None: ... + +class ReadTransport(BaseTransport): + def pause_reading(self) -> None: ... + def resume_reading(self) -> None: ... + +class WriteTransport(BaseTransport): + def set_write_buffer_limits( + self, high: int = ..., low: int = ... + ) -> None: ... + def get_write_buffer_size(self) -> int: ... + def write(self, data: Any) -> None: ... + def writelines(self, list_of_data: List[Any]) -> None: ... + def write_eof(self) -> None: ... + def can_write_eof(self) -> bool: ... + def abort(self) -> None: ... + +class Transport(ReadTransport, WriteTransport): ... + +class DatagramTransport(BaseTransport): + def sendto(self, data: Any, addr: Optional[Tuple[str, int]] = ...) -> None: ... + def abort(self) -> None: ... + +class SubprocessTransport(BaseTransport): + def get_pid(self) -> int: ... + def get_returncode(self) -> int: ... + def get_pipe_transport(self, fd: int) -> BaseTransport: ... + def send_signal(self, signal: int) -> int: ... + def terminate(self) -> None: ... + def kill(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/enum.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/enum.pyi new file mode 100644 index 000000000..6ca467b27 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/enum.pyi @@ -0,0 +1,65 @@ +# NB: third_party/3/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! +import sys +from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union +from abc import ABCMeta + +_T = TypeVar('_T') +_S = TypeVar('_S', bound=Type[Enum]) + +# Note: EnumMeta actually subclasses type directly, not ABCMeta. +# This is a temporary workaround to allow multiple creation of enums with builtins +# such as str as mixins, which due to the handling of ABCs of builtin types, cause +# spurious inconsistent metaclass structure. See #1595. +# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself +class EnumMeta(ABCMeta): + def __iter__(self: Type[_T]) -> Iterator[_T]: ... + def __reversed__(self: Type[_T]) -> Iterator[_T]: ... + def __contains__(self: Type[_T], member: Any) -> bool: ... + def __getitem__(self: Type[_T], name: str) -> _T: ... + @property + def __members__(self: Type[_T]) -> Mapping[str, _T]: ... + def __len__(self) -> int: ... + +class Enum(metaclass=EnumMeta): + def __new__(cls: Type[_T], value: Any) -> _T: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __dir__(self) -> List[str]: ... + def __format__(self, format_spec: str) -> str: ... + def __hash__(self) -> Any: ... + def __reduce_ex__(self, proto: Any) -> Any: ... + + name = ... # type: str + value = ... # type: Any + +class IntEnum(int, Enum): + value = ... # type: int + +def unique(enumeration: _S) -> _S: ... + +if sys.version_info >= (3, 6): + _auto_null = ... # type: Any + + # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto() + class auto(IntFlag): + value = ... # type: Any + + class Flag(Enum): + def __contains__(self: _T, other: _T) -> bool: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __bool__(self) -> bool: ... + def __or__(self: _T, other: _T) -> _T: ... + def __and__(self: _T, other: _T) -> _T: ... + def __xor__(self: _T, other: _T) -> _T: ... + def __invert__(self: _T) -> _T: ... + + # The `type: ignore` comment is needed because mypy considers the type + # signatures of several methods defined in int and Flag to be incompatible. + class IntFlag(int, Flag): # type: ignore + def __or__(self: _T, other: Union[int, _T]) -> _T: ... + def __and__(self: _T, other: Union[int, _T]) -> _T: ... + def __xor__(self: _T, other: Union[int, _T]) -> _T: ... + __ror__ = __or__ + __rand__ = __and__ + __rxor__ = __xor__ diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/pathlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/pathlib.pyi new file mode 100644 index 000000000..307979b55 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/pathlib.pyi @@ -0,0 +1,122 @@ +# Stubs for pathlib (Python 3.4) + +from typing import Any, Generator, IO, Optional, Sequence, Tuple, Type, TypeVar, Union, List +from types import TracebackType +import os +import sys + +_P = TypeVar('_P', bound='PurePath') + +if sys.version_info >= (3, 6): + _PurePathBase = os.PathLike[str] +else: + _PurePathBase = object + +class PurePath(_PurePathBase): + parts = ... # type: Tuple[str, ...] + drive = ... # type: str + root = ... # type: str + anchor = ... # type: str + name = ... # type: str + suffix = ... # type: str + suffixes = ... # type: List[str] + stem = ... # type: str + if sys.version_info < (3, 5): + def __init__(self, *pathsegments: str) -> None: ... + elif sys.version_info < (3, 6): + def __new__(cls: Type[_P], *args: Union[str, PurePath]) -> _P: ... + else: + def __new__(cls: Type[_P], *args: Union[str, os.PathLike[str]]) -> _P: ... + def __hash__(self) -> int: ... + def __lt__(self, other: PurePath) -> bool: ... + def __le__(self, other: PurePath) -> bool: ... + def __gt__(self, other: PurePath) -> bool: ... + def __ge__(self, other: PurePath) -> bool: ... + def __truediv__(self: _P, key: Union[str, PurePath]) -> _P: ... + def __bytes__(self) -> bytes: ... + def as_posix(self) -> str: ... + def as_uri(self) -> str: ... + def is_absolute(self) -> bool: ... + def is_reserved(self) -> bool: ... + def match(self, path_pattern: str) -> bool: ... + def relative_to(self: _P, *other: Union[str, PurePath]) -> _P: ... + def with_name(self: _P, name: str) -> _P: ... + def with_suffix(self: _P, suffix: str) -> _P: ... + def joinpath(self: _P, *other: Union[str, PurePath]) -> _P: ... + + @property + def parents(self: _P) -> Sequence[_P]: ... + @property + def parent(self: _P) -> _P: ... + +class PurePosixPath(PurePath): ... +class PureWindowsPath(PurePath): ... + +class Path(PurePath): + def __enter__(self) -> Path: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType]) -> Optional[bool]: ... + @classmethod + def cwd(cls: Type[_P]) -> _P: ... + def stat(self) -> os.stat_result: ... + def chmod(self, mode: int) -> None: ... + def exists(self) -> bool: ... + def glob(self, pattern: str) -> Generator[Path, None, None]: ... + def group(self) -> str: ... + def is_dir(self) -> bool: ... + def is_file(self) -> bool: ... + def is_symlink(self) -> bool: ... + def is_socket(self) -> bool: ... + def is_fifo(self) -> bool: ... + def is_block_device(self) -> bool: ... + def is_char_device(self) -> bool: ... + def iterdir(self) -> Generator[Path, None, None]: ... + def lchmod(self, mode: int) -> None: ... + def lstat(self) -> os.stat_result: ... + if sys.version_info < (3, 5): + def mkdir(self, mode: int = ..., + parents: bool = ...) -> None: ... + else: + def mkdir(self, mode: int = ..., parents: bool = ..., + exist_ok: bool = ...) -> None: ... + def open(self, mode: str = ..., buffering: int = ..., + encoding: Optional[str] = ..., errors: Optional[str] = ..., + newline: Optional[str] = ...) -> IO[Any]: ... + def owner(self) -> str: ... + def rename(self, target: Union[str, PurePath]) -> None: ... + def replace(self, target: Union[str, PurePath]) -> None: ... + if sys.version_info < (3, 6): + def resolve(self: _P) -> _P: ... + else: + def resolve(self: _P, strict: bool = ...) -> _P: ... + def rglob(self, pattern: str) -> Generator[Path, None, None]: ... + def rmdir(self) -> None: ... + def symlink_to(self, target: Union[str, Path], + target_is_directory: bool = ...) -> None: ... + def touch(self, mode: int = ..., exist_ok: bool = ...) -> None: ... + def unlink(self) -> None: ... + + if sys.version_info >= (3, 5): + @classmethod + def home(cls: Type[_P]) -> _P: ... + if sys.version_info < (3, 6): + def __new__(cls: Type[_P], *args: Union[str, PurePath], + **kwargs: Any) -> _P: ... + else: + def __new__(cls: Type[_P], *args: Union[str, os.PathLike[str]], + **kwargs: Any) -> _P: ... + + def absolute(self: _P) -> _P: ... + def expanduser(self: _P) -> _P: ... + def read_bytes(self) -> bytes: ... + def read_text(self, encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> str: ... + def samefile(self, other_path: Union[str, bytes, int, Path]) -> bool: ... + def write_bytes(self, data: bytes) -> int: ... + def write_text(self, data: str, encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> int: ... + + +class PosixPath(Path, PurePosixPath): ... +class WindowsPath(Path, PureWindowsPath): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/selectors.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/selectors.pyi new file mode 100644 index 000000000..38f49fe38 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/selectors.pyi @@ -0,0 +1,90 @@ +# Stubs for selector +# See https://docs.python.org/3/library/selectors.html + +from typing import Any, List, NamedTuple, Mapping, Tuple, Optional, Union +from abc import ABCMeta, abstractmethod +import socket + + +# Type aliases added mainly to preserve some context +# +# See https://github.com/python/typeshed/issues/482 +# for details regarding how _FileObject is typed. +_FileObject = Union[int, socket.socket] +_FileDescriptor = int +_EventMask = int + + +EVENT_READ = ... # type: _EventMask +EVENT_WRITE = ... # type: _EventMask + + +SelectorKey = NamedTuple('SelectorKey', [ + ('fileobj', _FileObject), + ('fd', _FileDescriptor), + ('events', _EventMask), + ('data', Any) +]) + + +class BaseSelector(metaclass=ABCMeta): + @abstractmethod + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + + @abstractmethod + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + + def modify(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + + @abstractmethod + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + + def close(self) -> None: ... + + def get_key(self, fileobj: _FileObject) -> SelectorKey: ... + + @abstractmethod + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... + + def __enter__(self) -> BaseSelector: ... + + def __exit__(self, *args: Any) -> None: ... + +class SelectSelector(BaseSelector): + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... + +class PollSelector(BaseSelector): + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... + +class EpollSelector(BaseSelector): + def fileno(self) -> int: ... + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... + +class DevpollSelector(BaseSelector): + def fileno(self) -> int: ... + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... + +class KqueueSelector(BaseSelector): + def fileno(self) -> int: ... + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... + +class DefaultSelector(BaseSelector): + def register(self, fileobj: _FileObject, events: _EventMask, data: Any = ...) -> SelectorKey: ... + def unregister(self, fileobj: _FileObject) -> SelectorKey: ... + def select(self, timeout: Optional[float] = ...) -> List[Tuple[SelectorKey, _EventMask]]: ... + def get_map(self) -> Mapping[_FileObject, SelectorKey]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/statistics.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/statistics.pyi new file mode 100644 index 000000000..d9116e587 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/statistics.pyi @@ -0,0 +1,24 @@ +# Stubs for statistics + +from decimal import Decimal +from fractions import Fraction +import sys +from typing import Iterable, Optional, TypeVar + +# Most functions in this module accept homogeneous collections of one of these types +_Number = TypeVar('_Number', float, Decimal, Fraction) + +class StatisticsError(ValueError): ... + +def mean(data: Iterable[_Number]) -> _Number: ... +if sys.version_info >= (3, 6): + def harmonic_mean(data: Iterable[_Number]) -> _Number: ... +def median(data: Iterable[_Number]) -> _Number: ... +def median_low(data: Iterable[_Number]) -> _Number: ... +def median_high(data: Iterable[_Number]) -> _Number: ... +def median_grouped(data: Iterable[_Number]) -> _Number: ... +def mode(data: Iterable[_Number]) -> _Number: ... +def pstdev(data: Iterable[_Number], mu: Optional[_Number] = ...) -> _Number: ... +def pvariance(data: Iterable[_Number], mu: Optional[_Number] = ...) -> _Number: ... +def stdev(data: Iterable[_Number], xbar: Optional[_Number] = ...) -> _Number: ... +def variance(data: Iterable[_Number], xbar: Optional[_Number] = ...) -> _Number: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/tracemalloc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/tracemalloc.pyi new file mode 100644 index 000000000..4556f04e8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.4/tracemalloc.pyi @@ -0,0 +1,70 @@ +# Stubs for tracemalloc (Python 3.4+) + +import sys +from typing import List, Optional, Sequence, Tuple, Union, overload + +def clear_traces() -> None: ... +def get_object_traceback(obj: object) -> Optional[Traceback]: ... +def get_traceback_limit() -> int: ... +def get_traced_memory() -> Tuple[int, int]: ... +def get_tracemalloc_memory() -> int: ... +def is_tracing() -> bool: ... +def start(nframe: int = ...) -> None: ... +def stop() -> None: ... +def take_snapshot() -> Snapshot: ... + +if sys.version_info >= (3, 6): + class DomainFilter: + inclusive = ... # type: bool + domain = ... # type: int + def __init__(self, inclusive: bool, domain: int) -> None: ... + +class Filter: + if sys.version_info >= (3, 6): + domain = ... # type: Optional[int] + inclusive = ... # type: bool + lineno = ... # type: Optional[int] + filename_pattern = ... # type: str + all_frames = ... # type: bool + def __init__(self, inclusive: bool, filename_pattern: str, lineno: Optional[int] = ..., all_frames: bool = ..., domain: Optional[int] = ...) -> None: ... + +class Frame: + filename = ... # type: str + lineno = ... # type: int + +class Snapshot: + def compare_to(self, old_snapshot: Snapshot, key_type: str, cumulative: bool = ...) -> List[StatisticDiff]: ... + def dump(self, filename: str) -> None: ... + if sys.version_info >= (3, 6): + def filter_traces(self, filters: Sequence[Union[DomainFilter, Filter]]) -> Snapshot: ... + else: + def filter_traces(self, filters: Sequence[Filter]) -> Snapshot: ... + @classmethod + def load(cls, filename: str) -> Snapshot: ... + def statistics(self, key_type: str, cumulative: bool = ...) -> List[Statistic]: ... + traceback_limit = ... # type: int + traces = ... # type: Sequence[Trace] + +class Statistic: + count = ... # type: int + size = ... # type: int + traceback = ... # type: Traceback + +class StatisticDiff: + count = ... # type: int + count_diff = ... # type: int + size = ... # type: int + size_diff = ... # type: int + traceback = ... # type: Traceback + +class Trace: + size = ... # type: int + traceback = ... # type: Traceback + +class Traceback(Sequence[Frame]): + def format(self, limit: Optional[int] = ...) -> List[str]: ... + @overload + def __getitem__(self, i: int) -> Frame: ... + @overload + def __getitem__(self, s: slice) -> Sequence[Frame]: ... + def __len__(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.5/zipapp.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.5/zipapp.pyi new file mode 100644 index 000000000..b90b7559c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.5/zipapp.pyi @@ -0,0 +1,16 @@ +# Stubs for zipapp (Python 3.5+) + +from pathlib import Path +import sys +from typing import BinaryIO, Callable, Optional, Union + +_Path = Union[str, Path, BinaryIO] + +class ZipAppError(Exception): ... + +if sys.version_info >= (3, 7): + def create_archive(source: _Path, target: Optional[_Path] = ..., interpreter: Optional[str] = ..., main: Optional[str] = ..., + filter: Optional[Callable[[Path], bool]] = ..., compressed: bool = ...) -> None: ... +else: + def create_archive(source: _Path, target: Optional[_Path] = ..., interpreter: Optional[str] = ..., main: Optional[str] = ...) -> None: ... +def get_interpreter(archive: _Path) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.6/secrets.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.6/secrets.pyi new file mode 100644 index 000000000..5069dba25 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.6/secrets.pyi @@ -0,0 +1,14 @@ +# Stubs for secrets (Python 3.6) + +from typing import Optional, Sequence, TypeVar +from hmac import compare_digest as compare_digest +from random import SystemRandom as SystemRandom + +_T = TypeVar('_T') + +def randbelow(exclusive_upper_bound: int) -> int: ... +def randbits(k: int) -> int: ... +def choice(seq: Sequence[_T]) -> _T: ... +def token_bytes(nbytes: Optional[int] = ...) -> bytes: ... +def token_hex(nbytes: Optional[int] = ...) -> str: ... +def token_urlsafe(nbytes: Optional[int] = ...) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.7/contextvars.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.7/contextvars.pyi new file mode 100644 index 000000000..ab2ae9e5f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.7/contextvars.pyi @@ -0,0 +1,30 @@ +from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar, Union + +_T = TypeVar('_T') + +class ContextVar(Generic[_T]): + def __init__(self, name: str, *, default: _T = ...) -> None: ... + @property + def name(self) -> str: ... + def get(self, default: _T = ...) -> _T: ... + def set(self, value: _T) -> Token[_T]: ... + def reset(self, token: Token[_T]) -> None: ... + +class Token(Generic[_T]): + @property + def var(self) -> ContextVar[_T]: ... + @property + def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express + MISSING: ClassVar[object] + +def copy_context() -> Context: ... + +# It doesn't make sense to make this generic, because for most Contexts each ContextVar will have +# a different value. +class Context(Mapping[ContextVar[Any], Any]): + def __init__(self) -> None: ... + def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ... + def copy(self) -> Context: ... + def __getitem__(self, key: ContextVar[Any]) -> Any: ... + def __iter__(self) -> Iterator[ContextVar[Any]]: ... + def __len__(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3.7/dataclasses.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.7/dataclasses.pyi new file mode 100644 index 000000000..de4fe69ca --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3.7/dataclasses.pyi @@ -0,0 +1,64 @@ +from typing import overload, Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Tuple, Type, TypeVar, Union + + +_T = TypeVar('_T') + +class _MISSING_TYPE: ... +MISSING: _MISSING_TYPE + +def asdict(obj: Any, *, dict_factory: Callable[[List[Tuple[str, Any]]], _T] = ...) -> _T: ... + +def astuple(obj: Any, *, tuple_factory: Callable[[List[Any]], _T] = ...) -> _T: ... + + +@overload +def dataclass(_cls: Type[_T]) -> Type[_T]: ... + +@overload +def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., + unsafe_hash: bool = ..., frozen: bool = ...) -> Callable[[Type[_T]], Type[_T]]: ... + + +class Field(Generic[_T]): + name: str + type: Type[_T] + default: _T + default_factory: Callable[[], _T] + repr: bool + hash: Optional[bool] + init: bool + compare: bool + metadata: Optional[Mapping[str, Any]] + + +# NOTE: Actual return type is 'Field[_T]', but we want to help type checkers +# to understand the magic that happens at runtime. +@overload # `default` and `default_factory` are optional and mutually exclusive. +def field(*, default: _T, + init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., + metadata: Optional[Mapping[str, Any]] = ...) -> _T: ... + +@overload +def field(*, default_factory: Callable[[], _T], + init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., + metadata: Optional[Mapping[str, Any]] = ...) -> _T: ... + +@overload +def field(*, + init: bool = ..., repr: bool = ..., hash: Optional[bool] = ..., compare: bool = ..., + metadata: Optional[Mapping[str, Any]] = ...) -> Any: ... + + +def fields(class_or_instance: Any) -> Tuple[Field[Any], ...]: ... + +def is_dataclass(obj: Any) -> bool: ... + +class FrozenInstanceError(AttributeError): ... + +class InitVar(Generic[_T]): ... + +def make_dataclass(cls_name: str, fields: Iterable[Union[str, Tuple[str, type], Tuple[str, type, Field[Any]]]], *, + bases: Tuple[type, ...] = ..., namespace: Optional[Dict[str, Any]] = ..., + init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., hash: bool = ..., frozen: bool = ...): ... + +def replace(obj: _T, **changes: Any) -> _T: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_ast.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_ast.pyi new file mode 100644 index 000000000..4b3de95ed --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_ast.pyi @@ -0,0 +1,384 @@ +import sys +import typing +from typing import Any, Optional, Union + +PyCF_ONLY_AST = ... # type: int + +_identifier = str + +class AST: + _attributes = ... # type: typing.Tuple[str, ...] + _fields = ... # type: typing.Tuple[str, ...] + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + +class mod(AST): + ... + +class Module(mod): + body = ... # type: typing.List[stmt] + if sys.version_info >= (3, 7): + docstring: Optional[str] + +class Interactive(mod): + body = ... # type: typing.List[stmt] + +class Expression(mod): + body = ... # type: expr + +class Suite(mod): + body = ... # type: typing.List[stmt] + + +class stmt(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class FunctionDef(stmt): + name = ... # type: _identifier + args = ... # type: arguments + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + returns = ... # type: Optional[expr] + if sys.version_info >= (3, 7): + docstring: Optional[str] + +class AsyncFunctionDef(stmt): + name = ... # type: _identifier + args = ... # type: arguments + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + returns = ... # type: Optional[expr] + if sys.version_info >= (3, 7): + docstring: Optional[str] + +class ClassDef(stmt): + name = ... # type: _identifier + bases = ... # type: typing.List[expr] + keywords = ... # type: typing.List[keyword] + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + if sys.version_info >= (3, 7): + docstring: Optional[str] + +class Return(stmt): + value = ... # type: Optional[expr] + +class Delete(stmt): + targets = ... # type: typing.List[expr] + +class Assign(stmt): + targets = ... # type: typing.List[expr] + value = ... # type: expr + +class AugAssign(stmt): + target = ... # type: expr + op = ... # type: operator + value = ... # type: expr + +if sys.version_info >= (3, 6): + class AnnAssign(stmt): + target = ... # type: expr + annotation = ... # type: expr + value = ... # type: Optional[expr] + simple = ... # type: int + +class For(stmt): + target = ... # type: expr + iter = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class AsyncFor(stmt): + target = ... # type: expr + iter = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class While(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class If(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class With(stmt): + items = ... # type: typing.List[withitem] + body = ... # type: typing.List[stmt] + +class AsyncWith(stmt): + items = ... # type: typing.List[withitem] + body = ... # type: typing.List[stmt] + +class Raise(stmt): + exc = ... # type: Optional[expr] + cause = ... # type: Optional[expr] + +class Try(stmt): + body = ... # type: typing.List[stmt] + handlers = ... # type: typing.List[ExceptHandler] + orelse = ... # type: typing.List[stmt] + finalbody = ... # type: typing.List[stmt] + +class Assert(stmt): + test = ... # type: expr + msg = ... # type: Optional[expr] + +class Import(stmt): + names = ... # type: typing.List[alias] + +class ImportFrom(stmt): + module = ... # type: Optional[_identifier] + names = ... # type: typing.List[alias] + level = ... # type: Optional[int] + +class Global(stmt): + names = ... # type: typing.List[_identifier] + +class Nonlocal(stmt): + names = ... # type: typing.List[_identifier] + +class Expr(stmt): + value = ... # type: expr + +class Pass(stmt): ... +class Break(stmt): ... +class Continue(stmt): ... + + +class slice(AST): + ... + +_slice = slice # this lets us type the variable named 'slice' below + +class Slice(slice): + lower = ... # type: Optional[expr] + upper = ... # type: Optional[expr] + step = ... # type: Optional[expr] + +class ExtSlice(slice): + dims = ... # type: typing.List[slice] + +class Index(slice): + value = ... # type: expr + + +class expr(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class BoolOp(expr): + op = ... # type: boolop + values = ... # type: typing.List[expr] + +class BinOp(expr): + left = ... # type: expr + op = ... # type: operator + right = ... # type: expr + +class UnaryOp(expr): + op = ... # type: unaryop + operand = ... # type: expr + +class Lambda(expr): + args = ... # type: arguments + body = ... # type: expr + +class IfExp(expr): + test = ... # type: expr + body = ... # type: expr + orelse = ... # type: expr + +class Dict(expr): + keys = ... # type: typing.List[expr] + values = ... # type: typing.List[expr] + +class Set(expr): + elts = ... # type: typing.List[expr] + +class ListComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class SetComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class DictComp(expr): + key = ... # type: expr + value = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class GeneratorExp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class Await(expr): + value = ... # type: expr + +class Yield(expr): + value = ... # type: Optional[expr] + +class YieldFrom(expr): + value = ... # type: expr + +class Compare(expr): + left = ... # type: expr + ops = ... # type: typing.List[cmpop] + comparators = ... # type: typing.List[expr] + +class Call(expr): + func = ... # type: expr + args = ... # type: typing.List[expr] + keywords = ... # type: typing.List[keyword] + +class Num(expr): + n = ... # type: Union[int, float] + +class Str(expr): + s = ... # type: str + +if sys.version_info >= (3, 6): + class FormattedValue(expr): + value = ... # type: expr + conversion = ... # type: Optional[int] + format_spec = ... # type: Optional[expr] + + class JoinedStr(expr): + values = ... # type: typing.List[expr] + +class Bytes(expr): + s = ... # type: bytes + +class NameConstant(expr): + value = ... # type: Any + +class Ellipsis(expr): ... + +class Attribute(expr): + value = ... # type: expr + attr = ... # type: _identifier + ctx = ... # type: expr_context + +class Subscript(expr): + value = ... # type: expr + slice = ... # type: _slice + ctx = ... # type: expr_context + +class Starred(expr): + value = ... # type: expr + ctx = ... # type: expr_context + +class Name(expr): + id = ... # type: _identifier + ctx = ... # type: expr_context + +class List(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + +class Tuple(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + + +class expr_context(AST): + ... + +class AugLoad(expr_context): ... +class AugStore(expr_context): ... +class Del(expr_context): ... +class Load(expr_context): ... +class Param(expr_context): ... +class Store(expr_context): ... + + +class boolop(AST): + ... + +class And(boolop): ... +class Or(boolop): ... + +class operator(AST): + ... + +class Add(operator): ... +class BitAnd(operator): ... +class BitOr(operator): ... +class BitXor(operator): ... +class Div(operator): ... +class FloorDiv(operator): ... +class LShift(operator): ... +class Mod(operator): ... +class Mult(operator): ... +class MatMult(operator): ... +class Pow(operator): ... +class RShift(operator): ... +class Sub(operator): ... + +class unaryop(AST): + ... + +class Invert(unaryop): ... +class Not(unaryop): ... +class UAdd(unaryop): ... +class USub(unaryop): ... + +class cmpop(AST): + ... + +class Eq(cmpop): ... +class Gt(cmpop): ... +class GtE(cmpop): ... +class In(cmpop): ... +class Is(cmpop): ... +class IsNot(cmpop): ... +class Lt(cmpop): ... +class LtE(cmpop): ... +class NotEq(cmpop): ... +class NotIn(cmpop): ... + + +class comprehension(AST): + target = ... # type: expr + iter = ... # type: expr + ifs = ... # type: typing.List[expr] + if sys.version_info >= (3, 6): + is_async = ... # type: int + + +class ExceptHandler(AST): + type = ... # type: Optional[expr] + name = ... # type: Optional[_identifier] + body = ... # type: typing.List[stmt] + lineno = ... # type: int + col_offset = ... # type: int + + +class arguments(AST): + args = ... # type: typing.List[arg] + vararg = ... # type: Optional[arg] + kwonlyargs = ... # type: typing.List[arg] + kw_defaults = ... # type: typing.List[expr] + kwarg = ... # type: Optional[arg] + defaults = ... # type: typing.List[expr] + +class arg(AST): + arg = ... # type: _identifier + annotation = ... # type: Optional[expr] + lineno = ... # type: int + col_offset = ... # type: int + +class keyword(AST): + arg = ... # type: Optional[_identifier] + value = ... # type: expr + +class alias(AST): + name = ... # type: _identifier + asname = ... # type: Optional[_identifier] + +class withitem(AST): + context_expr = ... # type: expr + optional_vars = ... # type: Optional[expr] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_compression.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_compression.pyi new file mode 100644 index 000000000..d84a11a51 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_compression.pyi @@ -0,0 +1,16 @@ +from typing import Any +import io + +BUFFER_SIZE = ... # type: Any + +class BaseStream(io.BufferedIOBase): ... + +class DecompressReader(io.RawIOBase): + def readable(self): ... + def __init__(self, fp, decomp_factory, trailing_error=..., **decomp_args): ... + def close(self): ... + def seekable(self): ... + def readinto(self, b): ... + def read(self, size=-1): ... + def seek(self, offset, whence=...): ... + def tell(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_curses.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_curses.pyi new file mode 100644 index 000000000..153065e90 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_curses.pyi @@ -0,0 +1,447 @@ +from typing import Any, BinaryIO, IO, Optional, Tuple, Union, overload + +_chtype = Union[str, bytes, int] + +ALL_MOUSE_EVENTS = ... # type: int +A_ALTCHARSET = ... # type: int +A_ATTRIBUTES = ... # type: int +A_BLINK = ... # type: int +A_BOLD = ... # type: int +A_CHARTEXT = ... # type: int +A_COLOR = ... # type: int +A_DIM = ... # type: int +A_HORIZONTAL = ... # type: int +A_INVIS = ... # type: int +A_LEFT = ... # type: int +A_LOW = ... # type: int +A_NORMAL = ... # type: int +A_PROTECT = ... # type: int +A_REVERSE = ... # type: int +A_RIGHT = ... # type: int +A_STANDOUT = ... # type: int +A_TOP = ... # type: int +A_UNDERLINE = ... # type: int +A_VERTICAL = ... # type: int +BUTTON1_CLICKED = ... # type: int +BUTTON1_DOUBLE_CLICKED = ... # type: int +BUTTON1_PRESSED = ... # type: int +BUTTON1_RELEASED = ... # type: int +BUTTON1_TRIPLE_CLICKED = ... # type: int +BUTTON2_CLICKED = ... # type: int +BUTTON2_DOUBLE_CLICKED = ... # type: int +BUTTON2_PRESSED = ... # type: int +BUTTON2_RELEASED = ... # type: int +BUTTON2_TRIPLE_CLICKED = ... # type: int +BUTTON3_CLICKED = ... # type: int +BUTTON3_DOUBLE_CLICKED = ... # type: int +BUTTON3_PRESSED = ... # type: int +BUTTON3_RELEASED = ... # type: int +BUTTON3_TRIPLE_CLICKED = ... # type: int +BUTTON4_CLICKED = ... # type: int +BUTTON4_DOUBLE_CLICKED = ... # type: int +BUTTON4_PRESSED = ... # type: int +BUTTON4_RELEASED = ... # type: int +BUTTON4_TRIPLE_CLICKED = ... # type: int +BUTTON_ALT = ... # type: int +BUTTON_CTRL = ... # type: int +BUTTON_SHIFT = ... # type: int +COLOR_BLACK = ... # type: int +COLOR_BLUE = ... # type: int +COLOR_CYAN = ... # type: int +COLOR_GREEN = ... # type: int +COLOR_MAGENTA = ... # type: int +COLOR_RED = ... # type: int +COLOR_WHITE = ... # type: int +COLOR_YELLOW = ... # type: int +ERR = ... # type: int +KEY_A1 = ... # type: int +KEY_A3 = ... # type: int +KEY_B2 = ... # type: int +KEY_BACKSPACE = ... # type: int +KEY_BEG = ... # type: int +KEY_BREAK = ... # type: int +KEY_BTAB = ... # type: int +KEY_C1 = ... # type: int +KEY_C3 = ... # type: int +KEY_CANCEL = ... # type: int +KEY_CATAB = ... # type: int +KEY_CLEAR = ... # type: int +KEY_CLOSE = ... # type: int +KEY_COMMAND = ... # type: int +KEY_COPY = ... # type: int +KEY_CREATE = ... # type: int +KEY_CTAB = ... # type: int +KEY_DC = ... # type: int +KEY_DL = ... # type: int +KEY_DOWN = ... # type: int +KEY_EIC = ... # type: int +KEY_END = ... # type: int +KEY_ENTER = ... # type: int +KEY_EOL = ... # type: int +KEY_EOS = ... # type: int +KEY_EXIT = ... # type: int +KEY_F0 = ... # type: int +KEY_F1 = ... # type: int +KEY_F10 = ... # type: int +KEY_F11 = ... # type: int +KEY_F12 = ... # type: int +KEY_F13 = ... # type: int +KEY_F14 = ... # type: int +KEY_F15 = ... # type: int +KEY_F16 = ... # type: int +KEY_F17 = ... # type: int +KEY_F18 = ... # type: int +KEY_F19 = ... # type: int +KEY_F2 = ... # type: int +KEY_F20 = ... # type: int +KEY_F21 = ... # type: int +KEY_F22 = ... # type: int +KEY_F23 = ... # type: int +KEY_F24 = ... # type: int +KEY_F25 = ... # type: int +KEY_F26 = ... # type: int +KEY_F27 = ... # type: int +KEY_F28 = ... # type: int +KEY_F29 = ... # type: int +KEY_F3 = ... # type: int +KEY_F30 = ... # type: int +KEY_F31 = ... # type: int +KEY_F32 = ... # type: int +KEY_F33 = ... # type: int +KEY_F34 = ... # type: int +KEY_F35 = ... # type: int +KEY_F36 = ... # type: int +KEY_F37 = ... # type: int +KEY_F38 = ... # type: int +KEY_F39 = ... # type: int +KEY_F4 = ... # type: int +KEY_F40 = ... # type: int +KEY_F41 = ... # type: int +KEY_F42 = ... # type: int +KEY_F43 = ... # type: int +KEY_F44 = ... # type: int +KEY_F45 = ... # type: int +KEY_F46 = ... # type: int +KEY_F47 = ... # type: int +KEY_F48 = ... # type: int +KEY_F49 = ... # type: int +KEY_F5 = ... # type: int +KEY_F50 = ... # type: int +KEY_F51 = ... # type: int +KEY_F52 = ... # type: int +KEY_F53 = ... # type: int +KEY_F54 = ... # type: int +KEY_F55 = ... # type: int +KEY_F56 = ... # type: int +KEY_F57 = ... # type: int +KEY_F58 = ... # type: int +KEY_F59 = ... # type: int +KEY_F6 = ... # type: int +KEY_F60 = ... # type: int +KEY_F61 = ... # type: int +KEY_F62 = ... # type: int +KEY_F63 = ... # type: int +KEY_F7 = ... # type: int +KEY_F8 = ... # type: int +KEY_F9 = ... # type: int +KEY_FIND = ... # type: int +KEY_HELP = ... # type: int +KEY_HOME = ... # type: int +KEY_IC = ... # type: int +KEY_IL = ... # type: int +KEY_LEFT = ... # type: int +KEY_LL = ... # type: int +KEY_MARK = ... # type: int +KEY_MAX = ... # type: int +KEY_MESSAGE = ... # type: int +KEY_MIN = ... # type: int +KEY_MOUSE = ... # type: int +KEY_MOVE = ... # type: int +KEY_NEXT = ... # type: int +KEY_NPAGE = ... # type: int +KEY_OPEN = ... # type: int +KEY_OPTIONS = ... # type: int +KEY_PPAGE = ... # type: int +KEY_PREVIOUS = ... # type: int +KEY_PRINT = ... # type: int +KEY_REDO = ... # type: int +KEY_REFERENCE = ... # type: int +KEY_REFRESH = ... # type: int +KEY_REPLACE = ... # type: int +KEY_RESET = ... # type: int +KEY_RESIZE = ... # type: int +KEY_RESTART = ... # type: int +KEY_RESUME = ... # type: int +KEY_RIGHT = ... # type: int +KEY_SAVE = ... # type: int +KEY_SBEG = ... # type: int +KEY_SCANCEL = ... # type: int +KEY_SCOMMAND = ... # type: int +KEY_SCOPY = ... # type: int +KEY_SCREATE = ... # type: int +KEY_SDC = ... # type: int +KEY_SDL = ... # type: int +KEY_SELECT = ... # type: int +KEY_SEND = ... # type: int +KEY_SEOL = ... # type: int +KEY_SEXIT = ... # type: int +KEY_SF = ... # type: int +KEY_SFIND = ... # type: int +KEY_SHELP = ... # type: int +KEY_SHOME = ... # type: int +KEY_SIC = ... # type: int +KEY_SLEFT = ... # type: int +KEY_SMESSAGE = ... # type: int +KEY_SMOVE = ... # type: int +KEY_SNEXT = ... # type: int +KEY_SOPTIONS = ... # type: int +KEY_SPREVIOUS = ... # type: int +KEY_SPRINT = ... # type: int +KEY_SR = ... # type: int +KEY_SREDO = ... # type: int +KEY_SREPLACE = ... # type: int +KEY_SRESET = ... # type: int +KEY_SRIGHT = ... # type: int +KEY_SRSUME = ... # type: int +KEY_SSAVE = ... # type: int +KEY_SSUSPEND = ... # type: int +KEY_STAB = ... # type: int +KEY_SUNDO = ... # type: int +KEY_SUSPEND = ... # type: int +KEY_UNDO = ... # type: int +KEY_UP = ... # type: int +OK = ... # type: int +REPORT_MOUSE_POSITION = ... # type: int +_C_API = ... # type: Any +version = ... # type: bytes + +def baudrate() -> int: ... +def beep() -> None: ... +def can_change_color() -> bool: ... +def cbreak(flag: bool = ...) -> None: ... +def color_content(color_number: int) -> Tuple[int, int, int]: ... +def color_pair(color_number: int) -> int: ... +def curs_set(visibility: int) -> int: ... +def def_prog_mode() -> None: ... +def def_shell_mode() -> None: ... +def delay_output(ms: int) -> None: ... +def doupdate() -> None: ... +def echo(flag: bool = ...) -> None: ... +def endwin() -> None: ... +def erasechar() -> bytes: ... +def filter() -> None: ... +def flash() -> None: ... +def flushinp() -> None: ... +def getmouse() -> Tuple[int, int, int, int, int]: ... +def getsyx() -> Tuple[int, int]: ... +def getwin(f: BinaryIO) -> _CursesWindow: ... +def halfdelay(tenths: int) -> None: ... +def has_colors() -> bool: ... +def has_ic() -> bool: ... +def has_il() -> bool: ... +def has_key(ch: int) -> bool: ... +def init_color(color_number: int, r: int, g: int, b: int) -> None: ... +def init_pair(pair_number: int, fg: int, bg: int) -> None: ... +def initscr() -> _CursesWindow: ... +def intrflush(ch: bool) -> None: ... +def is_term_resized(nlines: int, ncols: int) -> bool: ... +def isendwin() -> bool: ... +def keyname(k: int) -> bytes: ... +def killchar() -> bytes: ... +def longname() -> bytes: ... +def meta(yes: bool) -> None: ... +def mouseinterval(interval: int) -> None: ... +def mousemask(mousemask: int) -> Tuple[int, int]: ... +def napms(ms: int) -> int: ... +def newpad(nlines: int, ncols: int) -> _CursesWindow: ... +def newwin(nlines: int, ncols: int, begin_y: int = ..., begin_x: int = ...) -> _CursesWindow: ... +def nl(flag: bool = ...) -> None: ... +def nocbreak() -> None: ... +def noecho() -> None: ... +def nonl() -> None: ... +def noqiflush() -> None: ... +def noraw() -> None: ... +def pair_content(pair_number: int) -> Tuple[int, int]: ... +def pair_number(attr: int) -> int: ... +def putp(string: bytes) -> None: ... +def qiflush(flag: bool = ...) -> None: ... +def raw(flag: bool = ...) -> None: ... +def reset_prog_mode() -> None: ... +def reset_shell_mode() -> None: ... +def resetty() -> None: ... +def resize_term(nlines: int, ncols: int) -> None: ... +def resizeterm(nlines: int, ncols: int) -> None: ... +def savetty() -> None: ... +def setsyx(y: int, x: int) -> None: ... +def setupterm(termstr: str = ..., fd: int = ...) -> None: ... +def start_color() -> None: ... +def termattrs() -> int: ... +def termname() -> bytes: ... +def tigetflag(capname: str) -> int: ... +def tigetnum(capname: str) -> int: ... +def tigetstr(capname: str) -> bytes: ... +def tparm(fmt: bytes, i1: int = ..., i2: int = ..., i3: int = ..., i4: int = ..., i5: int = ..., i6: int = ..., i7: int = ..., i8: int = ..., i9: int = ...) -> bytes: ... +def typeahead(fd: int) -> None: ... +def unctrl(ch: _chtype) -> bytes: ... +def unget_wch(ch: _chtype) -> None: ... +def ungetch(ch: _chtype) -> None: ... +def ungetmouse(id: int, x: int, y: int, z: int, bstate: int) -> None: ... +def update_lines_cols() -> int: ... +def use_default_colors() -> None: ... +def use_env(flag: bool) -> None: ... + +class error(Exception): ... + +class _CursesWindow: + encoding = ... # type: str + @overload + def addch(self, ch: _chtype, attr: int = ...) -> None: ... + @overload + def addch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ... + @overload + def addnstr(self, str: str, n: int, attr: int = ...) -> None: ... + @overload + def addnstr(self, y: int, x: int, str: str, n: int, attr: int = ...) -> None: ... + @overload + def addstr(self, str: str, attr: int = ...) -> None: ... + @overload + def addstr(self, y: int, x: int, str: str, attr: int = ...) -> None: ... + def attroff(self, attr: int) -> None: ... + def attron(self, attr: int) -> None: ... + def attrset(self, attr: int) -> None: ... + def bkgd(self, ch: _chtype, attr: int = ...) -> None: ... + def bkgset(self, ch: _chtype, attr: int = ...) -> None: ... + def border(self, ls: _chtype = ..., rs: _chtype = ..., ts: _chtype = ..., bs: _chtype = ..., tl: _chtype = ..., tr: _chtype = ..., bl: _chtype = ..., br: _chtype = ...) -> None: ... + @overload + def box(self) -> None: ... + @overload + def box(self, vertch: _chtype = ..., horch: _chtype = ...) -> None: ... + @overload + def chgat(self, attr: int) -> None: ... + @overload + def chgat(self, num: int, attr: int) -> None: ... + @overload + def chgat(self, y: int, x: int, attr: int) -> None: ... + @overload + def chgat(self, y: int, x: int, num: int, attr: int) -> None: ... + def clear(self) -> None: ... + def clearok(self, yes: int) -> None: ... + def clrtobot(self) -> None: ... + def clrtoeol(self) -> None: ... + def cursyncup(self) -> None: ... + @overload + def delch(self) -> None: ... + @overload + def delch(self, y: int, x: int) -> None: ... + def deleteln(self) -> None: ... + @overload + def derwin(self, begin_y: int, begin_x: int) -> '_CursesWindow': ... + @overload + def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> '_CursesWindow': ... + def echochar(self, ch: _chtype, attr: int = ...) -> None: ... + def enclose(self, y: int, x: int) -> bool: ... + def erase(self) -> None: ... + def getbegyx(self) -> Tuple[int, int]: ... + def getbkgd(self) -> Tuple[int, int]: ... + @overload + def getch(self) -> _chtype: ... + @overload + def getch(self, y: int, x: int) -> _chtype: ... + @overload + def get_wch(self) -> _chtype: ... + @overload + def get_wch(self, y: int, x: int) -> _chtype: ... + @overload + def getkey(self) -> str: ... + @overload + def getkey(self, y: int, x: int) -> str: ... + def getmaxyx(self) -> Tuple[int, int]: ... + def getparyx(self) -> Tuple[int, int]: ... + @overload + def getstr(self) -> _chtype: ... + @overload + def getstr(self, n: int) -> _chtype: ... + @overload + def getstr(self, y: int, x: int) -> _chtype: ... + @overload + def getstr(self, y: int, x: int, n: int) -> _chtype: ... + def getyx(self) -> Tuple[int, int]: ... + @overload + def hline(self, ch: _chtype, n: int) -> None: ... + @overload + def hline(self, y: int, x: int, ch: _chtype, n: int) -> None: ... + def idcok(self, flag: bool) -> None: ... + def idlok(self, yes: bool) -> None: ... + def immedok(self, flag: bool) -> None: ... + @overload + def inch(self) -> _chtype: ... + @overload + def inch(self, y: int, x: int) -> _chtype: ... + @overload + def insch(self, ch: _chtype, attr: int = ...) -> None: ... + @overload + def insch(self, y: int, x: int, ch: _chtype, attr: int = ...) -> None: ... + def insdelln(self, nlines: int) -> None: ... + def insertln(self) -> None: ... + @overload + def insnstr(self, str: str, n: int, attr: int = ...) -> None: ... + @overload + def insnstr(self, y: int, x: int, str: str, n: int, attr: int = ...) -> None: ... + @overload + def insstr(self, str: str, attr: int = ...) -> None: ... + @overload + def insstr(self, y: int, x: int, str: str, attr: int = ...) -> None: ... + @overload + def instr(self, n: int = ...) -> _chtype: ... + @overload + def instr(self, y: int, x: int, n: int = ...) -> _chtype: ... + def is_linetouched(self, line: int) -> bool: ... + def is_wintouched(self) -> bool: ... + def keypad(self, yes: bool) -> None: ... + def leaveok(self, yes: bool) -> None: ... + def move(self, new_y: int, new_x: int) -> None: ... + def mvderwin(self, y: int, x: int) -> None: ... + def mvwin(self, new_y: int, new_x: int) -> None: ... + def nodelay(self, yes: bool) -> None: ... + def notimeout(self, yes: bool) -> None: ... + def noutrefresh(self) -> None: ... + @overload + def overlay(self, destwin: '_CursesWindow') -> None: ... + @overload + def overlay(self, destwin: '_CursesWindow', sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int) -> None: ... + @overload + def overwrite(self, destwin: '_CursesWindow') -> None: ... + @overload + def overwrite(self, destwin: '_CursesWindow', sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int) -> None: ... + def putwin(self, file: IO[Any]) -> None: ... + def redrawln(self, beg: int, num: int) -> None: ... + def redrawwin(self) -> None: ... + @overload + def refresh(self) -> None: ... + @overload + def refresh(self, pminrow: int, pmincol: int, sminrow: int, smincol: int, smaxrow: int, smaxcol: int) -> None: ... + def resize(self, nlines: int, ncols: int) -> None: ... + def scroll(self, lines: int = ...) -> None: ... + def scrollok(self, flag: bool) -> None: ... + def setscrreg(self, top: int, bottom: int) -> None: ... + def standend(self) -> None: ... + def standout(self) -> None: ... + @overload + def subpad(self, begin_y: int, begin_x: int) -> '_CursesWindow': ... + @overload + def subpad(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> '_CursesWindow': ... + @overload + def subwin(self, begin_y: int, begin_x: int) -> '_CursesWindow': ... + @overload + def subwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> '_CursesWindow': ... + def syncdown(self) -> None: ... + def syncok(self, flag: bool) -> None: ... + def syncup(self) -> None: ... + def timeout(self, delay: int) -> None: ... + def touchline(self, start: int, count: int, changed: bool = ...) -> None: ... + def touchwin(self) -> None: ... + def untouchwin(self) -> None: ... + @overload + def vline(self, ch: _chtype, n: int) -> None: ... + @overload + def vline(self, y: int, x: int, ch: _chtype, n: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_dummy_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_dummy_thread.pyi new file mode 100644 index 000000000..1260d42de --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_dummy_thread.pyi @@ -0,0 +1,21 @@ +from typing import Any, Callable, Dict, NoReturn, Optional, Tuple + +TIMEOUT_MAX: int +error = RuntimeError + +def start_new_thread(function: Callable[..., Any], args: Tuple[Any, ...], kwargs: Dict[str, Any] = ...) -> None: ... +def exit() -> NoReturn: ... +def get_ident() -> int: ... +def allocate_lock() -> LockType: ... +def stack_size(size: Optional[int] = ...) -> int: ... + +class LockType(object): + locked_status: bool + def __init__(self) -> None: ... + def acquire(self, waitflag: Optional[bool] = ..., timeout: int = ...) -> bool: ... + def __enter__(self, waitflag: Optional[bool] = ..., timeout: int = ...) -> bool: ... + def __exit__(self, typ: Any, val: Any, tb: Any) -> None: ... + def release(self) -> bool: ... + def locked(self) -> bool: ... + +def interrupt_main() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_imp.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_imp.pyi new file mode 100644 index 000000000..7015b3b0c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_imp.pyi @@ -0,0 +1,22 @@ +# Stubs for _imp (Python 3.6) + +import sys +import types +from typing import Any, List + +if sys.version_info >= (3, 5): + from importlib.machinery import ModuleSpec + def create_builtin(spec: ModuleSpec) -> types.ModuleType: ... + def create_dynamic(spec: ModuleSpec, file: Any = ...) -> None: ... + +def acquire_lock() -> None: ... +def exec_builtin(mod: types.ModuleType) -> int: ... +def exec_dynamic(mod: types.ModuleType) -> int: ... +def extension_suffixes() -> List[str]: ... +def get_frozen_object(name: str) -> types.CodeType: ... +def init_frozen(name: str) -> types.ModuleType: ... +def is_builtin(name: str) -> int: ... +def is_frozen(name: str) -> bool: ... +def is_frozen_package(name: str) -> bool: ... +def lock_held() -> bool: ... +def release_lock() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_importlib_modulespec.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_importlib_modulespec.pyi new file mode 100644 index 000000000..74545aab7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_importlib_modulespec.pyi @@ -0,0 +1,40 @@ +# ModuleSpec, ModuleType, Loader are part of a dependency cycle. +# They are officially defined/exported in other places: +# +# - ModuleType in types +# - Loader in importlib.abc +# - ModuleSpec in importlib.machinery (3.4 and later only) + +from abc import ABCMeta +import sys +from typing import Any, Dict, List, Optional + +class ModuleSpec: + def __init__(self, name: str, loader: Optional['Loader'], *, + origin: Optional[str] = ..., loader_state: Any = ..., + is_package: Optional[bool] = ...) -> None: ... + name = ... # type: str + loader = ... # type: Optional[Loader] + origin = ... # type: Optional[str] + submodule_search_locations = ... # type: Optional[List[str]] + loader_state = ... # type: Any + cached = ... # type: Optional[str] + parent = ... # type: Optional[str] + has_location = ... # type: bool + +class ModuleType: + __name__ = ... # type: str + __file__ = ... # type: str + __dict__ = ... # type: Dict[str, Any] + __loader__ = ... # type: Optional[Loader] + __package__ = ... # type: Optional[str] + __spec__ = ... # type: Optional[ModuleSpec] + def __init__(self, name: str, doc: Optional[str] = ...) -> None: ... + +class Loader(metaclass=ABCMeta): + def load_module(self, fullname: str) -> ModuleType: ... + def module_repr(self, module: ModuleType) -> str: ... + def create_module(self, spec: ModuleSpec) -> Optional[ModuleType]: ... + # Not defined on the actual class for backwards-compatibility reasons, + # but expected in new code. + def exec_module(self, module: ModuleType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_json.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_json.pyi new file mode 100644 index 000000000..ce9483af6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_json.pyi @@ -0,0 +1,30 @@ +"""Stub file for the '_json' module.""" + +from typing import Any, Tuple + +class make_encoder: + sort_keys = ... # type: Any + skipkeys = ... # type: Any + key_separator = ... # type: Any + indent = ... # type: Any + markers = ... # type: Any + default = ... # type: Any + encoder = ... # type: Any + item_separator = ... # type: Any + def __init__(self, markers, default, encoder, indent, key_separator, + item_separator, sort_keys, skipkeys, allow_nan) -> None: ... + def __call__(self, *args, **kwargs) -> Any: ... + +class make_scanner: + object_hook = ... # type: Any + object_pairs_hook = ... # type: Any + parse_int = ... # type: Any + parse_constant = ... # type: Any + parse_float = ... # type: Any + strict = ... # type: bool + # TODO: 'context' needs the attrs above (ducktype), but not __call__. + def __init__(self, context: "make_scanner") -> None: ... + def __call__(self, string: str, index: int) -> Tuple[Any, int]: ... + +def encode_basestring_ascii(s: str) -> str: ... +def scanstring(string: str, end: int, strict: bool = ...) -> Tuple[str, int]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_markupbase.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_markupbase.pyi new file mode 100644 index 000000000..58d107052 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_markupbase.pyi @@ -0,0 +1,9 @@ +from typing import Tuple + +class ParserBase: + def __init__(self) -> None: ... + def error(self, message: str) -> None: ... + def reset(self) -> None: ... + def getpos(self) -> Tuple[int, int]: ... + + def unkown_decl(self, data: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_operator.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_operator.pyi new file mode 100644 index 000000000..6d08cd7ef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_operator.pyi @@ -0,0 +1,64 @@ +# Stubs for _operator (Python 3.5) + +import sys +from typing import AnyStr + +# In reality the import is the other way around, but this way we can keep the operator stub in 2and3 +from operator import ( + truth as truth, + contains as contains, + indexOf as indexOf, + countOf as countOf, + is_ as is_, + is_not as is_not, + index as index, + add as add, + sub as sub, + mul as mul, + floordiv as floordiv, + truediv as truediv, + mod as mod, + neg as neg, + pos as pos, + abs as abs, + inv as inv, + invert as invert, + length_hint as length_hint, + lshift as lshift, + rshift as rshift, + not_ as not_, + and_ as and_, + xor as xor, + or_ as or_, + iadd as iadd, + isub as isub, + imul as imul, + ifloordiv as ifloordiv, + itruediv as itruediv, + imod as imod, + ilshift as ilshift, + irshift as irshift, + iand as iand, + ixor as ixor, + ior as ior, + concat as concat, + iconcat as iconcat, + getitem as getitem, + setitem as setitem, + delitem as delitem, + pow as pow, + ipow as ipow, + eq as eq, + ne as ne, + lt as lt, + le as le, + gt as gt, + ge as ge, + itemgetter as itemgetter, + attrgetter as attrgetter, + methodcaller as methodcaller, +) +if sys.version_info >= (3, 5): + from operator import matmul as matmul, imatmul as imatmul + +def _compare_digest(a: AnyStr, b: AnyStr) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_posixsubprocess.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_posixsubprocess.pyi new file mode 100644 index 000000000..67b7d7cc5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_posixsubprocess.pyi @@ -0,0 +1,14 @@ +# Stubs for _posixsubprocess + +# NOTE: These are incomplete! + +from typing import Tuple, Sequence, Callable + +def cloexec_pipe() -> Tuple[int, int]: ... +def fork_exec(args: Sequence[str], + executable_list: Sequence[bytes], close_fds: bool, fds_to_keep: Sequence[int], + cwd: str, env_list: Sequence[bytes], + p2cread: int, p2cwrite: int, c2pred: int, c2pwrite: int, + errread: int, errwrite: int, errpipe_read: int, + errpipe_write: int, restore_signals: int, start_new_session: int, + preexec_fn: Callable[[], None]) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_subprocess.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_subprocess.pyi new file mode 100644 index 000000000..76967b94b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_subprocess.pyi @@ -0,0 +1,38 @@ +# Stubs for _subprocess + +# NOTE: These are incomplete! + +from typing import Mapping, Any, Tuple + +CREATE_NEW_CONSOLE = 0 +CREATE_NEW_PROCESS_GROUP = 0 +STD_INPUT_HANDLE = 0 +STD_OUTPUT_HANDLE = 0 +STD_ERROR_HANDLE = 0 +SW_HIDE = 0 +STARTF_USESTDHANDLES = 0 +STARTF_USESHOWWINDOW = 0 +INFINITE = 0 +DUPLICATE_SAME_ACCESS = 0 +WAIT_OBJECT_0 = 0 + +# TODO not exported by the Python module +class Handle: + def Close(self) -> None: ... + +def GetVersion() -> int: ... +def GetExitCodeProcess(handle: Handle) -> int: ... +def WaitForSingleObject(handle: Handle, timeout: int) -> int: ... +def CreateProcess(executable: str, cmd_line: str, + proc_attrs, thread_attrs, + inherit: int, flags: int, + env_mapping: Mapping[str, str], + curdir: str, + startupinfo: Any) -> Tuple[Any, Handle, int, int]: ... +def GetModuleFileName(module: int) -> str: ... +def GetCurrentProcess() -> Handle: ... +def DuplicateHandle(source_proc: Handle, source: Handle, target_proc: Handle, + target: Any, access: int, inherit: int) -> int: ... +def CreatePipe(pipe_attrs, size: int) -> Tuple[Handle, Handle]: ... +def GetStdHandle(arg: int) -> int: ... +def TerminateProcess(handle: Handle, exit_code: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_thread.pyi new file mode 100644 index 000000000..a8e38a91a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_thread.pyi @@ -0,0 +1,15 @@ +# Stubs for _thread + +# NOTE: These are incomplete! + +from typing import Any + +def _count() -> int: ... +_dangling = ... # type: Any + +class LockType: + def acquire(self) -> None: ... + def release(self) -> None: ... + +def allocate_lock() -> LockType: ... +def get_ident() -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_threading_local.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_threading_local.pyi new file mode 100644 index 000000000..a286d2dd5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_threading_local.pyi @@ -0,0 +1,18 @@ +# Source: https://github.com/python/cpython/blob/master/Lib/_threading_local.py +from typing import Any, Dict, List, Tuple +from weakref import ReferenceType + +__all__: List[str] +localdict = Dict[Any, Any] + +class _localimpl: + key: str + dicts: Dict[int, Tuple[ReferenceType, localdict]] + def __init__(self) -> None: ... + def get_dict(self) -> localdict: ... + def create_dict(self) -> localdict: ... + +class local: + def __getattribute__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __delattr__(self, name: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_warnings.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_warnings.pyi new file mode 100644 index 000000000..4d890e51c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_warnings.pyi @@ -0,0 +1,11 @@ +from typing import Any, List, Optional, Type + +_defaultaction = ... # type: str +_onceregistry = ... # type: dict +filters = ... # type: List[tuple] + +def warn(message: Warning, category: Optional[Type[Warning]] = ..., stacklevel: int = ...) -> None: ... +def warn_explicit(message: Warning, category: Optional[Type[Warning]], + filename: str, lineno: int, + module: Any = ..., registry: dict = ..., + module_globals: dict = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_winapi.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_winapi.pyi new file mode 100644 index 000000000..3b532c6eb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/_winapi.pyi @@ -0,0 +1,78 @@ +from typing import Any, Union, Tuple, Optional, Dict, NoReturn, Sequence + +CREATE_NEW_CONSOLE: int +CREATE_NEW_PROCESS_GROUP: int +DUPLICATE_CLOSE_SOURCE: int +DUPLICATE_SAME_ACCESS: int +ERROR_ALREADY_EXISTS: int +ERROR_BROKEN_PIPE: int +ERROR_IO_PENDING: int +ERROR_MORE_DATA: int +ERROR_NETNAME_DELETED: int +ERROR_NO_DATA: int +ERROR_NO_SYSTEM_RESOURCES: int +ERROR_OPERATION_ABORTED: int +ERROR_PIPE_BUSY: int +ERROR_PIPE_CONNECTED: int +ERROR_SEM_TIMEOUT: int +FILE_FLAG_FIRST_PIPE_INSTANCE: int +FILE_FLAG_OVERLAPPED: int +FILE_GENERIC_READ: int +FILE_GENERIC_WRITE: int +GENERIC_READ: int +GENERIC_WRITE: int +INFINITE: int +NMPWAIT_WAIT_FOREVER: int +NULL: int +OPEN_EXISTING: int +PIPE_ACCESS_DUPLEX: int +PIPE_ACCESS_INBOUND: int +PIPE_READMODE_MESSAGE: int +PIPE_TYPE_MESSAGE: int +PIPE_UNLIMITED_INSTANCES: int +PIPE_WAIT: int +PROCESS_ALL_ACCESS: int +PROCESS_DUP_HANDLE: int +STARTF_USESHOWWINDOW: int +STARTF_USESTDHANDLES: int +STD_ERROR_HANDLE: int +STD_INPUT_HANDLE: int +STD_OUTPUT_HANDLE: int +STILL_ACTIVE: int +SW_HIDE: int +WAIT_ABANDONED_0: int +WAIT_OBJECT_0: int +WAIT_TIMEOUT: int + +def CloseHandle(handle: int) -> None: ... +def ConnectNamedPipe(handle: int, overlapped: Union[int, bool] = ...) -> None: ... +def CreateFile(file_name: str, desired_access: int, share_mode: int, security_attributes: int, creation_disposition: int, flags_and_attributes: int, template_file: int) -> int: ... +def CreateJunction(src_path: str, dest_path: str) -> None: ... +def CreateNamedPipe(name: str, open_mode: int, pipe_mode: int, max_instances: int, out_buffer_size: int, in_buffer_size: int, default_timeout: int, security_attributes: int) -> int: ... +def CreatePipe(pipe_attrs: Any, size: int) -> Tuple[int, int]: ... +def CreateProcess(application_name: Optional[str], command_line: Optional[str], proc_attrs: Any, thread_attrs: Any, inherit_handles: bool, creation_flags: int, env_mapping: Dict[str, str], cwd: Optional[str], startup_info: Any) -> Tuple[int, int, int, int]: ... +def DuplicateHandle(source_process_handle: int, source_handle: int, target_process_handle: int, desired_access: int, inherit_handle: bool, options: int = ...) -> int: ... +def ExitProcess(ExitCode: int) -> NoReturn: ... +def GetACP() -> int: ... +def GetFileType(handle: int) -> int: ... +def GetCurrentProcess() -> int: ... +def GetExitCodeProcess(process: int) -> int: ... +def GetLastError() -> int: ... +def GetModuleFileName(module_handle: int) -> str: ... +def GetStdHandle(std_handle: int) -> int: ... +def GetVersion() -> int: ... +def OpenProcess(desired_access: int, inherit_handle: bool, process_id: int) -> int: ... +def PeekNamedPipe(handle: int, size: int = ...) -> Union[Tuple[int, int], Tuple[bytes, int, int]]: ... +def ReadFile(handle: int, size: int, overlapped: Union[int, bool] = ...) -> Tuple[bytes, int]: ... +def SetNamedPipeHandleState(named_pipe: int, mode: int, max_collection_count: int, collect_data_timeout: int) -> None: ... +def TerminateProcess(handle: int, exit_code: int) -> None: ... +def WaitForMultipleObjects(handle_seq: Sequence[int], wait_flag: bool, milliseconds: int = ...) -> int: ... +def WaitForSingleObject(handle: int, milliseconds: int) -> int: ... +def WaitNamedPipe(name: str, timeout: int) -> None: ... +def WriteFile(handle: int, buffer: bytes, overlapped: Union[int, bool] = ...): ... + +class Overlapped: + event: int = ... + def GetOverlappedResult(self, wait: bool) -> Tuple[int, int]: ... + def cancel(self) -> None: ... + def getbuffer(self) -> Optional[bytes]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/abc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/abc.pyi new file mode 100644 index 000000000..9a442f292 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/abc.pyi @@ -0,0 +1,19 @@ +from typing import Any, Callable, Type, TypeVar +# Stubs for abc. + +_T = TypeVar('_T') +_FuncT = TypeVar('_FuncT', bound=Callable[..., Any]) + +# Thesee definitions have special processing in mypy +class ABCMeta(type): + def register(cls: "ABCMeta", subclass: Type[_T]) -> Type[_T]: ... + +def abstractmethod(callable: _FuncT) -> _FuncT: ... +class abstractproperty(property): ... +# These two are deprecated and not supported by mypy +def abstractstaticmethod(callable: _FuncT) -> _FuncT: ... +def abstractclassmethod(callable: _FuncT) -> _FuncT: ... + +class ABC(metaclass=ABCMeta): ... + +def get_cache_token() -> object: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/ast.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/ast.pyi new file mode 100644 index 000000000..241f874f1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/ast.pyi @@ -0,0 +1,26 @@ +# Python 3.5 ast + +import typing +from typing import Any, Union, Iterator + +from _ast import * + +class NodeVisitor(): + def visit(self, node: AST) -> Any: ... + def generic_visit(self, node: AST) -> None: ... + +class NodeTransformer(NodeVisitor): + def generic_visit(self, node: AST) -> None: ... + +def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> Module: ... +def copy_location(new_node: AST, old_node: AST) -> AST: ... +def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ... +def fix_missing_locations(node: AST) -> AST: ... +def get_docstring(node: AST, clean: bool = ...) -> str: ... +def increment_lineno(node: AST, n: int = ...) -> AST: ... +def iter_child_nodes(node: AST) -> Iterator[AST]: ... +def iter_fields(node: AST) -> Iterator[typing.Tuple[str, Any]]: ... +def literal_eval(node_or_string: Union[str, AST]) -> Any: ... +def walk(node: AST) -> Iterator[AST]: ... + +PyCF_ONLY_AST = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/atexit.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/atexit.pyi new file mode 100644 index 000000000..24f93899d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/atexit.pyi @@ -0,0 +1,9 @@ +"""Stub file for the 'atexit' module.""" + +from typing import Any, Callable + +def _clear() -> None: ... +def _ncallbacks() -> int: ... +def _run_exitfuncs() -> None: ... +def register(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Callable[..., Any]: ... +def unregister(func: Callable[..., Any]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/builtins.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/builtins.pyi new file mode 100644 index 000000000..9e1c74f73 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/builtins.pyi @@ -0,0 +1,1046 @@ +# Stubs for builtins (Python 3) + +from typing import ( + TypeVar, Iterator, Iterable, overload, Container, + Sequence, MutableSequence, Mapping, MutableMapping, NoReturn, Tuple, List, Any, Dict, Callable, Generic, + Set, AbstractSet, FrozenSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, + SupportsComplex, SupportsBytes, SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, + ValuesView, ByteString, Optional, AnyStr, Type, +) +from abc import abstractmethod, ABCMeta +from types import TracebackType, CodeType +import sys + +# Note that names imported above are not automatically made visible via the +# implicit builtins import. + +_T = TypeVar('_T') +_T_co = TypeVar('_T_co', covariant=True) +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') +_S = TypeVar('_S') +_T1 = TypeVar('_T1') +_T2 = TypeVar('_T2') +_T3 = TypeVar('_T3') +_T4 = TypeVar('_T4') +_T5 = TypeVar('_T5') +_TT = TypeVar('_TT', bound='type') + +class object: + __doc__ = ... # type: Optional[str] + __class__ = ... # type: type + __dict__ = ... # type: Dict[str, Any] + __slots__ = ... # type: Union[str, Iterable[str]] + __module__ = ... # type: str + if sys.version_info >= (3, 6): + __annotations__ = ... # type: Dict[str, Any] + + def __init__(self) -> None: ... + def __new__(cls) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __eq__(self, o: object) -> bool: ... + def __ne__(self, o: object) -> bool: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __hash__(self) -> int: ... + def __format__(self, format_spec: str) -> str: ... + def __getattribute__(self, name: str) -> Any: ... + def __delattr__(self, name: str) -> None: ... + def __sizeof__(self) -> int: ... + def __reduce__(self) -> tuple: ... + def __reduce_ex__(self, protocol: int) -> tuple: ... + def __dir__(self) -> Iterable[str]: ... + + if sys.version_info >= (3, 6): + def __init_subclass__(cls) -> None: ... + +class staticmethod: # Special, only valid as a decorator. + __func__ = ... # type: function + __isabstractmethod__ = ... # type: bool + + def __init__(self, f: function) -> None: ... + def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... + +class classmethod: # Special, only valid as a decorator. + __func__ = ... # type: function + __isabstractmethod__ = ... # type: bool + + def __init__(self, f: function) -> None: ... + def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _T, type: Optional[Type[_T]]=...) -> function: ... + +class type: + __bases__ = ... # type: Tuple[type, ...] + __name__ = ... # type: str + __qualname__ = ... # type: str + __module__ = ... # type: str + __dict__ = ... # type: Dict[str, Any] + __mro__ = ... # type: Tuple[type, ...] + + @overload + def __init__(self, o: object) -> None: ... + @overload + def __init__(self, name: str, bases: Tuple[type, ...], dict: Dict[str, Any]) -> None: ... + @overload + def __new__(cls, o: object) -> type: ... + @overload + def __new__(cls, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> type: ... + def __call__(self, *args: Any, **kwds: Any) -> Any: ... + def __subclasses__(self: _TT) -> List[_TT]: ... + # Note: the documentation doesnt specify what the return type is, the standard + # implementation seems to be returning a list. + def mro(self) -> List[type]: ... + def __instancecheck__(self, instance: Any) -> bool: ... + def __subclasscheck__(self, subclass: type) -> bool: ... + +class super: + @overload + def __init__(self, t: Any, obj: Any) -> None: ... + @overload + def __init__(self, t: Any) -> None: ... + @overload + def __init__(self) -> None: ... + +class int: + @overload + def __init__(self, x: Union[str, bytes, SupportsInt] = ...) -> None: ... + @overload + def __init__(self, x: Union[str, bytes], base: int) -> None: ... + + def bit_length(self) -> int: ... + def to_bytes(self, length: int, byteorder: str, *, signed: bool = ...) -> bytes: ... + @classmethod + def from_bytes(cls, bytes: Sequence[int], byteorder: str, *, + signed: bool = ...) -> int: ... # TODO buffer object argument + + def __add__(self, x: int) -> int: ... + def __sub__(self, x: int) -> int: ... + def __mul__(self, x: int) -> int: ... + def __floordiv__(self, x: int) -> int: ... + def __truediv__(self, x: int) -> float: ... + def __mod__(self, x: int) -> int: ... + def __divmod__(self, x: int) -> Tuple[int, int]: ... + def __radd__(self, x: int) -> int: ... + def __rsub__(self, x: int) -> int: ... + def __rmul__(self, x: int) -> int: ... + def __rfloordiv__(self, x: int) -> int: ... + def __rtruediv__(self, x: int) -> float: ... + def __rmod__(self, x: int) -> int: ... + def __rdivmod__(self, x: int) -> Tuple[int, int]: ... + def __pow__(self, x: int) -> Any: ... # Return type can be int or float, depending on x. + def __rpow__(self, x: int) -> Any: ... + def __and__(self, n: int) -> int: ... + def __or__(self, n: int) -> int: ... + def __xor__(self, n: int) -> int: ... + def __lshift__(self, n: int) -> int: ... + def __rshift__(self, n: int) -> int: ... + def __rand__(self, n: int) -> int: ... + def __ror__(self, n: int) -> int: ... + def __rxor__(self, n: int) -> int: ... + def __rlshift__(self, n: int) -> int: ... + def __rrshift__(self, n: int) -> int: ... + def __neg__(self) -> int: ... + def __pos__(self) -> int: ... + def __invert__(self) -> int: ... + def __round__(self, ndigits: Optional[int] = ...) -> int: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: int) -> bool: ... + def __le__(self, x: int) -> bool: ... + def __gt__(self, x: int) -> bool: ... + def __ge__(self, x: int) -> bool: ... + + def __str__(self) -> str: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + def __abs__(self) -> int: ... + def __hash__(self) -> int: ... + def __bool__(self) -> bool: ... + +class float: + def __init__(self, x: Union[SupportsFloat, str, bytes] = ...) -> None: ... + def as_integer_ratio(self) -> Tuple[int, int]: ... + def hex(self) -> str: ... + def is_integer(self) -> bool: ... + @classmethod + def fromhex(cls, s: str) -> float: ... + + def __add__(self, x: float) -> float: ... + def __sub__(self, x: float) -> float: ... + def __mul__(self, x: float) -> float: ... + def __floordiv__(self, x: float) -> float: ... + def __truediv__(self, x: float) -> float: ... + def __mod__(self, x: float) -> float: ... + def __divmod__(self, x: float) -> Tuple[float, float]: ... + def __pow__(self, x: float) -> float: ... + def __radd__(self, x: float) -> float: ... + def __rsub__(self, x: float) -> float: ... + def __rmul__(self, x: float) -> float: ... + def __rfloordiv__(self, x: float) -> float: ... + def __rtruediv__(self, x: float) -> float: ... + def __rmod__(self, x: float) -> float: ... + def __rdivmod__(self, x: float) -> Tuple[float, float]: ... + def __rpow__(self, x: float) -> float: ... + @overload + def __round__(self) -> int: ... + @overload + def __round__(self, ndigits: None) -> int: ... + @overload + def __round__(self, ndigits: int) -> float: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: float) -> bool: ... + def __le__(self, x: float) -> bool: ... + def __gt__(self, x: float) -> bool: ... + def __ge__(self, x: float) -> bool: ... + def __neg__(self) -> float: ... + def __pos__(self) -> float: ... + + def __str__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __abs__(self) -> float: ... + def __hash__(self) -> int: ... + def __bool__(self) -> bool: ... + +class complex: + @overload + def __init__(self, re: float = ..., im: float = ...) -> None: ... + @overload + def __init__(self, s: str) -> None: ... + @overload + def __init__(self, s: SupportsComplex) -> None: ... + + @property + def real(self) -> float: ... + @property + def imag(self) -> float: ... + + def conjugate(self) -> complex: ... + + def __add__(self, x: complex) -> complex: ... + def __sub__(self, x: complex) -> complex: ... + def __mul__(self, x: complex) -> complex: ... + def __pow__(self, x: complex) -> complex: ... + def __truediv__(self, x: complex) -> complex: ... + def __radd__(self, x: complex) -> complex: ... + def __rsub__(self, x: complex) -> complex: ... + def __rmul__(self, x: complex) -> complex: ... + def __rpow__(self, x: complex) -> complex: ... + def __rtruediv__(self, x: complex) -> complex: ... + + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __neg__(self) -> complex: ... + def __pos__(self) -> complex: ... + + def __str__(self) -> str: ... + def __complex__(self) -> complex: ... + def __abs__(self) -> float: ... + def __hash__(self) -> int: ... + def __bool__(self) -> bool: ... + +class str(Sequence[str]): + @overload + def __init__(self, o: object = ...) -> None: ... + @overload + def __init__(self, o: bytes, encoding: str = ..., errors: str = ...) -> None: ... + + def capitalize(self) -> str: ... + def casefold(self) -> str: ... + def center(self, width: int, fillchar: str = ...) -> str: ... + def count(self, x: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def encode(self, encoding: str = ..., errors: str = ...) -> bytes: ... + def endswith(self, suffix: Union[str, Tuple[str, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> str: ... + def find(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def format(self, *args: Any, **kwargs: Any) -> str: ... + def format_map(self, map: Mapping[str, Any]) -> str: ... + def index(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[str]) -> str: ... + def ljust(self, width: int, fillchar: str = ...) -> str: ... + def lower(self) -> str: ... + def lstrip(self, chars: Optional[str] = ...) -> str: ... + def partition(self, sep: str) -> Tuple[str, str, str]: ... + def replace(self, old: str, new: str, count: int = ...) -> str: ... + def rfind(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rindex(self, sub: str, __start: Optional[int] = ..., __end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: str = ...) -> str: ... + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def rstrip(self, chars: Optional[str] = ...) -> str: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def splitlines(self, keepends: bool = ...) -> List[str]: ... + def startswith(self, prefix: Union[str, Tuple[str, ...]], start: Optional[int] = ..., + end: Optional[int] = ...) -> bool: ... + def strip(self, chars: Optional[str] = ...) -> str: ... + def swapcase(self) -> str: ... + def title(self) -> str: ... + def translate(self, table: Union[Mapping[int, Union[int, str, None]], Sequence[Union[int, str, None]]]) -> str: ... + def upper(self) -> str: ... + def zfill(self, width: int) -> str: ... + @staticmethod + @overload + def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... + @staticmethod + @overload + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... + + def __getitem__(self, i: Union[int, slice]) -> str: ... + def __add__(self, s: str) -> str: ... + def __mul__(self, n: int) -> str: ... + def __rmul__(self, n: int) -> str: ... + def __mod__(self, value: Any) -> str: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: str) -> bool: ... + def __le__(self, x: str) -> bool: ... + def __gt__(self, x: str) -> bool: ... + def __ge__(self, x: str) -> bool: ... + + def __len__(self) -> int: ... + def __contains__(self, s: object) -> bool: ... + def __iter__(self) -> Iterator[str]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __hash__(self) -> int: ... + +class bytes(ByteString): + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str, encoding: str, + errors: str = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, o: SupportsBytes) -> None: ... + def capitalize(self) -> bytes: ... + def center(self, width: int, fillchar: bytes = ...) -> bytes: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def decode(self, encoding: str = ..., errors: str = ...) -> str: ... + def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytes: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def lower(self) -> bytes: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytes: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ... + def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytes: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytes]: ... + def splitlines(self, keepends: bool = ...) -> List[bytes]: ... + def startswith(self, prefix: Union[bytes, Tuple[bytes, ...]]) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytes: ... + def swapcase(self) -> bytes: ... + def title(self) -> bytes: ... + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytes: ... + def upper(self) -> bytes: ... + def zfill(self, width: int) -> bytes: ... + @classmethod + def fromhex(cls, s: str) -> bytes: ... + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytes: ... + def __add__(self, s: bytes) -> bytes: ... + def __mul__(self, n: int) -> bytes: ... + def __rmul__(self, n: int) -> bytes: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... + +class bytearray(MutableSequence[int], ByteString): + @overload + def __init__(self, ints: Iterable[int]) -> None: ... + @overload + def __init__(self, string: str, encoding: str, errors: str = ...) -> None: ... + @overload + def __init__(self, length: int) -> None: ... + @overload + def __init__(self) -> None: ... + def capitalize(self) -> bytearray: ... + def center(self, width: int, fillchar: bytes = ...) -> bytearray: ... + def count(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def copy(self) -> bytearray: ... + def decode(self, encoding: str = ..., errors: str = ...) -> str: ... + def endswith(self, suffix: bytes) -> bool: ... + def expandtabs(self, tabsize: int = ...) -> bytearray: ... + def find(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + def index(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def insert(self, index: int, object: int) -> None: ... + def isalnum(self) -> bool: ... + def isalpha(self) -> bool: ... + def isdigit(self) -> bool: ... + def islower(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... + def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + def lower(self) -> bytearray: ... + def lstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... + def replace(self, old: bytes, new: bytes, count: int = ...) -> bytearray: ... + def rfind(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rindex(self, sub: Union[bytes, int], start: Optional[int] = ..., end: Optional[int] = ...) -> int: ... + def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ... + def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ... + def rsplit(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def rstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def split(self, sep: Optional[bytes] = ..., maxsplit: int = ...) -> List[bytearray]: ... + def splitlines(self, keepends: bool = ...) -> List[bytearray]: ... + def startswith(self, prefix: bytes) -> bool: ... + def strip(self, chars: Optional[bytes] = ...) -> bytearray: ... + def swapcase(self) -> bytearray: ... + def title(self) -> bytearray: ... + def translate(self, table: Optional[bytes], delete: bytes = ...) -> bytearray: ... + def upper(self) -> bytearray: ... + def zfill(self, width: int) -> bytearray: ... + @classmethod + def fromhex(cls, s: str) -> bytearray: ... + @classmethod + def maketrans(cls, frm: bytes, to: bytes) -> bytes: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[int]: ... + def __str__(self) -> str: ... + def __repr__(self) -> str: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> bytearray: ... + @overload + def __setitem__(self, i: int, x: int) -> None: ... + @overload + def __setitem__(self, s: slice, x: Union[Iterable[int], bytes]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __add__(self, s: bytes) -> bytearray: ... + def __iadd__(self, s: Iterable[int]) -> bytearray: ... + def __mul__(self, n: int) -> bytearray: ... + def __rmul__(self, n: int) -> bytearray: ... + def __imul__(self, n: int) -> bytearray: ... + if sys.version_info >= (3, 5): + def __mod__(self, value: Any) -> bytes: ... + def __contains__(self, o: object) -> bool: ... + def __eq__(self, x: object) -> bool: ... + def __ne__(self, x: object) -> bool: ... + def __lt__(self, x: bytes) -> bool: ... + def __le__(self, x: bytes) -> bool: ... + def __gt__(self, x: bytes) -> bool: ... + def __ge__(self, x: bytes) -> bool: ... + +class memoryview(Sized, Container[int]): + format = ... # type: str + itemsize = ... # type: int + shape = ... # type: Optional[Tuple[int, ...]] + strides = ... # type: Optional[Tuple[int, ...]] + suboffsets = ... # type: Optional[Tuple[int, ...]] + readonly = ... # type: bool + ndim = ... # type: int + + def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... + + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> memoryview: ... + + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[int]: ... + def __len__(self) -> int: ... + + @overload + def __setitem__(self, i: int, o: bytes) -> None: ... + @overload + def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ... + @overload + def __setitem__(self, s: slice, o: memoryview) -> None: ... + + def tobytes(self) -> bytes: ... + def tolist(self) -> List[int]: ... + + if sys.version_info >= (3, 5): + def hex(self) -> str: ... + +class bool(int): + def __init__(self, o: object = ...) -> None: ... + @overload # type: ignore + def __and__(self, x: bool) -> bool: ... + @overload # type: ignore + def __and__(self, x: int) -> int: ... + @overload # type: ignore + def __or__(self, x: bool) -> bool: ... + @overload # type: ignore + def __or__(self, x: int) -> int: ... + @overload # type: ignore + def __xor__(self, x: bool) -> bool: ... + @overload # type: ignore + def __xor__(self, x: int) -> int: ... + @overload # type: ignore + def __rand__(self, x: bool) -> bool: ... + @overload # type: ignore + def __rand__(self, x: int) -> int: ... + @overload # type: ignore + def __ror__(self, x: bool) -> bool: ... + @overload # type: ignore + def __ror__(self, x: int) -> int: ... + @overload # type: ignore + def __rxor__(self, x: bool) -> bool: ... + @overload # type: ignore + def __rxor__(self, x: int) -> int: ... + +class slice: + start = ... # type: Optional[int] + step = ... # type: Optional[int] + stop = ... # type: Optional[int] + @overload + def __init__(self, stop: Optional[int]) -> None: ... + @overload + def __init__(self, start: Optional[int], stop: Optional[int], step: Optional[int] = ...) -> None: ... + def indices(self, len: int) -> Tuple[int, int, int]: ... + +class tuple(Sequence[_T_co], Generic[_T_co]): + def __new__(cls: Type[_T], iterable: Iterable[_T_co] = ...) -> _T: ... + def __init__(self, iterable: Iterable[_T_co] = ...) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, x: object) -> bool: ... + @overload + def __getitem__(self, x: int) -> _T_co: ... + @overload + def __getitem__(self, x: slice) -> Tuple[_T_co, ...]: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __lt__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __le__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __gt__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __ge__(self, x: Tuple[_T_co, ...]) -> bool: ... + def __add__(self, x: Tuple[_T_co, ...]) -> Tuple[_T_co, ...]: ... + def __mul__(self, n: int) -> Tuple[_T_co, ...]: ... + def __rmul__(self, n: int) -> Tuple[_T_co, ...]: ... + def count(self, x: Any) -> int: ... + if sys.version_info >= (3, 5): + def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... + else: + def index(self, x: Any) -> int: ... + +class function: + # TODO not defined in builtins! + __name__ = ... # type: str + __qualname__ = ... # type: str + __module__ = ... # type: str + __code__ = ... # type: CodeType + __annotations__ = ... # type: Dict[str, Any] + +class list(MutableSequence[_T], Generic[_T]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def clear(self) -> None: ... + def copy(self) -> List[_T]: ... + def append(self, object: _T) -> None: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def pop(self, index: int = ...) -> _T: ... + def index(self, object: _T, start: int = ..., stop: int = ...) -> int: ... + def count(self, object: _T) -> int: ... + def insert(self, index: int, object: _T) -> None: ... + def remove(self, object: _T) -> None: ... + def reverse(self) -> None: ... + def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __hash__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> _T: ... + @overload + def __getitem__(self, s: slice) -> List[_T]: ... + @overload + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __add__(self, x: List[_T]) -> List[_T]: ... + def __iadd__(self, x: Iterable[_T]) -> List[_T]: ... + def __mul__(self, n: int) -> List[_T]: ... + def __rmul__(self, n: int) -> List[_T]: ... + def __imul__(self, n: int) -> List[_T]: ... + def __contains__(self, o: object) -> bool: ... + def __reversed__(self) -> Iterator[_T]: ... + def __gt__(self, x: List[_T]) -> bool: ... + def __ge__(self, x: List[_T]) -> bool: ... + def __lt__(self, x: List[_T]) -> bool: ... + def __le__(self, x: List[_T]) -> bool: ... + +class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]): + # NOTE: Keyword arguments are special. If they are used, _KT must include + # str, but we have no way of enforcing it here. + @overload + def __init__(self, **kwargs: _VT) -> None: ... + @overload + def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def __init__(self, iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + + def __new__(cls: Type[_T1], *args: Any, **kwargs: Any) -> _T1: ... + + def clear(self) -> None: ... + def copy(self) -> Dict[_KT, _VT]: ... + def popitem(self) -> Tuple[_KT, _VT]: ... + def setdefault(self, k: _KT, default: Optional[_VT] = ...) -> _VT: ... + @overload + def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + @overload + def update(self, **kwargs: _VT) -> None: ... + def keys(self) -> KeysView[_KT]: ... + def values(self) -> ValuesView[_VT]: ... + def items(self) -> ItemsView[_KT, _VT]: ... + @staticmethod + @overload + def fromkeys(seq: Iterable[_T]) -> Dict[_T, Any]: ... # TODO: Actually a class method (mypy/issues#328) + @staticmethod + @overload + def fromkeys(seq: Iterable[_T], value: _S) -> Dict[_T, _S]: ... + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + +class set(MutableSet[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T] = ...) -> None: ... + def add(self, element: _T) -> None: ... + def clear(self) -> None: ... + def copy(self) -> Set[_T]: ... + def difference(self, *s: Iterable[object]) -> Set[_T]: ... + def difference_update(self, *s: Iterable[object]) -> None: ... + def discard(self, element: _T) -> None: ... + def intersection(self, *s: Iterable[object]) -> Set[_T]: ... + def intersection_update(self, *s: Iterable[Any]) -> None: ... + def isdisjoint(self, s: Iterable[Any]) -> bool: ... + def issubset(self, s: Iterable[Any]) -> bool: ... + def issuperset(self, s: Iterable[Any]) -> bool: ... + def pop(self) -> _T: ... + def remove(self, element: _T) -> None: ... + def symmetric_difference(self, s: Iterable[_T]) -> Set[_T]: ... + def symmetric_difference_update(self, s: Iterable[_T]) -> None: ... + def union(self, *s: Iterable[_T]) -> Set[_T]: ... + def update(self, *s: Iterable[_T]) -> None: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __and__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __iand__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __or__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __ior__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __sub__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __isub__(self, s: AbstractSet[object]) -> Set[_T]: ... + def __xor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __ixor__(self, s: AbstractSet[_S]) -> Set[Union[_T, _S]]: ... + def __le__(self, s: AbstractSet[object]) -> bool: ... + def __lt__(self, s: AbstractSet[object]) -> bool: ... + def __ge__(self, s: AbstractSet[object]) -> bool: ... + def __gt__(self, s: AbstractSet[object]) -> bool: ... + +class frozenset(AbstractSet[_T], Generic[_T]): + def __init__(self, iterable: Iterable[_T] = ...) -> None: ... + def copy(self) -> FrozenSet[_T]: ... + def difference(self, *s: Iterable[object]) -> FrozenSet[_T]: ... + def intersection(self, *s: Iterable[object]) -> FrozenSet[_T]: ... + def isdisjoint(self, s: Iterable[_T]) -> bool: ... + def issubset(self, s: Iterable[object]) -> bool: ... + def issuperset(self, s: Iterable[object]) -> bool: ... + def symmetric_difference(self, s: Iterable[_T]) -> FrozenSet[_T]: ... + def union(self, *s: Iterable[_T]) -> FrozenSet[_T]: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __and__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... + def __or__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... + def __sub__(self, s: AbstractSet[_T]) -> FrozenSet[_T]: ... + def __xor__(self, s: AbstractSet[_S]) -> FrozenSet[Union[_T, _S]]: ... + def __le__(self, s: AbstractSet[object]) -> bool: ... + def __lt__(self, s: AbstractSet[object]) -> bool: ... + def __ge__(self, s: AbstractSet[object]) -> bool: ... + def __gt__(self, s: AbstractSet[object]) -> bool: ... + +class enumerate(Iterator[Tuple[int, _T]], Generic[_T]): + def __init__(self, iterable: Iterable[_T], start: int = ...) -> None: ... + def __iter__(self) -> Iterator[Tuple[int, _T]]: ... + def __next__(self) -> Tuple[int, _T]: ... + +class range(Sequence[int]): + start = ... # type: int + stop = ... # type: int + step = ... # type: int + @overload + def __init__(self, stop: int) -> None: ... + @overload + def __init__(self, start: int, stop: int, step: int = ...) -> None: ... + def count(self, value: int) -> int: ... + def index(self, value: int, start: int = ..., stop: Optional[int] = ...) -> int: ... + def __len__(self) -> int: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[int]: ... + @overload + def __getitem__(self, i: int) -> int: ... + @overload + def __getitem__(self, s: slice) -> range: ... + def __repr__(self) -> str: ... + def __reversed__(self) -> Iterator[int]: ... + +class property: + def __init__(self, fget: Optional[Callable[[Any], Any]] = ..., + fset: Optional[Callable[[Any, Any], None]] = ..., + fdel: Optional[Callable[[Any], None]] = ..., + doc: Optional[str] = ...) -> None: ... + def getter(self, fget: Callable[[Any], Any]) -> property: ... + def setter(self, fset: Callable[[Any, Any], None]) -> property: ... + def deleter(self, fdel: Callable[[Any], None]) -> property: ... + def __get__(self, obj: Any, type: Optional[type] = ...) -> Any: ... + def __set__(self, obj: Any, value: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... + def fget(self) -> Any: ... + def fset(self, value: Any) -> None: ... + def fdel(self) -> None: ... + +NotImplemented = ... # type: Any + +def abs(n: SupportsAbs[_T]) -> _T: ... +def all(i: Iterable[object]) -> bool: ... +def any(i: Iterable[object]) -> bool: ... +def ascii(o: object) -> str: ... +def bin(number: int) -> str: ... +if sys.version_info >= (3, 7): + def breakpoint(*args: Any, **kws: Any) -> None: ... +def callable(o: object) -> bool: ... +def chr(code: int) -> str: ... +if sys.version_info >= (3, 6): + # This class is to be exported as PathLike from os, + # but we define it here as _PathLike to avoid import cycle issues. + # See https://github.com/python/typeshed/pull/991#issuecomment-288160993 + class _PathLike(Generic[AnyStr]): + def __fspath__(self) -> AnyStr: ... + def compile(source: Any, filename: Union[str, bytes, _PathLike], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... +else: + def compile(source: Any, filename: Union[str, bytes], mode: str, flags: int = ..., dont_inherit: int = ...) -> CodeType: ... +def copyright() -> None: ... +def credits() -> None: ... +def delattr(o: Any, name: str) -> None: ... +def dir(o: object = ...) -> List[str]: ... +_N = TypeVar('_N', int, float) +def divmod(a: _N, b: _N) -> Tuple[_N, _N]: ... +def eval(source: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +def exec(object: Union[str, bytes, CodeType], globals: Optional[Dict[str, Any]] = ..., locals: Optional[Mapping[str, Any]] = ...) -> Any: ... +def exit(code: Any = ...) -> NoReturn: ... +@overload +def filter(function: None, iterable: Iterable[Optional[_T]]) -> Iterator[_T]: ... +@overload +def filter(function: Callable[[_T], Any], iterable: Iterable[_T]) -> Iterator[_T]: ... +def format(o: object, format_spec: str = ...) -> str: ... +def getattr(o: Any, name: str, default: Any = ...) -> Any: ... +def globals() -> Dict[str, Any]: ... +def hasattr(o: Any, name: str) -> bool: ... +def hash(o: object) -> int: ... +def help(*args: Any, **kwds: Any) -> None: ... +def hex(i: int) -> str: ... # TODO __index__ +def id(o: object) -> int: ... +def input(prompt: Optional[Any] = ...) -> str: ... +@overload +def iter(iterable: Iterable[_T]) -> Iterator[_T]: ... +@overload +def iter(function: Callable[[], _T], sentinel: _T) -> Iterator[_T]: ... +def isinstance(o: object, t: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def issubclass(cls: type, classinfo: Union[type, Tuple[Union[type, Tuple], ...]]) -> bool: ... +def len(o: Sized) -> int: ... +def license() -> None: ... +def locals() -> Dict[str, Any]: ... +@overload +def map(func: Callable[[_T1], _S], iter1: Iterable[_T1]) -> Iterator[_S]: ... +@overload +def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3, _T4], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[_S]: ... +@overload +def map(func: Callable[[_T1, _T2, _T3, _T4, _T5], _S], + iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[_S]: ... +@overload +def map(func: Callable[..., _S], + iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[_S]: ... +@overload +def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +@overload +def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ... +@overload +def min(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default: _T = ...) -> _T: ... +@overload +def next(i: Iterator[_T]) -> _T: ... +@overload +def next(i: Iterator[_T], default: _VT) -> Union[_T, _VT]: ... +def oct(i: int) -> str: ... # TODO __index__ + +if sys.version_info >= (3, 6): + def open(file: Union[str, bytes, int, _PathLike], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... +else: + def open(file: Union[str, bytes, int], mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., closefd: bool = ...) -> IO[Any]: ... + +def ord(c: Union[str, bytes, bytearray]) -> int: ... +def print(*values: Any, sep: str = ..., end: str = ..., file: Optional[IO[str]] = ..., flush: bool = ...) -> None: ... +@overload +def pow(x: int, y: int) -> Any: ... # The return type can be int or float, depending on y +@overload +def pow(x: int, y: int, z: int) -> Any: ... +@overload +def pow(x: float, y: float) -> float: ... +@overload +def pow(x: float, y: float, z: float) -> float: ... +def quit(code: Optional[int] = ...) -> None: ... +@overload +def reversed(object: Sequence[_T]) -> Iterator[_T]: ... +@overload +def reversed(object: Reversible[_T]) -> Iterator[_T]: ... +def repr(o: object) -> str: ... +@overload +def round(number: float) -> int: ... +@overload +def round(number: float, ndigits: None) -> int: ... +@overload +def round(number: float, ndigits: int) -> float: ... +@overload +def round(number: SupportsRound[_T]) -> int: ... +@overload +def round(number: SupportsRound[_T], ndigits: None) -> int: ... # type: ignore +@overload +def round(number: SupportsRound[_T], ndigits: int) -> _T: ... +def setattr(object: Any, name: str, value: Any) -> None: ... +def sorted(iterable: Iterable[_T], *, + key: Optional[Callable[[_T], Any]] = ..., + reverse: bool = ...) -> List[_T]: ... +@overload +def sum(iterable: Iterable[_T]) -> Union[_T, int]: ... +@overload +def sum(iterable: Iterable[_T], start: _S) -> Union[_T, _S]: ... +def vars(object: Any = ...) -> Dict[str, Any]: ... +@overload +def zip(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4]]: ... +@overload +def zip(iter1: Iterable[_T1], iter2: Iterable[_T2], iter3: Iterable[_T3], + iter4: Iterable[_T4], iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, + _T3, _T4, _T5]]: ... +@overload +def zip(iter1: Iterable[Any], iter2: Iterable[Any], iter3: Iterable[Any], + iter4: Iterable[Any], iter5: Iterable[Any], iter6: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +def __import__(name: str, globals: Dict[str, Any] = ..., locals: Dict[str, Any] = ..., + fromlist: List[str] = ..., level: int = ...) -> Any: ... + +# Ellipsis + +# Actually the type of Ellipsis is , but since it's +# not exposed anywhere under that name, we make it private here. +class ellipsis: ... +Ellipsis = ... # type: ellipsis + +# Exceptions + +class BaseException: + args = ... # type: Tuple[Any, ...] + __cause__ = ... # type: Optional[BaseException] + __context__ = ... # type: Optional[BaseException] + __traceback__ = ... # type: Optional[TracebackType] + def __init__(self, *args: object, **kwargs: object) -> None: ... + def with_traceback(self, tb: Optional[TracebackType]) -> BaseException: ... + +class GeneratorExit(BaseException): ... +class KeyboardInterrupt(BaseException): ... +class SystemExit(BaseException): + code = 0 +class Exception(BaseException): ... +class ArithmeticError(Exception): ... +class OSError(Exception): + errno = 0 + strerror = ... # type: str + # filename, filename2 are actually Union[str, bytes, None] + filename = ... # type: Any + filename2 = ... # type: Any +IOError = OSError +EnvironmentError = OSError +class WindowsError(OSError): + winerror = ... # type: int +class LookupError(Exception): ... +class RuntimeError(Exception): ... +class ValueError(Exception): ... +class AssertionError(Exception): ... +class AttributeError(Exception): ... +class BufferError(Exception): ... +class EOFError(Exception): ... +class FloatingPointError(ArithmeticError): ... +class ImportError(Exception): + name = ... # type: str + path = ... # type: str +if sys.version_info >= (3, 6): + class ModuleNotFoundError(ImportError): ... +class IndexError(LookupError): ... +class KeyError(LookupError): ... +class MemoryError(Exception): ... +class NameError(Exception): ... +class NotImplementedError(RuntimeError): ... +class BlockingIOError(OSError): + characters_written = 0 +class ChildProcessError(OSError): ... +class ConnectionError(OSError): ... +class BrokenPipeError(ConnectionError): ... +class ConnectionAbortedError(ConnectionError): ... +class ConnectionRefusedError(ConnectionError): ... +class ConnectionResetError(ConnectionError): ... +class FileExistsError(OSError): ... +class FileNotFoundError(OSError): ... +class InterruptedError(OSError): ... +class IsADirectoryError(OSError): ... +class NotADirectoryError(OSError): ... +class PermissionError(OSError): ... +class ProcessLookupError(OSError): ... +class TimeoutError(OSError): ... +class OverflowError(ArithmeticError): ... +class ReferenceError(Exception): ... +class StopIteration(Exception): + value = ... # type: Any +if sys.version_info >= (3, 5): + class StopAsyncIteration(Exception): + value = ... # type: Any + class RecursionError(RuntimeError): ... +class SyntaxError(Exception): + msg = ... # type: str + lineno = ... # type: int + offset = ... # type: int + text = ... # type: str + filename = ... # type: str +class IndentationError(SyntaxError): ... +class TabError(IndentationError): ... +class SystemError(Exception): ... +class TypeError(Exception): ... +class UnboundLocalError(NameError): ... +class UnicodeError(ValueError): ... +class UnicodeDecodeError(UnicodeError): + encoding = ... # type: str + object = ... # type: bytes + start = ... # type: int + end = ... # type: int + reason = ... # type: str + def __init__(self, __encoding: str, __object: bytes, __start: int, __end: int, + __reason: str) -> None: ... +class UnicodeEncodeError(UnicodeError): + encoding = ... # type: str + object = ... # type: str + start = ... # type: int + end = ... # type: int + reason = ... # type: str + def __init__(self, __encoding: str, __object: str, __start: int, __end: int, + __reason: str) -> None: ... +class UnicodeTranslateError(UnicodeError): ... +class ZeroDivisionError(ArithmeticError): ... + +class Warning(Exception): ... +class UserWarning(Warning): ... +class DeprecationWarning(Warning): ... +class SyntaxWarning(Warning): ... +class RuntimeWarning(Warning): ... +class FutureWarning(Warning): ... +class PendingDeprecationWarning(Warning): ... +class ImportWarning(Warning): ... +class UnicodeWarning(Warning): ... +class BytesWarning(Warning): ... +class ResourceWarning(Warning): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/collections/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/collections/__init__.pyi new file mode 100644 index 000000000..ab358e229 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/collections/__init__.pyi @@ -0,0 +1,347 @@ +# Stubs for collections + +# Based on http://docs.python.org/3.2/library/collections.html + +# These are not exported. +import sys +import typing +from typing import ( + TypeVar, Generic, Dict, overload, List, Tuple, + Any, Type, Optional, Union +) +# These are exported. +from . import abc + +from typing import ( + Callable as Callable, + Container as Container, + Hashable as Hashable, + Iterable as Iterable, + Iterator as Iterator, + Sized as Sized, + Generator as Generator, + ByteString as ByteString, + Reversible as Reversible, + Mapping as Mapping, + MappingView as MappingView, + ItemsView as ItemsView, + KeysView as KeysView, + ValuesView as ValuesView, + MutableMapping as MutableMapping, + Sequence as Sequence, + MutableSequence as MutableSequence, + MutableSet as MutableSet, + AbstractSet as Set, +) +if sys.version_info >= (3, 6): + from typing import ( + Collection as Collection, + AsyncGenerator as AsyncGenerator, + ) +if sys.version_info >= (3, 5): + from typing import ( + Awaitable as Awaitable, + Coroutine as Coroutine, + AsyncIterable as AsyncIterable, + AsyncIterator as AsyncIterator, + ) + +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + + +# namedtuple is special-cased in the type checker; the initializer is ignored. +if sys.version_info >= (3, 7): + def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *, + rename: bool = ..., module: Optional[str] = ...) -> Type[tuple]: ... +elif sys.version_info >= (3, 6): + def namedtuple(typename: str, field_names: Union[str, Iterable[str]], *, + verbose: bool = ..., rename: bool = ..., module: Optional[str] = ...) -> Type[tuple]: ... +else: + def namedtuple(typename: str, field_names: Union[str, Iterable[str]], + verbose: bool = ..., rename: bool = ...) -> Type[tuple]: ... + +_UserDictT = TypeVar('_UserDictT', bound=UserDict) + +class UserDict(MutableMapping[_KT, _VT]): + data: Dict[_KT, _VT] + def __init__(self, dict: Optional[Mapping[_KT, _VT]] = ..., **kwargs: _VT) -> None: ... + def __len__(self) -> int: ... + def __getitem__(self, key: _KT) -> _VT: ... + def __setitem__(self, key: _KT, item: _VT) -> None: ... + def __delitem__(self, key: _KT) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def __contains__(self, key: object) -> bool: ... + def copy(self: _UserDictT) -> _UserDictT: ... + @classmethod + def fromkeys(cls: Type[_UserDictT], iterable: Iterable[_KT], value: Optional[_VT] = ...) -> _UserDictT: ... + +_UserListT = TypeVar('_UserListT', bound=UserList) + +class UserList(MutableSequence[_T]): + def __init__(self, initlist: Optional[Iterable[_T]] = ...) -> None: ... + def __lt__(self, other: object) -> bool: ... + def __le__(self, other: object) -> bool: ... + def __gt__(self, other: object) -> bool: ... + def __ge__(self, other: object) -> bool: ... + def __contains__(self, item: object) -> bool: ... + def __len__(self) -> int: ... + @overload + def __getitem__(self, i: int) -> _T: ... + @overload + def __getitem__(self, i: slice) -> Sequence[_T]: ... + @overload + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + def __setitem__(self, i: slice, o: Iterable[_T]) -> None: ... + def __delitem__(self, i: Union[int, slice]) -> None: ... + def __add__(self: _UserListT, other: Iterable[_T]) -> _UserListT: ... + def __iadd__(self: _UserListT, other: Iterable[_T]) -> _UserListT: ... + def __mul__(self: _UserListT, n: int) -> _UserListT: ... + def __imul__(self: _UserListT, n: int) -> _UserListT: ... + def append(self, item: _T) -> None: ... + def insert(self, i: int, item: _T) -> None: ... + def pop(self, i: int = ...) -> _T: ... + def remove(self, item: _T) -> None: ... + def clear(self) -> None: ... + def copy(self: _UserListT) -> _UserListT: ... + def count(self, item: _T) -> int: ... + def index(self, item: _T, *args: Any) -> int: ... + def reverse(self) -> None: ... + def sort(self, *args: Any, **kwds: Any) -> None: ... + def extend(self, other: Iterable[_T]) -> None: ... + +_UserStringT = TypeVar('_UserStringT', bound=UserString) + +class UserString(Sequence[str]): + def __init__(self, seq: object) -> None: ... + def __int__(self) -> int: ... + def __float__(self) -> float: ... + def __complex__(self) -> complex: ... + if sys.version_info >= (3, 5): + def __getnewargs__(self) -> Tuple[str]: ... + def __lt__(self, string: Union[str, UserString]) -> bool: ... + def __le__(self, string: Union[str, UserString]) -> bool: ... + def __gt__(self, string: Union[str, UserString]) -> bool: ... + def __ge__(self, string: Union[str, UserString]) -> bool: ... + def __contains__(self, char: object) -> bool: ... + def __len__(self) -> int: ... + # It should return a str to implement Sequence correctly, but it doesn't. + def __getitem__(self: _UserStringT, i: Union[int, slice]) -> _UserStringT: ... # type: ignore + def __add__(self: _UserStringT, other: object) -> _UserStringT: ... + def __mul__(self: _UserStringT, n: int) -> _UserStringT: ... + def __mod__(self: _UserStringT, args: Any) -> _UserStringT: ... + def capitalize(self: _UserStringT) -> _UserStringT: ... + if sys.version_info >= (3, 5): + def casefold(self: _UserStringT) -> _UserStringT: ... + def center(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ... + def count(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... + def encode(self: _UserStringT, encoding: Optional[str] = ..., errors: Optional[str] = ...) -> _UserStringT: ... + def endswith(self, suffix: Union[str, Tuple[str, ...]], start: int = ..., end: int = ...) -> bool: ... + def expandtabs(self: _UserStringT, tabsize: int = ...) -> _UserStringT: ... + def find(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... + def format(self, *args: Any, **kwds: Any) -> str: ... + if sys.version_info >= (3, 5): + def format_map(self, mapping: Mapping[str, Any]) -> str: ... + def index(self, sub: str, start: int = ..., end: int = ...) -> int: ... + def isalpha(self) -> bool: ... + def isalnum(self) -> bool: ... + def isdecimal(self) -> bool: ... + def isdigit(self) -> bool: ... + def isidentifier(self) -> bool: ... + def islower(self) -> bool: ... + def isnumeric(self) -> bool: ... + if sys.version_info >= (3, 5): + def isprintable(self) -> bool: ... + def isspace(self) -> bool: ... + def istitle(self) -> bool: ... + def isupper(self) -> bool: ... + def join(self, seq: Iterable[str]) -> str: ... + def ljust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ... + def lower(self: _UserStringT) -> _UserStringT: ... + def lstrip(self: _UserStringT, chars: Optional[str] = ...) -> _UserStringT: ... + if sys.version_info >= (3, 5): + @staticmethod + @overload + def maketrans(x: Union[Dict[int, _T], Dict[str, _T], Dict[Union[str, int], _T]]) -> Dict[int, _T]: ... + @staticmethod + @overload + def maketrans(x: str, y: str, z: str = ...) -> Dict[int, Union[int, None]]: ... + def partition(self, sep: str) -> Tuple[str, str, str]: ... + def replace(self: _UserStringT, old: Union[str, UserString], new: Union[str, UserString], maxsplit: int = ...) -> _UserStringT: ... + def rfind(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... + def rindex(self, sub: Union[str, UserString], start: int = ..., end: int = ...) -> int: ... + def rjust(self: _UserStringT, width: int, *args: Any) -> _UserStringT: ... + def rpartition(self, sep: str) -> Tuple[str, str, str]: ... + def rstrip(self: _UserStringT, chars: Optional[str] = ...) -> _UserStringT: ... + def split(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def rsplit(self, sep: Optional[str] = ..., maxsplit: int = ...) -> List[str]: ... + def splitlines(self, keepends: bool = ...) -> List[str]: ... + def startswith(self, prefix: Union[str, Tuple[str, ...]], start: int = ..., end: int = ...) -> bool: ... + def strip(self: _UserStringT, chars: Optional[str] = ...) -> _UserStringT: ... + def swapcase(self: _UserStringT) -> _UserStringT: ... + def title(self: _UserStringT) -> _UserStringT: ... + def translate(self: _UserStringT, *args: Any) -> _UserStringT: ... + def upper(self: _UserStringT) -> _UserStringT: ... + def zfill(self: _UserStringT, width: int) -> _UserStringT: ... + + +# Technically, deque only derives from MutableSequence in 3.5 (before then, the insert and index +# methods did not exist). +# But in practice it's not worth losing sleep over. +class deque(MutableSequence[_T], Generic[_T]): + @property + def maxlen(self) -> Optional[int]: ... + def __init__(self, iterable: Iterable[_T] = ..., + maxlen: int = ...) -> None: ... + def append(self, x: _T) -> None: ... + def appendleft(self, x: _T) -> None: ... + def clear(self) -> None: ... + if sys.version_info >= (3, 5): + def copy(self) -> deque[_T]: ... + def count(self, x: _T) -> int: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def extendleft(self, iterable: Iterable[_T]) -> None: ... + def insert(self, i: int, x: _T) -> None: ... + def index(self, x: _T, start: int = ..., stop: int = ...) -> int: ... + def pop(self, i: int = ...) -> _T: ... + def popleft(self) -> _T: ... + def remove(self, value: _T) -> None: ... + def reverse(self) -> None: ... + def rotate(self, n: int) -> None: ... + + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + def __str__(self) -> str: ... + def __hash__(self) -> int: ... + + # These methods of deque don't really take slices, but we need to + # define them as taking a slice to satisfy MutableSequence. + @overload + def __getitem__(self, index: int) -> _T: ... + @overload + def __getitem__(self, s: slice) -> Sequence[_T]: + raise TypeError + @overload + def __setitem__(self, i: int, x: _T) -> None: ... + @overload + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: + raise TypeError + @overload + def __delitem__(self, i: int) -> None: ... + @overload + def __delitem__(self, s: slice) -> None: + raise TypeError + + def __contains__(self, o: object) -> bool: ... + def __reversed__(self) -> Iterator[_T]: ... + + if sys.version_info >= (3, 5): + def __add__(self, other: deque[_T]) -> deque[_T]: ... + def __mul__(self, other: int) -> deque[_T]: ... + def __imul__(self, other: int) -> None: ... + +_CounterT = TypeVar('_CounterT', bound=Counter) + +class Counter(Dict[_T, int], Generic[_T]): + @overload + def __init__(self, **kwargs: int) -> None: ... + @overload + def __init__(self, mapping: Mapping[_T, int]) -> None: ... + @overload + def __init__(self, iterable: Iterable[_T]) -> None: ... + def copy(self: _CounterT) -> _CounterT: ... + def elements(self) -> Iterator[_T]: ... + + def most_common(self, n: Optional[int] = ...) -> List[Tuple[_T, int]]: ... + + @overload + def subtract(self, __mapping: Mapping[_T, int]) -> None: ... + @overload + def subtract(self, iterable: Iterable[_T]) -> None: ... + + # The Iterable[Tuple[...]] argument type is not actually desirable + # (the tuples will be added as keys, breaking type safety) but + # it's included so that the signature is compatible with + # Dict.update. Not sure if we should use '# type: ignore' instead + # and omit the type from the union. + @overload + def update(self, __m: Mapping[_T, int], **kwargs: int) -> None: ... + @overload + def update(self, __m: Union[Iterable[_T], Iterable[Tuple[_T, int]]], **kwargs: int) -> None: ... + @overload + def update(self, **kwargs: int) -> None: ... + + def __add__(self, other: Counter[_T]) -> Counter[_T]: ... + def __sub__(self, other: Counter[_T]) -> Counter[_T]: ... + def __and__(self, other: Counter[_T]) -> Counter[_T]: ... + def __or__(self, other: Counter[_T]) -> Counter[_T]: ... + def __pos__(self) -> Counter[_T]: ... + def __neg__(self) -> Counter[_T]: ... + def __iadd__(self, other: Counter[_T]) -> Counter[_T]: ... + def __isub__(self, other: Counter[_T]) -> Counter[_T]: ... + def __iand__(self, other: Counter[_T]) -> Counter[_T]: ... + def __ior__(self, other: Counter[_T]) -> Counter[_T]: ... + +_OrderedDictT = TypeVar('_OrderedDictT', bound=OrderedDict) + +class _OrderedDictKeysView(KeysView[_KT], Reversible[_KT]): + def __reversed__(self) -> Iterator[_KT]: ... +class _OrderedDictItemsView(ItemsView[_KT, _VT], Reversible[Tuple[_KT, _VT]]): + def __reversed__(self) -> Iterator[Tuple[_KT, _VT]]: ... +class _OrderedDictValuesView(ValuesView[_VT], Reversible[_VT]): + def __reversed__(self) -> Iterator[_VT]: ... + +class OrderedDict(Dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]): + def popitem(self, last: bool = ...) -> Tuple[_KT, _VT]: ... + def move_to_end(self, key: _KT, last: bool = ...) -> None: ... + def copy(self: _OrderedDictT) -> _OrderedDictT: ... + def __reversed__(self) -> Iterator[_KT]: ... + def keys(self) -> _OrderedDictKeysView[_KT]: ... + def items(self) -> _OrderedDictItemsView[_KT, _VT]: ... + def values(self) -> _OrderedDictValuesView[_VT]: ... + +_DefaultDictT = TypeVar('_DefaultDictT', bound=defaultdict) + +class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): + default_factory = ... # type: Callable[[], _VT] + + @overload + def __init__(self, **kwargs: _VT) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]]) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], **kwargs: _VT) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + map: Mapping[_KT, _VT]) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + iterable: Iterable[Tuple[_KT, _VT]]) -> None: ... + @overload + def __init__(self, default_factory: Optional[Callable[[], _VT]], + iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + def __missing__(self, key: _KT) -> _VT: ... + # TODO __reversed__ + def copy(self: _DefaultDictT) -> _DefaultDictT: ... + +class ChainMap(MutableMapping[_KT, _VT], Generic[_KT, _VT]): + def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... + + @property + def maps(self) -> List[Mapping[_KT, _VT]]: ... + + def new_child(self, m: Mapping[_KT, _VT] = ...) -> typing.ChainMap[_KT, _VT]: ... + + @property + def parents(self) -> typing.ChainMap[_KT, _VT]: ... + + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/collections/abc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/collections/abc.pyi new file mode 100644 index 000000000..a9577285c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/collections/abc.pyi @@ -0,0 +1,40 @@ +# Stubs for collections.abc (introduced from Python 3.3) +# +# https://docs.python.org/3.3/whatsnew/3.3.html#collections +import sys + +from . import ( + Container as Container, + Hashable as Hashable, + Iterable as Iterable, + Iterator as Iterator, + Sized as Sized, + Callable as Callable, + Mapping as Mapping, + MutableMapping as MutableMapping, + Sequence as Sequence, + MutableSequence as MutableSequence, + Set as Set, + MutableSet as MutableSet, + MappingView as MappingView, + ItemsView as ItemsView, + KeysView as KeysView, + ValuesView as ValuesView, +) + +if sys.version_info >= (3, 5): + from . import ( + Generator as Generator, + ByteString as ByteString, + Awaitable as Awaitable, + Coroutine as Coroutine, + AsyncIterable as AsyncIterable, + AsyncIterator as AsyncIterator, + ) + +if sys.version_info >= (3, 6): + from . import ( + Collection as Collection, + Reversible as Reversible, + AsyncGenerator as AsyncGenerator, + ) diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/compileall.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/compileall.pyi new file mode 100644 index 000000000..8d2731c05 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/compileall.pyi @@ -0,0 +1,20 @@ +# Stubs for compileall (Python 3) + +import os +import sys +from typing import Optional, Union, Pattern + +if sys.version_info < (3, 6): + _Path = Union[str, bytes] + _SuccessType = bool +else: + _Path = Union[str, bytes, os.PathLike] + _SuccessType = int + +# rx can be any object with a 'search' method; once we have Protocols we can change the type +if sys.version_info < (3, 5): + def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... +else: + def compile_dir(dir: _Path, maxlevels: int = ..., ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ..., workers: int = ...) -> _SuccessType: ... +def compile_file(fullname: _Path, ddir: Optional[_Path] = ..., force: bool = ..., rx: Optional[Pattern] = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... +def compile_path(skip_curdir: bool = ..., maxlevels: int = ..., force: bool = ..., quiet: int = ..., legacy: bool = ..., optimize: int = ...) -> _SuccessType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/__init__.pyi new file mode 100644 index 000000000..4439dcadb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/__init__.pyi @@ -0,0 +1,3 @@ +from ._base import * # noqa: F403 +from .thread import * # noqa: F403 +from .process import * # noqa: F403 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/_base.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/_base.pyi new file mode 100644 index 000000000..ff38f8689 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/_base.pyi @@ -0,0 +1,54 @@ +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple +from types import TracebackType +import sys + +FIRST_COMPLETED = ... # type: str +FIRST_EXCEPTION = ... # type: str +ALL_COMPLETED = ... # type: str +PENDING = ... # type: Any +RUNNING = ... # type: Any +CANCELLED = ... # type: Any +CANCELLED_AND_NOTIFIED = ... # type: Any +FINISHED = ... # type: Any +LOGGER = ... # type: Any + +class Error(Exception): ... +class CancelledError(Error): ... +class TimeoutError(Error): ... + +_T = TypeVar('_T') + +class Future(Generic[_T]): + def __init__(self) -> None: ... + def cancel(self) -> bool: ... + def cancelled(self) -> bool: ... + def running(self) -> bool: ... + def done(self) -> bool: ... + def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ... + def result(self, timeout: Optional[float] = ...) -> _T: ... + def set_running_or_notify_cancel(self) -> bool: ... + def set_result(self, result: _T) -> None: ... + + if sys.version_info >= (3,): + def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ... + def set_exception(self, exception: Optional[BaseException]) -> None: ... + else: + def exception(self, timeout: Optional[float] = ...) -> Any: ... + def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ... + def set_exception(self, exception: Any) -> None: ... + def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ... + + +class Executor: + def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ... + if sys.version_info >= (3, 5): + def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...) -> Iterator[_T]: ... + else: + def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...,) -> Iterator[_T]: ... + def shutdown(self, wait: bool = ...) -> None: ... + def __enter__(self: _T) -> _T: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ... + +def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ... + +def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/process.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/process.pyi new file mode 100644 index 000000000..c36180ff8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/process.pyi @@ -0,0 +1,11 @@ +from typing import Optional, Any +from ._base import Future, Executor +import sys + +EXTRA_QUEUED_CALLS = ... # type: Any + +if sys.version_info >= (3,): + class BrokenProcessPool(RuntimeError): ... + +class ProcessPoolExecutor(Executor): + def __init__(self, max_workers: Optional[int] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/thread.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/thread.pyi new file mode 100644 index 000000000..4f5b501b0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/concurrent/futures/thread.pyi @@ -0,0 +1,10 @@ +from typing import Optional +from ._base import Executor, Future +import sys + +class ThreadPoolExecutor(Executor): + if sys.version_info >= (3, 6) or sys.version_info < (3,): + def __init__(self, max_workers: Optional[int] = ..., + thread_name_prefix: str = ...) -> None: ... + else: + def __init__(self, max_workers: Optional[int] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/configparser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/configparser.pyi new file mode 100644 index 000000000..16c063ac2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/configparser.pyi @@ -0,0 +1,233 @@ +# Based on http://docs.python.org/3.5/library/configparser.html and on +# reading configparser.py. + +import sys +from typing import (AbstractSet, MutableMapping, Mapping, Dict, Sequence, List, + Union, Iterable, Iterator, Callable, Any, IO, overload, + Optional, Pattern, Type, TypeVar) +# Types only used in type comments only +from typing import Optional, Tuple # noqa + +if sys.version_info >= (3, 6): + from os import PathLike + +# Internal type aliases +_section = Mapping[str, str] +_parser = MutableMapping[str, _section] +_converter = Callable[[str], Any] +_converters = Dict[str, _converter] +_T = TypeVar('_T') + +if sys.version_info >= (3, 6): + _Path = Union[str, PathLike[str]] +else: + _Path = str + +DEFAULTSECT: str +MAX_INTERPOLATION_DEPTH: int + +class Interpolation: + def before_get(self, parser: _parser, + section: str, + option: str, + value: str, + defaults: _section) -> str: ... + + def before_set(self, parser: _parser, + section: str, + option: str, + value: str) -> str: ... + + def before_read(self, parser: _parser, + section: str, + option: str, + value: str) -> str: ... + + def before_write(self, parser: _parser, + section: str, + option: str, + value: str) -> str: ... + + +class BasicInterpolation(Interpolation): ... +class ExtendedInterpolation(Interpolation): ... +class LegacyInterpolation(Interpolation): ... + + +class RawConfigParser(_parser): + def __init__(self, + defaults: Optional[_section] = ..., + dict_type: Type[Mapping[str, str]] = ..., + allow_no_value: bool = ..., + *, + delimiters: Sequence[str] = ..., + comment_prefixes: Sequence[str] = ..., + inline_comment_prefixes: Optional[Sequence[str]] = ..., + strict: bool = ..., + empty_lines_in_values: bool = ..., + default_section: str = ..., + interpolation: Optional[Interpolation] = ...) -> None: ... + + def __len__(self) -> int: ... + + def __getitem__(self, section: str) -> SectionProxy: ... + + def __setitem__(self, section: str, options: _section) -> None: ... + + def __delitem__(self, section: str) -> None: ... + + def __iter__(self) -> Iterator[str]: ... + + def defaults(self) -> _section: ... + + def sections(self) -> List[str]: ... + + def add_section(self, section: str) -> None: ... + + def has_section(self, section: str) -> bool: ... + + def options(self, section: str) -> List[str]: ... + + def has_option(self, section: str, option: str) -> bool: ... + + def read(self, filenames: Union[_Path, Iterable[_Path]], + encoding: Optional[str] = ...) -> List[str]: ... + + def readfp(self, fp: IO[str], filename: Optional[str] = ...) -> None: ... + + def read_file(self, f: Iterable[str], source: Optional[str] = ...) -> None: ... + + def read_string(self, string: str, source: str = ...) -> None: ... + + def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], + source: str = ...) -> None: ... + + # These get* methods are partially applied (with the same names) in + # SectionProxy; the stubs should be kept updated together + def getint(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: int = ...) -> int: ... + + def getfloat(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: float = ...) -> float: ... + + def getboolean(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: bool = ...) -> bool: ... + + def _get_conv(self, section: str, option: str, conv: Callable[[str], _T], *, raw: bool = ..., vars: _section = ..., fallback: _T = ...) -> _T: ... + + # This is incompatible with MutableMapping so we ignore the type + def get(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: str = ...) -> str: # type: ignore + ... + + @overload + def items(self, *, raw: bool = ..., vars: _section = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ... + + @overload + def items(self, section: str, raw: bool = ..., vars: _section = ...) -> List[Tuple[str, str]]: ... + + def set(self, section: str, option: str, value: str) -> None: ... + + def write(self, + fileobject: IO[str], + space_around_delimiters: bool = ...) -> None: ... + + def remove_option(self, section: str, option: str) -> bool: ... + + def remove_section(self, section: str) -> bool: ... + + def optionxform(self, option: str) -> str: ... + + +class ConfigParser(RawConfigParser): + def __init__(self, + defaults: Optional[_section] = ..., + dict_type: Mapping[str, str] = ..., + allow_no_value: bool = ..., + delimiters: Sequence[str] = ..., + comment_prefixes: Sequence[str] = ..., + inline_comment_prefixes: Optional[Sequence[str]] = ..., + strict: bool = ..., + empty_lines_in_values: bool = ..., + default_section: str = ..., + interpolation: Optional[Interpolation] = ..., + converters: _converters = ...) -> None: ... + +class SafeConfigParser(ConfigParser): ... + +class SectionProxy(MutableMapping[str, str]): + def __init__(self, parser: RawConfigParser, name: str) -> None: ... + def __getitem__(self, key: str) -> str: ... + def __setitem__(self, key: str, value: str) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __contains__(self, key: object) -> bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + @property + def parser(self) -> RawConfigParser: ... + @property + def name(self) -> str: ... + def get(self, option: str, fallback: Optional[str] = ..., *, raw: bool = ..., vars: Optional[_section] = ..., **kwargs: Any) -> str: ... # type: ignore + + # These are partially-applied version of the methods with the same names in + # RawConfigParser; the stubs should be kept updated together + def getint(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: int = ...) -> int: ... + def getfloat(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: float = ...) -> float: ... + def getboolean(self, option: str, *, raw: bool = ..., vars: _section = ..., fallback: bool = ...) -> bool: ... + + # SectionProxy can have arbitrary attributes when custon converters are used + def __getattr__(self, key: str) -> Callable[..., Any]: ... + +class ConverterMapping(MutableMapping[str, Optional[_converter]]): + GETTERCRE: Pattern + def __init__(self, parser: RawConfigParser) -> None: ... + def __getitem__(self, key: str) -> _converter: ... + def __setitem__(self, key: str, value: Optional[_converter]) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + + +class Error(Exception): ... + + +class NoSectionError(Error): ... + + +class DuplicateSectionError(Error): + section = ... # type: str + source = ... # type: Optional[str] + lineno = ... # type: Optional[int] + + +class DuplicateOptionError(Error): + section = ... # type: str + option = ... # type: str + source = ... # type: Optional[str] + lineno = ... # type: Optional[int] + + +class NoOptionError(Error): + section = ... # type: str + option = ... # type: str + + +class InterpolationError(Error): + section = ... # type: str + option = ... # type: str + + +class InterpolationDepthError(InterpolationError): ... + + +class InterpolationMissingOptionError(InterpolationError): + reference = ... # type: str + + +class InterpolationSyntaxError(InterpolationError): ... + + +class ParsingError(Error): + source = ... # type: str + errors = ... # type: Sequence[Tuple[int, str]] + + +class MissingSectionHeaderError(ParsingError): + lineno = ... # type: int + line = ... # type: str diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/__init__.pyi new file mode 100644 index 000000000..d79727aaf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/__init__.pyi @@ -0,0 +1,10 @@ +import _curses +from _curses import * # noqa: F403 +from typing import Callable, Any, Sequence, Mapping + +LINES: int +COLS: int + +def initscr() -> _curses._CursesWindow: ... +def start_color() -> None: ... +def wrapper(func: Callable[..., Any], *arg: Any, **kwds: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/ascii.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/ascii.pyi new file mode 100644 index 000000000..403376925 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/ascii.pyi @@ -0,0 +1,62 @@ +from typing import List, Union, overload, TypeVar + +_Ch = TypeVar('_Ch', str, int) + +NUL: int +SOH: int +STX: int +ETX: int +EOT: int +ENQ: int +ACK: int +BEL: int +BS: int +TAB: int +HT: int +LF: int +NL: int +VT: int +FF: int +CR: int +SO: int +SI: int +DLE: int +DC1: int +DC2: int +DC3: int +DC4: int +NAK: int +SYN: int +ETB: int +CAN: int +EM: int +SUB: int +ESC: int +FS: int +GS: int +RS: int +US: int +SP: int +DEL: int + +controlnames: List[int] + +def isalnum(c: Union[str, int]) -> bool: ... +def isalpha(c: Union[str, int]) -> bool: ... +def isascii(c: Union[str, int]) -> bool: ... +def isblank(c: Union[str, int]) -> bool: ... +def iscntrl(c: Union[str, int]) -> bool: ... +def isdigit(c: Union[str, int]) -> bool: ... +def isgraph(c: Union[str, int]) -> bool: ... +def islower(c: Union[str, int]) -> bool: ... +def isprint(c: Union[str, int]) -> bool: ... +def ispunct(c: Union[str, int]) -> bool: ... +def isspace(c: Union[str, int]) -> bool: ... +def isupper(c: Union[str, int]) -> bool: ... +def isxdigit(c: Union[str, int]) -> bool: ... +def isctrl(c: Union[str, int]) -> bool: ... +def ismeta(c: Union[str, int]) -> bool: ... +def ascii(c: _Ch) -> _Ch: ... +def ctrl(c: _Ch) -> _Ch: ... +def alt(c: _Ch) -> _Ch: ... +def unctrl(c: Union[str, int]) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/panel.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/panel.pyi new file mode 100644 index 000000000..4b95fb079 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/panel.pyi @@ -0,0 +1,20 @@ +from _curses import _CursesWindow + +class _Curses_Panel: # type is (note the space in the class name) + def above(self) -> '_Curses_Panel': ... + def below(self) -> '_Curses_Panel': ... + def bottom(self) -> None: ... + def hidden(self) -> bool: ... + def hide(self) -> None: ... + def move(self, y: int, x: int) -> None: ... + def replace(self, win: _CursesWindow) -> None: ... + def set_userptr(self, obj: object) -> None: ... + def show(self) -> None: ... + def top(self) -> None: ... + def userptr(self) -> object: ... + def window(self) -> _CursesWindow: ... + +def bottom_panel() -> _Curses_Panel: ... +def new_panel(win: _CursesWindow) -> _Curses_Panel: ... +def top_panel() -> _Curses_Panel: ... +def update_panels() -> _Curses_Panel: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/textpad.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/textpad.pyi new file mode 100644 index 000000000..87103aed2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/curses/textpad.pyi @@ -0,0 +1,11 @@ +from _curses import _CursesWindow +from typing import Callable, Union + +def rectangle(win: _CursesWindow, uly: int, ulx: int, lry: int, lrx: int) -> None: ... + +class Textbox: + stripspaces: bool + def __init__(self, w: _CursesWindow, insert_mode: bool= ...) -> None: ... + def edit(self, validate: Callable[[int], int]) -> str: ... + def do_command(self, ch: Union[str, int]) -> None: ... + def gather(self) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/decimal.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/decimal.pyi new file mode 100644 index 000000000..e77328854 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/decimal.pyi @@ -0,0 +1,255 @@ +# Stubs for decimal (Python 3.4) + +from typing import ( + Any, Union, SupportsInt, SupportsFloat, SupportsAbs, SupportsRound, Sequence, + Tuple, NamedTuple, Dict +) + +_Decimal = Union[Decimal, int] +_ComparableNum = Union[Decimal, int, float] + +BasicContext = ... # type: Context +DefaultContext = ... # type: Context +ExtendedContext = ... # type: Context +HAVE_THREADS = ... # type: bool +MAX_EMAX = ... # type: int +MAX_PREC = ... # type: int +MIN_EMIN = ... # type: int +MIN_ETINY = ... # type: int +ROUND_05UP = ... # type: str +ROUND_CEILING = ... # type: str +ROUND_DOWN = ... # type: str +ROUND_FLOOR = ... # type: str +ROUND_HALF_DOWN = ... # type: str +ROUND_HALF_EVEN = ... # type: str +ROUND_HALF_UP = ... # type: str +ROUND_UP = ... # type: str + +def getcontext() -> Context: ... +def localcontext(ctx: Context = ...) -> _ContextManager: ... +def setcontext(c: Context) -> None: ... + +DecimalTuple = NamedTuple('DecimalTuple', + [('sign', int), + ('digits', Sequence[int]), # TODO: Use Tuple[int, ...] + ('exponent', int)]) + +class _ContextManager: + def __enter__(self) -> Context: ... + def __exit__(self, t, v, tb) -> None: ... + +class Context: + Emax = ... # type: int + Emin = ... # type: int + capitals = ... # type: int + clamp = ... # type: int + prec = ... # type: int + rounding = ... # type: str + traps = ... # type: Dict[type, bool] + def __init__(self, prec: int = ..., rounding: str = ..., Emin: int = ..., Emax: int = ..., + capitals: int = ..., clamp: int = ..., flags=..., traps=..., + _ignored_flags=...) -> None: ... + def Etiny(self): ... + def Etop(self): ... + def abs(self, x: _Decimal) -> Decimal: ... + def add(self, x: _Decimal, y: _Decimal) -> Decimal: ... + def canonical(self, x): ... + def clear_flags(self): ... + def clear_traps(self): ... + def compare(self, x, y): ... + def compare_signal(self, x, y): ... + def compare_total(self, x, y): ... + def compare_total_mag(self, x, y): ... + def copy(self): ... + def copy_abs(self, x): ... + def copy_decimal(self, x): ... + def copy_negate(self, x): ... + def copy_sign(self, x, y): ... + def create_decimal(self, x): ... + def create_decimal_from_float(self, f): ... + def divide(self, x, y): ... + def divide_int(self, x, y): ... + def divmod(self, x, y): ... + def exp(self, x): ... + def fma(self, x, y, z): ... + def is_canonical(self, x): ... + def is_finite(self, x): ... + def is_infinite(self, x): ... + def is_nan(self, x): ... + def is_normal(self, x): ... + def is_qnan(self, x): ... + def is_signed(self, x): ... + def is_snan(self): ... + def is_subnormal(self, x): ... + def is_zero(self, x): ... + def ln(self, x): ... + def log10(self, x): ... + def logb(self, x): ... + def logical_and(self, x, y): ... + def logical_invert(self, x): ... + def logical_or(self, x, y): ... + def logical_xor(self, x, y): ... + def max(self, x, y): ... + def max_mag(self, x, y): ... + def min(self, x, y): ... + def min_mag(self, x, y): ... + def minus(self, x): ... + def multiply(self, x, y): ... + def next_minus(self, x): ... + def next_plus(self, x): ... + def next_toward(self, x): ... + def normalize(self, x): ... + def number_class(self, x): ... + def plus(self, x): ... + def power(self, x, y): ... + def quantize(self, x, y): ... + def radix(self): ... + def remainder(self, x, y): ... + def remainder_near(self, x, y): ... + def rotate(self, x, y): ... + def same_quantum(self, x, y): ... + def scaleb(self, x, y): ... + def shift(self, x, y): ... + def sqrt(self, x): ... + def subtract(self, x, y): ... + def to_eng_string(self, x): ... + def to_integral(self, x): ... + def to_integral_exact(self, x): ... + def to_integral_value(self, x): ... + def to_sci_string(self, x): ... + def __copy__(self) -> Context: ... + def __delattr__(self, name): ... + def __reduce__(self): ... + +class ConversionSyntax(InvalidOperation): ... + +class Decimal(SupportsInt, SupportsFloat, SupportsAbs[Decimal], SupportsRound[int]): + # TODO: SupportsCeil, SupportsFloor, SupportsTrunc? + + def __init__(cls, value: Union[_Decimal, float, str, + Tuple[int, Sequence[int], int]] = ..., + context: Context = ...) -> None: ... + + @property + def imag(self) -> Decimal: ... + @property + def real(self) -> Decimal: ... + + def adjusted(self) -> int: ... + def as_tuple(self) -> DecimalTuple: ... + def canonical(self) -> Decimal: ... + def compare(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def compare_signal(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def compare_total(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def compare_total_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def conjugate(self) -> Decimal: ... + def copy_abs(self) -> Decimal: ... + def copy_negate(self) -> Decimal: ... + def copy_sign(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def exp(self, context: Context = ...) -> Decimal: ... + def fma(self, other: _Decimal, third: _Decimal, context: Context = ...) -> Decimal: ... + @classmethod + def from_float(cls, f: float) -> Decimal: ... + def is_canonical(self) -> bool: ... + def is_finite(self) -> bool: ... + def is_infinite(self) -> bool: ... + def is_nan(self) -> bool: ... + def is_normal(self, context: Context = ...) -> bool: ... + def is_qnan(self) -> bool: ... + def is_signed(self) -> bool: ... + def is_snan(self) -> bool: ... + def is_subnormal(self, context: Context = ...) -> bool: ... + def is_zero(self) -> bool: ... + def ln(self, context: Context = ...) -> Decimal: ... + def log10(self, context: Context = ...) -> Decimal: ... + def logb(self, context: Context = ...) -> Decimal: ... + def logical_and(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def logical_invert(self, context: Context = ...) -> Decimal: ... + def logical_or(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def logical_xor(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def max(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def max_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def min(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def min_mag(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def next_minus(self, context: Context = ...) -> Decimal: ... + def next_plus(self, context: Context = ...) -> Decimal: ... + def next_toward(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def normalize(self, context: Context = ...) -> Decimal: ... + def number_class(self, context: Context = ...) -> str: ... + def quantize(self, exp: _Decimal, rounding: str = ..., + context: Context = ...) -> Decimal: ... + def radix(self) -> Decimal: ... + def remainder_near(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def rotate(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def same_quantum(self, other: _Decimal, context: Context = ...) -> bool: ... + def scaleb(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def shift(self, other: _Decimal, context: Context = ...) -> Decimal: ... + def sqrt(self, context: Context = ...) -> Decimal: ... + def to_eng_string(self, context: Context = ...) -> str: ... + def to_integral(self, rounding: str = ..., context: Context = ...) -> Decimal: ... + def to_integral_exact(self, rounding: str = ..., context: Context = ...) -> Decimal: ... + def to_integral_value(self, rounding: str = ..., context: Context = ...) -> Decimal: ... + def __abs__(self) -> Decimal: ... + def __add__(self, other: _Decimal) -> Decimal: ... + def __bool__(self) -> bool: ... + def __ceil__(self) -> int: ... + def __complex__(self) -> complex: ... + def __copy__(self) -> Decimal: ... + def __deepcopy__(self) -> Decimal: ... + def __divmod__(self, other: _Decimal) -> Tuple[Decimal, Decimal]: ... + def __eq__(self, other: object) -> bool: ... + def __float__(self) -> float: ... + def __floor__(self) -> int: ... + def __floordiv__(self, other: _Decimal) -> Decimal: ... + def __format__(self, specifier, context=..., _localeconv=...) -> str: ... + def __ge__(self, other: _ComparableNum) -> bool: ... + def __gt__(self, other: _ComparableNum) -> bool: ... + def __hash__(self) -> int: ... + def __int__(self) -> int: ... + def __le__(self, other: _ComparableNum) -> bool: ... + def __lt__(self, other: _ComparableNum) -> bool: ... + def __mod__(self, other: _Decimal) -> Decimal: ... + def __mul__(self, other: _Decimal) -> Decimal: ... + def __ne__(self, other: object) -> bool: ... + def __neg__(self) -> Decimal: ... + def __pos__(self) -> Decimal: ... + def __pow__(self, other: _Decimal) -> Decimal: ... + def __radd__(self, other: int) -> Decimal: ... + def __rdivmod__(self, other: int) -> Tuple[Decimal, Decimal]: ... + def __reduce__(self): ... + def __rfloordiv__(self, other: int) -> Decimal: ... + def __rmod__(self, other: int) -> Decimal: ... + def __rmul__(self, other: int) -> Decimal: ... + def __round__(self, n=...) -> int: ... + def __rpow__(self, other: int) -> Decimal: ... + def __rsub__(self, other: int) -> Decimal: ... + def __rtruediv__(self, other: int) -> Decimal: ... + def __sub__(self, other: _Decimal) -> Decimal: ... + def __truediv__(self, other: _Decimal) -> Decimal: ... + def __trunc__(self) -> int: ... + +class DecimalException(ArithmeticError): ... + +class Clamped(DecimalException): ... + +class DivisionByZero(DecimalException, ZeroDivisionError): ... + +class DivisionImpossible(InvalidOperation): ... + +class DivisionUndefined(InvalidOperation, ZeroDivisionError): ... + +class FloatOperation(DecimalException, TypeError): ... + +class Inexact(DecimalException): ... + +class InvalidContext(InvalidOperation): ... + +class InvalidOperation(DecimalException): ... + +class Overflow(Inexact, Rounded): ... + +class Rounded(DecimalException): ... + +class Subnormal(DecimalException): ... + +class Underflow(Inexact, Rounded, Subnormal): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/__init__.pyi new file mode 100644 index 000000000..9ffd9966e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/__init__.pyi @@ -0,0 +1,31 @@ +# Stubs for email (Python 3.4) + +from typing import Callable, Optional, IO +import sys +from email.message import Message +from email.policy import Policy + +def message_from_string(s: str, _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> Message: ... +def message_from_bytes(s: bytes, _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> Message: ... +def message_from_file(fp: IO[str], _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> Message: ... +def message_from_binary_file(fp: IO[bytes], + _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> Message: ... + +# Names in __all__ with no definition: +# base64mime +# charset +# encoders +# errors +# feedparser +# generator +# header +# iterators +# message +# mime +# parser +# quoprimime +# utils diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/charset.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/charset.pyi new file mode 100644 index 000000000..5c674e452 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/charset.pyi @@ -0,0 +1,27 @@ +# Stubs for email.charset (Python 3.4) + +from typing import List, Optional, Iterator, Any + +class Charset: + input_charset = ... # type: str + header_encoding = ... # type: int + body_encoding = ... # type: int + output_charset = ... # type: Optional[str] + input_codec = ... # type: Optional[str] + output_codec = ... # type: Optional[str] + def __init__(self, input_charset: str = ...) -> None: ... + def get_body_encoding(self) -> str: ... + def get_output_charset(self) -> Optional[str]: ... + def header_encode(self, string: str) -> str: ... + def header_encode_lines(self, string: str, + maxlengths: Iterator[int]) -> List[str]: ... + def body_encode(self, string: str) -> str: ... + def __str__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +def add_charset(charset: Charset, header_enc: Optional[int] = ..., + body_enc: Optional[int] = ..., + output_charset: Optional[str] = ...) -> None: ... +def add_alias(alias: str, canonical: str) -> None: ... +def add_codec(charset: str, codecname: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/contentmanager.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/contentmanager.pyi new file mode 100644 index 000000000..096347409 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/contentmanager.pyi @@ -0,0 +1,15 @@ +# Stubs for email.contentmanager (Python 3.4) + +from typing import Any, Callable +from email.message import Message + +class ContentManager: + def __init__(self) -> None: ... + def get_content(self, msg: Message, *args: Any, **kw: Any) -> Any: ... + def set_content(self, msg: Message, obj: Any, *args: Any, + **kw: Any) -> Any: ... + def add_get_handler(self, key: str, handler: Callable[..., Any]) -> None: ... + def add_set_handler(self, typekey: type, + handler: Callable[..., Any]) -> None: ... + +raw_data_manager = ... # type: ContentManager diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/encoders.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/encoders.pyi new file mode 100644 index 000000000..bb5c84cb1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/encoders.pyi @@ -0,0 +1,8 @@ +# Stubs for email.encoders (Python 3.4) + +from email.message import Message + +def encode_base64(msg: Message) -> None: ... +def encode_quopri(msg: Message) -> None: ... +def encode_7or8bit(msg: Message) -> None: ... +def encode_noop(msg: Message) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/errors.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/errors.pyi new file mode 100644 index 000000000..77d9902cc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/errors.pyi @@ -0,0 +1,19 @@ +# Stubs for email.errors (Python 3.4) + +class MessageError(Exception): ... +class MessageParseError(MessageError): ... +class HeaderParseError(MessageParseError): ... +class BoundaryError(MessageParseError): ... +class MultipartConversionError(MessageError, TypeError): ... + +class MessageDefect(ValueError): ... +class NoBoundaryInMultipartDefect(MessageDefect): ... +class StartBoundaryNotFoundDefect(MessageDefect): ... +class FirstHeaderLineIsContinuationDefect(MessageDefect): ... +class MisplacedEnvelopeHeaderDefect(MessageDefect): ... +class MalformedHeaderDefect(MessageDefect): ... +class MultipartInvariantViolationDefect(MessageDefect): ... +class InvalidBase64PaddingDefect(MessageDefect): ... +class InvalidBase64CharactersDefect(MessageDefect): ... +class CloseBoundaryNotFoundDefect(MessageDefect): ... +class MissingHeaderBodySeparatorDefect(MessageDefect): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/feedparser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/feedparser.pyi new file mode 100644 index 000000000..48d940b39 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/feedparser.pyi @@ -0,0 +1,18 @@ +# Stubs for email.feedparser (Python 3.4) + +from typing import Callable +import sys +from email.message import Message +from email.policy import Policy + +class FeedParser: + def __init__(self, _factory: Callable[[], Message] = ..., *, + policy: Policy = ...) -> None: ... + def feed(self, data: str) -> None: ... + def close(self) -> Message: ... + +class BytesFeedParser: + def __init__(self, _factory: Callable[[], Message] = ..., *, + policy: Policy = ...) -> None: ... + def feed(self, data: str) -> None: ... + def close(self) -> Message: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/generator.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/generator.pyi new file mode 100644 index 000000000..dc908a151 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/generator.pyi @@ -0,0 +1,28 @@ +# Stubs for email.generator (Python 3.4) + +from typing import TextIO, Optional +from email.message import Message +from email.policy import Policy + +class Generator: + def clone(self, fp: TextIO) -> 'Generator': ... + def write(self, s: str) -> None: ... + def __init__(self, outfp: TextIO, mangle_from_: bool = ..., + maxheaderlen: int = ..., *, + policy: Policy = ...) -> None: ... + def flatten(self, msg: Message, unixfrom: bool = ..., + linesep: Optional[str] =...) -> None: ... + +class BytesGenerator: + def clone(self, fp: TextIO) -> 'Generator': ... + def write(self, s: str) -> None: ... + def __init__(self, outfp: TextIO, mangle_from_: bool = ..., + maxheaderlen: int = ..., *, + policy: Policy = ...) -> None: ... + def flatten(self, msg: Message, unixfrom: bool = ..., + linesep: Optional[str] =...) -> None: ... + +class DecodedGenerator(Generator): + # TODO `fmt` is positional + def __init__(self, outfp: TextIO, mangle_from_: bool = ..., + maxheaderlen: int = ..., *, fmt: Optional[str]) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/header.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/header.pyi new file mode 100644 index 000000000..f446d4a93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/header.pyi @@ -0,0 +1,25 @@ +# Stubs for email.header (Python 3.4) + +from typing import Union, Optional, Any, List, Tuple +from email.charset import Charset + +class Header: + def __init__(self, s: Union[bytes, str, None] = ..., + charset: Union[Charset, str, None] = ..., + maxlinelen: Optional[int] = ..., + header_name: Optional[str] = ..., continuation_ws: str = ..., + errors: str = ...) -> None: ... + def append(self, s: Union[bytes, str], + charset: Union[Charset, str, None] = ..., + errors: str = ...) -> None: ... + def encode(self, splitchars: str = ..., maxlinelen: Optional[int] = ..., + linesep: str = ...) -> str: ... + def __str__(self) -> str: ... + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +def decode_header(header: Union[Header, str]) -> List[Tuple[bytes, Optional[str]]]: ... +def make_header(decoded_seq: List[Tuple[bytes, Optional[str]]], + maxlinelen: Optional[int] =..., + header_name: Optional[str] = ..., + continuation_ws: str = ...) -> Header: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/headerregistry.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/headerregistry.pyi new file mode 100644 index 000000000..d011eaa86 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/headerregistry.pyi @@ -0,0 +1,97 @@ +# Stubs for email.headerregistry (Python 3.4) + +from datetime import datetime as _datetime +from typing import Dict, Tuple, Optional, Any, Union, Mapping +from email.errors import MessageDefect +from email.policy import Policy + +class BaseHeader(str): + @property + def name(self) -> str: ... + @property + def defects(self) -> Tuple[MessageDefect, ...]: ... + @property + def max_count(self) -> Optional[int]: ... + def __new__(cls, name: str, value: Any) -> 'BaseHeader': ... + def init(self, *args: Any, **kw: Any) -> None: ... + def fold(self, *, policy: Policy) -> str: ... + +class UnstructuredHeader: + @classmethod + def parse(cls, string: str, kwds: Dict[str, Any]) -> None: ... + +class UniqueUnstructuredHeader(UnstructuredHeader): ... + +class DateHeader: + datetime = ... # type: _datetime + @classmethod + def parse(cls, string: Union[str, _datetime], + kwds: Dict[str, Any]) -> None: ... + +class UniqueDateHeader(DateHeader): ... + +class AddressHeader: + groups = ... # type: Tuple[Group, ...] + addresses = ... # type: Tuple[Address, ...] + @classmethod + def parse(cls, string: str, kwds: Dict[str, Any]) -> None: ... + +class UniqueAddressHeader(AddressHeader): ... + +class SingleAddressHeader(AddressHeader): + @property + def address(self) -> Address: ... + +class UniqueSingleAddressHeader(SingleAddressHeader): ... + +class MIMEVersionHeader: + version = ... # type: Optional[str] + major = ... # type: Optional[int] + minor = ... # type: Optional[int] + @classmethod + def parse(cls, string: str, kwds: Dict[str, Any]) -> None: ... + +class ParameterizedMIMEHeader: + params = ... # type: Mapping[str, Any] + @classmethod + def parse(cls, string: str, kwds: Dict[str, Any]) -> None: ... + +class ContentTypeHeader(ParameterizedMIMEHeader): + content_type = ... # type: str + maintype = ... # type: str + subtype = ... # type: str + +class ContentDispositionHeader(ParameterizedMIMEHeader): + content_disposition = ... # type: str + +class ContentTransferEncodingHeader: + cte = ... # type: str + @classmethod + def parse(cls, string: str, kwds: Dict[str, Any]) -> None: ... + +class HeaderRegistry: + def __init__(self, base_class: BaseHeader = ..., + default_class: BaseHeader = ..., + use_default_map: bool = ...) -> None: ... + def map_to_type(self, name: str, cls: BaseHeader) -> None: ... + def __getitem__(self, name: str) -> BaseHeader: ... + def __call__(self, name: str, value: Any) -> BaseHeader: ... + +class Address: + display_name = ... # type: str + username = ... # type: str + domain = ... # type: str + @property + def addr_spec(self) -> str: ... + def __init__(self, display_name: str = ..., + username: Optional[str] = ..., + domain: Optional[str] = ..., + addr_spec: Optional[str]=...) -> None: ... + def __str__(self) -> str: ... + +class Group: + display_name = ... # type: Optional[str] + addresses = ... # type: Tuple[Address, ...] + def __init__(self, display_name: Optional[str] = ..., + addresses: Optional[Tuple[Address, ...]] = ...) -> None: ... + def __str__(self) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/iterators.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/iterators.pyi new file mode 100644 index 000000000..6a69f39c9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/iterators.pyi @@ -0,0 +1,8 @@ +# Stubs for email.iterators (Python 3.4) + +from typing import Iterator, Optional +from email.message import Message + +def body_line_iterator(msg: Message, decode: bool = ...) -> Iterator[str]: ... +def typed_subpart_iterator(msg: Message, maintype: str = ..., + subtype: Optional[str] = ...) -> Iterator[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/message.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/message.pyi new file mode 100644 index 000000000..e89e6b0b5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/message.pyi @@ -0,0 +1,105 @@ +# Stubs for email.message (Python 3.4) + +from typing import ( + List, Optional, Union, Tuple, TypeVar, Generator, Sequence, Iterator, Any +) +import sys +from email.charset import Charset +from email.errors import MessageDefect +from email.header import Header +from email.policy import Policy +from email.contentmanager import ContentManager + +_T = TypeVar('_T') + +_PayloadType = Union[List[Message], str, bytes] +_CharsetType = Union[Charset, str, None] +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] +_ParamType = Union[str, Tuple[Optional[str], Optional[str], str]] +_HeaderType = Union[str, Header] + +class Message: + preamble = ... # type: Optional[str] + epilogue = ... # type: Optional[str] + defects = ... # type: List[MessageDefect] + def __str__(self) -> str: ... + def is_multipart(self) -> bool: ... + def set_unixfrom(self, unixfrom: str) -> None: ... + def get_unixfrom(self) -> Optional[str]: ... + def attach(self, payload: 'Message') -> None: ... + def get_payload(self, i: int = ..., decode: bool = ...) -> Optional[_PayloadType]: ... + def set_payload(self, payload: _PayloadType, + charset: _CharsetType = ...) -> None: ... + def set_charset(self, charset: _CharsetType) -> None: ... + def get_charset(self) -> _CharsetType: ... + def __len__(self) -> int: ... + def __contains__(self, name: str) -> bool: ... + def __getitem__(self, name: str) -> Optional[_HeaderType]: ... + def __setitem__(self, name: str, val: _HeaderType) -> None: ... + def __delitem__(self, name: str) -> None: ... + def keys(self) -> List[str]: ... + def values(self) -> List[_HeaderType]: ... + def items(self) -> List[Tuple[str, _HeaderType]]: ... + def get(self, name: str, failobj: _T = ...) -> Union[_HeaderType, _T]: ... + def get_all(self, name: str, failobj: _T = ...) -> Union[List[_HeaderType], _T]: ... + def add_header(self, _name: str, _value: str, **_params: _ParamsType) -> None: ... + def replace_header(self, _name: str, _value: _HeaderType) -> None: ... + def get_content_type(self) -> str: ... + def get_content_maintype(self) -> str: ... + def get_content_subtype(self) -> str: ... + def get_default_type(self) -> str: ... + def set_default_type(self, ctype: str) -> None: ... + def get_params(self, failobj: _T = ..., header: str = ..., + unquote: bool = ...) -> Union[List[Tuple[str, str]], _T]: ... + def get_param(self, param: str, failobj: _T = ..., header: str = ..., + unquote: bool = ...) -> Union[_T, _ParamType]: ... + def del_param(self, param: str, header: str = ..., + requote: bool = ...) -> None: ... + def set_type(self, type: str, header: str = ..., + requote: bool = ...) -> None: ... + def get_filename(self, failobj: _T = ...) -> Union[_T, str]: ... + def get_boundary(self, failobj: _T = ...) -> Union[_T, str]: ... + def set_boundary(self, boundary: str) -> None: ... + def get_content_charset(self, failobj: _T = ...) -> Union[_T, str]: ... + def get_charsets(self, failobj: _T = ...) -> Union[_T, List[str]]: ... + def walk(self) -> Generator['Message', None, None]: ... + if sys.version_info >= (3, 5): + def get_content_disposition(self) -> Optional[str]: ... + def as_string(self, unixfrom: bool = ..., maxheaderlen: int = ..., + policy: Optional[Policy] = ...) -> str: ... + def as_bytes(self, unixfrom: bool = ..., + policy: Optional[Policy] = ...) -> bytes: ... + def __bytes__(self) -> bytes: ... + def set_param(self, param: str, value: str, header: str = ..., + requote: bool = ..., charset: str = ..., + language: str = ..., replace: bool = ...) -> None: ... + def __init__(self, policy: Policy = ...) -> None: ... + +class MIMEPart(Message): + def get_body(self, + preferencelist: Sequence[str] = ...) -> Optional[Message]: ... + def iter_attachments(self) -> Iterator[Message]: ... + def iter_parts(self) -> Iterator[Message]: ... + def get_content(self, *args: Any, + content_manager: Optional[ContentManager] = ..., + **kw: Any) -> Any: ... + def set_content(self, *args: Any, + content_manager: Optional[ContentManager] = ..., + **kw: Any) -> None: ... + def make_related(self, boundary: Optional[str] = ...) -> None: ... + def make_alternative(self, boundary: Optional[str] = ...) -> None: ... + def make_mixed(self, boundary: Optional[str] = ...) -> None: ... + def add_related(self, *args: Any, + content_manager: Optional[ContentManager] = ..., + **kw: Any) -> None: ... + def add_alternative(self, *args: Any, + content_manager: Optional[ContentManager] = ..., + **kw: Any) -> None: ... + def add_attachement(self, *args: Any, + content_manager: Optional[ContentManager] = ..., + **kw: Any) -> None: ... + def clear(self) -> None: ... + def clear_content(self) -> None: ... + def is_attachment(self) -> bool: ... + +class EmailMessage(MIMEPart): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/application.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/application.pyi new file mode 100644 index 000000000..1aa0580ec --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/application.pyi @@ -0,0 +1,11 @@ +# Stubs for email.mime.application (Python 3.4) + +from typing import Callable, Optional, Tuple, Union +from email.mime.nonmultipart import MIMENonMultipart + +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] + +class MIMEApplication(MIMENonMultipart): + def __init__(self, _data: bytes, _subtype: str = ..., + _encoder: Callable[[MIMEApplication], None] = ..., + **_params: _ParamsType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/audio.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/audio.pyi new file mode 100644 index 000000000..2d2c90c2a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/audio.pyi @@ -0,0 +1,11 @@ +# Stubs for email.mime.audio (Python 3.4) + +from typing import Callable, Optional, Tuple, Union +from email.mime.nonmultipart import MIMENonMultipart + +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] + +class MIMEAudio(MIMENonMultipart): + def __init__(self, _audiodata: bytes, _subtype: Optional[str] = ..., + _encoder: Callable[[MIMEAudio], None] = ..., + **_params: _ParamsType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/base.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/base.pyi new file mode 100644 index 000000000..448d34be1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/base.pyi @@ -0,0 +1,10 @@ +# Stubs for email.mime.base (Python 3.4) + +from typing import Optional, Tuple, Union +import email.message + +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] + +class MIMEBase(email.message.Message): + def __init__(self, _maintype: str, _subtype: str, + **_params: _ParamsType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/image.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/image.pyi new file mode 100644 index 000000000..9ec5deba0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/image.pyi @@ -0,0 +1,11 @@ +# Stubs for email.mime.image (Python 3.4) + +from typing import Callable, Optional, Tuple, Union +from email.mime.nonmultipart import MIMENonMultipart + +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] + +class MIMEImage(MIMENonMultipart): + def __init__(self, _imagedata: bytes, _subtype: Optional[str] = ..., + _encoder: Callable[[MIMEImage], None] = ..., + **_params: _ParamsType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/message.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/message.pyi new file mode 100644 index 000000000..561e8c35f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/message.pyi @@ -0,0 +1,7 @@ +# Stubs for email.mime.message (Python 3.4) + +from email.message import Message +from email.mime.nonmultipart import MIMENonMultipart + +class MIMEMessage(MIMENonMultipart): + def __init__(self, _msg: Message, _subtype: str = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/multipart.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/multipart.pyi new file mode 100644 index 000000000..ea5eba15e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/multipart.pyi @@ -0,0 +1,12 @@ +# Stubs for email.mime.multipart (Python 3.4) + +from typing import Optional, Sequence, Tuple, Union +from email.message import Message +from email.mime.base import MIMEBase + +_ParamsType = Union[str, None, Tuple[str, Optional[str], str]] + +class MIMEMultipart(MIMEBase): + def __init__(self, _subtype: str = ..., boundary: Optional[str] = ..., + _subparts: Optional[Sequence[Message]] = ..., + **_params: _ParamsType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/nonmultipart.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/nonmultipart.pyi new file mode 100644 index 000000000..1fd3ea98b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/nonmultipart.pyi @@ -0,0 +1,5 @@ +# Stubs for email.mime.nonmultipart (Python 3.4) + +from email.mime.base import MIMEBase + +class MIMENonMultipart(MIMEBase): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/text.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/text.pyi new file mode 100644 index 000000000..73adaf5f6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/mime/text.pyi @@ -0,0 +1,8 @@ +# Stubs for email.mime.text (Python 3.4) + +from typing import Optional +from email.mime.nonmultipart import MIMENonMultipart + +class MIMEText(MIMENonMultipart): + def __init__(self, _text: str, _subtype: str = ..., + _charset: Optional[str] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/parser.pyi new file mode 100644 index 000000000..884e6de9c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/parser.pyi @@ -0,0 +1,33 @@ +# Stubs for email.parser (Python 3.4) + +import email.feedparser +from email.message import Message +from typing import Callable, Optional, TextIO, BinaryIO +from email.policy import Policy + +FeedParser = email.feedparser.FeedParser +BytesFeedParser = email.feedparser.BytesFeedParser + +class Parser: + def __init__(self, _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> None: ... + def parse(self, fp: TextIO, headersonly: bool = ...) -> Message: ... + def parsestr(self, text: str, headersonly: bool = ...) -> Message: ... + +class HeaderParser(Parser): + def __init__(self, _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> None: ... + def parse(self, fp: TextIO, headersonly: bool = ...) -> Message: ... + def parsestr(self, text: str, headersonly: bool = ...) -> Message: ... + +class BytesHeaderParser(BytesParser): + def __init__(self, _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> None: ... + def parse(self, fp: BinaryIO, headersonly: bool = ...) -> Message: ... + def parsestr(self, text: str, headersonly: bool = ...) -> Message: ... + +class BytesParser: + def __init__(self, _class: Callable[[], Message] = ..., *, + policy: Policy = ...) -> None: ... + def parse(self, fp: BinaryIO, headersonly: bool = ...) -> Message: ... + def parsestr(self, text: str, headersonly: bool = ...) -> Message: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/policy.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/policy.pyi new file mode 100644 index 000000000..dbb66448a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/policy.pyi @@ -0,0 +1,64 @@ +# Stubs for email.policy (Python 3.4) + +from abc import abstractmethod +from typing import Any, List, Optional, Tuple, Union, Callable +import sys +from email.message import Message +from email.errors import MessageDefect +from email.header import Header +from email.contentmanager import ContentManager + +class Policy: + max_line_length = ... # type: Optional[int] + linesep = ... # type: str + cte_type = ... # type: str + raise_on_defect = ... # type: bool + if sys.version_info >= (3, 5): + mange_from = ... # type: bool + def __init__(self, **kw: Any) -> None: ... + def clone(self, **kw: Any) -> 'Policy': ... + def handle_defect(self, obj: Message, + defect: MessageDefect) -> None: ... + def register_defect(self, obj: Message, + defect: MessageDefect) -> None: ... + def header_max_count(self, name: str) -> Optional[int]: ... + @abstractmethod + def header_source_parse(self, sourcelines: List[str]) -> str: ... + @abstractmethod + def header_store_parse(self, name: str, + value: str) -> Tuple[str, str]: ... + @abstractmethod + def header_fetch_parse(self, name: str, + value: str) -> str: ... + @abstractmethod + def fold(self, name: str, value: str) -> str: ... + @abstractmethod + def fold_binary(self, name: str, value: str) -> bytes: ... + +class Compat32(Policy): + def header_source_parse(self, sourcelines: List[str]) -> str: ... + def header_store_parse(self, name: str, + value: str) -> Tuple[str, str]: ... + def header_fetch_parse(self, name: str, value: str) -> Union[str, Header]: ... # type: ignore + def fold(self, name: str, value: str) -> str: ... + def fold_binary(self, name: str, value: str) -> bytes: ... + +compat32 = ... # type: Compat32 + +class EmailPolicy(Policy): + utf8 = ... # type: bool + refold_source = ... # type: str + header_factory = ... # type: Callable[[str, str], str] + content_manager = ... # type: ContentManager + def header_source_parse(self, sourcelines: List[str]) -> str: ... + def header_store_parse(self, name: str, + value: str) -> Tuple[str, str]: ... + def header_fetch_parse(self, name: str, value: str) -> str: ... + def fold(self, name: str, value: str) -> str: ... + def fold_binary(self, name: str, value: str) -> bytes: ... + +default = ... # type: EmailPolicy +SMTP = ... # type: EmailPolicy +SMTPUTF8 = ... # type: EmailPolicy +HTTP = ... # type: EmailPolicy +strict = ... # type: EmailPolicy diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/utils.pyi new file mode 100644 index 000000000..6c0a18319 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/email/utils.pyi @@ -0,0 +1,33 @@ +# Stubs for email.utils (Python 3.4) + +from typing import List, Optional, Tuple, Union +from email.charset import Charset +import datetime + +_ParamType = Union[str, Tuple[Optional[str], Optional[str], str]] +_PDTZ = Tuple[int, int, int, int, int, int, int, int, int, Optional[int]] + +def quote(str: str) -> str: ... +def unquote(str: str) -> str: ... +def parseaddr(address: Optional[str]) -> Tuple[str, str]: ... +def formataddr(pair: Tuple[Optional[str], str], + charset: Union[str, Charset] = ...) -> str: ... +def getaddresses(fieldvalues: List[str]) -> List[Tuple[str, str]]: ... +def parsedate(date: str) -> Optional[Tuple[int, int, int, int, int, int, int, int, int]]: ... +def parsedate_tz(date: str) -> Optional[_PDTZ]: ... +def parsedate_to_datetime(date: str) -> datetime.datetime: ... +def mktime_tz(tuple: _PDTZ) -> int: ... +def formatdate(timeval: Optional[float] = ..., localtime: bool = ..., + usegmt: bool = ...) -> str: ... +def format_datetime(dt: datetime.datetime, usegmt: bool = ...) -> str: ... +def localtime(dt: Optional[datetime.datetime] = ...) -> datetime.datetime: ... +def make_msgid(idstring: Optional[str] = ..., + domain: Optional[str] = ...) -> str: ... +def decode_rfc2231(s: str) -> Tuple[Optional[str], Optional[str], str]: ... +def encode_rfc2231(s: str, charset: Optional[str] = ..., + language: Optional[str] = ...) -> str: ... +def collapse_rfc2231_value(value: _ParamType, errors: str = ..., + fallback_charset: str = ...) -> str: ... +def decode_params( + params: List[Tuple[str, str]] +) -> List[Tuple[str, _ParamType]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/encodings/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/encodings/__init__.pyi new file mode 100644 index 000000000..2ae6c0a93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/encodings/__init__.pyi @@ -0,0 +1,6 @@ +import codecs + +import typing + +def search_function(encoding: str) -> codecs.CodecInfo: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/encodings/utf_8.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/encodings/utf_8.pyi new file mode 100644 index 000000000..d38bd58d0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/encodings/utf_8.pyi @@ -0,0 +1,15 @@ +import codecs +from typing import Text, Tuple + +class IncrementalEncoder(codecs.IncrementalEncoder): + def encode(self, input: Text, final: bool = ...) -> bytes: ... + +class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def _buffer_decode(self, input: bytes, errors: str, final: bool) -> Tuple[Text, int]: ... + +class StreamWriter(codecs.StreamWriter): ... +class StreamReader(codecs.StreamReader): ... + +def getregentry() -> codecs.CodecInfo: ... +def encode(input: Text, errors: Text = ...) -> bytes: ... +def decode(input: bytes, errors: Text = ...) -> Text: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/fcntl.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/fcntl.pyi new file mode 100644 index 000000000..1ff20d60d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/fcntl.pyi @@ -0,0 +1,96 @@ +# Stubs for fcntl +from io import IOBase +from typing import Any, IO, Union + +FASYNC = ... # type: int +FD_CLOEXEC = ... # type: int +DN_ACCESS = ... # type: int +DN_ATTRIB = ... # type: int +DN_CREATE = ... # type: int +DN_DELETE = ... # type: int +DN_MODIFY = ... # type: int +DN_MULTISHOT = ... # type: int +DN_RENAME = ... # type: int +F_DUPFD = ... # type: int +F_DUPFD_CLOEXEC = ... # type: int +F_FULLFSYNC = ... # type: int +F_EXLCK = ... # type: int +F_GETFD = ... # type: int +F_GETFL = ... # type: int +F_GETLEASE = ... # type: int +F_GETLK = ... # type: int +F_GETLK64 = ... # type: int +F_GETOWN = ... # type: int +F_NOCACHE = ... # type: int +F_GETSIG = ... # type: int +F_NOTIFY = ... # type: int +F_RDLCK = ... # type: int +F_SETFD = ... # type: int +F_SETFL = ... # type: int +F_SETLEASE = ... # type: int +F_SETLK = ... # type: int +F_SETLK64 = ... # type: int +F_SETLKW = ... # type: int +F_SETLKW64 = ... # type: int +F_SETOWN = ... # type: int +F_SETSIG = ... # type: int +F_SHLCK = ... # type: int +F_UNLCK = ... # type: int +F_WRLCK = ... # type: int +I_ATMARK = ... # type: int +I_CANPUT = ... # type: int +I_CKBAND = ... # type: int +I_FDINSERT = ... # type: int +I_FIND = ... # type: int +I_FLUSH = ... # type: int +I_FLUSHBAND = ... # type: int +I_GETBAND = ... # type: int +I_GETCLTIME = ... # type: int +I_GETSIG = ... # type: int +I_GRDOPT = ... # type: int +I_GWROPT = ... # type: int +I_LINK = ... # type: int +I_LIST = ... # type: int +I_LOOK = ... # type: int +I_NREAD = ... # type: int +I_PEEK = ... # type: int +I_PLINK = ... # type: int +I_POP = ... # type: int +I_PUNLINK = ... # type: int +I_PUSH = ... # type: int +I_RECVFD = ... # type: int +I_SENDFD = ... # type: int +I_SETCLTIME = ... # type: int +I_SETSIG = ... # type: int +I_SRDOPT = ... # type: int +I_STR = ... # type: int +I_SWROPT = ... # type: int +I_UNLINK = ... # type: int +LOCK_EX = ... # type: int +LOCK_MAND = ... # type: int +LOCK_NB = ... # type: int +LOCK_READ = ... # type: int +LOCK_RW = ... # type: int +LOCK_SH = ... # type: int +LOCK_UN = ... # type: int +LOCK_WRITE = ... # type: int + +_AnyFile = Union[int, IO[Any], IOBase] + +# TODO All these return either int or bytes depending on the value of +# cmd (not on the type of arg). +def fcntl(fd: _AnyFile, + cmd: int, + arg: Union[int, bytes] = ...) -> Any: ... +# TODO This function accepts any object supporting a buffer interface, +# as arg, is there a better way to express this than bytes? +def ioctl(fd: _AnyFile, + request: int, + arg: Union[int, bytes] = ..., + mutate_flag: bool = ...) -> Any: ... +def flock(fd: _AnyFile, operation: int) -> None: ... +def lockf(fd: _AnyFile, + cmd: int, + len: int = ..., + start: int = ..., + whence: int = ...) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/fnmatch.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/fnmatch.pyi new file mode 100644 index 000000000..4f99b4aaf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/fnmatch.pyi @@ -0,0 +1,11 @@ +# Stubs for fnmatch + +# Based on http://docs.python.org/3.2/library/fnmatch.html and +# python-lib/fnmatch.py + +from typing import Iterable, List, AnyStr + +def fnmatch(name: AnyStr, pat: AnyStr) -> bool: ... +def fnmatchcase(name: AnyStr, pat: AnyStr) -> bool: ... +def filter(names: Iterable[AnyStr], pat: AnyStr) -> List[AnyStr]: ... +def translate(pat: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/functools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/functools.pyi new file mode 100644 index 000000000..d3a898427 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/functools.pyi @@ -0,0 +1,76 @@ +import sys +from typing import Any, Callable, Generic, Dict, Iterable, Mapping, Optional, Sequence, Tuple, Type, TypeVar, NamedTuple, Union, overload + +_AnyCallable = Callable[..., Any] + +_T = TypeVar("_T") +_S = TypeVar("_S") +@overload +def reduce(function: Callable[[_T, _S], _T], + sequence: Iterable[_S], initial: _T) -> _T: ... +@overload +def reduce(function: Callable[[_T, _T], _T], + sequence: Iterable[_T]) -> _T: ... + + +class _CacheInfo(NamedTuple('CacheInfo', [ + ('hits', int), + ('misses', int), + ('maxsize', int), + ('currsize', int) +])): ... + +class _lru_cache_wrapper(Generic[_T]): + __wrapped__ = ... # type: Callable[..., _T] + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... + def cache_info(self) -> _CacheInfo: ... + def cache_clear(self) -> None: ... + +class lru_cache(): + def __init__(self, maxsize: Optional[int] = ..., typed: bool = ...) -> None: ... + def __call__(self, f: Callable[..., _T]) -> _lru_cache_wrapper[_T]: ... + + +WRAPPER_ASSIGNMENTS = ... # type: Sequence[str] +WRAPPER_UPDATES = ... # type: Sequence[str] + +def update_wrapper(wrapper: _AnyCallable, wrapped: _AnyCallable, assigned: Sequence[str] = ..., + updated: Sequence[str] = ...) -> _AnyCallable: ... +def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_AnyCallable], _AnyCallable]: ... +def total_ordering(cls: type) -> type: ... +def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], Any]: ... + +class partial(Generic[_T]): + func = ... # type: Callable[..., _T] + args = ... # type: Tuple[Any, ...] + keywords = ... # type: Dict[str, Any] + def __init__(self, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... + +# With protocols, this could change into a generic protocol that defines __get__ and returns _T +_Descriptor = Any + +class partialmethod(Generic[_T]): + func: Union[Callable[..., _T], _Descriptor] + args: Tuple[Any, ...] + keywords: Dict[str, Any] + + @overload + def __init__(self, func: Callable[..., _T], *args: Any, **keywords: Any) -> None: ... + @overload + def __init__(self, func: _Descriptor, *args: Any, **keywords: Any) -> None: ... + def __get__(self, obj: Any, cls: Type[Any]) -> Callable[..., _T]: ... + @property + def __isabstractmethod__(self) -> bool: ... + +class _SingleDispatchCallable(Generic[_T]): + registry = ... # type: Mapping[Any, Callable[..., _T]] + def dispatch(self, cls: Any) -> Callable[..., _T]: ... + @overload + def register(self, cls: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + @overload + def register(self, cls: Any, func: Callable[..., _T]) -> Callable[..., _T]: ... + def _clear_cache(self) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... + +def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gc.pyi new file mode 100644 index 000000000..ec94f29c5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gc.pyi @@ -0,0 +1,28 @@ +# Stubs for gc + +from typing import Any, Dict, List, Tuple + + +DEBUG_COLLECTABLE = ... # type: int +DEBUG_LEAK = ... # type: int +DEBUG_SAVEALL = ... # type: int +DEBUG_STATS = ... # type: int +DEBUG_UNCOLLECTABLE = ... # type: int +callbacks = ... # type: List[Any] +garbage = ... # type: List[Any] + +def collect(generations: int = ...) -> int: ... +def disable() -> None: ... +def enable() -> None: ... +def get_count() -> Tuple[int, int, int]: ... +def get_debug() -> int: ... +def get_objects() -> List[Any]: ... +def get_referents(*objs: Any) -> List[Any]: ... +def get_referrers(*objs: Any) -> List[Any]: ... +def get_stats() -> List[Dict[str, Any]]: ... +def get_threshold() -> Tuple[int, int, int]: ... +def is_tracked(obj: Any) -> bool: ... +def isenabled() -> bool: ... +def set_debug(flags: int) -> None: ... +def set_threshold(threshold0: int, threshold1: int = ..., + threshold2: int = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/getopt.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/getopt.pyi new file mode 100644 index 000000000..dc75699bc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/getopt.pyi @@ -0,0 +1,19 @@ +# Stubs for getopt + +# Based on http://docs.python.org/3.2/library/getopt.html + +from typing import List, Tuple + +def getopt(args: List[str], shortopts: str, + longopts: List[str]=...) -> Tuple[List[Tuple[str, str]], + List[str]]: ... + +def gnu_getopt(args: List[str], shortopts: str, + longopts: List[str]=...) -> Tuple[List[Tuple[str, str]], + List[str]]: ... + +class GetoptError(Exception): + msg = ... # type: str + opt = ... # type: str + +error = GetoptError diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/getpass.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/getpass.pyi new file mode 100644 index 000000000..55a8433fc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/getpass.pyi @@ -0,0 +1,12 @@ +# Stubs for getpass + +from typing import Optional, TextIO + + +def getpass(prompt: str = ..., stream: Optional[TextIO] = ...) -> str: ... + + +def getuser() -> str: ... + + +class GetPassWarning(UserWarning): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gettext.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gettext.pyi new file mode 100644 index 000000000..04bf34a8a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gettext.pyi @@ -0,0 +1,44 @@ +# Stubs for gettext (Python 3.4) + +from typing import Any, IO, List, Optional, Union, Callable + +class NullTranslations: + def __init__(self, fp: IO[str] = ...) -> None: ... + def add_fallback(self, fallback: NullTranslations) -> None: ... + def gettext(self, message: str) -> str: ... + def lgettext(self, message: str) -> str: ... + def ngettext(self, singular: str, plural: str, n: int) -> str: ... + def lngettext(self, singular: str, plural: str, n: int) -> str: ... + def info(self) -> Any: ... + def charset(self) -> Any: ... + def output_charset(self) -> Any: ... + def set_output_charset(self, charset: Any) -> None: ... + def install(self, names: List[str] = ...) -> None: ... + +class GNUTranslations(NullTranslations): + LE_MAGIC = ... # type: int + BE_MAGIC = ... # type: int + +def find(domain: str, localedir: str = ..., languages: List[str] = ..., + all: bool = ...): ... + +def translation(domain: str, localedir: str = ..., languages: List[str] = ..., + class_: Callable[[IO[str]], NullTranslations] = ..., + fallback: bool =..., codeset: Any = ...) -> NullTranslations: ... + +def install(domain: str, localedir: str = ..., codeset: Any = ..., + names: List[str] = ...): ... + +def textdomain(domain: str = ...) -> str: ... +def bindtextdomain(domain: str, localedir: str = ...) -> str: ... +def bind_textdomain_codeset(domain: str, codeset: str = ...) -> str: ... +def dgettext(domain: str, message: str) -> str: ... +def ldgettext(domain: str, message: str) -> str: ... +def dngettext(domain: str, singular: str, plural: str, n: int) -> str: ... +def ldngettext(domain: str, singular: str, plural: str, n: int) -> str: ... +def gettext(message: str) -> str: ... +def lgettext(message: str) -> str: ... +def ngettext(singular: str, plural: str, n: int) -> str: ... +def lngettext(singular: str, plural: str, n: int) -> str: ... + +Catalog = translation diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/glob.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/glob.pyi new file mode 100644 index 000000000..701c4cacc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/glob.pyi @@ -0,0 +1,21 @@ +# Stubs for glob +# Based on http://docs.python.org/3/library/glob.html + +from typing import List, Iterator, AnyStr +import sys + +if sys.version_info >= (3, 6): + def glob0(dirname: AnyStr, pattern: AnyStr) -> List[AnyStr]: ... +else: + def glob0(dirname: AnyStr, basename: AnyStr) -> List[AnyStr]: ... + +def glob1(dirname: AnyStr, pattern: AnyStr) -> List[AnyStr]: ... + +if sys.version_info >= (3, 5): + def glob(pathname: AnyStr, *, recursive: bool = ...) -> List[AnyStr]: ... + def iglob(pathname: AnyStr, *, recursive: bool = ...) -> Iterator[AnyStr]: ... +else: + def glob(pathname: AnyStr) -> List[AnyStr]: ... + def iglob(pathname: AnyStr) -> Iterator[AnyStr]: ... + +def escape(pathname: AnyStr) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gzip.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gzip.pyi new file mode 100644 index 000000000..024413b09 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/gzip.pyi @@ -0,0 +1,49 @@ +from typing import Any, IO, Optional +from os.path import _PathType +import _compression +import zlib + +def open(filename, mode: str = ..., compresslevel: int = ..., encoding: Optional[str] = ..., errors: Optional[str] = ..., newline: Optional[str] = ...) -> IO[Any]: ... + +class _PaddedFile: + file: IO[bytes] + def __init__(self, f: IO[bytes], prepend: bytes = ...) -> None: ... + def read(self, size: int) -> bytes: ... + def prepend(self, prepend: bytes = ...) -> None: ... + def seek(self, off: int) -> int: ... + def seekable(self) -> bool: ... + +class GzipFile(_compression.BaseStream): + myfileobj: Optional[IO[bytes]] + mode: str + name: str + compress: zlib._Compress + fileobj: IO[bytes] + def __init__(self, filename: Optional[_PathType] = ..., mode: Optional[str] = ..., compresslevel: int = ..., fileobj: Optional[IO[bytes]] = ..., mtime: Optional[float] = ...) -> None: ... + @property + def filename(self) -> str: ... + @property + def mtime(self): ... + crc: int + def write(self, data: bytes) -> int: ... + def read(self, size: Optional[int] = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + def peek(self, n: int) -> bytes: ... + @property + def closed(self) -> bool: ... + def close(self) -> None: ... + def flush(self, zlib_mode: int = ...) -> None: ... + def fileno(self) -> int: ... + def rewind(self) -> None: ... + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def seekable(self) -> bool: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def readline(self, size: int = ...) -> bytes: ... + +class _GzipReader(_compression.DecompressReader): + def __init__(self, fp: IO[bytes]) -> None: ... + def read(self, size: int = ...) -> bytes: ... + +def compress(data, compresslevel: int = ...) -> bytes: ... +def decompress(data: bytes) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/hashlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/hashlib.pyi new file mode 100644 index 000000000..90bce96b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/hashlib.pyi @@ -0,0 +1,69 @@ +# Stubs for hashlib + +import sys +from typing import AbstractSet, Optional, Union + +_DataType = Union[bytes, bytearray, memoryview] + +class _Hash(object): + digest_size = ... # type: int + block_size = ... # type: int + + # [Python documentation note] Changed in version 3.4: The name attribute has + # been present in CPython since its inception, but until Python 3.4 was not + # formally specified, so may not exist on some platforms + name = ... # type: str + + def __init__(self, data: _DataType = ...) -> None: ... + + def copy(self) -> _Hash: ... + def digest(self) -> bytes: ... + def hexdigest(self) -> str: ... + def update(self, arg: _DataType) -> None: ... + +def md5(arg: _DataType = ...) -> _Hash: ... +def sha1(arg: _DataType = ...) -> _Hash: ... +def sha224(arg: _DataType = ...) -> _Hash: ... +def sha256(arg: _DataType = ...) -> _Hash: ... +def sha384(arg: _DataType = ...) -> _Hash: ... +def sha512(arg: _DataType = ...) -> _Hash: ... + +def new(name: str, data: _DataType = ...) -> _Hash: ... + +algorithms_guaranteed = ... # type: AbstractSet[str] +algorithms_available = ... # type: AbstractSet[str] + +def pbkdf2_hmac(hash_name: str, password: _DataType, salt: _DataType, iterations: int, dklen: Optional[int] = ...) -> bytes: ... + +if sys.version_info >= (3, 6): + class _VarLenHash(object): + digest_size = ... # type: int + block_size = ... # type: int + name = ... # type: str + + def __init__(self, data: _DataType = ...) -> None: ... + + def copy(self) -> _VarLenHash: ... + def digest(self, length: int) -> bytes: ... + def hexdigest(self, length: int) -> str: ... + def update(self, arg: _DataType) -> None: ... + + sha3_224 = _Hash + sha3_256 = _Hash + sha3_384 = _Hash + sha3_512 = _Hash + shake_128 = _VarLenHash + shake_256 = _VarLenHash + + def scrypt(password: _DataType, *, salt: _DataType, n: int, r: int, p: int, maxmem: int = ..., dklen: int = ...) -> bytes: ... + + class _BlakeHash(_Hash): + MAX_DIGEST_SIZE = ... # type: int + MAX_KEY_SIZE = ... # type: int + PERSON_SIZE = ... # type: int + SALT_SIZE = ... # type: int + + def __init__(self, data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> None: ... + + blake2b = _BlakeHash + blake2s = _BlakeHash diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/heapq.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/heapq.pyi new file mode 100644 index 000000000..5c49dfac1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/heapq.pyi @@ -0,0 +1,23 @@ +# Stubs for heapq + +# Based on http://docs.python.org/3.2/library/heapq.html + +import sys +from typing import TypeVar, List, Iterable, Any, Callable, Optional + +_T = TypeVar('_T') + +def heappush(heap: List[_T], item: _T) -> None: ... +def heappop(heap: List[_T]) -> _T: ... +def heappushpop(heap: List[_T], item: _T) -> _T: ... +def heapify(x: List[_T]) -> None: ... +def heapreplace(heap: List[_T], item: _T) -> _T: ... +if sys.version_info >= (3, 5): + def merge(*iterables: Iterable[_T], key: Callable[[_T], Any] = ..., + reverse: bool = ...) -> Iterable[_T]: ... +else: + def merge(*iterables: Iterable[_T]) -> Iterable[_T]: ... +def nlargest(n: int, iterable: Iterable[_T], + key: Optional[Callable[[_T], Any]] = ...) -> List[_T]: ... +def nsmallest(n: int, iterable: Iterable[_T], + key: Callable[[_T], Any] = ...) -> List[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/__init__.pyi new file mode 100644 index 000000000..af2a80021 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/__init__.pyi @@ -0,0 +1,4 @@ +from typing import AnyStr + +def escape(s: AnyStr, quote: bool = ...) -> AnyStr: ... +def unescape(s: AnyStr) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/entities.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/entities.pyi new file mode 100644 index 000000000..470217b0f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/entities.pyi @@ -0,0 +1,6 @@ +from typing import Any + +name2codepoint = ... # type: Any +html5 = ... # type: Any +codepoint2name = ... # type: Any +entitydefs = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/parser.pyi new file mode 100644 index 000000000..102a2cc0e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/html/parser.pyi @@ -0,0 +1,31 @@ +from typing import List, Tuple +from _markupbase import ParserBase +import sys + +class HTMLParser(ParserBase): + if sys.version_info >= (3, 5): + def __init__(self, *, convert_charrefs: bool = ...) -> None: ... + else: + def __init__(self, strict: bool = ..., *, + convert_charrefs: bool = ...) -> None: ... + def feed(self, feed: str) -> None: ... + def close(self) -> None: ... + def reset(self) -> None: ... + def getpos(self) -> Tuple[int, int]: ... + def get_starttag_text(self) -> str: ... + + def handle_starttag(self, tag: str, + attrs: List[Tuple[str, str]]) -> None: ... + def handle_endtag(self, tag: str) -> None: ... + def handle_startendtag(self, tag: str, + attrs: List[Tuple[str, str]]) -> None: ... + def handle_data(self, data: str) -> None: ... + def handle_entityref(self, name: str) -> None: ... + def handle_charref(self, name: str) -> None: ... + def handle_comment(self, data: str) -> None: ... + def handle_decl(self, decl: str) -> None: ... + def handle_pi(self, data: str) -> None: ... + def unknown_decl(self, data: str) -> None: ... + +if sys.version_info < (3, 5): + class HTMLParseError(Exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/__init__.pyi new file mode 100644 index 000000000..345d8f26e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/__init__.pyi @@ -0,0 +1,69 @@ +import sys + +from enum import IntEnum + +if sys.version_info >= (3, 5): + class HTTPStatus(IntEnum): + + def __init__(self, *a) -> None: ... + + phrase = ... # type: str + description = ... # type: str + + CONTINUE = ... # type: HTTPStatus + SWITCHING_PROTOCOLS = ... # type: HTTPStatus + PROCESSING = ... # type: HTTPStatus + OK = ... # type: HTTPStatus + CREATED = ... # type: HTTPStatus + ACCEPTED = ... # type: HTTPStatus + NON_AUTHORITATIVE_INFORMATION = ... # type: HTTPStatus + NO_CONTENT = ... # type: HTTPStatus + RESET_CONTENT = ... # type: HTTPStatus + PARTIAL_CONTENT = ... # type: HTTPStatus + MULTI_STATUS = ... # type: HTTPStatus + ALREADY_REPORTED = ... # type: HTTPStatus + IM_USED = ... # type: HTTPStatus + MULTIPLE_CHOICES = ... # type: HTTPStatus + MOVED_PERMANENTLY = ... # type: HTTPStatus + FOUND = ... # type: HTTPStatus + SEE_OTHER = ... # type: HTTPStatus + NOT_MODIFIED = ... # type: HTTPStatus + USE_PROXY = ... # type: HTTPStatus + TEMPORARY_REDIRECT = ... # type: HTTPStatus + PERMANENT_REDIRECT = ... # type: HTTPStatus + BAD_REQUEST = ... # type: HTTPStatus + UNAUTHORIZED = ... # type: HTTPStatus + PAYMENT_REQUIRED = ... # type: HTTPStatus + FORBIDDEN = ... # type: HTTPStatus + NOT_FOUND = ... # type: HTTPStatus + METHOD_NOT_ALLOWED = ... # type: HTTPStatus + NOT_ACCEPTABLE = ... # type: HTTPStatus + PROXY_AUTHENTICATION_REQUIRED = ... # type: HTTPStatus + REQUEST_TIMEOUT = ... # type: HTTPStatus + CONFLICT = ... # type: HTTPStatus + GONE = ... # type: HTTPStatus + LENGTH_REQUIRED = ... # type: HTTPStatus + PRECONDITION_FAILED = ... # type: HTTPStatus + REQUEST_ENTITY_TOO_LARGE = ... # type: HTTPStatus + REQUEST_URI_TOO_LONG = ... # type: HTTPStatus + UNSUPPORTED_MEDIA_TYPE = ... # type: HTTPStatus + REQUESTED_RANGE_NOT_SATISFIABLE = ... # type: HTTPStatus + EXPECTATION_FAILED = ... # type: HTTPStatus + UNPROCESSABLE_ENTITY = ... # type: HTTPStatus + LOCKED = ... # type: HTTPStatus + FAILED_DEPENDENCY = ... # type: HTTPStatus + UPGRADE_REQUIRED = ... # type: HTTPStatus + PRECONDITION_REQUIRED = ... # type: HTTPStatus + TOO_MANY_REQUESTS = ... # type: HTTPStatus + REQUEST_HEADER_FIELDS_TOO_LARGE = ... # type: HTTPStatus + INTERNAL_SERVER_ERROR = ... # type: HTTPStatus + NOT_IMPLEMENTED = ... # type: HTTPStatus + BAD_GATEWAY = ... # type: HTTPStatus + SERVICE_UNAVAILABLE = ... # type: HTTPStatus + GATEWAY_TIMEOUT = ... # type: HTTPStatus + HTTP_VERSION_NOT_SUPPORTED = ... # type: HTTPStatus + VARIANT_ALSO_NEGOTIATES = ... # type: HTTPStatus + INSUFFICIENT_STORAGE = ... # type: HTTPStatus + LOOP_DETECTED = ... # type: HTTPStatus + NOT_EXTENDED = ... # type: HTTPStatus + NETWORK_AUTHENTICATION_REQUIRED = ... # type: HTTPStatus diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/client.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/client.pyi new file mode 100644 index 000000000..419fe1b83 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/client.pyi @@ -0,0 +1,189 @@ +from typing import ( + Any, Dict, IO, Iterable, List, Iterator, Mapping, Optional, Tuple, Type, TypeVar, + Union, + overload, + BinaryIO, +) +import email.message +import io +from socket import socket +import sys +import ssl +import types + +_DataType = Union[bytes, IO[Any], Iterable[bytes], str] +_T = TypeVar('_T') + +HTTP_PORT = ... # type: int +HTTPS_PORT = ... # type: int + +CONTINUE = ... # type: int +SWITCHING_PROTOCOLS = ... # type: int +PROCESSING = ... # type: int + +OK = ... # type: int +CREATED = ... # type: int +ACCEPTED = ... # type: int +NON_AUTHORITATIVE_INFORMATION = ... # type: int +NO_CONTENT = ... # type: int +RESET_CONTENT = ... # type: int +PARTIAL_CONTENT = ... # type: int +MULTI_STATUS = ... # type: int +IM_USED = ... # type: int + +MULTIPLE_CHOICES = ... # type: int +MOVED_PERMANENTLY = ... # type: int +FOUND = ... # type: int +SEE_OTHER = ... # type: int +NOT_MODIFIED = ... # type: int +USE_PROXY = ... # type: int +TEMPORARY_REDIRECT = ... # type: int + +BAD_REQUEST = ... # type: int +UNAUTHORIZED = ... # type: int +PAYMENT_REQUIRED = ... # type: int +FORBIDDEN = ... # type: int +NOT_FOUND = ... # type: int +METHOD_NOT_ALLOWED = ... # type: int +NOT_ACCEPTABLE = ... # type: int +PROXY_AUTHENTICATION_REQUIRED = ... # type: int +REQUEST_TIMEOUT = ... # type: int +CONFLICT = ... # type: int +GONE = ... # type: int +LENGTH_REQUIRED = ... # type: int +PRECONDITION_FAILED = ... # type: int +REQUEST_ENTITY_TOO_LARGE = ... # type: int +REQUEST_URI_TOO_LONG = ... # type: int +UNSUPPORTED_MEDIA_TYPE = ... # type: int +REQUESTED_RANGE_NOT_SATISFIABLE = ... # type: int +EXPECTATION_FAILED = ... # type: int +UNPROCESSABLE_ENTITY = ... # type: int +LOCKED = ... # type: int +FAILED_DEPENDENCY = ... # type: int +UPGRADE_REQUIRED = ... # type: int +PRECONDITION_REQUIRED = ... # type: int +TOO_MANY_REQUESTS = ... # type: int +REQUEST_HEADER_FIELDS_TOO_LARGE = ... # type: int + +INTERNAL_SERVER_ERROR = ... # type: int +NOT_IMPLEMENTED = ... # type: int +BAD_GATEWAY = ... # type: int +SERVICE_UNAVAILABLE = ... # type: int +GATEWAY_TIMEOUT = ... # type: int +HTTP_VERSION_NOT_SUPPORTED = ... # type: int +INSUFFICIENT_STORAGE = ... # type: int +NOT_EXTENDED = ... # type: int +NETWORK_AUTHENTICATION_REQUIRED = ... # type: int + +responses = ... # type: Dict[int, str] + +class HTTPMessage(email.message.Message): ... + +if sys.version_info >= (3, 5): + # Ignore errors to work around python/mypy#5027 + class HTTPResponse(io.BufferedIOBase, BinaryIO): # type: ignore + msg = ... # type: HTTPMessage + headers = ... # type: HTTPMessage + version = ... # type: int + debuglevel = ... # type: int + closed = ... # type: bool + status = ... # type: int + reason = ... # type: str + def __init__(self, sock: socket, debuglevel: int = ..., + method: Optional[str] = ..., url: Optional[str] = ...) -> None: ... + def read(self, amt: Optional[int] = ...) -> bytes: ... + @overload + def getheader(self, name: str) -> Optional[str]: ... + @overload + def getheader(self, name: str, default: _T) -> Union[str, _T]: ... + def getheaders(self) -> List[Tuple[str, str]]: ... + def fileno(self) -> int: ... + def isclosed(self) -> bool: ... + def __iter__(self) -> Iterator[bytes]: ... + def __enter__(self) -> 'HTTPResponse': ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[types.TracebackType]) -> bool: ... +else: + class HTTPResponse(io.RawIOBase, BinaryIO): # type: ignore + msg = ... # type: HTTPMessage + headers = ... # type: HTTPMessage + version = ... # type: int + debuglevel = ... # type: int + closed = ... # type: bool + status = ... # type: int + reason = ... # type: str + def read(self, amt: Optional[int] = ...) -> bytes: ... + def readinto(self, b: bytearray) -> int: ... + @overload + def getheader(self, name: str) -> Optional[str]: ... + @overload + def getheader(self, name: str, default: _T) -> Union[str, _T]: ... + def getheaders(self) -> List[Tuple[str, str]]: ... + def fileno(self) -> int: ... + def __iter__(self) -> Iterator[bytes]: ... + def __enter__(self) -> 'HTTPResponse': ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[types.TracebackType]) -> bool: ... + +class HTTPConnection: + if sys.version_info >= (3, 7): + def __init__( + self, + host: str, port: Optional[int] = ..., + timeout: int = ..., + source_address: Optional[Tuple[str, int]] = ..., blocksize: int = ... + ) -> None: ... + else: + def __init__( + self, + host: str, port: Optional[int] = ..., + timeout: int = ..., + source_address: Optional[Tuple[str, int]] = ... + ) -> None: ... + def request(self, method: str, url: str, + body: Optional[_DataType] = ..., + headers: Mapping[str, str] = ...) -> None: ... + def getresponse(self) -> HTTPResponse: ... + def set_debuglevel(self, level: int) -> None: ... + def set_tunnel(self, host: str, port: Optional[int] = ..., + headers: Optional[Mapping[str, str]] = ...) -> None: ... + def connect(self) -> None: ... + def close(self) -> None: ... + def putrequest(self, request: str, selector: str, skip_host: bool = ..., + skip_accept_encoding: bool = ...) -> None: ... + def putheader(self, header: str, *argument: str) -> None: ... + def endheaders(self, message_body: Optional[_DataType] = ...) -> None: ... + def send(self, data: _DataType) -> None: ... + +class HTTPSConnection(HTTPConnection): + def __init__(self, + host: str, port: Optional[int] = ..., + key_file: Optional[str] = ..., + cert_file: Optional[str] = ..., + timeout: int = ..., + source_address: Optional[Tuple[str, int]] = ..., + *, context: Optional[ssl.SSLContext] = ..., + check_hostname: Optional[bool] = ...) -> None: ... + +class HTTPException(Exception): ... +error = HTTPException + +class NotConnected(HTTPException): ... +class InvalidURL(HTTPException): ... +class UnknownProtocol(HTTPException): ... +class UnknownTransferEncoding(HTTPException): ... +class UnimplementedFileMode(HTTPException): ... +class IncompleteRead(HTTPException): ... + +class ImproperConnectionState(HTTPException): ... +class CannotSendRequest(ImproperConnectionState): ... +class CannotSendHeader(ImproperConnectionState): ... +class ResponseNotReady(ImproperConnectionState): ... + +class BadStatusLine(HTTPException): ... +class LineTooLong(HTTPException): ... + +if sys.version_info >= (3, 5): + class RemoteDisconnected(ConnectionResetError, BadStatusLine): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/cookiejar.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/cookiejar.pyi new file mode 100644 index 000000000..d7eafec04 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/cookiejar.pyi @@ -0,0 +1,106 @@ +from typing import Iterable, Iterator, Optional, Sequence, Tuple, TypeVar, Union, overload +from http.client import HTTPResponse +from urllib.request import Request + +_T = TypeVar('_T') + +class LoadError(OSError): ... + + +class CookieJar(Iterable['Cookie']): + def __init__(self, policy: Optional['CookiePolicy'] = ...) -> None: ... + def add_cookie_header(self, request: Request) -> None: ... + def extract_cookies(self, response: HTTPResponse, + request: Request) -> None: ... + def set_policy(self, policy: 'CookiePolicy') -> None: ... + def make_cookies(self, response: HTTPResponse, + request: Request) -> Sequence['Cookie']: ... + def set_cookie(self, cookie: 'Cookie') -> None: ... + def set_cookie_if_ok(self, cookie: 'Cookie', + request: Request) -> None: ... + def clear(self, domain: str = ..., path: str = ..., + name: str = ...) -> None: ... + def clear_session_cookies(self) -> None: ... + def __iter__(self) -> Iterator['Cookie']: ... + def __len__(self) -> int: ... + +class FileCookieJar(CookieJar): + filename = ... # type: str + delayload = ... # type: bool + def __init__(self, filename: str = ..., delayload: bool = ..., + policy: Optional['CookiePolicy'] = ...) -> None: ... + def save(self, filename: Optional[str] = ..., ignore_discard: bool = ..., + ignore_expires: bool = ...) -> None: ... + def load(self, filename: Optional[str] = ..., ignore_discard: bool = ..., + ignore_expires: bool = ...) -> None: ... + def revert(self, filename: Optional[str] = ..., ignore_discard: bool = ..., + ignore_expires: bool = ...) -> None: ... + +class MozillaCookieJar(FileCookieJar): ... +class LWPCookieJar(FileCookieJar): ... + + +class CookiePolicy: + netscape = ... # type: bool + rfc2965 = ... # type: bool + hide_cookie2 = ... # type: bool + def set_ok(self, cookie: 'Cookie', request: Request) -> bool: ... + def return_ok(self, cookie: 'Cookie', request: Request) -> bool: ... + def domain_return_ok(self, domain: str, request: Request) -> bool: ... + def path_return_ok(self, path: str, request: Request) -> bool: ... + + +class DefaultCookiePolicy(CookiePolicy): + rfc2109_as_netscape = ... # type: bool + strict_domain = ... # type: bool + strict_rfc2965_unverifiable = ... # type: bool + strict_ns_unverifiable = ... # type: bool + strict_ns_domain = ... # type: int + strict_ns_set_initial_dollar = ... # type: bool + strict_ns_set_path = ... # type: bool + DomainStrictNoDots = ... # type: int + DomainStrictNonDomain = ... # type: int + DomainRFC2965Match = ... # type: int + DomainLiberal = ... # type: int + DomainStrict = ... # type: int + def __init__(self, blocked_domains: Optional[Sequence[str]] = ..., + allowed_domains: Optional[Sequence[str]] = ..., + netscape: bool = ..., + rfc2965: bool = ..., + rfc2109_as_netscape: Optional[bool] = ..., + hide_cookie2: bool = ..., strict_domain: bool = ..., + strict_rfc2965_unverifiable: bool =..., + strict_ns_unverifiable: bool = ..., + strict_ns_domain: int = ..., + strict_ns_set_initial_dollar: bool = ..., + strict_ns_set_path: bool = ...) -> None: ... + def blocked_domains(self) -> Tuple[str, ...]: ... + def set_blocked_domains(self, blocked_domains: Sequence[str]) -> None: ... + def is_blocked(self, domain: str) -> bool: ... + def allowed_domains(self) -> Optional[Tuple[str, ...]]: ... + def set_allowed_domains(self, allowed_domains: Optional[Sequence[str]]) -> None: ... + def is_not_allowed(self, domain: str) -> bool: ... + + +class Cookie: + version = ... # type: Optional[int] + name = ... # type: str + value = ... # type: Optional[str] + port = ... # type: Optional[str] + path = ... # type: str + secure = ... # type: bool + expires = ... # type: Optional[int] + discard = ... # type: bool + comment = ... # type: Optional[str] + comment_url = ... # type: Optional[str] + rfc2109 = ... # type: bool + port_specified = ... # type: bool + domain_specified = ... # type: bool + domain_initial_dot = ... # type: bool + def has_nonstandard_attr(self, name: str) -> bool: ... + @overload + def get_nonstandard_attr(self, name: str) -> Optional[str]: ... + @overload + def get_nonstandard_attr(self, name: str, default: _T = ...) -> Union[str, _T]: ... + def set_nonstandard_attr(self, name: str, value: str) -> None: ... + def is_expired(self, now: int = ...) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/cookies.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/cookies.pyi new file mode 100644 index 000000000..78223a7d8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/cookies.pyi @@ -0,0 +1,31 @@ +# Stubs for http.cookies (Python 3.5) + +from typing import Generic, Dict, List, Mapping, MutableMapping, Optional, TypeVar, Union + +_DataType = Union[str, Mapping[str, Union[str, 'Morsel']]] +_T = TypeVar('_T') + +class CookieError(Exception): ... + +class Morsel(Dict[str, str], Generic[_T]): + value = ... # type: str + coded_value = ... # type: _T + key = ... # type: str + def set(self, key: str, val: str, coded_val: _T) -> None: ... + def isReservedKey(self, K: str) -> bool: ... + def output(self, attrs: Optional[List[str]] = ..., + header: str = ...) -> str: ... + def js_output(self, attrs: Optional[List[str]] = ...) -> str: ... + def OutputString(self, attrs: Optional[List[str]] = ...) -> str: ... + +class BaseCookie(Dict[str, Morsel], Generic[_T]): + def __init__(self, input: Optional[_DataType] = ...) -> None: ... + def value_decode(self, val: str) -> _T: ... + def value_encode(self, val: _T) -> str: ... + def output(self, attrs: Optional[List[str]] = ..., header: str = ..., + sep: str = ...) -> str: ... + def js_output(self, attrs: Optional[List[str]] = ...) -> str: ... + def load(self, rawdata: _DataType) -> None: ... + def __setitem__(self, key: str, value: Union[str, Morsel]) -> None: ... + +class SimpleCookie(BaseCookie): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/server.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/server.pyi new file mode 100644 index 000000000..2e610e547 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/http/server.pyi @@ -0,0 +1,71 @@ +# Stubs for http.server (Python 3.4) + +import sys +from typing import Any, BinaryIO, Dict, List, Mapping, Optional, Tuple, Union +import socketserver +import email.message + +if sys.version_info >= (3, 7): + from builtins import _PathLike + +class HTTPServer(socketserver.TCPServer): + server_name = ... # type: str + server_port = ... # type: int + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type) -> None: ... + +class BaseHTTPRequestHandler: + client_address = ... # type: Tuple[str, int] + server = ... # type: socketserver.BaseServer + close_connection = ... # type: bool + requestline = ... # type: str + command = ... # type: str + path = ... # type: str + request_version = ... # type: str + headers = ... # type: email.message.Message + rfile = ... # type: BinaryIO + wfile = ... # type: BinaryIO + server_version = ... # type: str + sys_version = ... # type: str + error_message_format = ... # type: str + error_content_type = ... # type: str + protocol_version = ... # type: str + MessageClass = ... # type: type + responses = ... # type: Mapping[int, Tuple[str, str]] + def __init__(self, request: bytes, client_address: Tuple[str, int], + server: socketserver.BaseServer) -> None: ... + def handle(self) -> None: ... + def handle_one_request(self) -> None: ... + def handle_expect_100(self) -> bool: ... + def send_error(self, code: int, message: Optional[str] = ..., + explain: Optional[str] = ...) -> None: ... + def send_response(self, code: int, + message: Optional[str] = ...) -> None: ... + def send_header(self, keyword: str, value: str) -> None: ... + def send_response_only(self, code: int, + message: Optional[str] = ...) -> None: ... + def end_headers(self) -> None: ... + def flush_headers(self) -> None: ... + def log_request(self, code: Union[int, str] = ..., + size: Union[int, str] = ...) -> None: ... + def log_error(self, format: str, *args: Any) -> None: ... + def log_message(self, format: str, *args: Any) -> None: ... + def version_string(self) -> str: ... + def date_time_string(self, timestamp: Optional[int] = ...) -> str: ... + def log_date_time_string(self) -> str: ... + def address_string(self) -> str: ... + +class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): + extensions_map = ... # type: Dict[str, str] + if sys.version_info >= (3, 7): + def __init__(self, request: bytes, client_address: Tuple[str, int], + server: socketserver.BaseServer, directory: Optional[Union[str, _PathLike[str]]]) -> None: ... + else: + def __init__(self, request: bytes, client_address: Tuple[str, int], + server: socketserver.BaseServer) -> None: ... + def do_GET(self) -> None: ... + def do_HEAD(self) -> None: ... + +class CGIHTTPRequestHandler(SimpleHTTPRequestHandler): + cgi_directories = ... # type: List[str] + def do_POST(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/imp.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/imp.pyi new file mode 100644 index 000000000..33440910a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/imp.pyi @@ -0,0 +1,55 @@ +# Stubs for imp (Python 3.6) + +import os +import sys +import types +from typing import Any, IO, List, Optional, Tuple, TypeVar, Union + +from _imp import (lock_held as lock_held, acquire_lock as acquire_lock, release_lock as release_lock, + get_frozen_object as get_frozen_object, is_frozen_package as is_frozen_package, + init_frozen as init_frozen, is_builtin as is_builtin, is_frozen as is_frozen) + +if sys.version_info >= (3, 5): + from _imp import create_dynamic as create_dynamic + +_T = TypeVar('_T') + +if sys.version_info >= (3, 6): + _Path = Union[str, os.PathLike[str]] +else: + _Path = str + +SEARCH_ERROR: int +PY_SOURCE: int +PY_COMPILED: int +C_EXTENSION: int +PY_RESOURCE: int +PKG_DIRECTORY: int +C_BUILTIN: int +PY_FROZEN: int +PY_CODERESOURCE: int +IMP_HOOK: int + +def new_module(name: str) -> types.ModuleType: ... +def get_magic() -> bytes: ... +def get_tag() -> str: ... +def cache_from_source(path: _Path, debug_override: Optional[bool] = ...) -> str: ... +def source_from_cache(path: _Path) -> str: ... +def get_suffixes() -> List[Tuple[str, str, int]]: ... + +class NullImporter: + def __init__(self, path: _Path) -> None: ... + def find_module(self, fullname: Any) -> None: ... + +# PathLike doesn't work for the pathname argument here +def load_source(name: str, pathname: str, file: Optional[IO[Any]] = ...) -> types.ModuleType: ... +def load_compiled(name: str, pathname: str, file: Optional[IO[Any]] = ...) -> types.ModuleType: ... +def load_package(name: str, path: _Path) -> types.ModuleType: ... +def load_module(name: str, file: IO[Any], filename: str, details: Tuple[str, str, int]) -> types.ModuleType: ... +if sys.version_info >= (3, 6): + def find_module(name: str, path: Union[None, List[str], List[os.PathLike[str]], List[_Path]] = ...) -> Tuple[str, str, Tuple[IO[Any], str, int]]: ... +else: + def find_module(name: str, path: Optional[List[str]] = ...) -> Tuple[str, str, Tuple[IO[Any], str, int]]: ... +def reload(module: types.ModuleType) -> types.ModuleType: ... +def init_builtin(name: str) -> Optional[types.ModuleType]: ... +def load_dynamic(name: str, path: str, file: Optional[IO[Any]] = ...) -> types.ModuleType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/__init__.pyi new file mode 100644 index 000000000..78a81712d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/__init__.pyi @@ -0,0 +1,18 @@ +from importlib import util +from importlib.abc import Loader +import sys +import types +from typing import Any, Mapping, Optional, Sequence + +def __import__(name: str, globals: Optional[Mapping[str, Any]] = ..., + locals: Optional[Mapping[str, Any]] = ..., + fromlist: Sequence[str] = ..., + level: int = ...) -> types.ModuleType: ... + +def import_module(name: str, package: Optional[str] = ...) -> types.ModuleType: ... + +def find_loader(name: str, path: Optional[str] = ...) -> Optional[Loader]: ... + +def invalidate_caches() -> None: ... + +def reload(module: types.ModuleType) -> types.ModuleType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/abc.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/abc.pyi new file mode 100644 index 000000000..e8bf33e5d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/abc.pyi @@ -0,0 +1,97 @@ +from abc import ABCMeta, abstractmethod +import os +import sys +import types +from typing import Any, IO, Iterator, Mapping, Optional, Sequence, Tuple, Union + +# Loader is exported from this module, but for circular import reasons +# exists in its own stub file (with ModuleSpec and ModuleType). +from _importlib_modulespec import Loader as Loader # Exported + +from _importlib_modulespec import ModuleSpec + +_Path = Union[bytes, str] + +class Finder(metaclass=ABCMeta): + ... + # Technically this class defines the following method, but its subclasses + # in this module violate its signature. Since this class is deprecated, it's + # easier to simply ignore that this method exists. + # @abstractmethod + # def find_module(self, fullname: str, + # path: Optional[Sequence[_Path]] = ...) -> Optional[Loader]: ... + +class ResourceLoader(Loader): + @abstractmethod + def get_data(self, path: _Path) -> bytes: ... + +class InspectLoader(Loader): + def is_package(self, fullname: str) -> bool: ... + def get_code(self, fullname: str) -> Optional[types.CodeType]: ... + def load_module(self, fullname: str) -> types.ModuleType: ... + @abstractmethod + def get_source(self, fullname: str) -> Optional[str]: ... + def exec_module(self, module: types.ModuleType) -> None: ... + if sys.version_info < (3, 5): + def source_to_code(self, data: Union[bytes, str], + path: str = ...) -> types.CodeType: ... + else: + @staticmethod + def source_to_code(data: Union[bytes, str], + path: str = ...) -> types.CodeType: ... + +class ExecutionLoader(InspectLoader): + @abstractmethod + def get_filename(self, fullname: str) -> _Path: ... + def get_code(self, fullname: str) -> Optional[types.CodeType]: ... + +class SourceLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): + def path_mtime(self, path: _Path) -> Union[int, float]: ... + def set_data(self, path: _Path, data: bytes) -> None: ... + def get_source(self, fullname: str) -> Optional[str]: ... + def path_stats(self, path: _Path) -> Mapping[str, Any]: ... + + +class MetaPathFinder(Finder): + def find_module(self, fullname: str, + path: Optional[Sequence[_Path]]) -> Optional[Loader]: + ... + def invalidate_caches(self) -> None: ... + # Not defined on the actual class, but expected to exist. + def find_spec( + self, fullname: str, path: Optional[Sequence[_Path]], + target: Optional[types.ModuleType] = ... + ) -> Optional[ModuleSpec]: + ... + +class PathEntryFinder(Finder): + def find_module(self, fullname: str) -> Optional[Loader]: ... + def find_loader( + self, fullname: str + ) -> Tuple[Optional[Loader], Sequence[_Path]]: ... + def invalidate_caches(self) -> None: ... + # Not defined on the actual class, but expected to exist. + def find_spec( + self, fullname: str, + target: Optional[types.ModuleType] = ... + ) -> Optional[ModuleSpec]: ... + +class FileLoader(ResourceLoader, ExecutionLoader, metaclass=ABCMeta): + name = ... # type: str + path = ... # type: _Path + def __init__(self, fullname: str, path: _Path) -> None: ... + def get_data(self, path: _Path) -> bytes: ... + def get_filename(self, fullname: str) -> _Path: ... + +if sys.version_info >= (3, 7): + _PathLike = Union[bytes, str, os.PathLike[Any]] + + class ResourceReader(metaclass=ABCMeta): + @abstractmethod + def open_resource(self, resource: _PathLike) -> IO[bytes]: ... + @abstractmethod + def resource_path(self, resource: _PathLike) -> str: ... + @abstractmethod + def is_resource(self, name: str) -> bool: ... + @abstractmethod + def contents(self) -> Iterator[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/machinery.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/machinery.pyi new file mode 100644 index 000000000..98c4b9a5a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/machinery.pyi @@ -0,0 +1,120 @@ +import importlib.abc +import sys +import types +from typing import Any, Callable, List, Optional, Sequence, Tuple, Union + +# ModuleSpec is exported from this module, but for circular import +# reasons exists in its own stub file (with Loader and ModuleType). +from _importlib_modulespec import ModuleSpec as ModuleSpec # Exported + +class BuiltinImporter(importlib.abc.MetaPathFinder, + importlib.abc.InspectLoader): + # MetaPathFinder + @classmethod + def find_module( + cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]] + ) -> Optional[importlib.abc.Loader]: + ... + @classmethod + def find_spec(cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]], + target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: + ... + # InspectLoader + @classmethod + def is_package(cls, fullname: str) -> bool: ... + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @classmethod + def get_code(cls, fullname: str) -> None: ... + @classmethod + def get_source(cls, fullname: str) -> None: ... + # Loader + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @staticmethod + def module_repr(module: types.ModuleType) -> str: ... # type: ignore + @classmethod + def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: ... + @classmethod + def exec_module(cls, module: types.ModuleType) -> None: ... + +class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader): + # MetaPathFinder + @classmethod + def find_module( + cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]] + ) -> Optional[importlib.abc.Loader]: + ... + @classmethod + def find_spec(cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]], + target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: + ... + # InspectLoader + @classmethod + def is_package(cls, fullname: str) -> bool: ... + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @classmethod + def get_code(cls, fullname: str) -> None: ... + @classmethod + def get_source(cls, fullname: str) -> None: ... + # Loader + @classmethod + def load_module(cls, fullname: str) -> types.ModuleType: ... + @staticmethod + def module_repr(module: types.ModuleType) -> str: ... # type: ignore + @classmethod + def create_module(cls, spec: ModuleSpec) -> Optional[types.ModuleType]: + ... + @staticmethod + def exec_module(module: types.ModuleType) -> None: ... # type: ignore + +class WindowsRegistryFinder(importlib.abc.MetaPathFinder): + @classmethod + def find_module( + cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]] + ) -> Optional[importlib.abc.Loader]: + ... + @classmethod + def find_spec(cls, fullname: str, + path: Optional[Sequence[importlib.abc._Path]], + target: Optional[types.ModuleType] = ...) -> Optional[ModuleSpec]: + ... + +class PathFinder(importlib.abc.MetaPathFinder): ... + +SOURCE_SUFFIXES = ... # type: List[str] +DEBUG_BYTECODE_SUFFIXES = ... # type: List[str] +OPTIMIZED_BYTECODE_SUFFIXES = ... # type: List[str] +BYTECODE_SUFFIXES = ... # type: List[str] +EXTENSION_SUFFIXES = ... # type: List[str] + +def all_suffixes() -> List[str]: ... + +class FileFinder(importlib.abc.PathEntryFinder): + path = ... # type: str + def __init__( + self, path: str, + *loader_details: Tuple[importlib.abc.Loader, List[str]] + ) -> None: ... + @classmethod + def path_hook( + *loader_details: Tuple[importlib.abc.Loader, List[str]] + ) -> Callable[[str], importlib.abc.PathEntryFinder]: ... + +class SourceFileLoader(importlib.abc.FileLoader, + importlib.abc.SourceLoader): + ... + +class SourcelessFileLoader(importlib.abc.FileLoader, + importlib.abc.SourceLoader): + ... + +class ExtensionFileLoader(importlib.abc.ExecutionLoader): + def get_filename(self, fullname: str) -> importlib.abc._Path: ... + def get_source(self, fullname: str) -> None: ... # type: ignore diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/resources.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/resources.pyi new file mode 100644 index 000000000..2db82b326 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/resources.pyi @@ -0,0 +1,25 @@ +import sys +# This is a >=3.7 module, so we conditionally include its source. +if sys.version_info >= (3, 7): + import os + + from pathlib import Path + from types import ModuleType + from typing import ContextManager, Iterator, Union, BinaryIO, TextIO + + Package = Union[str, ModuleType] + Resource = Union[str, os.PathLike] + + def open_binary(package: Package, resource: Resource) -> BinaryIO: ... + def open_text(package: Package, + resource: Resource, + encoding: str = ..., + errors: str = ...) -> TextIO: ... + def read_binary(package: Package, resource: Resource) -> bytes: ... + def read_text(package: Package, + resource: Resource, + encoding: str = ..., + errors: str = ...) -> str: ... + def path(package: Package, resource: Resource) -> ContextManager[Path]: ... + def is_resource(package: Package, name: str) -> bool: ... + def contents(package: Package) -> Iterator[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/util.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/util.pyi new file mode 100644 index 000000000..801f93738 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/importlib/util.pyi @@ -0,0 +1,53 @@ +import importlib.abc +import importlib.machinery +import sys +import types +from typing import Any, Callable, List, Optional + +def module_for_loader( + fxn: Callable[..., types.ModuleType] +) -> Callable[..., types.ModuleType]: ... +def set_loader( + fxn: Callable[..., types.ModuleType] +) -> Callable[..., types.ModuleType]: ... +def set_package( + fxn: Callable[..., types.ModuleType] +) -> Callable[..., types.ModuleType]: ... + +def resolve_name(name: str, package: str) -> str: ... + +MAGIC_NUMBER = ... # type: bytes + +def cache_from_source(path: str, debug_override: Optional[bool] = ..., *, + optimization: Optional[Any] = ...) -> str: ... +def source_from_cache(path: str) -> str: ... +def decode_source(source_bytes: bytes) -> str: ... +def find_spec( + name: str, package: Optional[str] = ... +) -> Optional[importlib.machinery.ModuleSpec]: ... +def spec_from_loader( + name: str, loader: Optional[importlib.abc.Loader], *, + origin: Optional[str] = ..., loader_state: Optional[Any] = ..., + is_package: Optional[bool] = ... +) -> importlib.machinery.ModuleSpec: ... +def spec_from_file_location( + name: str, location: str, *, + loader: Optional[importlib.abc.Loader] = ..., + submodule_search_locations: Optional[List[str]] = ... +) -> importlib.machinery.ModuleSpec: ... + +if sys.version_info >= (3, 5): + def module_from_spec( + spec: importlib.machinery.ModuleSpec + ) -> types.ModuleType: ... + + class LazyLoader(importlib.abc.Loader): + def __init__(self, loader: importlib.abc.Loader) -> None: ... + @classmethod + def factory( + cls, loader: importlib.abc.Loader + ) -> Callable[..., 'LazyLoader']: ... + def create_module( + self, spec: importlib.machinery.ModuleSpec + ) -> Optional[types.ModuleType]: ... + def exec_module(self, module: types.ModuleType) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/inspect.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/inspect.pyi new file mode 100644 index 000000000..65e1f6c0d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/inspect.pyi @@ -0,0 +1,329 @@ +import sys +from typing import (AbstractSet, Any, Callable, Dict, Generator, List, Mapping, + MutableMapping, NamedTuple, Optional, Sequence, Tuple, + Union, + ) +from types import CodeType, FrameType, ModuleType, TracebackType + +# +# Types and members +# +class EndOfBlock(Exception): ... + +class BlockFinder: + indent: int + islambda: bool + started: bool + passline: bool + indecorator: bool + decoratorhasargs: bool + last: int + def tokeneater(self, type: int, token: str, srow_scol: Tuple[int, int], + erow_ecol: Tuple[int, int], line: str) -> None: ... + +CO_OPTIMIZED: int +CO_NEWLOCALS: int +CO_VARARGS: int +CO_VARKEYWORDS: int +CO_NESTED: int +CO_GENERATOR: int +CO_NOFREE: int +if sys.version_info >= (3, 5): + CO_COROUTINE: int + CO_ITERABLE_COROUTINE: int +if sys.version_info >= (3, 6): + CO_ASYNC_GENERATOR: int +TPFLAGS_IS_ABSTRACT: int + +if sys.version_info < (3, 6): + ModuleInfo = NamedTuple('ModuleInfo', [('name', str), + ('suffix', str), + ('mode', str), + ('module_type', int), + ]) + def getmoduleinfo(path: str) -> Optional[ModuleInfo]: ... + +def getmembers(object: object, + predicate: Optional[Callable[[Any], bool]] = ..., + ) -> List[Tuple[str, Any]]: ... +def getmodulename(path: str) -> Optional[str]: ... + +def ismodule(object: object) -> bool: ... +def isclass(object: object) -> bool: ... +def ismethod(object: object) -> bool: ... +def isfunction(object: object) -> bool: ... +def isgeneratorfunction(object: object) -> bool: ... +def isgenerator(object: object) -> bool: ... + +if sys.version_info >= (3, 5): + def iscoroutinefunction(object: object) -> bool: ... + def iscoroutine(object: object) -> bool: ... + def isawaitable(object: object) -> bool: ... +if sys.version_info >= (3, 6): + def isasyncgenfunction(object: object) -> bool: ... + def isasyncgen(object: object) -> bool: ... +def istraceback(object: object) -> bool: ... +def isframe(object: object) -> bool: ... +def iscode(object: object) -> bool: ... +def isbuiltin(object: object) -> bool: ... +def isroutine(object: object) -> bool: ... +def isabstract(object: object) -> bool: ... +def ismethoddescriptor(object: object) -> bool: ... +def isdatadescriptor(object: object) -> bool: ... +def isgetsetdescriptor(object: object) -> bool: ... +def ismemberdescriptor(object: object) -> bool: ... + + +# +# Retrieving source code +# +def findsource(object: object) -> Tuple[List[str], int]: ... +def getabsfile(object: object) -> str: ... +def getblock(lines: Sequence[str]) -> Sequence[str]: ... +def getdoc(object: object) -> str: ... +def getcomments(object: object) -> str: ... +def getfile(object: object) -> str: ... +def getmodule(object: object) -> ModuleType: ... +def getsourcefile(object: object) -> str: ... +# TODO restrict to "module, class, method, function, traceback, frame, +# or code object" +def getsourcelines(object: object) -> Tuple[List[str], int]: ... +# TODO restrict to "a module, class, method, function, traceback, frame, +# or code object" +def getsource(object: object) -> str: ... +def cleandoc(doc: str) -> str: ... +def indentsize(line: str) -> int: ... + + +# +# Introspecting callables with the Signature object +# +def signature(callable: Callable[..., Any], + *, + follow_wrapped: bool = ...) -> 'Signature': ... + +class Signature: + def __init__(self, + parameters: Optional[Sequence['Parameter']] = ..., + *, + return_annotation: Any = ...) -> None: ... + # TODO: can we be more specific here? + empty: object = ... + + parameters: Mapping[str, 'Parameter'] + + # TODO: can we be more specific here? + return_annotation: Any + + def bind(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ... + def bind_partial(self, *args: Any, **kwargs: Any) -> 'BoundArguments': ... + def replace(self, + *, + parameters: Optional[Sequence['Parameter']] = ..., + return_annotation: Any = ...) -> 'Signature': ... + + if sys.version_info >= (3, 5): + @classmethod + def from_callable(cls, + obj: Callable[..., Any], + *, + follow_wrapped: bool = ...) -> 'Signature': ... + +# The name is the same as the enum's name in CPython +class _ParameterKind: ... + +class Parameter: + def __init__(self, + name: str, + kind: _ParameterKind, + *, + default: Any = ..., + annotation: Any = ...) -> None: ... + empty: Any = ... + name: str + default: Any + annotation: Any + + kind: _ParameterKind + POSITIONAL_ONLY: _ParameterKind = ... + POSITIONAL_OR_KEYWORD: _ParameterKind = ... + VAR_POSITIONAL: _ParameterKind = ... + KEYWORD_ONLY: _ParameterKind = ... + VAR_KEYWORD: _ParameterKind = ... + + def replace(self, + *, + name: Optional[str] = ..., + kind: Optional[_ParameterKind] = ..., + default: Any = ..., + annotation: Any = ...) -> 'Parameter': ... + +class BoundArguments: + arguments: MutableMapping[str, Any] + args: Tuple[Any, ...] + kwargs: Dict[str, Any] + signature: Signature + + if sys.version_info >= (3, 5): + def apply_defaults(self) -> None: ... + + +# +# Classes and functions +# + +# TODO: The actual return type should be List[_ClassTreeItem] but mypy doesn't +# seem to be supporting this at the moment: +# _ClassTreeItem = Union[List['_ClassTreeItem'], Tuple[type, Tuple[type, ...]]] +def getclasstree(classes: List[type], unique: bool = ...) -> Any: ... + +ArgSpec = NamedTuple('ArgSpec', [('args', List[str]), + ('varargs', str), + ('keywords', str), + ('defaults', tuple), + ]) + +Arguments = NamedTuple('Arguments', [('args', List[str]), + ('varargs', Optional[str]), + ('varkw', Optional[str]), + ]) + +def getargs(co: CodeType) -> Arguments: ... +def getargspec(func: object) -> ArgSpec: ... + +FullArgSpec = NamedTuple('FullArgSpec', [('args', List[str]), + ('varargs', str), + ('varkw', str), + ('defaults', tuple), + ('kwonlyargs', List[str]), + ('kwonlydefaults', Dict[str, Any]), + ('annotations', Dict[str, Any]), + ]) + +def getfullargspec(func: object) -> FullArgSpec: ... + +# TODO make the field types more specific here +ArgInfo = NamedTuple('ArgInfo', [('args', List[str]), + ('varargs', Optional[str]), + ('keywords', Optional[str]), + ('locals', Dict[str, Any]), + ]) + +def getargvalues(frame: FrameType) -> ArgInfo: ... +def formatannotation(annotation: object, base_module: Optional[str] = ...) -> str: ... +def formatannotationrelativeto(object: object) -> Callable[[object], str]: ... +def formatargspec(args: List[str], + varargs: Optional[str] = ..., + varkw: Optional[str] = ..., + defaults: Optional[Tuple[Any, ...]] = ..., + kwonlyargs: Optional[List[str]] = ..., + kwonlydefaults: Optional[Dict[str, Any]] = ..., + annotations: Dict[str, Any] = ..., + formatarg: Callable[[str], str] = ..., + formatvarargs: Callable[[str], str] = ..., + formatvarkw: Callable[[str], str] = ..., + formatvalue: Callable[[Any], str] = ..., + formatreturns: Callable[[Any], str] = ..., + formatannotations: Callable[[Any], str] = ..., + ) -> str: ... +def formatargvalues(args: List[str], + varargs: Optional[str] = ..., + varkw: Optional[str] = ..., + locals: Optional[Dict[str, Any]] = ..., + formatarg: Optional[Callable[[str], str]] = ..., + formatvarargs: Optional[Callable[[str], str]] = ..., + formatvarkw: Optional[Callable[[str], str]] = ..., + formatvalue: Optional[Callable[[Any], str]] = ..., + ) -> str: ... +def getmro(cls: type) -> Tuple[type, ...]: ... + +def getcallargs(func: Callable[..., Any], + *args: Any, + **kwds: Any) -> Dict[str, Any]: ... + + +ClosureVars = NamedTuple('ClosureVars', [('nonlocals', Mapping[str, Any]), + ('globals', Mapping[str, Any]), + ('builtins', Mapping[str, Any]), + ('unbound', AbstractSet[str]), + ]) +def getclosurevars(func: Callable[..., Any]) -> ClosureVars: ... + +def unwrap(func: Callable[..., Any], + *, + stop: Callable[[Any], Any]) -> Any: ... + + +# +# The interpreter stack +# + +Traceback = NamedTuple( + 'Traceback', + [ + ('filename', str), + ('lineno', int), + ('function', str), + ('code_context', List[str]), + ('index', int), + ] +) + +# Python 3.5+ (functions returning it used to return regular tuples) +FrameInfo = NamedTuple('FrameInfo', [('frame', FrameType), + ('filename', str), + ('lineno', int), + ('function', str), + ('code_context', List[str]), + ('index', int), + ]) + +def getframeinfo(frame: Union[FrameType, TracebackType], context: int = ...) -> Traceback: ... +def getouterframes(frame: Any, context: int = ...) -> List[FrameInfo]: ... +def getinnerframes(traceback: TracebackType, context: int = ...) -> List[FrameInfo]: ... +def getlineno(frame: FrameType) -> int: ... +def currentframe() -> Optional[FrameType]: ... +def stack(context: int = ...) -> List[FrameInfo]: ... +def trace(context: int = ...) -> List[FrameInfo]: ... + +# +# Fetching attributes statically +# + +def getattr_static(obj: object, attr: str, default: Optional[Any] = ...) -> Any: ... + + +# +# Current State of Generators and Coroutines +# + +# TODO In the next two blocks of code, can we be more specific regarding the +# type of the "enums"? + +GEN_CREATED: str +GEN_RUNNING: str +GEN_SUSPENDED: str +GEN_CLOSED: str +def getgeneratorstate(generator: Generator[Any, Any, Any]) -> str: ... + +if sys.version_info >= (3, 5): + CORO_CREATED: str + CORO_RUNNING: str + CORO_SUSPENDED: str + CORO_CLOSED: str + # TODO can we be more specific than "object"? + def getcoroutinestate(coroutine: object) -> str: ... + +def getgeneratorlocals(generator: Generator[Any, Any, Any]) -> Dict[str, Any]: ... + +if sys.version_info >= (3, 5): + # TODO can we be more specific than "object"? + def getcoroutinelocals(coroutine: object) -> Dict[str, Any]: ... + +Attribute = NamedTuple('Attribute', [('name', str), + ('kind', str), + ('defining_class', type), + ('object', object), + ]) + +def classify_class_attrs(cls: type) -> List[Attribute]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/io.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/io.pyi new file mode 100644 index 000000000..701d496f8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/io.pyi @@ -0,0 +1,208 @@ +from typing import ( + List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple, Type, Any, IO, Iterable +) +import builtins +import codecs +from mmap import mmap +import sys +from types import TracebackType +from typing import TypeVar + +_bytearray_like = Union[bytearray, mmap] + +DEFAULT_BUFFER_SIZE = ... # type: int + +SEEK_SET = ... # type: int +SEEK_CUR = ... # type: int +SEEK_END = ... # type: int + +_T = TypeVar('_T', bound='IOBase') + +open = builtins.open + +BlockingIOError = builtins.BlockingIOError +class UnsupportedOperation(OSError, ValueError): ... + +class IOBase: + def __iter__(self) -> Iterator[bytes]: ... + def __next__(self) -> bytes: ... + def __enter__(self: _T) -> _T: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def readable(self) -> bool: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def writelines(self, lines: Iterable[Union[bytes, bytearray]]) -> None: ... + def readline(self, size: int = ...) -> bytes: ... + def __del__(self) -> None: ... + @property + def closed(self) -> bool: ... + +class RawIOBase(IOBase): + def readall(self) -> bytes: ... + def readinto(self, b: bytearray) -> Optional[int]: ... + def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... + def read(self, size: int = ...) -> Optional[bytes]: ... + +class BufferedIOBase(IOBase): + def detach(self) -> RawIOBase: ... + def readinto(self, b: _bytearray_like) -> int: ... + def write(self, b: Union[bytes, bytearray]) -> int: ... + if sys.version_info >= (3, 5): + def readinto1(self, b: _bytearray_like) -> int: ... + def read(self, size: Optional[int] = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + + +class FileIO(RawIOBase): + mode = ... # type: str + name = ... # type: Union[int, str] + def __init__( + self, + name: Union[str, bytes, int], + mode: str = ..., + closefd: bool = ..., + opener: Optional[Callable[[Union[int, str], str], int]] = ... + ) -> None: ... + +# TODO should extend from BufferedIOBase +class BytesIO(BinaryIO): + def __init__(self, initial_bytes: bytes = ...) -> None: ... + # BytesIO does not contain a "name" field. This workaround is necessary + # to allow BytesIO sub-classes to add this field, as it is defined + # as a read-only property on IO[]. + name: Any + def getvalue(self) -> bytes: ... + def getbuffer(self) -> memoryview: ... + # copied from IOBase + def __iter__(self) -> Iterator[bytes]: ... + def __next__(self) -> bytes: ... + def __enter__(self) -> 'BytesIO': ... + def __exit__(self, t: Optional[Type[BaseException]] = ..., value: Optional[BaseException] = ..., + traceback: Optional[TracebackType] = ...) -> bool: ... + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def readable(self) -> bool: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + # TODO should be the next line instead + # def writelines(self, lines: List[Union[bytes, bytearray]]) -> None: ... + def writelines(self, lines: Any) -> None: ... + def readline(self, size: int = ...) -> bytes: ... + def __del__(self) -> None: ... + closed = ... # type: bool + # copied from BufferedIOBase + def detach(self) -> RawIOBase: ... + def readinto(self, b: _bytearray_like) -> int: ... + def write(self, b: Union[bytes, bytearray]) -> int: ... + if sys.version_info >= (3, 5): + def readinto1(self, b: _bytearray_like) -> int: ... + def read(self, size: Optional[int] = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + +class BufferedReader(BufferedIOBase): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + def peek(self, size: int = ...) -> bytes: ... + +class BufferedWriter(BufferedIOBase): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + def flush(self) -> None: ... + def write(self, b: Union[bytes, bytearray]) -> int: ... + +class BufferedRandom(BufferedReader, BufferedWriter): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + +class BufferedRWPair(BufferedIOBase): + def __init__(self, reader: RawIOBase, writer: RawIOBase, + buffer_size: int = ...) -> None: ... + + +class TextIOBase(IOBase): + encoding = ... # type: str + errors = ... # type: Optional[str] + newlines = ... # type: Union[str, Tuple[str, ...], None] + def __iter__(self) -> Iterator[str]: ... # type: ignore + def __next__(self) -> str: ... # type: ignore + def detach(self) -> IOBase: ... + def write(self, s: str) -> int: ... + def readline(self, size: int = ...) -> str: ... # type: ignore + def read(self, size: Optional[int] = ...) -> str: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + +# TODO should extend from TextIOBase +class TextIOWrapper(TextIO): + line_buffering = ... # type: bool + # TODO uncomment after fixing mypy about using write_through + # def __init__(self, buffer: IO[bytes], encoding: str = ..., + # errors: Optional[str] = ..., newline: Optional[str] = ..., + # line_buffering: bool = ..., write_through: bool = ...) \ + # -> None: ... + def __init__( + self, + buffer: IO[bytes], + encoding: str = ..., + errors: Optional[str] = ..., + newline: Optional[str] = ..., + line_buffering: bool = ..., + write_through: bool = ... + ) -> None: ... + # copied from IOBase + def __exit__(self, t: Optional[Type[BaseException]] = ..., value: Optional[BaseException] = ..., + traceback: Optional[TracebackType] = ...) -> bool: ... + def close(self) -> None: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def readable(self) -> bool: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def seekable(self) -> bool: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + # TODO should be the next line instead + # def writelines(self, lines: List[str]) -> None: ... + def writelines(self, lines: Any) -> None: ... + def __del__(self) -> None: ... + closed = ... # type: bool + # copied from TextIOBase + encoding = ... # type: str + errors = ... # type: Optional[str] + newlines = ... # type: Union[str, Tuple[str, ...], None] + def __iter__(self) -> Iterator[str]: ... + def __next__(self) -> str: ... + def __enter__(self) -> 'TextIO': ... + def detach(self) -> IOBase: ... + def write(self, s: str) -> int: ... + def readline(self, size: int = ...) -> str: ... + def read(self, size: Optional[int] = ...) -> str: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + +class StringIO(TextIOWrapper): + def __init__(self, initial_value: str = ..., + newline: Optional[str] = ...) -> None: ... + # StringIO does not contain a "name" field. This workaround is necessary + # to allow StringIO sub-classes to add this field, as it is defined + # as a read-only property on IO[]. + name: Any + def getvalue(self) -> str: ... + def __enter__(self) -> 'StringIO': ... + +class IncrementalNewlineDecoder(codecs.IncrementalDecoder): + def decode(self, input: bytes, final: bool = ...) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/itertools.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/itertools.pyi new file mode 100644 index 000000000..8ca88cf92 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/itertools.pyi @@ -0,0 +1,106 @@ +# Stubs for itertools + +# Based on http://docs.python.org/3.2/library/itertools.html + +from typing import (Iterator, TypeVar, Iterable, overload, Any, Callable, Tuple, + Generic, Optional) + +_T = TypeVar('_T') +_S = TypeVar('_S') +_N = TypeVar('_N', int, float) + +def count(start: _N = ..., + step: _N = ...) -> Iterator[_N]: ... # more general types? +def cycle(iterable: Iterable[_T]) -> Iterator[_T]: ... + +@overload +def repeat(object: _T) -> Iterator[_T]: ... +@overload +def repeat(object: _T, times: int) -> Iterator[_T]: ... + +def accumulate(iterable: Iterable[_T], func: Callable[[_T, _T], _T] = ...) -> Iterator[_T]: ... + +class chain(Iterator[_T], Generic[_T]): + def __init__(self, *iterables: Iterable[_T]) -> None: ... + def __next__(self) -> _T: ... + def __iter__(self) -> Iterator[_T]: ... + @staticmethod + def from_iterable(iterable: Iterable[Iterable[_S]]) -> Iterator[_S]: ... + +def compress(data: Iterable[_T], selectors: Iterable[Any]) -> Iterator[_T]: ... +def dropwhile(predicate: Callable[[_T], Any], + iterable: Iterable[_T]) -> Iterator[_T]: ... +def filterfalse(predicate: Optional[Callable[[_T], Any]], + iterable: Iterable[_T]) -> Iterator[_T]: ... + +@overload +def groupby(iterable: Iterable[_T]) -> Iterator[Tuple[_T, Iterator[_T]]]: ... +@overload +def groupby(iterable: Iterable[_T], + key: Callable[[_T], _S]) -> Iterator[Tuple[_S, Iterator[_T]]]: ... + +@overload +def islice(iterable: Iterable[_T], stop: Optional[int]) -> Iterator[_T]: ... +@overload +def islice(iterable: Iterable[_T], start: Optional[int], stop: Optional[int], + step: Optional[int] = ...) -> Iterator[_T]: ... + +def starmap(func: Callable[..., _S], iterable: Iterable[Iterable[Any]]) -> Iterator[_S]: ... +def takewhile(predicate: Callable[[_T], Any], + iterable: Iterable[_T]) -> Iterator[_T]: ... +def tee(iterable: Iterable[_T], n: int = ...) -> Tuple[Iterator[_T], ...]: ... +def zip_longest(*p: Iterable[Any], + fillvalue: Any = ...) -> Iterator[Any]: ... + +_T1 = TypeVar('_T1') +_T2 = TypeVar('_T2') +_T3 = TypeVar('_T3') +_T4 = TypeVar('_T4') +_T5 = TypeVar('_T5') +_T6 = TypeVar('_T6') + +@overload +def product(iter1: Iterable[_T1]) -> Iterator[Tuple[_T1]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2]) -> Iterator[Tuple[_T1, _T2]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3]) -> Iterator[Tuple[_T1, _T2, _T3]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4]) -> Iterator[Tuple[_T1, _T2, _T3, _T4]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5]]: ... +@overload +def product(iter1: Iterable[_T1], + iter2: Iterable[_T2], + iter3: Iterable[_T3], + iter4: Iterable[_T4], + iter5: Iterable[_T5], + iter6: Iterable[_T6]) -> Iterator[Tuple[_T1, _T2, _T3, _T4, _T5, _T6]]: ... +@overload +def product(iter1: Iterable[Any], + iter2: Iterable[Any], + iter3: Iterable[Any], + iter4: Iterable[Any], + iter5: Iterable[Any], + iter6: Iterable[Any], + iter7: Iterable[Any], + *iterables: Iterable[Any]) -> Iterator[Tuple[Any, ...]]: ... +@overload +def product(*iterables: Iterable[Any], repeat: int) -> Iterator[Tuple[Any, ...]]: ... + +def permutations(iterable: Iterable[_T], + r: Optional[int] = ...) -> Iterator[Tuple[_T, ...]]: ... +def combinations(iterable: Iterable[_T], + r: int) -> Iterable[Tuple[_T, ...]]: ... +def combinations_with_replacement(iterable: Iterable[_T], + r: int) -> Iterable[Tuple[_T, ...]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/__init__.pyi new file mode 100644 index 000000000..10eac04a8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/__init__.pyi @@ -0,0 +1,55 @@ +import sys +from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union + +from .decoder import JSONDecoder as JSONDecoder +from .encoder import JSONEncoder as JSONEncoder +if sys.version_info >= (3, 5): + from .decoder import JSONDecodeError as JSONDecodeError + +def dumps(obj: Any, + skipkeys: bool = ..., + ensure_ascii: bool = ..., + check_circular: bool = ..., + allow_nan: bool = ..., + cls: Any = ..., + indent: Union[None, int, str] = ..., + separators: Optional[Tuple[str, str]] = ..., + default: Optional[Callable[[Any], Any]] = ..., + sort_keys: bool = ..., + **kwds: Any) -> str: ... + +def dump(obj: Any, + fp: IO[str], + skipkeys: bool = ..., + ensure_ascii: bool = ..., + check_circular: bool = ..., + allow_nan: bool = ..., + cls: Any = ..., + indent: Union[None, int, str] = ..., + separators: Optional[Tuple[str, str]] = ..., + default: Optional[Callable[[Any], Any]] = ..., + sort_keys: bool = ..., + **kwds: Any) -> None: ... + +def loads(s: Union[str, bytes, bytearray], + encoding: Any = ..., # ignored and deprecated + cls: Any = ..., + object_hook: Optional[Callable[[Dict], Any]] = ..., + parse_float: Optional[Callable[[str], Any]] = ..., + parse_int: Optional[Callable[[str], Any]] = ..., + parse_constant: Optional[Callable[[str], Any]] = ..., + object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., + **kwds: Any) -> Any: ... + +if sys.version_info >= (3, 6): + _LoadIO = IO[Any] +else: + _LoadIO = IO[str] +def load(fp: _LoadIO, + cls: Any = ..., + object_hook: Optional[Callable[[Dict], Any]] = ..., + parse_float: Optional[Callable[[str], Any]] = ..., + parse_int: Optional[Callable[[str], Any]] = ..., + parse_constant: Optional[Callable[[str], Any]] = ..., + object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., + **kwds: Any) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/decoder.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/decoder.pyi new file mode 100644 index 000000000..d5c7c04e4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/decoder.pyi @@ -0,0 +1,28 @@ +import sys +from typing import Any, Callable, Dict, List, Optional, Tuple + +if sys.version_info >= (3, 5): + class JSONDecodeError(ValueError): + msg: str + doc: str + pos: int + lineno: int + colno: int + def __init__(self, msg: str, doc: str, pos: int) -> None: ... + +class JSONDecoder: + object_hook = ... # type: Callable[[Dict[str, Any]], Any] + parse_float = ... # type: Callable[[str], Any] + parse_int = ... # type: Callable[[str], Any] + parse_constant = ... # Callable[[str], Any] + strict = ... # type: bool + object_pairs_hook = ... # type: Callable[[List[Tuple[str, Any]]], Any] + + def __init__(self, object_hook: Optional[Callable[[Dict[str, Any]], Any]] = ..., + parse_float: Optional[Callable[[str], Any]] = ..., + parse_int: Optional[Callable[[str], Any]] = ..., + parse_constant: Optional[Callable[[str], Any]] = ..., + strict: bool = ..., + object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], Any]] = ...) -> None: ... + def decode(self, s: str) -> Any: ... + def raw_decode(self, s: str, idx: int = ...) -> Tuple[Any, int]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/encoder.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/encoder.pyi new file mode 100644 index 000000000..cee377b09 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/json/encoder.pyi @@ -0,0 +1,20 @@ +from typing import Any, Callable, Iterator, Optional, Tuple + +class JSONEncoder: + item_separator = ... # type: str + key_separator = ... # type: str + + skipkeys = ... # type: bool + ensure_ascii = ... # type: bool + check_circular = ... # type: bool + allow_nan = ... # type: bool + sort_keys = ... # type: bool + indent = ... # type: int + + def __init__(self, skipkeys: bool = ..., ensure_ascii: bool = ..., + check_circular: bool = ..., allow_nan: bool = ..., sort_keys: bool = ..., + indent: Optional[int] = ..., separators: Optional[Tuple[str, str]] = ..., default: Optional[Callable] = ...) -> None: ... + + def default(self, o: Any) -> Any: ... + def encode(self, o: Any) -> str: ... + def iterencode(self, o: Any, _one_shot: bool = ...) -> Iterator[str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/macpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/macpath.pyi new file mode 100644 index 000000000..20a0da8fd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/macpath.pyi @@ -0,0 +1,48 @@ +# NB: posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +# Stubs for os.path +# Ron Murawski + +# based on http://docs.python.org/3.2/library/os.path.html +import sys +from typing import Any, List, Tuple, IO + +# ----- os.path variables ----- +supports_unicode_filenames = False + +# ----- os.path function stubs ----- +def abspath(path: str) -> str: ... +def basename(path) -> str: ... +def commonprefix(list: List[str]) -> str: ... +def dirname(path: str) -> str: ... +def exists(path: str) -> bool: ... +def lexists(path: str) -> bool: ... +def expanduser(path: str) -> str: ... +def expandvars(path: str) -> str: ... +def getatime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getmtime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getctime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getsize(path: str) -> int: ... +def isabs(path: str) -> bool: ... +def isfile(path: str) -> bool: ... +def isdir(path: str) -> bool: ... +def islink(path: str) -> bool: ... +def ismount(path: str) -> bool: ... +def join(path: str, *paths: str) -> str: ... +def normcase(path: str) -> str: ... +def normpath(path: str) -> str: ... +def realpath(path: str) -> str: ... +def relpath(path: str, start: str = ...) -> str: ... +def samefile(path1: str, path2: str) -> bool: ... + +def sameopenfile(fp1: IO[Any], fp2: IO[Any]) -> bool: ... + +# def samestat(stat1: stat_result, stat2: stat_result) -> bool: +# ... # Unix only +def split(path: str) -> Tuple[str, str]: ... +def splitdrive(path: str) -> Tuple[str, str]: ... +def splitext(path: str) -> Tuple[str, str]: ... +if sys.version_info < (3, 7) and sys.platform == 'win32': + def splitunc(path: str) -> Tuple[str, str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/msvcrt.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/msvcrt.pyi new file mode 100644 index 000000000..bcab64cd9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/msvcrt.pyi @@ -0,0 +1,8 @@ +# Stubs for msvcrt + +# NOTE: These are incomplete! + +from typing import overload, BinaryIO, TextIO + +def get_osfhandle(file: int) -> int: ... +def open_osfhandle(handle: int, flags: int) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/__init__.pyi new file mode 100644 index 000000000..c5e1e6e08 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/__init__.pyi @@ -0,0 +1,83 @@ +# Stubs for multiprocessing + +from typing import ( + Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List, + Union, Sequence, Tuple +) + +from logging import Logger +from multiprocessing import connection, pool, synchronize +from multiprocessing.context import ( + BaseContext, + ProcessError as ProcessError, BufferTooShort as BufferTooShort, TimeoutError as TimeoutError, AuthenticationError as AuthenticationError) +from multiprocessing.managers import SyncManager +from multiprocessing.process import current_process as current_process +from multiprocessing.queues import Queue as Queue, SimpleQueue as SimpleQueue, JoinableQueue as JoinableQueue +import sys + +# N.B. The functions below are generated at runtime by partially applying +# multiprocessing.context.BaseContext's methods, so the two signatures should +# be identical (modulo self). + +# Sychronization primitives +_LockLike = Union[synchronize.Lock, synchronize.RLock] +def Barrier(parties: int, + action: Optional[Callable] = ..., + timeout: Optional[float] = ...) -> synchronize.Barrier: ... +def BoundedSemaphore(value: int = ...) -> synchronize.BoundedSemaphore: ... +def Condition(lock: Optional[_LockLike] = ...) -> synchronize.Condition: ... +def Event(lock: Optional[_LockLike] = ...) -> synchronize.Event: ... +def Lock() -> synchronize.Lock: ... +def RLock() -> synchronize.RLock: ... +def Semaphore(value: int = ...) -> synchronize.Semaphore: ... + +def Pipe(duplex: bool = ...) -> Tuple[connection.Connection, connection.Connection]: ... + +def Pool(processes: Optional[int] = ..., + initializer: Optional[Callable[..., Any]] = ..., + initargs: Iterable[Any] = ..., + maxtasksperchild: Optional[int] = ...) -> pool.Pool: ... + +class Process(): + name: str + daemon: bool + pid: Optional[int] + exitcode: Optional[int] + authkey: bytes + sentinel: int + # TODO: set type of group to None + def __init__(self, + group: Any = ..., + target: Optional[Callable] = ..., + name: Optional[str] = ..., + args: Iterable[Any] = ..., + kwargs: Mapping[Any, Any] = ..., + *, + daemon: Optional[bool] = ...) -> None: ... + def start(self) -> None: ... + def run(self) -> None: ... + def terminate(self) -> None: ... + if sys.version_info >= (3, 7): + def kill(self) -> None: ... + def close(self) -> None: ... + def is_alive(self) -> bool: ... + def join(self, timeout: Optional[float] = ...) -> None: ... + +class Value(): + value: Any = ... + def __init__(self, typecode_or_type: str, *args: Any, lock: bool = ...) -> None: ... + +# ----- multiprocessing function stubs ----- +def active_children() -> List[Process]: ... +def allow_connection_pickling() -> None: ... +def cpu_count() -> int: ... +def freeze_support() -> None: ... +def get_logger() -> Logger: ... +def log_to_stderr(level: Optional[Union[str, int]] = ...) -> Logger: ... +def Manager() -> SyncManager: ... +def set_forkserver_preload(module_names: List[str]) -> None: ... +def set_executable(executable: str) -> None: ... +def get_all_start_methods() -> List[str]: ... +def get_context(method: Optional[str] = ...) -> BaseContext: ... +def get_start_method(allow_none: Optional[bool]) -> Optional[str]: ... +def set_start_method(method: str, force: Optional[bool] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/connection.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/connection.pyi new file mode 100644 index 000000000..7627b5226 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/connection.pyi @@ -0,0 +1,36 @@ +from typing import Any, Iterable, List, Optional, Tuple, Type, Union +import socket +import types + +# https://docs.python.org/3/library/multiprocessing.html#address-formats +_Address = Union[str, Tuple[str, int]] + +def deliver_challenge(connection: Connection, authkey: bytes) -> None: ... +def answer_challenge(connection: Connection, authkey: bytes) -> None: ... +def wait(object_list: Iterable[Union[Connection, socket.socket, int]], timeout: Optional[float] = ...) -> List[Union[Connection, socket.socket, int]]: ... +def Client(address: _Address, family: Optional[str] = ..., authkey: Optional[bytes] = ...) -> Connection: ... +def Pipe(duplex: bool = ...) -> Tuple[Connection, Connection]: ... + +class Listener: + def __init__(self, address: Optional[_Address] = ..., family: Optional[str] = ..., backlog: int = ..., authkey: Optional[bytes] = ...) -> None: ... + def accept(self) -> Connection: ... + def close(self) -> None: ... + @property + def address(self) -> _Address: ... + @property + def last_accepted(self) -> Optional[_Address]: ... + def __enter__(self) -> Listener: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_value: Optional[BaseException], exc_tb: Optional[types.TracebackType]) -> None: ... + +class Connection: + def close(self) -> None: ... + def fileno(self) -> int: ... + def poll(self, timeout: Optional[float] = ...) -> bool: ... + def recv(self) -> Any: ... + def recv_bytes(self, maxlength: Optional[int] = ...) -> bytes: ... + def recv_bytes_into(self, buf: Any, offset: int = ...) -> int: ... + def send(self, obj: Any) -> None: ... + def send_bytes(self, + buf: bytes, + offset: int = ..., + size: Optional[int] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/context.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/context.pyi new file mode 100644 index 000000000..359d8907c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/context.pyi @@ -0,0 +1,179 @@ +# Stubs for multiprocessing.context + +from logging import Logger +import multiprocessing +from multiprocessing import synchronize +from multiprocessing import queues +import sys +from typing import ( + Any, Callable, Iterable, Optional, List, Mapping, Sequence, Tuple, Type, + Union, +) + +_LockLike = Union[synchronize.Lock, synchronize.RLock] + +class ProcessError(Exception): ... + +class BufferTooShort(ProcessError): ... + +class TimeoutError(ProcessError): ... + +class AuthenticationError(ProcessError): ... + +class BaseContext(object): + ProcessError = ... # type: Type[Exception] + BufferTooShort = ... # type: Type[Exception] + TimeoutError = ... # type: Type[Exception] + AuthenticationError = ... # type: Type[Exception] + + # N.B. The methods below are applied at runtime to generate + # multiprocessing.*, so the signatures should be identical (modulo self). + + @staticmethod + def current_process() -> multiprocessing.Process: ... + @staticmethod + def active_children() -> List[multiprocessing.Process]: ... + def cpu_count(self) -> int: ... + # TODO: change return to SyncManager once a stub exists in multiprocessing.managers + def Manager(self) -> Any: ... + # TODO: change return to Pipe once a stub exists in multiprocessing.connection + def Pipe(self, duplex: bool) -> Any: ... + + def Barrier(self, + parties: int, + action: Optional[Callable] = ..., + timeout: Optional[float] = ...) -> synchronize.Barrier: ... + def BoundedSemaphore(self, + value: int = ...) -> synchronize.BoundedSemaphore: ... + def Condition(self, + lock: Optional[_LockLike] = ...) -> synchronize.Condition: ... + def Event(self, lock: Optional[_LockLike] = ...) -> synchronize.Event: ... + def Lock(self) -> synchronize.Lock: ... + def RLock(self) -> synchronize.RLock: ... + def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ... + + def Queue(self, maxsize: int = ...) -> queues.Queue: ... + def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue: ... + def SimpleQueue(self) -> queues.SimpleQueue: ... + def Pool( + self, + processes: Optional[int] = ..., + initializer: Optional[Callable[..., Any]] = ..., + initargs: Iterable[Any] = ..., + maxtasksperchild: Optional[int] = ... + ) -> multiprocessing.pool.Pool: ... + def Process( + self, + group: Any = ..., + target: Optional[Callable] = ..., + name: Optional[str] = ..., + args: Iterable[Any] = ..., + kwargs: Mapping[Any, Any] = ..., + *, + daemon: Optional[bool] = ... + ) -> multiprocessing.Process: ... + # TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out + # how to handle the ctype + # TODO: change return to RawValue once a stub exists in multiprocessing.sharedctypes + def RawValue(self, typecode_or_type: Any, *args: Any) -> Any: ... + # TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out + # how to handle the ctype + # TODO: change return to RawArray once a stub exists in multiprocessing.sharedctypes + def RawArray(self, typecode_or_type: Any, size_or_initializer: Union[int, Sequence[Any]]) -> Any: ... + # TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out + # how to handle the ctype + # TODO: change return to Value once a stub exists in multiprocessing.sharedctypes + def Value( + self, + typecode_or_type: Any, + *args: Any, + lock: bool = ... + ) -> Any: ... + # TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out + # how to handle the ctype + # TODO: change return to Array once a stub exists in multiprocessing.sharedctypes + def Array( + self, + typecode_or_type: Any, + size_or_initializer: Union[int, Sequence[Any]], + *, + lock: bool = ... + ) -> Any: ... + def freeze_support(self) -> None: ... + def get_logger(self) -> Logger: ... + def log_to_stderr(self, level: Optional[str] = ...) -> Logger: ... + def allow_connection_pickling(self) -> None: ... + def set_executable(self, executable: str) -> None: ... + def set_forkserver_preload(self, module_names: List[str]) -> None: ... + def get_context(self, method: Optional[str] = ...) -> BaseContext: ... + def get_start_method(self, allow_none: bool = ...) -> str: ... + def set_start_method(self, method: Optional[str] = ...) -> None: ... + @property + def reducer(self) -> str: ... + @reducer.setter + def reducer(self, reduction: str) -> None: ... + def _check_available(self) -> None: ... + +class Process(object): + _start_method: Optional[str] + @staticmethod + # TODO: type should be BaseProcess once a stub in multiprocessing.process exists + def _Popen(process_obj: Any) -> DefaultContext: ... + +class DefaultContext(object): + Process = ... # type: Type[multiprocessing.Process] + + def __init__(self, context: BaseContext) -> None: ... + def get_context(self, method: Optional[str] = ...) -> BaseContext: ... + def set_start_method(self, method: str, force: bool = ...) -> None: ... + def get_start_method(self, allow_none: bool = ...) -> str: ... + def get_all_start_methods(self) -> List[str]: ... + +if sys.platform != 'win32': + # TODO: type should be BaseProcess once a stub in multiprocessing.process exists + class ForkProcess(Any): # type: ignore + _start_method: str + @staticmethod + def _Popen(process_obj: Any) -> Any: ... + + # TODO: type should be BaseProcess once a stub in multiprocessing.process exists + class SpawnProcess(Any): # type: ignore + _start_method: str + @staticmethod + def _Popen(process_obj: Any) -> SpawnProcess: ... + + # TODO: type should be BaseProcess once a stub in multiprocessing.process exists + class ForkServerProcess(Any): # type: ignore + _start_method: str + @staticmethod + def _Popen(process_obj: Any) -> Any: ... + + class ForkContext(BaseContext): + _name: str + Process = ... # type: Type[ForkProcess] + + class SpawnContext(BaseContext): + _name: str + Process = ... # type: Type[SpawnProcess] + + class ForkServerContext(BaseContext): + _name: str + Process = ... # type: Type[ForkServerProcess] +else: + # TODO: type should be BaseProcess once a stub in multiprocessing.process exists + class SpawnProcess(Any): # type: ignore + _start_method: str + @staticmethod + # TODO: type should be BaseProcess once a stub in multiprocessing.process exists + def _Popen(process_obj: Process) -> Any: ... + + class SpawnContext(BaseContext): + _name: str + Process = ... # type: Type[SpawnProcess] + +def _force_start_method(method: str) -> None: ... +# TODO: type should be BaseProcess once a stub in multiprocessing.process exists +def get_spawning_popen() -> Optional[Any]: ... +# TODO: type should be BaseProcess once a stub in multiprocessing.process exists +def set_spawning_popen(popen: Any) -> None: ... +def assert_spawning(obj: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/dummy/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/dummy/__init__.pyi new file mode 100644 index 000000000..b393726ce --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/dummy/__init__.pyi @@ -0,0 +1,42 @@ +from typing import Any, Optional, List, Type + +import array +import sys +import threading +import weakref + +from .connection import Pipe +from threading import Lock, RLock, Semaphore, BoundedSemaphore +from threading import Event, Condition, Barrier +from queue import Queue + +JoinableQueue = Queue + + +class DummyProcess(threading.Thread): + _children = ... # type: weakref.WeakKeyDictionary + _parent = ... # type: threading.Thread + _pid = ... # type: None + _start_called = ... # type: int + exitcode = ... # type: Optional[int] + def __init__(self, group=..., target=..., name=..., args=..., kwargs=...) -> None: ... + +Process = DummyProcess + +class Namespace(object): + def __init__(self, **kwds) -> None: ... + +class Value(object): + _typecode = ... # type: Any + _value = ... # type: Any + value = ... # type: Any + def __init__(self, typecode, value, lock=...) -> None: ... + + +def Array(typecode, sequence, lock=...) -> array.array: ... +def Manager() -> Any: ... +def Pool(processes=..., initializer=..., initargs=...) -> Any: ... +def active_children() -> List: ... +def current_process() -> threading.Thread: ... +def freeze_support() -> None: ... +def shutdown() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/dummy/connection.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/dummy/connection.pyi new file mode 100644 index 000000000..fd0d9bd9b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/dummy/connection.pyi @@ -0,0 +1,35 @@ +from typing import Any, List, Optional, Tuple, Type, TypeVar + +from queue import Queue + +families = ... # type: List[None] + +_TConnection = TypeVar('_TConnection', bound=Connection) +_TListener = TypeVar('_TListener', bound=Listener) + +class Connection(object): + _in = ... # type: Any + _out = ... # type: Any + recv = ... # type: Any + recv_bytes = ... # type: Any + send = ... # type: Any + send_bytes = ... # type: Any + def __enter__(self: _TConnection) -> _TConnection: ... + def __exit__(self, exc_type, exc_value, exc_tb) -> None: ... + def __init__(self, _in, _out) -> None: ... + def close(self) -> None: ... + def poll(self, timeout: float=...) -> bool: ... + +class Listener(object): + _backlog_queue = ... # type: Optional[Queue] + @property + def address(self) -> Optional[Queue]: ... + def __enter__(self: _TListener) -> _TListener: ... + def __exit__(self, exc_type, exc_value, exc_tb) -> None: ... + def __init__(self, address=..., family=..., backlog=...) -> None: ... + def accept(self) -> Connection: ... + def close(self) -> None: ... + + +def Client(address) -> Connection: ... +def Pipe(duplex: bool=...) -> Tuple[Connection, Connection]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/managers.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/managers.pyi new file mode 100644 index 000000000..656ee8d2c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/managers.pyi @@ -0,0 +1,42 @@ +# Stubs for multiprocessing.managers + +# NOTE: These are incomplete! + +import queue +import threading +from typing import ( + Any, Callable, ContextManager, Dict, Iterable, List, Mapping, Optional, + Sequence, Tuple, TypeVar, Union, +) + +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +class Namespace: ... + +_Namespace = Namespace + +class BaseManager(ContextManager[BaseManager]): + address: Union[str, Tuple[str, int]] + def connect(self) -> None: ... + def register(self, typeid: str, callable: Any = ...) -> None: ... + def shutdown(self) -> None: ... + def start(self, initializer: Optional[Callable[..., Any]] = ..., + initargs: Iterable[Any] = ...) -> None: ... + +class SyncManager(BaseManager): + def BoundedSemaphore(self, value: Any = ...) -> threading.BoundedSemaphore: ... + def Condition(self, lock: Any = ...) -> threading.Condition: ... + def Event(self) -> threading.Event: ... + def Lock(self) -> threading.Lock: ... + def Namespace(self) -> _Namespace: ... + def Queue(self, maxsize: int = ...) -> queue.Queue: ... + def RLock(self) -> threading.RLock: ... + def Semaphore(self, value: Any = ...) -> threading.Semaphore: ... + def Array(self, typecode: Any, sequence: Sequence[_T]) -> Sequence[_T]: ... + def Value(self, typecode: Any, value: _T) -> _T: ... + def dict(self, sequence: Mapping[_KT, _VT] = ...) -> Dict[_KT, _VT]: ... + def list(self, sequence: Sequence[_T] = ...) -> List[_T]: ... + +class RemoteError(Exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/pool.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/pool.pyi new file mode 100644 index 000000000..bf33cb2f3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/pool.pyi @@ -0,0 +1,76 @@ +from typing import ( + Any, Callable, ContextManager, Iterable, Mapping, Optional, List, + TypeVar, Generic, +) + +_PT = TypeVar('_PT', bound='Pool') +_S = TypeVar('_S') +_T = TypeVar('_T') + +class AsyncResult(Generic[_T]): + def get(self, timeout: Optional[float] = ...) -> _T: ... + def wait(self, timeout: Optional[float] = ...) -> None: ... + def ready(self) -> bool: ... + def successful(self) -> bool: ... + +_IMIT = TypeVar('_IMIT', bound=IMapIterator) + +class IMapIterator(Iterable[_T]): + def __iter__(self: _IMIT) -> _IMIT: ... + def next(self, timeout: Optional[float] = ...) -> _T: ... + def __next__(self, timeout: Optional[float] = ...) -> _T: ... + +class Pool(ContextManager[Pool]): + def __init__(self, processes: Optional[int] = ..., + initializer: Optional[Callable[..., None]] = ..., + initargs: Iterable[Any] = ..., + maxtasksperchild: Optional[int] = ..., + context: Optional[Any] = ...) -> None: ... + def apply(self, + func: Callable[..., _T], + args: Iterable[Any] = ..., + kwds: Mapping[str, Any] = ...) -> _T: ... + def apply_async(self, + func: Callable[..., _T], + args: Iterable[Any] = ..., + kwds: Mapping[str, Any] = ..., + callback: Optional[Callable[[_T], None]] = ..., + error_callback: Optional[Callable[[BaseException], None]] = ...) -> AsyncResult[_T]: ... + def map(self, + func: Callable[[_S], _T], + iterable: Iterable[_S] = ..., + chunksize: Optional[int] = ...) -> List[_T]: ... + def map_async(self, func: Callable[[_S], _T], + iterable: Iterable[_S] = ..., + chunksize: Optional[int] = ..., + callback: Optional[Callable[[_T], None]] = ..., + error_callback: Optional[Callable[[BaseException], None]] = ...) -> AsyncResult[List[_T]]: ... + def imap(self, + func: Callable[[_S], _T], + iterable: Iterable[_S] = ..., + chunksize: Optional[int] = ...) -> IMapIterator[_T]: ... + def imap_unordered(self, + func: Callable[[_S], _T], + iterable: Iterable[_S] = ..., + chunksize: Optional[int] = ...) -> IMapIterator[_T]: ... + def starmap(self, + func: Callable[..., _T], + iterable: Iterable[Iterable[Any]] = ..., + chunksize: Optional[int] = ...) -> List[_T]: ... + def starmap_async(self, + func: Callable[..., _T], + iterable: Iterable[Iterable[Any]] = ..., + chunksize: Optional[int] = ..., + callback: Optional[Callable[[_T], None]] = ..., + error_callback: Optional[Callable[[BaseException], None]] = ...) -> AsyncResult[List[_T]]: ... + def close(self) -> None: ... + def terminate(self) -> None: ... + def join(self) -> None: ... + def __enter__(self: _PT) -> _PT: ... + + +class ThreadPool(Pool, ContextManager[ThreadPool]): + + def __init__(self, processes: Optional[int] = ..., + initializer: Optional[Callable[..., Any]] = ..., + initargs: Iterable[Any] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/process.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/process.pyi new file mode 100644 index 000000000..df8ea9300 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/process.pyi @@ -0,0 +1,5 @@ +from typing import List +from multiprocessing import Process + +def current_process() -> Process: ... +def active_children() -> List[Process]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/queues.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/queues.pyi new file mode 100644 index 000000000..c6dd0f20d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/queues.pyi @@ -0,0 +1,30 @@ +from typing import Any, Generic, Optional, TypeVar + +import queue + +_T = TypeVar('_T') + +class Queue(queue.Queue[_T]): + # FIXME: `ctx` is a circular dependency and it's not actually optional. + # It's marked as such to be able to use the generic Queue in __init__.pyi. + def __init__(self, maxsize: int = ..., *, ctx: Any = ...) -> None: ... + def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... + def put(self, obj: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... + def qsize(self) -> int: ... + def empty(self) -> bool: ... + def full(self) -> bool: ... + def put_nowait(self, item: _T) -> None: ... + def get_nowait(self) -> _T: ... + def close(self) -> None: ... + def join_thread(self) -> None: ... + def cancel_join_thread(self) -> None: ... + +class JoinableQueue(Queue[_T]): + def task_done(self) -> None: ... + def join(self) -> None: ... + +class SimpleQueue(Generic[_T]): + def __init__(self, *, ctx: Any = ...) -> None: ... + def empty(self) -> bool: ... + def get(self) -> _T: ... + def put(self, item: _T) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/synchronize.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/synchronize.pyi new file mode 100644 index 000000000..9b226810e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/multiprocessing/synchronize.pyi @@ -0,0 +1,63 @@ +from typing import Callable, ContextManager, Optional, Union + +from multiprocessing.context import BaseContext +import threading +import sys + +_LockLike = Union[Lock, RLock] + +class Barrier(threading.Barrier): + def __init__(self, + parties: int, + action: Optional[Callable] = ..., + timeout: Optional[float] = ..., + * + ctx: BaseContext) -> None: ... + +class BoundedSemaphore(Semaphore): + def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ... + +class Condition(ContextManager[bool]): + def __init__(self, + lock: Optional[_LockLike] = ..., + *, + ctx: BaseContext) -> None: ... + if sys.version_info >= (3, 7): + def notify(self, n: int = ...) -> None: ... + else: + def notify(self) -> None: ... + def notify_all(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> bool: ... + def wait_for(self, + predicate: Callable[[], bool], + timeout: Optional[float] = ...) -> bool: ... + def acquire(self, + block: bool = ..., + timeout: Optional[float] = ...) -> bool: ... + def release(self) -> None: ... + +class Event(ContextManager[bool]): + def __init__(self, + lock: Optional[_LockLike] = ..., + *, + ctx: BaseContext) -> None: ... + def is_set(self) -> bool: ... + def set(self) -> None: ... + def clear(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> bool: ... + +class Lock(SemLock): + def __init__(self, *, ctx: BaseContext) -> None: ... + +class RLock(SemLock): + def __init__(self, *, ctx: BaseContext) -> None: ... + +class Semaphore(SemLock): + def __init__(self, value: int = ..., *, ctx: BaseContext) -> None: ... + +# Not part of public API +class SemLock(ContextManager[bool]): + def acquire(self, + block: bool = ..., + timeout: Optional[float] = ...) -> bool: ... + def release(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/nntplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/nntplib.pyi new file mode 100644 index 000000000..00abdd994 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/nntplib.pyi @@ -0,0 +1,102 @@ +# Stubs for nntplib (Python 3) + +import datetime +import socket +import ssl +from typing import Any, Dict, IO, Iterable, List, NamedTuple, Optional, Tuple, TypeVar, Union + +_SelfT = TypeVar('_SelfT', bound=_NNTPBase) +_File = Union[IO[bytes], bytes, str, None] + + +class NNTPError(Exception): + response: str +class NNTPReplyError(NNTPError): ... +class NNTPTemporaryError(NNTPError): ... +class NNTPPermanentError(NNTPError): ... +class NNTPProtocolError(NNTPError): ... +class NNTPDataError(NNTPError): ... + +NNTP_PORT: int +NNTP_SSL_PORT: int + +GroupInfo = NamedTuple('GroupInfo', [ + ('group', str), + ('last', str), + ('first', str), + ('flag', str), +]) +ArticleInfo = NamedTuple('ArticleInfo', [ + ('number', int), + ('message_id', str), + ('lines', List[bytes]), +]) + +def decode_header(header_str: str) -> str: ... + +class _NNTPBase: + encoding: str + errors: str + + host: str + file: IO[bytes] + debugging: int + welcome: str + readermode_afterauth: bool + tls_on: bool + authenticated: bool + nntp_implementation: str + nntp_version: int + + def __init__(self, file: IO[bytes], host: str, + readermode: Optional[bool] = ..., timeout: float = ...) -> None: ... + def __enter__(self: _SelfT) -> _SelfT: ... + def __exit__(self, *args: Any) -> None: ... + def getwelcome(self) -> str: ... + def getcapabilities(self) -> Dict[str, List[str]]: ... + def set_debuglevel(self, level: int) -> None: ... + def debug(self, level: int) -> None: ... + def capabilities(self) -> Tuple[str, Dict[str, List[str]]]: ... + def newgroups(self, date: Union[datetime.date, datetime.datetime], *, file: _File = ...) -> Tuple[str, List[str]]: ... + def newnews(self, group: str, date: Union[datetime.date, datetime.datetime], *, file: _File = ...) -> Tuple[str, List[str]]: ... + def list(self, group_pattern: Optional[str] = ..., *, file: _File = ...) -> Tuple[str, List[str]]: ... + def description(self, group: str) -> str: ... + def descriptions(self, group_pattern: str) -> Tuple[str, Dict[str, str]]: ... + def group(self, name: str) -> Tuple[str, int, int, int, str]: ... + def help(self, *, file: _File = ...) -> Tuple[str, List[str]]: ... + def stat(self, message_spec: Any = ...) -> Tuple[str, int, str]: ... + def next(self) -> Tuple[str, int, str]: ... + def last(self) -> Tuple[str, int, str]: ... + def head(self, message_spec: Any = ..., *, file: _File = ...) -> Tuple[str, ArticleInfo]: ... + def body(self, message_spec: Any = ..., *, file: _File = ...) -> Tuple[str, ArticleInfo]: ... + def article(self, message_spec: Any = ..., *, file: _File = ...) -> Tuple[str, ArticleInfo]: ... + def slave(self) -> str: ... + def xhdr(self, hdr: str, str: Any, *, file: _File = ...) -> Tuple[str, List[str]]: ... + def xover(self, start: int, end: int, *, file: _File = ...) -> Tuple[str, List[Tuple[int, Dict[str, str]]]]: ... + def over(self, message_spec: Union[None, str, List[Any], Tuple[Any, ...]], *, file: _File = ...) -> Tuple[str, List[Tuple[int, Dict[str, str]]]]: ... + def xgtitle(self, group: str, *, file: _File = ...) -> Tuple[str, List[Tuple[str, str]]]: ... + def xpath(self, id: Any) -> Tuple[str, str]: ... + def date(self) -> Tuple[str, datetime.datetime]: ... + def post(self, data: Union[bytes, Iterable[bytes]]) -> str: ... + def ihave(self, message_id: Any, data: Union[bytes, Iterable[bytes]]) -> str: ... + def quit(self) -> str: ... + def login(self, user: Optional[str] = ..., password: Optional[str] = ..., usenetrc: bool = ...) -> None: ... + def starttls(self, ssl_context: Optional[ssl.SSLContext] = ...) -> None: ... + + +class NNTP(_NNTPBase): + port: int + sock: socket.socket + + def __init__(self, host: str, port: int = ..., user: Optional[str] = ..., password: Optional[str] = ..., + readermode: Optional[bool] = ..., usenetrc: bool = ..., + timeout: float = ...) -> None: ... + + +class NNTP_SSL(_NNTPBase): + sock: socket.socket + + def __init__(self, host: str, port: int = ..., user: Optional[str] = ..., password: Optional[str] = ..., + ssl_context: Optional[ssl.SSLContext] = ..., + readermode: Optional[bool] = ..., usenetrc: bool = ..., + timeout: float = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/ntpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/ntpath.pyi new file mode 100644 index 000000000..20a0da8fd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/ntpath.pyi @@ -0,0 +1,48 @@ +# NB: posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +# Stubs for os.path +# Ron Murawski + +# based on http://docs.python.org/3.2/library/os.path.html +import sys +from typing import Any, List, Tuple, IO + +# ----- os.path variables ----- +supports_unicode_filenames = False + +# ----- os.path function stubs ----- +def abspath(path: str) -> str: ... +def basename(path) -> str: ... +def commonprefix(list: List[str]) -> str: ... +def dirname(path: str) -> str: ... +def exists(path: str) -> bool: ... +def lexists(path: str) -> bool: ... +def expanduser(path: str) -> str: ... +def expandvars(path: str) -> str: ... +def getatime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getmtime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getctime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getsize(path: str) -> int: ... +def isabs(path: str) -> bool: ... +def isfile(path: str) -> bool: ... +def isdir(path: str) -> bool: ... +def islink(path: str) -> bool: ... +def ismount(path: str) -> bool: ... +def join(path: str, *paths: str) -> str: ... +def normcase(path: str) -> str: ... +def normpath(path: str) -> str: ... +def realpath(path: str) -> str: ... +def relpath(path: str, start: str = ...) -> str: ... +def samefile(path1: str, path2: str) -> bool: ... + +def sameopenfile(fp1: IO[Any], fp2: IO[Any]) -> bool: ... + +# def samestat(stat1: stat_result, stat2: stat_result) -> bool: +# ... # Unix only +def split(path: str) -> Tuple[str, str]: ... +def splitdrive(path: str) -> Tuple[str, str]: ... +def splitext(path: str) -> Tuple[str, str]: ... +if sys.version_info < (3, 7) and sys.platform == 'win32': + def splitunc(path: str) -> Tuple[str, str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/nturl2path.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/nturl2path.pyi new file mode 100644 index 000000000..b8ad8d682 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/nturl2path.pyi @@ -0,0 +1,2 @@ +def url2pathname(url: str) -> str: ... +def pathname2url(p: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/os/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/os/__init__.pyi new file mode 100644 index 000000000..a375cd65b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/os/__init__.pyi @@ -0,0 +1,644 @@ +# Stubs for os +# Ron Murawski + +from io import TextIOWrapper as _TextIOWrapper +import sys +from typing import ( + Mapping, MutableMapping, Dict, List, Any, Tuple, IO, Iterable, Iterator, NoReturn, overload, Union, AnyStr, + Optional, Generic, Set, Callable, Text, Sequence, NamedTuple, TypeVar, ContextManager +) + +# Re-exported names from other modules. +from builtins import OSError as error +from posix import stat_result as stat_result +from . import path as path + +_T = TypeVar('_T') + +# ----- os variables ----- + +if sys.version_info >= (3, 2): + supports_bytes_environ: bool + +if sys.version_info >= (3, 3): + supports_dir_fd: Set[Callable[..., Any]] + supports_fd: Set[Callable[..., Any]] + supports_effective_ids: Set[Callable[..., Any]] + supports_follow_symlinks: Set[Callable[..., Any]] + + PRIO_PROCESS: int # Unix only + PRIO_PGRP: int # Unix only + PRIO_USER: int # Unix only + + F_LOCK: int # Unix only + F_TLOCK: int # Unix only + F_ULOCK: int # Unix only + F_TEST: int # Unix only + + POSIX_FADV_NORMAL: int # Unix only + POSIX_FADV_SEQUENTIAL: int # Unix only + POSIX_FADV_RANDOM: int # Unix only + POSIX_FADV_NOREUSE: int # Unix only + POSIX_FADV_WILLNEED: int # Unix only + POSIX_FADV_DONTNEED: int # Unix only + + SF_NODISKIO: int # Unix only + SF_MNOWAIT: int # Unix only + SF_SYNC: int # Unix only + + XATTR_SIZE_MAX: int # Linux only + XATTR_CREATE: int # Linux only + XATTR_REPLACE: int # Linux only + + P_PID: int # Unix only + P_PGID: int # Unix only + P_ALL: int # Unix only + + WEXITED: int # Unix only + WSTOPPED: int # Unix only + WNOWAIT: int # Unix only + + CLD_EXITED: int # Unix only + CLD_DUMPED: int # Unix only + CLD_TRAPPED: int # Unix only + CLD_CONTINUED: int # Unix only + + SCHED_OTHER: int # some flavors of Unix + SCHED_BATCH: int # some flavors of Unix + SCHED_IDLE: int # some flavors of Unix + SCHED_SPORADIC: int # some flavors of Unix + SCHED_FIFO: int # some flavors of Unix + SCHED_RR: int # some flavors of Unix + SCHED_RESET_ON_FORK: int # some flavors of Unix + + RTLD_LAZY: int + RTLD_NOW: int + RTLD_GLOBAL: int + RTLD_LOCAL: int + RTLD_NODELETE: int + RTLD_NOLOAD: int + RTLD_DEEPBIND: int + + +SEEK_SET: int +SEEK_CUR: int +SEEK_END: int +if sys.version_info >= (3, 3): + SEEK_DATA: int # some flavors of Unix + SEEK_HOLE: int # some flavors of Unix + +O_RDONLY: int +O_WRONLY: int +O_RDWR: int +O_APPEND: int +O_CREAT: int +O_EXCL: int +O_TRUNC: int +O_DSYNC: int # Unix only +O_RSYNC: int # Unix only +O_SYNC: int # Unix only +O_NDELAY: int # Unix only +O_NONBLOCK: int # Unix only +O_NOCTTY: int # Unix only +if sys.version_info >= (3, 3): + O_CLOEXEC: int # Unix only +O_SHLOCK: int # Unix only +O_EXLOCK: int # Unix only +O_BINARY: int # Windows only +O_NOINHERIT: int # Windows only +O_SHORT_LIVED: int # Windows only +O_TEMPORARY: int # Windows only +O_RANDOM: int # Windows only +O_SEQUENTIAL: int # Windows only +O_TEXT: int # Windows only +O_ASYNC: int # Gnu extension if in C library +O_DIRECT: int # Gnu extension if in C library +O_DIRECTORY: int # Gnu extension if in C library +O_NOFOLLOW: int # Gnu extension if in C library +O_NOATIME: int # Gnu extension if in C library +if sys.version_info >= (3, 4): + O_PATH: int # Gnu extension if in C library + O_TMPFILE: int # Gnu extension if in C library +O_LARGEFILE: int # Gnu extension if in C library + +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +linesep: str +devnull: str +name: str + +F_OK: int +R_OK: int +W_OK: int +X_OK: int + +class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]): + def copy(self) -> Dict[AnyStr, AnyStr]: ... + def __delitem__(self, key: AnyStr) -> None: ... + def __getitem__(self, key: AnyStr) -> AnyStr: ... + def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ... + def __iter__(self) -> Iterator[AnyStr]: ... + def __len__(self) -> int: ... + +environ: _Environ[str] +if sys.version_info >= (3, 2): + environb: _Environ[bytes] + +confstr_names: Dict[str, int] # Unix only +pathconf_names: Dict[str, int] # Unix only +sysconf_names: Dict[str, int] # Unix only + +EX_OK: int # Unix only +EX_USAGE: int # Unix only +EX_DATAERR: int # Unix only +EX_NOINPUT: int # Unix only +EX_NOUSER: int # Unix only +EX_NOHOST: int # Unix only +EX_UNAVAILABLE: int # Unix only +EX_SOFTWARE: int # Unix only +EX_OSERR: int # Unix only +EX_OSFILE: int # Unix only +EX_CANTCREAT: int # Unix only +EX_IOERR: int # Unix only +EX_TEMPFAIL: int # Unix only +EX_PROTOCOL: int # Unix only +EX_NOPERM: int # Unix only +EX_CONFIG: int # Unix only +EX_NOTFOUND: int # Unix only + +P_NOWAIT: int +P_NOWAITO: int +P_WAIT: int +if sys.platform == 'win32': + P_DETACH: int # Windows only + P_OVERLAY: int # Windows only + +# wait()/waitpid() options +WNOHANG: int # Unix only +WCONTINUED: int # some Unix systems +WUNTRACED: int # Unix only + +TMP_MAX: int # Undocumented, but used by tempfile + +# ----- os classes (structures) ----- +if sys.version_info >= (3, 6): + from builtins import _PathLike as PathLike # See comment in builtins + +_PathType = path._PathType +if sys.version_info >= (3, 3): + _FdOrPathType = Union[int, _PathType] +else: + _FdOrPathType = _PathType + +if sys.version_info >= (3, 6): + class DirEntry(PathLike[AnyStr]): + # This is what the scandir interator yields + # The constructor is hidden + + name: AnyStr + path: AnyStr + def inode(self) -> int: ... + def is_dir(self, follow_symlinks: bool = ...) -> bool: ... + def is_file(self, follow_symlinks: bool = ...) -> bool: ... + def is_symlink(self) -> bool: ... + def stat(self) -> stat_result: ... + + def __fspath__(self) -> AnyStr: ... +elif sys.version_info >= (3, 5): + class DirEntry(Generic[AnyStr]): + # This is what the scandir interator yields + # The constructor is hidden + + name: AnyStr + path: AnyStr + def inode(self) -> int: ... + def is_dir(self, follow_symlinks: bool = ...) -> bool: ... + def is_file(self, follow_symlinks: bool = ...) -> bool: ... + def is_symlink(self) -> bool: ... + def stat(self) -> stat_result: ... + + +class statvfs_result: # Unix only + f_bsize: int + f_frsize: int + f_blocks: int + f_bfree: int + f_bavail: int + f_files: int + f_ffree: int + f_favail: int + f_flag: int + f_namemax: int + +# ----- os function stubs ----- +if sys.version_info >= (3, 6): + def fsencode(filename: Union[str, bytes, PathLike]) -> bytes: ... +else: + def fsencode(filename: Union[str, bytes]) -> bytes: ... + +if sys.version_info >= (3, 6): + def fsdecode(filename: Union[str, bytes, PathLike]) -> str: ... +else: + def fsdecode(filename: Union[str, bytes]) -> str: ... + +if sys.version_info >= (3, 6): + @overload + def fspath(path: str) -> str: ... + @overload + def fspath(path: bytes) -> bytes: ... + @overload + def fspath(path: PathLike) -> Any: ... + +def get_exec_path(env: Optional[Mapping[str, str]] = ...) -> List[str]: ... +# NOTE: get_exec_path(): returns List[bytes] when env not None +def ctermid() -> str: ... # Unix only +def getegid() -> int: ... # Unix only +def geteuid() -> int: ... # Unix only +def getgid() -> int: ... # Unix only +if sys.version_info >= (3, 3): + def getgrouplist(user: str, gid: int) -> List[int]: ... # Unix only +def getgroups() -> List[int]: ... # Unix only, behaves differently on Mac +def initgroups(username: str, gid: int) -> None: ... # Unix only +def getlogin() -> str: ... +def getpgid(pid: int) -> int: ... # Unix only +def getpgrp() -> int: ... # Unix only +def getpid() -> int: ... +def getppid() -> int: ... +if sys.version_info >= (3, 3): + def getpriority(which: int, who: int) -> int: ... # Unix only + def setpriority(which: int, who: int, priority: int) -> None: ... # Unix only +def getresuid() -> Tuple[int, int, int]: ... # Unix only +def getresgid() -> Tuple[int, int, int]: ... # Unix only +def getuid() -> int: ... # Unix only +def setegid(egid: int) -> None: ... # Unix only +def seteuid(euid: int) -> None: ... # Unix only +def setgid(gid: int) -> None: ... # Unix only +def setgroups(groups: Sequence[int]) -> None: ... # Unix only +def setpgrp() -> None: ... # Unix only +def setpgid(pid: int, pgrp: int) -> None: ... # Unix only +def setregid(rgid: int, egid: int) -> None: ... # Unix only +def setresgid(rgid: int, egid: int, sgid: int) -> None: ... # Unix only +def setresuid(ruid: int, euid: int, suid: int) -> None: ... # Unix only +def setreuid(ruid: int, euid: int) -> None: ... # Unix only +def getsid(pid: int) -> int: ... # Unix only +def setsid() -> None: ... # Unix only +def setuid(uid: int) -> None: ... # Unix only +def strerror(code: int) -> str: ... +def umask(mask: int) -> int: ... +if sys.version_info >= (3, 3): + from posix import uname_result + def uname() -> uname_result: ... # Unix only +else: + def uname() -> Tuple[str, str, str, str, str]: ... # Unix only + +@overload +def getenv(key: Text) -> Optional[str]: ... +@overload +def getenv(key: Text, default: _T) -> Union[str, _T]: ... +def getenvb(key: bytes, default: bytes = ...) -> bytes: ... +def putenv(key: Union[bytes, Text], value: Union[bytes, Text]) -> None: ... +def unsetenv(key: Union[bytes, Text]) -> None: ... + +# Return IO or TextIO +def fdopen(fd: int, mode: str = ..., buffering: int = ..., encoding: str = ..., + errors: str = ..., newline: str = ..., closefd: bool = ...) -> Any: ... +def close(fd: int) -> None: ... +def closerange(fd_low: int, fd_high: int) -> None: ... +def device_encoding(fd: int) -> Optional[str]: ... +def dup(fd: int) -> int: ... +def dup2(fd: int, fd2: int) -> None: ... +def fchmod(fd: int, mode: int) -> None: ... # Unix only +def fchown(fd: int, uid: int, gid: int) -> None: ... # Unix only +def fdatasync(fd: int) -> None: ... # Unix only, not Mac +def fpathconf(fd: int, name: Union[str, int]) -> int: ... # Unix only +def fstat(fd: int) -> stat_result: ... +def fstatvfs(fd: int) -> statvfs_result: ... # Unix only +def fsync(fd: int) -> None: ... +def ftruncate(fd: int, length: int) -> None: ... # Unix only +if sys.version_info >= (3, 5): + def get_blocking(fd: int) -> bool: ... # Unix only + def set_blocking(fd: int, blocking: bool) -> None: ... # Unix only +def isatty(fd: int) -> bool: ... # Unix only +if sys.version_info >= (3, 3): + def lockf(__fd: int, __cmd: int, __length: int) -> None: ... # Unix only +def lseek(fd: int, pos: int, how: int) -> int: ... +if sys.version_info >= (3, 3): + def open(file: _PathType, flags: int, mode: int = ..., *, dir_fd: Optional[int] = ...) -> int: ... +else: + def open(file: _PathType, flags: int, mode: int = ...) -> int: ... +def openpty() -> Tuple[int, int]: ... # some flavors of Unix +def pipe() -> Tuple[int, int]: ... +if sys.version_info >= (3, 3): + def pipe2(flags: int) -> Tuple[int, int]: ... # some flavors of Unix + def posix_fallocate(fd: int, offset: int, length: int) -> None: ... # Unix only + def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ... # Unix only + def pread(fd: int, buffersize: int, offset: int) -> bytes: ... # Unix only + def pwrite(fd: int, string: bytes, offset: int) -> int: ... # Unix only +def read(fd: int, n: int) -> bytes: ... +if sys.version_info >= (3, 3): + @overload + def sendfile(__out_fd: int, __in_fd: int, offset: Optional[int], count: int) -> int: ... # Unix only + @overload + def sendfile(__out_fd: int, __in_fd: int, offset: int, count: int, + headers: Sequence[bytes] = ..., trailers: Sequence[bytes] = ..., flags: int = ...) -> int: ... # FreeBSD and Mac OS X only + def readv(fd: int, buffers: Sequence[bytearray]) -> int: ... # Unix only + def writev(fd: int, buffers: Sequence[bytes]) -> int: ... # Unix only + + terminal_size = NamedTuple('terminal_size', [('columns', int), ('lines', int)]) + def get_terminal_size(fd: int = ...) -> terminal_size: ... + +if sys.version_info >= (3, 4): + def get_inheritable(fd: int) -> bool: ... + def set_inheritable(fd: int, inheritable: bool) -> None: ... + +def tcgetpgrp(fd: int) -> int: ... # Unix only +def tcsetpgrp(fd: int, pg: int) -> None: ... # Unix only +def ttyname(fd: int) -> str: ... # Unix only +def write(fd: int, string: bytes) -> int: ... +if sys.version_info >= (3, 3): + def access(path: _FdOrPathType, mode: int, *, dir_fd: Optional[int] = ..., + effective_ids: bool = ..., follow_symlinks: bool = ...) -> bool: ... +else: + def access(path: _PathType, mode: int) -> bool: ... +def chdir(path: _FdOrPathType) -> None: ... +def fchdir(fd: int) -> None: ... +def getcwd() -> str: ... +def getcwdb() -> bytes: ... +if sys.version_info >= (3, 3): + def chflags(path: _PathType, flags: int, follow_symlinks: bool = ...) -> None: ... # some flavors of Unix + def chmod(path: _FdOrPathType, mode: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... + def chown(path: _FdOrPathType, uid: int, gid: int, *, dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... # Unix only +else: + def chflags(path: _PathType, flags: int) -> None: ... # Some flavors of Unix + def chmod(path: _PathType, mode: int) -> None: ... + def chown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only +def chroot(path: _PathType) -> None: ... # Unix only +def lchflags(path: _PathType, flags: int) -> None: ... # Unix only +def lchmod(path: _PathType, mode: int) -> None: ... # Unix only +def lchown(path: _PathType, uid: int, gid: int) -> None: ... # Unix only +if sys.version_info >= (3, 3): + def link(src: _PathType, link_name: _PathType, *, src_dir_fd: Optional[int] = ..., + dst_dir_fd: Optional[int] = ..., follow_symlinks: bool = ...) -> None: ... +else: + def link(src: _PathType, link_name: _PathType) -> None: ... + +if sys.version_info >= (3, 6): + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + @overload + def listdir(path: int) -> List[str]: ... + @overload + def listdir(path: PathLike[str]) -> List[str]: ... +elif sys.version_info >= (3, 3): + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + @overload + def listdir(path: int) -> List[str]: ... +else: + @overload + def listdir(path: Optional[str] = ...) -> List[str]: ... + @overload + def listdir(path: bytes) -> List[bytes]: ... + +if sys.version_info >= (3, 3): + def lstat(path: _PathType, *, dir_fd: Optional[int] = ...) -> stat_result: ... + def mkdir(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... + def mkfifo(path: _PathType, mode: int = ..., *, dir_fd: Optional[int] = ...) -> None: ... # Unix only +else: + def lstat(path: _PathType) -> stat_result: ... + def mkdir(path: _PathType, mode: int = ...) -> None: ... + def mkfifo(path: _PathType, mode: int = ...) -> None: ... # Unix only +if sys.version_info >= (3, 4): + def makedirs(name: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ... +else: + def makedirs(path: _PathType, mode: int = ..., exist_ok: bool = ...) -> None: ... +if sys.version_info >= (3, 4): + def mknod(path: _PathType, mode: int = ..., device: int = ..., + *, dir_fd: Optional[int] = ...) -> None: ... +elif sys.version_info >= (3, 3): + def mknod(filename: _PathType, mode: int = ..., device: int = ..., + *, dir_fd: Optional[int] = ...) -> None: ... +else: + def mknod(filename: _PathType, mode: int = ..., device: int = ...) -> None: ... +def major(device: int) -> int: ... +def minor(device: int) -> int: ... +def makedev(major: int, minor: int) -> int: ... +def pathconf(path: _FdOrPathType, name: Union[str, int]) -> int: ... # Unix only +if sys.version_info >= (3, 6): + def readlink(path: Union[AnyStr, PathLike[AnyStr]], *, dir_fd: Optional[int] = ...) -> AnyStr: ... +elif sys.version_info >= (3, 3): + def readlink(path: AnyStr, *, dir_fd: Optional[int] = ...) -> AnyStr: ... +else: + def readlink(path: AnyStr) -> AnyStr: ... +if sys.version_info >= (3, 3): + def remove(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... +else: + def remove(path: _PathType) -> None: ... +if sys.version_info >= (3, 4): + def removedirs(name: _PathType) -> None: ... +else: + def removedirs(path: _PathType) -> None: ... +if sys.version_info >= (3, 3): + def rename(src: _PathType, dst: _PathType, *, + src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... +else: + def rename(src: _PathType, dst: _PathType) -> None: ... +def renames(old: _PathType, new: _PathType) -> None: ... +if sys.version_info >= (3, 3): + def replace(src: _PathType, dst: _PathType, *, + src_dir_fd: Optional[int] = ..., dst_dir_fd: Optional[int] = ...) -> None: ... + def rmdir(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... +else: + def rmdir(path: _PathType) -> None: ... +if sys.version_info >= (3, 7): + class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]): + def __next__(self) -> DirEntry[AnyStr]: ... + def close(self) -> None: ... + @overload + def scandir() -> _ScandirIterator[str]: ... + @overload + def scandir(path: int) -> _ScandirIterator[str]: ... + @overload + def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ... +elif sys.version_info >= (3, 6): + class _ScandirIterator(Iterator[DirEntry[AnyStr]], ContextManager[_ScandirIterator[AnyStr]]): + def __next__(self) -> DirEntry[AnyStr]: ... + def close(self) -> None: ... + @overload + def scandir() -> _ScandirIterator[str]: ... + @overload + def scandir(path: Union[AnyStr, PathLike[AnyStr]]) -> _ScandirIterator[AnyStr]: ... +elif sys.version_info >= (3, 5): + @overload + def scandir() -> Iterator[DirEntry[str]]: ... + @overload + def scandir(path: AnyStr) -> Iterator[DirEntry[AnyStr]]: ... +if sys.version_info >= (3, 3): + def stat(path: _FdOrPathType, *, dir_fd: Optional[int] = ..., + follow_symlinks: bool = ...) -> stat_result: ... +else: + def stat(path: _PathType) -> stat_result: ... +if sys.version_info < (3, 7): + @overload + def stat_float_times() -> bool: ... + @overload + def stat_float_times(__newvalue: bool) -> None: ... +def statvfs(path: _FdOrPathType) -> statvfs_result: ... # Unix only +if sys.version_info >= (3, 3): + def symlink(source: _PathType, link_name: _PathType, + target_is_directory: bool = ..., *, dir_fd: Optional[int] = ...) -> None: ... + def sync() -> None: ... # Unix only + def truncate(path: _FdOrPathType, length: int) -> None: ... # Unix only up to version 3.4 + def unlink(path: _PathType, *, dir_fd: Optional[int] = ...) -> None: ... + def utime(path: _FdOrPathType, times: Optional[Union[Tuple[int, int], Tuple[float, float]]] = ..., *, + ns: Tuple[int, int] = ..., dir_fd: Optional[int] = ..., + follow_symlinks: bool = ...) -> None: ... +else: + def symlink(source: _PathType, link_name: _PathType, + target_is_directory: bool = ...) -> None: + ... # final argument in Windows only + def unlink(path: _PathType) -> None: ... + def utime(path: _PathType, times: Optional[Tuple[float, float]]) -> None: ... + +if sys.version_info >= (3, 6): + def walk(top: Union[AnyStr, PathLike[AnyStr]], topdown: bool = ..., + onerror: Optional[Callable[[OSError], Any]] = ..., + followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[AnyStr]]]: ... +else: + def walk(top: AnyStr, topdown: bool = ..., onerror: Optional[Callable[[OSError], Any]] = ..., + followlinks: bool = ...) -> Iterator[Tuple[AnyStr, List[AnyStr], + List[AnyStr]]]: ... +if sys.version_info >= (3, 3): + if sys.version_info >= (3, 7): + @overload + def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ..., + onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... # Unix only + @overload + def fwalk(top: bytes, topdown: bool = ..., + onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + dir_fd: Optional[int] = ...) -> Iterator[Tuple[bytes, List[bytes], List[bytes], int]]: ... # Unix only + elif sys.version_info >= (3, 6): + def fwalk(top: Union[str, PathLike[str]] = ..., topdown: bool = ..., + onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... # Unix only + else: + def fwalk(top: str = ..., topdown: bool = ..., + onerror: Optional[Callable] = ..., *, follow_symlinks: bool = ..., + dir_fd: Optional[int] = ...) -> Iterator[Tuple[str, List[str], List[str], int]]: ... # Unix only + def getxattr(path: _FdOrPathType, attribute: _PathType, *, follow_symlinks: bool = ...) -> bytes: ... # Linux only + def listxattr(path: _FdOrPathType, *, follow_symlinks: bool = ...) -> List[str]: ... # Linux only + def removexattr(path: _FdOrPathType, attribute: _PathType, *, follow_symlinks: bool = ...) -> None: ... # Linux only + def setxattr(path: _FdOrPathType, attribute: _PathType, value: bytes, flags: int = ..., *, + follow_symlinks: bool = ...) -> None: ... # Linux only + +def abort() -> NoReturn: ... +# These are defined as execl(file, *args) but the first *arg is mandatory. +def execl(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ... +def execlp(file: _PathType, __arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> NoReturn: ... + +# These are: execle(file, *args, env) but env is pulled from the last element of the args. +def execle(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ... +def execlpe(file: _PathType, __arg0: Union[bytes, Text], *args: Any) -> NoReturn: ... + +# The docs say `args: tuple or list of strings` +# The implementation enforces tuple or list so we can't use Sequence. +_ExecVArgs = Union[Tuple[Union[bytes, Text], ...], List[bytes], List[Text], List[Union[bytes, Text]]] +def execv(path: _PathType, args: _ExecVArgs) -> NoReturn: ... +def execve(path: _FdOrPathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ... +def execvp(file: _PathType, args: _ExecVArgs) -> NoReturn: ... +def execvpe(file: _PathType, args: _ExecVArgs, env: Mapping[str, str]) -> NoReturn: ... + +def _exit(n: int) -> NoReturn: ... +def fork() -> int: ... # Unix only +def forkpty() -> Tuple[int, int]: ... # some flavors of Unix +def kill(pid: int, sig: int) -> None: ... +def killpg(pgid: int, sig: int) -> None: ... # Unix only +def nice(increment: int) -> int: ... # Unix only +def plock(op: int) -> None: ... # Unix only ???op is int? + +if sys.version_info >= (3, 0): + class _wrap_close(_TextIOWrapper): + def close(self) -> Optional[int]: ... # type: ignore + def popen(command: str, mode: str = ..., buffering: int = ...) -> _wrap_close: ... +else: + class _wrap_close(IO[Text]): + def close(self) -> Optional[int]: ... # type: ignore + def popen(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> _wrap_close: ... + def popen2(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> Tuple[IO[Text], IO[Text]]: ... + def popen3(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> Tuple[IO[Text], IO[Text], IO[Text]]: ... + def popen4(__cmd: Text, __mode: Text = ..., __bufsize: int = ...) -> Tuple[IO[Text], IO[Text]]: ... + +def spawnl(mode: int, path: _PathType, arg0: Union[bytes, Text], *args: Union[bytes, Text]) -> int: ... +def spawnle(mode: int, path: _PathType, arg0: Union[bytes, Text], + *args: Any) -> int: ... # Imprecise sig +def spawnlp(mode: int, file: _PathType, arg0: Union[bytes, Text], + *args: Union[bytes, Text]) -> int: ... # Unix only TODO +def spawnlpe(mode: int, file: _PathType, arg0: Union[bytes, Text], *args: Any) -> int: + ... # Imprecise signature; Unix only TODO +def spawnv(mode: int, path: _PathType, args: List[Union[bytes, Text]]) -> int: ... +def spawnve(mode: int, path: _PathType, args: List[Union[bytes, Text]], + env: Mapping[str, str]) -> int: ... +def spawnvp(mode: int, file: _PathType, args: List[Union[bytes, Text]]) -> int: ... # Unix only +def spawnvpe(mode: int, file: _PathType, args: List[Union[bytes, Text]], + env: Mapping[str, str]) -> int: + ... # Unix only +def startfile(path: _PathType, operation: Optional[str] = ...) -> None: ... # Windows only +def system(command: _PathType) -> int: ... +if sys.version_info >= (3, 3): + from posix import times_result + def times() -> times_result: ... +else: + def times() -> Tuple[float, float, float, float, float]: ... +def wait() -> Tuple[int, int]: ... # Unix only +if sys.version_info >= (3, 3): + from posix import waitid_result + def waitid(idtype: int, ident: int, options: int) -> waitid_result: ... # Unix only +def waitpid(pid: int, options: int) -> Tuple[int, int]: ... +def wait3(options: int) -> Tuple[int, int, Any]: ... # Unix only +def wait4(pid: int, options: int) -> Tuple[int, int, Any]: ... # Unix only +def WCOREDUMP(status: int) -> bool: ... # Unix only +def WIFCONTINUED(status: int) -> bool: ... # Unix only +def WIFSTOPPED(status: int) -> bool: ... # Unix only +def WIFSIGNALED(status: int) -> bool: ... # Unix only +def WIFEXITED(status: int) -> bool: ... # Unix only +def WEXITSTATUS(status: int) -> int: ... # Unix only +def WSTOPSIG(status: int) -> int: ... # Unix only +def WTERMSIG(status: int) -> int: ... # Unix only + +if sys.version_info >= (3, 3): + from posix import sched_param + def sched_get_priority_min(policy: int) -> int: ... # some flavors of Unix + def sched_get_priority_max(policy: int) -> int: ... # some flavors of Unix + def sched_setscheduler(pid: int, policy: int, param: sched_param) -> None: ... # some flavors of Unix + def sched_getscheduler(pid: int) -> int: ... # some flavors of Unix + def sched_setparam(pid: int, param: sched_param) -> None: ... # some flavors of Unix + def sched_getparam(pid: int) -> sched_param: ... # some flavors of Unix + def sched_rr_get_interval(pid: int) -> float: ... # some flavors of Unix + def sched_yield() -> None: ... # some flavors of Unix + def sched_setaffinity(pid: int, mask: Iterable[int]) -> None: ... # some flavors of Unix + def sched_getaffinity(pid: int) -> Set[int]: ... # some flavors of Unix + +def confstr(name: Union[str, int]) -> Optional[str]: ... # Unix only +if sys.version_info >= (3, 4): + def cpu_count() -> Optional[int]: ... +def getloadavg() -> Tuple[float, float, float]: ... # Unix only +def sysconf(name: Union[str, int]) -> int: ... # Unix only +if sys.version_info >= (3, 6): + def getrandom(size: int, flags: int = ...) -> bytes: ... + def urandom(size: int) -> bytes: ... +else: + def urandom(n: int) -> bytes: ... + +if sys.version_info >= (3, 7): + def register_at_fork(func: Callable[..., object], when: str) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/os/path.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/os/path.pyi new file mode 100644 index 000000000..56106428b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/os/path.pyi @@ -0,0 +1,173 @@ +# NB: path.pyi and stdlib/2 and stdlib/3 must remain consistent! +# Stubs for os.path +# Ron Murawski + +from posix import stat_result +import sys +from typing import ( + overload, List, Any, AnyStr, Sequence, Tuple, BinaryIO, TextIO, + TypeVar, Union, Text, Callable, Optional +) + +_T = TypeVar('_T') + +if sys.version_info >= (3, 6): + from builtins import _PathLike + _PathType = Union[bytes, Text, _PathLike] + _StrPath = Union[Text, _PathLike[Text]] + _BytesPath = Union[bytes, _PathLike[bytes]] +else: + _PathType = Union[bytes, Text] + _StrPath = Text + _BytesPath = bytes + +# ----- os.path variables ----- +supports_unicode_filenames: bool +# aliases (also in os) +curdir: str +pardir: str +sep: str +altsep: str +extsep: str +pathsep: str +defpath: str +devnull: str + +# ----- os.path function stubs ----- +if sys.version_info >= (3, 6): + # Overloads are necessary to work around python/mypy#3644. + @overload + def abspath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def abspath(path: AnyStr) -> AnyStr: ... + @overload + def basename(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def basename(path: AnyStr) -> AnyStr: ... + @overload + def dirname(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def dirname(path: AnyStr) -> AnyStr: ... + @overload + def expanduser(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expanduser(path: AnyStr) -> AnyStr: ... + @overload + def expandvars(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def expandvars(path: AnyStr) -> AnyStr: ... + @overload + def normcase(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normcase(path: AnyStr) -> AnyStr: ... + @overload + def normpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + @overload + def realpath(path: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(path: AnyStr) -> AnyStr: ... + else: + @overload + def realpath(filename: _PathLike[AnyStr]) -> AnyStr: ... + @overload + def realpath(filename: AnyStr) -> AnyStr: ... + +else: + def abspath(path: AnyStr) -> AnyStr: ... + def basename(path: AnyStr) -> AnyStr: ... + def dirname(path: AnyStr) -> AnyStr: ... + def expanduser(path: AnyStr) -> AnyStr: ... + def expandvars(path: AnyStr) -> AnyStr: ... + def normcase(path: AnyStr) -> AnyStr: ... + def normpath(path: AnyStr) -> AnyStr: ... + if sys.platform == 'win32': + def realpath(path: AnyStr) -> AnyStr: ... + else: + def realpath(filename: AnyStr) -> AnyStr: ... + +if sys.version_info >= (3, 6): + # In reality it returns str for sequences of _StrPath and bytes for sequences + # of _BytesPath, but mypy does not accept such a signature. + def commonpath(paths: Sequence[_PathType]) -> Any: ... +elif sys.version_info >= (3, 5): + def commonpath(paths: Sequence[AnyStr]) -> AnyStr: ... + +# NOTE: Empty lists results in '' (str) regardless of contained type. +# Also, in Python 2 mixed sequences of Text and bytes results in either Text or bytes +# So, fall back to Any +def commonprefix(list: Sequence[_PathType]) -> Any: ... + +def exists(path: _PathType) -> bool: ... +def lexists(path: _PathType) -> bool: ... + +# These return float if os.stat_float_times() == True, +# but int is a subclass of float. +def getatime(path: _PathType) -> float: ... +def getmtime(path: _PathType) -> float: ... +def getctime(path: _PathType) -> float: ... + +def getsize(path: _PathType) -> int: ... +def isabs(path: _PathType) -> bool: ... +def isfile(path: _PathType) -> bool: ... +def isdir(path: _PathType) -> bool: ... +def islink(path: _PathType) -> bool: ... +def ismount(path: _PathType) -> bool: ... + +if sys.version_info < (3, 0): + # Make sure signatures are disjunct, and allow combinations of bytes and unicode. + # (Since Python 2 allows that, too) + # Note that e.g. os.path.join("a", "b", "c", "d", u"e") will still result in + # a type error. + @overload + def join(__p1: bytes, *p: bytes) -> bytes: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: bytes, __p4: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: bytes, __p3: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: bytes, __p2: Text, *p: _PathType) -> Text: ... + @overload + def join(__p1: Text, *p: _PathType) -> Text: ... +elif sys.version_info >= (3, 6): + # Mypy complains that the signatures overlap (same for relpath below), but things seem to behave correctly anyway. + @overload + def join(path: _StrPath, *paths: _StrPath) -> Text: ... # type: ignore + @overload + def join(path: _BytesPath, *paths: _BytesPath) -> bytes: ... +else: + def join(path: AnyStr, *paths: AnyStr) -> AnyStr: ... + +@overload +def relpath(path: _BytesPath, start: Optional[_BytesPath] = ...) -> bytes: ... # type: ignore +@overload +def relpath(path: _StrPath, start: Optional[_StrPath] = ...) -> Text: ... + +def samefile(path1: _PathType, path2: _PathType) -> bool: ... +def sameopenfile(fp1: int, fp2: int) -> bool: ... +def samestat(stat1: stat_result, stat2: stat_result) -> bool: ... + +if sys.version_info >= (3, 6): + @overload + def split(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: _PathLike[AnyStr]) -> Tuple[AnyStr, AnyStr]: ... + @overload + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... +else: + def split(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitdrive(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + def splitext(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... + +def splitunc(path: AnyStr) -> Tuple[AnyStr, AnyStr]: ... # Windows only, deprecated + +if sys.version_info < (3,): + def walk(path: AnyStr, visit: Callable[[_T, AnyStr, List[AnyStr]], Any], arg: _T) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/pipes.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/pipes.pyi new file mode 100644 index 000000000..00fc994a6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/pipes.pyi @@ -0,0 +1,19 @@ +# Stubs for pipes + +# Based on http://docs.python.org/3.5/library/pipes.html + +import os + +class Template: + def __init__(self) -> None: ... + def reset(self) -> None: ... + def clone(self) -> 'Template': ... + def debug(self, flag: bool) -> None: ... + def append(self, cmd: str, kind: str) -> None: ... + def prepend(self, cmd: str, kind: str) -> None: ... + def open(self, file: str, rw: str) -> os._wrap_close: ... + def copy(self, file: str, rw: str) -> os._wrap_close: ... + +# Not documented, but widely used. +# Documented as shlex.quote since 3.3. +def quote(s: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/platform.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/platform.pyi new file mode 100644 index 000000000..728e259fe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/platform.pyi @@ -0,0 +1,34 @@ +# Stubs for platform (Python 3.5) + +from os import devnull as DEV_NULL +from os import popen +from typing import Tuple, NamedTuple + +def libc_ver(executable: str = ..., lib: str = ..., version: str = ..., chunksize: int = ...) -> Tuple[str, str]: ... +def linux_distribution(distname: str = ..., version: str = ..., id: str = ..., supported_dists: Tuple[str, ...] = ..., full_distribution_name: bool = ...) -> Tuple[str, str, str]: ... +def dist(distname: str = ..., version: str = ..., id: str = ..., supported_dists: Tuple[str, ...] = ...) -> Tuple[str, str, str]: ... +def win32_ver(release: str = ..., version: str = ..., csd: str = ..., ptype: str = ...) -> Tuple[str, str, str, str]: ... +def mac_ver(release: str = ..., versioninfo: Tuple[str, str, str] = ..., machine: str = ...) -> Tuple[str, Tuple[str, str, str], str]: ... +def java_ver(release: str = ..., vendor: str = ..., vminfo: Tuple[str, str, str] = ..., osinfo: Tuple[str, str, str] = ...) -> Tuple[str, str, Tuple[str, str, str], Tuple[str, str, str]]: ... +def system_alias(system: str, release: str, version: str) -> Tuple[str, str, str]: ... +def architecture(executable: str = ..., bits: str = ..., linkage: str = ...) -> Tuple[str, str]: ... + +uname_result = NamedTuple('uname_result', [('system', str), ('node', str), ('release', str), ('version', str), ('machine', str), ('processor', str)]) + +def uname() -> uname_result: ... +def system() -> str: ... +def node() -> str: ... +def release() -> str: ... +def version() -> str: ... +def machine() -> str: ... +def processor() -> str: ... + +def python_implementation() -> str: ... +def python_version() -> str: ... +def python_version_tuple() -> Tuple[str, str, str]: ... +def python_branch() -> str: ... +def python_revision() -> str: ... +def python_build() -> Tuple[str, str]: ... +def python_compiler() -> str: ... + +def platform(aliased: bool = ..., terse: bool = ...) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/posix.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/posix.pyi new file mode 100644 index 000000000..19e29a8cf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/posix.pyi @@ -0,0 +1,69 @@ +# Stubs for posix + +# NOTE: These are incomplete! + +from typing import NamedTuple, Tuple + +class stat_result: + # For backward compatibility, the return value of stat() is also + # accessible as a tuple of at least 10 integers giving the most important + # (and portable) members of the stat structure, in the order st_mode, + # st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, + # st_ctime. More items may be added at the end by some implementations. + + st_mode: int # protection bits, + st_ino: int # inode number, + st_dev: int # device, + st_nlink: int # number of hard links, + st_uid: int # user id of owner, + st_gid: int # group id of owner, + st_size: int # size of file, in bytes, + st_atime: float # time of most recent access, + st_mtime: float # time of most recent content modification, + st_ctime: float # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) + st_atime_ns: int # time of most recent access, in nanoseconds + st_mtime_ns: int # time of most recent content modification in nanoseconds + st_ctime_ns: int # platform dependent (time of most recent metadata change on Unix, or the time of creation on Windows) in nanoseconds + + # not documented + def __init__(self, tuple: Tuple[int, ...]) -> None: ... + + # On some Unix systems (such as Linux), the following attributes may also + # be available: + st_blocks: int # number of blocks allocated for file + st_blksize: int # filesystem blocksize + st_rdev: int # type of device if an inode device + st_flags: int # user defined flags for file + + # On other Unix systems (such as FreeBSD), the following attributes may be + # available (but may be only filled out if root tries to use them): + st_gen: int # file generation number + st_birthtime: int # time of file creation + + # On Mac OS systems, the following attributes may also be available: + st_rsize: int + st_creator: int + st_type: int + +uname_result = NamedTuple('uname_result', [('sysname', str), ('nodename', str), + ('release', str), ('version', str), ('machine', str)]) + +times_result = NamedTuple('times_result', [ + ('user', float), + ('system', float), + ('children_user', float), + ('children_system', float), + ('elapsed', float), +]) + +waitid_result = NamedTuple('waitid_result', [ + ('si_pid', int), + ('si_uid', int), + ('si_signo', int), + ('si_status', int), + ('si_code', int), +]) + +sched_param = NamedTuple('sched_priority', [ + ('sched_priority', int), +]) diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/posixpath.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/posixpath.pyi new file mode 100644 index 000000000..20a0da8fd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/posixpath.pyi @@ -0,0 +1,48 @@ +# NB: posixpath.pyi, ntpath.pyi, and macpath.pyi must remain consistent! +# Stubs for os.path +# Ron Murawski + +# based on http://docs.python.org/3.2/library/os.path.html +import sys +from typing import Any, List, Tuple, IO + +# ----- os.path variables ----- +supports_unicode_filenames = False + +# ----- os.path function stubs ----- +def abspath(path: str) -> str: ... +def basename(path) -> str: ... +def commonprefix(list: List[str]) -> str: ... +def dirname(path: str) -> str: ... +def exists(path: str) -> bool: ... +def lexists(path: str) -> bool: ... +def expanduser(path: str) -> str: ... +def expandvars(path: str) -> str: ... +def getatime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getmtime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getctime(path: str) -> int: + ... # return float if os.stat_float_times() returns True +def getsize(path: str) -> int: ... +def isabs(path: str) -> bool: ... +def isfile(path: str) -> bool: ... +def isdir(path: str) -> bool: ... +def islink(path: str) -> bool: ... +def ismount(path: str) -> bool: ... +def join(path: str, *paths: str) -> str: ... +def normcase(path: str) -> str: ... +def normpath(path: str) -> str: ... +def realpath(path: str) -> str: ... +def relpath(path: str, start: str = ...) -> str: ... +def samefile(path1: str, path2: str) -> bool: ... + +def sameopenfile(fp1: IO[Any], fp2: IO[Any]) -> bool: ... + +# def samestat(stat1: stat_result, stat2: stat_result) -> bool: +# ... # Unix only +def split(path: str) -> Tuple[str, str]: ... +def splitdrive(path: str) -> Tuple[str, str]: ... +def splitext(path: str) -> Tuple[str, str]: ... +if sys.version_info < (3, 7) and sys.platform == 'win32': + def splitunc(path: str) -> Tuple[str, str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/queue.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/queue.pyi new file mode 100644 index 000000000..1eb7360fa --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/queue.pyi @@ -0,0 +1,30 @@ +# Stubs for queue + +# NOTE: These are incomplete! + +from typing import Any, TypeVar, Generic, Optional + +_T = TypeVar('_T') + +class Empty(Exception): ... +class Full(Exception): ... + +class Queue(Generic[_T]): + maxsize = ... # type: int + def __init__(self, maxsize: int = ...) -> None: ... + def _init(self, maxsize: int) -> None: ... + def empty(self) -> bool: ... + def full(self) -> bool: ... + def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... + def get_nowait(self) -> _T: ... + def _get(self) -> _T: ... + def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... + def put_nowait(self, item: _T) -> None: ... + def _put(self, item: _T) -> None: ... + def join(self) -> None: ... + def qsize(self) -> int: ... + def _qsize(self) -> int: ... + def task_done(self) -> None: ... + +class PriorityQueue(Queue[_T]): ... +class LifoQueue(Queue[_T]): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/random.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/random.pyi new file mode 100644 index 000000000..41107fc4f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/random.pyi @@ -0,0 +1,72 @@ +# Stubs for random +# Ron Murawski +# Updated by Jukka Lehtosalo + +# based on http://docs.python.org/3.2/library/random.html + +# ----- random classes ----- + +import _random +import sys +from typing import ( + Any, TypeVar, Sequence, List, Callable, AbstractSet, Union, Optional +) + +_T = TypeVar('_T') + +class Random(_random.Random): + def __init__(self, x: Any = ...) -> None: ... + def seed(self, a: Any = ..., version: int = ...) -> None: ... + def getstate(self) -> tuple: ... + def setstate(self, state: tuple) -> None: ... + def getrandbits(self, k: int) -> int: ... + def randrange(self, start: int, stop: Union[int, None] = ..., step: int = ...) -> int: ... + def randint(self, a: int, b: int) -> int: ... + def choice(self, seq: Sequence[_T]) -> _T: ... + if sys.version_info >= (3, 6): + def choices(self, population: Sequence[_T], weights: Optional[Sequence[float]] = ..., *, cum_weights: Optional[Sequence[float]] = ..., k: int = ...) -> List[_T]: ... + def shuffle(self, x: List[Any], random: Union[Callable[[], float], None] = ...) -> None: ... + def sample(self, population: Union[Sequence[_T], AbstractSet[_T]], k: int) -> List[_T]: ... + def random(self) -> float: ... + def uniform(self, a: float, b: float) -> float: ... + def triangular(self, low: float = ..., high: float = ..., + mode: float = ...) -> float: ... + def betavariate(self, alpha: float, beta: float) -> float: ... + def expovariate(self, lambd: float) -> float: ... + def gammavariate(self, alpha: float, beta: float) -> float: ... + def gauss(self, mu: float, sigma: float) -> float: ... + def lognormvariate(self, mu: float, sigma: float) -> float: ... + def normalvariate(self, mu: float, sigma: float) -> float: ... + def vonmisesvariate(self, mu: float, kappa: float) -> float: ... + def paretovariate(self, alpha: float) -> float: ... + def weibullvariate(self, alpha: float, beta: float) -> float: ... + +# SystemRandom is not implemented for all OS's; good on Windows & Linux +class SystemRandom(Random): + ... + +# ----- random function stubs ----- +def seed(a: Any = ..., version: int = ...) -> None: ... +def getstate() -> object: ... +def setstate(state: object) -> None: ... +def getrandbits(k: int) -> int: ... +def randrange(start: int, stop: Union[None, int] = ..., step: int = ...) -> int: ... +def randint(a: int, b: int) -> int: ... +def choice(seq: Sequence[_T]) -> _T: ... +if sys.version_info >= (3, 6): + def choices(population: Sequence[_T], weights: Optional[Sequence[float]] = ..., *, cum_weights: Optional[Sequence[float]] = ..., k: int = ...) -> List[_T]: ... +def shuffle(x: List[Any], random: Union[Callable[[], float], None] = ...) -> None: ... +def sample(population: Union[Sequence[_T], AbstractSet[_T]], k: int) -> List[_T]: ... +def random() -> float: ... +def uniform(a: float, b: float) -> float: ... +def triangular(low: float = ..., high: float = ..., + mode: float = ...) -> float: ... +def betavariate(alpha: float, beta: float) -> float: ... +def expovariate(lambd: float) -> float: ... +def gammavariate(alpha: float, beta: float) -> float: ... +def gauss(mu: float, sigma: float) -> float: ... +def lognormvariate(mu: float, sigma: float) -> float: ... +def normalvariate(mu: float, sigma: float) -> float: ... +def vonmisesvariate(mu: float, kappa: float) -> float: ... +def paretovariate(alpha: float) -> float: ... +def weibullvariate(alpha: float, beta: float) -> float: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/re.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/re.pyi new file mode 100644 index 000000000..942f9bf6b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/re.pyi @@ -0,0 +1,151 @@ +# Stubs for re +# Ron Murawski +# 'bytes' support added by Jukka Lehtosalo + +# based on: http://docs.python.org/3.2/library/re.html +# and http://hg.python.org/cpython/file/618ea5612e83/Lib/re.py + +import sys +from typing import ( + List, Iterator, overload, Callable, Tuple, Sequence, Dict, + Generic, AnyStr, Match, Pattern, Any, Optional, Union +) + +# ----- re variables and constants ----- +if sys.version_info >= (3, 6): + import enum + class RegexFlag(enum.IntFlag): + A = 0 + ASCII = 0 + DEBUG = 0 + I = 0 + IGNORECASE = 0 + L = 0 + LOCALE = 0 + M = 0 + MULTILINE = 0 + S = 0 + DOTALL = 0 + X = 0 + VERBOSE = 0 + U = 0 + UNICODE = 0 + T = 0 + TEMPLATE = 0 + + A = RegexFlag.A + ASCII = RegexFlag.ASCII + DEBUG = RegexFlag.DEBUG + I = RegexFlag.I + IGNORECASE = RegexFlag.IGNORECASE + L = RegexFlag.L + LOCALE = RegexFlag.LOCALE + M = RegexFlag.M + MULTILINE = RegexFlag.MULTILINE + S = RegexFlag.S + DOTALL = RegexFlag.DOTALL + X = RegexFlag.X + VERBOSE = RegexFlag.VERBOSE + U = RegexFlag.U + UNICODE = RegexFlag.UNICODE + T = RegexFlag.T + TEMPLATE = RegexFlag.TEMPLATE + _FlagsType = Union[int, RegexFlag] +else: + A = 0 + ASCII = 0 + DEBUG = 0 + I = 0 + IGNORECASE = 0 + L = 0 + LOCALE = 0 + M = 0 + MULTILINE = 0 + S = 0 + DOTALL = 0 + X = 0 + VERBOSE = 0 + U = 0 + UNICODE = 0 + T = 0 + TEMPLATE = 0 + _FlagsType = int + +class error(Exception): ... + +@overload +def compile(pattern: AnyStr, flags: _FlagsType = ...) -> Pattern[AnyStr]: ... +@overload +def compile(pattern: Pattern[AnyStr], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... + +@overload +def search(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Optional[Match[AnyStr]]: ... +@overload +def search(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Optional[Match[AnyStr]]: ... + +@overload +def match(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Optional[Match[AnyStr]]: ... +@overload +def match(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Optional[Match[AnyStr]]: ... + +# New in Python 3.4 +@overload +def fullmatch(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> Optional[Match[AnyStr]]: ... +@overload +def fullmatch(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> Optional[Match[AnyStr]]: ... + +@overload +def split(pattern: AnyStr, string: AnyStr, + maxsplit: int = ..., flags: _FlagsType = ...) -> List[AnyStr]: ... +@overload +def split(pattern: Pattern[AnyStr], string: AnyStr, + maxsplit: int = ..., flags: _FlagsType = ...) -> List[AnyStr]: ... + +@overload +def findall(pattern: AnyStr, string: AnyStr, flags: _FlagsType = ...) -> List[Any]: ... +@overload +def findall(pattern: Pattern[AnyStr], string: AnyStr, flags: _FlagsType = ...) -> List[Any]: ... + +# Return an iterator yielding match objects over all non-overlapping matches +# for the RE pattern in string. The string is scanned left-to-right, and +# matches are returned in the order found. Empty matches are included in the +# result unless they touch the beginning of another match. +@overload +def finditer(pattern: AnyStr, string: AnyStr, + flags: _FlagsType = ...) -> Iterator[Match[AnyStr]]: ... +@overload +def finditer(pattern: Pattern[AnyStr], string: AnyStr, + flags: _FlagsType = ...) -> Iterator[Match[AnyStr]]: ... + +@overload +def sub(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int = ..., + flags: _FlagsType = ...) -> AnyStr: ... +@overload +def sub(pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., flags: _FlagsType = ...) -> AnyStr: ... +@overload +def sub(pattern: Pattern[AnyStr], repl: AnyStr, string: AnyStr, count: int = ..., + flags: _FlagsType = ...) -> AnyStr: ... +@overload +def sub(pattern: Pattern[AnyStr], repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., flags: _FlagsType = ...) -> AnyStr: ... + +@overload +def subn(pattern: AnyStr, repl: AnyStr, string: AnyStr, count: int = ..., + flags: _FlagsType = ...) -> Tuple[AnyStr, int]: ... +@overload +def subn(pattern: AnyStr, repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., + flags: _FlagsType = ...) -> Tuple[AnyStr, int]: ... +@overload +def subn(pattern: Pattern[AnyStr], repl: AnyStr, string: AnyStr, count: int = ..., + flags: _FlagsType = ...) -> Tuple[AnyStr, int]: ... +@overload +def subn(pattern: Pattern[AnyStr], repl: Callable[[Match[AnyStr]], AnyStr], + string: AnyStr, count: int = ..., + flags: _FlagsType = ...) -> Tuple[AnyStr, int]: ... + +def escape(string: AnyStr) -> AnyStr: ... + +def purge() -> None: ... +def template(pattern: Union[AnyStr, Pattern[AnyStr]], flags: _FlagsType = ...) -> Pattern[AnyStr]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/reprlib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/reprlib.pyi new file mode 100644 index 000000000..462251875 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/reprlib.pyi @@ -0,0 +1,37 @@ +# Stubs for reprlib (Python 3) + +from array import array +from typing import Any, Callable, Deque, Dict, FrozenSet, List, Set, Tuple + +_ReprFunc = Callable[[Any], str] + +def recursive_repr(fillvalue: str = ...) -> Callable[[_ReprFunc], _ReprFunc]: ... + +class Repr: + maxlevel: int + maxdict: int + maxlist: int + maxtuple: int + maxset: int + maxfrozenset: int + maxdeque: int + maxarray: int + maxlong: int + maxstring: int + maxother: int + def __init__(self) -> None: ... + def repr(self, x: Any) -> str: ... + def repr1(self, x: Any, level: int) -> str: ... + def repr_tuple(self, x: Tuple[Any, ...], level: int) -> str: ... + def repr_list(self, x: List[Any], level: int) -> str: ... + def repr_array(self, x: array, level: int) -> str: ... + def repr_set(self, x: Set[Any], level: int) -> str: ... + def repr_frozenset(self, x: FrozenSet[Any], level: int) -> str: ... + def repr_deque(self, x: Deque[Any], level: int) -> str: ... + def repr_dict(self, x: Dict[Any, Any], level: int) -> str: ... + def repr_str(self, x: str, level: int) -> str: ... + def repr_int(self, x: int, level: int) -> str: ... + def repr_instance(self, x: Any, level: int) -> str: ... + +aRepr: Repr +def repr(x: object) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/resource.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/resource.pyi new file mode 100644 index 000000000..b4c74d620 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/resource.pyi @@ -0,0 +1,42 @@ +# Stubs for resource + +# NOTE: These are incomplete! + +from typing import Tuple, Optional, NamedTuple + +RLIMIT_AS = ... # type: int +RLIMIT_CORE = ... # type: int +RLIMIT_CPU = ... # type: int +RLIMIT_DATA = ... # type: int +RLIMIT_FSIZE = ... # type: int +RLIMIT_MEMLOCK = ... # type: int +RLIMIT_MSGQUEUE = ... # type: int +RLIMIT_NICE = ... # type: int +RLIMIT_NOFILE = ... # type: int +RLIMIT_NPROC = ... # type: int +RLIMIT_OFILE = ... # type: int +RLIMIT_RSS = ... # type: int +RLIMIT_RTPRIO = ... # type: int +RLIMIT_RTTIME = ... # type: int +RLIMIT_SIGPENDING = ... # type: int +RLIMIT_STACK = ... # type: int +RLIM_INFINITY = ... # type: int +RUSAGE_CHILDREN = ... # type: int +RUSAGE_SELF = ... # type: int +RUSAGE_THREAD = ... # type: int + +_RUsage = NamedTuple('_RUsage', [('ru_utime', float), ('ru_stime', float), ('ru_maxrss', int), + ('ru_ixrss', int), ('ru_idrss', int), ('ru_isrss', int), + ('ru_minflt', int), ('ru_majflt', int), ('ru_nswap', int), + ('ru_inblock', int), ('ru_oublock', int), ('ru_msgsnd', int), + ('ru_msgrcv', int), ('ru_nsignals', int), ('ru_nvcsw', int), + ('ru_nivcsw', int)]) + +def getpagesize() -> int: ... +def getrlimit(resource: int) -> Tuple[int, int]: ... +def getrusage(who: int) -> _RUsage: ... +def prlimit(pid: int, resource: int, limits: Optional[Tuple[int, int]]) -> Tuple[int, int]: ... +def setrlimit(resource: int, limits: Tuple[int, int]) -> None: ... + +# NOTE: This is an alias of OSError in Python 3.3. +class error(Exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/runpy.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/runpy.pyi new file mode 100644 index 000000000..193a320eb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/runpy.pyi @@ -0,0 +1,17 @@ +from typing import Any + +class _TempModule: + mod_name = ... # type: Any + module = ... # type: Any + def __init__(self, mod_name): ... + def __enter__(self): ... + def __exit__(self, *args): ... + +class _ModifiedArgv0: + value = ... # type: Any + def __init__(self, value): ... + def __enter__(self): ... + def __exit__(self, *args): ... + +def run_module(mod_name, init_globals=None, run_name=None, alter_sys=False): ... +def run_path(path_name, init_globals=None, run_name=None): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/shelve.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/shelve.pyi new file mode 100644 index 000000000..4a339692c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/shelve.pyi @@ -0,0 +1,31 @@ +from typing import Any, Dict, Iterator, Optional, Tuple +import collections + + +class Shelf(collections.MutableMapping): + def __init__(self, dict: Dict[bytes, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + def __contains__(self, key: Any) -> bool: ... # key should be str, but it would conflict with superclass's type signature + def get(self, key: str, default: Any = ...) -> Any: ... + def __getitem__(self, key: str) -> Any: ... + def __setitem__(self, key: str, value: Any) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __enter__(self) -> Shelf: ... + def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... + def close(self) -> None: ... + def __del__(self) -> None: ... + def sync(self) -> None: ... + +class BsdDbShelf(Shelf): + def __init__(self, dict: Dict[bytes, Any], protocol: Optional[int] = ..., writeback: bool = ..., keyencoding: str = ...) -> None: ... + def set_location(self, key: Any) -> Tuple[str, Any]: ... + def next(self) -> Tuple[str, Any]: ... + def previous(self) -> Tuple[str, Any]: ... + def first(self) -> Tuple[str, Any]: ... + def last(self) -> Tuple[str, Any]: ... + +class DbfilenameShelf(Shelf): + def __init__(self, filename: str, flag: str = ..., protocol: Optional[int] = ..., writeback: bool = ...) -> None: ... + +def open(filename: str, flag: str = ..., protocol: Optional[int] = ..., writeback: bool = ...) -> DbfilenameShelf: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/shlex.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/shlex.pyi new file mode 100644 index 000000000..891d10698 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/shlex.pyi @@ -0,0 +1,50 @@ +# Stubs for shlex + +# Based on http://docs.python.org/3.2/library/shlex.html + +from typing import List, Tuple, Any, TextIO, Union, Optional, Iterable, TypeVar +import sys + +def split(s: str, comments: bool = ..., + posix: bool = ...) -> List[str]: ... + +# Added in 3.3, use (undocumented) pipes.quote in previous versions. +def quote(s: str) -> str: ... + +_SLT = TypeVar('_SLT', bound=shlex) + +class shlex(Iterable[str]): + commenters = ... # type: str + wordchars = ... # type: str + whitespace = ... # type: str + escape = ... # type: str + quotes = ... # type: str + escapedquotes = ... # type: str + whitespace_split = ... # type: bool + infile = ... # type: str + instream = ... # type: TextIO + source = ... # type: str + debug = 0 + lineno = 0 + token = ... # type: str + eof = ... # type: str + if sys.version_info >= (3, 6): + punctuation_chars = ... # type: str + + if sys.version_info >= (3, 6): + def __init__(self, instream: Union[str, TextIO] = ..., infile: Optional[str] = ..., + posix: bool = ..., punctuation_chars: Union[bool, str] = ...) -> None: ... + else: + def __init__(self, instream: Union[str, TextIO] = ..., infile: Optional[str] = ..., + posix: bool = ...) -> None: ... + def get_token(self) -> str: ... + def push_token(self, tok: str) -> None: ... + def read_token(self) -> str: ... + def sourcehook(self, filename: str) -> Tuple[str, TextIO]: ... + # TODO argument types + def push_source(self, newstream: Any, newfile: Any = ...) -> None: ... + def pop_source(self) -> None: ... + def error_leader(self, infile: str = ..., + lineno: int = ...) -> None: ... + def __iter__(self: _SLT) -> _SLT: ... + def __next__(self) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/signal.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/signal.pyi new file mode 100644 index 000000000..34a8cdd07 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/signal.pyi @@ -0,0 +1,187 @@ +"""Stub file for the 'signal' module.""" + +import sys +from enum import IntEnum +from typing import Any, Callable, List, Tuple, Dict, Generic, Union, Optional, Iterable, Set +from types import FrameType + +class ItimerError(IOError): ... + +ITIMER_PROF: int = ... +ITIMER_REAL: int = ... +ITIMER_VIRTUAL: int = ... + +NSIG: int = ... + +if sys.version_info >= (3, 5): + class Signals(IntEnum): + SIGABRT = ... + SIGALRM = ... + SIGBREAK = ... # Windows + SIGBUS = ... + SIGCHLD = ... + SIGCLD = ... + SIGCONT = ... + SIGEMT = ... + SIGFPE = ... + SIGHUP = ... + SIGILL = ... + SIGINFO = ... + SIGINT = ... + SIGIO = ... + SIGIOT = ... + SIGKILL = ... + SIGPIPE = ... + SIGPOLL = ... + SIGPROF = ... + SIGPWR = ... + SIGQUIT = ... + SIGRTMAX = ... + SIGRTMIN = ... + SIGSEGV = ... + SIGSTOP = ... + SIGSYS = ... + SIGTERM = ... + SIGTRAP = ... + SIGTSTP = ... + SIGTTIN = ... + SIGTTOU = ... + SIGURG = ... + SIGUSR1 = ... + SIGUSR2 = ... + SIGVTALRM = ... + SIGWINCH = ... + SIGXCPU = ... + SIGXFSZ = ... + + class Handlers(IntEnum): + SIG_DFL = ... + SIG_IGN = ... + + SIG_DFL = Handlers.SIG_DFL + SIG_IGN = Handlers.SIG_IGN + + class Sigmasks(IntEnum): + SIG_BLOCK = ... + SIG_UNBLOCK = ... + SIG_SETMASK = ... + + SIG_BLOCK = Sigmasks.SIG_BLOCK + SIG_UNBLOCK = Sigmasks.SIG_UNBLOCK + SIG_SETMASK = Sigmasks.SIG_SETMASK + + _SIG = Signals + _SIGNUM = Union[int, Signals] + _HANDLER = Union[Callable[[Signals, FrameType], None], int, Handlers, None] +else: + SIG_DFL: int = ... + SIG_IGN: int = ... + + SIG_BLOCK: int = ... + SIG_UNBLOCK: int = ... + SIG_SETMASK: int = ... + + _SIG = int + _SIGNUM = int + _HANDLER = Union[Callable[[int, FrameType], None], int, None] + +SIGABRT: _SIG = ... +SIGALRM: _SIG = ... +SIGBREAK: _SIG = ... # Windows +SIGBUS: _SIG = ... +SIGCHLD: _SIG = ... +SIGCLD: _SIG = ... +SIGCONT: _SIG = ... +SIGEMT: _SIG = ... +SIGFPE: _SIG = ... +SIGHUP: _SIG = ... +SIGILL: _SIG = ... +SIGINFO: _SIG = ... +SIGINT: _SIG = ... +SIGIO: _SIG = ... +SIGIOT: _SIG = ... +SIGKILL: _SIG = ... +SIGPIPE: _SIG = ... +SIGPOLL: _SIG = ... +SIGPROF: _SIG = ... +SIGPWR: _SIG = ... +SIGQUIT: _SIG = ... +SIGRTMAX: _SIG = ... +SIGRTMIN: _SIG = ... +SIGSEGV: _SIG = ... +SIGSTOP: _SIG = ... +SIGSYS: _SIG = ... +SIGTERM: _SIG = ... +SIGTRAP: _SIG = ... +SIGTSTP: _SIG = ... +SIGTTIN: _SIG = ... +SIGTTOU: _SIG = ... +SIGURG: _SIG = ... +SIGUSR1: _SIG = ... +SIGUSR2: _SIG = ... +SIGVTALRM: _SIG = ... +SIGWINCH: _SIG = ... +SIGXCPU: _SIG = ... +SIGXFSZ: _SIG = ... + +# Windows +CTRL_C_EVENT: _SIG = ... +CTRL_BREAK_EVENT: _SIG = ... + +class struct_siginfo(Tuple[int, int, int, int, int, int, int]): + def __init__(self, sequence: Iterable[int]) -> None: ... + @property + def si_signo(self) -> int: ... + @property + def si_code(self) -> int: ... + @property + def si_errno(self) -> int: ... + @property + def si_pid(self) -> int: ... + @property + def si_uid(self) -> int: ... + @property + def si_status(self) -> int: ... + @property + def si_band(self) -> int: ... + +def alarm(time: int) -> int: ... + +def default_int_handler(signum: int, frame: FrameType) -> None: + raise KeyboardInterrupt() + +def getitimer(which: int) -> Tuple[float, float]: ... + +def getsignal(signalnum: _SIGNUM) -> _HANDLER: + raise ValueError() + +def pause() -> None: ... + +def pthread_kill(thread_id: int, signum: int) -> None: + raise OSError() + +def pthread_sigmask(how: int, mask: Iterable[int]) -> Set[_SIGNUM]: + raise OSError() + +def set_wakeup_fd(fd: int) -> int: ... + +def setitimer(which: int, seconds: float, interval: float = ...) -> Tuple[float, float]: ... + +def siginterrupt(signalnum: int, flag: bool) -> None: + raise OSError() + +def signal(signalnum: _SIGNUM, handler: _HANDLER) -> _HANDLER: + raise OSError() + +def sigpending() -> Any: + raise OSError() + +def sigtimedwait(sigset: Iterable[int], timeout: float) -> Optional[struct_siginfo]: + raise OSError() + raise ValueError() + +def sigwait(sigset: Iterable[int]) -> _SIGNUM: + raise OSError() + +def sigwaitinfo(sigset: Iterable[int]) -> struct_siginfo: + raise OSError() diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/smtplib.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/smtplib.pyi new file mode 100644 index 000000000..2397448d4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/smtplib.pyi @@ -0,0 +1,109 @@ +from email.message import Message as _Message +from typing import ( + Any, AnyStr, Dict, Generic, List, Optional, Sequence, Tuple, Union, + Pattern) + +_Reply = Tuple[int, bytes] +_SendErrs = Dict[str, _Reply] + +SMTP_PORT: int +SMTP_SSL_PORT: int +CRLF: str +bCRLF: bytes + +OLDSTYLE_AUTH: Pattern[str] + +class SMTPException(OSError): ... +class SMTPServerDisconnected(SMTPException): ... + +class SMTPResponseException(SMTPException): + smtp_code = ... # type: int + smtp_error = ... # type: Union[bytes, str] + args = ... # type: Union[Tuple[int, Union[bytes, str]], Tuple[int, bytes, str]] + def __init__(self, code: int, msg: Union[bytes, str]) -> None: ... + +class SMTPSenderRefused(SMTPResponseException): + smtp_code = ... # type: int + smtp_error = ... # type: bytes + sender = ... # type: str + args = ... # type: Tuple[int, bytes, str] + def __init__(self, code: int, msg: bytes, sender: str) -> None: ... + +class SMTPRecipientsRefused(SMTPException): + recipients = ... # type: _SendErrs + args = ... # type: Tuple[_SendErrs] + def __init__(self, recipients: _SendErrs) -> None: ... + +class SMTPDataError(SMTPResponseException): ... +class SMTPConnectError(SMTPResponseException): ... +class SMTPHeloError(SMTPResponseException): ... +class SMTPAuthenticationError(SMTPResponseException): ... + +def quoteaddr(addrstring): ... +def quotedata(data): ... + +class SMTP: + debuglevel = ... # type: int + file = ... # type: Any + helo_resp = ... # type: Any + ehlo_msg = ... # type: Any + ehlo_resp = ... # type: Any + does_esmtp = ... # type: Any + default_port = ... # type: Any + timeout = ... # type: float + esmtp_features = ... # type: Any + source_address = ... # type: Any + local_hostname = ... # type: Any + def __init__(self, host: str = ..., port: int = ..., + local_hostname: Optional[str] = ..., timeout: float = ..., + source_address: Tuple[str, int] = ...) -> None: ... + def __enter__(self): ... + def __exit__(self, *args): ... + def set_debuglevel(self, debuglevel: int) -> None: ... + sock = ... # type: Any + def connect(self, host=..., port=..., source_address=...): ... + def send(self, s): ... + def putcmd(self, cmd, args=...): ... + def getreply(self) -> _Reply: ... + def docmd(self, cmd, args=...): ... + def helo(self, name=...): ... + def ehlo(self, name=...): ... + def has_extn(self, opt): ... + def help(self, args=...): ... + def rset(self) -> _Reply: ... + def noop(self) -> _Reply: ... + def mail(self, sender: str, options: Sequence[str] = ...) -> _Reply: ... + def rcpt(self, recip: str, options: Sequence[str] = ...) -> _Reply: ... + def data(self, msg): ... + def verify(self, address): ... + vrfy = ... # type: Any + def expn(self, address): ... + def ehlo_or_helo_if_needed(self): ... + def login(self, user, password): ... + def starttls(self, keyfile=..., certfile=..., context=...): ... + def sendmail(self, from_addr: str, to_addrs: Union[str, Sequence[str]], + msg: Union[bytes, str], mail_options: Sequence[str] = ..., + rcpt_options: List[str] = ...) -> _SendErrs: ... + def send_message(self, msg: _Message, from_addr: Optional[str] = ..., + to_addrs: Optional[Union[str, Sequence[str]]] = ..., + mail_options: List[str] = ..., + rcpt_options: Sequence[str] = ...) -> _SendErrs: ... + def close(self): ... + def quit(self) -> _Reply: ... + +class SMTP_SSL(SMTP): + default_port = ... # type: Any + keyfile = ... # type: Any + certfile = ... # type: Any + context = ... # type: Any + def __init__(self, host=..., port=..., local_hostname=..., keyfile=..., certfile=..., + timeout=..., source_address=..., context=...): ... + +class LMTP(SMTP): + ehlo_msg = ... # type: Any + def __init__(self, host: str = ..., port: int = ..., + local_hostname: Optional[str] = ..., + source_address: Optional[Tuple[str, int]] = ...) -> None: ... + sock = ... # type: Any + file = ... # type: Any + def connect(self, host=..., port=..., source_address=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/socketserver.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/socketserver.pyi new file mode 100644 index 000000000..3c4aec6cd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/socketserver.pyi @@ -0,0 +1,99 @@ +# NB: SocketServer.pyi and socketserver.pyi must remain consistent! +# Stubs for socketserver + +from typing import Any, BinaryIO, Optional, Tuple, Type +from socket import SocketType +import sys +import types + +class BaseServer: + address_family = ... # type: int + RequestHandlerClass = ... # type: type + server_address = ... # type: Tuple[str, int] + socket = ... # type: SocketType + allow_reuse_address = ... # type: bool + request_queue_size = ... # type: int + socket_type = ... # type: int + timeout = ... # type: Optional[float] + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type) -> None: ... + def fileno(self) -> int: ... + def handle_request(self) -> None: ... + def serve_forever(self, poll_interval: float = ...) -> None: ... + def shutdown(self) -> None: ... + def server_close(self) -> None: ... + def finish_request(self, request: bytes, + client_address: Tuple[str, int]) -> None: ... + def get_request(self) -> None: ... + def handle_error(self, request: bytes, + client_address: Tuple[str, int]) -> None: ... + def handle_timeout(self) -> None: ... + def process_request(self, request: bytes, + client_address: Tuple[str, int]) -> None: ... + def server_activate(self) -> None: ... + def server_bind(self) -> None: ... + def verify_request(self, request: bytes, + client_address: Tuple[str, int]) -> bool: ... + if sys.version_info >= (3, 6): + def __enter__(self) -> 'BaseServer': ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[types.TracebackType]) -> bool: ... + if sys.version_info >= (3, 3): + def service_actions(self) -> None: ... + +class TCPServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + +class UDPServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + +if sys.platform != 'win32': + class UnixStreamServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + + class UnixDatagramServer(BaseServer): + def __init__(self, server_address: Tuple[str, int], + RequestHandlerClass: type, + bind_and_activate: bool = ...) -> None: ... + +class ForkingMixIn: ... +class ThreadingMixIn: ... + +class ForkingTCPServer(ForkingMixIn, TCPServer): ... +class ForkingUDPServer(ForkingMixIn, UDPServer): ... +class ThreadingTCPServer(ThreadingMixIn, TCPServer): ... +class ThreadingUDPServer(ThreadingMixIn, UDPServer): ... +if sys.platform != 'win32': + class ThreadingUnixStreamServer(ThreadingMixIn, UnixStreamServer): ... + class ThreadingUnixDatagramServer(ThreadingMixIn, UnixDatagramServer): ... + + +class BaseRequestHandler: + # Those are technically of types, respectively: + # * Union[SocketType, Tuple[bytes, SocketType]] + # * Union[Tuple[str, int], str] + # But there are some concerns that having unions here would cause + # too much inconvenience to people using it (see + # https://github.com/python/typeshed/pull/384#issuecomment-234649696) + request = ... # type: Any + client_address = ... # type: Any + + server = ... # type: BaseServer + def setup(self) -> None: ... + def handle(self) -> None: ... + def finish(self) -> None: ... + +class StreamRequestHandler(BaseRequestHandler): + rfile = ... # type: BinaryIO + wfile = ... # type: BinaryIO + +class DatagramRequestHandler(BaseRequestHandler): + rfile = ... # type: BinaryIO + wfile = ... # type: BinaryIO diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/spwd.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/spwd.pyi new file mode 100644 index 000000000..0e55d7421 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/spwd.pyi @@ -0,0 +1,14 @@ +from typing import List, NamedTuple + +struct_spwd = NamedTuple("struct_spwd", [("sp_namp", str), + ("sp_pwdp", str), + ("sp_lstchg", int), + ("sp_min", int), + ("sp_max", int), + ("sp_warn", int), + ("sp_inact", int), + ("sp_expire", int), + ("sp_flag", int)]) + +def getspall() -> List[struct_spwd]: ... +def getspnam(name: str) -> struct_spwd: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sre_constants.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sre_constants.pyi new file mode 100644 index 000000000..10e393cc7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sre_constants.pyi @@ -0,0 +1,114 @@ +# Source: https://github.com/python/cpython/blob/master/Lib/sre_constants.py + +from typing import Any, Dict, List, Optional, Union + +MAGIC = ... # type: int + +class error(Exception): + msg = ... # type: str + pattern = ... # type: Optional[Union[str, bytes]] + pos = ... # type: Optional[int] + lineno = ... # type: int + colno = ... # type: int + def __init__(self, msg: str, pattern: Union[str, bytes] = ..., pos: int = ...) -> None: ... + +class _NamedIntConstant(int): + name = ... # type: Any + def __new__(cls, value: int, name: str): ... + +MAXREPEAT = ... # type: _NamedIntConstant +OPCODES = ... # type: List[_NamedIntConstant] +ATCODES = ... # type: List[_NamedIntConstant] +CHCODES = ... # type: List[_NamedIntConstant] +OP_IGNORE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant] +AT_MULTILINE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant] +AT_LOCALE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant] +AT_UNICODE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant] +CH_LOCALE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant] +CH_UNICODE = ... # type: Dict[_NamedIntConstant, _NamedIntConstant] +SRE_FLAG_TEMPLATE = ... # type: int +SRE_FLAG_IGNORECASE = ... # type: int +SRE_FLAG_LOCALE = ... # type: int +SRE_FLAG_MULTILINE = ... # type: int +SRE_FLAG_DOTALL = ... # type: int +SRE_FLAG_UNICODE = ... # type: int +SRE_FLAG_VERBOSE = ... # type: int +SRE_FLAG_DEBUG = ... # type: int +SRE_FLAG_ASCII = ... # type: int +SRE_INFO_PREFIX = ... # type: int +SRE_INFO_LITERAL = ... # type: int +SRE_INFO_CHARSET = ... # type: int + + +# Stubgen above; manually defined constants below (dynamic at runtime) + +# from OPCODES +FAILURE = ... # type: _NamedIntConstant +SUCCESS = ... # type: _NamedIntConstant +ANY = ... # type: _NamedIntConstant +ANY_ALL = ... # type: _NamedIntConstant +ASSERT = ... # type: _NamedIntConstant +ASSERT_NOT = ... # type: _NamedIntConstant +AT = ... # type: _NamedIntConstant +BRANCH = ... # type: _NamedIntConstant +CALL = ... # type: _NamedIntConstant +CATEGORY = ... # type: _NamedIntConstant +CHARSET = ... # type: _NamedIntConstant +BIGCHARSET = ... # type: _NamedIntConstant +GROUPREF = ... # type: _NamedIntConstant +GROUPREF_EXISTS = ... # type: _NamedIntConstant +GROUPREF_IGNORE = ... # type: _NamedIntConstant +IN = ... # type: _NamedIntConstant +IN_IGNORE = ... # type: _NamedIntConstant +INFO = ... # type: _NamedIntConstant +JUMP = ... # type: _NamedIntConstant +LITERAL = ... # type: _NamedIntConstant +LITERAL_IGNORE = ... # type: _NamedIntConstant +MARK = ... # type: _NamedIntConstant +MAX_UNTIL = ... # type: _NamedIntConstant +MIN_UNTIL = ... # type: _NamedIntConstant +NOT_LITERAL = ... # type: _NamedIntConstant +NOT_LITERAL_IGNORE = ... # type: _NamedIntConstant +NEGATE = ... # type: _NamedIntConstant +RANGE = ... # type: _NamedIntConstant +REPEAT = ... # type: _NamedIntConstant +REPEAT_ONE = ... # type: _NamedIntConstant +SUBPATTERN = ... # type: _NamedIntConstant +MIN_REPEAT_ONE = ... # type: _NamedIntConstant +RANGE_IGNORE = ... # type: _NamedIntConstant +MIN_REPEAT = ... # type: _NamedIntConstant +MAX_REPEAT = ... # type: _NamedIntConstant + +# from ATCODES +AT_BEGINNING = ... # type: _NamedIntConstant +AT_BEGINNING_LINE = ... # type: _NamedIntConstant +AT_BEGINNING_STRING = ... # type: _NamedIntConstant +AT_BOUNDARY = ... # type: _NamedIntConstant +AT_NON_BOUNDARY = ... # type: _NamedIntConstant +AT_END = ... # type: _NamedIntConstant +AT_END_LINE = ... # type: _NamedIntConstant +AT_END_STRING = ... # type: _NamedIntConstant +AT_LOC_BOUNDARY = ... # type: _NamedIntConstant +AT_LOC_NON_BOUNDARY = ... # type: _NamedIntConstant +AT_UNI_BOUNDARY = ... # type: _NamedIntConstant +AT_UNI_NON_BOUNDARY = ... # type: _NamedIntConstant + +# from CHCODES +CATEGORY_DIGIT = ... # type: _NamedIntConstant +CATEGORY_NOT_DIGIT = ... # type: _NamedIntConstant +CATEGORY_SPACE = ... # type: _NamedIntConstant +CATEGORY_NOT_SPACE = ... # type: _NamedIntConstant +CATEGORY_WORD = ... # type: _NamedIntConstant +CATEGORY_NOT_WORD = ... # type: _NamedIntConstant +CATEGORY_LINEBREAK = ... # type: _NamedIntConstant +CATEGORY_NOT_LINEBREAK = ... # type: _NamedIntConstant +CATEGORY_LOC_WORD = ... # type: _NamedIntConstant +CATEGORY_LOC_NOT_WORD = ... # type: _NamedIntConstant +CATEGORY_UNI_DIGIT = ... # type: _NamedIntConstant +CATEGORY_UNI_NOT_DIGIT = ... # type: _NamedIntConstant +CATEGORY_UNI_SPACE = ... # type: _NamedIntConstant +CATEGORY_UNI_NOT_SPACE = ... # type: _NamedIntConstant +CATEGORY_UNI_WORD = ... # type: _NamedIntConstant +CATEGORY_UNI_NOT_WORD = ... # type: _NamedIntConstant +CATEGORY_UNI_LINEBREAK = ... # type: _NamedIntConstant +CATEGORY_UNI_NOT_LINEBREAK = ... # type: _NamedIntConstant diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sre_parse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sre_parse.pyi new file mode 100644 index 000000000..0c9859d26 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sre_parse.pyi @@ -0,0 +1,81 @@ +# Source: https://github.com/python/cpython/blob/master/Lib/sre_parse.py + +from typing import ( + Any, Dict, FrozenSet, Iterable, List, Match, + Optional, Pattern as _Pattern, Tuple, Union +) +from sre_constants import _NamedIntConstant as NIC, error as _Error + +SPECIAL_CHARS = ... # type: str +REPEAT_CHARS = ... # type: str +DIGITS = ... # type: FrozenSet[str] +OCTDIGITS = ... # type: FrozenSet[str] +HEXDIGITS = ... # type: FrozenSet[str] +ASCIILETTERS = ... # type: FrozenSet[str] +WHITESPACE = ... # type: FrozenSet[str] +ESCAPES = ... # type: Dict[str, Tuple[NIC, int]] +CATEGORIES = ... # type: Dict[str, Union[Tuple[NIC, NIC], Tuple[NIC, List[Tuple[NIC, NIC]]]]] +FLAGS = ... # type: Dict[str, int] +GLOBAL_FLAGS = ... # type: int + +class Verbose(Exception): ... + +class Pattern: + flags = ... # type: int + groupdict = ... # type: Dict[str, int] + groupwidths = ... # type: List[Optional[int]] + lookbehindgroups = ... # type: Optional[int] + def __init__(self) -> None: ... + @property + def groups(self) -> int: ... + def opengroup(self, name: str = ...) -> int: ... + def closegroup(self, gid: int, p: SubPattern) -> None: ... + def checkgroup(self, gid: int) -> bool: ... + def checklookbehindgroup(self, gid: int, source: Tokenizer) -> None: ... + + +_OpSubpatternType = Tuple[Optional[int], int, int, SubPattern] +_OpGroupRefExistsType = Tuple[int, SubPattern, SubPattern] +_OpInType = List[Tuple[NIC, int]] +_OpBranchType = Tuple[None, List[SubPattern]] +_AvType = Union[_OpInType, _OpBranchType, Iterable[SubPattern], _OpGroupRefExistsType, _OpSubpatternType] +_CodeType = Tuple[NIC, _AvType] + + +class SubPattern: + pattern = ... # type: Pattern + data = ... # type: List[_CodeType] + width = ... # type: Optional[int] + def __init__(self, pattern: Pattern, data: List[_CodeType] = ...) -> None: ... + def dump(self, level: int = ...) -> None: ... + def __len__(self) -> int: ... + def __delitem__(self, index: Union[int, slice]) -> None: ... + def __getitem__(self, index: Union[int, slice]) -> Union[SubPattern, _CodeType]: ... + def __setitem__(self, index: Union[int, slice], code: _CodeType) -> None: ... + def insert(self, index: int, code: _CodeType) -> None: ... + def append(self, code: _CodeType) -> None: ... + def getwidth(self) -> int: ... + + +class Tokenizer: + istext = ... # type: bool + string = ... # type: Any + decoded_string = ... # type: str + index = ... # type: int + next = ... # type: Optional[str] + def __init__(self, string: Any) -> None: ... + def match(self, char: str) -> bool: ... + def get(self) -> Optional[str]: ... + def getwhile(self, n: int, charset: Iterable[str]) -> str: ... + def getuntil(self, terminator: str) -> str: ... + @property + def pos(self) -> int: ... + def tell(self) -> int: ... + def seek(self, index: int) -> None: ... + def error(self, msg: str, offset: int = ...) -> _Error: ... + +def fix_flags(src: Union[str, bytes], flag: int) -> int: ... +def parse(str: str, flags: int = ..., pattern: Pattern = ...) -> SubPattern: ... +_TemplateType = Tuple[List[Tuple[int, int]], List[str]] +def parse_template(source: str, pattern: _Pattern) -> _TemplateType: ... +def expand_template(template: _TemplateType, match: Match) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/stat.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/stat.pyi new file mode 100644 index 000000000..c45a06863 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/stat.pyi @@ -0,0 +1,75 @@ +# Stubs for stat + +# Based on http://docs.python.org/3.2/library/stat.html + +import sys +import typing + +def S_ISDIR(mode: int) -> bool: ... +def S_ISCHR(mode: int) -> bool: ... +def S_ISBLK(mode: int) -> bool: ... +def S_ISREG(mode: int) -> bool: ... +def S_ISFIFO(mode: int) -> bool: ... +def S_ISLNK(mode: int) -> bool: ... +def S_ISSOCK(mode: int) -> bool: ... + +def S_IMODE(mode: int) -> int: ... +def S_IFMT(mode: int) -> int: ... + +def filemode(mode: int) -> str: ... + +ST_MODE = 0 +ST_INO = 0 +ST_DEV = 0 +ST_NLINK = 0 +ST_UID = 0 +ST_GID = 0 +ST_SIZE = 0 +ST_ATIME = 0 +ST_MTIME = 0 +ST_CTIME = 0 + +S_IFSOCK = 0 +S_IFLNK = 0 +S_IFREG = 0 +S_IFBLK = 0 +S_IFDIR = 0 +S_IFCHR = 0 +S_IFIFO = 0 +S_ISUID = 0 +S_ISGID = 0 +S_ISVTX = 0 + +S_IRWXU = 0 +S_IRUSR = 0 +S_IWUSR = 0 +S_IXUSR = 0 + +S_IRWXG = 0 +S_IRGRP = 0 +S_IWGRP = 0 +S_IXGRP = 0 + +S_IRWXO = 0 +S_IROTH = 0 +S_IWOTH = 0 +S_IXOTH = 0 + +S_ENFMT = 0 +S_IREAD = 0 +S_IWRITE = 0 +S_IEXEC = 0 + +UF_NODUMP = 0 +UF_IMMUTABLE = 0 +UF_APPEND = 0 +UF_OPAQUE = 0 +UF_NOUNLINK = 0 +if sys.platform == 'darwin': + UF_COMPRESSED = 0 # OS X 10.6+ only + UF_HIDDEN = 0 # OX X 10.5+ only +SF_ARCHIVED = 0 +SF_IMMUTABLE = 0 +SF_APPEND = 0 +SF_NOUNLINK = 0 +SF_SNAPSHOT = 0 diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/string.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/string.pyi new file mode 100644 index 000000000..c07c186d1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/string.pyi @@ -0,0 +1,42 @@ +# Stubs for string + +# Based on http://docs.python.org/3.2/library/string.html + +from typing import Mapping, Sequence, Any, Optional, Union, List, Tuple, Iterable + +ascii_letters = ... # type: str +ascii_lowercase = ... # type: str +ascii_uppercase = ... # type: str +digits = ... # type: str +hexdigits = ... # type: str +octdigits = ... # type: str +punctuation = ... # type: str +printable = ... # type: str +whitespace = ... # type: str + +def capwords(s: str, sep: str = ...) -> str: ... + +class Template: + template = ... # type: str + + def __init__(self, template: str) -> None: ... + def substitute(self, mapping: Mapping[str, str] = ..., **kwds: str) -> str: ... + def safe_substitute(self, mapping: Mapping[str, str] = ..., + **kwds: str) -> str: ... + +# TODO(MichalPokorny): This is probably badly and/or loosely typed. +class Formatter: + def format(self, format_string: str, *args: Any, **kwargs: Any) -> str: ... + def vformat(self, format_string: str, args: Sequence[Any], + kwargs: Mapping[str, Any]) -> str: ... + def parse(self, format_string: str) -> Iterable[Tuple[str, Optional[str], Optional[str], Optional[str]]]: ... + def get_field(self, field_name: str, args: Sequence[Any], + kwargs: Mapping[str, Any]) -> Any: ... + def get_value(self, key: Union[int, str], args: Sequence[Any], + kwargs: Mapping[str, Any]) -> Any: + raise IndexError() + raise KeyError() + def check_unused_args(self, used_args: Sequence[Union[int, str]], args: Sequence[Any], + kwargs: Mapping[str, Any]) -> None: ... + def format_field(self, value: Any, format_spec: str) -> Any: ... + def convert_field(self, value: Any, conversion: str) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/subprocess.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/subprocess.pyi new file mode 100644 index 000000000..c0d175bb0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/subprocess.pyi @@ -0,0 +1,312 @@ +# Stubs for subprocess + +# Based on http://docs.python.org/3.6/library/subprocess.html +import sys +from typing import Sequence, Any, Mapping, Callable, Tuple, IO, Optional, Union, List, Type, Text +from types import TracebackType + +# We prefer to annotate inputs to methods (eg subprocess.check_call) with these +# union types. However, outputs (eg check_call return) and class attributes +# (eg TimeoutError.cmd) we prefer to annotate with Any, so the caller does not +# have to use an assertion to confirm which type. +# +# For example: +# +# try: +# x = subprocess.check_output(["ls", "-l"]) +# reveal_type(x) # Any, but morally is _TXT +# except TimeoutError as e: +# reveal_type(e.cmd) # Any, but morally is _CMD +_FILE = Union[None, int, IO[Any]] +_TXT = Union[bytes, Text] +if sys.version_info >= (3, 6): + from builtins import _PathLike + _PATH = Union[bytes, Text, _PathLike] +else: + _PATH = Union[bytes, Text] +# Python 3.6 does't support _CMD being a single PathLike. +# See: https://bugs.python.org/issue31961 +_CMD = Union[_TXT, Sequence[_PATH]] +_ENV = Union[Mapping[bytes, _TXT], Mapping[Text, _TXT]] + +if sys.version_info >= (3, 5): + class CompletedProcess: + # morally: _CMD + args = ... # type: Any + returncode = ... # type: int + # morally: Optional[_TXT] + stdout = ... # type: Any + stderr = ... # type: Any + def __init__(self, args: _CMD, + returncode: int, + stdout: Optional[_TXT] = ..., + stderr: Optional[_TXT] = ...) -> None: ... + def check_returncode(self) -> None: ... + + if sys.version_info >= (3, 6): + # Nearly same args as Popen.__init__ except for timeout, input, and check + def run(args: _CMD, + timeout: Optional[float] = ..., + input: Optional[_TXT] = ..., + check: bool = ..., + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> CompletedProcess: ... + else: + # Nearly same args as Popen.__init__ except for timeout, input, and check + def run(args: _CMD, + timeout: Optional[float] = ..., + input: Optional[_TXT] = ..., + check: bool = ..., + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> CompletedProcess: ... + +# Same args as Popen.__init__ +def call(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float = ...) -> int: ... + +# Same args as Popen.__init__ +def check_call(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stdout: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float = ...) -> int: ... + +if sys.version_info >= (3, 6): + # 3.6 added encoding and errors + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + timeout: float = ..., + input: _TXT = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + ) -> Any: ... # morally: -> _TXT +else: + def check_output(args: _CMD, + bufsize: int = ..., + executable: _PATH = ..., + stdin: _FILE = ..., + stderr: _FILE = ..., + preexec_fn: Callable[[], Any] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Any = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + timeout: float = ..., + input: _TXT = ..., + ) -> Any: ... # morally: -> _TXT + + +PIPE = ... # type: int +STDOUT = ... # type: int +DEVNULL = ... # type: int +class SubprocessError(Exception): ... +class TimeoutExpired(SubprocessError): + # morally: _CMD + cmd = ... # type: Any + timeout = ... # type: float + # morally: Optional[_TXT] + output = ... # type: Any + stdout = ... # type: Any + stderr = ... # type: Any + + +class CalledProcessError(Exception): + returncode = 0 + # morally: _CMD + cmd = ... # type: Any + # morally: Optional[_TXT] + output = ... # type: Any + + if sys.version_info >= (3, 5): + # morally: Optional[_TXT] + stdout = ... # type: Any + stderr = ... # type: Any + + def __init__(self, + returncode: int, + cmd: _CMD, + output: Optional[_TXT] = ..., + stderr: Optional[_TXT] = ...) -> None: ... + +class Popen: + args = ... # type: _CMD + stdin = ... # type: IO[Any] + stdout = ... # type: IO[Any] + stderr = ... # type: IO[Any] + pid = 0 + returncode = 0 + + if sys.version_info >= (3, 6): + def __init__(self, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ..., + *, + encoding: Optional[str] = ..., + errors: Optional[str] = ...) -> None: ... + else: + def __init__(self, + args: _CMD, + bufsize: int = ..., + executable: Optional[_PATH] = ..., + stdin: Optional[_FILE] = ..., + stdout: Optional[_FILE] = ..., + stderr: Optional[_FILE] = ..., + preexec_fn: Optional[Callable[[], Any]] = ..., + close_fds: bool = ..., + shell: bool = ..., + cwd: Optional[_PATH] = ..., + env: Optional[_ENV] = ..., + universal_newlines: bool = ..., + startupinfo: Optional[Any] = ..., + creationflags: int = ..., + restore_signals: bool = ..., + start_new_session: bool = ..., + pass_fds: Any = ...) -> None: ... + + def poll(self) -> int: ... + def wait(self, timeout: Optional[float] = ...) -> int: ... + # Return str/bytes + def communicate(self, + input: Optional[_TXT] = ..., + timeout: Optional[float] = ..., + # morally: -> Tuple[Optional[_TXT], Optional[_TXT]] + ) -> Tuple[Any, Any]: ... + def send_signal(self, signal: int) -> None: ... + def terminate(self) -> None: ... + def kill(self) -> None: ... + def __enter__(self) -> 'Popen': ... + def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> bool: ... + +# The result really is always a str. +def getstatusoutput(cmd: _TXT) -> Tuple[int, str]: ... +def getoutput(cmd: _TXT) -> str: ... + +def list2cmdline(seq: Sequence[str]) -> str: ... # undocumented + +if sys.platform == 'win32': + class STARTUPINFO: + if sys.version_info >= (3, 7): + def __init__(self, *, dwFlags: int = ..., hStdInput: Optional[Any] = ..., hStdOutput: Optional[Any] = ..., hStdError: Optional[Any] = ..., wShowWindow: int = ..., lpAttributeList: Optional[Mapping[str, Any]] = ...) -> None: ... + dwFlags: int + hStdInput: Optional[Any] + hStdOutput: Optional[Any] + hStdError: Optional[Any] + wShowWindow: int + if sys.version_info >= (3, 7): + lpAttributeList: Mapping[str, Any] + + STD_INPUT_HANDLE: Any + STD_OUTPUT_HANDLE: Any + STD_ERROR_HANDLE: Any + SW_HIDE: int + STARTF_USESTDHANDLES: int + STARTF_USESHOWWINDOW: int + CREATE_NEW_CONSOLE: int + CREATE_NEW_PROCESS_GROUP: int + if sys.version_info >= (3, 7): + ABOVE_NORMAL_PRIORITY_CLASS: int + BELOW_NORMAL_PRIORITY_CLASS: int + HIGH_PRIORITY_CLASS: int + IDLE_PRIORITY_CLASS: int + NORMAL_PRIORITY_CLASS: int + REALTIME_PRIORITY_CLASS: int + CREATE_NO_WINDOW: int + DETACHED_PROCESS: int + CREATE_DEFAULT_ERROR_MODE: int + CREATE_BREAKAWAY_FROM_JOB: int diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/symbol.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/symbol.pyi new file mode 100644 index 000000000..f228cf7ba --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/symbol.pyi @@ -0,0 +1,97 @@ +# Stubs for symbol (Python 3) + +import sys +from typing import Dict + +single_input = ... # type: int +file_input = ... # type: int +eval_input = ... # type: int +decorator = ... # type: int +decorators = ... # type: int +decorated = ... # type: int +if sys.version_info >= (3, 5): + async_funcdef = ... # type: int +funcdef = ... # type: int +parameters = ... # type: int +typedargslist = ... # type: int +tfpdef = ... # type: int +varargslist = ... # type: int +vfpdef = ... # type: int +stmt = ... # type: int +simple_stmt = ... # type: int +small_stmt = ... # type: int +expr_stmt = ... # type: int +if sys.version_info >= (3, 6): + annassign = ... # type: int +testlist_star_expr = ... # type: int +augassign = ... # type: int +del_stmt = ... # type: int +pass_stmt = ... # type: int +flow_stmt = ... # type: int +break_stmt = ... # type: int +continue_stmt = ... # type: int +return_stmt = ... # type: int +yield_stmt = ... # type: int +raise_stmt = ... # type: int +import_stmt = ... # type: int +import_name = ... # type: int +import_from = ... # type: int +import_as_name = ... # type: int +dotted_as_name = ... # type: int +import_as_names = ... # type: int +dotted_as_names = ... # type: int +dotted_name = ... # type: int +global_stmt = ... # type: int +nonlocal_stmt = ... # type: int +assert_stmt = ... # type: int +compound_stmt = ... # type: int +if sys.version_info >= (3, 5): + async_stmt = ... # type: int +if_stmt = ... # type: int +while_stmt = ... # type: int +for_stmt = ... # type: int +try_stmt = ... # type: int +with_stmt = ... # type: int +with_item = ... # type: int +except_clause = ... # type: int +suite = ... # type: int +test = ... # type: int +test_nocond = ... # type: int +lambdef = ... # type: int +lambdef_nocond = ... # type: int +or_test = ... # type: int +and_test = ... # type: int +not_test = ... # type: int +comparison = ... # type: int +comp_op = ... # type: int +star_expr = ... # type: int +expr = ... # type: int +xor_expr = ... # type: int +and_expr = ... # type: int +shift_expr = ... # type: int +arith_expr = ... # type: int +term = ... # type: int +factor = ... # type: int +power = ... # type: int +if sys.version_info >= (3, 5): + atom_expr = ... # type: int +atom = ... # type: int +testlist_comp = ... # type: int +trailer = ... # type: int +subscriptlist = ... # type: int +subscript = ... # type: int +sliceop = ... # type: int +exprlist = ... # type: int +testlist = ... # type: int +dictorsetmaker = ... # type: int +classdef = ... # type: int +arglist = ... # type: int +argument = ... # type: int +comp_iter = ... # type: int +comp_for = ... # type: int +comp_if = ... # type: int +encoding_decl = ... # type: int +yield_expr = ... # type: int +yield_arg = ... # type: int + +sym_name = ... # type: Dict[int, str] diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sys.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sys.pyi new file mode 100644 index 000000000..128be7ba0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/sys.pyi @@ -0,0 +1,192 @@ +# Stubs for sys +# Ron Murawski + +# based on http://docs.python.org/3.2/library/sys.html + +from typing import ( + List, NoReturn, Sequence, Any, Dict, Tuple, TextIO, overload, Optional, + Union, TypeVar, Callable, Type +) +import sys +from types import FrameType, ModuleType, TracebackType + +from importlib.abc import MetaPathFinder + +_T = TypeVar('_T') + +# ----- sys variables ----- +abiflags: str +argv: List[str] +base_exec_prefix: str +base_prefix: str +byteorder: str +builtin_module_names: Sequence[str] # actually a tuple of strings +copyright: str +# dllhandle = 0 # Windows only +dont_write_bytecode: bool +__displayhook__: Any # contains the original value of displayhook +__excepthook__: Any # contains the original value of excepthook +exec_prefix: str +executable: str +float_repr_style: str +hexversion: int +last_type: Optional[Type[BaseException]] +last_value: Optional[BaseException] +last_traceback: Optional[TracebackType] +maxsize: int +maxunicode: int +meta_path: List[MetaPathFinder] +modules: Dict[str, ModuleType] +path: List[str] +path_hooks: List[Any] # TODO precise type; function, path to finder +path_importer_cache: Dict[str, Any] # TODO precise type +platform: str +prefix: str +ps1: str +ps2: str +stdin: TextIO +stdout: TextIO +stderr: TextIO +__stdin__: TextIO +__stdout__: TextIO +__stderr__: TextIO +# deprecated and removed in Python 3.3: +subversion: Tuple[str, str, str] +tracebacklimit: int +version: str +api_version: int +warnoptions: Any +# Each entry is a tuple of the form (action, message, category, module, +# lineno) +# winver = '' # Windows only +_xoptions: Dict[Any, Any] + + +flags: _flags +class _flags: + debug: int + division_warning: int + inspect: int + interactive: int + optimize: int + dont_write_bytecode: int + no_user_site: int + no_site: int + ignore_environment: int + verbose: int + bytes_warning: int + quiet: int + hash_randomization: int + if sys.version_info >= (3, 7): + dev_mode: int + +float_info: _float_info +class _float_info: + epsilon: float # DBL_EPSILON + dig: int # DBL_DIG + mant_dig: int # DBL_MANT_DIG + max: float # DBL_MAX + max_exp: int # DBL_MAX_EXP + max_10_exp: int # DBL_MAX_10_EXP + min: float # DBL_MIN + min_exp: int # DBL_MIN_EXP + min_10_exp: int # DBL_MIN_10_EXP + radix: int # FLT_RADIX + rounds: int # FLT_ROUNDS + +hash_info: _hash_info +class _hash_info: + width: int + modulus: int + inf: int + nan: int + imag: int + +implementation: _implementation +class _implementation: + name: str + version: _version_info + hexversion: int + cache_tag: str + +int_info: _int_info +class _int_info: + bits_per_digit: int + sizeof_digit: int + +class _version_info(Tuple[int, int, int, str, int]): + major: int + minor: int + micro: int + releaselevel: str + serial: int +version_info: _version_info + +def call_tracing(fn: Callable[..., _T], args: Any) -> _T: ... +def _clear_type_cache() -> None: ... +def _current_frames() -> Dict[int, Any]: ... +def displayhook(value: Optional[int]) -> None: ... +def excepthook(type_: Type[BaseException], value: BaseException, + traceback: TracebackType) -> None: ... +def exc_info() -> Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]]: ... +# sys.exit() accepts an optional argument of anything printable +def exit(arg: object = ...) -> NoReturn: + raise SystemExit() +def getcheckinterval() -> int: ... # deprecated +def getdefaultencoding() -> str: ... +def getdlopenflags() -> int: ... # Unix only +def getfilesystemencoding() -> str: ... +def getrefcount(arg: Any) -> int: ... +def getrecursionlimit() -> int: ... + +@overload +def getsizeof(obj: object) -> int: ... +@overload +def getsizeof(obj: object, default: int) -> int: ... + +def getswitchinterval() -> float: ... + +@overload +def _getframe() -> FrameType: ... +@overload +def _getframe(depth: int) -> FrameType: ... + +_ProfileFunc = Callable[[FrameType, str, Any], Any] +def getprofile() -> Optional[_ProfileFunc]: ... +def setprofile(profilefunc: Optional[_ProfileFunc]) -> None: ... + +_TraceFunc = Callable[[FrameType, str, Any], Optional[Callable[[FrameType, str, Any], Any]]] +def gettrace() -> Optional[_TraceFunc]: ... +def settrace(tracefunc: _TraceFunc) -> None: ... + + +class _WinVersion(Tuple[int, int, int, int, + str, int, int, int, int, + Tuple[int, int, int]]): + major: int + minor: int + build: int + platform: int + service_pack: str + service_pack_minor: int + service_pack_major: int + suite_mast: int + product_type: int + platform_version: Tuple[int, int, int] + + +def getwindowsversion() -> _WinVersion: ... # Windows only +def intern(string: str) -> str: ... + +if sys.version_info >= (3, 5): + def is_finalizing() -> bool: ... + +def setcheckinterval(interval: int) -> None: ... # deprecated +def setdlopenflags(n: int) -> None: ... # Linux only +def setrecursionlimit(limit: int) -> None: ... +def setswitchinterval(interval: float) -> None: ... +def settscdump(on_flag: bool) -> None: ... + +def gettotalrefcount() -> int: ... # Debug builds only diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tempfile.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tempfile.pyi new file mode 100644 index 000000000..5900f25af --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tempfile.pyi @@ -0,0 +1,91 @@ +# Stubs for tempfile +# Ron Murawski + +# based on http://docs.python.org/3.3/library/tempfile.html + +import sys +from types import TracebackType +from typing import Any, AnyStr, Generic, IO, Optional, Tuple, Type + +# global variables +TMP_MAX: int +tempdir = ... # type: Optional[str] +template = ... # type: str + + +if sys.version_info >= (3, 5): + def TemporaryFile( + mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., + dir: Optional[AnyStr] = ... + ) -> IO[Any]: + ... + def NamedTemporaryFile( + mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + newline: Optional[str] = ..., suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., + dir: Optional[AnyStr] = ..., delete: bool =... + ) -> IO[Any]: + ... + def SpooledTemporaryFile( + max_size: int = ..., mode: str = ..., buffering: int = ..., + encoding: str = ..., newline: str = ..., suffix: Optional[AnyStr] = ..., + prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ... + ) -> IO[Any]: + ... + + class TemporaryDirectory(Generic[AnyStr]): + name = ... # type: str + def __init__(self, suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., + dir: Optional[AnyStr] = ...) -> None: ... + def cleanup(self) -> None: ... + def __enter__(self) -> AnyStr: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + + def mkstemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ..., + text: bool = ...) -> Tuple[int, AnyStr]: ... + def mkdtemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., + dir: Optional[str] = ...) -> AnyStr: ... + def mktemp(suffix: Optional[AnyStr] = ..., prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ...) -> AnyStr: ... + + def gettempdirb() -> bytes: ... + def gettempprefixb() -> bytes: ... +else: + def TemporaryFile( + mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + newline: Optional[str] = ..., suffix: str = ..., prefix: str = ..., + dir: Optional[str] = ... + ) -> IO[Any]: + ... + def NamedTemporaryFile( + mode: str = ..., buffering: int = ..., encoding: Optional[str] = ..., + newline: Optional[str] = ..., suffix: str = ..., prefix: str = ..., + dir: Optional[str] = ..., delete: bool =... + ) -> IO[Any]: + ... + def SpooledTemporaryFile( + max_size: int = ..., mode: str = ..., buffering: int = ..., + encoding: str = ..., newline: str = ..., suffix: str = ..., + prefix: str = ..., dir: Optional[str] = ... + ) -> IO[Any]: + ... + + class TemporaryDirectory: + name = ... # type: str + def __init__(self, suffix: str = ..., prefix: str = ..., + dir: Optional[str] = ...) -> None: ... + def cleanup(self) -> None: ... + def __enter__(self) -> str: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + + def mkstemp(suffix: str = ..., prefix: str = ..., dir: Optional[str] = ..., + text: bool = ...) -> Tuple[int, str]: ... + def mkdtemp(suffix: str = ..., prefix: str = ..., + dir: Optional[str] = ...) -> str: ... + def mktemp(suffix: str = ..., prefix: str = ..., dir: Optional[str] = ...) -> str: ... + +def gettempdir() -> str: ... +def gettempprefix() -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/textwrap.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/textwrap.pyi new file mode 100644 index 000000000..f61f975bb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/textwrap.pyi @@ -0,0 +1,113 @@ +from typing import Callable, List, Optional, Dict, Pattern + +class TextWrapper: + width: int = ... + initial_indent: str = ... + subsequent_indent: str = ... + expand_tabs: bool = ... + replace_whitespace: bool = ... + fix_sentence_endings: bool = ... + drop_whitespace: bool = ... + break_long_words: bool = ... + break_on_hyphens: bool = ... + tabsize: int = ... + max_lines: Optional[int] = ... + placeholder: str = ... + + # Attributes not present in documentation + sentence_end_re: Pattern[str] = ... + wordsep_re: Pattern[str] = ... + wordsep_simple_re: Pattern[str] = ... + whitespace_trans: str = ... + unicode_whitespace_trans: Dict[int, int] = ... + uspace: int = ... + x: int = ... + + def __init__( + self, + width: int = ..., + initial_indent: str = ..., + subsequent_indent: str = ..., + expand_tabs: bool = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + drop_whitespace: bool = ..., + break_on_hyphens: bool = ..., + tabsize: int = ..., + *, + max_lines: Optional[int] = ..., + placeholder: str = ...) -> None: + ... + + # Private methods *are* part of the documented API for subclasses. + def _munge_whitespace(self, text: str) -> str: ... + def _split(self, text: str) -> List[str]: ... + def _fix_sentence_endings(self, chunks: List[str]) -> None: ... + def _handle_long_word(self, reversed_chunks: List[str], cur_line: List[str], cur_len: int, width: int) -> None: ... + def _wrap_chunks(self, chunks: List[str]) -> List[str]: ... + def _split_chunks(self, text: str) -> List[str]: ... + + def wrap(self, text: str) -> List[str]: ... + def fill(self, text: str) -> str: ... + + +def wrap( + text: str = ..., + width: int = ..., + *, + initial_indent: str = ..., + subsequent_indent: str = ..., + expand_tabs: bool = ..., + tabsize: int = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + break_on_hyphens: bool = ..., + drop_whitespace: bool = ..., + max_lines: int = ..., + placeholder: str = ... +) -> List[str]: + ... + +def fill( + text: str, + width: int = ..., + *, + initial_indent: str = ..., + subsequent_indent: str = ..., + expand_tabs: bool = ..., + tabsize: int = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + break_on_hyphens: bool = ..., + drop_whitespace: bool = ..., + max_lines: int = ..., + placeholder: str = ... +) -> str: + ... + +def shorten( + text: str, + width: int, + *, + initial_indent: str = ..., + subsequent_indent: str = ..., + expand_tabs: bool = ..., + tabsize: int = ..., + replace_whitespace: bool = ..., + fix_sentence_endings: bool = ..., + break_long_words: bool = ..., + break_on_hyphens: bool = ..., + drop_whitespace: bool = ..., + # Omit `max_lines: int = None`, it is forced to 1 here. + placeholder: str = ... +) -> str: + ... + +def dedent(text: str) -> str: + ... + +def indent(text: str, prefix: str, predicate: Callable[[str], bool] = ...) -> str: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/__init__.pyi new file mode 100644 index 000000000..f7f7f8cf0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/__init__.pyi @@ -0,0 +1,656 @@ +from typing import Any +from tkinter.constants import * # noqa: F403 + +TclError = ... # type: Any +wantobjects = ... # type: Any +TkVersion = ... # type: Any +TclVersion = ... # type: Any +READABLE = ... # type: Any +WRITABLE = ... # type: Any +EXCEPTION = ... # type: Any + +class Event: ... + +def NoDefaultRoot(): ... + +class Variable: + def __init__(self, master=None, value=None, name=None): ... + def __del__(self): ... + def set(self, value): ... + initialize = ... # type: Any + def get(self): ... + def trace_variable(self, mode, callback): ... + trace = ... # type: Any + def trace_vdelete(self, mode, cbname): ... + def trace_vinfo(self): ... + def __eq__(self, other): ... + +class StringVar(Variable): + def __init__(self, master=None, value=None, name=None): ... + def get(self): ... + +class IntVar(Variable): + def __init__(self, master=None, value=None, name=None): ... + def get(self): ... + +class DoubleVar(Variable): + def __init__(self, master=None, value=None, name=None): ... + def get(self): ... + +class BooleanVar(Variable): + def __init__(self, master=None, value=None, name=None): ... + def set(self, value): ... + initialize = ... # type: Any + def get(self): ... + +def mainloop(n=0): ... + +getint = ... # type: Any +getdouble = ... # type: Any + +def getboolean(s): ... + +class Misc: + def destroy(self): ... + def deletecommand(self, name): ... + def tk_strictMotif(self, boolean=None): ... + def tk_bisque(self): ... + def tk_setPalette(self, *args, **kw): ... + def tk_menuBar(self, *args): ... + def wait_variable(self, name: str = ...): ... + waitvar = ... # type: Any + def wait_window(self, window=None): ... + def wait_visibility(self, window=None): ... + def setvar(self, name: str = ..., value: str = ...): ... + def getvar(self, name: str = ...): ... + def getint(self, s): ... + def getdouble(self, s): ... + def getboolean(self, s): ... + def focus_set(self): ... + focus = ... # type: Any + def focus_force(self): ... + def focus_get(self): ... + def focus_displayof(self): ... + def focus_lastfor(self): ... + def tk_focusFollowsMouse(self): ... + def tk_focusNext(self): ... + def tk_focusPrev(self): ... + def after(self, ms, func=None, *args): ... + def after_idle(self, func, *args): ... + def after_cancel(self, id): ... + def bell(self, displayof=0): ... + def clipboard_get(self, **kw): ... + def clipboard_clear(self, **kw): ... + def clipboard_append(self, string, **kw): ... + def grab_current(self): ... + def grab_release(self): ... + def grab_set(self): ... + def grab_set_global(self): ... + def grab_status(self): ... + def option_add(self, pattern, value, priority=None): ... + def option_clear(self): ... + def option_get(self, name, className): ... + def option_readfile(self, fileName, priority=None): ... + def selection_clear(self, **kw): ... + def selection_get(self, **kw): ... + def selection_handle(self, command, **kw): ... + def selection_own(self, **kw): ... + def selection_own_get(self, **kw): ... + def send(self, interp, cmd, *args): ... + def lower(self, belowThis=None): ... + def tkraise(self, aboveThis=None): ... + lift = ... # type: Any + def winfo_atom(self, name, displayof=0): ... + def winfo_atomname(self, id, displayof=0): ... + def winfo_cells(self): ... + def winfo_children(self): ... + def winfo_class(self): ... + def winfo_colormapfull(self): ... + def winfo_containing(self, rootX, rootY, displayof=0): ... + def winfo_depth(self): ... + def winfo_exists(self): ... + def winfo_fpixels(self, number): ... + def winfo_geometry(self): ... + def winfo_height(self): ... + def winfo_id(self): ... + def winfo_interps(self, displayof=0): ... + def winfo_ismapped(self): ... + def winfo_manager(self): ... + def winfo_name(self): ... + def winfo_parent(self): ... + def winfo_pathname(self, id, displayof=0): ... + def winfo_pixels(self, number): ... + def winfo_pointerx(self): ... + def winfo_pointerxy(self): ... + def winfo_pointery(self): ... + def winfo_reqheight(self): ... + def winfo_reqwidth(self): ... + def winfo_rgb(self, color): ... + def winfo_rootx(self): ... + def winfo_rooty(self): ... + def winfo_screen(self): ... + def winfo_screencells(self): ... + def winfo_screendepth(self): ... + def winfo_screenheight(self): ... + def winfo_screenmmheight(self): ... + def winfo_screenmmwidth(self): ... + def winfo_screenvisual(self): ... + def winfo_screenwidth(self): ... + def winfo_server(self): ... + def winfo_toplevel(self): ... + def winfo_viewable(self): ... + def winfo_visual(self): ... + def winfo_visualid(self): ... + def winfo_visualsavailable(self, includeids=0): ... + def winfo_vrootheight(self): ... + def winfo_vrootwidth(self): ... + def winfo_vrootx(self): ... + def winfo_vrooty(self): ... + def winfo_width(self): ... + def winfo_x(self): ... + def winfo_y(self): ... + def update(self): ... + def update_idletasks(self): ... + def bindtags(self, tagList=None): ... + def bind(self, sequence=None, func=None, add=None): ... + def unbind(self, sequence, funcid=None): ... + def bind_all(self, sequence=None, func=None, add=None): ... + def unbind_all(self, sequence): ... + def bind_class(self, className, sequence=None, func=None, add=None): ... + def unbind_class(self, className, sequence): ... + def mainloop(self, n=0): ... + def quit(self): ... + def nametowidget(self, name): ... + register = ... # type: Any + def configure(self, cnf=None, **kw): ... + config = ... # type: Any + def cget(self, key): ... + __getitem__ = ... # type: Any + def __setitem__(self, key, value): ... + def keys(self): ... + def pack_propagate(self, flag=...): ... + propagate = ... # type: Any + def pack_slaves(self): ... + slaves = ... # type: Any + def place_slaves(self): ... + def grid_anchor(self, anchor=None): ... + anchor = ... # type: Any + def grid_bbox(self, column=None, row=None, col2=None, row2=None): ... + bbox = ... # type: Any + def grid_columnconfigure(self, index, cnf=..., **kw): ... + columnconfigure = ... # type: Any + def grid_location(self, x, y): ... + def grid_propagate(self, flag=...): ... + def grid_rowconfigure(self, index, cnf=..., **kw): ... + rowconfigure = ... # type: Any + def grid_size(self): ... + size = ... # type: Any + def grid_slaves(self, row=None, column=None): ... + def event_add(self, virtual, *sequences): ... + def event_delete(self, virtual, *sequences): ... + def event_generate(self, sequence, **kw): ... + def event_info(self, virtual=None): ... + def image_names(self): ... + def image_types(self): ... + +class CallWrapper: + func = ... # type: Any + subst = ... # type: Any + widget = ... # type: Any + def __init__(self, func, subst, widget): ... + def __call__(self, *args): ... + +class XView: + def xview(self, *args): ... + def xview_moveto(self, fraction): ... + def xview_scroll(self, number, what): ... + +class YView: + def yview(self, *args): ... + def yview_moveto(self, fraction): ... + def yview_scroll(self, number, what): ... + +class Wm: + def wm_aspect(self, minNumer=None, minDenom=None, maxNumer=None, maxDenom=None): ... + aspect = ... # type: Any + def wm_attributes(self, *args): ... + attributes = ... # type: Any + def wm_client(self, name=None): ... + client = ... # type: Any + def wm_colormapwindows(self, *wlist): ... + colormapwindows = ... # type: Any + def wm_command(self, value=None): ... + command = ... # type: Any + def wm_deiconify(self): ... + deiconify = ... # type: Any + def wm_focusmodel(self, model=None): ... + focusmodel = ... # type: Any + def wm_forget(self, window): ... + forget = ... # type: Any + def wm_frame(self): ... + frame = ... # type: Any + def wm_geometry(self, newGeometry=None): ... + geometry = ... # type: Any + def wm_grid(self, baseWidth=None, baseHeight=None, widthInc=None, heightInc=None): ... + grid = ... # type: Any + def wm_group(self, pathName=None): ... + group = ... # type: Any + def wm_iconbitmap(self, bitmap=None, default=None): ... + iconbitmap = ... # type: Any + def wm_iconify(self): ... + iconify = ... # type: Any + def wm_iconmask(self, bitmap=None): ... + iconmask = ... # type: Any + def wm_iconname(self, newName=None): ... + iconname = ... # type: Any + def wm_iconphoto(self, default=False, *args): ... + iconphoto = ... # type: Any + def wm_iconposition(self, x=None, y=None): ... + iconposition = ... # type: Any + def wm_iconwindow(self, pathName=None): ... + iconwindow = ... # type: Any + def wm_manage(self, widget): ... + manage = ... # type: Any + def wm_maxsize(self, width=None, height=None): ... + maxsize = ... # type: Any + def wm_minsize(self, width=None, height=None): ... + minsize = ... # type: Any + def wm_overrideredirect(self, boolean=None): ... + overrideredirect = ... # type: Any + def wm_positionfrom(self, who=None): ... + positionfrom = ... # type: Any + def wm_protocol(self, name=None, func=None): ... + protocol = ... # type: Any + def wm_resizable(self, width=None, height=None): ... + resizable = ... # type: Any + def wm_sizefrom(self, who=None): ... + sizefrom = ... # type: Any + def wm_state(self, newstate=None): ... + state = ... # type: Any + def wm_title(self, string=None): ... + title = ... # type: Any + def wm_transient(self, master=None): ... + transient = ... # type: Any + def wm_withdraw(self): ... + withdraw = ... # type: Any + +class Tk(Misc, Wm): + master = ... # type: Any + children = ... # type: Any + tk = ... # type: Any + def __init__(self, screenName=None, baseName=None, className: str = ..., useTk=1, sync=0, use=None) -> None: ... + def loadtk(self): ... + def destroy(self): ... + def readprofile(self, baseName, className): ... + def report_callback_exception(self, exc, val, tb): ... + def __getattr__(self, attr): ... + +def Tcl(screenName=None, baseName=None, className: str = ..., useTk=0): ... + +class Pack: + def pack_configure(self, cnf=..., **kw): ... + pack = ... # type: Any + def pack_forget(self): ... + forget = ... # type: Any + def pack_info(self): ... + info = ... # type: Any + propagate = ... # type: Any + slaves = ... # type: Any + +class Place: + def place_configure(self, cnf=..., **kw): ... + place = ... # type: Any + def place_forget(self): ... + forget = ... # type: Any + def place_info(self): ... + info = ... # type: Any + slaves = ... # type: Any + +class Grid: + def grid_configure(self, cnf=..., **kw): ... + grid = ... # type: Any + bbox = ... # type: Any + columnconfigure = ... # type: Any + def grid_forget(self): ... + forget = ... # type: Any + def grid_remove(self): ... + def grid_info(self): ... + info = ... # type: Any + location = ... # type: Any + propagate = ... # type: Any + rowconfigure = ... # type: Any + size = ... # type: Any + slaves = ... # type: Any + +class BaseWidget(Misc): + widgetName = ... # type: Any + def __init__(self, master, widgetName, cnf=..., kw=..., extra=...): ... + def destroy(self): ... + +class Widget(BaseWidget, Pack, Place, Grid): ... + +class Toplevel(BaseWidget, Wm): + def __init__(self, master=None, cnf=..., **kw): ... + +class Button(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def flash(self): ... + def invoke(self): ... + +class Canvas(Widget, XView, YView): + def __init__(self, master=None, cnf=..., **kw): ... + def addtag(self, *args): ... + def addtag_above(self, newtag, tagOrId): ... + def addtag_all(self, newtag): ... + def addtag_below(self, newtag, tagOrId): ... + def addtag_closest(self, newtag, x, y, halo=None, start=None): ... + def addtag_enclosed(self, newtag, x1, y1, x2, y2): ... + def addtag_overlapping(self, newtag, x1, y1, x2, y2): ... + def addtag_withtag(self, newtag, tagOrId): ... + def bbox(self, *args): ... + def tag_unbind(self, tagOrId, sequence, funcid=None): ... + def tag_bind(self, tagOrId, sequence=None, func=None, add=None): ... + def canvasx(self, screenx, gridspacing=None): ... + def canvasy(self, screeny, gridspacing=None): ... + def coords(self, *args): ... + def create_arc(self, *args, **kw): ... + def create_bitmap(self, *args, **kw): ... + def create_image(self, *args, **kw): ... + def create_line(self, *args, **kw): ... + def create_oval(self, *args, **kw): ... + def create_polygon(self, *args, **kw): ... + def create_rectangle(self, *args, **kw): ... + def create_text(self, *args, **kw): ... + def create_window(self, *args, **kw): ... + def dchars(self, *args): ... + def delete(self, *args): ... + def dtag(self, *args): ... + def find(self, *args): ... + def find_above(self, tagOrId): ... + def find_all(self): ... + def find_below(self, tagOrId): ... + def find_closest(self, x, y, halo=None, start=None): ... + def find_enclosed(self, x1, y1, x2, y2): ... + def find_overlapping(self, x1, y1, x2, y2): ... + def find_withtag(self, tagOrId): ... + def focus(self, *args): ... + def gettags(self, *args): ... + def icursor(self, *args): ... + def index(self, *args): ... + def insert(self, *args): ... + def itemcget(self, tagOrId, option): ... + def itemconfigure(self, tagOrId, cnf=None, **kw): ... + itemconfig = ... # type: Any + def tag_lower(self, *args): ... + lower = ... # type: Any + def move(self, *args): ... + def postscript(self, cnf=..., **kw): ... + def tag_raise(self, *args): ... + lift = ... # type: Any + def scale(self, *args): ... + def scan_mark(self, x, y): ... + def scan_dragto(self, x, y, gain=10): ... + def select_adjust(self, tagOrId, index): ... + def select_clear(self): ... + def select_from(self, tagOrId, index): ... + def select_item(self): ... + def select_to(self, tagOrId, index): ... + def type(self, tagOrId): ... + +class Checkbutton(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def deselect(self): ... + def flash(self): ... + def invoke(self): ... + def select(self): ... + def toggle(self): ... + +class Entry(Widget, XView): + def __init__(self, master=None, cnf=..., **kw): ... + def delete(self, first, last=None): ... + def get(self): ... + def icursor(self, index): ... + def index(self, index): ... + def insert(self, index, string): ... + def scan_mark(self, x): ... + def scan_dragto(self, x): ... + def selection_adjust(self, index): ... + select_adjust = ... # type: Any + def selection_clear(self): ... + select_clear = ... # type: Any + def selection_from(self, index): ... + select_from = ... # type: Any + def selection_present(self): ... + select_present = ... # type: Any + def selection_range(self, start, end): ... + select_range = ... # type: Any + def selection_to(self, index): ... + select_to = ... # type: Any + +class Frame(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + +class Label(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + +class Listbox(Widget, XView, YView): + def __init__(self, master=None, cnf=..., **kw): ... + def activate(self, index): ... + def bbox(self, index): ... + def curselection(self): ... + def delete(self, first, last=None): ... + def get(self, first, last=None): ... + def index(self, index): ... + def insert(self, index, *elements): ... + def nearest(self, y): ... + def scan_mark(self, x, y): ... + def scan_dragto(self, x, y): ... + def see(self, index): ... + def selection_anchor(self, index): ... + select_anchor = ... # type: Any + def selection_clear(self, first, last=None): ... + select_clear = ... # type: Any + def selection_includes(self, index): ... + select_includes = ... # type: Any + def selection_set(self, first, last=None): ... + select_set = ... # type: Any + def size(self): ... + def itemcget(self, index, option): ... + def itemconfigure(self, index, cnf=None, **kw): ... + itemconfig = ... # type: Any + +class Menu(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def tk_popup(self, x, y, entry: str = ...): ... + def tk_bindForTraversal(self): ... + def activate(self, index): ... + def add(self, itemType, cnf=..., **kw): ... + def add_cascade(self, cnf=..., **kw): ... + def add_checkbutton(self, cnf=..., **kw): ... + def add_command(self, cnf=..., **kw): ... + def add_radiobutton(self, cnf=..., **kw): ... + def add_separator(self, cnf=..., **kw): ... + def insert(self, index, itemType, cnf=..., **kw): ... + def insert_cascade(self, index, cnf=..., **kw): ... + def insert_checkbutton(self, index, cnf=..., **kw): ... + def insert_command(self, index, cnf=..., **kw): ... + def insert_radiobutton(self, index, cnf=..., **kw): ... + def insert_separator(self, index, cnf=..., **kw): ... + def delete(self, index1, index2=None): ... + def entrycget(self, index, option): ... + def entryconfigure(self, index, cnf=None, **kw): ... + entryconfig = ... # type: Any + def index(self, index): ... + def invoke(self, index): ... + def post(self, x, y): ... + def type(self, index): ... + def unpost(self): ... + def xposition(self, index): ... + def yposition(self, index): ... + +class Menubutton(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + +class Message(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + +class Radiobutton(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def deselect(self): ... + def flash(self): ... + def invoke(self): ... + def select(self): ... + +class Scale(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def get(self): ... + def set(self, value): ... + def coords(self, value=None): ... + def identify(self, x, y): ... + +class Scrollbar(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def activate(self, index=None): ... + def delta(self, deltax, deltay): ... + def fraction(self, x, y): ... + def identify(self, x, y): ... + def get(self): ... + def set(self, first, last): ... + +class Text(Widget, XView, YView): + def __init__(self, master=None, cnf=..., **kw): ... + def bbox(self, index): ... + def compare(self, index1, op, index2): ... + def count(self, index1, index2, *args): ... + def debug(self, boolean=None): ... + def delete(self, index1, index2=None): ... + def dlineinfo(self, index): ... + def dump(self, index1, index2=None, command=None, **kw): ... + def edit(self, *args): ... + def edit_modified(self, arg=None): ... + def edit_redo(self): ... + def edit_reset(self): ... + def edit_separator(self): ... + def edit_undo(self): ... + def get(self, index1, index2=None): ... + def image_cget(self, index, option): ... + def image_configure(self, index, cnf=None, **kw): ... + def image_create(self, index, cnf=..., **kw): ... + def image_names(self): ... + def index(self, index): ... + def insert(self, index, chars, *args): ... + def mark_gravity(self, markName, direction=None): ... + def mark_names(self): ... + def mark_set(self, markName, index): ... + def mark_unset(self, *markNames): ... + def mark_next(self, index): ... + def mark_previous(self, index): ... + def peer_create(self, newPathName, cnf=..., **kw): ... + def peer_names(self): ... + def replace(self, index1, index2, chars, *args): ... + def scan_mark(self, x, y): ... + def scan_dragto(self, x, y): ... + def search(self, pattern, index, stopindex=None, forwards=None, backwards=None, exact=None, regexp=None, nocase=None, count=None, elide=None): ... + def see(self, index): ... + def tag_add(self, tagName, index1, *args): ... + def tag_unbind(self, tagName, sequence, funcid=None): ... + def tag_bind(self, tagName, sequence, func, add=None): ... + def tag_cget(self, tagName, option): ... + def tag_configure(self, tagName, cnf=None, **kw): ... + tag_config = ... # type: Any + def tag_delete(self, *tagNames): ... + def tag_lower(self, tagName, belowThis=None): ... + def tag_names(self, index=None): ... + def tag_nextrange(self, tagName, index1, index2=None): ... + def tag_prevrange(self, tagName, index1, index2=None): ... + def tag_raise(self, tagName, aboveThis=None): ... + def tag_ranges(self, tagName): ... + def tag_remove(self, tagName, index1, index2=None): ... + def window_cget(self, index, option): ... + def window_configure(self, index, cnf=None, **kw): ... + window_config = ... # type: Any + def window_create(self, index, cnf=..., **kw): ... + def window_names(self): ... + def yview_pickplace(self, *what): ... + +class _setit: + def __init__(self, var, value, callback=None): ... + def __call__(self, *args): ... + +class OptionMenu(Menubutton): + widgetName = ... # type: Any + menuname = ... # type: Any + def __init__(self, master, variable, value, *values, **kwargs): ... + def __getitem__(self, name): ... + def destroy(self): ... + +class Image: + name = ... # type: Any + tk = ... # type: Any + def __init__(self, imgtype, name=None, cnf=..., master=None, **kw): ... + def __del__(self): ... + def __setitem__(self, key, value): ... + def __getitem__(self, key): ... + def configure(self, **kw): ... + config = ... # type: Any + def height(self): ... + def type(self): ... + def width(self): ... + +class PhotoImage(Image): + def __init__(self, name=None, cnf=..., master=None, **kw): ... + def blank(self): ... + def cget(self, option): ... + def __getitem__(self, key): ... + def copy(self): ... + def zoom(self, x, y: str = ...): ... + def subsample(self, x, y: str = ...): ... + def get(self, x, y): ... + def put(self, data, to=None): ... + def write(self, filename, format=None, from_coords=None): ... + +class BitmapImage(Image): + def __init__(self, name=None, cnf=..., master=None, **kw): ... + +def image_names(): ... +def image_types(): ... + +class Spinbox(Widget, XView): + def __init__(self, master=None, cnf=..., **kw): ... + def bbox(self, index): ... + def delete(self, first, last=None): ... + def get(self): ... + def icursor(self, index): ... + def identify(self, x, y): ... + def index(self, index): ... + def insert(self, index, s): ... + def invoke(self, element): ... + def scan(self, *args): ... + def scan_mark(self, x): ... + def scan_dragto(self, x): ... + def selection(self, *args): ... + def selection_adjust(self, index): ... + def selection_clear(self): ... + def selection_element(self, element=None): ... + +class LabelFrame(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + +class PanedWindow(Widget): + def __init__(self, master=None, cnf=..., **kw): ... + def add(self, child, **kw): ... + def remove(self, child): ... + forget = ... # type: Any + def identify(self, x, y): ... + def proxy(self, *args): ... + def proxy_coord(self): ... + def proxy_forget(self): ... + def proxy_place(self, x, y): ... + def sash(self, *args): ... + def sash_coord(self, index): ... + def sash_mark(self, index): ... + def sash_place(self, index, x, y): ... + def panecget(self, child, option): ... + def paneconfigure(self, tagOrId, cnf=None, **kw): ... + paneconfig = ... # type: Any + def panes(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/commondialog.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/commondialog.pyi new file mode 100644 index 000000000..d6a8a0d1f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/commondialog.pyi @@ -0,0 +1,8 @@ +from typing import Any, Mapping, Optional + +class Dialog: + command: Optional[Any] = ... + master: Optional[Any] = ... + options: Mapping[str, Any] = ... + def __init__(self, master: Optional[Any] = ..., **options) -> None: ... + def show(self, **options) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/constants.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/constants.pyi new file mode 100644 index 000000000..d613dc628 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/constants.pyi @@ -0,0 +1,79 @@ +from typing import Any + +NO = ... # type: Any +YES = ... # type: Any +TRUE = ... # type: Any +FALSE = ... # type: Any +ON = ... # type: Any +OFF = ... # type: Any +N = ... # type: Any +S = ... # type: Any +W = ... # type: Any +E = ... # type: Any +NW = ... # type: Any +SW = ... # type: Any +NE = ... # type: Any +SE = ... # type: Any +NS = ... # type: Any +EW = ... # type: Any +NSEW = ... # type: Any +CENTER = ... # type: Any +NONE = ... # type: Any +X = ... # type: Any +Y = ... # type: Any +BOTH = ... # type: Any +LEFT = ... # type: Any +TOP = ... # type: Any +RIGHT = ... # type: Any +BOTTOM = ... # type: Any +RAISED = ... # type: Any +SUNKEN = ... # type: Any +FLAT = ... # type: Any +RIDGE = ... # type: Any +GROOVE = ... # type: Any +SOLID = ... # type: Any +HORIZONTAL = ... # type: Any +VERTICAL = ... # type: Any +NUMERIC = ... # type: Any +CHAR = ... # type: Any +WORD = ... # type: Any +BASELINE = ... # type: Any +INSIDE = ... # type: Any +OUTSIDE = ... # type: Any +SEL = ... # type: Any +SEL_FIRST = ... # type: Any +SEL_LAST = ... # type: Any +END = ... # type: Any +INSERT = ... # type: Any +CURRENT = ... # type: Any +ANCHOR = ... # type: Any +ALL = ... # type: Any +NORMAL = ... # type: Any +DISABLED = ... # type: Any +ACTIVE = ... # type: Any +HIDDEN = ... # type: Any +CASCADE = ... # type: Any +CHECKBUTTON = ... # type: Any +COMMAND = ... # type: Any +RADIOBUTTON = ... # type: Any +SEPARATOR = ... # type: Any +SINGLE = ... # type: Any +BROWSE = ... # type: Any +MULTIPLE = ... # type: Any +EXTENDED = ... # type: Any +DOTBOX = ... # type: Any +UNDERLINE = ... # type: Any +PIESLICE = ... # type: Any +CHORD = ... # type: Any +ARC = ... # type: Any +FIRST = ... # type: Any +LAST = ... # type: Any +BUTT = ... # type: Any +PROJECTING = ... # type: Any +ROUND = ... # type: Any +BEVEL = ... # type: Any +MITER = ... # type: Any +MOVETO = ... # type: Any +SCROLL = ... # type: Any +UNITS = ... # type: Any +PAGES = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/dialog.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/dialog.pyi new file mode 100644 index 000000000..3136f21e6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/dialog.pyi @@ -0,0 +1,10 @@ +from typing import Any, Mapping, Optional +from tkinter import Widget + +DIALOG_ICON: str + +class Dialog(Widget): + widgetName: str = ... + num: int = ... + def __init__(self, master: Optional[Any] = ..., cnf: Mapping[str, Any] = ..., **kw) -> None: ... + def destroy(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/filedialog.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/filedialog.pyi new file mode 100644 index 000000000..6d5f16513 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/filedialog.pyi @@ -0,0 +1,65 @@ +from typing import Any, Dict, Optional, Tuple +from tkinter import Button, commondialog, Entry, Frame, Listbox, Scrollbar, Toplevel + +dialogstates: Dict[Any, Tuple[Any, Any]] + +class FileDialog: + title: str = ... + master: Any = ... + directory: Optional[Any] = ... + top: Toplevel = ... + botframe: Frame = ... + selection: Entry = ... + filter: Entry = ... + midframe: Entry = ... + filesbar: Scrollbar = ... + files: Listbox = ... + dirsbar: Scrollbar = ... + dirs: Listbox = ... + ok_button: Button = ... + filter_button: Button = ... + cancel_button: Button = ... + def __init__(self, master, title: Optional[Any] = ...) -> None: ... # title is usually a str or None, but e.g. int doesn't raise en exception either + how: Optional[Any] = ... + def go(self, dir_or_file: Any = ..., pattern: str = ..., default: str = ..., key: Optional[Any] = ...): ... + def quit(self, how: Optional[Any] = ...) -> None: ... + def dirs_double_event(self, event) -> None: ... + def dirs_select_event(self, event) -> None: ... + def files_double_event(self, event) -> None: ... + def files_select_event(self, event) -> None: ... + def ok_event(self, event) -> None: ... + def ok_command(self) -> None: ... + def filter_command(self, event: Optional[Any] = ...) -> None: ... + def get_filter(self): ... + def get_selection(self): ... + def cancel_command(self, event: Optional[Any] = ...) -> None: ... + def set_filter(self, dir, pat) -> None: ... + def set_selection(self, file) -> None: ... + +class LoadFileDialog(FileDialog): + title: str = ... + def ok_command(self) -> None: ... + +class SaveFileDialog(FileDialog): + title: str = ... + def ok_command(self): ... + +class _Dialog(commondialog.Dialog): ... + +class Open(_Dialog): + command: str = ... + +class SaveAs(_Dialog): + command: str = ... + +class Directory(commondialog.Dialog): + command: str = ... + +def askopenfilename(**options): ... +def asksaveasfilename(**options): ... +def askopenfilenames(**options): ... +def askopenfile(mode: str = ..., **options): ... +def askopenfiles(mode: str = ..., **options): ... +def asksaveasfile(mode: str = ..., **options): ... +def askdirectory(**options): ... +def test() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/messagebox.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/messagebox.pyi new file mode 100644 index 000000000..b44e66081 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/messagebox.pyi @@ -0,0 +1,31 @@ +from tkinter.commondialog import Dialog +from typing import Any, Optional + +ERROR: str +INFO: str +QUESTION: str +WARNING: str +ABORTRETRYIGNORE: str +OK: str +OKCANCEL: str +RETRYCANCEL: str +YESNO: str +YESNOCANCEL: str +ABORT: str +RETRY: str +IGNORE: str +CANCEL: str +YES: str +NO: str + +class Message(Dialog): + command: str = ... + +def showinfo(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> str: ... +def showwarning(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> str: ... +def showerror(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> str: ... +def askquestion(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> str: ... +def askokcancel(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> bool: ... +def askyesno(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> bool: ... +def askyesnocancel(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> Optional[bool]: ... +def askretrycancel(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/ttk.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/ttk.pyi new file mode 100644 index 000000000..b8073d0fe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tkinter/ttk.pyi @@ -0,0 +1,160 @@ +import sys +from typing import Any +import tkinter + +def tclobjs_to_py(adict): ... +def setup_master(master=None): ... + +class Style: + master = ... # type: Any + tk = ... # type: Any + def __init__(self, master=None): ... + def configure(self, style, query_opt=None, **kw): ... + def map(self, style, query_opt=None, **kw): ... + def lookup(self, style, option, state=None, default=None): ... + def layout(self, style, layoutspec=None): ... + def element_create(self, elementname, etype, *args, **kw): ... + def element_names(self): ... + def element_options(self, elementname): ... + def theme_create(self, themename, parent=None, settings=None): ... + def theme_settings(self, themename, settings): ... + def theme_names(self): ... + def theme_use(self, themename=None): ... + +class Widget(tkinter.Widget): + def __init__(self, master, widgetname, kw=None): ... + def identify(self, x, y): ... + def instate(self, statespec, callback=None, *args, **kw): ... + def state(self, statespec=None): ... + +class Button(Widget): + def __init__(self, master=None, **kw): ... + def invoke(self): ... + +class Checkbutton(Widget): + def __init__(self, master=None, **kw): ... + def invoke(self): ... + +class Entry(Widget, tkinter.Entry): + def __init__(self, master=None, widget=None, **kw): ... + def bbox(self, index): ... + def identify(self, x, y): ... + def validate(self): ... + +class Combobox(Entry): + def __init__(self, master=None, **kw): ... + def current(self, newindex=None): ... + def set(self, value): ... + +class Frame(Widget): + def __init__(self, master=None, **kw): ... + +class Label(Widget): + def __init__(self, master=None, **kw): ... + +class Labelframe(Widget): + def __init__(self, master=None, **kw): ... + +LabelFrame = ... # type: Any + +class Menubutton(Widget): + def __init__(self, master=None, **kw): ... + +class Notebook(Widget): + def __init__(self, master=None, **kw): ... + def add(self, child, **kw): ... + def forget(self, tab_id): ... + def hide(self, tab_id): ... + def identify(self, x, y): ... + def index(self, tab_id): ... + def insert(self, pos, child, **kw): ... + def select(self, tab_id=None): ... + def tab(self, tab_id, option=None, **kw): ... + def tabs(self): ... + def enable_traversal(self): ... + +class Panedwindow(Widget, tkinter.PanedWindow): + def __init__(self, master=None, **kw): ... + forget = ... # type: Any + def insert(self, pos, child, **kw): ... + def pane(self, pane, option=None, **kw): ... + def sashpos(self, index, newpos=None): ... + +PanedWindow = ... # type: Any + +class Progressbar(Widget): + def __init__(self, master=None, **kw): ... + def start(self, interval=None): ... + def step(self, amount=None): ... + def stop(self): ... + +class Radiobutton(Widget): + def __init__(self, master=None, **kw): ... + def invoke(self): ... + +class Scale(Widget, tkinter.Scale): + def __init__(self, master=None, **kw): ... + def configure(self, cnf=None, **kw): ... + def get(self, x=None, y=None): ... + +class Scrollbar(Widget, tkinter.Scrollbar): + def __init__(self, master=None, **kw): ... + +class Separator(Widget): + def __init__(self, master=None, **kw): ... + +class Sizegrip(Widget): + def __init__(self, master=None, **kw): ... + +if sys.version_info >= (3, 7): + class Spinbox(Entry): + def __init__(self, master: Any = ..., **kw: Any) -> None: ... + def set(self, value: Any) -> None: ... + +class Treeview(Widget, tkinter.XView, tkinter.YView): + def __init__(self, master=None, **kw): ... + def bbox(self, item, column=None): ... + def get_children(self, item=None): ... + def set_children(self, item, *newchildren): ... + def column(self, column, option=None, **kw): ... + def delete(self, *items): ... + def detach(self, *items): ... + def exists(self, item): ... + def focus(self, item=None): ... + def heading(self, column, option=None, **kw): ... + def identify(self, component, x, y): ... + def identify_row(self, y): ... + def identify_column(self, x): ... + def identify_region(self, x, y): ... + def identify_element(self, x, y): ... + def index(self, item): ... + def insert(self, parent, index, iid=None, **kw): ... + def item(self, item, option=None, **kw): ... + def move(self, item, parent, index): ... + reattach = ... # type: Any + def next(self, item): ... + def parent(self, item): ... + def prev(self, item): ... + def see(self, item): ... + def selection(self, selop=None, items=None): ... + def selection_set(self, items): ... + def selection_add(self, items): ... + def selection_remove(self, items): ... + def selection_toggle(self, items): ... + def set(self, item, column=None, value=None): ... + def tag_bind(self, tagname, sequence=None, callback=None): ... + def tag_configure(self, tagname, option=None, **kw): ... + def tag_has(self, tagname, item=None): ... + +class LabeledScale(Frame): + label = ... # type: Any + scale = ... # type: Any + def __init__(self, master=None, variable=None, from_=0, to=10, **kw): ... + def destroy(self): ... + value = ... # type: Any + +class OptionMenu(Menubutton): + def __init__(self, master, variable, default=None, *values, **kwargs): ... + def __getitem__(self, item): ... + def set_menu(self, default=None, *values): ... + def destroy(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tokenize.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tokenize.pyi new file mode 100644 index 000000000..7a17ca2c2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/tokenize.pyi @@ -0,0 +1,114 @@ +from typing import Any, Callable, Generator, Iterable, List, NamedTuple, Optional, Union, Sequence, TextIO, Tuple +from builtins import open as _builtin_open +import sys +from token import * # noqa: F403 + +COMMENT = ... # type: int +NL = ... # type: int +ENCODING = ... # type: int + +_Position = Tuple[int, int] + +_TokenInfo = NamedTuple('TokenInfo', [ + ('type', int), + ('string', str), + ('start', _Position), + ('end', _Position), + ('line', str) +]) + +class TokenInfo(_TokenInfo): + @property + def exact_type(self) -> int: ... + +# Backwards compatible tokens can be sequences of a shorter length too +_Token = Union[TokenInfo, Sequence[Union[int, str, _Position]]] + +class TokenError(Exception): ... +class StopTokenizing(Exception): ... + +class Untokenizer: + tokens = ... # type: List[str] + prev_row = ... # type: int + prev_col = ... # type: int + encoding = ... # type: Optional[str] + def __init__(self) -> None: ... + def add_whitespace(self, start: _Position) -> None: ... + def untokenize(self, iterable: Iterable[_Token]) -> str: ... + def compat(self, token: Sequence[Union[int, str]], iterable: Iterable[_Token]) -> None: ... + +def untokenize(iterable: Iterable[_Token]) -> Any: ... +def detect_encoding(readline: Callable[[], bytes]) -> Tuple[str, Sequence[bytes]]: ... +def tokenize(readline: Callable[[], bytes]) -> Generator[TokenInfo, None, None]: ... +def generate_tokens(readline: Callable[[], str]) -> Generator[TokenInfo, None, None]: ... + +if sys.version_info >= (3, 6): + from os import PathLike + def open(filename: Union[str, bytes, int, PathLike]) -> TextIO: ... +else: + def open(filename: Union[str, bytes, int]) -> TextIO: ... + +# Names in __all__ with no definition: +# AMPER +# AMPEREQUAL +# ASYNC +# AT +# ATEQUAL +# AWAIT +# CIRCUMFLEX +# CIRCUMFLEXEQUAL +# COLON +# COMMA +# DEDENT +# DOT +# DOUBLESLASH +# DOUBLESLASHEQUAL +# DOUBLESTAR +# DOUBLESTAREQUAL +# ELLIPSIS +# ENDMARKER +# EQEQUAL +# EQUAL +# ERRORTOKEN +# GREATER +# GREATEREQUAL +# INDENT +# ISEOF +# ISNONTERMINAL +# ISTERMINAL +# LBRACE +# LEFTSHIFT +# LEFTSHIFTEQUAL +# LESS +# LESSEQUAL +# LPAR +# LSQB +# MINEQUAL +# MINUS +# NAME +# NEWLINE +# NOTEQUAL +# NT_OFFSET +# NUMBER +# N_TOKENS +# OP +# PERCENT +# PERCENTEQUAL +# PLUS +# PLUSEQUAL +# RARROW +# RBRACE +# RIGHTSHIFT +# RIGHTSHIFTEQUAL +# RPAR +# RSQB +# SEMI +# SLASH +# SLASHEQUAL +# STAR +# STAREQUAL +# STRING +# TILDE +# VBAR +# VBAREQUAL +# tok_name diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/types.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/types.pyi new file mode 100644 index 000000000..adc629cbe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/types.pyi @@ -0,0 +1,206 @@ +# Stubs for types +# Note, all classes "defined" here require special handling. + +# TODO parts of this should be conditional on version + +import sys +from typing import ( + Any, Awaitable, Callable, Dict, Generic, Iterator, Mapping, Optional, Tuple, TypeVar, + Union, overload, Type +) + +# ModuleType is exported from this module, but for circular import +# reasons exists in its own stub file (with ModuleSpec and Loader). +from _importlib_modulespec import ModuleType as ModuleType # Exported + +_T = TypeVar('_T') +_T_co = TypeVar('_T_co', covariant=True) +_T_contra = TypeVar('_T_contra', contravariant=True) +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +class _Cell: + cell_contents = ... # type: Any + +class FunctionType: + __closure__ = ... # type: Optional[Tuple[_Cell, ...]] + __code__ = ... # type: CodeType + __defaults__ = ... # type: Optional[Tuple[Any, ...]] + __dict__ = ... # type: Dict[str, Any] + __globals__ = ... # type: Dict[str, Any] + __name__ = ... # type: str + __qualname__ = ... # type: str + __annotations__ = ... # type: Dict[str, Any] + __kwdefaults__ = ... # type: Dict[str, Any] + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __get__(self, obj: Optional[object], type: Optional[type]) -> 'MethodType': ... +LambdaType = FunctionType + +class CodeType: + """Create a code object. Not for the faint of heart.""" + co_argcount = ... # type: int + co_kwonlyargcount = ... # type: int + co_nlocals = ... # type: int + co_stacksize = ... # type: int + co_flags = ... # type: int + co_code = ... # type: bytes + co_consts = ... # type: Tuple[Any, ...] + co_names = ... # type: Tuple[str, ...] + co_varnames = ... # type: Tuple[str, ...] + co_filename = ... # type: Optional[str] + co_name = ... # type: str + co_firstlineno = ... # type: int + co_lnotab = ... # type: bytes + co_freevars = ... # type: Tuple[str, ...] + co_cellvars = ... # type: Tuple[str, ...] + def __init__( + self, + argcount: int, + kwonlyargcount: int, + nlocals: int, + stacksize: int, + flags: int, + codestring: bytes, + constants: Tuple[Any, ...], + names: Tuple[str, ...], + varnames: Tuple[str, ...], + filename: str, + name: str, + firstlineno: int, + lnotab: bytes, + freevars: Tuple[str, ...] = ..., + cellvars: Tuple[str, ...] = ..., + ) -> None: ... + +class MappingProxyType(Mapping[_KT, _VT], Generic[_KT, _VT]): + def __init__(self, mapping: Mapping[_KT, _VT]) -> None: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + +class SimpleNamespace: + def __init__(self, **kwargs: Any) -> None: ... + def __getattribute__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __delattr__(self, name: str) -> None: ... + +class GeneratorType: + gi_code = ... # type: CodeType + gi_frame = ... # type: FrameType + gi_running = ... # type: bool + gi_yieldfrom = ... # type: Optional[GeneratorType] + def __iter__(self) -> 'GeneratorType': ... + def __next__(self) -> Any: ... + def close(self) -> None: ... + def send(self, arg: Any) -> Any: ... + @overload + def throw(self, val: BaseException) -> Any: ... + @overload + def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... + +if sys.version_info >= (3, 6): + class AsyncGeneratorType(Generic[_T_co, _T_contra]): + ag_await: Optional[Awaitable[Any]] + ag_frame: FrameType + ag_running: bool + ag_code: CodeType + def __aiter__(self) -> Awaitable[AsyncGeneratorType[_T_co, _T_contra]]: ... + def __anext__(self) -> Awaitable[_T_co]: ... + def asend(self, val: _T_contra) -> Awaitable[_T_co]: ... + @overload + def athrow(self, val: BaseException) -> Awaitable[_T_co]: ... + @overload + def athrow(self, typ: Type[BaseException], val: BaseException, tb: TracebackType = ...) -> Awaitable[_T_co]: ... + def aclose(self) -> Awaitable[_T_co]: ... + +class CoroutineType: + cr_await = ... # type: Optional[Any] + cr_code = ... # type: CodeType + cr_frame = ... # type: FrameType + cr_running = ... # type: bool + def close(self) -> None: ... + def send(self, arg: Any) -> Any: ... + @overload + def throw(self, val: BaseException) -> Any: ... + @overload + def throw(self, typ: type, val: BaseException = ..., tb: 'TracebackType' = ...) -> Any: ... + +class _StaticFunctionType: + """Fictional type to correct the type of MethodType.__func__. + + FunctionType is a descriptor, so mypy follows the descriptor protocol and + converts MethodType.__func__ back to MethodType (the return type of + FunctionType.__get__). But this is actually a special case; MethodType is + implemented in C and its attribute access doesn't go through + __getattribute__. + + By wrapping FunctionType in _StaticFunctionType, we get the right result; + similar to wrapping a function in staticmethod() at runtime to prevent it + being bound as a method. + """ + def __get__(self, obj: Optional[object], type: Optional[type]) -> 'FunctionType': ... + +class MethodType: + __func__ = ... # type: _StaticFunctionType + __self__ = ... # type: object + __name__ = ... # type: str + __qualname__ = ... # type: str + def __init__(self, func: Callable, obj: object) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +class BuiltinFunctionType: + __self__ = ... # type: Union[object, ModuleType] + __name__ = ... # type: str + __qualname__ = ... # type: str + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... +BuiltinMethodType = BuiltinFunctionType + +class TracebackType: + if sys.version_info >= (3, 7): + def __init__(self, tb_next: Optional[TracebackType], tb_frame: FrameType, tb_lasti: int, tb_lineno: int) -> None: ... + tb_next: Optional[TracebackType] + else: + @property + def tb_next(self) -> Optional[TracebackType]: ... + # the rest are read-only even in 3.7 + @property + def tb_frame(self) -> FrameType: ... + @property + def tb_lasti(self) -> int: ... + @property + def tb_lineno(self) -> int: ... + +class FrameType: + f_back = ... # type: FrameType + f_builtins = ... # type: Dict[str, Any] + f_code = ... # type: CodeType + f_globals = ... # type: Dict[str, Any] + f_lasti = ... # type: int + f_lineno = ... # type: int + f_locals = ... # type: Dict[str, Any] + f_trace = ... # type: Callable[[], None] + if sys.version_info >= (3, 7): + f_frace_lines: bool + f_trace_opcodes: bool + + def clear(self) -> None: ... + +class GetSetDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = ...) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... +class MemberDescriptorType: + __name__ = ... # type: str + __objclass__ = ... # type: type + def __get__(self, obj: Any, type: type = ...) -> Any: ... + def __set__(self, obj: Any) -> None: ... + def __delete__(self, obj: Any) -> None: ... + +def new_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ..., exec_body: Callable[[Dict[str, Any]], None] = ...) -> type: ... +def prepare_class(name: str, bases: Tuple[type, ...] = ..., kwds: Dict[str, Any] = ...) -> Tuple[type, Dict[str, Any], Dict[str, Any]]: ... + +# Actually a different type, but `property` is special and we want that too. +DynamicClassAttribute = property + +def coroutine(f: Callable[..., Any]) -> CoroutineType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/typing.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/typing.pyi new file mode 100644 index 000000000..b40317522 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/typing.pyi @@ -0,0 +1,557 @@ +# Stubs for typing + +import sys +from abc import abstractmethod, ABCMeta +from types import CodeType, FrameType, TracebackType +import collections # Needed by aliases like DefaultDict, see mypy issue 2986 + +# Definitions of special type checking related constructs. Their definition +# are not used, so their value does not matter. + +overload = object() +Any = object() +TypeVar = object() +_promote = object() +no_type_check = object() + +class _SpecialForm: + def __getitem__(self, typeargs: Any) -> Any: ... + +Tuple: _SpecialForm = ... +Generic: _SpecialForm = ... +Protocol: _SpecialForm = ... +Callable: _SpecialForm = ... +Type: _SpecialForm = ... +ClassVar: _SpecialForm = ... + +class GenericMeta(type): ... + +# Return type that indicates a function does not return. +# This type is equivalent to the None type, but the no-op Union is necessary to +# distinguish the None type from the None value. +NoReturn = Union[None] + +# Type aliases and type constructors + +class TypeAlias: + # Class for defining generic aliases for library types. + def __init__(self, target_type: type) -> None: ... + def __getitem__(self, typeargs: Any) -> Any: ... + +Union = TypeAlias(object) +Optional = TypeAlias(object) +List = TypeAlias(object) +Dict = TypeAlias(object) +DefaultDict = TypeAlias(object) +Set = TypeAlias(object) +FrozenSet = TypeAlias(object) +Counter = TypeAlias(object) +Deque = TypeAlias(object) +ChainMap = TypeAlias(object) + +# Predefined type variables. +AnyStr = TypeVar('AnyStr', str, bytes) + +# Abstract base classes. + +# These type variables are used by the container types. +_T = TypeVar('_T') +_S = TypeVar('_S') +_KT = TypeVar('_KT') # Key type. +_VT = TypeVar('_VT') # Value type. +_T_co = TypeVar('_T_co', covariant=True) # Any type covariant containers. +_V_co = TypeVar('_V_co', covariant=True) # Any type covariant containers. +_KT_co = TypeVar('_KT_co', covariant=True) # Key type covariant containers. +_VT_co = TypeVar('_VT_co', covariant=True) # Value type covariant containers. +_T_contra = TypeVar('_T_contra', contravariant=True) # Ditto contravariant. +_TC = TypeVar('_TC', bound=Type[object]) + +def runtime(cls: _TC) -> _TC: ... + +@runtime +class SupportsInt(Protocol, metaclass=ABCMeta): + @abstractmethod + def __int__(self) -> int: ... + +@runtime +class SupportsFloat(Protocol, metaclass=ABCMeta): + @abstractmethod + def __float__(self) -> float: ... + +@runtime +class SupportsComplex(Protocol, metaclass=ABCMeta): + @abstractmethod + def __complex__(self) -> complex: ... + +@runtime +class SupportsBytes(Protocol, metaclass=ABCMeta): + @abstractmethod + def __bytes__(self) -> bytes: ... + +@runtime +class SupportsAbs(Protocol[_T_co]): + @abstractmethod + def __abs__(self) -> _T_co: ... + +@runtime +class SupportsRound(Protocol[_T_co]): + @abstractmethod + def __round__(self, ndigits: int = ...) -> _T_co: ... + +@runtime +class Reversible(Protocol[_T_co]): + @abstractmethod + def __reversed__(self) -> Iterator[_T_co]: ... + +@runtime +class Sized(Protocol, metaclass=ABCMeta): + @abstractmethod + def __len__(self) -> int: ... + +@runtime +class Hashable(Protocol, metaclass=ABCMeta): + # TODO: This is special, in that a subclass of a hashable class may not be hashable + # (for example, list vs. object). It's not obvious how to represent this. This class + # is currently mostly useless for static checking. + @abstractmethod + def __hash__(self) -> int: ... + +@runtime +class Iterable(Protocol[_T_co]): + @abstractmethod + def __iter__(self) -> Iterator[_T_co]: ... + +@runtime +class Iterator(Iterable[_T_co], Protocol[_T_co]): + @abstractmethod + def __next__(self) -> _T_co: ... + def __iter__(self) -> Iterator[_T_co]: ... + +class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): + @abstractmethod + def __next__(self) -> _T_co: ... + + @abstractmethod + def send(self, value: _T_contra) -> _T_co: ... + + @abstractmethod + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., + tb: Optional[TracebackType] = ...) -> _T_co: ... + + @abstractmethod + def close(self) -> None: ... + + @abstractmethod + def __iter__(self) -> Generator[_T_co, _T_contra, _V_co]: ... + + @property + def gi_code(self) -> CodeType: ... + @property + def gi_frame(self) -> FrameType: ... + @property + def gi_running(self) -> bool: ... + @property + def gi_yieldfrom(self) -> Optional[Generator]: ... + +# TODO: Several types should only be defined if sys.python_version >= (3, 5): +# Awaitable, AsyncIterator, AsyncIterable, Coroutine, Collection. +# See https: //github.com/python/typeshed/issues/655 for why this is not easy. + +@runtime +class Awaitable(Protocol[_T_co]): + @abstractmethod + def __await__(self) -> Generator[Any, None, _T_co]: ... + +class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): + @abstractmethod + def send(self, value: _T_contra) -> _T_co: ... + + @abstractmethod + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., + tb: Optional[TracebackType] = ...) -> _T_co: ... + + @abstractmethod + def close(self) -> None: ... + + +# NOTE: This type does not exist in typing.py or PEP 484. +# The parameters corrrespond to Generator, but the 4th is the original type. +class AwaitableGenerator(Awaitable[_V_co], Generator[_T_co, _T_contra, _V_co], + Generic[_T_co, _T_contra, _V_co, _S], metaclass=ABCMeta): ... + +@runtime +class AsyncIterable(Protocol[_T_co]): + @abstractmethod + def __aiter__(self) -> AsyncIterator[_T_co]: ... + +@runtime +class AsyncIterator(AsyncIterable[_T_co], + Protocol[_T_co]): + @abstractmethod + def __anext__(self) -> Awaitable[_T_co]: ... + def __aiter__(self) -> AsyncIterator[_T_co]: ... + +if sys.version_info >= (3, 6): + class AsyncGenerator(AsyncIterator[_T_co], Generic[_T_co, _T_contra]): + @abstractmethod + def __anext__(self) -> Awaitable[_T_co]: ... + + @abstractmethod + def asend(self, value: _T_contra) -> Awaitable[_T_co]: ... + + @abstractmethod + def athrow(self, typ: Type[BaseException], val: Optional[BaseException] = ..., + tb: Any = ...) -> Awaitable[_T_co]: ... + + @abstractmethod + def aclose(self) -> Awaitable[_T_co]: ... + + @abstractmethod + def __aiter__(self) -> AsyncGenerator[_T_co, _T_contra]: ... + + @property + def ag_await(self) -> Any: ... + @property + def ag_code(self) -> CodeType: ... + @property + def ag_frame(self) -> FrameType: ... + @property + def ag_running(self) -> bool: ... + +@runtime +class Container(Protocol[_T_co]): + @abstractmethod + def __contains__(self, x: object) -> bool: ... + + +if sys.version_info >= (3, 6): + @runtime + class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ... + _Collection = Collection +else: + @runtime + class _Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ... + +class Sequence(_Collection[_T_co], Reversible[_T_co], Generic[_T_co]): + @overload + @abstractmethod + def __getitem__(self, i: int) -> _T_co: ... + @overload + @abstractmethod + def __getitem__(self, s: slice) -> Sequence[_T_co]: ... + # Mixin methods + if sys.version_info >= (3, 5): + def index(self, x: Any, start: int = ..., end: int = ...) -> int: ... + else: + def index(self, x: Any) -> int: ... + def count(self, x: Any) -> int: ... + def __contains__(self, x: object) -> bool: ... + def __iter__(self) -> Iterator[_T_co]: ... + def __reversed__(self) -> Iterator[_T_co]: ... + +class MutableSequence(Sequence[_T], Generic[_T]): + @abstractmethod + def insert(self, index: int, object: _T) -> None: ... + @overload + @abstractmethod + def __setitem__(self, i: int, o: _T) -> None: ... + @overload + @abstractmethod + def __setitem__(self, s: slice, o: Iterable[_T]) -> None: ... + @overload + @abstractmethod + def __delitem__(self, i: int) -> None: ... + @overload + @abstractmethod + def __delitem__(self, i: slice) -> None: ... + # Mixin methods + def append(self, object: _T) -> None: ... + def clear(self) -> None: ... + def extend(self, iterable: Iterable[_T]) -> None: ... + def reverse(self) -> None: ... + def pop(self, index: int = ...) -> _T: ... + def remove(self, object: _T) -> None: ... + def __iadd__(self, x: Iterable[_T]) -> MutableSequence[_T]: ... + +class AbstractSet(_Collection[_T_co], Generic[_T_co]): + @abstractmethod + def __contains__(self, x: object) -> bool: ... + # Mixin methods + def __le__(self, s: AbstractSet[Any]) -> bool: ... + def __lt__(self, s: AbstractSet[Any]) -> bool: ... + def __gt__(self, s: AbstractSet[Any]) -> bool: ... + def __ge__(self, s: AbstractSet[Any]) -> bool: ... + def __and__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ... + def __or__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ... + def __sub__(self, s: AbstractSet[Any]) -> AbstractSet[_T_co]: ... + def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ... + # TODO: Argument can be a more general ABC? + def isdisjoint(self, s: AbstractSet[Any]) -> bool: ... + +class MutableSet(AbstractSet[_T], Generic[_T]): + @abstractmethod + def add(self, x: _T) -> None: ... + @abstractmethod + def discard(self, x: _T) -> None: ... + # Mixin methods + def clear(self) -> None: ... + def pop(self) -> _T: ... + def remove(self, element: _T) -> None: ... + def __ior__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ... + def __iand__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ... + def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ... + def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ... + +class MappingView(Sized): + def __len__(self) -> int: ... + +class ItemsView(AbstractSet[Tuple[_KT_co, _VT_co]], MappingView, Generic[_KT_co, _VT_co]): + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ... + +class KeysView(AbstractSet[_KT_co], MappingView, Generic[_KT_co]): + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_KT_co]: ... + +class ValuesView(MappingView, Iterable[_VT_co], Generic[_VT_co]): + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_VT_co]: ... + +@runtime +class ContextManager(Protocol[_T_co]): + def __enter__(self) -> _T_co: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType]) -> Optional[bool]: ... + +if sys.version_info >= (3, 5): + @runtime + class AsyncContextManager(Protocol[_T_co]): + def __aenter__(self) -> Awaitable[_T_co]: ... + def __aexit__(self, exc_type: Optional[Type[BaseException]], + exc_value: Optional[BaseException], + traceback: Optional[TracebackType]) -> Awaitable[Optional[bool]]: ... + +class Mapping(_Collection[_KT], Generic[_KT, _VT_co]): + # TODO: We wish the key type could also be covariant, but that doesn't work, + # see discussion in https: //github.com/python/typing/pull/273. + @abstractmethod + def __getitem__(self, k: _KT) -> _VT_co: + ... + # Mixin methods + @overload + def get(self, k: _KT) -> Optional[_VT_co]: ... + @overload + def get(self, k: _KT, default: Union[_VT_co, _T]) -> Union[_VT_co, _T]: ... + def items(self) -> AbstractSet[Tuple[_KT, _VT_co]]: ... + def keys(self) -> AbstractSet[_KT]: ... + def values(self) -> ValuesView[_VT_co]: ... + def __contains__(self, o: object) -> bool: ... + +class MutableMapping(Mapping[_KT, _VT], Generic[_KT, _VT]): + @abstractmethod + def __setitem__(self, k: _KT, v: _VT) -> None: ... + @abstractmethod + def __delitem__(self, v: _KT) -> None: ... + + def clear(self) -> None: ... + @overload + def pop(self, k: _KT) -> _VT: ... + @overload + def pop(self, k: _KT, default: Union[_VT, _T] = ...) -> Union[_VT, _T]: ... + def popitem(self) -> Tuple[_KT, _VT]: ... + def setdefault(self, k: _KT, default: _VT = ...) -> _VT: ... + # 'update' used to take a Union, but using overloading is better. + # The second overloaded type here is a bit too general, because + # Mapping[Tuple[_KT, _VT], W] is a subclass of Iterable[Tuple[_KT, _VT]], + # but will always have the behavior of the first overloaded type + # at runtime, leading to keys of a mix of types _KT and Tuple[_KT, _VT]. + # We don't currently have any way of forcing all Mappings to use + # the first overload, but by using overloading rather than a Union, + # mypy will commit to using the first overload when the argument is + # known to be a Mapping with unknown type parameters, which is closer + # to the behavior we want. See mypy issue #1430. + @overload + def update(self, __m: Mapping[_KT, _VT], **kwargs: _VT) -> None: ... + @overload + def update(self, __m: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ... + @overload + def update(self, **kwargs: _VT) -> None: ... + +Text = str + +TYPE_CHECKING = True + +class IO(Iterator[AnyStr], Generic[AnyStr]): + # TODO detach + # TODO use abstract properties + @property + def mode(self) -> str: ... + @property + def name(self) -> str: ... + @abstractmethod + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + @abstractmethod + def fileno(self) -> int: ... + @abstractmethod + def flush(self) -> None: ... + @abstractmethod + def isatty(self) -> bool: ... + # TODO what if n is None? + @abstractmethod + def read(self, n: int = ...) -> AnyStr: ... + @abstractmethod + def readable(self) -> bool: ... + @abstractmethod + def readline(self, limit: int = ...) -> AnyStr: ... + @abstractmethod + def readlines(self, hint: int = ...) -> list[AnyStr]: ... + @abstractmethod + def seek(self, offset: int, whence: int = ...) -> int: ... + @abstractmethod + def seekable(self) -> bool: ... + @abstractmethod + def tell(self) -> int: ... + @abstractmethod + def truncate(self, size: Optional[int] = ...) -> int: ... + @abstractmethod + def writable(self) -> bool: ... + # TODO buffer objects + @abstractmethod + def write(self, s: AnyStr) -> int: ... + @abstractmethod + def writelines(self, lines: Iterable[AnyStr]) -> None: ... + + @abstractmethod + def __next__(self) -> AnyStr: ... + @abstractmethod + def __iter__(self) -> Iterator[AnyStr]: ... + @abstractmethod + def __enter__(self) -> IO[AnyStr]: ... + @abstractmethod + def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], + traceback: Optional[TracebackType]) -> bool: ... + +class BinaryIO(IO[bytes]): + # TODO readinto + # TODO read1? + # TODO peek? + @overload + @abstractmethod + def write(self, s: bytearray) -> int: ... + @overload + @abstractmethod + def write(self, s: bytes) -> int: ... + + @abstractmethod + def __enter__(self) -> BinaryIO: ... + +class TextIO(IO[str]): + # TODO use abstractproperty + @property + def buffer(self) -> BinaryIO: ... + @property + def encoding(self) -> str: ... + @property + def errors(self) -> Optional[str]: ... + @property + def line_buffering(self) -> int: ... # int on PyPy, bool on CPython + @property + def newlines(self) -> Any: ... # None, str or tuple + @abstractmethod + def __enter__(self) -> TextIO: ... + +class ByteString(Sequence[int], metaclass=ABCMeta): ... + +class Match(Generic[AnyStr]): + pos = 0 + endpos = 0 + lastindex = 0 + lastgroup = ... # type: AnyStr + string = ... # type: AnyStr + + # The regular expression object whose match() or search() method produced + # this match instance. + re = ... # type: 'Pattern[AnyStr]' + + def expand(self, template: AnyStr) -> AnyStr: ... + + @overload + def group(self, group1: int = ...) -> AnyStr: ... + @overload + def group(self, group1: str) -> AnyStr: ... + @overload + def group(self, group1: int, group2: int, + *groups: int) -> Sequence[AnyStr]: ... + @overload + def group(self, group1: str, group2: str, + *groups: str) -> Sequence[AnyStr]: ... + + def groups(self, default: AnyStr = ...) -> Sequence[AnyStr]: ... + def groupdict(self, default: AnyStr = ...) -> dict[str, AnyStr]: ... + def start(self, group: Union[int, str] = ...) -> int: ... + def end(self, group: Union[int, str] = ...) -> int: ... + def span(self, group: Union[int, str] = ...) -> Tuple[int, int]: ... + if sys.version_info >= (3, 6): + def __getitem__(self, g: Union[int, str]) -> AnyStr: ... + +class Pattern(Generic[AnyStr]): + flags = 0 + groupindex = ... # type: Mapping[str, int] + groups = 0 + pattern = ... # type: AnyStr + + def search(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Optional[Match[AnyStr]]: ... + def match(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Optional[Match[AnyStr]]: ... + # New in Python 3.4 + def fullmatch(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Optional[Match[AnyStr]]: ... + def split(self, string: AnyStr, maxsplit: int = ...) -> list[AnyStr]: ... + def findall(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> list[Any]: ... + def finditer(self, string: AnyStr, pos: int = ..., + endpos: int = ...) -> Iterator[Match[AnyStr]]: ... + + @overload + def sub(self, repl: AnyStr, string: AnyStr, + count: int = ...) -> AnyStr: ... + @overload + def sub(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, + count: int = ...) -> AnyStr: ... + + @overload + def subn(self, repl: AnyStr, string: AnyStr, + count: int = ...) -> Tuple[AnyStr, int]: ... + @overload + def subn(self, repl: Callable[[Match[AnyStr]], AnyStr], string: AnyStr, + count: int = ...) -> Tuple[AnyStr, int]: ... + +# Functions + +def get_type_hints(obj: Callable, globalns: Optional[dict[str, Any]] = ..., + localns: Optional[dict[str, Any]] = ...) -> dict[str, Any]: ... + +def cast(tp: Type[_T], obj: Any) -> _T: ... + +# Type constructors + +# NamedTuple is special-cased in the type checker +class NamedTuple(tuple): + _field_types = ... # type: collections.OrderedDict[str, Type[Any]] + _fields = ... # type: Tuple[str, ...] + _source = ... # type: str + + def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., *, + verbose: bool = ..., rename: bool = ..., **kwargs: Any) -> None: ... + + @classmethod + def _make(cls: Type[_T], iterable: Iterable[Any]) -> _T: ... + + def _asdict(self) -> collections.OrderedDict[str, Any]: ... + def _replace(self: _T, **kwargs: Any) -> _T: ... + +def NewType(name: str, tp: Type[_T]) -> Type[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/unittest/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/unittest/__init__.pyi new file mode 100644 index 000000000..5ef71a243 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/unittest/__init__.pyi @@ -0,0 +1,328 @@ +# Stubs for unittest + +from typing import ( + Any, Callable, Container, ContextManager, Dict, FrozenSet, Generic, Iterable, + Iterator, List, NoReturn, Optional, overload, Pattern, Sequence, Set, TextIO, + Tuple, Type, TypeVar, Union +) +import logging +import sys +from types import ModuleType, TracebackType + + +_T = TypeVar('_T') +_FT = TypeVar('_FT', bound=Callable[..., Any]) +_E = TypeVar('_E', bound=Exception) + + +def expectedFailure(func: _FT) -> _FT: ... +def skip(reason: str) -> Callable[[_FT], _FT]: ... +def skipIf(condition: object, reason: str) -> Callable[[_FT], _FT]: ... +def skipUnless(condition: object, reason: str) -> Callable[[_FT], _FT]: ... + +class SkipTest(Exception): + def __init__(self, reason: str) -> None: ... + + +class TestCase: + failureException = ... # type: Type[BaseException] + longMessage = ... # type: bool + maxDiff = ... # type: Optional[int] + def __init__(self, methodName: str = ...) -> None: ... + def setUp(self) -> None: ... + def tearDown(self) -> None: ... + @classmethod + def setUpClass(cls) -> None: ... + @classmethod + def tearDownClass(cls) -> None: ... + def run(self, result: Optional[TestResult] = ...) -> TestCase: ... + def skipTest(self, reason: Any) -> None: ... + def subTest(self, msg: Any = ..., **params: Any) -> ContextManager[None]: ... + def debug(self) -> None: ... + def assertEqual(self, first: Any, second: Any, msg: Any = ...) -> None: ... + def assertNotEqual(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + def assertTrue(self, expr: Any, msg: Any = ...) -> None: ... + def assertFalse(self, expr: Any, msg: Any = ...) -> None: ... + def assertIs(self, first: Any, second: Any, msg: Any = ...) -> None: ... + def assertIsNot(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + def assertIsNone(self, expr: Any, msg: Any = ...) -> None: ... + def assertIsNotNone(self, expr: Any, msg: Any = ...) -> None: ... + def assertIn(self, member: Any, container: Container[Any], + msg: Any = ...) -> None: ... + def assertNotIn(self, member: Any, container: Container[Any], + msg: Any = ...) -> None: ... + def assertIsInstance(self, obj: Any, + cls: Union[type, Tuple[type, ...]], + msg: Any = ...) -> None: ... + def assertNotIsInstance(self, obj: Any, + cls: Union[type, Tuple[type, ...]], + msg: Any = ...) -> None: ... + def assertGreater(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + def assertGreaterEqual(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + def assertLess(self, first: Any, second: Any, msg: Any = ...) -> None: ... + def assertLessEqual(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + @overload + def assertRaises(self, # type: ignore + exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], + callable: Callable[..., Any], + *args: Any, **kwargs: Any) -> None: ... + @overload + def assertRaises(self, + exception: Union[Type[_E], Tuple[Type[_E], ...]], + msg: Any = ...) -> _AssertRaisesContext[_E]: ... + @overload + def assertRaisesRegex(self, # type: ignore + exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], + callable: Callable[..., Any], + *args: Any, **kwargs: Any) -> None: ... + @overload + def assertRaisesRegex(self, + exception: Union[Type[_E], Tuple[Type[_E], ...]], + msg: Any = ...) -> _AssertRaisesContext[_E]: ... + @overload + def assertWarns(self, # type: ignore + exception: Union[Type[Warning], Tuple[Type[Warning], ...]], + callable: Callable[..., Any], + *args: Any, **kwargs: Any) -> None: ... + @overload + def assertWarns(self, + exception: Union[Type[Warning], Tuple[Type[Warning], ...]], + msg: Any = ...) -> _AssertWarnsContext: ... + @overload + def assertWarnsRegex(self, # type: ignore + exception: Union[Type[Warning], Tuple[Type[Warning], ...]], + callable: Callable[..., Any], + *args: Any, **kwargs: Any) -> None: ... + @overload + def assertWarnsRegex(self, + exception: Union[Type[Warning], Tuple[Type[Warning], ...]], + msg: Any = ...) -> _AssertWarnsContext: ... + def assertLogs( + self, logger: Optional[logging.Logger] = ..., + level: Union[int, str, None] = ... + ) -> _AssertLogsContext: ... + def assertAlmostEqual(self, first: float, second: float, places: int = ..., + msg: Any = ..., delta: float = ...) -> None: ... + def assertNotAlmostEqual(self, first: float, second: float, + places: int = ..., msg: Any = ..., + delta: float = ...) -> None: ... + def assertRegex(self, text: str, regex: Union[str, Pattern[str]], + msg: Any = ...) -> None: ... + def assertNotRegex(self, text: str, regex: Union[str, Pattern[str]], + msg: Any = ...) -> None: ... + def assertCountEqual(self, first: Iterable[Any], second: Iterable[Any], + msg: Any = ...) -> None: ... + def addTypeEqualityFunc(self, typeobj: Type[Any], + function: Callable[..., None]) -> None: ... + def assertMultiLineEqual(self, first: str, second: str, + msg: Any = ...) -> None: ... + def assertSequenceEqual(self, first: Sequence[Any], second: Sequence[Any], + msg: Any = ..., + seq_type: Type[Sequence[Any]] = ...) -> None: ... + def assertListEqual(self, first: List[Any], second: List[Any], + msg: Any = ...) -> None: ... + def assertTupleEqual(self, first: Tuple[Any, ...], second: Tuple[Any, ...], + msg: Any = ...) -> None: ... + def assertSetEqual(self, first: Union[Set[Any], FrozenSet[Any]], + second: Union[Set[Any], FrozenSet[Any]], msg: Any = ...) -> None: ... + def assertDictEqual(self, first: Dict[Any, Any], second: Dict[Any, Any], + msg: Any = ...) -> None: ... + def fail(self, msg: Any = ...) -> NoReturn: ... + def countTestCases(self) -> int: ... + def defaultTestResult(self) -> TestResult: ... + def id(self) -> str: ... + def shortDescription(self) -> Optional[str]: ... + def addCleanup(self, function: Callable[..., Any], *args: Any, + **kwargs: Any) -> None: ... + def doCleanups(self) -> None: ... + # below is deprecated + def failUnlessEqual(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + def assertEquals(self, first: Any, second: Any, msg: Any = ...) -> None: ... + def failIfEqual(self, first: Any, second: Any, msg: Any = ...) -> None: ... + def assertNotEquals(self, first: Any, second: Any, + msg: Any = ...) -> None: ... + def failUnless(self, expr: bool, msg: Any = ...) -> None: ... + def assert_(self, expr: bool, msg: Any = ...) -> None: ... + def failIf(self, expr: bool, msg: Any = ...) -> None: ... + @overload + def failUnlessRaises(self, # type: ignore + exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], + callable: Callable[..., Any] = ..., + *args: Any, **kwargs: Any) -> None: ... + @overload + def failUnlessRaises(self, + exception: Union[Type[_E], Tuple[Type[_E], ...]], + msg: Any = ...) -> _AssertRaisesContext[_E]: ... + def failUnlessAlmostEqual(self, first: float, second: float, + places: int = ..., msg: Any = ...) -> None: ... + def assertAlmostEquals(self, first: float, second: float, places: int = ..., + msg: Any = ..., delta: float = ...) -> None: ... + def failIfAlmostEqual(self, first: float, second: float, places: int = ..., + msg: Any = ...) -> None: ... + def assertNotAlmostEquals(self, first: float, second: float, + places: int = ..., msg: Any = ..., + delta: float = ...) -> None: ... + def assertRegexpMatches(self, text: str, regex: Union[str, Pattern[str]], + msg: Any = ...) -> None: ... + @overload + def assertRaisesRegexp(self, # type: ignore + exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], + callable: Callable[..., Any] = ..., + *args: Any, **kwargs: Any) -> None: ... + @overload + def assertRaisesRegexp(self, + exception: Union[Type[_E], Tuple[Type[_E], ...]], + msg: Any = ...) -> _AssertRaisesContext[_E]: ... + +class FunctionTestCase(TestCase): + def __init__(self, testFunc: Callable[[], None], + setUp: Optional[Callable[[], None]] = ..., + tearDown: Optional[Callable[[], None]] = ..., + description: Optional[str] = ...) -> None: ... + +class _AssertRaisesContext(Generic[_E]): + exception = ... # type: _E + def __enter__(self) -> _AssertRaisesContext[_E]: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + +class _AssertWarnsContext: + warning = ... # type: Warning + filename = ... # type: str + lineno = ... # type: int + def __enter__(self) -> _AssertWarnsContext: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + +class _AssertLogsContext: + records = ... # type: List[logging.LogRecord] + output = ... # type: List[str] + def __enter__(self) -> _AssertLogsContext: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> bool: ... + + +_TestType = Union[TestCase, TestSuite] + +class TestSuite(Iterable[_TestType]): + def __init__(self, tests: Iterable[_TestType] = ...) -> None: ... + def addTest(self, test: _TestType) -> None: ... + def addTests(self, tests: Iterable[_TestType]) -> None: ... + def run(self, result: TestResult) -> TestResult: ... + def debug(self) -> None: ... + def countTestCases(self) -> int: ... + def __iter__(self) -> Iterator[_TestType]: ... + + +class TestLoader: + if sys.version_info >= (3, 5): + errors = ... # type: List[Type[BaseException]] + testMethodPrefix = ... # type: str + sortTestMethodsUsing = ... # type: Callable[[str, str], bool] + suiteClass = ... # type: Callable[[List[TestCase]], TestSuite] + def loadTestsFromTestCase(self, + testCaseClass: Type[TestCase]) -> TestSuite: ... + if sys.version_info >= (3, 5): + def loadTestsFromModule(self, module: ModuleType, + *, pattern: Any = ...) -> TestSuite: ... + else: + def loadTestsFromModule(self, + module: ModuleType) -> TestSuite: ... + def loadTestsFromName(self, name: str, + module: Optional[ModuleType] = ...) -> TestSuite: ... + def loadTestsFromNames(self, names: Sequence[str], + module: Optional[ModuleType] = ...) -> TestSuite: ... + def getTestCaseNames(self, + testCaseClass: Type[TestCase]) -> Sequence[str]: ... + def discover(self, start_dir: str, pattern: str = ..., + top_level_dir: Optional[str] = ...) -> TestSuite: ... + +_SysExcInfoType = Tuple[Optional[Type[BaseException]], + Optional[BaseException], + Optional[TracebackType]] + +class TestResult: + errors = ... # type: List[Tuple[TestCase, str]] + failures = ... # type: List[Tuple[TestCase, str]] + skipped = ... # type: List[Tuple[TestCase, str]] + expectedFailures = ... # type: List[Tuple[TestCase, str]] + unexpectedSuccesses = ... # type: List[TestCase] + shouldStop = ... # type: bool + testsRun = ... # type: int + buffer = ... # type: bool + failfast = ... # type: bool + tb_locals = ... # type: bool + def wasSuccessful(self) -> bool: ... + def stop(self) -> None: ... + def startTest(self, test: TestCase) -> None: ... + def stopTest(self, test: TestCase) -> None: ... + def startTestRun(self) -> None: ... + def stopTestRun(self) -> None: ... + def addError(self, test: TestCase, err: _SysExcInfoType) -> None: ... + def addFailure(self, test: TestCase, err: _SysExcInfoType) -> None: ... + def addSuccess(self, test: TestCase) -> None: ... + def addSkip(self, test: TestCase, reason: str) -> None: ... + def addExpectedFailure(self, test: TestCase, + err: _SysExcInfoType) -> None: ... + def addUnexpectedSuccess(self, test: TestCase) -> None: ... + def addSubTest(self, test: TestCase, subtest: TestCase, + outcome: Optional[_SysExcInfoType]) -> None: ... + +class TextTestResult(TestResult): + def __init__(self, stream: TextIO, descriptions: bool, + verbosity: int) -> None: ... +_TextTestResult = TextTestResult + +defaultTestLoader = ... # type: TestLoader + +_ResultClassType = Callable[[TextIO, bool, int], TestResult] + +class TestRunner: + def run(self, test: Union[TestSuite, TestCase]) -> TestResult: ... + +class TextTestRunner(TestRunner): + if sys.version_info >= (3, 5): + def __init__(self, stream: Optional[TextIO] = ..., + descriptions: bool = ..., verbosity: int = ..., + failfast: bool = ..., buffer: bool = ..., + resultclass: Optional[_ResultClassType] = ..., + warnings: Optional[Type[Warning]] = ..., + *, tb_locals: bool = ...) -> None: ... + else: + def __init__(self, + stream: Optional[TextIO] = ..., + descriptions: bool = ..., verbosity: int = ..., + failfast: bool = ..., buffer: bool = ..., + resultclass: Optional[_ResultClassType] = ..., + warnings: Optional[Type[Warning]] = ...) -> None: ... + def _makeResult(self) -> TestResult: ... + +# not really documented +class TestProgram: + result = ... # type: TestResult + +def main(module: str = ..., + defaultTest: Union[str, Iterable[str], None] = ..., + argv: Optional[List[str]] = ..., + testRunner: Union[Type[TestRunner], TestRunner, None] = ..., + testLoader: TestLoader = ..., exit: bool = ..., verbosity: int = ..., + failfast: Optional[bool] = ..., catchbreak: Optional[bool] = ..., + buffer: Optional[bool] = ..., + warnings: Optional[str] = ...) -> TestProgram: ... + +def load_tests(loader: TestLoader, tests: TestSuite, + pattern: Optional[str]) -> TestSuite: ... + +def installHandler() -> None: ... +def registerResult(result: TestResult) -> None: ... +def removeResult(result: TestResult) -> bool: ... +@overload +def removeHandler() -> None: ... +@overload +def removeHandler(function: _FT) -> _FT: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/unittest/mock.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/unittest/mock.pyi new file mode 100644 index 000000000..259e583e5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/unittest/mock.pyi @@ -0,0 +1,146 @@ +# Stubs for mock + +import sys +from typing import Any, Optional, Text, Type + +FILTER_DIR = ... # type: Any + +class _slotted: ... + +class _SentinelObject: + name = ... # type: Any + def __init__(self, name: Any) -> None: ... + +class _Sentinel: + def __init__(self) -> None: ... + def __getattr__(self, name: str) -> Any: ... + +sentinel = ... # type: Any +DEFAULT = ... # type: Any + +class _CallList(list): + def __contains__(self, value: Any) -> bool: ... + +class _MockIter: + obj = ... # type: Any + def __init__(self, obj: Any) -> None: ... + def __iter__(self) -> Any: ... + def __next__(self) -> Any: ... + +class Base: + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + +# TODO: Defining this and other mock classes as classes in this stub causes +# many false positives with mypy and production code. See if we can +# improve mypy somehow and use a class with an "Any" base class. +NonCallableMock: Any + +class CallableMixin(Base): + side_effect = ... # type: Any + def __init__(self, spec: Optional[Any] = ..., side_effect: Optional[Any] = ..., return_value: Any = ..., wraps: Optional[Any] = ..., name: Optional[Any] = ..., spec_set: Optional[Any] = ..., parent: Optional[Any] = ..., _spec_state: Optional[Any] = ..., _new_name: Any = ..., _new_parent: Optional[Any] = ..., **kwargs: Any) -> None: ... + def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... + +Mock: Any + +class _patch: + attribute_name = ... # type: Any + getter = ... # type: Any + attribute = ... # type: Any + new = ... # type: Any + new_callable = ... # type: Any + spec = ... # type: Any + create = ... # type: bool + has_local = ... # type: Any + spec_set = ... # type: Any + autospec = ... # type: Any + kwargs = ... # type: Any + additional_patchers = ... # type: Any + def __init__(self, getter: Any, attribute: Any, new: Any, spec: Any, create: Any, spec_set: Any, autospec: Any, new_callable: Any, kwargs: Any) -> None: ... + def copy(self) -> Any: ... + def __call__(self, func: Any) -> Any: ... + def decorate_class(self, klass: Any) -> Any: ... + def decorate_callable(self, func: Any) -> Any: ... + def get_original(self) -> Any: ... + target = ... # type: Any + temp_original = ... # type: Any + is_local = ... # type: Any + def __enter__(self) -> Any: ... + def __exit__(self, *exc_info: Any) -> Any: ... + def start(self) -> Any: ... + def stop(self) -> Any: ... + +class _patch_dict: + in_dict = ... # type: Any + values = ... # type: Any + clear = ... # type: Any + def __init__(self, in_dict: Any, values: Any = ..., clear: Any = ..., **kwargs: Any) -> None: ... + def __call__(self, f: Any) -> Any: ... + def decorate_class(self, klass: Any) -> Any: ... + def __enter__(self) -> Any: ... + def __exit__(self, *args: Any) -> Any: ... + start = ... # type: Any + stop = ... # type: Any + +class _patcher: + TEST_PREFIX = ... # type: str + dict = ... # type: Type[_patch_dict] + def __call__(self, target: Any, new: Optional[Any] = ..., spec: Optional[Any] = ..., create: bool = ..., spec_set: Optional[Any] = ..., autospec: Optional[Any] = ..., new_callable: Optional[Any] = ..., **kwargs: Any) -> Any: ... + def object(self, target: Any, attribute: Text, new: Optional[Any] = ..., spec: Optional[Any] = ..., create: bool = ..., spec_set: Optional[Any] = ..., autospec: Optional[Any] = ..., new_callable: Optional[Any] = ..., **kwargs: Any) -> _patch: ... + def multiple(self, target: Any, spec: Optional[Any] = ..., create: bool = ..., spec_set: Optional[Any] = ..., autospec: Optional[Any] = ..., new_callable: Optional[Any] = ..., **kwargs: Any) -> Any: ... + def stopall(self) -> None: ... + +patch = ... # type: _patcher + +class MagicMixin: + def __init__(self, *args: Any, **kw: Any) -> None: ... + +NonCallableMagicMock: Any +MagicMock: Any + +class MagicProxy: + name = ... # type: Any + parent = ... # type: Any + def __init__(self, name: Any, parent: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def create_mock(self) -> Any: ... + def __get__(self, obj: Any, _type: Optional[Any] = ...) -> Any: ... + +class _ANY: + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +ANY = ... # type: Any + +class _Call(tuple): + def __new__(cls, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> Any: ... + name = ... # type: Any + parent = ... # type: Any + from_kall = ... # type: Any + def __init__(self, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> None: ... + def __eq__(self, other: Any) -> bool: ... + __ne__ = ... # type: Any + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __getattr__(self, attr: Any) -> Any: ... + def count(self, *args: Any, **kwargs: Any) -> Any: ... + def index(self, *args: Any, **kwargs: Any) -> Any: ... + def call_list(self) -> Any: ... + +call = ... # type: Any + +def create_autospec(spec: Any, spec_set: Any = ..., instance: Any = ..., _parent: Optional[Any] = ..., _name: Optional[Any] = ..., **kwargs: Any) -> Any: ... + +class _SpecState: + spec = ... # type: Any + ids = ... # type: Any + spec_set = ... # type: Any + parent = ... # type: Any + instance = ... # type: Any + name = ... # type: Any + def __init__(self, spec: Any, spec_set: Any = ..., parent: Optional[Any] = ..., name: Optional[Any] = ..., ids: Optional[Any] = ..., instance: Any = ...) -> None: ... + +def mock_open(mock: Optional[Any] = ..., read_data: Any = ...) -> Any: ... + +PropertyMock: Any + +if sys.version_info >= (3, 7): + def seal(mock: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/error.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/error.pyi new file mode 100644 index 000000000..a29347c19 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/error.pyi @@ -0,0 +1,11 @@ +from typing import Dict, Union +from urllib.response import addinfourl + +# Stubs for urllib.error + +class URLError(IOError): + reason = ... # type: Union[str, BaseException] +class HTTPError(URLError, addinfourl): + code = ... # type: int + headers = ... # type: Dict[str, str] +class ContentTooShortError(URLError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/parse.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/parse.pyi new file mode 100644 index 000000000..c04bf4e98 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/parse.pyi @@ -0,0 +1,147 @@ +# Stubs for urllib.parse +from typing import Any, List, Dict, Tuple, AnyStr, Generic, overload, Sequence, Mapping, Union, NamedTuple, Callable +import sys + +_Str = Union[bytes, str] + + +uses_relative = ... # type: List[str] +uses_netloc = ... # type: List[str] +uses_params = ... # type: List[str] +non_hierarchical = ... # type: List[str] +uses_query = ... # type: List[str] +uses_fragment = ... # type: List[str] +scheme_chars = ... # type: str +MAX_CACHE_SIZE = 0 + +class _ResultMixinBase(Generic[AnyStr]): + def geturl(self) -> AnyStr: ... + +class _ResultMixinStr(_ResultMixinBase[str]): + def encode(self, encoding: str = ..., errors: str = ...) -> '_ResultMixinBytes': ... + + +class _ResultMixinBytes(_ResultMixinBase[str]): + def decode(self, encoding: str = ..., errors: str = ...) -> '_ResultMixinStr': ... + + +class _NetlocResultMixinBase(Generic[AnyStr]): + username = ... # type: AnyStr + password = ... # type: AnyStr + hostname = ... # type: AnyStr + port = ... # type: int + +class _NetlocResultMixinStr(_NetlocResultMixinBase[str], _ResultMixinStr): ... + + +class _NetlocResultMixinBytes(_NetlocResultMixinBase[str], _ResultMixinBytes): ... + +class _DefragResultBase(tuple, Generic[AnyStr]): + url = ... # type: AnyStr + fragment = ... # type: AnyStr + + +_SplitResultBase = NamedTuple( + '_SplitResultBase', + [ + ('scheme', str), ('netloc', str), ('path', str), ('query', str), ('fragment', str) + ] +) +_SplitResultBytesBase = NamedTuple( + '_SplitResultBytesBase', + [ + ('scheme', bytes), ('netloc', bytes), ('path', bytes), ('query', bytes), ('fragment', bytes) + ] +) + +_ParseResultBase = NamedTuple( + '_ParseResultBase', + [ + ('scheme', str), ('netloc', str), ('path', str), ('params', str), ('query', str), ('fragment', str) + ] +) +_ParseResultBytesBase = NamedTuple( + '_ParseResultBytesBase', + [ + ('scheme', bytes), ('netloc', bytes), ('path', bytes), ('params', bytes), ('query', bytes), ('fragment', bytes) + ] +) + +# Structured result objects for string data +class DefragResult(_DefragResultBase[str], _ResultMixinStr): ... + +class SplitResult(_SplitResultBase, _NetlocResultMixinStr): ... + +class ParseResult(_ParseResultBase, _NetlocResultMixinStr): ... + +# Structured result objects for bytes data +class DefragResultBytes(_DefragResultBase[bytes], _ResultMixinBytes): ... + +class SplitResultBytes(_SplitResultBytesBase, _NetlocResultMixinBytes): ... + +class ParseResultBytes(_ParseResultBytesBase, _NetlocResultMixinBytes): ... + + +def parse_qs(qs: AnyStr, keep_blank_values: bool = ..., strict_parsing: bool = ..., encoding: str = ..., errors: str = ...) -> Dict[AnyStr, List[AnyStr]]: ... + +def parse_qsl(qs: AnyStr, keep_blank_values: bool = ..., strict_parsing: bool = ..., encoding: str = ..., errors: str = ...) -> List[Tuple[AnyStr, AnyStr]]: ... + + +@overload +def quote(string: str, safe: _Str = ..., encoding: str = ..., errors: str = ...) -> str: ... +@overload +def quote(string: bytes, safe: _Str = ...) -> str: ... + +def quote_from_bytes(bs: bytes, safe: _Str = ...) -> str: ... + +@overload +def quote_plus(string: str, safe: _Str = ..., encoding: str = ..., errors: str = ...) -> str: ... +@overload +def quote_plus(string: bytes, safe: _Str = ...) -> str: ... + +def unquote(string: str, encoding: str = ..., errors: str = ...) -> str: ... + +def unquote_to_bytes(string: _Str) -> bytes: ... + +def unquote_plus(string: str, encoding: str = ..., errors: str = ...) -> str: ... + +@overload +def urldefrag(url: str) -> DefragResult: ... +@overload +def urldefrag(url: bytes) -> DefragResultBytes: ... + +if sys.version_info >= (3, 5): + def urlencode(query: Union[Mapping[Any, Any], + Mapping[Any, Sequence[Any]], + Sequence[Tuple[Any, Any]], + Sequence[Tuple[Any, Sequence[Any]]]], + doseq: bool = ..., safe: AnyStr = ..., encoding: str = ..., errors: str = ..., + quote_via: Callable[[str, AnyStr, str, str], str] = ...) -> str: ... +else: + def urlencode(query: Union[Mapping[Any, Any], + Mapping[Any, Sequence[Any]], + Sequence[Tuple[Any, Any]], + Sequence[Tuple[Any, Sequence[Any]]]], + doseq: bool = ..., safe: AnyStr = ..., encoding: str = ..., errors: str = ...) -> str: ... + +def urljoin(base: AnyStr, url: AnyStr, allow_fragments: bool = ...) -> AnyStr: ... + +@overload +def urlparse(url: str, scheme: str = ..., allow_fragments: bool = ...) -> ParseResult: ... +@overload +def urlparse(url: bytes, scheme: bytes = ..., allow_fragments: bool = ...) -> ParseResultBytes: ... + +@overload +def urlsplit(url: str, scheme: str = ..., allow_fragments: bool = ...) -> SplitResult: ... +@overload +def urlsplit(url: bytes, scheme: bytes = ..., allow_fragments: bool = ...) -> SplitResultBytes: ... + +@overload +def urlunparse(components: Tuple[AnyStr, AnyStr, AnyStr, AnyStr, AnyStr, AnyStr]) -> AnyStr: ... +@overload +def urlunparse(components: Sequence[AnyStr]) -> AnyStr: ... + +@overload +def urlunsplit(components: Tuple[AnyStr, AnyStr, AnyStr, AnyStr, AnyStr]) -> AnyStr: ... +@overload +def urlunsplit(components: Sequence[AnyStr]) -> AnyStr: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/request.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/request.pyi new file mode 100644 index 000000000..dfedf4773 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/request.pyi @@ -0,0 +1,208 @@ +# Stubs for urllib.request (Python 3.4) + +from typing import ( + Any, Callable, ClassVar, Dict, List, IO, Mapping, Optional, Sequence, Tuple, + TypeVar, Union, overload, +) +from http.client import HTTPResponse, HTTPMessage +from http.cookiejar import CookieJar +from email.message import Message +from urllib.response import addinfourl +import ssl +import sys +import os + +_T = TypeVar('_T') +_UrlopenRet = Union[HTTPResponse, addinfourl] + + +def urlopen( + url: Union[str, 'Request'], data: Optional[bytes] = ..., + timeout: float = ..., *, cafile: Optional[str] = ..., + capath: Optional[str] = ..., cadefault: bool = ..., + context: Optional[ssl.SSLContext] = ... +) -> _UrlopenRet: ... +def install_opener(opener: OpenerDirector) -> None: ... +def build_opener( + *handlers: Union[BaseHandler, Callable[[], BaseHandler]] +) -> OpenerDirector: ... +def url2pathname(path: str) -> str: ... +def pathname2url(path: str) -> str: ... +def getproxies() -> Dict[str, str]: ... +def parse_http_list(s: str) -> List[str]: ... +def parse_keqv_list(l: List[str]) -> Dict[str, str]: ... + +class Request: + @property + def full_url(self) -> str: ... + @full_url.setter + def full_url(self, value: str) -> None: ... + @full_url.deleter + def full_url(self) -> None: ... + type: str + host: str + origin_req_host: str + selector: str + data: Optional[bytes] + headers: Dict[str, str] + unverifiable: bool + method: Optional[str] + def __init__(self, url: str, data: Optional[bytes] = ..., + headers: Dict[str, str] =..., origin_req_host: Optional[str] = ..., + unverifiable: bool = ..., method: Optional[str] = ...) -> None: ... + def get_method(self) -> str: ... + def add_header(self, key: str, val: str) -> None: ... + def add_unredirected_header(self, key: str, val: str) -> None: ... + def has_header(self, header_name: str) -> bool: ... + def remove_header(self, header_name: str) -> None: ... + def get_full_url(self) -> str: ... + def set_proxy(self, host: str, type: str) -> None: ... + @overload + def get_header(self, header_name: str) -> Optional[str]: ... + @overload + def get_header(self, header_name: str, default: _T) -> Union[str, _T]: ... + def header_items(self) -> List[Tuple[str, str]]: ... + +class OpenerDirector: + addheaders: List[Tuple[str, str]] + def add_handler(self, handler: BaseHandler) -> None: ... + def open(self, url: Union[str, Request], data: Optional[bytes] = ..., + timeout: float = ...) -> _UrlopenRet: ... + def error(self, proto: str, *args: Any) -> _UrlopenRet: ... + + +class BaseHandler: + handler_order: ClassVar[int] + parent: OpenerDirector + def add_parent(self, parent: OpenerDirector) -> None: ... + def close(self) -> None: ... + def http_error_nnn(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> _UrlopenRet: ... + +class HTTPDefaultErrorHandler(BaseHandler): ... + +class HTTPRedirectHandler(BaseHandler): + def redirect_request(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str], + newurl: str) -> Optional[Request]: ... + def http_error_301(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + def http_error_302(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + def http_error_303(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + def http_error_307(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + +class HTTPCookieProcessor(BaseHandler): + cookiejar: CookieJar + def __init__(self, cookiejar: Optional[CookieJar] = ...) -> None: ... + +class ProxyHandler(BaseHandler): + def __init__(self, proxies: Optional[Dict[str, str]] = ...) -> None: ... + # TODO add a method for every (common) proxy protocol + +class HTTPPasswordMgr: + def add_password(self, realm: str, uri: Union[str, Sequence[str]], + user: str, passwd: str) -> None: ... + def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ... + +class HTTPPasswordMgrWithDefaultRealm(HTTPPasswordMgr): + def add_password(self, realm: str, uri: Union[str, Sequence[str]], + user: str, passwd: str) -> None: ... + def find_user_password(self, realm: str, authuri: str) -> Tuple[Optional[str], Optional[str]]: ... + +if sys.version_info >= (3, 5): + class HTTPPasswordMgrWithPriorAuth(HTTPPasswordMgrWithDefaultRealm): + def add_password(self, realm: str, uri: Union[str, Sequence[str]], + user: str, passwd: str, + is_authenticated: bool = ...) -> None: ... + def update_authenticated(self, uri: Union[str, Sequence[str]], + is_authenticated: bool = ...) -> None: ... + def is_authenticated(self, authuri: str) -> bool: ... + +class AbstractBasicAuthHandler: + def __init__(self, + password_mgr: Optional[HTTPPasswordMgr] = ...) -> None: ... + def http_error_auth_reqed(self, authreq: str, host: str, req: Request, + headers: Mapping[str, str]) -> None: ... + +class HTTPBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + def http_error_401(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + +class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): + def http_error_407(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + +class AbstractDigestAuthHandler: + def __init__(self, passwd: Optional[HTTPPasswordMgr] = ...) -> None: ... + def reset_retry_count(self) -> None: ... + def http_error_auth_reqed(self, auth_header: str, host: str, req: Request, + headers: Mapping[str, str]) -> None: ... + def retry_http_digest_auth(self, req: Request, auth: str) -> Optional[_UrlopenRet]: ... + def get_cnonce(self, nonce: str) -> str: ... + def get_authorization(self, req: Request, chal: Mapping[str, str]) -> str: ... + def get_algorithm_impls(self, algorithm: str) -> Tuple[Callable[[str], str], Callable[[str, str], str]]: ... + def get_entity_digest(self, data: Optional[bytes], chal: Mapping[str, str]) -> Optional[str]: ... + +class HTTPDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + def http_error_401(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + +class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): + def http_error_407(self, req: Request, fp: IO[str], code: int, msg: int, + hdrs: Mapping[str, str]) -> Optional[_UrlopenRet]: ... + +class HTTPHandler(BaseHandler): + def http_open(self, req: Request) -> _UrlopenRet: ... + +class HTTPSHandler(BaseHandler): + def __init__(self, debuglevel: int = ..., + context: Optional[ssl.SSLContext] = ..., + check_hostname: bool = ...) -> None: ... + def https_open(self, req: Request) -> _UrlopenRet: ... + +class FileHandler(BaseHandler): + def file_open(self, req: Request) -> _UrlopenRet: ... + +class DataHandler(BaseHandler): + def data_open(self, req: Request) -> _UrlopenRet: ... + +class FTPHandler(BaseHandler): + def ftp_open(self, req: Request) -> _UrlopenRet: ... + +class CacheFTPHandler(FTPHandler): + def setTimeout(self, t: float) -> None: ... + def setMaxConns(self, m: int) -> None: ... + +class UnknownHandler(BaseHandler): + def unknown_open(self, req: Request) -> _UrlopenRet: ... + +class HTTPErrorProcessor(BaseHandler): + def http_response(self) -> _UrlopenRet: ... + def https_response(self) -> _UrlopenRet: ... + +if sys.version_info >= (3, 6): + def urlretrieve(url: str, filename: Optional[Union[str, os.PathLike]] = ..., + reporthook: Optional[Callable[[int, int, int], None]] = ..., + data: Optional[bytes] = ...) -> Tuple[str, HTTPMessage]: ... +else: + def urlretrieve(url: str, filename: Optional[str] = ..., + reporthook: Optional[Callable[[int, int, int], None]] = ..., + data: Optional[bytes] = ...) -> Tuple[str, HTTPMessage]: ... +def urlcleanup() -> None: ... + +class URLopener: + version: ClassVar[str] + def __init__(self, proxies: Optional[Dict[str, str]] = ..., + **x509: str) -> None: ... + def open(self, fullurl: str, data: Optional[bytes] = ...) -> _UrlopenRet: ... + def open_unknown(self, fullurl: str, + data: Optional[bytes] = ...) -> _UrlopenRet: ... + def retrieve(self, url: str, filename: Optional[str] = ..., + reporthook: Optional[Callable[[int, int, int], None]] = ..., + data: Optional[bytes] = ...) -> Tuple[str, Optional[Message]]: ... + +class FancyURLopener(URLopener): + def prompt_user_passwd(self, host: str, realm: str) -> Tuple[str, str]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/response.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/response.pyi new file mode 100644 index 000000000..ef3507d7d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/response.pyi @@ -0,0 +1,41 @@ +# private module, we only expose what's needed + +from typing import BinaryIO, Iterable, List, Mapping, Optional, Type, TypeVar +from types import TracebackType + +_AIUT = TypeVar("_AIUT", bound=addbase) + +class addbase(BinaryIO): + def __enter__(self: _AIUT) -> _AIUT: ... + def __exit__(self, type: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> bool: ... + def __iter__(self: _AIUT) -> _AIUT: ... + def __next__(self) -> bytes: ... + def close(self) -> None: ... + # These methods don't actually exist, but the class inherits at runtime from + # tempfile._TemporaryFileWrapper, which uses __getattr__ to delegate to the + # underlying file object. To satisfy the BinaryIO interface, we pretend that this + # class has these additional methods. + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def read(self, n: int = ...) -> bytes: ... + def readable(self) -> bool: ... + def readline(self, limit: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def write(self, s: bytes) -> int: ... + def writelines(self, lines: Iterable[bytes]) -> None: ... + +class addinfo(addbase): + headers: Mapping[str, str] + def info(self) -> Mapping[str, str]: ... + +class addinfourl(addinfo): + url: str + code: int + def geturl(self) -> str: ... + def getcode(self) -> int: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/robotparser.pyi b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/robotparser.pyi new file mode 100644 index 000000000..36150ab01 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/stdlib/3/urllib/robotparser.pyi @@ -0,0 +1,18 @@ +# Stubs for urllib.robotparser (Python 3.4) + +from typing import Iterable, NamedTuple, Optional +import sys + +_RequestRate = NamedTuple('_RequestRate', [('requests', int), ('seconds', int)]) + +class RobotFileParser: + def __init__(self, url: str = ...) -> None: ... + def set_url(self, url: str) -> None: ... + def read(self) -> None: ... + def parse(self, lines: Iterable[str]) -> None: ... + def can_fetch(self, user_agent: str, url: str) -> bool: ... + def mtime(self) -> int: ... + def modified(self) -> None: ... + if sys.version_info >= (3, 6): + def crawl_delay(self, useragent: str) -> Optional[str]: ... + def request_rate(self, useragent: str) -> Optional[_RequestRate]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/OpenSSL/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/OpenSSL/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/OpenSSL/crypto.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/OpenSSL/crypto.pyi new file mode 100644 index 000000000..972a4f816 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/OpenSSL/crypto.pyi @@ -0,0 +1,185 @@ +# Stubs for OpenSSL.crypto (Python 2) + +from typing import Any, Callable, Iterable, List, Optional, Set, Text, Tuple, Union + +from cryptography.hazmat.primitives.asymmetric import dsa, rsa + +FILETYPE_PEM = ... # type: int +FILETYPE_ASN1 = ... # type: int +FILETYPE_TEXT = ... # type: int +TYPE_RSA = ... # type: int +TYPE_DSA = ... # type: int + +class Error(Exception): ... + +class PKey: + def __init__(self) -> None: ... + def to_cryptography_key(self) -> Union[rsa.RSAPublicKey, rsa.RSAPrivateKey, dsa.DSAPublicKey, dsa.DSAPrivateKey]: ... + @classmethod + def from_cryptography_key(cls, crypto_key: Union[rsa.RSAPublicKey, rsa.RSAPrivateKey, dsa.DSAPublicKey, dsa.DSAPrivateKey]): ... + def generate_key(self, type: int, bits: int) -> None: ... + def check(self) -> bool: ... + def type(self) -> int: ... + def bits(self) -> int: ... + +class _EllipticCurve: + name = ... # type: Text + +def get_elliptic_curves() -> Set[_EllipticCurve]: ... +def get_elliptic_curve(name: str) -> _EllipticCurve: ... + +class X509Name: + def __init__(self, name: X509Name) -> None: ... + countryName = ... # type: Union[str, unicode] + stateOrProvinceName = ... # type: Union[str, unicode] + localityName = ... # type: Union[str, unicode] + organizationName = ... # type: Union[str, unicode] + organizationalUnitName = ... # type: Union[str, unicode] + commonName = ... # type: Union[str, unicode] + emailAddress = ... # type: Union[str, unicode] + C = ... # type: Union[str, unicode] + ST = ... # type: Union[str, unicode] + L = ... # type: Union[str, unicode] + O = ... # type: Union[str, unicode] + OU = ... # type: Union[str, unicode] + CN = ... # type: Union[str, unicode] + def hash(self) -> int: ... + def der(self) -> bytes: ... + def get_components(self) -> List[Tuple[str, str]]: ... + +class X509Extension: + def __init__(self, type_name: bytes, critical: bool, value: bytes, subject: Optional[X509] = ..., issuer: Optional[X509] = ...) -> None: ... + def get_critical(self) -> bool: ... + def get_short_name(self) -> str: ... + def get_data(self) -> str: ... + +class X509Req: + def __init__(self) -> None: ... + def set_pubkey(self, pkey: PKey) -> None: ... + def get_pubkey(self) -> PKey: ... + def set_version(self, version: int) -> None: ... + def get_version(self) -> int: ... + def get_subject(self) -> X509Name: ... + def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... + def get_extensions(self) -> List[X509Extension]: ... + def sign(self, pkey: PKey, digest: str) -> None: ... + def verify(self, pkey: PKey) -> bool: ... + +class X509: + def __init__(self) -> None: ... + def set_version(self, version: int) -> None: ... + def get_version(self) -> int: ... + def get_pubkey(self) -> PKey: ... + def set_pubkey(self, pkey: PKey) -> None: ... + def sign(self, pkey: PKey, digest: str) -> None: ... + def get_signature_algorithm(self) -> str: ... + def digest(self, digest_name: str) -> str: ... + def subject_name_hash(self) -> str: ... + def set_serial_number(self, serial: int) -> None: ... + def get_serial_number(self) -> int: ... + def gmtime_adj_notAfter(self, amount: int) -> None: ... + def gmtime_adj_notBefore(self, amount: int) -> None: ... + def has_expired(self) -> bool: ... + def get_notBefore(self) -> str: ... + def set_notBefore(self, when: str) -> None: ... + def get_notAfter(self) -> str: ... + def set_notAfter(self, when: str) -> None: ... + def get_issuer(self) -> X509Name: ... + def set_issuer(self, issuer: X509Name) -> None: ... + def get_subject(self) -> X509Name: ... + def set_subject(self, subject: X509Name) -> None: ... + def get_extension_count(self) -> int: ... + def add_extensions(self, extensions: Iterable[X509Extension]) -> None: ... + def get_extension(self, index: int) -> X509Extension: ... + +class X509StoreFlags: + CRL_CHECK = ... # type: int + CRL_CHECK_ALL = ... # type: int + IGNORE_CRITICAL = ... # type: int + X509_STRICT = ... # type: int + ALLOW_PROXY_CERTS = ... # type: int + POLICY_CHECK = ... # type: int + EXPLICIT_POLICY = ... # type: int + INHIBIT_MAP = ... # type: int + NOTIFY_POLICY = ... # type: int + CHECK_SS_SIGNATURE = ... # type: int + CB_ISSUER_CHECK = ... # type: int + +class X509Store: + def __init__(self) -> None: ... + def add_cert(self, cert: X509) -> None: ... + def add_crl(self, crl: CRL) -> None: ... + def set_flags(self, flags: int) -> None: ... + +class X509StoreContextError(Exception): + certificate = ... # type: X509 + def __init__(self, message: str, certificate: X509) -> None: ... + +class X509StoreContext: + def __init__(self, store: X509Store, certificate: X509) -> None: ... + def set_store(self, store: X509Store) -> None: ... + def verify_certificate(self) -> None: ... + +def load_certificate(type: int, buffer: Union[str, unicode]) -> X509: ... +def dump_certificate(type: int, cert: X509) -> bytes: ... +def dump_publickey(type: int, pkey: PKey) -> bytes: ... +def dump_privatekey(type: int, pkey: PKey, cipher: Optional[str] = ..., passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> bytes: ... + +class Revoked: + def __init__(self) -> None: ... + def set_serial(self, hex_str: str) -> None: ... + def get_serial(self) -> str: ... + def set_reason(self, reason: str) -> None: ... + def get_reason(self) -> str: ... + def all_reasons(self) -> List[str]: ... + def set_rev_date(self, when: str) -> None: ... + def get_rev_date(self) -> str: ... + +class CRL: + def __init__(self) -> None: ... + def get_revoked(self) -> Tuple[Revoked, ...]: ... + def add_revoked(self, revoked: Revoked) -> None: ... + def get_issuer(self) -> X509Name: ... + def set_version(self, version: int) -> None: ... + def set_lastUpdate(self, when: str) -> None: ... + def set_nextUpdate(self, when: str) -> None: ... + def sign(self, issuer_cert: X509, issuer_key: PKey, digest: str) -> None: ... + def export(self, cert: X509, key: PKey, type: int = ..., days: int = ..., digest: str = ...) -> bytes: ... + +class PKCS7: + def type_is_signed(self) -> bool: ... + def type_is_enveloped(self) -> bool: ... + def type_is_signedAndEnveloped(self) -> bool: ... + def type_is_data(self) -> bool: ... + def get_type_name(self) -> str: ... + +class PKCS12: + def __init__(self) -> None: ... + def get_certificate(self) -> X509: ... + def set_certificate(self, cert: X509) -> None: ... + def get_privatekey(self) -> PKey: ... + def set_privatekey(self, pkey: PKey) -> None: ... + def get_ca_certificates(self) -> Tuple[X509, ...]: ... + def set_ca_certificates(self, cacerts: Iterable[X509]) -> None: ... + def set_friendlyname(self, name: bytes) -> None: ... + def get_friendlyname(self) -> bytes: ... + def export(self, passphrase: Optional[str] = ..., iter: int = ..., maciter: int = ...): ... + +class NetscapeSPKI: + def __init__(self) -> None: ... + def sign(self, pkey: PKey, digest: str) -> None: ... + def verify(self, key: PKey) -> bool: ... + def b64_encode(self) -> str: ... + def get_pubkey(self) -> PKey: ... + def set_pubkey(self, pkey: PKey) -> None: ... + +def load_publickey(type: int, buffer: Union[str, unicode]) -> PKey: ... +def load_privatekey(type: int, buffer: bytes, passphrase: Optional[Union[str, Callable[[int], int]]] = ...): ... +def dump_certificate_request(type: int, req: X509Req): ... +def load_certificate_request(type, buffer: Union[str, unicode]) -> X509Req: ... +def sign(pkey: PKey, data: Union[str, unicode], digest: str) -> bytes: ... +def verify(cert: X509, signature: bytes, data: Union[str, unicode], digest: str) -> None: ... +def dump_crl(type: int, crl: CRL) -> bytes: ... +def load_crl(type: int, buffer: Union[str, unicode]) -> CRL: ... +def load_pkcs7_data(type: int, buffer: Union[str, unicode]) -> PKCS7: ... +def load_pkcs12(buffer: Union[str, unicode], passphrase: Optional[Union[str, Callable[[int], int]]] = ...) -> PKCS12: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/__init__.pyi new file mode 100644 index 000000000..4439dcadb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/__init__.pyi @@ -0,0 +1,3 @@ +from ._base import * # noqa: F403 +from .thread import * # noqa: F403 +from .process import * # noqa: F403 diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/_base.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/_base.pyi new file mode 100644 index 000000000..ff38f8689 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/_base.pyi @@ -0,0 +1,54 @@ +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple +from types import TracebackType +import sys + +FIRST_COMPLETED = ... # type: str +FIRST_EXCEPTION = ... # type: str +ALL_COMPLETED = ... # type: str +PENDING = ... # type: Any +RUNNING = ... # type: Any +CANCELLED = ... # type: Any +CANCELLED_AND_NOTIFIED = ... # type: Any +FINISHED = ... # type: Any +LOGGER = ... # type: Any + +class Error(Exception): ... +class CancelledError(Error): ... +class TimeoutError(Error): ... + +_T = TypeVar('_T') + +class Future(Generic[_T]): + def __init__(self) -> None: ... + def cancel(self) -> bool: ... + def cancelled(self) -> bool: ... + def running(self) -> bool: ... + def done(self) -> bool: ... + def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ... + def result(self, timeout: Optional[float] = ...) -> _T: ... + def set_running_or_notify_cancel(self) -> bool: ... + def set_result(self, result: _T) -> None: ... + + if sys.version_info >= (3,): + def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ... + def set_exception(self, exception: Optional[BaseException]) -> None: ... + else: + def exception(self, timeout: Optional[float] = ...) -> Any: ... + def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ... + def set_exception(self, exception: Any) -> None: ... + def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ... + + +class Executor: + def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ... + if sys.version_info >= (3, 5): + def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...) -> Iterator[_T]: ... + else: + def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...,) -> Iterator[_T]: ... + def shutdown(self, wait: bool = ...) -> None: ... + def __enter__(self: _T) -> _T: ... + def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ... + +def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ... + +def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/process.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/process.pyi new file mode 100644 index 000000000..c36180ff8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/process.pyi @@ -0,0 +1,11 @@ +from typing import Optional, Any +from ._base import Future, Executor +import sys + +EXTRA_QUEUED_CALLS = ... # type: Any + +if sys.version_info >= (3,): + class BrokenProcessPool(RuntimeError): ... + +class ProcessPoolExecutor(Executor): + def __init__(self, max_workers: Optional[int] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/thread.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/thread.pyi new file mode 100644 index 000000000..4f5b501b0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/concurrent/futures/thread.pyi @@ -0,0 +1,10 @@ +from typing import Optional +from ._base import Executor, Future +import sys + +class ThreadPoolExecutor(Executor): + if sys.version_info >= (3, 6) or sys.version_info < (3,): + def __init__(self, max_workers: Optional[int] = ..., + thread_name_prefix: str = ...) -> None: ... + else: + def __init__(self, max_workers: Optional[int] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/dsa.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/dsa.pyi new file mode 100644 index 000000000..cfb0c7367 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/dsa.pyi @@ -0,0 +1,4 @@ +# Minimal stub expressing only the classes required by OpenSSL.crypto. + +class DSAPrivateKey: ... +class DSAPublicKey: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi new file mode 100644 index 000000000..57e3bef65 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/asymmetric/rsa.pyi @@ -0,0 +1,4 @@ +# Minimal stub expressing only the classes required by OpenSSL.crypto. + +class RSAPrivateKey: ... +class RSAPublicKey: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/serialization.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/serialization.pyi new file mode 100644 index 000000000..e2c506b0e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/cryptography/hazmat/primitives/serialization.pyi @@ -0,0 +1,28 @@ +from typing import Any +from enum import Enum + +def load_pem_private_key(data, password, backend): ... +def load_pem_public_key(data, backend): ... +def load_der_private_key(data, password, backend): ... +def load_der_public_key(data, backend): ... +def load_ssh_public_key(data, backend): ... + +class Encoding(Enum): + PEM = ... # type: str + DER = ... # type: str + +class PrivateFormat(Enum): + PKCS8 = ... # type: str + TraditionalOpenSSL = ... # type: str + +class PublicFormat(Enum): + SubjectPublicKeyInfo = ... # type: str + PKCS1 = ... # type: str + +class KeySerializationEncryption: ... + +class BestAvailableEncryption: + password = ... # type: Any + def __init__(self, password) -> None: ... + +class NoEncryption: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/enum.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/enum.pyi new file mode 100644 index 000000000..c41677861 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/enum.pyi @@ -0,0 +1,35 @@ +from typing import List, Any, TypeVar, Union, Iterable, Iterator, TypeVar, Generic, Type, Sized, Reversible, Container, Mapping +from abc import ABCMeta + +_T = TypeVar('_T') +_S = TypeVar('_S', bound=Type[Enum]) + +# Note: EnumMeta actually subclasses type directly, not ABCMeta. +# This is a temporary workaround to allow multiple creation of enums with builtins +# such as str as mixins, which due to the handling of ABCs of builtin types, cause +# spurious inconsistent metaclass structure. See #1595. +class EnumMeta(ABCMeta, Iterable[Enum], Sized, Reversible[Enum], Container[Enum]): + def __iter__(self: Type[_T]) -> Iterator[_T]: ... + def __reversed__(self: Type[_T]) -> Iterator[_T]: ... + def __contains__(self, member: Any) -> bool: ... + def __getitem__(self: Type[_T], name: str) -> _T: ... + @property + def __members__(self: Type[_T]) -> Mapping[str, _T]: ... + def __len__(self) -> int: ... + +class Enum(metaclass=EnumMeta): + def __new__(cls: Type[_T], value: Any) -> _T: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __dir__(self) -> List[str]: ... + def __format__(self, format_spec: str) -> str: ... + def __hash__(self) -> Any: ... + def __reduce_ex__(self, proto: Any) -> Any: ... + + name = ... # type: str + value = ... # type: Any + +class IntEnum(int, Enum): + value = ... # type: int + +def unique(enumeration: _S) -> _S: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/fb303/FacebookService.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/fb303/FacebookService.pyi new file mode 100644 index 000000000..2f23924e8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/fb303/FacebookService.pyi @@ -0,0 +1,297 @@ +from typing import Any +from thrift.Thrift import TProcessor # type: ignore + +fastbinary = ... # type: Any + +class Iface: + def getName(self): ... + def getVersion(self): ... + def getStatus(self): ... + def getStatusDetails(self): ... + def getCounters(self): ... + def getCounter(self, key): ... + def setOption(self, key, value): ... + def getOption(self, key): ... + def getOptions(self): ... + def getCpuProfile(self, profileDurationInSec): ... + def aliveSince(self): ... + def reinitialize(self): ... + def shutdown(self): ... + +class Client(Iface): + def __init__(self, iprot, oprot=...) -> None: ... + def getName(self): ... + def send_getName(self): ... + def recv_getName(self): ... + def getVersion(self): ... + def send_getVersion(self): ... + def recv_getVersion(self): ... + def getStatus(self): ... + def send_getStatus(self): ... + def recv_getStatus(self): ... + def getStatusDetails(self): ... + def send_getStatusDetails(self): ... + def recv_getStatusDetails(self): ... + def getCounters(self): ... + def send_getCounters(self): ... + def recv_getCounters(self): ... + def getCounter(self, key): ... + def send_getCounter(self, key): ... + def recv_getCounter(self): ... + def setOption(self, key, value): ... + def send_setOption(self, key, value): ... + def recv_setOption(self): ... + def getOption(self, key): ... + def send_getOption(self, key): ... + def recv_getOption(self): ... + def getOptions(self): ... + def send_getOptions(self): ... + def recv_getOptions(self): ... + def getCpuProfile(self, profileDurationInSec): ... + def send_getCpuProfile(self, profileDurationInSec): ... + def recv_getCpuProfile(self): ... + def aliveSince(self): ... + def send_aliveSince(self): ... + def recv_aliveSince(self): ... + def reinitialize(self): ... + def send_reinitialize(self): ... + def shutdown(self): ... + def send_shutdown(self): ... + +class Processor(Iface, TProcessor): + def __init__(self, handler) -> None: ... + def process(self, iprot, oprot): ... + def process_getName(self, seqid, iprot, oprot): ... + def process_getVersion(self, seqid, iprot, oprot): ... + def process_getStatus(self, seqid, iprot, oprot): ... + def process_getStatusDetails(self, seqid, iprot, oprot): ... + def process_getCounters(self, seqid, iprot, oprot): ... + def process_getCounter(self, seqid, iprot, oprot): ... + def process_setOption(self, seqid, iprot, oprot): ... + def process_getOption(self, seqid, iprot, oprot): ... + def process_getOptions(self, seqid, iprot, oprot): ... + def process_getCpuProfile(self, seqid, iprot, oprot): ... + def process_aliveSince(self, seqid, iprot, oprot): ... + def process_reinitialize(self, seqid, iprot, oprot): ... + def process_shutdown(self, seqid, iprot, oprot): ... + +class getName_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getName_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getVersion_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getVersion_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getStatus_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getStatus_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getStatusDetails_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getStatusDetails_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getCounters_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getCounters_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getCounter_args: + thrift_spec = ... # type: Any + key = ... # type: Any + def __init__(self, key=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getCounter_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class setOption_args: + thrift_spec = ... # type: Any + key = ... # type: Any + value = ... # type: Any + def __init__(self, key=..., value=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class setOption_result: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getOption_args: + thrift_spec = ... # type: Any + key = ... # type: Any + def __init__(self, key=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getOption_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getOptions_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getOptions_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getCpuProfile_args: + thrift_spec = ... # type: Any + profileDurationInSec = ... # type: Any + def __init__(self, profileDurationInSec=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class getCpuProfile_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class aliveSince_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class aliveSince_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class reinitialize_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class shutdown_args: + thrift_spec = ... # type: Any + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/fb303/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/fb303/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/gflags.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/gflags.pyi new file mode 100644 index 000000000..8ffe77964 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/gflags.pyi @@ -0,0 +1,214 @@ +from typing import Any, Callable, Dict, Iterable, IO, List, Optional, Union +from types import ModuleType + +class FlagsError(Exception): ... + +class DuplicateFlag(FlagsError): ... + +class CantOpenFlagFileError(FlagsError): ... + +class DuplicateFlagCannotPropagateNoneToSwig(DuplicateFlag): ... + +class DuplicateFlagError(DuplicateFlag): + def __init__(self, flagname: str, flag_values: FlagValues, other_flag_values: FlagValues = ...) -> None: ... + +class IllegalFlagValue(FlagsError): ... + +class UnrecognizedFlag(FlagsError): ... + +class UnrecognizedFlagError(UnrecognizedFlag): + def __init__(self, flagname: str, flagvalue: str = ...) -> None: ... + +def GetHelpWidth() -> int: ... +def CutCommonSpacePrefix(text) -> str: ... +def TextWrap(text: str, length: int = ..., indent: str = ..., firstline_indent: str = ..., tabs: str = ...) -> str: ... +def DocToHelp(doc: str) -> str: ... + +class FlagValues: + def __init__(self) -> None: ... + def UseGnuGetOpt(self, use_gnu_getopt: bool = ...) -> None: ... + def IsGnuGetOpt(self) -> bool: ... +# TODO dict type + def FlagDict(self) -> dict: ... + def FlagsByModuleDict(self) -> Dict[str, List[Flag]]: ... + def FlagsByModuleIdDict(self) -> Dict[int, List[Flag]]: ... + def KeyFlagsByModuleDict(self) -> Dict[str, List[Flag]]: ... + def FindModuleDefiningFlag(self, flagname: str, default: str = ...) -> str: ... + def FindModuleIdDefiningFlag(self, flagname: str, default: int = ...) -> int: ... + def AppendFlagValues(self, flag_values: FlagValues) -> None: ... + def RemoveFlagValues(self, flag_values: FlagValues) -> None: ... + def __setitem__(self, name: str, flag: Flag) -> None: ... + def __getitem__(self, name: str) -> Flag: ... + def __getattr__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any): ... + def __delattr__(self, flag_name: str) -> None: ... + def SetDefault(self, name: str, value: Any) -> None: ... + def __contains__(self, name: str) -> bool: ... + has_key = __contains__ + def __iter__(self) -> Iterable[str]: ... + def __call__(self, argv: List[str]) -> List[str]: ... + def Reset(self) -> None: ... + def RegisteredFlags(self) -> List[str]: ... + def FlagValuesDict(self) -> Dict[str, Any]: ... + def __str__(self) -> str: ... + def GetHelp(self, prefix: str = ...) -> str: ... + def ModuleHelp(self, module: Union[ModuleType, str]) -> str: ... + def MainModuleHelp(self) -> str: ... + def get(self, name: str, default: Any) -> Any: ... + def ShortestUniquePrefixes(self, fl: Dict[str, Flag]) -> Dict[str, str]: ... + def ExtractFilename(self, flagfile_str: str) -> str: ... + def ReadFlagsFromFiles(self, argv: List[str], force_gnu: bool = ...) -> List[str]: ... + def FlagsIntoString(self) -> str: ... + def AppendFlagsIntoFile(self, filename: str) -> None: ... + def WriteHelpInXMLFormat(self, outfile: IO[str] = ...) -> None: ... +# TODO validator: gflags_validators.Validator + def AddValidator(self, validator: Any) -> None: ... + +FLAGS = ... # type: FlagValues + +class Flag: + name = ... # type: str + default = ... # type: Any + default_as_str = ... # type: str + value = ... # type: Any + help = ... # type: str + short_name = ... # type: str + boolean = False + present = False + parser = ... # type: ArgumentParser + serializer = ... # type: ArgumentSerializer + allow_override = False + + def __init__(self, parser: ArgumentParser, serializer: ArgumentSerializer, name: str, + default: Optional[str], help_string: str, short_name: str = ..., boolean: bool = ..., + allow_override: bool = ...) -> None: ... + def Parse(self, argument: Any) -> Any: ... + def Unparse(self) -> None: ... + def Serialize(self) -> str: ... + def SetDefault(self, value: Any) -> None: ... + def Type(self) -> str: ... + def WriteInfoInXMLFormat(self, outfile: IO[str], module_name: str, is_key: bool = ..., indent: str = ...) -> None: ... + +class ArgumentParser(object): + syntactic_help = ... # type: str +# TODO what is this + def Parse(self, argument: Any) -> Any: ... + def Type(self) -> str: ... + def WriteCustomInfoInXMLFormat(self, outfile: IO[str], indent: str) -> None: ... + +class ArgumentSerializer: + def Serialize(self, value: Any) -> unicode: ... + +class ListSerializer(ArgumentSerializer): + def __init__(self, list_sep: str) -> None: ... + def Serialize(self, value: List[Any]) -> str: ... + +def RegisterValidator(flag_name: str, + checker: Callable[[Any], bool], + message: str = ..., + flag_values: FlagValues = ...) -> None: ... +def MarkFlagAsRequired(flag_name: str, flag_values: FlagValues = ...) -> None: ... + +def DEFINE(parser: ArgumentParser, name: str, default: Any, help: str, + flag_values: FlagValues = ..., serializer: ArgumentSerializer = ..., **args: Any) -> None: ... +def DEFINE_flag(flag: Flag, flag_values: FlagValues = ...) -> None: ... +def DECLARE_key_flag(flag_name: str, flag_values: FlagValues = ...) -> None: ... +def ADOPT_module_key_flags(module: ModuleType, flag_values: FlagValues = ...) -> None: ... +def DEFINE_string(name: str, default: Optional[str], help: str, flag_values: FlagValues = ..., **args: Any): ... + +class BooleanParser(ArgumentParser): + def Convert(self, argument: Any) -> bool: ... + def Parse(self, argument: Any) -> bool: ... + def Type(self) -> str: ... + +class BooleanFlag(Flag): + def __init__(self, name: str, default: Optional[bool], help: str, short_name=..., **args: Any) -> None: ... + +def DEFINE_boolean(name: str, default: Optional[bool], help: str, flag_values: FlagValues = ..., **args: Any) -> None: ... + +DEFINE_bool = DEFINE_boolean + +class HelpFlag(BooleanFlag): + def __init__(self) -> None: ... + def Parse(self, arg: Any) -> None: ... + +class HelpXMLFlag(BooleanFlag): + def __init__(self) -> None: ... + def Parse(self, arg: Any) -> None: ... + +class HelpshortFlag(BooleanFlag): + def __init__(self) -> None: ... + def Parse(self, arg: Any) -> None: ... + +class NumericParser(ArgumentParser): + def IsOutsideBounds(self, val: float) -> bool: ... + def Parse(self, argument: Any) -> float: ... + def WriteCustomInfoInXMLFormat(self, outfile: IO[str], indent: str) -> None: ... + def Convert(self, argument: Any) -> Any: ... + +class FloatParser(NumericParser): + number_article = ... # type: str + number_name = ... # type: str + syntactic_help = ... # type: str + def __init__(self, lower_bound: float = ..., upper_bound: float = ...) -> None: ... + def Convert(self, argument: Any) -> float: ... + def Type(self) -> str: ... + +def DEFINE_float(name: str, default: Optional[float], help: str, lower_bound: float = ..., + upper_bound: float = ..., flag_values: FlagValues = ..., **args: Any) -> None: ... + +class IntegerParser(NumericParser): + number_article = ... # type: str + number_name = ... # type: str + syntactic_help = ... # type: str + def __init__(self, lower_bound: int = ..., upper_bound: int = ...) -> None: ... + def Convert(self, argument: Any) -> int: ... + def Type(self) -> str: ... + +def DEFINE_integer(name: str, default: Optional[int], help: str, lower_bound: int = ..., + upper_bound: int = ..., flag_values: FlagValues = ..., **args: Any) -> None: ... + +class EnumParser(ArgumentParser): + def __init__(self, enum_values: List[str]) -> None: ... + def Parse(self, argument: Any) -> Any: ... + def Type(self) -> str: ... + +class EnumFlag(Flag): + def __init__(self, name: str, default: Optional[str], help: str, enum_values: List[str], + short_name: str, **args: Any) -> None: ... + +def DEFINE_enum(name: str, default: Optional[str], enum_values: List[str], help: str, + flag_values: FlagValues = ..., **args: Any) -> None: ... + +class BaseListParser(ArgumentParser): + def __init__(self, token: str = ..., name: str = ...) -> None: ... + def Parse(self, argument: Any) -> list: ... + def Type(self) -> str: ... + +class ListParser(BaseListParser): + def __init__(self) -> None: ... + def WriteCustomInfoInXMLFormat(self, outfile: IO[str], indent: str): ... + +class WhitespaceSeparatedListParser(BaseListParser): + def __init__(self) -> None: ... + def WriteCustomInfoInXMLFormat(self, outfile: IO[str], indent: str): ... + +def DEFINE_list(name: str, default: Optional[List[str]], help: str, flag_values: FlagValues = ..., **args: Any) -> None: ... +def DEFINE_spaceseplist(name: str, default: Optional[List[str]], help: str, flag_values: FlagValues = ..., **args: Any) -> None: ... + +class MultiFlag(Flag): + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def Parse(self, arguments: Any) -> None: ... + def Serialize(self) -> str: ... + def Type(self) -> str: ... + +def DEFINE_multistring(name: str, default: Optional[Union[str, List[str]]], help: str, + flag_values: FlagValues = ..., **args: Any) -> None: ... + +def DEFINE_multi_int(name: str, default: Optional[Union[int, List[int]]], help: str, lower_bound: int = ..., + upper_bound: int = ..., flag_values: FlagValues = ..., **args: Any) -> None: ... + + +def DEFINE_multi_float(name: str, default: Optional[Union[float, List[float]]], help: str, + lower_bound: float = ..., upper_bound: float = ..., + flag_values: FlagValues = ..., **args: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/itsdangerous.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/itsdangerous.pyi new file mode 100644 index 000000000..8e4acb520 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/itsdangerous.pyi @@ -0,0 +1,150 @@ +from datetime import datetime +from itertools import izip +from typing import Any, Callable, IO, MutableMapping, Optional, Text, Tuple, Union + +PY2 = ... # type: bool +text_type = unicode +int_to_byte = chr +number_types = (int, long, float) +_serializer = Any # must be an object that has "dumps" and "loads" attributes (e.g. the json module) + +bytes_like = Union[bytearray, str] + +class _CompactJSON: + def loads(self, payload: Text) -> Any: ... + def dumps(self, obj: Any) -> Text: ... + +compact_json = _CompactJSON +EPOCH = ... # type: int + +def want_bytes(s: str, encoding: str = ..., errors: str = ...) -> bytes: ... +def is_text_serializer(serializer: Any) -> bool: ... +def constant_time_compare(val1: bytes_like, val2: bytes_like) -> bool: ... + +class BadData(Exception): + message = ... # type: str + def __init__(self, message: str) -> None: ... + +class BadPayload(BadData): + original_error = ... # type: Optional[Exception] + def __init__(self, message: str, original_error: Optional[Exception] = ...) -> None: ... + +class BadSignature(BadData): + payload = ... # type: Optional[Any] + def __init__(self, message: str, payload: Optional[Any] = ...) -> None: ... + +class BadTimeSignature(BadSignature): + date_signed = ... # type: Optional[int] + def __init__(self, message, payload: Optional[Any] = ..., date_signed: Optional[int] = ...) -> None: ... + +class BadHeader(BadSignature): + header = ... # type: Any + original_error = ... # type: Any + def __init__(self, message, payload=None, header=None, original_error=None) -> None: ... + +class SignatureExpired(BadTimeSignature): ... + +def base64_encode(string: bytes_like) -> bytes: ... +def base64_decode(string: bytes_like) -> bytes: ... +def int_to_bytes(num: int) -> bytes: ... +def bytes_to_int(bytestr: bytes_like) -> bytes: ... + +class SigningAlgorithm: + def get_signature(self, key: bytes_like, value: bytes_like) -> bytes: ... + def verify_signature(self, key: bytes_like, value: bytes_like, sig: bytes_like) -> bool: ... + +class NoneAlgorithm(SigningAlgorithm): + def get_signature(self, key: bytes_like, value: bytes_like) -> str: ... + +class HMACAlgorithm(SigningAlgorithm): + default_digest_method = ... # type: Callable + digest_method = ... # type: Callable + def __init__(self, digest_method: Optional[Callable] = ...) -> None: ... + def get_signature(self, key: bytes_like, value: bytes_like) -> bytes: ... + +class Signer: + default_digest_method = ... # type: Callable + default_key_derivation = ... # type: str + secret_key = ... # type: bytes_like + sep = ... # type: str + salt = ... # type: bytes_like + key_derivation = ... # type: str + digest_method = ... # type: Callable + algorithm = ... # type: SigningAlgorithm + def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., sep: Optional[str] = ..., + key_derivation: Optional[str] = ..., + digest_method: Optional[Callable] = ..., + algorithm: Optional[SigningAlgorithm] = ...) -> None: ... + def derive_key(self) -> bytes: ... + def get_signature(self, value: bytes_like) -> bytes: ... + def sign(self, value: bytes_like) -> bytes: ... + def verify_signature(self, value: bytes_like, sig: bytes_like) -> bool: ... + def unsign(self, signed_value: str) -> str: ... + def validate(self, signed_value: str) -> bool: ... + +class TimestampSigner(Signer): + def get_timestamp(self) -> int: ... + def timestamp_to_datetime(self, ts: int) -> datetime: ... + def sign(self, value: bytes_like) -> bytes: ... + def unsign(self, value: str, max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ... + def validate(self, signed_value: str, max_age: Optional[int] = ...) -> bool: ... + +class Serializer: + default_serializer = ... # type: _serializer + default_signer = ... # type: Callable[..., Signer] + secret_key = ... # type: Any + salt = ... # type: bytes_like + serializer = ... # type: _serializer + is_text_serializer = ... # type: bool + signer = ... # type: Signer + signer_kwargs = ... # type: MutableMapping + def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ... + def load_payload(self, payload: Any, serializer: Optional[_serializer] = ...) -> Any: ... + def dump_payload(self, *args, **kwargs) -> str: ... + def make_signer(self, salt: Optional[bytes_like] = ...) -> Signer: ... + def dumps(self, obj: Any, salt: Optional[bytes_like] = ...) -> str: ... + def dump(self, obj: Any, f: IO[str], salt: Optional[bytes_like] = ...) -> None: ... + def loads(self, s: str, salt: Optional[bytes_like] = ...) -> Any: ... + def load(self, f: IO[str], salt: Optional[bytes_like] = ...): ... + def loads_unsafe(self, s, salt: Optional[bytes_like] = ...) -> Tuple[bool, Any]: ... + def load_unsafe(self, f: IO[str], *args, **kwargs) -> Tuple[bool, Any]: ... + +class TimedSerializer(Serializer): + default_signer = ... # type: Callable[..., TimestampSigner] + def loads(self, s: str, salt: Optional[bytes_like] = ..., max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ... + def loads_unsafe(self, s: str, salt: Optional[bytes_like] = ..., max_age: Optional[int] = ...) -> Tuple[bool, Any]: ... + +class JSONWebSignatureSerializer(Serializer): + jws_algorithms = ... # type: MutableMapping[str, SigningAlgorithm] + default_algorithm = ... # type: str + default_serializer = ... # type: Any + algorithm_name = ... # type: str + algorithm = ... # type: Any + def __init__(self, secret_key: bytes_like, salt: Optional[bytes_like] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ... + def load_payload(self, payload: Any, serializer: Optional[_serializer] = ..., return_header: bool = ...) -> Any: ... + def dump_payload(self, *args, **kwargs) -> bytes: ... + def make_algorithm(self, algorithm_name: str) -> SigningAlgorithm: ... + def make_signer(self, salt: Optional[bytes_like] = ..., algorithm_name: Optional[str] = ...) -> Signer: ... + def make_header(self, header_fields: Optional[MutableMapping] = ...) -> MutableMapping: ... + def dumps(self, obj: Any, salt: Optional[bytes_like] = ..., header_fields: Optional[MutableMapping] = ...) -> str: ... + def loads(self, s: str, salt: Optional[bytes_like] = ..., return_header: bool = ...) -> Any: ... + def loads_unsafe(self, s, salt: Optional[bytes_like] = ..., return_header: bool = ...) -> Tuple[bool, Any]: ... + +class TimedJSONWebSignatureSerializer(JSONWebSignatureSerializer): + DEFAULT_EXPIRES_IN = ... # type: int + expires_in = ... # type: int + def __init__(self, secret_key: bytes_like, expires_in: Optional[int] = ..., **kwargs) -> None: ... + def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ... + def loads(self, s: str, salt: Optional[bytes_like] = ..., return_header: bool = ...) -> Any: ... + def get_issue_date(self, header: MutableMapping) -> Optional[datetime]: ... + def now(self) -> int: ... + +class URLSafeSerializerMixin: + def load_payload(self, payload: Any, serializer=None, return_header=False, **kwargs) -> Any: ... # FIXME: This is invalid but works around https://github.com/pallets/itsdangerous/issues/74 + def dump_payload(self, *args, **kwargs) -> str: ... + +class URLSafeSerializer(URLSafeSerializerMixin, Serializer): + default_serializer = ... # type: Any + +class URLSafeTimedSerializer(URLSafeSerializerMixin, TimedSerializer): + default_serializer = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/client.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/client.pyi new file mode 100644 index 000000000..3fd79a388 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/client.pyi @@ -0,0 +1,96 @@ +from typing import Any + +string_types = ... # type: Any +bytes_types = ... # type: Any +LOST_STATES = ... # type: Any +ENVI_VERSION = ... # type: Any +ENVI_VERSION_KEY = ... # type: Any +log = ... # type: Any + +class KazooClient: + logger = ... # type: Any + handler = ... # type: Any + auth_data = ... # type: Any + default_acl = ... # type: Any + randomize_hosts = ... # type: Any + hosts = ... # type: Any + chroot = ... # type: Any + state = ... # type: Any + state_listeners = ... # type: Any + read_only = ... # type: Any + retry = ... # type: Any + Barrier = ... # type: Any + Counter = ... # type: Any + DoubleBarrier = ... # type: Any + ChildrenWatch = ... # type: Any + DataWatch = ... # type: Any + Election = ... # type: Any + NonBlockingLease = ... # type: Any + MultiNonBlockingLease = ... # type: Any + Lock = ... # type: Any + Party = ... # type: Any + Queue = ... # type: Any + LockingQueue = ... # type: Any + SetPartitioner = ... # type: Any + Semaphore = ... # type: Any + ShallowParty = ... # type: Any + def __init__(self, hosts=..., timeout=..., client_id=..., handler=..., default_acl=..., auth_data=..., read_only=..., randomize_hosts=..., connection_retry=..., command_retry=..., logger=..., **kwargs) -> None: ... + @property + def client_state(self): ... + @property + def client_id(self): ... + @property + def connected(self): ... + def set_hosts(self, hosts, randomize_hosts=...): ... + def add_listener(self, listener): ... + def remove_listener(self, listener): ... + def start(self, timeout=...): ... + def start_async(self): ... + def stop(self): ... + def restart(self): ... + def close(self): ... + def command(self, cmd=...): ... + def server_version(self, retries=...): ... + def add_auth(self, scheme, credential): ... + def add_auth_async(self, scheme, credential): ... + def unchroot(self, path): ... + def sync_async(self, path): ... + def sync(self, path): ... + def create(self, path, value=..., acl=..., ephemeral=..., sequence=..., makepath=...): ... + def create_async(self, path, value=..., acl=..., ephemeral=..., sequence=..., makepath=...): ... + def ensure_path(self, path, acl=...): ... + def ensure_path_async(self, path, acl=...): ... + def exists(self, path, watch=...): ... + def exists_async(self, path, watch=...): ... + def get(self, path, watch=...): ... + def get_async(self, path, watch=...): ... + def get_children(self, path, watch=..., include_data=...): ... + def get_children_async(self, path, watch=..., include_data=...): ... + def get_acls(self, path): ... + def get_acls_async(self, path): ... + def set_acls(self, path, acls, version=...): ... + def set_acls_async(self, path, acls, version=...): ... + def set(self, path, value, version=...): ... + def set_async(self, path, value, version=...): ... + def transaction(self): ... + def delete(self, path, version=..., recursive=...): ... + def delete_async(self, path, version=...): ... + def reconfig(self, joining, leaving, new_members, from_config=...): ... + def reconfig_async(self, joining, leaving, new_members, from_config): ... + +class TransactionRequest: + client = ... # type: Any + operations = ... # type: Any + committed = ... # type: Any + def __init__(self, client) -> None: ... + def create(self, path, value=..., acl=..., ephemeral=..., sequence=...): ... + def delete(self, path, version=...): ... + def set_data(self, path, value, version=...): ... + def check(self, path, version): ... + def commit_async(self): ... + def commit(self): ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, exc_tb): ... + +class KazooState: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/exceptions.pyi new file mode 100644 index 000000000..dcec322a3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/exceptions.pyi @@ -0,0 +1,58 @@ +from typing import Any + +class KazooException(Exception): ... +class ZookeeperError(KazooException): ... +class CancelledError(KazooException): ... +class ConfigurationError(KazooException): ... +class ZookeeperStoppedError(KazooException): ... +class ConnectionDropped(KazooException): ... +class LockTimeout(KazooException): ... +class WriterNotClosedException(KazooException): ... + +EXCEPTIONS = ... # type: Any + +class RolledBackError(ZookeeperError): ... +class SystemZookeeperError(ZookeeperError): ... +class RuntimeInconsistency(ZookeeperError): ... +class DataInconsistency(ZookeeperError): ... +class ConnectionLoss(ZookeeperError): ... +class MarshallingError(ZookeeperError): ... +class UnimplementedError(ZookeeperError): ... +class OperationTimeoutError(ZookeeperError): ... +class BadArgumentsError(ZookeeperError): ... +class NewConfigNoQuorumError(ZookeeperError): ... +class ReconfigInProcessError(ZookeeperError): ... +class APIError(ZookeeperError): ... +class NoNodeError(ZookeeperError): ... +class NoAuthError(ZookeeperError): ... +class BadVersionError(ZookeeperError): ... +class NoChildrenForEphemeralsError(ZookeeperError): ... +class NodeExistsError(ZookeeperError): ... +class NotEmptyError(ZookeeperError): ... +class SessionExpiredError(ZookeeperError): ... +class InvalidCallbackError(ZookeeperError): ... +class InvalidACLError(ZookeeperError): ... +class AuthFailedError(ZookeeperError): ... +class SessionMovedError(ZookeeperError): ... +class NotReadOnlyCallError(ZookeeperError): ... +class ConnectionClosedError(SessionExpiredError): ... + +ConnectionLossException = ... # type: Any +MarshallingErrorException = ... # type: Any +SystemErrorException = ... # type: Any +RuntimeInconsistencyException = ... # type: Any +DataInconsistencyException = ... # type: Any +UnimplementedException = ... # type: Any +OperationTimeoutException = ... # type: Any +BadArgumentsException = ... # type: Any +ApiErrorException = ... # type: Any +NoNodeException = ... # type: Any +NoAuthException = ... # type: Any +BadVersionException = ... # type: Any +NoChildrenForEphemeralsException = ... # type: Any +NodeExistsException = ... # type: Any +InvalidACLException = ... # type: Any +AuthFailedException = ... # type: Any +NotEmptyException = ... # type: Any +SessionExpiredException = ... # type: Any +InvalidCallbackException = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/recipe/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/recipe/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/recipe/watchers.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/recipe/watchers.pyi new file mode 100644 index 000000000..545f5018c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/kazoo/recipe/watchers.pyi @@ -0,0 +1,21 @@ +from typing import Any + +log = ... # type: Any + +class DataWatch: + def __init__(self, client, path, func=..., *args, **kwargs) -> None: ... + def __call__(self, func): ... + +class ChildrenWatch: + def __init__(self, client, path, func=..., allow_session_lost=..., send_event=...) -> None: ... + def __call__(self, func): ... + +class PatientChildrenWatch: + client = ... # type: Any + path = ... # type: Any + children = ... # type: Any + time_boundary = ... # type: Any + children_changed = ... # type: Any + def __init__(self, client, path, time_boundary=...) -> None: ... + asy = ... # type: Any + def start(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/pycurl.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/pycurl.pyi new file mode 100644 index 000000000..84ca57cea --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/pycurl.pyi @@ -0,0 +1,605 @@ +# TODO(MichalPokorny): more precise types + +from typing import Any, Tuple + +GLOBAL_ACK_EINTR = ... # type: int +GLOBAL_ALL = ... # type: int +GLOBAL_DEFAULT = ... # type: int +GLOBAL_NOTHING = ... # type: int +GLOBAL_SSL = ... # type: int +GLOBAL_WIN32 = ... # type: int + +def global_init(option: int) -> None: ... +def global_cleanup() -> None: ... + +version = ... # type: str + +def version_info() -> Tuple[int, str, int, str, int, str, + int, str, tuple, Any, int, Any]: ... + +class error(Exception): ... + +class Curl(object): + def close(self) -> None: ... + def setopt(self, option: int, value: Any) -> None: ... + def perform(self) -> None: ... + def getinfo(self, info: Any) -> Any: ... + def reset(self) -> None: ... + def unsetopt(self, option: int) -> Any: ... + def pause(self, bitmask: Any) -> Any: ... + def errstr(self) -> str: ... + + # TODO(MichalPokorny): wat? + USERPWD = ... # type: int + +class CurlMulti(object): + def close(self) -> None: ... + def add_handle(self, obj: Curl) -> None: ... + def remove_handle(self, obj: Curl) -> None: ... + def perform(self) -> Tuple[Any, int]: ... + def fdset(self) -> tuple: ... + def select(self, timeout: float = ...) -> int: ... + def info_read(self, max_objects: int = ...) -> tuple: ... + +class CurlShare(object): + def close(self) -> None: ... + def setopt(self, option: int, value: Any) -> Any: ... + +ACCEPTTIMEOUT_MS = ... # type: int +ACCEPT_ENCODING = ... # type: int +ADDRESS_SCOPE = ... # type: int +APPCONNECT_TIME = ... # type: int +APPEND = ... # type: int +AUTOREFERER = ... # type: int +BUFFERSIZE = ... # type: int +CAINFO = ... # type: int +CAPATH = ... # type: int +CLOSESOCKETFUNCTION = ... # type: int +COMPILE_DATE = ... # type: str +COMPILE_LIBCURL_VERSION_NUM = ... # type: int +COMPILE_PY_VERSION_HEX = ... # type: int +CONDITION_UNMET = ... # type: int +CONNECTTIMEOUT = ... # type: int +CONNECTTIMEOUT_MS = ... # type: int +CONNECT_ONLY = ... # type: int +CONNECT_TIME = ... # type: int +CONTENT_LENGTH_DOWNLOAD = ... # type: int +CONTENT_LENGTH_UPLOAD = ... # type: int +CONTENT_TYPE = ... # type: int +COOKIE = ... # type: int +COOKIEFILE = ... # type: int +COOKIEJAR = ... # type: int +COOKIELIST = ... # type: int +COOKIESESSION = ... # type: int +COPYPOSTFIELDS = ... # type: int +CRLF = ... # type: int +CRLFILE = ... # type: int +CSELECT_ERR = ... # type: int +CSELECT_IN = ... # type: int +CSELECT_OUT = ... # type: int +CURL_HTTP_VERSION_1_0 = ... # type: int +CURL_HTTP_VERSION_1_1 = ... # type: int +CURL_HTTP_VERSION_2 = ... # type: int +CURL_HTTP_VERSION_2_0 = ... # type: int +CURL_HTTP_VERSION_LAST = ... # type: int +CURL_HTTP_VERSION_NONE = ... # type: int +CUSTOMREQUEST = ... # type: int +DEBUGFUNCTION = ... # type: int +DIRLISTONLY = ... # type: int +DNS_CACHE_TIMEOUT = ... # type: int +DNS_SERVERS = ... # type: int +DNS_USE_GLOBAL_CACHE = ... # type: int +EFFECTIVE_URL = ... # type: int +EGDSOCKET = ... # type: int +ENCODING = ... # type: int +EXPECT_100_TIMEOUT_MS = ... # type: int +FAILONERROR = ... # type: int +FILE = ... # type: int +FOLLOWLOCATION = ... # type: int +FORBID_REUSE = ... # type: int +FORM_BUFFER = ... # type: int +FORM_BUFFERPTR = ... # type: int +FORM_CONTENTS = ... # type: int +FORM_CONTENTTYPE = ... # type: int +FORM_FILE = ... # type: int +FORM_FILENAME = ... # type: int +FRESH_CONNECT = ... # type: int +FTPAPPEND = ... # type: int +FTPAUTH_DEFAULT = ... # type: int +FTPAUTH_SSL = ... # type: int +FTPAUTH_TLS = ... # type: int +FTPLISTONLY = ... # type: int +FTPMETHOD_DEFAULT = ... # type: int +FTPMETHOD_MULTICWD = ... # type: int +FTPMETHOD_NOCWD = ... # type: int +FTPMETHOD_SINGLECWD = ... # type: int +FTPPORT = ... # type: int +FTPSSLAUTH = ... # type: int +FTPSSL_ALL = ... # type: int +FTPSSL_CONTROL = ... # type: int +FTPSSL_NONE = ... # type: int +FTPSSL_TRY = ... # type: int +FTP_ACCOUNT = ... # type: int +FTP_ALTERNATIVE_TO_USER = ... # type: int +FTP_CREATE_MISSING_DIRS = ... # type: int +FTP_ENTRY_PATH = ... # type: int +FTP_FILEMETHOD = ... # type: int +FTP_RESPONSE_TIMEOUT = ... # type: int +FTP_SKIP_PASV_IP = ... # type: int +FTP_SSL = ... # type: int +FTP_SSL_CCC = ... # type: int +FTP_USE_EPRT = ... # type: int +FTP_USE_EPSV = ... # type: int +FTP_USE_PRET = ... # type: int +GSSAPI_DELEGATION = ... # type: int +GSSAPI_DELEGATION_FLAG = ... # type: int +GSSAPI_DELEGATION_NONE = ... # type: int +GSSAPI_DELEGATION_POLICY_FLAG = ... # type: int +HEADER = ... # type: int +HEADERFUNCTION = ... # type: int +HEADEROPT = ... # type: int +HEADER_SEPARATE = ... # type: int +HEADER_SIZE = ... # type: int +HEADER_UNIFIED = ... # type: int +HTTP200ALIASES = ... # type: int +HTTPAUTH = ... # type: int +HTTPAUTH_ANY = ... # type: int +HTTPAUTH_ANYSAFE = ... # type: int +HTTPAUTH_AVAIL = ... # type: int +HTTPAUTH_BASIC = ... # type: int +HTTPAUTH_DIGEST = ... # type: int +HTTPAUTH_DIGEST_IE = ... # type: int +HTTPAUTH_GSSNEGOTIATE = ... # type: int +HTTPAUTH_NEGOTIATE = ... # type: int +HTTPAUTH_NONE = ... # type: int +HTTPAUTH_NTLM = ... # type: int +HTTPAUTH_NTLM_WB = ... # type: int +HTTPAUTH_ONLY = ... # type: int +HTTPGET = ... # type: int +HTTPHEADER = ... # type: int +HTTPPOST = ... # type: int +HTTPPROXYTUNNEL = ... # type: int +HTTP_CODE = ... # type: int +HTTP_CONNECTCODE = ... # type: int +HTTP_CONTENT_DECODING = ... # type: int +HTTP_TRANSFER_DECODING = ... # type: int +HTTP_VERSION = ... # type: int +IGNORE_CONTENT_LENGTH = ... # type: int +INFILE = ... # type: int +INFILESIZE = ... # type: int +INFILESIZE_LARGE = ... # type: int +INFOTYPE_DATA_IN = ... # type: int +INFOTYPE_DATA_OUT = ... # type: int +INFOTYPE_HEADER_IN = ... # type: int +INFOTYPE_HEADER_OUT = ... # type: int +INFOTYPE_SSL_DATA_IN = ... # type: int +INFOTYPE_SSL_DATA_OUT = ... # type: int +INFOTYPE_TEXT = ... # type: int +INFO_CERTINFO = ... # type: int +INFO_COOKIELIST = ... # type: int +INFO_FILETIME = ... # type: int +INFO_RTSP_CLIENT_CSEQ = ... # type: int +INFO_RTSP_CSEQ_RECV = ... # type: int +INFO_RTSP_SERVER_CSEQ = ... # type: int +INFO_RTSP_SESSION_ID = ... # type: int +INTERFACE = ... # type: int +IOCMD_NOP = ... # type: int +IOCMD_RESTARTREAD = ... # type: int +IOCTLDATA = ... # type: int +IOCTLFUNCTION = ... # type: int +IOE_FAILRESTART = ... # type: int +IOE_OK = ... # type: int +IOE_UNKNOWNCMD = ... # type: int +IPRESOLVE = ... # type: int +IPRESOLVE_V4 = ... # type: int +IPRESOLVE_V6 = ... # type: int +IPRESOLVE_WHATEVER = ... # type: int +ISSUERCERT = ... # type: int +KEYPASSWD = ... # type: int +KHMATCH_MISMATCH = ... # type: int +KHMATCH_MISSING = ... # type: int +KHMATCH_OK = ... # type: int +KHSTAT_DEFER = ... # type: int +KHSTAT_FINE = ... # type: int +KHSTAT_FINE_ADD_TO_FILE = ... # type: int +KHSTAT_REJECT = ... # type: int +KHTYPE_DSS = ... # type: int +KHTYPE_RSA = ... # type: int +KHTYPE_RSA1 = ... # type: int +KHTYPE_UNKNOWN = ... # type: int +KRB4LEVEL = ... # type: int +KRBLEVEL = ... # type: int +LASTSOCKET = ... # type: int +LOCALPORT = ... # type: int +LOCALPORTRANGE = ... # type: int +LOCAL_IP = ... # type: int +LOCAL_PORT = ... # type: int +LOCK_DATA_COOKIE = ... # type: int +LOCK_DATA_DNS = ... # type: int +LOCK_DATA_SSL_SESSION = ... # type: int +LOGIN_OPTIONS = ... # type: int +LOW_SPEED_LIMIT = ... # type: int +LOW_SPEED_TIME = ... # type: int +MAIL_AUTH = ... # type: int +MAIL_FROM = ... # type: int +MAIL_RCPT = ... # type: int +MAXCONNECTS = ... # type: int +MAXFILESIZE = ... # type: int +MAXFILESIZE_LARGE = ... # type: int +MAXREDIRS = ... # type: int +MAX_RECV_SPEED_LARGE = ... # type: int +MAX_SEND_SPEED_LARGE = ... # type: int +M_CHUNK_LENGTH_PENALTY_SIZE = ... # type: int +M_CONTENT_LENGTH_PENALTY_SIZE = ... # type: int +M_MAXCONNECTS = ... # type: int +M_MAX_HOST_CONNECTIONS = ... # type: int +M_MAX_PIPELINE_LENGTH = ... # type: int +M_MAX_TOTAL_CONNECTIONS = ... # type: int +M_PIPELINING = ... # type: int +M_PIPELINING_SERVER_BL = ... # type: int +M_PIPELINING_SITE_BL = ... # type: int +M_SOCKETFUNCTION = ... # type: int +M_TIMERFUNCTION = ... # type: int +NAMELOOKUP_TIME = ... # type: int +NETRC = ... # type: int +NETRC_FILE = ... # type: int +NETRC_IGNORED = ... # type: int +NETRC_OPTIONAL = ... # type: int +NETRC_REQUIRED = ... # type: int +NEW_DIRECTORY_PERMS = ... # type: int +NEW_FILE_PERMS = ... # type: int +NOBODY = ... # type: int +NOPROGRESS = ... # type: int +NOPROXY = ... # type: int +NOSIGNAL = ... # type: int +NUM_CONNECTS = ... # type: int +OPENSOCKETFUNCTION = ... # type: int +OPT_CERTINFO = ... # type: int +OPT_FILETIME = ... # type: int +OS_ERRNO = ... # type: int +PASSWORD = ... # type: int +PATH_AS_IS = ... # type: int +PAUSE_ALL = ... # type: int +PAUSE_CONT = ... # type: int +PAUSE_RECV = ... # type: int +PAUSE_SEND = ... # type: int +PINNEDPUBLICKEY = ... # type: int +PIPEWAIT = ... # type: int +PIPE_HTTP1 = ... # type: int +PIPE_MULTIPLEX = ... # type: int +PIPE_NOTHING = ... # type: int +POLL_IN = ... # type: int +POLL_INOUT = ... # type: int +POLL_NONE = ... # type: int +POLL_OUT = ... # type: int +POLL_REMOVE = ... # type: int +PORT = ... # type: int +POST = ... # type: int +POST301 = ... # type: int +POSTFIELDS = ... # type: int +POSTFIELDSIZE = ... # type: int +POSTFIELDSIZE_LARGE = ... # type: int +POSTQUOTE = ... # type: int +POSTREDIR = ... # type: int +PREQUOTE = ... # type: int +PRETRANSFER_TIME = ... # type: int +PRIMARY_IP = ... # type: int +PRIMARY_PORT = ... # type: int +PROGRESSFUNCTION = ... # type: int +PROTOCOLS = ... # type: int +PROTO_ALL = ... # type: int +PROTO_DICT = ... # type: int +PROTO_FILE = ... # type: int +PROTO_FTP = ... # type: int +PROTO_FTPS = ... # type: int +PROTO_GOPHER = ... # type: int +PROTO_HTTP = ... # type: int +PROTO_HTTPS = ... # type: int +PROTO_IMAP = ... # type: int +PROTO_IMAPS = ... # type: int +PROTO_LDAP = ... # type: int +PROTO_LDAPS = ... # type: int +PROTO_POP3 = ... # type: int +PROTO_POP3S = ... # type: int +PROTO_RTMP = ... # type: int +PROTO_RTMPE = ... # type: int +PROTO_RTMPS = ... # type: int +PROTO_RTMPT = ... # type: int +PROTO_RTMPTE = ... # type: int +PROTO_RTMPTS = ... # type: int +PROTO_RTSP = ... # type: int +PROTO_SCP = ... # type: int +PROTO_SFTP = ... # type: int +PROTO_SMB = ... # type: int +PROTO_SMBS = ... # type: int +PROTO_SMTP = ... # type: int +PROTO_SMTPS = ... # type: int +PROTO_TELNET = ... # type: int +PROTO_TFTP = ... # type: int +PROXY = ... # type: int +PROXYAUTH = ... # type: int +PROXYAUTH_AVAIL = ... # type: int +PROXYHEADER = ... # type: int +PROXYPASSWORD = ... # type: int +PROXYPORT = ... # type: int +PROXYTYPE = ... # type: int +PROXYTYPE_HTTP = ... # type: int +PROXYTYPE_HTTP_1_0 = ... # type: int +PROXYTYPE_SOCKS4 = ... # type: int +PROXYTYPE_SOCKS4A = ... # type: int +PROXYTYPE_SOCKS5 = ... # type: int +PROXYTYPE_SOCKS5_HOSTNAME = ... # type: int +PROXYUSERNAME = ... # type: int +PROXYUSERPWD = ... # type: int +PROXY_SERVICE_NAME = ... # type: int +PROXY_TRANSFER_MODE = ... # type: int +PUT = ... # type: int +QUOTE = ... # type: int +RANDOM_FILE = ... # type: int +RANGE = ... # type: int +READDATA = ... # type: int +READFUNCTION = ... # type: int +READFUNC_ABORT = ... # type: int +READFUNC_PAUSE = ... # type: int +REDIRECT_COUNT = ... # type: int +REDIRECT_TIME = ... # type: int +REDIRECT_URL = ... # type: int +REDIR_POST_301 = ... # type: int +REDIR_POST_302 = ... # type: int +REDIR_POST_303 = ... # type: int +REDIR_POST_ALL = ... # type: int +REDIR_PROTOCOLS = ... # type: int +REFERER = ... # type: int +REQUEST_SIZE = ... # type: int +RESOLVE = ... # type: int +RESPONSE_CODE = ... # type: int +RESUME_FROM = ... # type: int +RESUME_FROM_LARGE = ... # type: int +SASL_IR = ... # type: int +SEEKFUNCTION = ... # type: int +SEEKFUNC_CANTSEEK = ... # type: int +SEEKFUNC_FAIL = ... # type: int +SEEKFUNC_OK = ... # type: int +SERVICE_NAME = ... # type: int +SHARE = ... # type: int +SH_SHARE = ... # type: int +SH_UNSHARE = ... # type: int +SIZE_DOWNLOAD = ... # type: int +SIZE_UPLOAD = ... # type: int +SOCKET_TIMEOUT = ... # type: int +SOCKOPTFUNCTION = ... # type: int +SOCKOPT_ALREADY_CONNECTED = ... # type: int +SOCKOPT_ERROR = ... # type: int +SOCKOPT_OK = ... # type: int +SOCKS5_GSSAPI_NEC = ... # type: int +SOCKS5_GSSAPI_SERVICE = ... # type: int +SOCKTYPE_ACCEPT = ... # type: int +SOCKTYPE_IPCXN = ... # type: int +SPEED_DOWNLOAD = ... # type: int +SPEED_UPLOAD = ... # type: int +SSH_AUTH_ANY = ... # type: int +SSH_AUTH_DEFAULT = ... # type: int +SSH_AUTH_HOST = ... # type: int +SSH_AUTH_KEYBOARD = ... # type: int +SSH_AUTH_NONE = ... # type: int +SSH_AUTH_PASSWORD = ... # type: int +SSH_AUTH_PUBLICKEY = ... # type: int +SSH_AUTH_TYPES = ... # type: int +SSH_HOST_PUBLIC_KEY_MD5 = ... # type: int +SSH_KEYFUNCTION = ... # type: int +SSH_KNOWNHOSTS = ... # type: int +SSH_PRIVATE_KEYFILE = ... # type: int +SSH_PUBLIC_KEYFILE = ... # type: int +SSLCERT = ... # type: int +SSLCERTPASSWD = ... # type: int +SSLCERTTYPE = ... # type: int +SSLENGINE = ... # type: int +SSLENGINE_DEFAULT = ... # type: int +SSLKEY = ... # type: int +SSLKEYPASSWD = ... # type: int +SSLKEYTYPE = ... # type: int +SSLOPT_ALLOW_BEAST = ... # type: int +SSLVERSION = ... # type: int +SSLVERSION_DEFAULT = ... # type: int +SSLVERSION_SSLv2 = ... # type: int +SSLVERSION_SSLv3 = ... # type: int +SSLVERSION_TLSv1 = ... # type: int +SSLVERSION_TLSv1_0 = ... # type: int +SSLVERSION_TLSv1_1 = ... # type: int +SSLVERSION_TLSv1_2 = ... # type: int +SSL_CIPHER_LIST = ... # type: int +SSL_ENABLE_ALPN = ... # type: int +SSL_ENABLE_NPN = ... # type: int +SSL_ENGINES = ... # type: int +SSL_FALSESTART = ... # type: int +SSL_OPTIONS = ... # type: int +SSL_SESSIONID_CACHE = ... # type: int +SSL_VERIFYHOST = ... # type: int +SSL_VERIFYPEER = ... # type: int +SSL_VERIFYRESULT = ... # type: int +SSL_VERIFYSTATUS = ... # type: int +STARTTRANSFER_TIME = ... # type: int +STDERR = ... # type: int +TCP_KEEPALIVE = ... # type: int +TCP_KEEPIDLE = ... # type: int +TCP_KEEPINTVL = ... # type: int +TCP_NODELAY = ... # type: int +TELNETOPTIONS = ... # type: int +TFTP_BLKSIZE = ... # type: int +TIMECONDITION = ... # type: int +TIMECONDITION_IFMODSINCE = ... # type: int +TIMECONDITION_IFUNMODSINCE = ... # type: int +TIMECONDITION_LASTMOD = ... # type: int +TIMECONDITION_NONE = ... # type: int +TIMEOUT = ... # type: int +TIMEOUT_MS = ... # type: int +TIMEVALUE = ... # type: int +TLSAUTH_PASSWORD = ... # type: int +TLSAUTH_TYPE = ... # type: int +TLSAUTH_USERNAME = ... # type: int +TOTAL_TIME = ... # type: int +TRANSFERTEXT = ... # type: int +TRANSFER_ENCODING = ... # type: int +UNIX_SOCKET_PATH = ... # type: int +UNRESTRICTED_AUTH = ... # type: int +UPLOAD = ... # type: int +URL = ... # type: int +USERAGENT = ... # type: int +USERNAME = ... # type: int +USERPWD = ... # type: int +USESSL_ALL = ... # type: int +USESSL_CONTROL = ... # type: int +USESSL_NONE = ... # type: int +USESSL_TRY = ... # type: int +USE_SSL = ... # type: int +VERBOSE = ... # type: int +VERSION_ASYNCHDNS = ... # type: int +VERSION_CONV = ... # type: int +VERSION_CURLDEBUG = ... # type: int +VERSION_DEBUG = ... # type: int +VERSION_GSSAPI = ... # type: int +VERSION_GSSNEGOTIATE = ... # type: int +VERSION_HTTP2 = ... # type: int +VERSION_IDN = ... # type: int +VERSION_IPV6 = ... # type: int +VERSION_KERBEROS4 = ... # type: int +VERSION_KERBEROS5 = ... # type: int +VERSION_LARGEFILE = ... # type: int +VERSION_LIBZ = ... # type: int +VERSION_NTLM = ... # type: int +VERSION_NTLM_WB = ... # type: int +VERSION_SPNEGO = ... # type: int +VERSION_SSL = ... # type: int +VERSION_SSPI = ... # type: int +VERSION_TLSAUTH_SRP = ... # type: int +VERSION_UNIX_SOCKETS = ... # type: int +WILDCARDMATCH = ... # type: int +WRITEDATA = ... # type: int +WRITEFUNCTION = ... # type: int +WRITEFUNC_PAUSE = ... # type: int +WRITEHEADER = ... # type: int +XFERINFOFUNCTION = ... # type: int +XOAUTH2_BEARER = ... # type: int + +E_ABORTED_BY_CALLBACK = ... # type: int +E_AGAIN = ... # type: int +E_ALREADY_COMPLETE = ... # type: int +E_BAD_CALLING_ORDER = ... # type: int +E_BAD_CONTENT_ENCODING = ... # type: int +E_BAD_DOWNLOAD_RESUME = ... # type: int +E_BAD_FUNCTION_ARGUMENT = ... # type: int +E_BAD_PASSWORD_ENTERED = ... # type: int +E_CALL_MULTI_PERFORM = ... # type: int +E_CHUNK_FAILED = ... # type: int +E_CONV_FAILED = ... # type: int +E_CONV_REQD = ... # type: int +E_COULDNT_CONNECT = ... # type: int +E_COULDNT_RESOLVE_HOST = ... # type: int +E_COULDNT_RESOLVE_PROXY = ... # type: int +E_FAILED_INIT = ... # type: int +E_FILESIZE_EXCEEDED = ... # type: int +E_FILE_COULDNT_READ_FILE = ... # type: int +E_FTP_ACCEPT_FAILED = ... # type: int +E_FTP_ACCEPT_TIMEOUT = ... # type: int +E_FTP_ACCESS_DENIED = ... # type: int +E_FTP_BAD_DOWNLOAD_RESUME = ... # type: int +E_FTP_BAD_FILE_LIST = ... # type: int +E_FTP_CANT_GET_HOST = ... # type: int +E_FTP_CANT_RECONNECT = ... # type: int +E_FTP_COULDNT_GET_SIZE = ... # type: int +E_FTP_COULDNT_RETR_FILE = ... # type: int +E_FTP_COULDNT_SET_ASCII = ... # type: int +E_FTP_COULDNT_SET_BINARY = ... # type: int +E_FTP_COULDNT_SET_TYPE = ... # type: int +E_FTP_COULDNT_STOR_FILE = ... # type: int +E_FTP_COULDNT_USE_REST = ... # type: int +E_FTP_PARTIAL_FILE = ... # type: int +E_FTP_PORT_FAILED = ... # type: int +E_FTP_PRET_FAILED = ... # type: int +E_FTP_QUOTE_ERROR = ... # type: int +E_FTP_SSL_FAILED = ... # type: int +E_FTP_USER_PASSWORD_INCORRECT = ... # type: int +E_FTP_WEIRD_227_FORMAT = ... # type: int +E_FTP_WEIRD_PASS_REPLY = ... # type: int +E_FTP_WEIRD_PASV_REPLY = ... # type: int +E_FTP_WEIRD_SERVER_REPLY = ... # type: int +E_FTP_WEIRD_USER_REPLY = ... # type: int +E_FTP_WRITE_ERROR = ... # type: int +E_FUNCTION_NOT_FOUND = ... # type: int +E_GOT_NOTHING = ... # type: int +E_HTTP2 = ... # type: int +E_HTTP_NOT_FOUND = ... # type: int +E_HTTP_PORT_FAILED = ... # type: int +E_HTTP_POST_ERROR = ... # type: int +E_HTTP_RANGE_ERROR = ... # type: int +E_HTTP_RETURNED_ERROR = ... # type: int +E_INTERFACE_FAILED = ... # type: int +E_LDAP_CANNOT_BIND = ... # type: int +E_LDAP_INVALID_URL = ... # type: int +E_LDAP_SEARCH_FAILED = ... # type: int +E_LIBRARY_NOT_FOUND = ... # type: int +E_LOGIN_DENIED = ... # type: int +E_MALFORMAT_USER = ... # type: int +E_MULTI_ADDED_ALREADY = ... # type: int +E_MULTI_BAD_EASY_HANDLE = ... # type: int +E_MULTI_BAD_HANDLE = ... # type: int +E_MULTI_BAD_SOCKET = ... # type: int +E_MULTI_CALL_MULTI_PERFORM = ... # type: int +E_MULTI_CALL_MULTI_SOCKET = ... # type: int +E_MULTI_INTERNAL_ERROR = ... # type: int +E_MULTI_OK = ... # type: int +E_MULTI_OUT_OF_MEMORY = ... # type: int +E_MULTI_UNKNOWN_OPTION = ... # type: int +E_NOT_BUILT_IN = ... # type: int +E_NO_CONNECTION_AVAILABLE = ... # type: int +E_OK = ... # type: int +E_OPERATION_TIMEDOUT = ... # type: int +E_OPERATION_TIMEOUTED = ... # type: int +E_OUT_OF_MEMORY = ... # type: int +E_PARTIAL_FILE = ... # type: int +E_PEER_FAILED_VERIFICATION = ... # type: int +E_QUOTE_ERROR = ... # type: int +E_RANGE_ERROR = ... # type: int +E_READ_ERROR = ... # type: int +E_RECV_ERROR = ... # type: int +E_REMOTE_ACCESS_DENIED = ... # type: int +E_REMOTE_DISK_FULL = ... # type: int +E_REMOTE_FILE_EXISTS = ... # type: int +E_REMOTE_FILE_NOT_FOUND = ... # type: int +E_RTSP_CSEQ_ERROR = ... # type: int +E_RTSP_SESSION_ERROR = ... # type: int +E_SEND_ERROR = ... # type: int +E_SEND_FAIL_REWIND = ... # type: int +E_SHARE_IN_USE = ... # type: int +E_SSH = ... # type: int +E_SSL_CACERT = ... # type: int +E_SSL_CACERT_BADFILE = ... # type: int +E_SSL_CERTPROBLEM = ... # type: int +E_SSL_CIPHER = ... # type: int +E_SSL_CONNECT_ERROR = ... # type: int +E_SSL_CRL_BADFILE = ... # type: int +E_SSL_ENGINE_INITFAILED = ... # type: int +E_SSL_ENGINE_NOTFOUND = ... # type: int +E_SSL_ENGINE_SETFAILED = ... # type: int +E_SSL_INVALIDCERTSTATUS = ... # type: int +E_SSL_ISSUER_ERROR = ... # type: int +E_SSL_PEER_CERTIFICATE = ... # type: int +E_SSL_PINNEDPUBKEYNOTMATCH = ... # type: int +E_SSL_SHUTDOWN_FAILED = ... # type: int +E_TELNET_OPTION_SYNTAX = ... # type: int +E_TFTP_DISKFULL = ... # type: int +E_TFTP_EXISTS = ... # type: int +E_TFTP_ILLEGAL = ... # type: int +E_TFTP_NOSUCHUSER = ... # type: int +E_TFTP_NOTFOUND = ... # type: int +E_TFTP_PERM = ... # type: int +E_TFTP_UNKNOWNID = ... # type: int +E_TOO_MANY_REDIRECTS = ... # type: int +E_UNKNOWN_OPTION = ... # type: int +E_UNKNOWN_TELNET_OPTION = ... # type: int +E_UNSUPPORTED_PROTOCOL = ... # type: int +E_UPLOAD_FAILED = ... # type: int +E_URL_MALFORMAT = ... # type: int +E_URL_MALFORMAT_USER = ... # type: int +E_USE_SSL_FAILED = ... # type: int +E_WRITE_ERROR = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/pymssql.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/pymssql.pyi new file mode 100644 index 000000000..a35b050c9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/pymssql.pyi @@ -0,0 +1,48 @@ +from datetime import datetime, date, time + +from typing import Any, Dict, Tuple, Iterable, List, Optional, Union, Sequence + +Scalar = Union[int, float, str, datetime, date, time] +Result = Union[Tuple[Scalar, ...], Dict[str, Scalar]] + +class Connection(object): + def __init__(self, user, password, host, database, timeout, + login_timeout, charset, as_dict) -> None: ... + def autocommit(self, status: bool) -> None: ... + def close(self) -> None: ... + def commit(self) -> None: ... + def cursor(self) -> 'Cursor': ... + def rollback(self) -> None: ... + +class Cursor(object): + def __init__(self) -> None: ... + def __iter__(self): ... + def __next__(self) -> Any: ... + def callproc(self, procname: str, **kwargs) -> None: ... + def close(self) -> None: ... + def execute(self, stmt: str, + params: Optional[Union[Scalar, Tuple[Scalar, ...], + Dict[str, Scalar]]]) -> None: ... + def executemany(self, stmt: str, + params: Optional[Sequence[Tuple[Scalar, ...]]]) -> None: ... + def fetchall(self) -> List[Result]: ... + def fetchmany(self, size: Optional[int]) -> List[Result]: ... + def fetchone(self) -> Result: ... + +def connect(server: Optional[str], + user: Optional[str], + password: Optional[str], + database: Optional[str], + timeout: Optional[int], + login_timeout: Optional[int], + charset: Optional[str], + as_dict: Optional[bool], + host: Optional[str], + appname: Optional[str], + port: Optional[str], + + conn_properties: Optional[Union[str, Sequence[str]]], + autocommit: Optional[bool], + tds_version: Optional[str]) -> Connection: ... +def get_max_connections() -> int: ... +def set_max_connections(n: int) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/__init__.pyi new file mode 100644 index 000000000..333de49b0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/__init__.pyi @@ -0,0 +1,24 @@ +from . import client +from . import connection +from . import utils +from . import exceptions + +Redis = client.Redis +StrictRedis = client.StrictRedis +BlockingConnectionPool = connection.BlockingConnectionPool +ConnectionPool = connection.ConnectionPool +Connection = connection.Connection +SSLConnection = connection.SSLConnection +UnixDomainSocketConnection = connection.UnixDomainSocketConnection +from_url = utils.from_url +AuthenticationError = exceptions.AuthenticationError +BusyLoadingError = exceptions.BusyLoadingError +ConnectionError = exceptions.ConnectionError +DataError = exceptions.DataError +InvalidResponse = exceptions.InvalidResponse +PubSubError = exceptions.PubSubError +ReadOnlyError = exceptions.ReadOnlyError +RedisError = exceptions.RedisError +ResponseError = exceptions.ResponseError +TimeoutError = exceptions.TimeoutError +WatchError = exceptions.WatchError diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/client.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/client.pyi new file mode 100644 index 000000000..99f2adf9d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/client.pyi @@ -0,0 +1,289 @@ +from typing import Any + +SYM_EMPTY = ... # type: Any + +def list_or_args(keys, args): ... +def timestamp_to_datetime(response): ... +def string_keys_to_dict(key_string, callback): ... +def dict_merge(*dicts): ... +def parse_debug_object(response): ... +def parse_object(response, infotype): ... +def parse_info(response): ... + +SENTINEL_STATE_TYPES = ... # type: Any + +def parse_sentinel_state(item): ... +def parse_sentinel_master(response): ... +def parse_sentinel_masters(response): ... +def parse_sentinel_slaves_and_sentinels(response): ... +def parse_sentinel_get_master(response): ... +def pairs_to_dict(response): ... +def pairs_to_dict_typed(response, type_info): ... +def zset_score_pairs(response, **options): ... +def sort_return_tuples(response, **options): ... +def int_or_none(response): ... +def float_or_none(response): ... +def bool_ok(response): ... +def parse_client_list(response, **options): ... +def parse_config_get(response, **options): ... +def parse_scan(response, **options): ... +def parse_hscan(response, **options): ... +def parse_zscan(response, **options): ... +def parse_slowlog_get(response, **options): ... + +class StrictRedis: + RESPONSE_CALLBACKS = ... # type: Any + @classmethod + def from_url(cls, url, db=..., **kwargs): ... + connection_pool = ... # type: Any + response_callbacks = ... # type: Any + def __init__(self, host=..., port=..., db=..., password=..., socket_timeout=..., socket_connect_timeout=..., socket_keepalive=..., socket_keepalive_options=..., connection_pool=..., unix_socket_path=..., encoding=..., encoding_errors=..., charset=..., errors=..., decode_responses=..., retry_on_timeout=..., ssl=..., ssl_keyfile=..., ssl_certfile=..., ssl_cert_reqs=..., ssl_ca_certs=...) -> None: ... + def set_response_callback(self, command, callback): ... + def pipeline(self, transaction=..., shard_hint=...): ... + def transaction(self, func, *watches, **kwargs): ... + def lock(self, name, timeout=..., sleep=..., blocking_timeout=..., lock_class=..., thread_local=...): ... + def pubsub(self, **kwargs): ... + def execute_command(self, *args, **options): ... + def parse_response(self, connection, command_name, **options): ... + def bgrewriteaof(self): ... + def bgsave(self): ... + def client_kill(self, address): ... + def client_list(self): ... + def client_getname(self): ... + def client_setname(self, name): ... + def config_get(self, pattern=...): ... + def config_set(self, name, value): ... + def config_resetstat(self): ... + def config_rewrite(self): ... + def dbsize(self): ... + def debug_object(self, key): ... + def echo(self, value): ... + def flushall(self): ... + def flushdb(self): ... + def info(self, section=...): ... + def lastsave(self): ... + def object(self, infotype, key): ... + def ping(self): ... + def save(self): ... + def sentinel(self, *args): ... + def sentinel_get_master_addr_by_name(self, service_name): ... + def sentinel_master(self, service_name): ... + def sentinel_masters(self): ... + def sentinel_monitor(self, name, ip, port, quorum): ... + def sentinel_remove(self, name): ... + def sentinel_sentinels(self, service_name): ... + def sentinel_set(self, name, option, value): ... + def sentinel_slaves(self, service_name): ... + def shutdown(self): ... + def slaveof(self, host=..., port=...): ... + def slowlog_get(self, num=...): ... + def slowlog_len(self): ... + def slowlog_reset(self): ... + def time(self): ... + def append(self, key, value): ... + def bitcount(self, key, start=..., end=...): ... + def bitop(self, operation, dest, *keys): ... + def bitpos(self, key, bit, start=..., end=...): ... + def decr(self, name, amount=...): ... + def delete(self, *names): ... + def __delitem__(self, name): ... + def dump(self, name): ... + def exists(self, name): ... + __contains__ = ... # type: Any + def expire(self, name, time): ... + def expireat(self, name, when): ... + def get(self, name): ... + def __getitem__(self, name): ... + def getbit(self, name, offset): ... + def getrange(self, key, start, end): ... + def getset(self, name, value): ... + def incr(self, name, amount=...): ... + def incrby(self, name, amount=...): ... + def incrbyfloat(self, name, amount=...): ... + def keys(self, pattern=...): ... + def mget(self, keys, *args): ... + def mset(self, *args, **kwargs): ... + def msetnx(self, *args, **kwargs): ... + def move(self, name, db): ... + def persist(self, name): ... + def pexpire(self, name, time): ... + def pexpireat(self, name, when): ... + def psetex(self, name, time_ms, value): ... + def pttl(self, name): ... + def randomkey(self): ... + def rename(self, src, dst): ... + def renamenx(self, src, dst): ... + def restore(self, name, ttl, value): ... + def set(self, name, value, ex=..., px=..., nx=..., xx=...): ... + def __setitem__(self, name, value): ... + def setbit(self, name, offset, value): ... + def setex(self, name, time, value): ... + def setnx(self, name, value): ... + def setrange(self, name, offset, value): ... + def strlen(self, name): ... + def substr(self, name, start, end=...): ... + def ttl(self, name): ... + def type(self, name): ... + def watch(self, *names): ... + def unwatch(self): ... + def blpop(self, keys, timeout=...): ... + def brpop(self, keys, timeout=...): ... + def brpoplpush(self, src, dst, timeout=...): ... + def lindex(self, name, index): ... + def linsert(self, name, where, refvalue, value): ... + def llen(self, name): ... + def lpop(self, name): ... + def lpush(self, name, *values): ... + def lpushx(self, name, value): ... + def lrange(self, name, start, end): ... + def lrem(self, name, count, value): ... + def lset(self, name, index, value): ... + def ltrim(self, name, start, end): ... + def rpop(self, name): ... + def rpoplpush(self, src, dst): ... + def rpush(self, name, *values): ... + def rpushx(self, name, value): ... + def sort(self, name, start=..., num=..., by=..., get=..., desc=..., alpha=..., store=..., groups=...): ... + def scan(self, cursor=..., match=..., count=...): ... + def scan_iter(self, match=..., count=...): ... + def sscan(self, name, cursor=..., match=..., count=...): ... + def sscan_iter(self, name, match=..., count=...): ... + def hscan(self, name, cursor=..., match=..., count=...): ... + def hscan_iter(self, name, match=..., count=...): ... + def zscan(self, name, cursor=..., match=..., count=..., score_cast_func=...): ... + def zscan_iter(self, name, match=..., count=..., score_cast_func=...): ... + def sadd(self, name, *values): ... + def scard(self, name): ... + def sdiff(self, keys, *args): ... + def sdiffstore(self, dest, keys, *args): ... + def sinter(self, keys, *args): ... + def sinterstore(self, dest, keys, *args): ... + def sismember(self, name, value): ... + def smembers(self, name): ... + def smove(self, src, dst, value): ... + def spop(self, name): ... + def srandmember(self, name, number=...): ... + def srem(self, name, *values): ... + def sunion(self, keys, *args): ... + def sunionstore(self, dest, keys, *args): ... + def zadd(self, name, *args, **kwargs): ... + def zcard(self, name): ... + def zcount(self, name, min, max): ... + def zincrby(self, name, value, amount=...): ... + def zinterstore(self, dest, keys, aggregate=...): ... + def zlexcount(self, name, min, max): ... + def zrange(self, name, start, end, desc=..., withscores=..., score_cast_func=...): ... + def zrangebylex(self, name, min, max, start=..., num=...): ... + def zrangebyscore(self, name, min, max, start=..., num=..., withscores=..., score_cast_func=...): ... + def zrank(self, name, value): ... + def zrem(self, name, *values): ... + def zremrangebylex(self, name, min, max): ... + def zremrangebyrank(self, name, min, max): ... + def zremrangebyscore(self, name, min, max): ... + def zrevrange(self, name, start, end, withscores=..., score_cast_func=...): ... + def zrevrangebyscore(self, name, max, min, start=..., num=..., withscores=..., score_cast_func=...): ... + def zrevrank(self, name, value): ... + def zscore(self, name, value): ... + def zunionstore(self, dest, keys, aggregate=...): ... + def pfadd(self, name, *values): ... + def pfcount(self, name): ... + def pfmerge(self, dest, *sources): ... + def hdel(self, name, *keys): ... + def hexists(self, name, key): ... + def hget(self, name, key): ... + def hgetall(self, name): ... + def hincrby(self, name, key, amount=...): ... + def hincrbyfloat(self, name, key, amount=...): ... + def hkeys(self, name): ... + def hlen(self, name): ... + def hset(self, name, key, value): ... + def hsetnx(self, name, key, value): ... + def hmset(self, name, mapping): ... + def hmget(self, name, keys, *args): ... + def hvals(self, name): ... + def publish(self, channel, message): ... + def eval(self, script, numkeys, *keys_and_args): ... + def evalsha(self, sha, numkeys, *keys_and_args): ... + def script_exists(self, *args): ... + def script_flush(self): ... + def script_kill(self): ... + def script_load(self, script): ... + def register_script(self, script): ... + +class Redis(StrictRedis): + RESPONSE_CALLBACKS = ... # type: Any + def pipeline(self, transaction=..., shard_hint=...): ... + def setex(self, name, value, time): ... + def lrem(self, name, value, num=...): ... + def zadd(self, name, *args, **kwargs): ... + +class PubSub: + PUBLISH_MESSAGE_TYPES = ... # type: Any + UNSUBSCRIBE_MESSAGE_TYPES = ... # type: Any + connection_pool = ... # type: Any + shard_hint = ... # type: Any + ignore_subscribe_messages = ... # type: Any + connection = ... # type: Any + encoding = ... # type: Any + encoding_errors = ... # type: Any + decode_responses = ... # type: Any + def __init__(self, connection_pool, shard_hint=..., ignore_subscribe_messages=...) -> None: ... + def __del__(self): ... + channels = ... # type: Any + patterns = ... # type: Any + def reset(self): ... + def close(self): ... + def on_connect(self, connection): ... + def encode(self, value): ... + @property + def subscribed(self): ... + def execute_command(self, *args, **kwargs): ... + def parse_response(self, block=...): ... + def psubscribe(self, *args, **kwargs): ... + def punsubscribe(self, *args): ... + def subscribe(self, *args, **kwargs): ... + def unsubscribe(self, *args): ... + def listen(self): ... + def get_message(self, ignore_subscribe_messages=...): ... + def handle_message(self, response, ignore_subscribe_messages=...): ... + def run_in_thread(self, sleep_time=...): ... + +class BasePipeline: + UNWATCH_COMMANDS = ... # type: Any + connection_pool = ... # type: Any + connection = ... # type: Any + response_callbacks = ... # type: Any + transaction = ... # type: Any + shard_hint = ... # type: Any + watching = ... # type: Any + def __init__(self, connection_pool, response_callbacks, transaction, shard_hint) -> None: ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, traceback): ... + def __del__(self): ... + def __len__(self): ... + command_stack = ... # type: Any + scripts = ... # type: Any + explicit_transaction = ... # type: Any + def reset(self): ... + def multi(self): ... + def execute_command(self, *args, **kwargs): ... + def immediate_execute_command(self, *args, **options): ... + def pipeline_execute_command(self, *args, **options): ... + def raise_first_error(self, commands, response): ... + def annotate_exception(self, exception, number, command): ... + def parse_response(self, connection, command_name, **options): ... + def load_scripts(self): ... + def execute(self, raise_on_error=...): ... + def watch(self, *names): ... + def unwatch(self): ... + def script_load_for_pipeline(self, script): ... + +class StrictPipeline(BasePipeline, StrictRedis): ... +class Pipeline(BasePipeline, Redis): ... + +class Script: + registered_client = ... # type: Any + script = ... # type: Any + sha = ... # type: Any + def __init__(self, registered_client, script) -> None: ... + def __call__(self, keys=..., args=..., client=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/connection.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/connection.pyi new file mode 100644 index 000000000..975647712 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/connection.pyi @@ -0,0 +1,131 @@ +from typing import Any + +ssl_available = ... # type: Any +hiredis_version = ... # type: Any +HIREDIS_SUPPORTS_CALLABLE_ERRORS = ... # type: Any +HIREDIS_SUPPORTS_BYTE_BUFFER = ... # type: Any +msg = ... # type: Any +HIREDIS_USE_BYTE_BUFFER = ... # type: Any +SYM_STAR = ... # type: Any +SYM_DOLLAR = ... # type: Any +SYM_CRLF = ... # type: Any +SYM_EMPTY = ... # type: Any +SERVER_CLOSED_CONNECTION_ERROR = ... # type: Any + +class Token: + value = ... # type: Any + def __init__(self, value) -> None: ... + +class BaseParser: + EXCEPTION_CLASSES = ... # type: Any + def parse_error(self, response): ... + +class SocketBuffer: + socket_read_size = ... # type: Any + bytes_written = ... # type: Any + bytes_read = ... # type: Any + def __init__(self, socket, socket_read_size) -> None: ... + @property + def length(self): ... + def read(self, length): ... + def readline(self): ... + def purge(self): ... + def close(self): ... + +class PythonParser(BaseParser): + encoding = ... # type: Any + socket_read_size = ... # type: Any + def __init__(self, socket_read_size) -> None: ... + def __del__(self): ... + def on_connect(self, connection): ... + def on_disconnect(self): ... + def can_read(self): ... + def read_response(self): ... + +class HiredisParser(BaseParser): + socket_read_size = ... # type: Any + def __init__(self, socket_read_size) -> None: ... + def __del__(self): ... + def on_connect(self, connection): ... + def on_disconnect(self): ... + def can_read(self): ... + def read_response(self): ... + +DefaultParser = ... # type: Any + +class Connection: + description_format = ... # type: Any + pid = ... # type: Any + host = ... # type: Any + port = ... # type: Any + db = ... # type: Any + password = ... # type: Any + socket_timeout = ... # type: Any + socket_connect_timeout = ... # type: Any + socket_keepalive = ... # type: Any + socket_keepalive_options = ... # type: Any + retry_on_timeout = ... # type: Any + encoding = ... # type: Any + encoding_errors = ... # type: Any + decode_responses = ... # type: Any + def __init__(self, host=..., port=..., db=..., password=..., socket_timeout=..., socket_connect_timeout=..., socket_keepalive=..., socket_keepalive_options=..., retry_on_timeout=..., encoding=..., encoding_errors=..., decode_responses=..., parser_class=..., socket_read_size=...) -> None: ... + def __del__(self): ... + def register_connect_callback(self, callback): ... + def clear_connect_callbacks(self): ... + def connect(self): ... + def on_connect(self): ... + def disconnect(self): ... + def send_packed_command(self, command): ... + def send_command(self, *args): ... + def can_read(self): ... + def read_response(self): ... + def encode(self, value): ... + def pack_command(self, *args): ... + def pack_commands(self, commands): ... + +class SSLConnection(Connection): + description_format = ... # type: Any + keyfile = ... # type: Any + certfile = ... # type: Any + cert_reqs = ... # type: Any + ca_certs = ... # type: Any + def __init__(self, ssl_keyfile=..., ssl_certfile=..., ssl_cert_reqs=..., ssl_ca_certs=..., **kwargs) -> None: ... + +class UnixDomainSocketConnection(Connection): + description_format = ... # type: Any + pid = ... # type: Any + path = ... # type: Any + db = ... # type: Any + password = ... # type: Any + socket_timeout = ... # type: Any + retry_on_timeout = ... # type: Any + encoding = ... # type: Any + encoding_errors = ... # type: Any + decode_responses = ... # type: Any + def __init__(self, path=..., db=..., password=..., socket_timeout=..., encoding=..., encoding_errors=..., decode_responses=..., retry_on_timeout=..., parser_class=..., socket_read_size=...) -> None: ... + +class ConnectionPool: + @classmethod + def from_url(cls, url, db=..., **kwargs): ... + connection_class = ... # type: Any + connection_kwargs = ... # type: Any + max_connections = ... # type: Any + def __init__(self, connection_class=..., max_connections=..., **connection_kwargs) -> None: ... + pid = ... # type: Any + def reset(self): ... + def get_connection(self, command_name, *keys, **options): ... + def make_connection(self): ... + def release(self, connection): ... + def disconnect(self): ... + +class BlockingConnectionPool(ConnectionPool): + queue_class = ... # type: Any + timeout = ... # type: Any + def __init__(self, max_connections=..., timeout=..., connection_class=..., queue_class=..., **connection_kwargs) -> None: ... + pid = ... # type: Any + pool = ... # type: Any + def reset(self): ... + def make_connection(self): ... + def get_connection(self, command_name, *keys, **options): ... + def release(self, connection): ... + def disconnect(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/exceptions.pyi new file mode 100644 index 000000000..e0cd08a83 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/exceptions.pyi @@ -0,0 +1,17 @@ +class RedisError(Exception): ... + +def __unicode__(self): ... + +class AuthenticationError(RedisError): ... +class ConnectionError(RedisError): ... +class TimeoutError(RedisError): ... +class BusyLoadingError(ConnectionError): ... +class InvalidResponse(RedisError): ... +class ResponseError(RedisError): ... +class DataError(RedisError): ... +class PubSubError(RedisError): ... +class WatchError(RedisError): ... +class NoScriptError(ResponseError): ... +class ExecAbortError(ResponseError): ... +class ReadOnlyError(ResponseError): ... +class LockError(RedisError, ValueError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/utils.pyi new file mode 100644 index 000000000..5e32010bf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/redis/utils.pyi @@ -0,0 +1,8 @@ +from typing import Any + +HIREDIS_AVAILABLE = ... # type: Any + +def from_url(url, db=..., **kwargs): ... +def pipeline(redis_obj): ... + +class dummy: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/__init__.pyi new file mode 100644 index 000000000..8a1261f55 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/__init__.pyi @@ -0,0 +1,15 @@ +from . import mapper +from . import util + +class _RequestConfig: + def __getattr__(self, name): ... + def __setattr__(self, name, value): ... + def __delattr__(self, name): ... + def load_wsgi_environ(self, environ): ... + +def request_config(original=...): ... + +Mapper = mapper.Mapper +redirect_to = util.redirect_to +url_for = util.url_for +URLGenerator = util.URLGenerator diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/mapper.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/mapper.pyi new file mode 100644 index 000000000..074c4ffd1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/mapper.pyi @@ -0,0 +1,66 @@ +from typing import Any + +COLLECTION_ACTIONS = ... # type: Any +MEMBER_ACTIONS = ... # type: Any + +def strip_slashes(name): ... + +class SubMapperParent: + def submapper(self, **kargs): ... + def collection(self, collection_name, resource_name, path_prefix=..., member_prefix=..., controller=..., collection_actions=..., member_actions=..., member_options=..., **kwargs): ... + +class SubMapper(SubMapperParent): + kwargs = ... # type: Any + obj = ... # type: Any + collection_name = ... # type: Any + member = ... # type: Any + resource_name = ... # type: Any + formatted = ... # type: Any + def __init__(self, obj, resource_name=..., collection_name=..., actions=..., formatted=..., **kwargs) -> None: ... + def connect(self, *args, **kwargs): ... + def link(self, rel=..., name=..., action=..., method=..., formatted=..., **kwargs): ... + def new(self, **kwargs): ... + def edit(self, **kwargs): ... + def action(self, name=..., action=..., method=..., formatted=..., **kwargs): ... + def index(self, name=..., **kwargs): ... + def show(self, name=..., **kwargs): ... + def create(self, **kwargs): ... + def update(self, **kwargs): ... + def delete(self, **kwargs): ... + def add_actions(self, actions): ... + def __enter__(self): ... + def __exit__(self, type, value, tb): ... + +class Mapper(SubMapperParent): + matchlist = ... # type: Any + maxkeys = ... # type: Any + minkeys = ... # type: Any + urlcache = ... # type: Any + prefix = ... # type: Any + req_data = ... # type: Any + directory = ... # type: Any + always_scan = ... # type: Any + controller_scan = ... # type: Any + debug = ... # type: Any + append_slash = ... # type: Any + sub_domains = ... # type: Any + sub_domains_ignore = ... # type: Any + domain_match = ... # type: Any + explicit = ... # type: Any + encoding = ... # type: Any + decode_errors = ... # type: Any + hardcode_names = ... # type: Any + minimization = ... # type: Any + create_regs_lock = ... # type: Any + def __init__(self, controller_scan=..., directory=..., always_scan=..., register=..., explicit=...) -> None: ... + environ = ... # type: Any + def extend(self, routes, path_prefix=...): ... + def make_route(self, *args, **kargs): ... + def connect(self, *args, **kargs): ... + def create_regs(self, *args, **kwargs): ... + def match(self, url=..., environ=...): ... + def routematch(self, url=..., environ=...): ... + obj = ... # type: Any + def generate(self, *args, **kargs): ... + def resource(self, member_name, collection_name, **kwargs): ... + def redirect(self, match_path, destination_path, *args, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/util.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/util.pyi new file mode 100644 index 000000000..aeb97f3d4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/routes/util.pyi @@ -0,0 +1,20 @@ +from typing import Any + +class RoutesException(Exception): ... +class MatchException(RoutesException): ... +class GenerationException(RoutesException): ... + +def url_for(*args, **kargs): ... + +class URLGenerator: + mapper = ... # type: Any + environ = ... # type: Any + def __init__(self, mapper, environ) -> None: ... + def __call__(self, *args, **kargs): ... + def current(self, *args, **kwargs): ... + +def redirect_to(*args, **kargs): ... +def cache_hostinfo(environ): ... +def controller_scan(directory=...): ... +def as_unicode(value, encoding, errors=...): ... +def ascii_characters(string): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/scribe.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/scribe.pyi new file mode 100644 index 000000000..bd7262b1a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/scribe.pyi @@ -0,0 +1,39 @@ +from typing import Any + +import fb303.FacebookService +from .ttypes import * # noqa: F403 +from thrift.Thrift import TProcessor # type: ignore # We don't have thrift stubs in typeshed + +class Iface(fb303.FacebookService.Iface): + def Log(self, messages): ... + +class Client(fb303.FacebookService.Client, Iface): + def __init__(self, iprot, oprot=...) -> None: ... + def Log(self, messages): ... + def send_Log(self, messages): ... + def recv_Log(self): ... + +class Processor(fb303.FacebookService.Processor, Iface, TProcessor): + def __init__(self, handler) -> None: ... + def process(self, iprot, oprot): ... + def process_Log(self, seqid, iprot, oprot): ... + +class Log_args: + thrift_spec = ... # type: Any + messages = ... # type: Any + def __init__(self, messages=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class Log_result: + thrift_spec = ... # type: Any + success = ... # type: Any + def __init__(self, success=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/ttypes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/ttypes.pyi new file mode 100644 index 000000000..69ec920c1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/scribe/ttypes.pyi @@ -0,0 +1,18 @@ +from typing import Any + +fastbinary = ... # type: Any + +class ResultCode: + OK = ... # type: Any + TRY_LATER = ... # type: Any + +class LogEntry: + thrift_spec = ... # type: Any + category = ... # type: Any + message = ... # type: Any + def __init__(self, category=..., message=...) -> None: ... + def read(self, iprot): ... + def write(self, oprot): ... + def validate(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/__init__.pyi new file mode 100644 index 000000000..f54abb2f6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/__init__.pyi @@ -0,0 +1,91 @@ +# Stubs for six (Python 2.7) + +from __future__ import print_function + +import types +from typing import ( + Any, AnyStr, Callable, Dict, Iterable, Mapping, NoReturn, Optional, + Pattern, Tuple, Type, TypeVar, Union, overload, ValuesView, KeysView, ItemsView +) +import typing +import unittest + +# Exports +from __builtin__ import unichr as unichr +from StringIO import StringIO as StringIO, StringIO as BytesIO +from functools import wraps as wraps +from . import moves + + +_T = TypeVar('_T') +_K = TypeVar('_K') +_V = TypeVar('_V') + +# TODO make constant, then move this stub to 2and3 +# https://github.com/python/typeshed/issues/17 +PY2 = True +PY3 = False +PY34 = False + +string_types = (str, unicode) +integer_types = (int, long) +class_types = (type, types.ClassType) +text_type = unicode +binary_type = str + +MAXSIZE = ... # type: int + +# def add_move +# def remove_move + +def advance_iterator(it: typing.Iterator[_T]) -> _T: ... +next = advance_iterator + +def callable(obj: object) -> bool: ... + +def get_unbound_function(unbound: types.MethodType) -> types.FunctionType: ... +def create_bound_method(func: types.FunctionType, obj: object) -> types.MethodType: ... +def create_unbound_method(func: types.FunctionType, cls: Union[type, types.ClassType]) -> types.MethodType: ... + +class Iterator: + def next(self) -> Any: ... + +def get_method_function(meth: types.MethodType) -> types.FunctionType: ... +def get_method_self(meth: types.MethodType) -> Optional[object]: ... +def get_function_closure(fun: types.FunctionType) -> Optional[Tuple[types._Cell, ...]]: ... +def get_function_code(fun: types.FunctionType) -> types.CodeType: ... +def get_function_defaults(fun: types.FunctionType) -> Optional[Tuple[Any, ...]]: ... +def get_function_globals(fun: types.FunctionType) -> Dict[str, Any]: ... + +def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ... +def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ... +def iteritems(d: Mapping[_K, _V]) -> typing.Iterator[Tuple[_K, _V]]: ... +# def iterlists + +def viewkeys(d: Mapping[_K, _V]) -> KeysView[_K]: ... +def viewvalues(d: Mapping[_K, _V]) -> ValuesView[_V]: ... +def viewitems(d: Mapping[_K, _V]) -> ItemsView[_K, _V]: ... + +def b(s: str) -> binary_type: ... +def u(s: str) -> text_type: ... +int2byte = chr +def byte2int(bs: binary_type) -> int: ... +def indexbytes(buf: binary_type, i: int) -> int: ... +def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... + +def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: str = ...) -> None: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, msg: str = ...) -> Any: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... +def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: str = ...) -> None: ... + +def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = ...) -> NoReturn: ... +def exec_(_code_: Union[unicode, types.CodeType], _globs_: Dict[str, Any] = ..., _locs_: Dict[str, Any] = ...): ... +def raise_from(value: BaseException, from_value: Optional[BaseException]) -> NoReturn: ... + +print_ = print + +def with_metaclass(meta: type, *bases: type) -> type: ... +def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... +def python_2_unicode_compatible(klass: _T) -> _T: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/BaseHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/BaseHTTPServer.pyi new file mode 100644 index 000000000..16f7a9dc1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/BaseHTTPServer.pyi @@ -0,0 +1 @@ +from BaseHTTPServer import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/SimpleHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/SimpleHTTPServer.pyi new file mode 100644 index 000000000..97cfe7717 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/SimpleHTTPServer.pyi @@ -0,0 +1 @@ +from SimpleHTTPServer import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/__init__.pyi new file mode 100644 index 000000000..ade03042c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/__init__.pyi @@ -0,0 +1,66 @@ +# Stubs for six.moves +# +# Note: Commented out items means they weren't implemented at the time. +# Uncomment them when the modules have been added to the typeshed. +from cStringIO import StringIO as cStringIO +from itertools import ifilter as filter +from itertools import ifilterfalse as filterfalse +from __builtin__ import raw_input as input +from __builtin__ import intern as intern +from itertools import imap as map +from os import getcwdu as getcwd +from os import getcwd as getcwdb +from __builtin__ import xrange as range +from __builtin__ import reload as reload_module +from __builtin__ import reduce as reduce +from pipes import quote as shlex_quote +from StringIO import StringIO as StringIO +from UserDict import UserDict as UserDict +from UserList import UserList as UserList +from UserString import UserString as UserString +from __builtin__ import xrange as xrange +from itertools import izip as zip +from itertools import izip_longest as zip_longest +import __builtin__ as builtins +from . import configparser +# import copy_reg as copyreg +# import gdbm as dbm_gnu +from . import _dummy_thread +from . import http_cookiejar +from . import http_cookies +from . import html_entities +from . import html_parser +from . import http_client +# import email.MIMEMultipart as email_mime_multipart +# import email.MIMENonMultipart as email_mime_nonmultipart +from . import email_mime_text +# import email.MIMEBase as email_mime_base +from . import BaseHTTPServer +# import CGIHTTPServer as CGIHTTPServer +from . import SimpleHTTPServer +from . import cPickle +from . import queue +from . import reprlib +from . import socketserver +from . import _thread +# import Tkinter as tkinter +# import Dialog as tkinter_dialog +# import FileDialog as tkinter_filedialog +# import ScrolledText as tkinter_scrolledtext +# import SimpleDialog as tkinter_simpledialog +# import Tix as tkinter_tix +# import ttk as tkinter_ttk +# import Tkconstants as tkinter_constants +# import Tkdnd as tkinter_dnd +# import tkColorChooser as tkinter_colorchooser +# import tkCommonDialog as tkinter_commondialog +# import tkFileDialog as tkinter_tkfiledialog +# import tkFont as tkinter_font +# import tkMessageBox as tkinter_messagebox +# import tkSimpleDialog as tkinter_tksimpledialog +from . import urllib_parse +from . import urllib_error +from . import urllib +from . import urllib_robotparser +from . import xmlrpc_client +# import SimpleXMLRPCServer as xmlrpc_server diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/_dummy_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/_dummy_thread.pyi new file mode 100644 index 000000000..3efe922c9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/_dummy_thread.pyi @@ -0,0 +1 @@ +from dummy_thread import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/_thread.pyi new file mode 100644 index 000000000..b27f4c70d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/_thread.pyi @@ -0,0 +1 @@ +from thread import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/cPickle.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/cPickle.pyi new file mode 100644 index 000000000..ca829a750 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/cPickle.pyi @@ -0,0 +1 @@ +from cPickle import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/configparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/configparser.pyi new file mode 100644 index 000000000..b2da53afb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/configparser.pyi @@ -0,0 +1 @@ +from ConfigParser import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/email_mime_text.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/email_mime_text.pyi new file mode 100644 index 000000000..214bf1e24 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/email_mime_text.pyi @@ -0,0 +1 @@ +from email.MIMEText import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/html_entities.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/html_entities.pyi new file mode 100644 index 000000000..9e15d010d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/html_entities.pyi @@ -0,0 +1 @@ +from htmlentitydefs import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/html_parser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/html_parser.pyi new file mode 100644 index 000000000..984cee67f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/html_parser.pyi @@ -0,0 +1 @@ +from HTMLParser import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_client.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_client.pyi new file mode 100644 index 000000000..24ef0b4cb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_client.pyi @@ -0,0 +1 @@ +from httplib import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_cookiejar.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_cookiejar.pyi new file mode 100644 index 000000000..1357ad3b0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_cookiejar.pyi @@ -0,0 +1 @@ +from cookielib import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_cookies.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_cookies.pyi new file mode 100644 index 000000000..5115c0dff --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/http_cookies.pyi @@ -0,0 +1 @@ +from Cookie import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/queue.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/queue.pyi new file mode 100644 index 000000000..7ce3ccb32 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/queue.pyi @@ -0,0 +1 @@ +from Queue import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/reprlib.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/reprlib.pyi new file mode 100644 index 000000000..40ad10384 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/reprlib.pyi @@ -0,0 +1 @@ +from repr import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/socketserver.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/socketserver.pyi new file mode 100644 index 000000000..c80a6e7b5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/socketserver.pyi @@ -0,0 +1 @@ +from SocketServer import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/__init__.pyi new file mode 100644 index 000000000..d08209c51 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/__init__.pyi @@ -0,0 +1,5 @@ +import six.moves.urllib.error as error +import six.moves.urllib.parse as parse +import six.moves.urllib.request as request +import six.moves.urllib.response as response +import six.moves.urllib.robotparser as robotparser diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/error.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/error.pyi new file mode 100644 index 000000000..044327ee4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/error.pyi @@ -0,0 +1,3 @@ +from urllib2 import URLError as URLError +from urllib2 import HTTPError as HTTPError +from urllib import ContentTooShortError as ContentTooShortError diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/parse.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/parse.pyi new file mode 100644 index 000000000..4096c27fa --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/parse.pyi @@ -0,0 +1,24 @@ +# Stubs for six.moves.urllib.parse +from urlparse import ParseResult as ParseResult +from urlparse import SplitResult as SplitResult +from urlparse import parse_qs as parse_qs +from urlparse import parse_qsl as parse_qsl +from urlparse import urldefrag as urldefrag +from urlparse import urljoin as urljoin +from urlparse import urlparse as urlparse +from urlparse import urlsplit as urlsplit +from urlparse import urlunparse as urlunparse +from urlparse import urlunsplit as urlunsplit +from urllib import quote as quote +from urllib import quote_plus as quote_plus +from urllib import unquote as unquote +from urllib import unquote_plus as unquote_plus +from urllib import urlencode as urlencode +from urllib import splitquery as splitquery +from urllib import splittag as splittag +from urllib import splituser as splituser +from urlparse import uses_fragment as uses_fragment +from urlparse import uses_netloc as uses_netloc +from urlparse import uses_params as uses_params +from urlparse import uses_query as uses_query +from urlparse import uses_relative as uses_relative diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/request.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/request.pyi new file mode 100644 index 000000000..0b8ad8cff --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/request.pyi @@ -0,0 +1,34 @@ +# Stubs for six.moves.urllib.request +from urllib2 import urlopen as urlopen +from urllib2 import install_opener as install_opener +from urllib2 import build_opener as build_opener +from urllib import pathname2url as pathname2url +from urllib import url2pathname as url2pathname +from urllib import getproxies as getproxies +from urllib2 import Request as Request +from urllib2 import OpenerDirector as OpenerDirector +from urllib2 import HTTPDefaultErrorHandler as HTTPDefaultErrorHandler +from urllib2 import HTTPRedirectHandler as HTTPRedirectHandler +from urllib2 import HTTPCookieProcessor as HTTPCookieProcessor +from urllib2 import ProxyHandler as ProxyHandler +from urllib2 import BaseHandler as BaseHandler +from urllib2 import HTTPPasswordMgr as HTTPPasswordMgr +from urllib2 import HTTPPasswordMgrWithDefaultRealm as HTTPPasswordMgrWithDefaultRealm +from urllib2 import AbstractBasicAuthHandler as AbstractBasicAuthHandler +from urllib2 import HTTPBasicAuthHandler as HTTPBasicAuthHandler +from urllib2 import ProxyBasicAuthHandler as ProxyBasicAuthHandler +from urllib2 import AbstractDigestAuthHandler as AbstractDigestAuthHandler +from urllib2 import HTTPDigestAuthHandler as HTTPDigestAuthHandler +from urllib2 import ProxyDigestAuthHandler as ProxyDigestAuthHandler +from urllib2 import HTTPHandler as HTTPHandler +from urllib2 import HTTPSHandler as HTTPSHandler +from urllib2 import FileHandler as FileHandler +from urllib2 import FTPHandler as FTPHandler +from urllib2 import CacheFTPHandler as CacheFTPHandler +from urllib2 import UnknownHandler as UnknownHandler +from urllib2 import HTTPErrorProcessor as HTTPErrorProcessor +from urllib import urlretrieve as urlretrieve +from urllib import urlcleanup as urlcleanup +from urllib import URLopener as URLopener +from urllib import FancyURLopener as FancyURLopener +from urllib import proxy_bypass as proxy_bypass diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/response.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/response.pyi new file mode 100644 index 000000000..83e117fb6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/response.pyi @@ -0,0 +1,5 @@ +# Stubs for six.moves.urllib.response +from urllib import addbase as addbase +from urllib import addclosehook as addclosehook +from urllib import addinfo as addinfo +from urllib import addinfourl as addinfourl diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/robotparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/robotparser.pyi new file mode 100644 index 000000000..11eef5040 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib/robotparser.pyi @@ -0,0 +1 @@ +from robotparser import RobotFileParser as RobotFileParser diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_error.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_error.pyi new file mode 100644 index 000000000..b5608125d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_error.pyi @@ -0,0 +1 @@ +from .urllib.error import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_parse.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_parse.pyi new file mode 100644 index 000000000..bdb4d1c03 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_parse.pyi @@ -0,0 +1 @@ +from .urllib.parse import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_robotparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_robotparser.pyi new file mode 100644 index 000000000..ddb63b781 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/urllib_robotparser.pyi @@ -0,0 +1 @@ +from robotparser import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/xmlrpc_client.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/xmlrpc_client.pyi new file mode 100644 index 000000000..1b3bd7468 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/six/moves/xmlrpc_client.pyi @@ -0,0 +1 @@ +from xmlrpclib import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/concurrent.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/concurrent.pyi new file mode 100644 index 000000000..82c29dac5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/concurrent.pyi @@ -0,0 +1,43 @@ +from typing import Any + +futures = ... # type: Any + +class ReturnValueIgnoredError(Exception): ... + +class _TracebackLogger: + exc_info = ... # type: Any + formatted_tb = ... # type: Any + def __init__(self, exc_info) -> None: ... + def activate(self): ... + def clear(self): ... + def __del__(self): ... + +class Future: + def __init__(self) -> None: ... + def cancel(self): ... + def cancelled(self): ... + def running(self): ... + def done(self): ... + def result(self, timeout=...): ... + def exception(self, timeout=...): ... + def add_done_callback(self, fn): ... + def set_result(self, result): ... + def set_exception(self, exception): ... + def exc_info(self): ... + def set_exc_info(self, exc_info): ... + def __del__(self): ... + +TracebackFuture = ... # type: Any +FUTURES = ... # type: Any + +def is_future(x): ... + +class DummyExecutor: + def submit(self, fn, *args, **kwargs): ... + def shutdown(self, wait=...): ... + +dummy_executor = ... # type: Any + +def run_on_executor(*args, **kwargs): ... +def return_future(f): ... +def chain_future(a, b): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/gen.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/gen.pyi new file mode 100644 index 000000000..4ec96b5af --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/gen.pyi @@ -0,0 +1,109 @@ +from typing import Any +from collections import namedtuple + +singledispatch = ... # type: Any + +class KeyReuseError(Exception): ... +class UnknownKeyError(Exception): ... +class LeakedCallbackError(Exception): ... +class BadYieldError(Exception): ... +class ReturnValueIgnoredError(Exception): ... +class TimeoutError(Exception): ... + +def engine(func): ... +def coroutine(func, replace_callback=...): ... + +class Return(Exception): + value = ... # type: Any + def __init__(self, value=...) -> None: ... + +class WaitIterator: + current_index = ... # type: Any + def __init__(self, *args, **kwargs) -> None: ... + def done(self): ... + def next(self): ... + +class YieldPoint: + def start(self, runner): ... + def is_ready(self): ... + def get_result(self): ... + +class Callback(YieldPoint): + key = ... # type: Any + def __init__(self, key) -> None: ... + runner = ... # type: Any + def start(self, runner): ... + def is_ready(self): ... + def get_result(self): ... + +class Wait(YieldPoint): + key = ... # type: Any + def __init__(self, key) -> None: ... + runner = ... # type: Any + def start(self, runner): ... + def is_ready(self): ... + def get_result(self): ... + +class WaitAll(YieldPoint): + keys = ... # type: Any + def __init__(self, keys) -> None: ... + runner = ... # type: Any + def start(self, runner): ... + def is_ready(self): ... + def get_result(self): ... + +def Task(func, *args, **kwargs): ... + +class YieldFuture(YieldPoint): + future = ... # type: Any + io_loop = ... # type: Any + def __init__(self, future, io_loop=...) -> None: ... + runner = ... # type: Any + key = ... # type: Any + result_fn = ... # type: Any + def start(self, runner): ... + def is_ready(self): ... + def get_result(self): ... + +class Multi(YieldPoint): + keys = ... # type: Any + children = ... # type: Any + unfinished_children = ... # type: Any + quiet_exceptions = ... # type: Any + def __init__(self, children, quiet_exceptions=...) -> None: ... + def start(self, runner): ... + def is_ready(self): ... + def get_result(self): ... + +def multi_future(children, quiet_exceptions=...): ... +def maybe_future(x): ... +def with_timeout(timeout, future, io_loop=..., quiet_exceptions=...): ... +def sleep(duration): ... + +moment = ... # type: Any + +class Runner: + gen = ... # type: Any + result_future = ... # type: Any + future = ... # type: Any + yield_point = ... # type: Any + pending_callbacks = ... # type: Any + results = ... # type: Any + running = ... # type: Any + finished = ... # type: Any + had_exception = ... # type: Any + io_loop = ... # type: Any + stack_context_deactivate = ... # type: Any + def __init__(self, gen, result_future, first_yielded) -> None: ... + def register_callback(self, key): ... + def is_ready(self, key): ... + def set_result(self, key, result): ... + def pop_result(self, key): ... + def run(self): ... + def handle_yield(self, yielded): ... + def result_callback(self, key): ... + def handle_exception(self, typ, value, tb): ... + +Arguments = namedtuple('Arguments', ['args', 'kwargs']) + +def convert_yielded(yielded): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httpclient.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httpclient.pyi new file mode 100644 index 000000000..d3c7127cd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httpclient.pyi @@ -0,0 +1,108 @@ +from typing import Any +from tornado.util import Configurable + +class HTTPClient: + def __init__(self, async_client_class=..., **kwargs) -> None: ... + def __del__(self): ... + def close(self): ... + def fetch(self, request, **kwargs): ... + +class AsyncHTTPClient(Configurable): + @classmethod + def configurable_base(cls): ... + @classmethod + def configurable_default(cls): ... + def __new__(cls, io_loop=..., force_instance=..., **kwargs): ... + io_loop = ... # type: Any + defaults = ... # type: Any + def initialize(self, io_loop, defaults=...): ... + def close(self): ... + def fetch(self, request, callback=..., raise_error=..., **kwargs): ... + def fetch_impl(self, request, callback): ... + @classmethod + def configure(cls, impl, **kwargs): ... + +class HTTPRequest: + headers = ... # type: Any + proxy_host = ... # type: Any + proxy_port = ... # type: Any + proxy_username = ... # type: Any + proxy_password = ... # type: Any + url = ... # type: Any + method = ... # type: Any + body = ... # type: Any + body_producer = ... # type: Any + auth_username = ... # type: Any + auth_password = ... # type: Any + auth_mode = ... # type: Any + connect_timeout = ... # type: Any + request_timeout = ... # type: Any + follow_redirects = ... # type: Any + max_redirects = ... # type: Any + user_agent = ... # type: Any + decompress_response = ... # type: Any + network_interface = ... # type: Any + streaming_callback = ... # type: Any + header_callback = ... # type: Any + prepare_curl_callback = ... # type: Any + allow_nonstandard_methods = ... # type: Any + validate_cert = ... # type: Any + ca_certs = ... # type: Any + allow_ipv6 = ... # type: Any + client_key = ... # type: Any + client_cert = ... # type: Any + ssl_options = ... # type: Any + expect_100_continue = ... # type: Any + start_time = ... # type: Any + def __init__(self, url, method=..., headers=..., body=..., auth_username=..., auth_password=..., auth_mode=..., connect_timeout=..., request_timeout=..., if_modified_since=..., follow_redirects=..., max_redirects=..., user_agent=..., use_gzip=..., network_interface=..., streaming_callback=..., header_callback=..., prepare_curl_callback=..., proxy_host=..., proxy_port=..., proxy_username=..., proxy_password=..., allow_nonstandard_methods=..., validate_cert=..., ca_certs=..., allow_ipv6=..., client_key=..., client_cert=..., body_producer=..., expect_100_continue=..., decompress_response=..., ssl_options=...) -> None: ... + @property + def headers(self): ... + @headers.setter + def headers(self, value): ... + @property + def body(self): ... + @body.setter + def body(self, value): ... + @property + def body_producer(self): ... + @body_producer.setter + def body_producer(self, value): ... + @property + def streaming_callback(self): ... + @streaming_callback.setter + def streaming_callback(self, value): ... + @property + def header_callback(self): ... + @header_callback.setter + def header_callback(self, value): ... + @property + def prepare_curl_callback(self): ... + @prepare_curl_callback.setter + def prepare_curl_callback(self, value): ... + +class HTTPResponse: + request = ... # type: Any + code = ... # type: Any + reason = ... # type: Any + headers = ... # type: Any + buffer = ... # type: Any + effective_url = ... # type: Any + error = ... # type: Any + request_time = ... # type: Any + time_info = ... # type: Any + def __init__(self, request, code, headers=..., buffer=..., effective_url=..., error=..., request_time=..., time_info=..., reason=...) -> None: ... + body = ... # type: Any + def rethrow(self): ... + +class HTTPError(Exception): + code = ... # type: Any + response = ... # type: Any + def __init__(self, code, message=..., response=...) -> None: ... + +class _RequestProxy: + request = ... # type: Any + defaults = ... # type: Any + def __init__(self, request, defaults) -> None: ... + def __getattr__(self, name): ... + +def main(): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httpserver.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httpserver.pyi new file mode 100644 index 000000000..3738c85b4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httpserver.pyi @@ -0,0 +1,41 @@ +from typing import Any +from tornado import httputil +from tornado.tcpserver import TCPServer +from tornado.util import Configurable + +class HTTPServer(TCPServer, Configurable, httputil.HTTPServerConnectionDelegate): + def __init__(self, *args, **kwargs) -> None: ... + request_callback = ... # type: Any + no_keep_alive = ... # type: Any + xheaders = ... # type: Any + protocol = ... # type: Any + conn_params = ... # type: Any + def initialize(self, request_callback, no_keep_alive=..., io_loop=..., xheaders=..., ssl_options=..., protocol=..., decompress_request=..., chunk_size=..., max_header_size=..., idle_connection_timeout=..., body_timeout=..., max_body_size=..., max_buffer_size=...): ... + @classmethod + def configurable_base(cls): ... + @classmethod + def configurable_default(cls): ... + def close_all_connections(self): ... + def handle_stream(self, stream, address): ... + def start_request(self, server_conn, request_conn): ... + def on_close(self, server_conn): ... + +class _HTTPRequestContext: + address = ... # type: Any + protocol = ... # type: Any + address_family = ... # type: Any + remote_ip = ... # type: Any + def __init__(self, stream, address, protocol) -> None: ... + +class _ServerRequestAdapter(httputil.HTTPMessageDelegate): + server = ... # type: Any + connection = ... # type: Any + request = ... # type: Any + delegate = ... # type: Any + def __init__(self, server, server_conn, request_conn) -> None: ... + def headers_received(self, start_line, headers): ... + def data_received(self, chunk): ... + def finish(self): ... + def on_connection_close(self): ... + +HTTPRequest = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httputil.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httputil.pyi new file mode 100644 index 000000000..bdcbfa5b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/httputil.pyi @@ -0,0 +1,89 @@ +from typing import Any +from tornado.util import ObjectDict +from collections import namedtuple + +class SSLError(Exception): ... + +class _NormalizedHeaderCache(dict): + size = ... # type: Any + queue = ... # type: Any + def __init__(self, size) -> None: ... + def __missing__(self, key): ... + +class HTTPHeaders(dict): + def __init__(self, *args, **kwargs) -> None: ... + def add(self, name, value): ... + def get_list(self, name): ... + def get_all(self): ... + def parse_line(self, line): ... + @classmethod + def parse(cls, headers): ... + def __setitem__(self, name, value): ... + def __getitem__(self, name): ... + def __delitem__(self, name): ... + def __contains__(self, name): ... + def get(self, name, default=...): ... + def update(self, *args, **kwargs): ... + def copy(self): ... + __copy__ = ... # type: Any + def __deepcopy__(self, memo_dict): ... + +class HTTPServerRequest: + method = ... # type: Any + uri = ... # type: Any + version = ... # type: Any + headers = ... # type: Any + body = ... # type: Any + remote_ip = ... # type: Any + protocol = ... # type: Any + host = ... # type: Any + files = ... # type: Any + connection = ... # type: Any + arguments = ... # type: Any + query_arguments = ... # type: Any + body_arguments = ... # type: Any + def __init__(self, method=..., uri=..., version=..., headers=..., body=..., host=..., files=..., connection=..., start_line=...) -> None: ... + def supports_http_1_1(self): ... + @property + def cookies(self): ... + def write(self, chunk, callback=...): ... + def finish(self): ... + def full_url(self): ... + def request_time(self): ... + def get_ssl_certificate(self, binary_form=...): ... + +class HTTPInputError(Exception): ... +class HTTPOutputError(Exception): ... + +class HTTPServerConnectionDelegate: + def start_request(self, server_conn, request_conn): ... + def on_close(self, server_conn): ... + +class HTTPMessageDelegate: + def headers_received(self, start_line, headers): ... + def data_received(self, chunk): ... + def finish(self): ... + def on_connection_close(self): ... + +class HTTPConnection: + def write_headers(self, start_line, headers, chunk=..., callback=...): ... + def write(self, chunk, callback=...): ... + def finish(self): ... + +def url_concat(url, args): ... + +class HTTPFile(ObjectDict): ... + +def parse_body_arguments(content_type, body, arguments, files, headers=...): ... +def parse_multipart_form_data(boundary, data, arguments, files): ... +def format_timestamp(ts): ... + +RequestStartLine = namedtuple('RequestStartLine', ['method', 'path', 'version']) + +def parse_request_start_line(line): ... + +ResponseStartLine = namedtuple('ResponseStartLine', ['version', 'code', 'reason']) + +def parse_response_start_line(line): ... +def doctests(): ... +def split_host_and_port(netloc): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/ioloop.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/ioloop.pyi new file mode 100644 index 000000000..e4f97e7ee --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/ioloop.pyi @@ -0,0 +1,84 @@ +from typing import Any +from tornado.util import Configurable + +signal = ... # type: Any + +class TimeoutError(Exception): ... + +class IOLoop(Configurable): + NONE = ... # type: Any + READ = ... # type: Any + WRITE = ... # type: Any + ERROR = ... # type: Any + @staticmethod + def instance(): ... + @staticmethod + def initialized(): ... + def install(self): ... + @staticmethod + def clear_instance(): ... + @staticmethod + def current(instance=...): ... + def make_current(self): ... + @staticmethod + def clear_current(): ... + @classmethod + def configurable_base(cls): ... + @classmethod + def configurable_default(cls): ... + def initialize(self, make_current=...): ... + def close(self, all_fds=...): ... + def add_handler(self, fd, handler, events): ... + def update_handler(self, fd, events): ... + def remove_handler(self, fd): ... + def set_blocking_signal_threshold(self, seconds, action): ... + def set_blocking_log_threshold(self, seconds): ... + def log_stack(self, signal, frame): ... + def start(self): ... + def stop(self): ... + def run_sync(self, func, timeout=...): ... + def time(self): ... + def add_timeout(self, deadline, callback, *args, **kwargs): ... + def call_later(self, delay, callback, *args, **kwargs): ... + def call_at(self, when, callback, *args, **kwargs): ... + def remove_timeout(self, timeout): ... + def add_callback(self, callback, *args, **kwargs): ... + def add_callback_from_signal(self, callback, *args, **kwargs): ... + def spawn_callback(self, callback, *args, **kwargs): ... + def add_future(self, future, callback): ... + def handle_callback_exception(self, callback): ... + def split_fd(self, fd): ... + def close_fd(self, fd): ... + +class PollIOLoop(IOLoop): + time_func = ... # type: Any + def initialize(self, impl, time_func=..., **kwargs): ... + def close(self, all_fds=...): ... + def add_handler(self, fd, handler, events): ... + def update_handler(self, fd, events): ... + def remove_handler(self, fd): ... + def set_blocking_signal_threshold(self, seconds, action): ... + def start(self): ... + def stop(self): ... + def time(self): ... + def call_at(self, deadline, callback, *args, **kwargs): ... + def remove_timeout(self, timeout): ... + def add_callback(self, callback, *args, **kwargs): ... + def add_callback_from_signal(self, callback, *args, **kwargs): ... + +class _Timeout: + deadline = ... # type: Any + callback = ... # type: Any + tiebreaker = ... # type: Any + def __init__(self, deadline, callback, io_loop) -> None: ... + def __lt__(self, other): ... + def __le__(self, other): ... + +class PeriodicCallback: + callback = ... # type: Any + callback_time = ... # type: Any + io_loop = ... # type: Any + def __init__(self, callback, callback_time, io_loop=...) -> None: ... + def start(self): ... + def stop(self): ... + def is_running(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/locks.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/locks.pyi new file mode 100644 index 000000000..eaeba24f8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/locks.pyi @@ -0,0 +1,45 @@ +from typing import Any + +class _TimeoutGarbageCollector: + def __init__(self): ... + +class Condition(_TimeoutGarbageCollector): + io_loop = ... # type: Any + def __init__(self): ... + def wait(self, timeout=None): ... + def notify(self, n=1): ... + def notify_all(self): ... + +class Event: + def __init__(self): ... + def is_set(self): ... + def set(self): ... + def clear(self): ... + def wait(self, timeout=None): ... + +class _ReleasingContextManager: + def __init__(self, obj): ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_val, exc_tb): ... + +class Semaphore(_TimeoutGarbageCollector): + def __init__(self, value=1): ... + def release(self): ... + def acquire(self, timeout=None): ... + def __enter__(self): ... + __exit__ = ... # type: Any + def __aenter__(self): ... + def __aexit__(self, typ, value, tb): ... + +class BoundedSemaphore(Semaphore): + def __init__(self, value=1): ... + def release(self): ... + +class Lock: + def __init__(self): ... + def acquire(self, timeout=None): ... + def release(self): ... + def __enter__(self): ... + __exit__ = ... # type: Any + def __aenter__(self): ... + def __aexit__(self, typ, value, tb): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/netutil.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/netutil.pyi new file mode 100644 index 000000000..b12154b6b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/netutil.pyi @@ -0,0 +1,45 @@ +from typing import Any +from tornado.util import Configurable + +ssl = ... # type: Any +certifi = ... # type: Any +xrange = ... # type: Any +ssl_match_hostname = ... # type: Any +SSLCertificateError = ... # type: Any + +def bind_sockets(port, address=..., family=..., backlog=..., flags=...): ... +def bind_unix_socket(file, mode=..., backlog=...): ... +def add_accept_handler(sock, callback, io_loop=...): ... +def is_valid_ip(ip): ... + +class Resolver(Configurable): + @classmethod + def configurable_base(cls): ... + @classmethod + def configurable_default(cls): ... + def resolve(self, host, port, family=..., callback=...): ... + def close(self): ... + +class ExecutorResolver(Resolver): + io_loop = ... # type: Any + executor = ... # type: Any + close_executor = ... # type: Any + def initialize(self, io_loop=..., executor=..., close_executor=...): ... + def close(self): ... + def resolve(self, host, port, family=...): ... + +class BlockingResolver(ExecutorResolver): + def initialize(self, io_loop=...): ... + +class ThreadedResolver(ExecutorResolver): + def initialize(self, io_loop=..., num_threads=...): ... + +class OverrideResolver(Resolver): + resolver = ... # type: Any + mapping = ... # type: Any + def initialize(self, resolver, mapping): ... + def close(self): ... + def resolve(self, host, port, *args, **kwargs): ... + +def ssl_options_to_context(ssl_options): ... +def ssl_wrap_socket(socket, ssl_options, server_hostname=..., **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/process.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/process.pyi new file mode 100644 index 000000000..c46745498 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/process.pyi @@ -0,0 +1,24 @@ +from typing import Any, Optional + +long = int +CalledProcessError: Any + +def cpu_count() -> int: ... +def fork_processes(num_processes, max_restarts: int = ...) -> Optional[int]: ... +def task_id() -> int: ... + +class Subprocess: + STREAM: Any = ... + io_loop: Any = ... + stdin: Any = ... + stdout: Any = ... + stderr: Any = ... + proc: Any = ... + returncode: Any = ... + def __init__(self, *args, **kwargs) -> None: ... + def set_exit_callback(self, callback): ... + def wait_for_exit(self, raise_error: bool = ...): ... + @classmethod + def initialize(cls, io_loop: Optional[Any] = ...): ... + @classmethod + def uninitialize(cls): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/tcpserver.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/tcpserver.pyi new file mode 100644 index 000000000..489e4d4ec --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/tcpserver.pyi @@ -0,0 +1,17 @@ +from typing import Any + +ssl = ... # type: Any + +class TCPServer: + io_loop = ... # type: Any + ssl_options = ... # type: Any + max_buffer_size = ... # type: Any + read_chunk_size = ... # type: Any + def __init__(self, io_loop=..., ssl_options=..., max_buffer_size=..., read_chunk_size=...) -> None: ... + def listen(self, port, address=...): ... + def add_sockets(self, sockets): ... + def add_socket(self, socket): ... + def bind(self, port, address=..., family=..., backlog=...): ... + def start(self, num_processes=...): ... + def stop(self): ... + def handle_stream(self, stream, address): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/testing.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/testing.pyi new file mode 100644 index 000000000..5b8c6626d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/testing.pyi @@ -0,0 +1,60 @@ +from typing import Any +import unittest +import logging + +AsyncHTTPClient = ... # type: Any +gen = ... # type: Any +HTTPServer = ... # type: Any +IOLoop = ... # type: Any +netutil = ... # type: Any +SimpleAsyncHTTPClient = ... # type: Any + +def get_unused_port(): ... +def bind_unused_port(): ... + +class AsyncTestCase(unittest.TestCase): + def __init__(self, *args, **kwargs): ... + io_loop = ... # type: Any + def setUp(self): ... + def tearDown(self): ... + def get_new_ioloop(self): ... + def run(self, result=None): ... + def stop(self, _arg=None, **kwargs): ... + def wait(self, condition=None, timeout=5): ... + +class AsyncHTTPTestCase(AsyncTestCase): + http_client = ... # type: Any + http_server = ... # type: Any + def setUp(self): ... + def get_http_client(self): ... + def get_http_server(self): ... + def get_app(self): ... + def fetch(self, path, **kwargs): ... + def get_httpserver_options(self): ... + def get_http_port(self): ... + def get_protocol(self): ... + def get_url(self, path): ... + def tearDown(self): ... + +class AsyncHTTPSTestCase(AsyncHTTPTestCase): + def get_http_client(self): ... + def get_httpserver_options(self): ... + def get_ssl_options(self): ... + def get_protocol(self): ... + +def gen_test(f): ... + +class LogTrapTestCase(unittest.TestCase): + def run(self, result=None): ... + +class ExpectLog(logging.Filter): + logger = ... # type: Any + regex = ... # type: Any + required = ... # type: Any + matched = ... # type: Any + def __init__(self, logger, regex, required=True): ... + def filter(self, record): ... + def __enter__(self): ... + def __exit__(self, typ, value, tb): ... + +def main(**kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/util.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/util.pyi new file mode 100644 index 000000000..cf535c402 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/util.pyi @@ -0,0 +1,46 @@ +from typing import Any + +xrange = ... # type: Any + +class ObjectDict(dict): + def __getattr__(self, name): ... + def __setattr__(self, name, value): ... + +class GzipDecompressor: + decompressobj = ... # type: Any + def __init__(self) -> None: ... + def decompress(self, value, max_length=...): ... + @property + def unconsumed_tail(self): ... + def flush(self): ... + +unicode_type = ... # type: Any +basestring_type = ... # type: Any + +def import_object(name): ... + +bytes_type = ... # type: Any + +def errno_from_exception(e): ... + +class Configurable: + def __new__(cls, *args, **kwargs): ... + @classmethod + def configurable_base(cls): ... + @classmethod + def configurable_default(cls): ... + def initialize(self): ... + @classmethod + def configure(cls, impl, **kwargs): ... + @classmethod + def configured_class(cls): ... + +class ArgReplacer: + name = ... # type: Any + arg_pos = ... # type: Any + def __init__(self, func, name) -> None: ... + def get_old_value(self, args, kwargs, default=...): ... + def replace(self, new_value, args, kwargs): ... + +def timedelta_to_seconds(td): ... +def doctests(): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/web.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/web.pyi new file mode 100644 index 000000000..69e5a3726 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2/tornado/web.pyi @@ -0,0 +1,257 @@ +from typing import Any +from tornado import httputil + +MIN_SUPPORTED_SIGNED_VALUE_VERSION = ... # type: Any +MAX_SUPPORTED_SIGNED_VALUE_VERSION = ... # type: Any +DEFAULT_SIGNED_VALUE_VERSION = ... # type: Any +DEFAULT_SIGNED_VALUE_MIN_VERSION = ... # type: Any + +class RequestHandler: + SUPPORTED_METHODS = ... # type: Any + application = ... # type: Any + request = ... # type: Any + path_args = ... # type: Any + path_kwargs = ... # type: Any + ui = ... # type: Any + def __init__(self, application, request, **kwargs) -> None: ... + def initialize(self): ... + @property + def settings(self): ... + def head(self, *args, **kwargs): ... + def get(self, *args, **kwargs): ... + def post(self, *args, **kwargs): ... + def delete(self, *args, **kwargs): ... + def patch(self, *args, **kwargs): ... + def put(self, *args, **kwargs): ... + def options(self, *args, **kwargs): ... + def prepare(self): ... + def on_finish(self): ... + def on_connection_close(self): ... + def clear(self): ... + def set_default_headers(self): ... + def set_status(self, status_code, reason=...): ... + def get_status(self): ... + def set_header(self, name, value): ... + def add_header(self, name, value): ... + def clear_header(self, name): ... + def get_argument(self, name, default=..., strip=...): ... + def get_arguments(self, name, strip=...): ... + def get_body_argument(self, name, default=..., strip=...): ... + def get_body_arguments(self, name, strip=...): ... + def get_query_argument(self, name, default=..., strip=...): ... + def get_query_arguments(self, name, strip=...): ... + def decode_argument(self, value, name=...): ... + @property + def cookies(self): ... + def get_cookie(self, name, default=...): ... + def set_cookie(self, name, value, domain=..., expires=..., path=..., expires_days=..., **kwargs): ... + def clear_cookie(self, name, path=..., domain=...): ... + def clear_all_cookies(self, path=..., domain=...): ... + def set_secure_cookie(self, name, value, expires_days=..., version=..., **kwargs): ... + def create_signed_value(self, name, value, version=...): ... + def get_secure_cookie(self, name, value=..., max_age_days=..., min_version=...): ... + def get_secure_cookie_key_version(self, name, value=...): ... + def redirect(self, url, permanent=..., status=...): ... + def write(self, chunk): ... + def render(self, template_name, **kwargs): ... + def render_string(self, template_name, **kwargs): ... + def get_template_namespace(self): ... + def create_template_loader(self, template_path): ... + def flush(self, include_footers=..., callback=...): ... + def finish(self, chunk=...): ... + def send_error(self, status_code=..., **kwargs): ... + def write_error(self, status_code, **kwargs): ... + @property + def locale(self): ... + @locale.setter + def locale(self, value): ... + def get_user_locale(self): ... + def get_browser_locale(self, default=...): ... + @property + def current_user(self): ... + @current_user.setter + def current_user(self, value): ... + def get_current_user(self): ... + def get_login_url(self): ... + def get_template_path(self): ... + @property + def xsrf_token(self): ... + def check_xsrf_cookie(self): ... + def xsrf_form_html(self): ... + def static_url(self, path, include_host=..., **kwargs): ... + def require_setting(self, name, feature=...): ... + def reverse_url(self, name, *args): ... + def compute_etag(self): ... + def set_etag_header(self): ... + def check_etag_header(self): ... + def data_received(self, chunk): ... + def log_exception(self, typ, value, tb): ... + +def asynchronous(method): ... +def stream_request_body(cls): ... +def removeslash(method): ... +def addslash(method): ... + +class Application(httputil.HTTPServerConnectionDelegate): + transforms = ... # type: Any + handlers = ... # type: Any + named_handlers = ... # type: Any + default_host = ... # type: Any + settings = ... # type: Any + ui_modules = ... # type: Any + ui_methods = ... # type: Any + def __init__(self, handlers=..., default_host=..., transforms=..., **settings) -> None: ... + def listen(self, port, address=..., **kwargs): ... + def add_handlers(self, host_pattern, host_handlers): ... + def add_transform(self, transform_class): ... + def start_request(self, server_conn, request_conn): ... + def __call__(self, request): ... + def reverse_url(self, name, *args): ... + def log_request(self, handler): ... + +class _RequestDispatcher(httputil.HTTPMessageDelegate): + application = ... # type: Any + connection = ... # type: Any + request = ... # type: Any + chunks = ... # type: Any + handler_class = ... # type: Any + handler_kwargs = ... # type: Any + path_args = ... # type: Any + path_kwargs = ... # type: Any + def __init__(self, application, connection) -> None: ... + def headers_received(self, start_line, headers): ... + stream_request_body = ... # type: Any + def set_request(self, request): ... + def data_received(self, data): ... + def finish(self): ... + def on_connection_close(self): ... + handler = ... # type: Any + def execute(self): ... + +class HTTPError(Exception): + status_code = ... # type: Any + log_message = ... # type: Any + args = ... # type: Any + reason = ... # type: Any + def __init__(self, status_code, log_message=..., *args, **kwargs) -> None: ... + +class Finish(Exception): ... + +class MissingArgumentError(HTTPError): + arg_name = ... # type: Any + def __init__(self, arg_name) -> None: ... + +class ErrorHandler(RequestHandler): + def initialize(self, status_code): ... + def prepare(self): ... + def check_xsrf_cookie(self): ... + +class RedirectHandler(RequestHandler): + def initialize(self, url, permanent=...): ... + def get(self): ... + +class StaticFileHandler(RequestHandler): + CACHE_MAX_AGE = ... # type: Any + root = ... # type: Any + default_filename = ... # type: Any + def initialize(self, path, default_filename=...): ... + @classmethod + def reset(cls): ... + def head(self, path): ... + path = ... # type: Any + absolute_path = ... # type: Any + modified = ... # type: Any + def get(self, path, include_body=...): ... + def compute_etag(self): ... + def set_headers(self): ... + def should_return_304(self): ... + @classmethod + def get_absolute_path(cls, root, path): ... + def validate_absolute_path(self, root, absolute_path): ... + @classmethod + def get_content(cls, abspath, start=..., end=...): ... + @classmethod + def get_content_version(cls, abspath): ... + def get_content_size(self): ... + def get_modified_time(self): ... + def get_content_type(self): ... + def set_extra_headers(self, path): ... + def get_cache_time(self, path, modified, mime_type): ... + @classmethod + def make_static_url(cls, settings, path, include_version=...): ... + def parse_url_path(self, url_path): ... + @classmethod + def get_version(cls, settings, path): ... + +class FallbackHandler(RequestHandler): + fallback = ... # type: Any + def initialize(self, fallback): ... + def prepare(self): ... + +class OutputTransform: + def __init__(self, request) -> None: ... + def transform_first_chunk(self, status_code, headers, chunk, finishing): ... + def transform_chunk(self, chunk, finishing): ... + +class GZipContentEncoding(OutputTransform): + CONTENT_TYPES = ... # type: Any + MIN_LENGTH = ... # type: Any + def __init__(self, request) -> None: ... + def transform_first_chunk(self, status_code, headers, chunk, finishing): ... + def transform_chunk(self, chunk, finishing): ... + +def authenticated(method): ... + +class UIModule: + handler = ... # type: Any + request = ... # type: Any + ui = ... # type: Any + locale = ... # type: Any + def __init__(self, handler) -> None: ... + @property + def current_user(self): ... + def render(self, *args, **kwargs): ... + def embedded_javascript(self): ... + def javascript_files(self): ... + def embedded_css(self): ... + def css_files(self): ... + def html_head(self): ... + def html_body(self): ... + def render_string(self, path, **kwargs): ... + +class _linkify(UIModule): + def render(self, text, **kwargs): ... + +class _xsrf_form_html(UIModule): + def render(self): ... + +class TemplateModule(UIModule): + def __init__(self, handler) -> None: ... + def render(self, path, **kwargs): ... + def embedded_javascript(self): ... + def javascript_files(self): ... + def embedded_css(self): ... + def css_files(self): ... + def html_head(self): ... + def html_body(self): ... + +class _UIModuleNamespace: + handler = ... # type: Any + ui_modules = ... # type: Any + def __init__(self, handler, ui_modules) -> None: ... + def __getitem__(self, key): ... + def __getattr__(self, key): ... + +class URLSpec: + regex = ... # type: Any + handler_class = ... # type: Any + kwargs = ... # type: Any + name = ... # type: Any + def __init__(self, pattern, handler, kwargs=..., name=...) -> None: ... + def reverse(self, *args): ... + +url = ... # type: Any + +def create_signed_value(secret, name, value, version=..., clock=..., key_version=...): ... +def decode_signed_value(secret, name, value, max_age_days=..., clock=..., min_version=...): ... +def get_signature_key_version(value): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/AES.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/AES.pyi new file mode 100644 index 000000000..b23eacc4a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/AES.pyi @@ -0,0 +1,19 @@ +from typing import Any, Union, Text +from .blockalgo import BlockAlgo + +__revision__ = ... # type: str + +class AESCipher(BlockAlgo): + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> AESCipher: ... + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int +block_size = ... # type: int +key_size = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/ARC2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/ARC2.pyi new file mode 100644 index 000000000..93aea85ac --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/ARC2.pyi @@ -0,0 +1,19 @@ +from typing import Any, Union, Text +from .blockalgo import BlockAlgo + +__revision__ = ... # type: str + +class RC2Cipher(BlockAlgo): + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> RC2Cipher: ... + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int +block_size = ... # type: int +key_size = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/ARC4.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/ARC4.pyi new file mode 100644 index 000000000..c5c17ea3d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/ARC4.pyi @@ -0,0 +1,15 @@ +from typing import Any, Union, Text + +__revision__ = ... # type: str + +class ARC4Cipher: + block_size = ... # type: int + key_size = ... # type: int + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + def encrypt(self, plaintext): ... + def decrypt(self, ciphertext): ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> ARC4Cipher: ... + +block_size = ... # type: int +key_size = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/Blowfish.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/Blowfish.pyi new file mode 100644 index 000000000..87240131a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/Blowfish.pyi @@ -0,0 +1,19 @@ +from typing import Any, Union, Text +from .blockalgo import BlockAlgo + +__revision__ = ... # type: str + +class BlowfishCipher(BlockAlgo): + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> BlowfishCipher: ... + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int +block_size = ... # type: int +key_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/CAST.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/CAST.pyi new file mode 100644 index 000000000..0a8c115b1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/CAST.pyi @@ -0,0 +1,19 @@ +from typing import Any, Union, Text +from .blockalgo import BlockAlgo + +__revision__ = ... # type: str + +class CAST128Cipher(BlockAlgo): + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> CAST128Cipher: ... + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int +block_size = ... # type: int +key_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/DES.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/DES.pyi new file mode 100644 index 000000000..a3fcf2e73 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/DES.pyi @@ -0,0 +1,19 @@ +from typing import Any, Union, Text +from .blockalgo import BlockAlgo + +__revision__ = ... # type: str + +class DESCipher(BlockAlgo): + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> DESCipher: ... + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int +block_size = ... # type: int +key_size = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/DES3.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/DES3.pyi new file mode 100644 index 000000000..3a7f479c4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/DES3.pyi @@ -0,0 +1,20 @@ +from typing import Any, Union, Text + +from .blockalgo import BlockAlgo + +__revision__ = ... # type: str + +class DES3Cipher(BlockAlgo): + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + +def new(key: Union[bytes, Text], *args, **kwargs) -> DES3Cipher: ... + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int +block_size = ... # type: int +key_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/PKCS1_OAEP.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/PKCS1_OAEP.pyi new file mode 100644 index 000000000..50980a46b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/PKCS1_OAEP.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional, Union, Text + +from Crypto.PublicKey.RSA import _RSAobj + +class PKCS1OAEP_Cipher: + def __init__(self, key: _RSAobj, hashAlgo: Any, mgfunc: Any, label: Any) -> None: ... + def can_encrypt(self): ... + def can_decrypt(self): ... + def encrypt(self, message: Union[bytes, Text]) -> bytes: ... + def decrypt(self, ct: bytes) -> bytes: ... + + +def new(key: _RSAobj, hashAlgo: Optional[Any] = ..., mgfunc: Optional[Any] = ..., label: Any = ...) -> PKCS1OAEP_Cipher: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/PKCS1_v1_5.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/PKCS1_v1_5.pyi new file mode 100644 index 000000000..7a4eddf1a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/PKCS1_v1_5.pyi @@ -0,0 +1,13 @@ +from typing import Any, Union, Text + +from Crypto.PublicKey.RSA import _RSAobj + +class PKCS115_Cipher: + def __init__(self, key: _RSAobj) -> None: ... + def can_encrypt(self) -> bool: ... + def can_decrypt(self) -> bool: ... + rf = ... # type: Any + def encrypt(self, message: Union[bytes, Text]) -> bytes: ... + def decrypt(self, ct: bytes, sentinel: Any) -> bytes: ... + +def new(key: _RSAobj) -> PKCS115_Cipher: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/XOR.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/XOR.pyi new file mode 100644 index 000000000..2d631c578 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/XOR.pyi @@ -0,0 +1,16 @@ +from typing import Any, Union, Text + +__revision__ = ... # type: str + +class XORCipher: + block_size = ... # type: int + key_size = ... # type: int + def __init__(self, key: Union[bytes, Text], *args, **kwargs) -> None: ... + def encrypt(self, plaintext: Union[bytes, Text]) -> bytes: ... + def decrypt(self, ciphertext: bytes) -> bytes: ... + + +def new(key: Union[bytes, Text], *args, **kwargs) -> XORCipher: ... + +block_size = ... # type: int +key_size = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/__init__.pyi new file mode 100644 index 000000000..309f2746d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/__init__.pyi @@ -0,0 +1,11 @@ +# Names in __all__ with no definition: +# AES +# ARC2 +# ARC4 +# Blowfish +# CAST +# DES +# DES3 +# PKCS1_OAEP +# PKCS1_v1_5 +# XOR diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/blockalgo.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/blockalgo.pyi new file mode 100644 index 000000000..7c205189a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Cipher/blockalgo.pyi @@ -0,0 +1,17 @@ +from typing import Any, Union, Text + +MODE_ECB = ... # type: int +MODE_CBC = ... # type: int +MODE_CFB = ... # type: int +MODE_PGP = ... # type: int +MODE_OFB = ... # type: int +MODE_CTR = ... # type: int +MODE_OPENPGP = ... # type: int + +class BlockAlgo: + mode = ... # type: int + block_size = ... # type: int + IV = ... # type: Any + def __init__(self, factory: Any, key: Union[bytes, Text], *args, **kwargs) -> None: ... + def encrypt(self, plaintext: Union[bytes, Text]) -> bytes: ... + def decrypt(self, ciphertext: bytes) -> bytes: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/HMAC.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/HMAC.pyi new file mode 100644 index 000000000..afc005b9c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/HMAC.pyi @@ -0,0 +1,16 @@ +from typing import Any, Optional + +digest_size = ... # type: Any + +class HMAC: + digest_size = ... # type: Any + digestmod = ... # type: Any + outer = ... # type: Any + inner = ... # type: Any + def __init__(self, key, msg: Optional[Any] = ..., digestmod: Optional[Any] = ...) -> None: ... + def update(self, msg): ... + def copy(self): ... + def digest(self): ... + def hexdigest(self): ... + +def new(key, msg: Optional[Any] = ..., digestmod: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD2.pyi new file mode 100644 index 000000000..75e382d44 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD2.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class MD2Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD4.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD4.pyi new file mode 100644 index 000000000..6644f23cb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD4.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class MD4Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD5.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD5.pyi new file mode 100644 index 000000000..e8e9eb39f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/MD5.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class MD5Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/RIPEMD.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/RIPEMD.pyi new file mode 100644 index 000000000..6919ec95c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/RIPEMD.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class RIPEMD160Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA.pyi new file mode 100644 index 000000000..03c722b9c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class SHA1Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA224.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA224.pyi new file mode 100644 index 000000000..85d6cb7d0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA224.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class SHA224Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA256.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA256.pyi new file mode 100644 index 000000000..252d25e23 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA256.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class SHA256Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA384.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA384.pyi new file mode 100644 index 000000000..3a61a6391 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA384.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class SHA384Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA512.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA512.pyi new file mode 100644 index 000000000..10cedb060 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/SHA512.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional +from Crypto.Hash.hashalgo import HashAlgo + +class SHA512Hash(HashAlgo): + oid = ... # type: Any + digest_size = ... # type: int + block_size = ... # type: int + def __init__(self, data: Optional[Any] = ...) -> None: ... + def new(self, data: Optional[Any] = ...): ... + +def new(data: Optional[Any] = ...): ... + +digest_size = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/__init__.pyi new file mode 100644 index 000000000..9af06f41e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/__init__.pyi @@ -0,0 +1,11 @@ +# Names in __all__ with no definition: +# HMAC +# MD2 +# MD4 +# MD5 +# RIPEMD +# SHA +# SHA224 +# SHA256 +# SHA384 +# SHA512 diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/hashalgo.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/hashalgo.pyi new file mode 100644 index 000000000..e7c84f075 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Hash/hashalgo.pyi @@ -0,0 +1,11 @@ +from typing import Any, Optional + +class HashAlgo: + digest_size = ... # type: Any + block_size = ... # type: Any + def __init__(self, hashFactory, data: Optional[Any] = ...) -> None: ... + def update(self, data): ... + def digest(self): ... + def hexdigest(self): ... + def copy(self): ... + def new(self, data: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/AllOrNothing.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/AllOrNothing.pyi new file mode 100644 index 000000000..5d3e426f1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/AllOrNothing.pyi @@ -0,0 +1,10 @@ +from typing import Any, Optional + +__revision__ = ... # type: str + +def isInt(x): ... + +class AllOrNothing: + def __init__(self, ciphermodule, mode: Optional[Any] = ..., IV: Optional[Any] = ...) -> None: ... + def digest(self, text): ... + def undigest(self, blocks): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/Chaffing.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/Chaffing.pyi new file mode 100644 index 000000000..eec11bd33 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/Chaffing.pyi @@ -0,0 +1,5 @@ +__revision__ = ... # type: str + +class Chaff: + def __init__(self, factor: float = ..., blocksper: int = ...) -> None: ... + def chaff(self, blocks): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/KDF.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/KDF.pyi new file mode 100644 index 000000000..20cedb017 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/KDF.pyi @@ -0,0 +1,7 @@ +from typing import Any, Optional +from Crypto.Hash import SHA as SHA1 + +__revision__ = ... # type: str + +def PBKDF1(password, salt, dkLen, count: int = ..., hashAlgo: Optional[Any] = ...): ... +def PBKDF2(password, salt, dkLen: int = ..., count: int = ..., prf: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/__init__.pyi new file mode 100644 index 000000000..e3744e5ee --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Protocol/__init__.pyi @@ -0,0 +1,4 @@ +# Names in __all__ with no definition: +# AllOrNothing +# Chaffing +# KDF diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/DSA.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/DSA.pyi new file mode 100644 index 000000000..f0e6dd202 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/DSA.pyi @@ -0,0 +1,27 @@ +from typing import Any, Optional +from .pubkey import pubkey + +class _DSAobj(pubkey): + keydata = ... # type: Any + implementation = ... # type: Any + key = ... # type: Any + def __init__(self, implementation, key) -> None: ... + def __getattr__(self, attrname): ... + def sign(self, M, K): ... + def verify(self, M, signature): ... + def has_private(self): ... + def size(self): ... + def can_blind(self): ... + def can_encrypt(self): ... + def can_sign(self): ... + def publickey(self): ... + +class DSAImplementation: + error = ... # type: Any + def __init__(self, **kwargs) -> None: ... + def generate(self, bits, randfunc: Optional[Any] = ..., progress_func: Optional[Any] = ...): ... + def construct(self, tup): ... + +generate = ... # type: Any +construct = ... # type: Any +error = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/ElGamal.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/ElGamal.pyi new file mode 100644 index 000000000..5bc238d1b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/ElGamal.pyi @@ -0,0 +1,19 @@ +from typing import Any, Optional + +from Crypto.PublicKey.pubkey import pubkey +from Crypto.PublicKey.pubkey import * # noqa: F403 + +class error(Exception): ... + +def generate(bits, randfunc, progress_func: Optional[Any] = ...): ... +def construct(tup): ... + +class ElGamalobj(pubkey): + keydata = ... # type: Any + def encrypt(self, plaintext, K): ... + def decrypt(self, ciphertext): ... + def sign(self, M, K): ... + def verify(self, M, signature): ... + def size(self): ... + def has_private(self): ... + def publickey(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/RSA.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/RSA.pyi new file mode 100644 index 000000000..cd10d748c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/RSA.pyi @@ -0,0 +1,32 @@ +from typing import Any, Optional, Union, Text +from .pubkey import pubkey + +class _RSAobj(pubkey): + keydata = ... # type: Any + implementation = ... # type: Any + key = ... # type: Any + def __init__(self, implementation, key, randfunc: Optional[Any] = ...) -> None: ... + def __getattr__(self, attrname): ... + def encrypt(self, plaintext, K): ... + def decrypt(self, ciphertext): ... + def sign(self, M, K): ... + def verify(self, M, signature): ... + def has_private(self): ... + def size(self): ... + def can_blind(self): ... + def can_encrypt(self): ... + def can_sign(self): ... + def publickey(self): ... + def exportKey(self, format: str = ..., passphrase: Optional[Any] = ..., pkcs: int = ...): ... + +class RSAImplementation: + error = ... # type: Any + def __init__(self, **kwargs) -> None: ... + def generate(self, bits, randfunc: Optional[Any] = ..., progress_func: Optional[Any] = ..., e: int = ...): ... + def construct(self, tup): ... + def importKey(self, externKey: Any, passphrase: Union[None, bytes, Text] = ...) -> _RSAobj: ... + +generate = ... # type: Any +construct = ... # type: Any +importKey = ... # type: Any +error = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/__init__.pyi new file mode 100644 index 000000000..36d9e9434 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/__init__.pyi @@ -0,0 +1,4 @@ +# Names in __all__ with no definition: +# DSA +# ElGamal +# RSA diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/pubkey.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/pubkey.pyi new file mode 100644 index 000000000..cbaf5f39a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/PublicKey/pubkey.pyi @@ -0,0 +1,21 @@ +from Crypto.Util.number import * # noqa: F403 + +__revision__ = ... # type: str + +class pubkey: + def __init__(self) -> None: ... + def encrypt(self, plaintext, K): ... + def decrypt(self, ciphertext): ... + def sign(self, M, K): ... + def verify(self, M, signature): ... + def validate(self, M, signature): ... + def blind(self, M, B): ... + def unblind(self, M, B): ... + def can_sign(self): ... + def can_encrypt(self): ... + def can_blind(self): ... + def size(self): ... + def has_private(self): ... + def publickey(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/FortunaAccumulator.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/FortunaAccumulator.pyi new file mode 100644 index 000000000..bb898b204 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/FortunaAccumulator.pyi @@ -0,0 +1,25 @@ +from typing import Any + +__revision__ = ... # type: str + +class FortunaPool: + digest_size = ... # type: Any + def __init__(self) -> None: ... + def append(self, data): ... + def digest(self): ... + def hexdigest(self): ... + length = ... # type: int + def reset(self): ... + +def which_pools(r): ... + +class FortunaAccumulator: + min_pool_size = ... # type: int + reseed_interval = ... # type: float + reseed_count = ... # type: int + generator = ... # type: Any + last_reseed = ... # type: Any + pools = ... # type: Any + def __init__(self) -> None: ... + def random_data(self, bytes): ... + def add_random_event(self, source_number, pool_number, data): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/FortunaGenerator.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/FortunaGenerator.pyi new file mode 100644 index 000000000..1d69094c5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/FortunaGenerator.pyi @@ -0,0 +1,16 @@ +from typing import Any + +__revision__ = ... # type: str + +class AESGenerator: + block_size = ... # type: Any + key_size = ... # type: int + max_blocks_per_request = ... # type: Any + counter = ... # type: Any + key = ... # type: Any + block_size_shift = ... # type: Any + blocks_per_key = ... # type: Any + max_bytes_per_request = ... # type: Any + def __init__(self) -> None: ... + def reseed(self, seed): ... + def pseudo_random_data(self, bytes): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/SHAd256.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/SHAd256.pyi new file mode 100644 index 000000000..0dfb69167 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/SHAd256.pyi @@ -0,0 +1,13 @@ +from typing import Any, Optional + +class _SHAd256: + digest_size = ... # type: Any + def __init__(self, internal_api_check, sha256_hash_obj) -> None: ... + def copy(self): ... + def digest(self): ... + def hexdigest(self): ... + def update(self, data): ... + +digest_size = ... # type: Any + +def new(data: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/Fortuna/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/__init__.pyi new file mode 100644 index 000000000..a9c47e6e6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/__init__.pyi @@ -0,0 +1 @@ +__revision__ = ... # type: str diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/fallback.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/fallback.pyi new file mode 100644 index 000000000..d25d8590a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/fallback.pyi @@ -0,0 +1,5 @@ +from .rng_base import BaseRNG + +class PythonOSURandomRNG(BaseRNG): + name = ... # type: str + def __init__(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/posix.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/posix.pyi new file mode 100644 index 000000000..0506ffab0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/posix.pyi @@ -0,0 +1,6 @@ +from typing import Any, Optional +from .rng_base import BaseRNG + +class DevURandomRNG(BaseRNG): + name = ... # type: str + def __init__(self, devname: Optional[Any] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/rng_base.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/rng_base.pyi new file mode 100644 index 000000000..46ac79c95 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/OSRNG/rng_base.pyi @@ -0,0 +1,11 @@ +__revision__ = ... # type: str + +class BaseRNG: + closed = ... # type: bool + def __init__(self) -> None: ... + def __del__(self): ... + def __enter__(self): ... + def __exit__(self): ... + def close(self): ... + def flush(self): ... + def read(self, N: int = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/__init__.pyi new file mode 100644 index 000000000..f30acfd3a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/__init__.pyi @@ -0,0 +1 @@ +def new(*args, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/random.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/random.pyi new file mode 100644 index 000000000..4178db7f6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Random/random.pyi @@ -0,0 +1,17 @@ +from typing import Any, Optional + +class StrongRandom: + def __init__(self, rng: Optional[Any] = ..., randfunc: Optional[Any] = ...) -> None: ... + def getrandbits(self, k): ... + def randrange(self, *args): ... + def randint(self, a, b): ... + def choice(self, seq): ... + def shuffle(self, x): ... + def sample(self, population, k): ... + +getrandbits = ... # type: Any +randrange = ... # type: Any +randint = ... # type: Any +choice = ... # type: Any +shuffle = ... # type: Any +sample = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/PKCS1_PSS.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/PKCS1_PSS.pyi new file mode 100644 index 000000000..8341c2b4e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/PKCS1_PSS.pyi @@ -0,0 +1,9 @@ +from typing import Any, Optional + +class PSS_SigScheme: + def __init__(self, key, mgfunc, saltLen) -> None: ... + def can_sign(self): ... + def sign(self, mhash): ... + def verify(self, mhash, S): ... + +def new(key, mgfunc: Optional[Any] = ..., saltLen: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/PKCS1_v1_5.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/PKCS1_v1_5.pyi new file mode 100644 index 000000000..4a2b22531 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/PKCS1_v1_5.pyi @@ -0,0 +1,7 @@ +class PKCS115_SigScheme: + def __init__(self, key) -> None: ... + def can_sign(self): ... + def sign(self, mhash): ... + def verify(self, mhash, S): ... + +def new(key): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/__init__.pyi new file mode 100644 index 000000000..560f06fd9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Signature/__init__.pyi @@ -0,0 +1,3 @@ +# Names in __all__ with no definition: +# PKCS1_PSS +# PKCS1_v1_5 diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/Counter.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/Counter.pyi new file mode 100644 index 000000000..4aae7f269 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/Counter.pyi @@ -0,0 +1,3 @@ +from typing import Any + +def new(nbits, prefix: Any = ..., suffix: Any = ..., initial_value: int = ..., overflow: int = ..., little_endian: bool = ..., allow_wraparound: bool = ..., disable_shortcut: bool = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/RFC1751.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/RFC1751.pyi new file mode 100644 index 000000000..273204b24 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/RFC1751.pyi @@ -0,0 +1,9 @@ +from typing import Any + +__revision__ = ... # type: str +binary = ... # type: Any + +def key_to_english(key): ... +def english_to_key(s): ... + +wordlist = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/__init__.pyi new file mode 100644 index 000000000..174729952 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/__init__.pyi @@ -0,0 +1,6 @@ +# Names in __all__ with no definition: +# RFC1751 +# asn1 +# number +# randpool +# strxor diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/asn1.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/asn1.pyi new file mode 100644 index 000000000..036a3034f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/asn1.pyi @@ -0,0 +1,45 @@ +from typing import Any, Optional + +class DerObject: + typeTags = ... # type: Any + typeTag = ... # type: Any + payload = ... # type: Any + def __init__(self, ASN1Type: Optional[Any] = ..., payload: Any = ...) -> None: ... + def isType(self, ASN1Type): ... + def encode(self): ... + def decode(self, derEle, noLeftOvers: int = ...): ... + +class DerInteger(DerObject): + value = ... # type: Any + def __init__(self, value: int = ...) -> None: ... + payload = ... # type: Any + def encode(self): ... + def decode(self, derEle, noLeftOvers: int = ...): ... + +class DerSequence(DerObject): + def __init__(self, startSeq: Optional[Any] = ...) -> None: ... + def __delitem__(self, n): ... + def __getitem__(self, n): ... + def __setitem__(self, key, value): ... + def __setslice__(self, i, j, sequence): ... + def __delslice__(self, i, j): ... + def __getslice__(self, i, j): ... + def __len__(self): ... + def append(self, item): ... + def hasInts(self): ... + def hasOnlyInts(self): ... + payload = ... # type: Any + def encode(self): ... + def decode(self, derEle, noLeftOvers: int = ...): ... + +class DerOctetString(DerObject): + payload = ... # type: Any + def __init__(self, value: Any = ...) -> None: ... + def decode(self, derEle, noLeftOvers: int = ...): ... + +class DerNull(DerObject): + def __init__(self) -> None: ... + +class DerObjectId(DerObject): + def __init__(self) -> None: ... + def decode(self, derEle, noLeftOvers: int = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/number.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/number.pyi new file mode 100644 index 000000000..796e487ea --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/number.pyi @@ -0,0 +1,22 @@ +from typing import Any, Optional +from warnings import warn as _warn + +__revision__ = ... # type: str +bignum = ... # type: Any + +def size(N): ... +def getRandomNumber(N, randfunc: Optional[Any] = ...): ... +def getRandomInteger(N, randfunc: Optional[Any] = ...): ... +def getRandomRange(a, b, randfunc: Optional[Any] = ...): ... +def getRandomNBitInteger(N, randfunc: Optional[Any] = ...): ... +def GCD(x, y): ... +def inverse(u, v): ... +def getPrime(N, randfunc: Optional[Any] = ...): ... +def getStrongPrime(N, e: int = ..., false_positive_prob: float = ..., randfunc: Optional[Any] = ...): ... +def isPrime(N, false_positive_prob: float = ..., randfunc: Optional[Any] = ...): ... +def long_to_bytes(n, blocksize: int = ...): ... +def bytes_to_long(s): ... +def long2str(n, blocksize: int = ...): ... +def str2long(s): ... + +sieve_base = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/randpool.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/randpool.pyi new file mode 100644 index 000000000..2b05706da --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/randpool.pyi @@ -0,0 +1,16 @@ +from typing import Any, Optional + +__revision__ = ... # type: str + +class RandomPool: + bytes = ... # type: Any + bits = ... # type: Any + entropy = ... # type: Any + def __init__(self, numbytes: int = ..., cipher: Optional[Any] = ..., hash: Optional[Any] = ..., file: Optional[Any] = ...) -> None: ... + def get_bytes(self, N): ... + def randomize(self, N: int = ...): ... + def stir(self, s: str = ...): ... + def stir_n(self, N: int = ...): ... + def add_event(self, s: str = ...): ... + def getBytes(self, N): ... + def addEvent(self, event, s: str = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/strxor.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/strxor.pyi new file mode 100644 index 000000000..cb6269bbb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/Util/strxor.pyi @@ -0,0 +1,2 @@ +def strxor(*args, **kwargs): ... +def strxor_c(*args, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/__init__.pyi new file mode 100644 index 000000000..6d8e1248d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/__init__.pyi @@ -0,0 +1,7 @@ +# Names in __all__ with no definition: +# Cipher +# Hash +# Protocol +# PublicKey +# Signature +# Util diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/pct_warnings.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/pct_warnings.pyi new file mode 100644 index 000000000..b77e975b2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/Crypto/pct_warnings.pyi @@ -0,0 +1,7 @@ +class CryptoWarning(Warning): ... +class CryptoDeprecationWarning(DeprecationWarning, CryptoWarning): ... +class CryptoRuntimeWarning(RuntimeWarning, CryptoWarning): ... +class RandomPool_DeprecationWarning(CryptoDeprecationWarning): ... +class ClockRewindWarning(CryptoRuntimeWarning): ... +class GetRandomNumber_DeprecationWarning(CryptoDeprecationWarning): ... +class PowmInsecureWarning(CryptoRuntimeWarning): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/atomicwrites/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/atomicwrites/__init__.pyi new file mode 100644 index 000000000..07edff697 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/atomicwrites/__init__.pyi @@ -0,0 +1,13 @@ +from typing import AnyStr, Callable, ContextManager, IO, Optional, Text, Type + +def replace_atomic(src: AnyStr, dst: AnyStr) -> None: ... +def move_atomic(src: AnyStr, dst: AnyStr) -> None: ... +class AtomicWriter(object): + def __init__(self, path: AnyStr, mode: Text = ..., overwrite: bool = ...) -> None: ... + def open(self) -> ContextManager[IO]: ... + def _open(self, get_fileobject: Callable) -> ContextManager[IO]: ... + def get_fileobject(self, dir: Optional[AnyStr] = ..., **kwargs) -> IO: ... + def sync(self, f: IO) -> None: ... + def commit(self, f: IO) -> None: ... + def rollback(self, f: IO) -> None: ... +def atomic_write(path: AnyStr, writer_cls: Type[AtomicWriter] = ..., **cls_kwargs: object) -> ContextManager[IO]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/__init__.pyi new file mode 100644 index 000000000..eaf0900ce --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/__init__.pyi @@ -0,0 +1,212 @@ +from typing import Any, Callable, Dict, Generic, List, Optional, Sequence, Mapping, Tuple, Type, TypeVar, Union, overload +# `import X as X` is required to make these public +from . import exceptions as exceptions +from . import filters as filters +from . import converters as converters +from . import validators as validators + +_T = TypeVar('_T') +_C = TypeVar('_C', bound=type) + +_ValidatorType = Callable[[Any, Attribute, _T], Any] +_ConverterType = Callable[[Any], _T] +_FilterType = Callable[[Attribute, Any], bool] +# FIXME: in reality, if multiple validators are passed they must be in a list or tuple, +# but those are invariant and so would prevent subtypes of _ValidatorType from working +# when passed in a list or tuple. +_ValidatorArgType = Union[_ValidatorType[_T], Sequence[_ValidatorType[_T]]] + +# _make -- + +NOTHING: object + +# NOTE: Factory lies about its return type to make this possible: `x: List[int] = Factory(list)` +# Work around mypy issue #4554 in the common case by using an overload. +@overload +def Factory(factory: Callable[[], _T]) -> _T: ... +@overload +def Factory(factory: Union[Callable[[Any], _T], Callable[[], _T]], takes_self: bool = ...) -> _T: ... + +class Attribute(Generic[_T]): + name: str + default: Optional[_T] + validator: Optional[_ValidatorType[_T]] + repr: bool + cmp: bool + hash: Optional[bool] + init: bool + converter: Optional[_ConverterType[_T]] + metadata: Dict[Any, Any] + type: Optional[Type[_T]] + def __lt__(self, x: Attribute) -> bool: ... + def __le__(self, x: Attribute) -> bool: ... + def __gt__(self, x: Attribute) -> bool: ... + def __ge__(self, x: Attribute) -> bool: ... + + +# NOTE: We had several choices for the annotation to use for type arg: +# 1) Type[_T] +# - Pros: works in PyCharm without plugin support +# - Cons: produces less informative error in the case of conflicting TypeVars +# e.g. `attr.ib(default='bad', type=int)` +# 2) Callable[..., _T] +# - Pros: more informative errors than #1 +# - Cons: validator tests results in confusing error. +# e.g. `attr.ib(type=int, validator=validate_str)` +# 3) type (and do all of the work in the mypy plugin) +# - Pros: in mypy, the behavior of type argument is exactly the same as with +# annotations. +# - Cons: completely disables type inspections in PyCharm when using the +# type arg. +# We chose option #1 until either PyCharm adds support for attrs, or python 2 +# reaches EOL. + +# NOTE: If you update these, update `ib` and `attr` below. + +# `attr` lies about its return type to make the following possible: +# attr() -> Any +# attr(8) -> int +# attr(validator=) -> Whatever the callable expects. +# This makes this type of assignments possible: +# x: int = attr(8) +# +# This form catches explicit None or no default but with no other arguments returns Any. +@overload +def attrib(default: None = ..., + validator: None = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + convert: None = ..., + metadata: Optional[Mapping[Any, Any]] = ..., + type: None = ..., + converter: None = ..., + factory: None = ..., + ) -> Any: ... +# This form catches an explicit None or no default and infers the type from the other arguments. +@overload +def attrib(default: None = ..., + validator: Optional[_ValidatorArgType[_T]] = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + convert: Optional[_ConverterType[_T]] = ..., + metadata: Optional[Mapping[Any, Any]] = ..., + type: Optional[Type[_T]] = ..., + converter: Optional[_ConverterType[_T]] = ..., + factory: Optional[Callable[[], _T]] = ..., + ) -> _T: ... +# This form catches an explicit default argument. +@overload +def attrib(default: _T, + validator: Optional[_ValidatorArgType[_T]] = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + convert: Optional[_ConverterType[_T]] = ..., + metadata: Optional[Mapping[Any, Any]] = ..., + type: Optional[Type[_T]] = ..., + converter: Optional[_ConverterType[_T]] = ..., + factory: Optional[Callable[[], _T]] = ..., + ) -> _T: ... +# This form covers type=non-Type: e.g. forward references (str), Any +@overload +def attrib(default: Optional[_T] = ..., + validator: Optional[_ValidatorArgType[_T]] = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + convert: Optional[_ConverterType[_T]] = ..., + metadata: Optional[Mapping[Any, Any]] = ..., + type: object = ..., + converter: Optional[_ConverterType[_T]] = ..., + factory: Optional[Callable[[], _T]] = ..., + ) -> Any: ... + + +# NOTE: If you update these, update `s` and `attributes` below. +@overload +def attrs(maybe_cls: _C, + these: Optional[Dict[str, Any]] = ..., + repr_ns: Optional[str] = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + slots: bool = ..., + frozen: bool = ..., + str: bool = ..., + auto_attribs: bool = ...) -> _C: ... +@overload +def attrs(maybe_cls: None = ..., + these: Optional[Dict[str, Any]] = ..., + repr_ns: Optional[str] = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + slots: bool = ..., + frozen: bool = ..., + str: bool = ..., + auto_attribs: bool = ...) -> Callable[[_C], _C]: ... + + +# TODO: add support for returning NamedTuple from the mypy plugin +class _Fields(Tuple[Attribute, ...]): + def __getattr__(self, name: str) -> Attribute: ... + +def fields(cls: type) -> _Fields: ... +def fields_dict(cls: type) -> Dict[str, Attribute]: ... +def validate(inst: Any) -> None: ... + +# TODO: add support for returning a proper attrs class from the mypy plugin +# we use Any instead of _CountingAttr so that e.g. `make_class('Foo', [attr.ib()])` is valid +def make_class(name: str, + attrs: Union[List[str], Tuple[str, ...], Dict[str, Any]], + bases: Tuple[type, ...] = ..., + repr_ns: Optional[str] = ..., + repr: bool = ..., + cmp: bool = ..., + hash: Optional[bool] = ..., + init: bool = ..., + slots: bool = ..., + frozen: bool = ..., + str: bool = ..., + auto_attribs: bool = ...) -> type: ... + +# _funcs -- + +# TODO: add support for returning TypedDict from the mypy plugin +# FIXME: asdict/astuple do not honor their factory args. waiting on one of these: +# https://github.com/python/mypy/issues/4236 +# https://github.com/python/typing/issues/253 +def asdict(inst: Any, + recurse: bool = ..., + filter: Optional[_FilterType] = ..., + dict_factory: Type[Mapping[Any, Any]] = ..., + retain_collection_types: bool = ...) -> Dict[str, Any]: ... +# TODO: add support for returning NamedTuple from the mypy plugin +def astuple(inst: Any, + recurse: bool = ..., + filter: Optional[_FilterType] = ..., + tuple_factory: Type[Sequence] = ..., + retain_collection_types: bool = ...) -> Tuple[Any, ...]: ... +def has(cls: type) -> bool: ... +def assoc(inst: _T, **changes: Any) -> _T: ... +def evolve(inst: _T, **changes: Any) -> _T: ... + +# _config -- + +def set_run_validators(run: bool) -> None: ... +def get_run_validators() -> bool: ... + + +# aliases -- + +s = attributes = attrs +ib = attr = attrib +dataclass = attrs # Technically, partial(attrs, auto_attribs=True) ;) diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/converters.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/converters.pyi new file mode 100644 index 000000000..9e31677e7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/converters.pyi @@ -0,0 +1,6 @@ +from typing import TypeVar, Optional +from . import _ConverterType + +_T = TypeVar('_T') + +def optional(converter: _ConverterType[_T]) -> _ConverterType[Optional[_T]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/exceptions.pyi new file mode 100644 index 000000000..4a2904fc2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/exceptions.pyi @@ -0,0 +1,6 @@ +class FrozenInstanceError(AttributeError): + msg: str = ... +class AttrsAttributeNotFoundError(ValueError): ... +class NotAnAttrsClassError(ValueError): ... +class DefaultAlreadySetError(RuntimeError): ... +class UnannotatedAttributeError(RuntimeError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/filters.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/filters.pyi new file mode 100644 index 000000000..a618140c2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/filters.pyi @@ -0,0 +1,5 @@ +from typing import Union +from . import Attribute, _FilterType + +def include(*what: Union[type, Attribute]) -> _FilterType: ... +def exclude(*what: Union[type, Attribute]) -> _FilterType: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/validators.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/validators.pyi new file mode 100644 index 000000000..3fc34377c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/attr/validators.pyi @@ -0,0 +1,10 @@ +from typing import Container, List, Union, TypeVar, Type, Any, Optional, Tuple +from . import _ValidatorType + +_T = TypeVar('_T') + +def instance_of(type: Union[Tuple[Type[_T], ...], Type[_T]]) -> _ValidatorType[_T]: ... +def provides(interface: Any) -> _ValidatorType[Any]: ... +def optional(validator: Union[_ValidatorType[_T], List[_ValidatorType[_T]]]) -> _ValidatorType[Optional[_T]]: ... +def in_(options: Container[_T]) -> _ValidatorType[_T]: ... +def and_(*validators: _ValidatorType[_T]) -> _ValidatorType[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports/ssl_match_hostname.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports/ssl_match_hostname.pyi new file mode 100644 index 000000000..c21998013 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports/ssl_match_hostname.pyi @@ -0,0 +1,3 @@ +class CertificateError(ValueError): ... + +def match_hostname(cert, hostname): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports_abc.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports_abc.pyi new file mode 100644 index 000000000..8deebc0cc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/backports_abc.pyi @@ -0,0 +1,15 @@ +from typing import Any + +def mk_gen(): ... +def mk_awaitable(): ... +def mk_coroutine(): ... + +Generator = ... # type: Any +Awaitable = ... # type: Any +Coroutine = ... # type: Any + +def isawaitable(obj): ... + +PATCHED = ... # type: Any + +def patch(patch_inspect=True): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/__init__.pyi new file mode 100644 index 000000000..d7b30c81c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/__init__.pyi @@ -0,0 +1,76 @@ +from typing import Any, Optional, Text +import logging + +from .s3.connection import S3Connection + +Version = ... # type: Any +UserAgent = ... # type: Any +config = ... # type: Any +BUCKET_NAME_RE = ... # type: Any +TOO_LONG_DNS_NAME_COMP = ... # type: Any +GENERATION_RE = ... # type: Any +VERSION_RE = ... # type: Any +ENDPOINTS_PATH = ... # type: Any + +def init_logging(): ... + +class NullHandler(logging.Handler): + def emit(self, record): ... + +log = ... # type: Any +perflog = ... # type: Any + +def set_file_logger(name, filepath, level: Any = ..., format_string: Optional[Any] = ...): ... +def set_stream_logger(name, level: Any = ..., format_string: Optional[Any] = ...): ... +def connect_sqs(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_s3(aws_access_key_id: Optional[Text] = ..., aws_secret_access_key: Optional[Text] = ..., **kwargs) -> S3Connection: ... +def connect_gs(gs_access_key_id: Optional[Any] = ..., gs_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_ec2(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_elb(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_autoscale(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudwatch(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_sdb(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_fps(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_mturk(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudfront(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_vpc(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_rds(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_rds2(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_emr(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_sns(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_iam(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_route53(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudformation(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_euca(host: Optional[Any] = ..., aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., port: int = ..., path: str = ..., is_secure: bool = ..., **kwargs): ... +def connect_glacier(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_ec2_endpoint(url, aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_walrus(host: Optional[Any] = ..., aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., port: int = ..., path: str = ..., is_secure: bool = ..., **kwargs): ... +def connect_ses(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_sts(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_ia(ia_access_key_id: Optional[Any] = ..., ia_secret_access_key: Optional[Any] = ..., is_secure: bool = ..., **kwargs): ... +def connect_dynamodb(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_swf(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudsearch(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudsearch2(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., sign_request: bool = ..., **kwargs): ... +def connect_cloudsearchdomain(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_beanstalk(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_elastictranscoder(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_opsworks(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_redshift(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_support(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudtrail(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_directconnect(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_kinesis(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_logs(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_route53domains(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cognito_identity(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cognito_sync(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_kms(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_awslambda(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_codedeploy(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_configservice(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_cloudhsm(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_ec2containerservice(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def connect_machinelearning(aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., **kwargs): ... +def storage_uri(uri_str, default_scheme: str = ..., debug: int = ..., validate: bool = ..., bucket_storage_uri_class: Any = ..., suppress_consec_slashes: bool = ..., is_latest: bool = ...): ... +def storage_uri_for_key(key): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/auth.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/auth.pyi new file mode 100644 index 000000000..57127ad02 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/auth.pyi @@ -0,0 +1,108 @@ +from typing import Any, Optional +from boto.auth_handler import AuthHandler + +SIGV4_DETECT = ... # type: Any + +class HmacKeys: + host = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def update_provider(self, provider): ... + def algorithm(self): ... + def sign_string(self, string_to_sign): ... + +class AnonAuthHandler(AuthHandler, HmacKeys): + capability = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def add_auth(self, http_request, **kwargs): ... + +class HmacAuthV1Handler(AuthHandler, HmacKeys): + capability = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def update_provider(self, provider): ... + def add_auth(self, http_request, **kwargs): ... + +class HmacAuthV2Handler(AuthHandler, HmacKeys): + capability = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def update_provider(self, provider): ... + def add_auth(self, http_request, **kwargs): ... + +class HmacAuthV3Handler(AuthHandler, HmacKeys): + capability = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def add_auth(self, http_request, **kwargs): ... + +class HmacAuthV3HTTPHandler(AuthHandler, HmacKeys): + capability = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def headers_to_sign(self, http_request): ... + def canonical_headers(self, headers_to_sign): ... + def string_to_sign(self, http_request): ... + def add_auth(self, req, **kwargs): ... + +class HmacAuthV4Handler(AuthHandler, HmacKeys): + capability = ... # type: Any + service_name = ... # type: Any + region_name = ... # type: Any + def __init__(self, host, config, provider, service_name: Optional[Any] = ..., region_name: Optional[Any] = ...) -> None: ... + def headers_to_sign(self, http_request): ... + def host_header(self, host, http_request): ... + def query_string(self, http_request): ... + def canonical_query_string(self, http_request): ... + def canonical_headers(self, headers_to_sign): ... + def signed_headers(self, headers_to_sign): ... + def canonical_uri(self, http_request): ... + def payload(self, http_request): ... + def canonical_request(self, http_request): ... + def scope(self, http_request): ... + def split_host_parts(self, host): ... + def determine_region_name(self, host): ... + def determine_service_name(self, host): ... + def credential_scope(self, http_request): ... + def string_to_sign(self, http_request, canonical_request): ... + def signature(self, http_request, string_to_sign): ... + def add_auth(self, req, **kwargs): ... + +class S3HmacAuthV4Handler(HmacAuthV4Handler, AuthHandler): + capability = ... # type: Any + region_name = ... # type: Any + def __init__(self, *args, **kwargs) -> None: ... + def clean_region_name(self, region_name): ... + def canonical_uri(self, http_request): ... + def canonical_query_string(self, http_request): ... + def host_header(self, host, http_request): ... + def headers_to_sign(self, http_request): ... + def determine_region_name(self, host): ... + def determine_service_name(self, host): ... + def mangle_path_and_params(self, req): ... + def payload(self, http_request): ... + def add_auth(self, req, **kwargs): ... + def presign(self, req, expires, iso_date: Optional[Any] = ...): ... + +class STSAnonHandler(AuthHandler): + capability = ... # type: Any + def add_auth(self, http_request, **kwargs): ... + +class QuerySignatureHelper(HmacKeys): + def add_auth(self, http_request, **kwargs): ... + +class QuerySignatureV0AuthHandler(QuerySignatureHelper, AuthHandler): + SignatureVersion = ... # type: int + capability = ... # type: Any + +class QuerySignatureV1AuthHandler(QuerySignatureHelper, AuthHandler): + SignatureVersion = ... # type: int + capability = ... # type: Any + def __init__(self, *args, **kw) -> None: ... + +class QuerySignatureV2AuthHandler(QuerySignatureHelper, AuthHandler): + SignatureVersion = ... # type: int + capability = ... # type: Any + +class POSTPathQSV2AuthHandler(QuerySignatureV2AuthHandler, AuthHandler): + capability = ... # type: Any + def add_auth(self, req, **kwargs): ... + +def get_auth_handler(host, config, provider, requested_capability: Optional[Any] = ...): ... +def detect_potential_sigv4(func): ... +def detect_potential_s3sigv4(func): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/auth_handler.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/auth_handler.pyi new file mode 100644 index 000000000..b9a0400a8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/auth_handler.pyi @@ -0,0 +1,9 @@ +from typing import Any +from boto.plugin import Plugin + +class NotReadyToAuthenticate(Exception): ... + +class AuthHandler(Plugin): + capability = ... # type: Any + def __init__(self, host, config, provider) -> None: ... + def add_auth(self, http_request): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/compat.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/compat.pyi new file mode 100644 index 000000000..ef4a7c6d5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/compat.pyi @@ -0,0 +1,17 @@ +import sys + +from typing import Any +from base64 import encodestring as encodebytes + +from six.moves import http_client + +expanduser = ... # type: Any + +if sys.version_info >= (3, 0): + StandardError = Exception +else: + StandardError = __builtins__.StandardError + +long_type = ... # type: Any +unquote_str = ... # type: Any +parse_qs_safe = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/connection.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/connection.pyi new file mode 100644 index 000000000..d8c40cbf8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/connection.pyi @@ -0,0 +1,115 @@ +from typing import Any, Dict, Optional, Text +from six.moves import http_client + +HAVE_HTTPS_CONNECTION = ... # type: bool +ON_APP_ENGINE = ... # type: Any +PORTS_BY_SECURITY = ... # type: Any +DEFAULT_CA_CERTS_FILE = ... # type: Any + +class HostConnectionPool: + queue = ... # type: Any + def __init__(self) -> None: ... + def size(self): ... + def put(self, conn): ... + def get(self): ... + def clean(self): ... + +class ConnectionPool: + CLEAN_INTERVAL = ... # type: float + STALE_DURATION = ... # type: float + host_to_pool = ... # type: Any + last_clean_time = ... # type: float + mutex = ... # type: Any + def __init__(self) -> None: ... + def size(self): ... + def get_http_connection(self, host, port, is_secure): ... + def put_http_connection(self, host, port, is_secure, conn): ... + def clean(self): ... + +class HTTPRequest: + method = ... # type: Any + protocol = ... # type: Any + host = ... # type: Any + port = ... # type: Any + path = ... # type: Any + auth_path = ... # type: Any + params = ... # type: Any + headers = ... # type: Any + body = ... # type: Any + def __init__(self, method, protocol, host, port, path, auth_path, params, headers, body) -> None: ... + def authorize(self, connection, **kwargs): ... + +class HTTPResponse(http_client.HTTPResponse): + def __init__(self, *args, **kwargs) -> None: ... + def read(self, amt: Optional[Any] = ...): ... + +class AWSAuthConnection: + suppress_consec_slashes = ... # type: Any + num_retries = ... # type: int + is_secure = ... # type: Any + https_validate_certificates = ... # type: Any + ca_certificates_file = ... # type: Any + port = ... # type: Any + http_exceptions = ... # type: Any + http_unretryable_exceptions = ... # type: Any + socket_exception_values = ... # type: Any + https_connection_factory = ... # type: Any + protocol = ... # type: str + host = ... # type: Any + path = ... # type: Any + debug = ... # type: Any + host_header = ... # type: Any + http_connection_kwargs = ... # type: Any + provider = ... # type: Any + auth_service_name = ... # type: Any + request_hook = ... # type: Any + def __init__(self, host, aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., is_secure: bool = ..., port: Optional[Any] = ..., proxy: Optional[Any] = ..., proxy_port: Optional[Any] = ..., proxy_user: Optional[Any] = ..., proxy_pass: Optional[Any] = ..., debug: int = ..., https_connection_factory: Optional[Any] = ..., path: str = ..., provider: str = ..., security_token: Optional[Any] = ..., suppress_consec_slashes: bool = ..., validate_certs: bool = ..., profile_name: Optional[Any] = ...) -> None: ... + auth_region_name = ... # type: Any + @property + def connection(self): ... + @property + def aws_access_key_id(self): ... + @property + def gs_access_key_id(self): ... # type: Any + access_key = ... # type: Any + @property + def aws_secret_access_key(self): ... + @property + def gs_secret_access_key(self): ... + secret_key = ... # type: Any + @property + def profile_name(self): ... + def get_path(self, path: str = ...): ... + def server_name(self, port: Optional[Any] = ...): ... + proxy = ... # type: Any + proxy_port = ... # type: Any + proxy_user = ... # type: Any + proxy_pass = ... # type: Any + no_proxy = ... # type: Any + use_proxy = ... # type: Any + def handle_proxy(self, proxy, proxy_port, proxy_user, proxy_pass): ... + def get_http_connection(self, host, port, is_secure): ... + def skip_proxy(self, host): ... + def new_http_connection(self, host, port, is_secure): ... + def put_http_connection(self, host, port, is_secure, connection): ... + def proxy_ssl(self, host: Optional[Any] = ..., port: Optional[Any] = ...): ... + def prefix_proxy_to_path(self, path, host: Optional[Any] = ...): ... + def get_proxy_auth_header(self): ... + def get_proxy_url_with_auth(self): ... + def set_host_header(self, request): ... + def set_request_hook(self, hook): ... + def build_base_http_request(self, method, path, auth_path, params: Optional[Any] = ..., headers: Optional[Any] = ..., data: str = ..., host: Optional[Any] = ...): ... + def make_request(self, method, path, headers: Optional[Any] = ..., data: str = ..., host: Optional[Any] = ..., auth_path: Optional[Any] = ..., sender: Optional[Any] = ..., override_num_retries: Optional[Any] = ..., params: Optional[Any] = ..., retry_handler: Optional[Any] = ...): ... + def close(self): ... + +class AWSQueryConnection(AWSAuthConnection): + APIVersion = ... # type: str + ResponseError = ... # type: Any + def __init__(self, aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., is_secure: bool = ..., port: Optional[Any] = ..., proxy: Optional[Any] = ..., proxy_port: Optional[Any] = ..., proxy_user: Optional[Any] = ..., proxy_pass: Optional[Any] = ..., host: Optional[Any] = ..., debug: int = ..., https_connection_factory: Optional[Any] = ..., path: str = ..., security_token: Optional[Any] = ..., validate_certs: bool = ..., profile_name: Optional[Any] = ..., provider: str = ...) -> None: ... + def get_utf8_value(self, value): ... + def make_request(self, action, params: Optional[Any] = ..., path: str = ..., verb: str = ..., *args, **kwargs): ... # type: ignore # https://github.com/python/mypy/issues/1237 + def build_list_params(self, params, items, label): ... + def build_complex_list_params(self, params, items, label, names): ... + def get_list(self, action, params, markers, path: str = ..., parent: Optional[Any] = ..., verb: str = ...): ... + def get_object(self, action, params, cls, path: str = ..., parent: Optional[Any] = ..., verb: str = ...): ... + def get_status(self, action, params, path: str = ..., parent: Optional[Any] = ..., verb: str = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/ec2/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/ec2/__init__.pyi new file mode 100644 index 000000000..edb9359ec --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/ec2/__init__.pyi @@ -0,0 +1,7 @@ +from typing import Any + +RegionData = ... # type: Any + +def regions(**kw_params): ... +def connect_to_region(region_name, **kw_params): ... +def get_region(region_name, **kw_params): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/elb/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/elb/__init__.pyi new file mode 100644 index 000000000..1d6c43ff3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/elb/__init__.pyi @@ -0,0 +1,39 @@ +from typing import Any +from boto.connection import AWSQueryConnection + +RegionData = ... # type: Any + +def regions(): ... +def connect_to_region(region_name, **kw_params): ... + +class ELBConnection(AWSQueryConnection): + APIVersion = ... # type: Any + DefaultRegionName = ... # type: Any + DefaultRegionEndpoint = ... # type: Any + region = ... # type: Any + def __init__(self, aws_access_key_id=..., aws_secret_access_key=..., is_secure=..., port=..., proxy=..., proxy_port=..., proxy_user=..., proxy_pass=..., debug=..., https_connection_factory=..., region=..., path=..., security_token=..., validate_certs=..., profile_name=...) -> None: ... + def build_list_params(self, params, items, label): ... + def get_all_load_balancers(self, load_balancer_names=..., marker=...): ... + def create_load_balancer(self, name, zones, listeners=..., subnets=..., security_groups=..., scheme=..., complex_listeners=...): ... + def create_load_balancer_listeners(self, name, listeners=..., complex_listeners=...): ... + def delete_load_balancer(self, name): ... + def delete_load_balancer_listeners(self, name, ports): ... + def enable_availability_zones(self, load_balancer_name, zones_to_add): ... + def disable_availability_zones(self, load_balancer_name, zones_to_remove): ... + def modify_lb_attribute(self, load_balancer_name, attribute, value): ... + def get_all_lb_attributes(self, load_balancer_name): ... + def get_lb_attribute(self, load_balancer_name, attribute): ... + def register_instances(self, load_balancer_name, instances): ... + def deregister_instances(self, load_balancer_name, instances): ... + def describe_instance_health(self, load_balancer_name, instances=...): ... + def configure_health_check(self, name, health_check): ... + def set_lb_listener_SSL_certificate(self, lb_name, lb_port, ssl_certificate_id): ... + def create_app_cookie_stickiness_policy(self, name, lb_name, policy_name): ... + def create_lb_cookie_stickiness_policy(self, cookie_expiration_period, lb_name, policy_name): ... + def create_lb_policy(self, lb_name, policy_name, policy_type, policy_attributes): ... + def delete_lb_policy(self, lb_name, policy_name): ... + def set_lb_policies_of_listener(self, lb_name, lb_port, policies): ... + def set_lb_policies_of_backend_server(self, lb_name, instance_port, policies): ... + def apply_security_groups_to_lb(self, name, security_groups): ... + def attach_lb_to_subnets(self, name, subnets): ... + def detach_lb_from_subnets(self, name, subnets): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/exception.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/exception.pyi new file mode 100644 index 000000000..bf11522b7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/exception.pyi @@ -0,0 +1,146 @@ +from typing import Any, Optional +from boto.compat import StandardError + +class BotoClientError(StandardError): + reason = ... # type: Any + def __init__(self, reason, *args) -> None: ... + +class SDBPersistenceError(StandardError): ... +class StoragePermissionsError(BotoClientError): ... +class S3PermissionsError(StoragePermissionsError): ... +class GSPermissionsError(StoragePermissionsError): ... + +class BotoServerError(StandardError): + status = ... # type: Any + reason = ... # type: Any + body = ... # type: Any + request_id = ... # type: Any + error_code = ... # type: Any + message = ... # type: str + box_usage = ... # type: Any + def __init__(self, status, reason, body: Optional[Any] = ..., *args) -> None: ... + def __getattr__(self, name): ... + def __setattr__(self, name, value): ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class ConsoleOutput: + parent = ... # type: Any + instance_id = ... # type: Any + timestamp = ... # type: Any + comment = ... # type: Any + output = ... # type: Any + def __init__(self, parent: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class StorageCreateError(BotoServerError): + bucket = ... # type: Any + def __init__(self, status, reason, body: Optional[Any] = ...) -> None: ... + def endElement(self, name, value, connection): ... + +class S3CreateError(StorageCreateError): ... +class GSCreateError(StorageCreateError): ... +class StorageCopyError(BotoServerError): ... +class S3CopyError(StorageCopyError): ... +class GSCopyError(StorageCopyError): ... + +class SQSError(BotoServerError): + detail = ... # type: Any + type = ... # type: Any + def __init__(self, status, reason, body: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class SQSDecodeError(BotoClientError): + message = ... # type: Any + def __init__(self, reason, message) -> None: ... + +class StorageResponseError(BotoServerError): + resource = ... # type: Any + def __init__(self, status, reason, body: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class S3ResponseError(StorageResponseError): ... +class GSResponseError(StorageResponseError): ... + +class EC2ResponseError(BotoServerError): + errors = ... # type: Any + def __init__(self, status, reason, body: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + request_id = ... # type: Any + def endElement(self, name, value, connection): ... + +class JSONResponseError(BotoServerError): + status = ... # type: Any + reason = ... # type: Any + body = ... # type: Any + error_message = ... # type: Any + error_code = ... # type: Any + def __init__(self, status, reason, body: Optional[Any] = ..., *args) -> None: ... + +class DynamoDBResponseError(JSONResponseError): ... +class SWFResponseError(JSONResponseError): ... +class EmrResponseError(BotoServerError): ... + +class _EC2Error: + connection = ... # type: Any + error_code = ... # type: Any + error_message = ... # type: Any + def __init__(self, connection: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class SDBResponseError(BotoServerError): ... +class AWSConnectionError(BotoClientError): ... +class StorageDataError(BotoClientError): ... +class S3DataError(StorageDataError): ... +class GSDataError(StorageDataError): ... + +class InvalidUriError(Exception): + message = ... # type: Any + def __init__(self, message) -> None: ... + +class InvalidAclError(Exception): + message = ... # type: Any + def __init__(self, message) -> None: ... + +class InvalidCorsError(Exception): + message = ... # type: Any + def __init__(self, message) -> None: ... + +class NoAuthHandlerFound(Exception): ... + +class InvalidLifecycleConfigError(Exception): + message = ... # type: Any + def __init__(self, message) -> None: ... + +class ResumableTransferDisposition: + START_OVER = ... # type: str + WAIT_BEFORE_RETRY = ... # type: str + ABORT_CUR_PROCESS = ... # type: str + ABORT = ... # type: str + +class ResumableUploadException(Exception): + message = ... # type: Any + disposition = ... # type: Any + def __init__(self, message, disposition) -> None: ... + +class ResumableDownloadException(Exception): + message = ... # type: Any + disposition = ... # type: Any + def __init__(self, message, disposition) -> None: ... + +class TooManyRecordsException(Exception): + message = ... # type: Any + def __init__(self, message) -> None: ... + +class PleaseRetryException(Exception): + message = ... # type: Any + response = ... # type: Any + def __init__(self, message, response: Optional[Any] = ...) -> None: ... + +class InvalidInstanceMetadataError(Exception): + MSG = ... # type: str + def __init__(self, msg) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/__init__.pyi new file mode 100644 index 000000000..41fff607e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/__init__.pyi @@ -0,0 +1,5 @@ +from typing import List +import boto.regioninfo + +def regions() -> List[boto.regioninfo.RegionInfo]: ... +def connect_to_region(region_name, **kw_params): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/exceptions.pyi new file mode 100644 index 000000000..5ac2ecd20 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/exceptions.pyi @@ -0,0 +1,17 @@ +from boto.exception import BotoServerError + +class InvalidGrantTokenException(BotoServerError): ... +class DisabledException(BotoServerError): ... +class LimitExceededException(BotoServerError): ... +class DependencyTimeoutException(BotoServerError): ... +class InvalidMarkerException(BotoServerError): ... +class AlreadyExistsException(BotoServerError): ... +class InvalidCiphertextException(BotoServerError): ... +class KeyUnavailableException(BotoServerError): ... +class InvalidAliasNameException(BotoServerError): ... +class UnsupportedOperationException(BotoServerError): ... +class InvalidArnException(BotoServerError): ... +class KMSInternalException(BotoServerError): ... +class InvalidKeyUsageException(BotoServerError): ... +class MalformedPolicyDocumentException(BotoServerError): ... +class NotFoundException(BotoServerError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/layer1.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/layer1.pyi new file mode 100644 index 000000000..558b02a12 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/kms/layer1.pyi @@ -0,0 +1,37 @@ +from typing import Any, Dict, List, Mapping, Optional, Type +from boto.connection import AWSQueryConnection + +class KMSConnection(AWSQueryConnection): + APIVersion = ... # type: str + DefaultRegionName = ... # type: str + DefaultRegionEndpoint = ... # type: str + ServiceName = ... # type: str + TargetPrefix = ... # type: str + ResponseError = ... # type: Type[Exception] + region = ... # type: Any + def __init__(self, **kwargs) -> None: ... + def create_alias(self, alias_name: str, target_key_id: str) -> Optional[Dict[str, Any]]: ... + def create_grant(self, key_id: str, grantee_principal: str, retiring_principal: Optional[str] = ..., operations: Optional[List[str]] = ..., constraints: Optional[Dict[str, Dict[str, str]]] = ..., grant_tokens: Optional[List[str]] = ...) -> Optional[Dict[str, Any]]: ... + def create_key(self, policy: Optional[str] = ..., description: Optional[str] = ..., key_usage: Optional[str] = ...) -> Optional[Dict[str, Any]]: ... + def decrypt(self, ciphertext_blob: bytes, encryption_context: Optional[Mapping[str, Any]] = ..., grant_tokens: Optional[List[str]] = ...) -> Optional[Dict[str, Any]]: ... + def delete_alias(self, alias_name: str) -> Optional[Dict[str, Any]]: ... + def describe_key(self, key_id: str) -> Optional[Dict[str, Any]]: ... + def disable_key(self, key_id: str) -> Optional[Dict[str, Any]]: ... + def disable_key_rotation(self, key_id: str) -> Optional[Dict[str, Any]]: ... + def enable_key(self, key_id: str) -> Optional[Dict[str, Any]]: ... + def enable_key_rotation(self, key_id: str) -> Optional[Dict[str, Any]]: ... + def encrypt(self, key_id: str, plaintext: bytes, encryption_context: Optional[Mapping[str, Any]] = ..., grant_tokens: Optional[List[str]] = ...) -> Optional[Dict[str, Any]]: ... + def generate_data_key(self, key_id: str, encryption_context: Optional[Mapping[str, Any]] = ..., number_of_bytes: Optional[int] = ..., key_spec: Optional[str] = ..., grant_tokens: Optional[List[str]] = ...) -> Optional[Dict[str, Any]]: ... + def generate_data_key_without_plaintext(self, key_id: str, encryption_context: Optional[Mapping[str, Any]] = ..., key_spec: Optional[str] = ..., number_of_bytes: Optional[int] = ..., grant_tokens: Optional[List[str]] = ...) -> Optional[Dict[str, Any]]: ... + def generate_random(self, number_of_bytes: Optional[int] = ...) -> Optional[Dict[str, Any]]: ... + def get_key_policy(self, key_id: str, policy_name: str) -> Optional[Dict[str, Any]]: ... + def get_key_rotation_status(self, key_id: str) -> Optional[Dict[str, Any]]: ... + def list_aliases(self, limit: Optional[int] = ..., marker: Optional[str] = ...) -> Optional[Dict[str, Any]]: ... + def list_grants(self, key_id: str, limit: Optional[int] = ..., marker: Optional[str] = ...) -> Optional[Dict[str, Any]]: ... + def list_key_policies(self, key_id: str, limit: Optional[int] = ..., marker: Optional[str] = ...) -> Optional[Dict[str, Any]]: ... + def list_keys(self, limit: Optional[int] = ..., marker: Optional[str] = ...) -> Optional[Dict[str, Any]]: ... + def put_key_policy(self, key_id: str, policy_name: str, policy: str) -> Optional[Dict[str, Any]]: ... + def re_encrypt(self, ciphertext_blob: bytes, destination_key_id: str, source_encryption_context: Optional[Mapping[str, Any]] = ..., destination_encryption_context: Optional[Mapping[str, Any]] = ..., grant_tokens: Optional[List[str]] = ...) -> Optional[Dict[str, Any]]: ... + def retire_grant(self, grant_token: str) -> Optional[Dict[str, Any]]: ... + def revoke_grant(self, key_id: str, grant_id: str) -> Optional[Dict[str, Any]]: ... + def update_key_description(self, key_id: str, description: str) -> Optional[Dict[str, Any]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/plugin.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/plugin.pyi new file mode 100644 index 000000000..c40c6c4e4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/plugin.pyi @@ -0,0 +1,9 @@ +from typing import Any, Optional + +class Plugin: + capability = ... # type: Any + @classmethod + def is_capable(cls, requested_capability): ... + +def get_plugin(cls, requested_capability: Optional[Any] = ...): ... +def load_plugins(config): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/regioninfo.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/regioninfo.pyi new file mode 100644 index 000000000..37726096d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/regioninfo.pyi @@ -0,0 +1,16 @@ +from typing import Any, Optional + +def load_endpoint_json(path): ... +def merge_endpoints(defaults, additions): ... +def load_regions(): ... +def get_regions(service_name, region_cls: Optional[Any] = ..., connection_cls: Optional[Any] = ...): ... + +class RegionInfo: + connection = ... # type: Any + name = ... # type: Any + endpoint = ... # type: Any + connection_cls = ... # type: Any + def __init__(self, connection: Optional[Any] = ..., name: Optional[Any] = ..., endpoint: Optional[Any] = ..., connection_cls: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def connect(self, **kw_params): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/__init__.pyi new file mode 100644 index 000000000..d88955e0d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/__init__.pyi @@ -0,0 +1,14 @@ +from typing import Optional + +from .connection import S3Connection + +from boto.connection import AWSAuthConnection +from boto.regioninfo import RegionInfo + +from typing import List, Type, Text + +class S3RegionInfo(RegionInfo): + def connect(self, name: Optional[Text] = ..., endpoint: Optional[str] = ..., connection_cls: Optional[Type[AWSAuthConnection]] = ..., **kw_params) -> S3Connection: ... + +def regions() -> List[S3RegionInfo]: ... +def connect_to_region(region_name: Text, **kw_params): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/acl.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/acl.pyi new file mode 100644 index 000000000..fccf21226 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/acl.pyi @@ -0,0 +1,39 @@ +from .connection import S3Connection +from .user import User +from typing import Any, Dict, Optional, List, Text, Union + +CannedACLStrings = ... # type: List[str] + +class Policy: + parent = ... # type: Any + namespace = ... # type: Any + acl = ... # type: ACL + def __init__(self, parent: Optional[Any] = ...) -> None: ... + owner = ... # type: User + def startElement(self, name: Text, attrs: Dict[str, Any], connection: S3Connection) -> Union[None, User, ACL]: ... + def endElement(self, name: Text, value: Any, connection: S3Connection) -> None: ... + def to_xml(self) -> str: ... + +class ACL: + policy = ... # type: Policy + grants = ... # type: List[Grant] + def __init__(self, policy: Optional[Policy] = ...) -> None: ... + def add_grant(self, grant: Grant) -> None: ... + def add_email_grant(self, permission: Text, email_address: Text) -> None: ... + def add_user_grant(self, permission: Text, user_id: Text, display_name: Optional[Text] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name: Text, value: Any, connection: S3Connection) -> None: ... + def to_xml(self) -> str: ... + +class Grant: + NameSpace = ... # type: Text + permission = ... # type: Text + id = ... # type: Text + display_name = ... # type: Text + uri = ... # type: Text + email_address = ... # type: Text + type = ... # type: Text + def __init__(self, permission: Optional[Text] = ..., type: Optional[Text] = ..., id: Optional[Text] = ..., display_name: Optional[Text] = ..., uri: Optional[Text] = ..., email_address: Optional[Text] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name: Text, value: Any, connection: S3Connection) -> None: ... + def to_xml(self) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucket.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucket.pyi new file mode 100644 index 000000000..031c55aef --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucket.pyi @@ -0,0 +1,94 @@ +from .bucketlistresultset import BucketListResultSet +from .connection import S3Connection +from .key import Key + +from typing import Any, Dict, Optional, Text, Type, List + +class S3WebsiteEndpointTranslate: + trans_region = ... # type: Dict[str, str] + @classmethod + def translate_region(self, reg: Text) -> str: ... + +S3Permissions = ... # type: List[str] + +class Bucket: + LoggingGroup = ... # type: str + BucketPaymentBody = ... # type: str + VersioningBody = ... # type: str + VersionRE = ... # type: str + MFADeleteRE = ... # type: str + name = ... # type: Text + connection = ... # type: S3Connection + key_class = ... # type: Type[Key] + def __init__(self, connection: Optional[S3Connection] = ..., name: Optional[Text] = ..., key_class: Type[Key] = ...) -> None: ... + def __iter__(self): ... + def __contains__(self, key_name) -> bool: ... + def startElement(self, name, attrs, connection): ... + creation_date = ... # type: Any + def endElement(self, name, value, connection): ... + def set_key_class(self, key_class): ... + def lookup(self, key_name, headers: Optional[Dict[Text, Text]] = ...): ... + def get_key(self, key_name, headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ..., response_headers: Optional[Dict[Text, Text]] = ..., validate: bool = ...) -> Key: ... + def list(self, prefix: Text = ..., delimiter: Text = ..., marker: Text = ..., headers: Optional[Dict[Text, Text]] = ..., encoding_type: Optional[Any] = ...) -> BucketListResultSet: ... + def list_versions(self, prefix: str = ..., delimiter: str = ..., key_marker: str = ..., version_id_marker: str = ..., headers: Optional[Dict[Text, Text]] = ..., encoding_type: Optional[Text] = ...) -> BucketListResultSet: ... + def list_multipart_uploads(self, key_marker: str = ..., upload_id_marker: str = ..., headers: Optional[Dict[Text, Text]] = ..., encoding_type: Optional[Any] = ...): ... + def validate_kwarg_names(self, kwargs, names): ... + def get_all_keys(self, headers: Optional[Dict[Text, Text]] = ..., **params): ... + def get_all_versions(self, headers: Optional[Dict[Text, Text]] = ..., **params): ... + def validate_get_all_versions_params(self, params): ... + def get_all_multipart_uploads(self, headers: Optional[Dict[Text, Text]] = ..., **params): ... + def new_key(self, key_name: Optional[Any] = ...): ... + def generate_url(self, expires_in, method: str = ..., headers: Optional[Dict[Text, Text]] = ..., force_http: bool = ..., response_headers: Optional[Dict[Text, Text]] = ..., expires_in_absolute: bool = ...): ... + def delete_keys(self, keys, quiet: bool = ..., mfa_token: Optional[Any] = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def delete_key(self, key_name, headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ..., mfa_token: Optional[Any] = ...): ... + def copy_key(self, new_key_name, src_bucket_name, src_key_name, metadata: Optional[Any] = ..., src_version_id: Optional[Any] = ..., storage_class: str = ..., preserve_acl: bool = ..., encrypt_key: bool = ..., headers: Optional[Dict[Text, Text]] = ..., query_args: Optional[Any] = ...): ... + def set_canned_acl(self, acl_str, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ...): ... + def get_xml_acl(self, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ...): ... + def set_xml_acl(self, acl_str, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ..., query_args: str = ...): ... + def set_acl(self, acl_or_str, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ...): ... + def get_acl(self, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ...): ... + def set_subresource(self, subresource, value, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ...): ... + def get_subresource(self, subresource, key_name: str = ..., headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ...): ... + def make_public(self, recursive: bool = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def add_email_grant(self, permission, email_address, recursive: bool = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def add_user_grant(self, permission, user_id, recursive: bool = ..., headers: Optional[Dict[Text, Text]] = ..., display_name: Optional[Any] = ...): ... + def list_grants(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_location(self): ... + def set_xml_logging(self, logging_str, headers: Optional[Dict[Text, Text]] = ...): ... + def enable_logging(self, target_bucket, target_prefix: str = ..., grants: Optional[Any] = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def disable_logging(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_logging_status(self, headers: Optional[Dict[Text, Text]] = ...): ... + def set_as_logging_target(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_request_payment(self, headers: Optional[Dict[Text, Text]] = ...): ... + def set_request_payment(self, payer: str = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def configure_versioning(self, versioning, mfa_delete: bool = ..., mfa_token: Optional[Any] = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def get_versioning_status(self, headers: Optional[Dict[Text, Text]] = ...): ... + def configure_lifecycle(self, lifecycle_config, headers: Optional[Dict[Text, Text]] = ...): ... + def get_lifecycle_config(self, headers: Optional[Dict[Text, Text]] = ...): ... + def delete_lifecycle_configuration(self, headers: Optional[Dict[Text, Text]] = ...): ... + def configure_website(self, suffix: Optional[Any] = ..., error_key: Optional[Any] = ..., redirect_all_requests_to: Optional[Any] = ..., routing_rules: Optional[Any] = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def set_website_configuration(self, config, headers: Optional[Dict[Text, Text]] = ...): ... + def set_website_configuration_xml(self, xml, headers: Optional[Dict[Text, Text]] = ...): ... + def get_website_configuration(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_website_configuration_obj(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_website_configuration_with_xml(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_website_configuration_xml(self, headers: Optional[Dict[Text, Text]] = ...): ... + def delete_website_configuration(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_website_endpoint(self): ... + def get_policy(self, headers: Optional[Dict[Text, Text]] = ...): ... + def set_policy(self, policy, headers: Optional[Dict[Text, Text]] = ...): ... + def delete_policy(self, headers: Optional[Dict[Text, Text]] = ...): ... + def set_cors_xml(self, cors_xml, headers: Optional[Dict[Text, Text]] = ...): ... + def set_cors(self, cors_config, headers: Optional[Dict[Text, Text]] = ...): ... + def get_cors_xml(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_cors(self, headers: Optional[Dict[Text, Text]] = ...): ... + def delete_cors(self, headers: Optional[Dict[Text, Text]] = ...): ... + def initiate_multipart_upload(self, key_name, headers: Optional[Dict[Text, Text]] = ..., reduced_redundancy: bool = ..., metadata: Optional[Any] = ..., encrypt_key: bool = ..., policy: Optional[Any] = ...): ... + def complete_multipart_upload(self, key_name, upload_id, xml_body, headers: Optional[Dict[Text, Text]] = ...): ... + def cancel_multipart_upload(self, key_name, upload_id, headers: Optional[Dict[Text, Text]] = ...): ... + def delete(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_tags(self): ... + def get_xml_tags(self): ... + def set_xml_tags(self, tag_str, headers: Optional[Dict[Text, Text]] = ..., query_args: str = ...): ... + def set_tags(self, tags, headers: Optional[Dict[Text, Text]] = ...): ... + def delete_tags(self, headers: Optional[Dict[Text, Text]] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucketlistresultset.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucketlistresultset.pyi new file mode 100644 index 000000000..e219faaa6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucketlistresultset.pyi @@ -0,0 +1,40 @@ +from .bucket import Bucket +from .key import Key + +from typing import Any, Iterable, Iterator, Optional + +def bucket_lister(bucket, prefix: str = ..., delimiter: str = ..., marker: str = ..., headers: Optional[Any] = ..., encoding_type: Optional[Any] = ...): ... + +class BucketListResultSet(Iterable[Key]): + bucket = ... # type: Any + prefix = ... # type: Any + delimiter = ... # type: Any + marker = ... # type: Any + headers = ... # type: Any + encoding_type = ... # type: Any + def __init__(self, bucket: Optional[Any] = ..., prefix: str = ..., delimiter: str = ..., marker: str = ..., headers: Optional[Any] = ..., encoding_type: Optional[Any] = ...) -> None: ... + def __iter__(self) -> Iterator[Key]: ... + +def versioned_bucket_lister(bucket, prefix: str = ..., delimiter: str = ..., key_marker: str = ..., version_id_marker: str = ..., headers: Optional[Any] = ..., encoding_type: Optional[Any] = ...): ... + +class VersionedBucketListResultSet: + bucket = ... # type: Any + prefix = ... # type: Any + delimiter = ... # type: Any + key_marker = ... # type: Any + version_id_marker = ... # type: Any + headers = ... # type: Any + encoding_type = ... # type: Any + def __init__(self, bucket: Optional[Any] = ..., prefix: str = ..., delimiter: str = ..., key_marker: str = ..., version_id_marker: str = ..., headers: Optional[Any] = ..., encoding_type: Optional[Any] = ...) -> None: ... + def __iter__(self) -> Iterator[Key]: ... + +def multipart_upload_lister(bucket, key_marker: str = ..., upload_id_marker: str = ..., headers: Optional[Any] = ..., encoding_type: Optional[Any] = ...): ... + +class MultiPartUploadListResultSet: + bucket = ... # type: Any + key_marker = ... # type: Any + upload_id_marker = ... # type: Any + headers = ... # type: Any + encoding_type = ... # type: Any + def __init__(self, bucket: Optional[Any] = ..., key_marker: str = ..., upload_id_marker: str = ..., headers: Optional[Any] = ..., encoding_type: Optional[Any] = ...) -> None: ... + def __iter__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucketlogging.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucketlogging.pyi new file mode 100644 index 000000000..5c53f2a93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/bucketlogging.pyi @@ -0,0 +1,11 @@ +from typing import Any, Optional + +class BucketLogging: + target = ... # type: Any + prefix = ... # type: Any + grants = ... # type: Any + def __init__(self, target: Optional[Any] = ..., prefix: Optional[Any] = ..., grants: Optional[Any] = ...) -> None: ... + def add_grant(self, grant): ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/connection.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/connection.pyi new file mode 100644 index 000000000..c84f20dc6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/connection.pyi @@ -0,0 +1,67 @@ +from .bucket import Bucket + +from typing import Any, Dict, Optional, Text, Type +from boto.connection import AWSAuthConnection +from boto.exception import BotoClientError + +def check_lowercase_bucketname(n): ... +def assert_case_insensitive(f): ... + +class _CallingFormat: + def get_bucket_server(self, server, bucket): ... + def build_url_base(self, connection, protocol, server, bucket, key: str = ...): ... + def build_host(self, server, bucket): ... + def build_auth_path(self, bucket, key: str = ...): ... + def build_path_base(self, bucket, key: str = ...): ... + +class SubdomainCallingFormat(_CallingFormat): + def get_bucket_server(self, server, bucket): ... + +class VHostCallingFormat(_CallingFormat): + def get_bucket_server(self, server, bucket): ... + +class OrdinaryCallingFormat(_CallingFormat): + def get_bucket_server(self, server, bucket): ... + def build_path_base(self, bucket, key: str = ...): ... + +class ProtocolIndependentOrdinaryCallingFormat(OrdinaryCallingFormat): + def build_url_base(self, connection, protocol, server, bucket, key: str = ...): ... + +class Location: + DEFAULT = ... # type: str + EU = ... # type: str + EUCentral1 = ... # type: str + USWest = ... # type: str + USWest2 = ... # type: str + SAEast = ... # type: str + APNortheast = ... # type: str + APSoutheast = ... # type: str + APSoutheast2 = ... # type: str + CNNorth1 = ... # type: str + +class NoHostProvided: ... +class HostRequiredError(BotoClientError): ... + +class S3Connection(AWSAuthConnection): + DefaultHost = ... # type: Any + DefaultCallingFormat = ... # type: Any + QueryString = ... # type: str + calling_format = ... # type: Any + bucket_class = ... # type: Type[Bucket] + anon = ... # type: Any + def __init__(self, aws_access_key_id: Optional[Any] = ..., aws_secret_access_key: Optional[Any] = ..., is_secure: bool = ..., port: Optional[Any] = ..., proxy: Optional[Any] = ..., proxy_port: Optional[Any] = ..., proxy_user: Optional[Any] = ..., proxy_pass: Optional[Any] = ..., host: Any = ..., debug: int = ..., https_connection_factory: Optional[Any] = ..., calling_format: Any = ..., path: str = ..., provider: str = ..., bucket_class: Type[Bucket] = ..., security_token: Optional[Any] = ..., suppress_consec_slashes: bool = ..., anon: bool = ..., validate_certs: Optional[Any] = ..., profile_name: Optional[Any] = ...) -> None: ... + def __iter__(self): ... + def __contains__(self, bucket_name): ... + def set_bucket_class(self, bucket_class: Type[Bucket]) -> None: ... + def build_post_policy(self, expiration_time, conditions): ... + def build_post_form_args(self, bucket_name, key, expires_in: int = ..., acl: Optional[Any] = ..., success_action_redirect: Optional[Any] = ..., max_content_length: Optional[Any] = ..., http_method: str = ..., fields: Optional[Any] = ..., conditions: Optional[Any] = ..., storage_class: str = ..., server_side_encryption: Optional[Any] = ...): ... + def generate_url_sigv4(self, expires_in, method, bucket: str = ..., key: str = ..., headers: Optional[Dict[Text, Text]] = ..., force_http: bool = ..., response_headers: Optional[Dict[Text, Text]] = ..., version_id: Optional[Any] = ..., iso_date: Optional[Any] = ...): ... + def generate_url(self, expires_in, method, bucket: str = ..., key: str = ..., headers: Optional[Dict[Text, Text]] = ..., query_auth: bool = ..., force_http: bool = ..., response_headers: Optional[Dict[Text, Text]] = ..., expires_in_absolute: bool = ..., version_id: Optional[Any] = ...): ... + def get_all_buckets(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_canonical_user_id(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_bucket(self, bucket_name: Text, validate: bool = ..., headers: Optional[Dict[Text, Text]] = ...) -> Bucket: ... + def head_bucket(self, bucket_name, headers: Optional[Dict[Text, Text]] = ...): ... + def lookup(self, bucket_name, validate: bool = ..., headers: Optional[Dict[Text, Text]] = ...): ... + def create_bucket(self, bucket_name, headers: Optional[Dict[Text, Text]] = ..., location: Any = ..., policy: Optional[Any] = ...): ... + def delete_bucket(self, bucket, headers: Optional[Dict[Text, Text]] = ...): ... + def make_request(self, method, bucket: str = ..., key: str = ..., headers: Optional[Any] = ..., data: str = ..., query_args: Optional[Any] = ..., sender: Optional[Any] = ..., override_num_retries: Optional[Any] = ..., retry_handler: Optional[Any] = ..., *args, **kwargs): ... # type: ignore # https://github.com/python/mypy/issues/1237 diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/cors.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/cors.pyi new file mode 100644 index 000000000..9ae263db8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/cors.pyi @@ -0,0 +1,19 @@ +from typing import Any, Optional + +class CORSRule: + allowed_method = ... # type: Any + allowed_origin = ... # type: Any + id = ... # type: Any + allowed_header = ... # type: Any + max_age_seconds = ... # type: Any + expose_header = ... # type: Any + def __init__(self, allowed_method: Optional[Any] = ..., allowed_origin: Optional[Any] = ..., id: Optional[Any] = ..., allowed_header: Optional[Any] = ..., max_age_seconds: Optional[Any] = ..., expose_header: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self) -> str: ... + +class CORSConfiguration(list): + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self) -> str: ... + def add_rule(self, allowed_method, allowed_origin, id: Optional[Any] = ..., allowed_header: Optional[Any] = ..., max_age_seconds: Optional[Any] = ..., expose_header: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/deletemarker.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/deletemarker.pyi new file mode 100644 index 000000000..b2ad36a44 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/deletemarker.pyi @@ -0,0 +1,12 @@ +from typing import Any, Optional + +class DeleteMarker: + bucket = ... # type: Any + name = ... # type: Any + version_id = ... # type: Any + is_latest = ... # type: bool + last_modified = ... # type: Any + owner = ... # type: Any + def __init__(self, bucket: Optional[Any] = ..., name: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/key.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/key.pyi new file mode 100644 index 000000000..ed44009b1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/key.pyi @@ -0,0 +1,87 @@ +from typing import Any, Callable, Dict, Optional, Text + +class Key: + DefaultContentType = ... # type: str + RestoreBody = ... # type: str + BufferSize = ... # type: Any + base_user_settable_fields = ... # type: Any + base_fields = ... # type: Any + bucket = ... # type: Any + name = ... # type: str + metadata = ... # type: Any + cache_control = ... # type: Any + content_type = ... # type: Any + content_encoding = ... # type: Any + content_disposition = ... # type: Any + content_language = ... # type: Any + filename = ... # type: Any + etag = ... # type: Any + is_latest = ... # type: bool + last_modified = ... # type: Any + owner = ... # type: Any + path = ... # type: Any + resp = ... # type: Any + mode = ... # type: Any + size = ... # type: Any + version_id = ... # type: Any + source_version_id = ... # type: Any + delete_marker = ... # type: bool + encrypted = ... # type: Any + ongoing_restore = ... # type: Any + expiry_date = ... # type: Any + local_hashes = ... # type: Any + def __init__(self, bucket: Optional[Any] = ..., name: Optional[Any] = ...) -> None: ... + def __iter__(self): ... + @property + def provider(self): ... + key = ... # type: Any + md5 = ... # type: Any + base64md5 = ... # type: Any + storage_class = ... # type: Any + def get_md5_from_hexdigest(self, md5_hexdigest): ... + def handle_encryption_headers(self, resp): ... + def handle_version_headers(self, resp, force: bool = ...): ... + def handle_restore_headers(self, response): ... + def handle_addl_headers(self, headers): ... + def open_read(self, headers: Optional[Dict[Text, Text]] = ..., query_args: str = ..., override_num_retries: Optional[Any] = ..., response_headers: Optional[Dict[Text, Text]] = ...): ... + def open_write(self, headers: Optional[Dict[Text, Text]] = ..., override_num_retries: Optional[Any] = ...): ... + def open(self, mode: str = ..., headers: Optional[Dict[Text, Text]] = ..., query_args: Optional[Any] = ..., override_num_retries: Optional[Any] = ...): ... + closed = ... # type: bool + def close(self, fast: bool = ...): ... + def next(self): ... + __next__ = ... # type: Any + def read(self, size: int = ...): ... + def change_storage_class(self, new_storage_class, dst_bucket: Optional[Any] = ..., validate_dst_bucket: bool = ...): ... + def copy(self, dst_bucket, dst_key, metadata: Optional[Any] = ..., reduced_redundancy: bool = ..., preserve_acl: bool = ..., encrypt_key: bool = ..., validate_dst_bucket: bool = ...): ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def exists(self, headers: Optional[Dict[Text, Text]] = ...): ... + def delete(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_metadata(self, name): ... + def set_metadata(self, name, value): ... + def update_metadata(self, d): ... + def set_acl(self, acl_str, headers: Optional[Dict[Text, Text]] = ...): ... + def get_acl(self, headers: Optional[Dict[Text, Text]] = ...): ... + def get_xml_acl(self, headers: Optional[Dict[Text, Text]] = ...): ... + def set_xml_acl(self, acl_str, headers: Optional[Dict[Text, Text]] = ...): ... + def set_canned_acl(self, acl_str, headers: Optional[Dict[Text, Text]] = ...): ... + def get_redirect(self): ... + def set_redirect(self, redirect_location, headers: Optional[Dict[Text, Text]] = ...): ... + def make_public(self, headers: Optional[Dict[Text, Text]] = ...): ... + def generate_url(self, expires_in, method: str = ..., headers: Optional[Dict[Text, Text]] = ..., query_auth: bool = ..., force_http: bool = ..., response_headers: Optional[Dict[Text, Text]] = ..., expires_in_absolute: bool = ..., version_id: Optional[Any] = ..., policy: Optional[Any] = ..., reduced_redundancy: bool = ..., encrypt_key: bool = ...): ... + def send_file(self, fp, headers: Optional[Dict[Text, Text]] = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., query_args: Optional[Any] = ..., chunked_transfer: bool = ..., size: Optional[Any] = ...): ... + def should_retry(self, response, chunked_transfer: bool = ...): ... + def compute_md5(self, fp, size: Optional[Any] = ...): ... + def set_contents_from_stream(self, fp, headers: Optional[Dict[Text, Text]] = ..., replace: bool = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., policy: Optional[Any] = ..., reduced_redundancy: bool = ..., query_args: Optional[Any] = ..., size: Optional[Any] = ...): ... + def set_contents_from_file(self, fp, headers: Optional[Dict[Text, Text]] = ..., replace: bool = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., policy: Optional[Any] = ..., md5: Optional[Any] = ..., reduced_redundancy: bool = ..., query_args: Optional[Any] = ..., encrypt_key: bool = ..., size: Optional[Any] = ..., rewind: bool = ...): ... + def set_contents_from_filename(self, filename, headers: Optional[Dict[Text, Text]] = ..., replace: bool = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., policy: Optional[Any] = ..., md5: Optional[Any] = ..., reduced_redundancy: bool = ..., encrypt_key: bool = ...): ... + def set_contents_from_string(self, string_data: Text, headers: Optional[Dict[Text, Text]] = ..., replace: bool = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., policy: Optional[Any] = ..., md5: Optional[Any] = ..., reduced_redundancy: bool = ..., encrypt_key: bool = ...) -> None: ... + def get_file(self, fp, headers: Optional[Dict[Text, Text]] = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., torrent: bool = ..., version_id: Optional[Any] = ..., override_num_retries: Optional[Any] = ..., response_headers: Optional[Dict[Text, Text]] = ...): ... + def get_torrent_file(self, fp, headers: Optional[Dict[Text, Text]] = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ...): ... + def get_contents_to_file(self, fp, headers: Optional[Dict[Text, Text]] = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., torrent: bool = ..., version_id: Optional[Any] = ..., res_download_handler: Optional[Any] = ..., response_headers: Optional[Dict[Text, Text]] = ...): ... + def get_contents_to_filename(self, filename, headers: Optional[Dict[Text, Text]] = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., torrent: bool = ..., version_id: Optional[Any] = ..., res_download_handler: Optional[Any] = ..., response_headers: Optional[Dict[Text, Text]] = ...): ... + def get_contents_as_string(self, headers: Optional[Dict[Text, Text]] = ..., cb: Optional[Callable[[int, int], Any]] = ..., num_cb: int = ..., torrent: bool = ..., version_id: Optional[Any] = ..., response_headers: Optional[Dict[Text, Text]] = ..., encoding: Optional[Any] = ...) -> str: ... + def add_email_grant(self, permission, email_address, headers: Optional[Dict[Text, Text]] = ...): ... + def add_user_grant(self, permission, user_id, headers: Optional[Dict[Text, Text]] = ..., display_name: Optional[Any] = ...): ... + def set_remote_metadata(self, metadata_plus, metadata_minus, preserve_acl, headers: Optional[Dict[Text, Text]] = ...): ... + def restore(self, days, headers: Optional[Dict[Text, Text]] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/keyfile.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/keyfile.pyi new file mode 100644 index 000000000..447ab1667 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/keyfile.pyi @@ -0,0 +1,29 @@ +from typing import Any + +class KeyFile: + key = ... # type: Any + location = ... # type: int + closed = ... # type: bool + softspace = ... # type: int + mode = ... # type: str + encoding = ... # type: str + errors = ... # type: str + newlines = ... # type: str + name = ... # type: Any + def __init__(self, key) -> None: ... + def tell(self): ... + def seek(self, pos, whence: Any = ...): ... + def read(self, size): ... + def close(self): ... + def isatty(self): ... + def getkey(self): ... + def write(self, buf): ... + def fileno(self): ... + def flush(self): ... + def next(self): ... + def readinto(self): ... + def readline(self): ... + def readlines(self): ... + def truncate(self): ... + def writelines(self): ... + def xreadlines(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/lifecycle.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/lifecycle.pyi new file mode 100644 index 000000000..18a7533e6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/lifecycle.pyi @@ -0,0 +1,51 @@ +from typing import Any, Optional + +class Rule: + id = ... # type: Any + prefix = ... # type: Any + status = ... # type: Any + expiration = ... # type: Any + transition = ... # type: Any + def __init__(self, id: Optional[Any] = ..., prefix: Optional[Any] = ..., status: Optional[Any] = ..., expiration: Optional[Any] = ..., transition: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + +class Expiration: + days = ... # type: Any + date = ... # type: Any + def __init__(self, days: Optional[Any] = ..., date: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + +class Transition: + days = ... # type: Any + date = ... # type: Any + storage_class = ... # type: Any + def __init__(self, days: Optional[Any] = ..., date: Optional[Any] = ..., storage_class: Optional[Any] = ...) -> None: ... + def to_xml(self): ... + +class Transitions(list): + transition_properties = ... # type: int + current_transition_property = ... # type: int + temp_days = ... # type: Any + temp_date = ... # type: Any + temp_storage_class = ... # type: Any + def __init__(self) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + def add_transition(self, days: Optional[Any] = ..., date: Optional[Any] = ..., storage_class: Optional[Any] = ...): ... + @property + def days(self): ... + @property + def date(self): ... + @property + def storage_class(self): ... + +class Lifecycle(list): + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + def add_rule(self, id: Optional[Any] = ..., prefix: str = ..., status: str = ..., expiration: Optional[Any] = ..., transition: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/multidelete.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/multidelete.pyi new file mode 100644 index 000000000..fa19cadd3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/multidelete.pyi @@ -0,0 +1,27 @@ +from typing import Any, Optional + +class Deleted: + key = ... # type: Any + version_id = ... # type: Any + delete_marker = ... # type: Any + delete_marker_version_id = ... # type: Any + def __init__(self, key: Optional[Any] = ..., version_id: Optional[Any] = ..., delete_marker: bool = ..., delete_marker_version_id: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class Error: + key = ... # type: Any + version_id = ... # type: Any + code = ... # type: Any + message = ... # type: Any + def __init__(self, key: Optional[Any] = ..., version_id: Optional[Any] = ..., code: Optional[Any] = ..., message: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class MultiDeleteResult: + bucket = ... # type: Any + deleted = ... # type: Any + errors = ... # type: Any + def __init__(self, bucket: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/multipart.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/multipart.pyi new file mode 100644 index 000000000..81a9452ca --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/multipart.pyi @@ -0,0 +1,49 @@ +from typing import Any, Optional + +class CompleteMultiPartUpload: + bucket = ... # type: Any + location = ... # type: Any + bucket_name = ... # type: Any + key_name = ... # type: Any + etag = ... # type: Any + version_id = ... # type: Any + encrypted = ... # type: Any + def __init__(self, bucket: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +class Part: + bucket = ... # type: Any + part_number = ... # type: Any + last_modified = ... # type: Any + etag = ... # type: Any + size = ... # type: Any + def __init__(self, bucket: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + +def part_lister(mpupload, part_number_marker: Optional[Any] = ...): ... + +class MultiPartUpload: + bucket = ... # type: Any + bucket_name = ... # type: Any + key_name = ... # type: Any + id = ... # type: Any + initiator = ... # type: Any + owner = ... # type: Any + storage_class = ... # type: Any + initiated = ... # type: Any + part_number_marker = ... # type: Any + next_part_number_marker = ... # type: Any + max_parts = ... # type: Any + is_truncated = ... # type: bool + def __init__(self, bucket: Optional[Any] = ...) -> None: ... + def __iter__(self): ... + def to_xml(self): ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def get_all_parts(self, max_parts: Optional[Any] = ..., part_number_marker: Optional[Any] = ..., encoding_type: Optional[Any] = ...): ... + def upload_part_from_file(self, fp, part_num, headers: Optional[Any] = ..., replace: bool = ..., cb: Optional[Any] = ..., num_cb: int = ..., md5: Optional[Any] = ..., size: Optional[Any] = ...): ... + def copy_part_from_key(self, src_bucket_name, src_key_name, part_num, start: Optional[Any] = ..., end: Optional[Any] = ..., src_version_id: Optional[Any] = ..., headers: Optional[Any] = ...): ... + def complete_upload(self): ... + def cancel_upload(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/prefix.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/prefix.pyi new file mode 100644 index 000000000..0d7b61a58 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/prefix.pyi @@ -0,0 +1,10 @@ +from typing import Any, Optional + +class Prefix: + bucket = ... # type: Any + name = ... # type: Any + def __init__(self, bucket: Optional[Any] = ..., name: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + @property + def provider(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/tagging.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/tagging.pyi new file mode 100644 index 000000000..4f4ad0496 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/tagging.pyi @@ -0,0 +1,22 @@ +from typing import Any, Optional + +class Tag: + key = ... # type: Any + value = ... # type: Any + def __init__(self, key: Optional[Any] = ..., value: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + def __eq__(self, other): ... + +class TagSet(list): + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def add_tag(self, key, value): ... + def to_xml(self): ... + +class Tags(list): + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + def add_tag_set(self, tag_set): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/user.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/user.pyi new file mode 100644 index 000000000..73d93428e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/user.pyi @@ -0,0 +1,10 @@ +from typing import Any, Optional + +class User: + type = ... # type: Any + id = ... # type: Any + display_name = ... # type: Any + def __init__(self, parent: Optional[Any] = ..., id: str = ..., display_name: str = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self, element_name: str = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/website.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/website.pyi new file mode 100644 index 000000000..b410b82d1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/s3/website.pyi @@ -0,0 +1,62 @@ +from typing import Any, Optional + +def tag(key, value): ... + +class WebsiteConfiguration: + suffix = ... # type: Any + error_key = ... # type: Any + redirect_all_requests_to = ... # type: Any + routing_rules = ... # type: Any + def __init__(self, suffix: Optional[Any] = ..., error_key: Optional[Any] = ..., redirect_all_requests_to: Optional[Any] = ..., routing_rules: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + +class _XMLKeyValue: + translator = ... # type: Any + container = ... # type: Any + def __init__(self, translator, container: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + +class RedirectLocation(_XMLKeyValue): + TRANSLATOR = ... # type: Any + hostname = ... # type: Any + protocol = ... # type: Any + def __init__(self, hostname: Optional[Any] = ..., protocol: Optional[Any] = ...) -> None: ... + def to_xml(self): ... + +class RoutingRules(list): + def add_rule(self, rule): ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + +class RoutingRule: + condition = ... # type: Any + redirect = ... # type: Any + def __init__(self, condition: Optional[Any] = ..., redirect: Optional[Any] = ...) -> None: ... + def startElement(self, name, attrs, connection): ... + def endElement(self, name, value, connection): ... + def to_xml(self): ... + @classmethod + def when(cls, key_prefix: Optional[Any] = ..., http_error_code: Optional[Any] = ...): ... + def then_redirect(self, hostname: Optional[Any] = ..., protocol: Optional[Any] = ..., replace_key: Optional[Any] = ..., replace_key_prefix: Optional[Any] = ..., http_redirect_code: Optional[Any] = ...): ... + +class Condition(_XMLKeyValue): + TRANSLATOR = ... # type: Any + key_prefix = ... # type: Any + http_error_code = ... # type: Any + def __init__(self, key_prefix: Optional[Any] = ..., http_error_code: Optional[Any] = ...) -> None: ... + def to_xml(self): ... + +class Redirect(_XMLKeyValue): + TRANSLATOR = ... # type: Any + hostname = ... # type: Any + protocol = ... # type: Any + replace_key = ... # type: Any + replace_key_prefix = ... # type: Any + http_redirect_code = ... # type: Any + def __init__(self, hostname: Optional[Any] = ..., protocol: Optional[Any] = ..., replace_key: Optional[Any] = ..., replace_key_prefix: Optional[Any] = ..., http_redirect_code: Optional[Any] = ...) -> None: ... + def to_xml(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/utils.pyi new file mode 100644 index 000000000..b3c542540 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/boto/utils.pyi @@ -0,0 +1,239 @@ +import datetime +import logging.handlers +import subprocess +import sys +import time + +import boto.connection +from typing import ( + Any, + Callable, + ContextManager, + Dict, + IO, + Iterable, + List, + Mapping, + Optional, + Sequence, + Tuple, + Type, + TypeVar, + Union, +) + +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +if sys.version_info[0] >= 3: + # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO + import io + _StringIO = io.StringIO + + from hashlib import _Hash + _HashType = _Hash + + from email.message import Message as _Message +else: + # TODO move _StringIO definition into boto.compat once stubs exist and rename to StringIO + import StringIO + _StringIO = StringIO.StringIO + + from hashlib import _hash + _HashType = _hash + + # TODO use email.message.Message once stubs exist + _Message = Any + +_Provider = Any # TODO replace this with boto.provider.Provider once stubs exist +_LockType = Any # TODO replace this with _thread.LockType once stubs exist + + +JSONDecodeError = ... # type: Type[ValueError] +qsa_of_interest = ... # type: List[str] + + +def unquote_v(nv: str) -> Union[str, Tuple[str, str]]: ... +def canonical_string( + method: str, + path: str, + headers: Mapping[str, Optional[str]], + expires: Optional[int] = ..., + provider: Optional[_Provider] = ..., +) -> str: ... +def merge_meta( + headers: Mapping[str, str], + metadata: Mapping[str, str], + provider: Optional[_Provider] = ..., +) -> Mapping[str, str]: ... +def get_aws_metadata( + headers: Mapping[str, str], + provider: Optional[_Provider] = ..., +) -> Mapping[str, str]: ... +def retry_url( + url: str, + retry_on_404: bool = ..., + num_retries: int = ..., + timeout: Optional[int] = ..., +) -> str: ... + +class LazyLoadMetadata(Dict[_KT, _VT]): + def __init__( + self, + url: str, + num_retries: int, + timeout: Optional[int] = ..., + ) -> None: ... + +def get_instance_metadata( + version: str = ..., + url: str = ..., + data: str = ..., + timeout: Optional[int] = ..., + num_retries: int = ..., +) -> Optional[LazyLoadMetadata]: ... +def get_instance_identity( + version: str = ..., + url: str = ..., + timeout: Optional[int] = ..., + num_retries: int = ..., +) -> Optional[Mapping[str, Any]]: ... +def get_instance_userdata( + version: str = ..., + sep: Optional[str] = ..., + url: str = ..., + timeout: Optional[int] = ..., + num_retries: int = ..., +) -> Mapping[str, str]: ... + +ISO8601 = ... # type: str +ISO8601_MS = ... # type: str +RFC1123 = ... # type: str +LOCALE_LOCK = ... # type: _LockType + +def setlocale(name: Union[str, Tuple[str, str]]) -> ContextManager[str]: ... +def get_ts(ts: Optional[time.struct_time] = ...) -> str: ... +def parse_ts(ts: str) -> datetime.datetime: ... +def find_class(module_name: str, class_name: Optional[str] = ...) -> Optional[Type[Any]]: ... +def update_dme(username: str, password: str, dme_id: str, ip_address: str) -> str: ... +def fetch_file( + uri: str, + file: Optional[IO[str]] = ..., + username: Optional[str] = ..., + password: Optional[str] = ..., +) -> Optional[IO[str]]: ... + +class ShellCommand: + exit_code = ... # type: int + command = ... # type: subprocess._CMD + log_fp = ... # type: _StringIO + wait = ... # type: bool + fail_fast = ... # type: bool + + def __init__( + self, + command: subprocess._CMD, + wait: bool = ..., + fail_fast: bool = ..., + cwd: Optional[subprocess._TXT] = ..., + ) -> None: ... + + process = ... # type: subprocess.Popen + + def run(self, cwd: Optional[subprocess._CMD] = ...) -> Optional[int]: ... + def setReadOnly(self, value) -> None: ... + def getStatus(self) -> Optional[int]: ... + + status = ... # type: Optional[int] + + def getOutput(self) -> str: ... + + output = ... # type: str + +class AuthSMTPHandler(logging.handlers.SMTPHandler): + username = ... # type: str + password = ... # type: str + def __init__( + self, + mailhost: str, + username: str, + password: str, + fromaddr: str, + toaddrs: Sequence[str], + subject: str, + ) -> None: ... + +class LRUCache(Dict[_KT, _VT]): + class _Item: + previous = ... # type: Optional[LRUCache._Item] + next = ... # type: Optional[LRUCache._Item] + key = ... + value = ... + def __init__(self, key, value) -> None: ... + + _dict = ... # type: Dict[_KT, LRUCache._Item] + capacity = ... # type: int + head = ... # type: Optional[LRUCache._Item] + tail = ... # type: Optional[LRUCache._Item] + + def __init__(self, capacity: int) -> None: ... + + +# This exists to work around Password.str's name shadowing the str type +_str = str + +class Password: + hashfunc = ... # type: Callable[[bytes], _HashType] + str = ... # type: Optional[_str] + + def __init__( + self, + str: Optional[_str] = ..., + hashfunc: Optional[Callable[[bytes], _HashType]] = ..., + ) -> None: ... + def set(self, value: Union[bytes, _str]) -> None: ... + def __eq__(self, other: Any) -> bool: ... + def __len__(self) -> int: ... + +def notify( + subject: str, + body: Optional[str] = ..., + html_body: Optional[Union[Sequence[str], str]] = ..., + to_string: Optional[str] = ..., + attachments: Optional[Iterable[_Message]] = ..., + append_instance_id: bool = ..., +) -> None: ... +def get_utf8_value(value: str) -> bytes: ... +def mklist(value: Any) -> List: ... +def pythonize_name(name: str) -> str: ... +def write_mime_multipart( + content: List[Tuple[str, str]], + compress: bool = ..., + deftype: str = ..., + delimiter: str = ..., +) -> str: ... +def guess_mime_type(content: str, deftype: str) -> str: ... +def compute_md5( + fp: IO[Any], + buf_size: int = ..., + size: Optional[int] = ..., +) -> Tuple[str, str, int]: ... +def compute_hash( + fp: IO[Any], + buf_size: int = ..., + size: Optional[int] = ..., + hash_algorithm: Any = ..., +) -> Tuple[str, str, int]: ... +def find_matching_headers(name: str, headers: Mapping[str, Optional[str]]) -> List[str]: ... +def merge_headers_by_name(name: str, headers: Mapping[str, Optional[str]]) -> str: ... + +class RequestHook: + def handle_request_data( + self, + request: boto.connection.HTTPRequest, + response: boto.connection.HTTPResponse, + error: bool = ..., + ) -> Any: ... + +def host_is_ipv6(hostname: str) -> bool: ... +def parse_host(hostname: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/certifi.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/certifi.pyi new file mode 100644 index 000000000..c809e6d49 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/certifi.pyi @@ -0,0 +1,2 @@ +def where() -> str: ... +def old_where() -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/characteristic/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/characteristic/__init__.pyi new file mode 100644 index 000000000..20bd6e58a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/characteristic/__init__.pyi @@ -0,0 +1,34 @@ +from typing import Sequence, Callable, Union, Any, Optional, AnyStr, TypeVar, Type + +def with_repr(attrs: Sequence[Union[AnyStr, Attribute]]) -> Callable[..., Any]: ... +def with_cmp(attrs: Sequence[Union[AnyStr, Attribute]]) -> Callable[..., Any]: ... +def with_init(attrs: Sequence[Union[AnyStr, Attribute]]) -> Callable[..., Any]: ... +def immutable(attrs: Sequence[Union[AnyStr, Attribute]]) -> Callable[..., Any]: ... + +def strip_leading_underscores(attribute_name: AnyStr) -> AnyStr: ... + +NOTHING = Any + +_T = TypeVar('_T') + +def attributes( + attrs: Sequence[Union[AnyStr, Attribute]], + apply_with_cmp: bool = ..., + apply_with_init: bool = ..., + apply_with_repr: bool = ..., + apply_immutable: bool = ..., + store_attributes: Optional[Callable[[type, Attribute], Any]] = ..., + **kw: Optional[dict]) -> Callable[[Type[_T]], Type[_T]]: ... + +class Attribute: + def __init__( + self, + name: AnyStr, + exclude_from_cmp: bool = ..., + exclude_from_init: bool = ..., + exclude_from_repr: bool = ..., + exclude_from_immutable: bool = ..., + default_value: Any = ..., + default_factory: Optional[Callable[[None], Any]] = ..., + instance_of: Optional[Any] = ..., + init_aliaser: Optional[Callable[[AnyStr], AnyStr]] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/README.md b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/README.md new file mode 100644 index 000000000..d7410e3fc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/README.md @@ -0,0 +1,11 @@ +# click 6.6, Python 3 + +`__init__.pyi` is literally a copy of click/__init__.py. It's a shortcut module +anyway in the actual sources so it works well without additional changes. + +The types are pretty complete but they were created mostly for public API use +so some internal modules (`_compat`) or functions (`core._bashcomplete`) are +deliberately missing. If you feel the need to add those, pull requests accepted. + +Speaking of pull requests, it would be great if the option decorators informed +the type checker on what types the command callback should accept. diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/__init__.pyi new file mode 100644 index 000000000..2ac61bef4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/__init__.pyi @@ -0,0 +1,156 @@ +# -*- coding: utf-8 -*- +""" + click + ~~~~~ + + Click is a simple Python module that wraps the stdlib's optparse to make + writing command line scripts fun. Unlike other modules, it's based around + a simple API that does not come with too much magic and is composable. + + In case optparse ever gets removed from the stdlib, it will be shipped by + this module. + + :copyright: (c) 2014 by Armin Ronacher. + :license: BSD, see LICENSE for more details. +""" + +# Core classes +from .core import ( + Context as Context, + BaseCommand as BaseCommand, + Command as Command, + MultiCommand as MultiCommand, + Group as Group, + CommandCollection as CommandCollection, + Parameter as Parameter, + Option as Option, + Argument as Argument, +) + +# Globals +from .globals import get_current_context as get_current_context + +# Decorators +from .decorators import ( + pass_context as pass_context, + pass_obj as pass_obj, + make_pass_decorator as make_pass_decorator, + command as command, + group as group, + argument as argument, + option as option, + confirmation_option as confirmation_option, + password_option as password_option, + version_option as version_option, + help_option as help_option, +) + +# Types +from .types import ( + ParamType as ParamType, + File as File, + Path as Path, + Choice as Choice, + IntRange as IntRange, + Tuple as Tuple, + STRING as STRING, + INT as INT, + FLOAT as FLOAT, + BOOL as BOOL, + UUID as UUID, + UNPROCESSED as UNPROCESSED, +) + +# Utilities +from .utils import ( + echo as echo, + get_binary_stream as get_binary_stream, + get_text_stream as get_text_stream, + open_file as open_file, + format_filename as format_filename, + get_app_dir as get_app_dir, + get_os_args as get_os_args, +) + +# Terminal functions +from .termui import ( + prompt as prompt, + confirm as confirm, + get_terminal_size as get_terminal_size, + echo_via_pager as echo_via_pager, + progressbar as progressbar, + clear as clear, + style as style, + unstyle as unstyle, + secho as secho, + edit as edit, + launch as launch, + getchar as getchar, + pause as pause, +) + +# Exceptions +from .exceptions import ( + ClickException as ClickException, + UsageError as UsageError, + BadParameter as BadParameter, + FileError as FileError, + Abort as Abort, + NoSuchOption as NoSuchOption, + BadOptionUsage as BadOptionUsage, + BadArgumentUsage as BadArgumentUsage, + MissingParameter as MissingParameter, +) + +# Formatting +from .formatting import HelpFormatter as HelpFormatter, wrap_text as wrap_text + +# Parsing +from .parser import OptionParser as OptionParser + + +__all__ = [ + # Core classes + 'Context', 'BaseCommand', 'Command', 'MultiCommand', 'Group', + 'CommandCollection', 'Parameter', 'Option', 'Argument', + + # Globals + 'get_current_context', + + # Decorators + 'pass_context', 'pass_obj', 'make_pass_decorator', 'command', 'group', + 'argument', 'option', 'confirmation_option', 'password_option', + 'version_option', 'help_option', + + # Types + 'ParamType', 'File', 'Path', 'Choice', 'IntRange', 'Tuple', 'STRING', + 'INT', 'FLOAT', 'BOOL', 'UUID', 'UNPROCESSED', + + # Utilities + 'echo', 'get_binary_stream', 'get_text_stream', 'open_file', + 'format_filename', 'get_app_dir', 'get_os_args', + + # Terminal functions + 'prompt', 'confirm', 'get_terminal_size', 'echo_via_pager', + 'progressbar', 'clear', 'style', 'unstyle', 'secho', 'edit', 'launch', + 'getchar', 'pause', + + # Exceptions + 'ClickException', 'UsageError', 'BadParameter', 'FileError', + 'Abort', 'NoSuchOption', 'BadOptionUsage', 'BadArgumentUsage', + 'MissingParameter', + + # Formatting + 'HelpFormatter', 'wrap_text', + + # Parsing + 'OptionParser', +] + + +# Controls if click should emit the warning about the use of unicode +# literals. +disable_unicode_literals_warning = False + + +__version__ = '6.6' diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/_termui_impl.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/_termui_impl.pyi new file mode 100644 index 000000000..927c54ca5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/_termui_impl.pyi @@ -0,0 +1,12 @@ +from typing import ContextManager, Iterator, Generic, TypeVar + +_T = TypeVar("_T") + +class ProgressBar(object, Generic[_T]): + def update(self, n_steps: int) -> None: ... + def finish(self) -> None: ... + def __enter__(self) -> "ProgressBar[_T]": ... + def __exit__(self, exc_type, exc_value, tb) -> None: ... + def __iter__(self) -> "ProgressBar[_T]": ... + def next(self) -> _T: ... + def __next__(self) -> _T: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/core.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/core.pyi new file mode 100644 index 000000000..255a8bd06 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/core.pyi @@ -0,0 +1,469 @@ +from contextlib import contextmanager +from typing import ( + Any, + Callable, + Dict, + Generator, + Iterable, + List, + Mapping, + Optional, + Sequence, + Set, + Tuple, + TypeVar, + Union, +) + +from click.formatting import HelpFormatter +from click.parser import OptionParser + +def invoke_param_callback( + callback: Callable[['Context', 'Parameter', Optional[str]], Any], + ctx: 'Context', + param: 'Parameter', + value: Optional[str] +) -> Any: + ... + + +@contextmanager +def augment_usage_errors( + ctx: 'Context', param: Optional['Parameter'] = ... +) -> Generator[None, None, None]: + ... + + +def iter_params_for_processing( + invocation_order: Sequence['Parameter'], + declaration_order: Iterable['Parameter'], +) -> Iterable['Parameter']: + ... + + +class Context: + parent: Optional['Context'] + command: 'Command' + info_name: Optional[str] + params: Dict + args: List[str] + protected_args: List[str] + obj: Any + default_map: Mapping[str, Any] + invoked_subcommand: Optional[str] + terminal_width: Optional[int] + max_content_width: Optional[int] + allow_extra_args: bool + allow_interspersed_args: bool + ignore_unknown_options: bool + help_option_names: List[str] + token_normalize_func: Optional[Callable[[str], str]] + resilient_parsing: bool + auto_envvar_prefix: Optional[str] + color: Optional[bool] + _meta: Dict[str, Any] + _close_callbacks: List + _depth: int + + # properties + meta: Dict[str, Any] + command_path: str + + def __init__( + self, + command: 'Command', + parent: Optional['Context'] = ..., + info_name: Optional[str] = ..., + obj: Optional[Any] = ..., + auto_envvar_prefix: Optional[str] = ..., + default_map: Optional[Mapping[str, Any]] = ..., + terminal_width: Optional[int] = ..., + max_content_width: Optional[int] = ..., + resilient_parsing: bool = ..., + allow_extra_args: Optional[bool] = ..., + allow_interspersed_args: Optional[bool] = ..., + ignore_unknown_options: Optional[bool] = ..., + help_option_names: Optional[List[str]] = ..., + token_normalize_func: Optional[Callable[[str], str]] = ..., + color: Optional[bool] = ... + ) -> None: + ... + + @contextmanager + def scope(self, cleanup: bool = ...) -> Generator['Context', None, None]: + ... + + def make_formatter(self) -> HelpFormatter: + ... + + def call_on_close(self, f: Callable) -> Callable: + ... + + def close(self) -> None: + ... + + def find_root(self) -> 'Context': + ... + + def find_object(self, object_type: type) -> Any: + ... + + def ensure_object(self, object_type: type) -> Any: + ... + + def lookup_default(self, name: str) -> Any: + ... + + def fail(self, message: str) -> None: + ... + + def abort(self) -> None: + ... + + def exit(self, code: Union[int, str] = ...) -> None: + ... + + def get_usage(self) -> str: + ... + + def get_help(self) -> str: + ... + + def invoke( + self, callback: Union['Command', Callable], *args, **kwargs + ) -> Any: + ... + + def forward( + self, callback: Union['Command', Callable], *args, **kwargs + ) -> Any: + ... + +class BaseCommand: + allow_extra_args: bool + allow_interspersed_args: bool + ignore_unknown_options: bool + name: str + context_settings: Dict + + def __init__(self, name: str, context_settings: Optional[Dict] = ...) -> None: + ... + + def get_usage(self, ctx: Context) -> str: + ... + + def get_help(self, ctx: Context) -> str: + ... + + def make_context( + self, info_name: str, args: List[str], parent: Optional[Context] = ..., **extra + ) -> Context: + ... + + def parse_args(self, ctx: Context, args: List[str]) -> List[str]: + ... + + def invoke(self, ctx: Context) -> Any: + ... + + def main( + self, + args: Optional[List[str]] = ..., + prog_name: Optional[str] = ..., + complete_var: Optional[str] = ..., + standalone_mode: bool = ..., + **extra + ) -> Any: + ... + + def __call__(self, *args, **kwargs) -> Any: + ... + + +class Command(BaseCommand): + callback: Optional[Callable] + params: List['Parameter'] + help: Optional[str] + epilog: Optional[str] + short_help: Optional[str] + options_metavar: str + add_help_option: bool + + def __init__( + self, + name: str, + context_settings: Optional[Dict] = ..., + callback: Optional[Callable] = ..., + params: Optional[List['Parameter']] = ..., + help: Optional[str] = ..., + epilog: Optional[str] = ..., + short_help: Optional[str] = ..., + options_metavar: str = ..., + add_help_option: bool = ... + ) -> None: + ... + + def get_params(self, ctx: Context) -> List['Parameter']: + ... + + def format_usage( + self, + ctx: Context, + formatter: HelpFormatter + ) -> None: + ... + + def collect_usage_pieces(self, ctx: Context) -> List[str]: + ... + + def get_help_option_names(self, ctx: Context) -> Set[str]: + ... + + def get_help_option(self, ctx: Context) -> Optional['Option']: + ... + + def make_parser(self, ctx: Context) -> OptionParser: + ... + + def format_help(self, ctx: Context, formatter: HelpFormatter) -> None: + ... + + def format_help_text(self, ctx: Context, formatter: HelpFormatter) -> None: + ... + + def format_options(self, ctx: Context, formatter: HelpFormatter) -> None: + ... + + def format_epilog(self, ctx: Context, formatter: HelpFormatter) -> None: + ... + + +_T = TypeVar('_T') +_Decorator = Callable[[_T], _T] + + +class MultiCommand(Command): + no_args_is_help: bool + invoke_without_command: bool + subcommand_metavar: str + chain: bool + result_callback: Callable + + def __init__( + self, + name: Optional[str] = ..., + invoke_without_command: bool = ..., + no_args_is_help: Optional[bool] = ..., + subcommand_metavar: Optional[str] = ..., + chain: bool = ..., + result_callback: Optional[Callable] = ..., + **attrs + ) -> None: + ... + + def resultcallback( + self, replace: bool = ... + ) -> _Decorator: + ... + + def format_commands(self, ctx: Context, formatter: HelpFormatter) -> None: + ... + + def resolve_command( + self, ctx: Context, args: List[str] + ) -> Tuple[str, Command, List[str]]: + ... + + def get_command(self, ctx: Context, cmd_name: str) -> Optional[Command]: + ... + + def list_commands(self, ctx: Context) -> Iterable[Command]: + ... + + +class Group(MultiCommand): + commands: Dict[str, Command] + + def __init__( + self, name: Optional[str] = ..., commands: Optional[Dict[str, Command]] = ..., **attrs + ) -> None: + ... + + def add_command(self, cmd: Command, name: Optional[str] = ...): + ... + + def command(self, *args, **kwargs) -> _Decorator: + ... + + def group(self, *args, **kwargs) -> _Decorator: + ... + + +class CommandCollection(MultiCommand): + sources: List[MultiCommand] + + def __init__( + self, name: Optional[str] = ..., sources: Optional[List[MultiCommand]] = ..., **attrs + ) -> None: + ... + + def add_source(self, multi_cmd: MultiCommand) -> None: + ... + + +class _ParamType: + name: str + is_composite: bool + envvar_list_splitter: Optional[str] + + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> Any: + ... + + def get_metavar(self, param: Parameter) -> str: + ... + + def get_missing_message(self, param: Parameter) -> str: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> Any: + ... + + def split_envvar_value(self, rv: str) -> List[str]: + ... + + def fail(self, message: str, param: Optional[Parameter] = ..., ctx: Optional[Context] = ...) -> None: + ... + + +# This type is here to resolve https://github.com/python/mypy/issues/5275 +_ConvertibleType = Union[type, _ParamType, Tuple[type, ...], Callable[[str], Any], Callable[[Optional[str]], Any]] + + +class Parameter: + param_type_name: str + name: str + opts: List[str] + secondary_opts: List[str] + type: _ParamType + required: bool + callback: Optional[Callable[[Context, 'Parameter', str], Any]] + nargs: int + multiple: bool + expose_value: bool + default: Any + is_eager: bool + metavar: Optional[str] + envvar: Union[str, List[str], None] + # properties + human_readable_name: str + + def __init__( + self, + param_decls: Optional[List[str]] = ..., + type: Optional[_ConvertibleType] = ..., + required: bool = ..., + default: Optional[Any] = ..., + callback: Optional[Callable[[Context, 'Parameter', str], Any]] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ... + ) -> None: + ... + + def make_metavar(self) -> str: + ... + + def get_default(self, ctx: Context) -> Any: + ... + + def add_to_parser(self, parser: OptionParser, ctx: Context) -> None: + ... + + def consume_value(self, ctx: Context, opts: Dict[str, Any]) -> Any: + ... + + def type_cast_value(self, ctx: Context, value: Any) -> Any: + ... + + def process_value(self, ctx: Context, value: Any) -> Any: + ... + + def value_is_missing(self, value: Any) -> bool: + ... + + def full_process_value(self, ctx: Context, value: Any) -> Any: + ... + + def resolve_envvar_value(self, ctx: Context) -> str: + ... + + def value_from_envvar(self, ctx: Context) -> Union[str, List[str]]: + ... + + def handle_parse_result( + self, ctx: Context, opts: Dict[str, Any], args: List[str] + ) -> Tuple[Any, List[str]]: + ... + + def get_help_record(self, ctx: Context) -> Tuple[str, str]: + ... + + def get_usage_pieces(self, ctx: Context) -> List[str]: + ... + + +class Option(Parameter): + prompt: str # sic + confirmation_prompt: bool + hide_input: bool + is_flag: bool + flag_value: Any + is_bool_flag: bool + count: bool + multiple: bool + allow_from_autoenv: bool + help: Optional[str] + show_default: bool + + def __init__( + self, + param_decls: Optional[List[str]] = ..., + show_default: bool = ..., + prompt: Union[bool, str] = ..., + confirmation_prompt: bool = ..., + hide_input: bool = ..., + is_flag: Optional[bool] = ..., + flag_value: Optional[Any] = ..., + multiple: bool = ..., + count: bool = ..., + allow_from_autoenv: bool = ..., + type: Optional[_ConvertibleType] = ..., + help: Optional[str] = ..., + **attrs + ) -> None: + ... + + def prompt_for_value(self, ctx: Context) -> Any: + ... + + +class Argument(Parameter): + def __init__( + self, + param_decls: Optional[List[str]] = ..., + required: Optional[bool] = ..., + **attrs + ) -> None: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/decorators.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/decorators.pyi new file mode 100644 index 000000000..74c53187c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/decorators.pyi @@ -0,0 +1,226 @@ +from distutils.version import Version +from typing import Any, Callable, Dict, List, Optional, Type, TypeVar, Union, Text + +from click.core import Command, Group, Argument, Option, Parameter, Context, _ConvertibleType + +_T = TypeVar('_T') +_Decorator = Callable[[_T], _T] + +_Callback = Callable[ + [Context, Union[Option, Parameter], Union[bool, int, str]], + Any +] + +def pass_context(_T) -> _T: + ... + + +def pass_obj(_T) -> _T: + ... + + +def make_pass_decorator( + object_type: type, ensure: bool = ... +) -> Callable[[_T], _T]: + ... + + +# NOTE: Decorators below have **attrs converted to concrete constructor +# arguments from core.pyi to help with type checking. + +def command( + name: Optional[str] = ..., + cls: Optional[Type[Command]] = ..., + # Command + context_settings: Optional[Dict] = ..., + help: Optional[str] = ..., + epilog: Optional[str] = ..., + short_help: Optional[str] = ..., + options_metavar: str = ..., + add_help_option: bool = ..., +) -> _Decorator: + ... + + +# This inherits attrs from Group, MultiCommand and Command. + +def group( + name: Optional[str] = ..., + cls: Type[Command] = ..., + # Group + commands: Optional[Dict[str, Command]] = ..., + # MultiCommand + invoke_without_command: bool = ..., + no_args_is_help: Optional[bool] = ..., + subcommand_metavar: Optional[str] = ..., + chain: bool = ..., + result_callback: Optional[Callable] = ..., + # Command + help: Optional[str] = ..., + epilog: Optional[str] = ..., + short_help: Optional[str] = ..., + options_metavar: str = ..., + add_help_option: bool = ..., + # User-defined + **kwargs: Any, +) -> _Decorator: + ... + + +def argument( + *param_decls: str, + cls: Type[Argument] = ..., + # Argument + required: Optional[bool] = ..., + # Parameter + type: Optional[_ConvertibleType] = ..., + default: Optional[Any] = ..., + callback: Optional[_Callback] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ... +) -> _Decorator: + ... + + +def option( + *param_decls: str, + cls: Type[Option] = ..., + # Option + show_default: bool = ..., + prompt: Union[bool, Text] = ..., + confirmation_prompt: bool = ..., + hide_input: bool = ..., + is_flag: Optional[bool] = ..., + flag_value: Optional[Any] = ..., + multiple: bool = ..., + count: bool = ..., + allow_from_autoenv: bool = ..., + type: Optional[_ConvertibleType] = ..., + help: Optional[str] = ..., + # Parameter + default: Optional[Any] = ..., + required: bool = ..., + callback: Optional[_Callback] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ..., + # User-defined + **kwargs: Any, +) -> _Decorator: + ... + + +def confirmation_option( + *param_decls: str, + cls: Type[Option] = ..., + # Option + show_default: bool = ..., + prompt: Union[bool, Text] = ..., + confirmation_prompt: bool = ..., + hide_input: bool = ..., + is_flag: bool = ..., + flag_value: Optional[Any] = ..., + multiple: bool = ..., + count: bool = ..., + allow_from_autoenv: bool = ..., + type: Optional[_ConvertibleType] = ..., + help: str = ..., + # Parameter + default: Optional[Any] = ..., + callback: Optional[_Callback] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ... +) -> _Decorator: + ... + + +def password_option( + *param_decls: str, + cls: Type[Option] = ..., + # Option + show_default: bool = ..., + prompt: Union[bool, Text] = ..., + confirmation_prompt: bool = ..., + hide_input: bool = ..., + is_flag: Optional[bool] = ..., + flag_value: Optional[Any] = ..., + multiple: bool = ..., + count: bool = ..., + allow_from_autoenv: bool = ..., + type: Optional[_ConvertibleType] = ..., + help: Optional[str] = ..., + # Parameter + default: Optional[Any] = ..., + callback: Optional[_Callback] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ... +) -> _Decorator: + ... + + +def version_option( + version: Optional[Union[str, Version]] = ..., + *param_decls: str, + cls: Type[Option] = ..., + # Option + prog_name: Optional[str] = ..., + message: Optional[str] = ..., + show_default: bool = ..., + prompt: Union[bool, Text] = ..., + confirmation_prompt: bool = ..., + hide_input: bool = ..., + is_flag: bool = ..., + flag_value: Optional[Any] = ..., + multiple: bool = ..., + count: bool = ..., + allow_from_autoenv: bool = ..., + type: Optional[_ConvertibleType] = ..., + help: str = ..., + # Parameter + default: Optional[Any] = ..., + callback: Optional[_Callback] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ... +) -> _Decorator: + ... + + +def help_option( + *param_decls: str, + cls: Type[Option] = ..., + # Option + show_default: bool = ..., + prompt: Union[bool, Text] = ..., + confirmation_prompt: bool = ..., + hide_input: bool = ..., + is_flag: bool = ..., + flag_value: Optional[Any] = ..., + multiple: bool = ..., + count: bool = ..., + allow_from_autoenv: bool = ..., + type: Optional[_ConvertibleType] = ..., + help: str = ..., + # Parameter + default: Optional[Any] = ..., + callback: Optional[_Callback] = ..., + nargs: Optional[int] = ..., + metavar: Optional[str] = ..., + expose_value: bool = ..., + is_eager: bool = ..., + envvar: Optional[Union[str, List[str]]] = ... +) -> _Decorator: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/exceptions.pyi new file mode 100644 index 000000000..6f08d7ac5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/exceptions.pyi @@ -0,0 +1,91 @@ +from typing import IO, List, Optional + +from click.core import Context, Parameter + + +class ClickException(Exception): + exit_code: int + message: str + + def __init__(self, message: str) -> None: + ... + + def format_message(self) -> str: + ... + + def show(self, file=None) -> None: + ... + + +class UsageError(ClickException): + ctx: Optional[Context] + + def __init__(self, message: str, ctx: Optional[Context] = ...) -> None: + ... + + def show(self, file: Optional[IO] = ...) -> None: + ... + + +class BadParameter(UsageError): + param: Optional[Parameter] + param_hint: Optional[str] + + def __init__( + self, + message: str, + ctx: Optional[Context] = ..., + param: Optional[Parameter] = ..., + param_hint: Optional[str] = ... + ) -> None: + ... + + +class MissingParameter(BadParameter): + param_type: str # valid values: 'parameter', 'option', 'argument' + + def __init__( + self, + message: Optional[str] = ..., + ctx: Optional[Context] = ..., + param: Optional[Parameter] = ..., + param_hint: Optional[str] = ..., + param_type: Optional[str] = ... + ) -> None: + ... + + +class NoSuchOption(UsageError): + option_name: str + possibilities: Optional[List[str]] + + def __init__( + self, + option_name: str, + message: Optional[str] = ..., + possibilities: Optional[List[str]] = ..., + ctx: Optional[Context] = ... + ) -> None: + ... + + +class BadOptionUsage(UsageError): + def __init__(self, message: str, ctx: Optional[Context] = ...) -> None: + ... + + +class BadArgumentUsage(UsageError): + def __init__(self, message: str, ctx: Optional[Context] = ...) -> None: + ... + + +class FileError(ClickException): + ui_filename: str + filename: str + + def __init__(self, filename: str, hint: Optional[str] = ...) -> None: + ... + + +class Abort(RuntimeError): + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/formatting.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/formatting.pyi new file mode 100644 index 000000000..f4fe249e2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/formatting.pyi @@ -0,0 +1,89 @@ +from contextlib import contextmanager +from typing import Generator, Iterable, List, Optional, Tuple + + +FORCED_WIDTH: Optional[int] + + +def measure_table(rows: Iterable[Iterable[str]]) -> Tuple[int, ...]: + ... + + +def iter_rows( + rows: Iterable[Iterable[str]], col_count: int +) -> Generator[Tuple[str, ...], None, None]: + ... + + +def wrap_text( + text: str, + width: int = ..., + initial_indent: str = ..., + subsequent_indent: str = ..., + preserve_paragraphs: bool = ... +) -> str: + ... + + +class HelpFormatter: + indent_increment: int + width: Optional[int] + current_indent: int + buffer: List[str] + + def __init__( + self, + indent_increment: int = ..., + width: Optional[int] = ..., + max_width: Optional[int] = ..., + ) -> None: + ... + + def write(self, string: str) -> None: + ... + + def indent(self) -> None: + ... + + def dedent(self) -> None: + ... + + def write_usage( + self, + prog: str, + args: str = ..., + prefix: str = ..., + ): + ... + + def write_heading(self, heading: str) -> None: + ... + + def write_paragraph(self) -> None: + ... + + def write_text(self, text: str) -> None: + ... + + def write_dl( + self, + rows: Iterable[Iterable[str]], + col_max: int = ..., + col_spacing: int = ..., + ) -> None: + ... + + @contextmanager + def section(self, name) -> Generator[None, None, None]: + ... + + @contextmanager + def indentation(self) -> Generator[None, None, None]: + ... + + def getvalue(self) -> str: + ... + + +def join_options(options: List[str]) -> Tuple[str, bool]: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/globals.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/globals.pyi new file mode 100644 index 000000000..11adce3fa --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/globals.pyi @@ -0,0 +1,18 @@ +from click.core import Context +from typing import Optional + + +def get_current_context(silent: bool = ...) -> Context: + ... + + +def push_context(ctx: Context) -> None: + ... + + +def pop_context() -> None: + ... + + +def resolve_color_default(color: Optional[bool] = ...) -> Optional[bool]: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/parser.pyi new file mode 100644 index 000000000..5184da571 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/parser.pyi @@ -0,0 +1,102 @@ +from typing import Any, Dict, Iterable, List, Optional, Set, Tuple + +from click.core import Context + + +def _unpack_args( + args: Iterable[str], nargs_spec: Iterable[int] +) -> Tuple[Tuple[Optional[Tuple[str, ...]], ...], List[str]]: + ... + + +def split_opt(opt: str) -> Tuple[str, str]: + ... + + +def normalize_opt(opt: str, ctx: Context) -> str: + ... + + +def split_arg_string(string: str) -> List[str]: + ... + + +class Option: + dest: str + action: str + nargs: int + const: Any + obj: Any + prefixes: Set[str] + _short_opts: List[str] + _long_opts: List[str] + # properties + takes_value: bool + + def __init__( + self, + opts: Iterable[str], + dest: str, + action: Optional[str] = ..., + nargs: int = ..., + const: Optional[Any] = ..., + obj: Optional[Any] = ... + ) -> None: + ... + + def process(self, value: Any, state: 'ParsingState') -> None: + ... + + +class Argument: + dest: str + nargs: int + obj: Any + + def __init__(self, dest: str, nargs: int = ..., obj: Optional[Any] = ...) -> None: + ... + + def process(self, value: Any, state: 'ParsingState') -> None: + ... + + +class ParsingState: + opts: Dict[str, Any] + largs: List[str] + rargs: List[str] + order: List[Any] + + def __init__(self, rargs: List[str]) -> None: + ... + + +class OptionParser: + ctx: Optional[Context] + allow_interspersed_args: bool + ignore_unknown_options: bool + _short_opt: Dict[str, Option] + _long_opt: Dict[str, Option] + _opt_prefixes: Set[str] + _args: List[Argument] + + def __init__(self, ctx: Optional[Context] = ...) -> None: + ... + + def add_option( + self, + opts: Iterable[str], + dest: str, + action: Optional[str] = ..., + nargs: int = ..., + const: Optional[Any] = ..., + obj: Optional[Any] = ... + ) -> None: + ... + + def add_argument(self, dest: str, nargs: int = ..., obj: Optional[Any] = ...) -> None: + ... + + def parse_args( + self, args: List[str] + ) -> Tuple[Dict[str, Any], List[str], List[Any]]: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/termui.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/termui.pyi new file mode 100644 index 000000000..167ce04d7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/termui.pyi @@ -0,0 +1,168 @@ +from typing import ( + Any, + Callable, + Generator, + Iterable, + IO, + List, + Optional, + Text, + overload, + Tuple, + TypeVar, +) + +from click.core import _ConvertibleType +from click._termui_impl import ProgressBar as _ProgressBar + + +def hidden_prompt_func(prompt: str) -> str: + ... + + +def _build_prompt( + text: str, + suffix: str, + show_default: bool = ..., + default: Optional[str] = ..., +) -> str: + ... + + +def prompt( + text: str, + default: Optional[str] = ..., + hide_input: bool = ..., + confirmation_prompt: bool = ..., + type: Optional[_ConvertibleType] = ..., + value_proc: Optional[Callable[[Optional[str]], Any]] = ..., + prompt_suffix: str = ..., + show_default: bool = ..., + err: bool = ..., +) -> Any: + ... + + +def confirm( + text: str, + default: bool = ..., + abort: bool = ..., + prompt_suffix: str = ..., + show_default: bool = ..., + err: bool = ..., +) -> bool: + ... + + +def get_terminal_size() -> Tuple[int, int]: + ... + + +def echo_via_pager(text: str, color: Optional[bool] = ...) -> None: + ... + + +_T = TypeVar('_T') + +@overload +def progressbar( + iterable: Iterable[_T], + length: Optional[int] = ..., + label: Optional[str] = ..., + show_eta: bool = ..., + show_percent: Optional[bool] = ..., + show_pos: bool = ..., + item_show_func: Optional[Callable[[_T], str]] = ..., + fill_char: str = ..., + empty_char: str = ..., + bar_template: str = ..., + info_sep: str = ..., + width: int = ..., + file: Optional[IO] = ..., + color: Optional[bool] = ..., +) -> _ProgressBar[_T]: + ... + +@overload +def progressbar( + iterable: None = ..., + length: Optional[int] = ..., + label: Optional[str] = ..., + show_eta: bool = ..., + show_percent: Optional[bool] = ..., + show_pos: bool = ..., + item_show_func: Optional[Callable[[_T], str]] = ..., + fill_char: str = ..., + empty_char: str = ..., + bar_template: str = ..., + info_sep: str = ..., + width: int = ..., + file: Optional[IO] = ..., + color: Optional[bool] = ..., +) -> _ProgressBar[int]: + ... + +def clear() -> None: + ... + + +def style( + text: str, + fg: Optional[str] = ..., + bg: Optional[str] = ..., + bold: Optional[bool] = ..., + dim: Optional[bool] = ..., + underline: Optional[bool] = ..., + blink: Optional[bool] = ..., + reverse: Optional[bool] = ..., + reset: bool = ..., +): + ... + + +def unstyle(text: str) -> str: + ... + + +# Styling options copied from style() for nicer type checking. +def secho( + text: str, + file: Optional[IO] = ..., + nl: bool = ..., + err: bool = ..., + color: Optional[bool] = ..., + fg: Optional[str] = ..., + bg: Optional[str] = ..., + bold: Optional[bool] = ..., + dim: Optional[bool] = ..., + underline: Optional[bool] = ..., + blink: Optional[bool] = ..., + reverse: Optional[bool] = ..., + reset: bool = ..., +): + ... + + +def edit( + text: Optional[str] = ..., + editor: Optional[str] = ..., + env: Optional[str] = ..., + require_save: bool = ..., + extension: str = ..., + filename: Optional[str] = ..., +) -> str: + ... + + +def launch(url: str, wait: bool = ..., locate: bool = ...) -> int: + ... + + +def getchar(echo: bool = ...) -> Text: + ... + + +def pause( + info: str = ..., err: bool = ... +) -> None: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/types.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/types.pyi new file mode 100644 index 000000000..83fe905a4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/types.pyi @@ -0,0 +1,248 @@ +from typing import Any, Callable, IO, Iterable, List, Optional, TypeVar, Union, Tuple as _PyTuple, Type +import uuid + +from click.core import Context, Parameter, _ParamType as ParamType, _ConvertibleType + +class BoolParamType(ParamType): + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> bool: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> bool: + ... + + +class CompositeParamType(ParamType): + arity: int + + +class Choice(ParamType): + choices: Iterable[str] + def __init__(self, choices: Iterable[str]) -> None: + ... + + +class FloatParamType(ParamType): + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> float: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> float: + ... + + +class FloatRange(FloatParamType): + ... + + +class File(ParamType): + def __init__( + self, + mode: str = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + lazy: Optional[bool] = ..., + atomic: Optional[bool] = ..., + ) -> None: + ... + + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> IO: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> IO: + ... + + def resolve_lazy_flag(self, value: str) -> bool: + ... + + +_F = TypeVar('_F') # result of the function +_Func = Callable[[Optional[str]], _F] + + +class FuncParamType(ParamType): + func: _Func + + def __init__(self, func: _Func) -> None: + ... + + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> _F: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> _F: + ... + + +class IntParamType(ParamType): + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> int: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> int: + ... + + +class IntRange(IntParamType): + def __init__( + self, min: Optional[int] = ..., max: Optional[int] = ..., clamp: bool = ... + ) -> None: + ... + + +_PathType = TypeVar('_PathType', str, bytes) + + +class Path(ParamType): + def __init__( + self, + exists: bool = ..., + file_okay: bool = ..., + dir_okay: bool = ..., + writable: bool = ..., + readable: bool = ..., + resolve_path: bool = ..., + allow_dash: bool = ..., + path_type: Optional[Type[_PathType]] = ..., + ) -> None: + ... + + def coerce_path_result(self, rv: Union[str, bytes]) -> _PathType: + ... + + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> _PathType: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> _PathType: + ... + +class StringParamType(ParamType): + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> str: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> str: + ... + + +class Tuple(CompositeParamType): + types: List[ParamType] + + def __init__(self, types: Iterable[Any]) -> None: + ... + + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> Tuple: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> Tuple: + ... + + +class UnprocessedParamType(ParamType): + ... + + +class UUIDParameterType(ParamType): + def __call__( + self, + value: Optional[str], + param: Optional[Parameter] = ..., + ctx: Optional[Context] = ..., + ) -> uuid.UUID: + ... + + def convert( + self, + value: str, + param: Optional[Parameter], + ctx: Optional[Context], + ) -> uuid.UUID: + ... + + +def convert_type(ty: Optional[_ConvertibleType], default: Optional[Any] = ...) -> ParamType: + ... + +# parameter type shortcuts + +BOOL = BoolParamType() +FLOAT = FloatParamType() +INT = IntParamType() +STRING = StringParamType() +UNPROCESSED = UnprocessedParamType() +UUID = UUIDParameterType() diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/utils.pyi new file mode 100644 index 000000000..1a6b962da --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/click/utils.pyi @@ -0,0 +1,117 @@ +from typing import Any, Callable, Iterator, IO, List, Optional, TypeVar, Union, Text + +_T = TypeVar('_T') +_Decorator = Callable[[_T], _T] + + +def _posixify(name: str) -> str: + ... + + +def safecall(func: _T) -> _T: + ... + + +def make_str(value: Any) -> str: + ... + + +def make_default_short_help(help: str, max_length: int = ...): + ... + + +class LazyFile: + name: str + mode: str + encoding: Optional[str] + errors: str + atomic: bool + + def __init__( + self, + filename: str, + mode: str = ..., + encoding: Optional[str] = ..., + errors: str = ..., + atomic: bool = ... + ) -> None: + ... + + def open(self) -> IO: + ... + + def close(self) -> None: + ... + + def close_intelligently(self) -> None: + ... + + def __enter__(self) -> 'LazyFile': + ... + + def __exit__(self, exc_type, exc_value, tb): + ... + + def __iter__(self) -> Iterator: + ... + + +class KeepOpenFile: + _file: IO + + def __init__(self, file: IO) -> None: + ... + + def __enter__(self) -> 'KeepOpenFile': + ... + + def __exit__(self, exc_type, exc_value, tb): + ... + + def __iter__(self) -> Iterator: + ... + + +def echo( + message: Optional[Union[bytes, Text]] = ..., + file: Optional[IO] = ..., + nl: bool = ..., + err: bool = ..., + color: Optional[bool] = ..., +) -> None: + ... + + +def get_binary_stream(name: str) -> IO[bytes]: + ... + + +def get_text_stream( + name: str, encoding: Optional[str] = ..., errors: str = ... +) -> IO[str]: + ... + + +def open_file( + filename: str, + mode: str = ..., + encoding: Optional[str] = ..., + errors: str = ..., + lazy: bool = ..., + atomic: bool = ... +) -> Union[IO, LazyFile, KeepOpenFile]: + ... + + +def get_os_args() -> List[str]: + ... + + +def format_filename(filename: str, shorten: bool = ...) -> str: + ... + + +def get_app_dir( + app_name: str, roaming: bool = ..., force_posix: bool = ... +) -> str: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/croniter.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/croniter.pyi new file mode 100644 index 000000000..0d01b7e05 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/croniter.pyi @@ -0,0 +1,41 @@ +import datetime +from typing import Any, Dict, Iterator, List, Optional, Text, Tuple, Type, TypeVar, Union + +_RetType = Union[Type[float], Type[datetime.datetime]] +_SelfT = TypeVar('_SelfT', bound=croniter) + +class CroniterError(ValueError): ... +class CroniterBadCronError(CroniterError): ... +class CroniterBadDateError(CroniterError): ... +class CroniterNotAlphaError(CroniterError): ... + +class croniter(Iterator[Any]): + MONTHS_IN_YEAR: int + RANGES: Tuple[Tuple[int, int], ...] + DAYS: Tuple[int, ...] + ALPHACONV: Tuple[Dict[str, Any], ...] + LOWMAP: Tuple[Dict[int, Any], ...] + bad_length: str + tzinfo: Optional[datetime.tzinfo] + cur: float + expanded: List[List[str]] + start_time: float + dst_start_time: float + nth_weekday_of_month: Dict[str, Any] + def __init__(self, expr_format: Text, start_time: Optional[Union[float, datetime.datetime]] = ..., ret_type: Optional[_RetType] = ...) -> None: ... + # Most return value depend on ret_type, which can be passed in both as a method argument and as + # a constructor argument. + def get_next(self, ret_type: Optional[_RetType] = ...) -> Any: ... + def get_prev(self, ret_type: Optional[_RetType] = ...) -> Any: ... + def get_current(self, ret_type: Optional[_RetType] = ...) -> Any: ... + def __iter__(self: _SelfT) -> _SelfT: ... + def __next__(self, ret_type: Optional[_RetType] = ...) -> Any: ... + def next(self, ret_type: Optional[_RetType] = ...) -> Any: ... + def all_next(self, ret_type: Optional[_RetType] = ...) -> Iterator[Any]: ... + def all_prev(self, ret_type: Optional[_RetType] = ...) -> Iterator[Any]: ... + def iter(self, ret_type: Optional[_RetType] = ...) -> Iterator[Any]: ... + def is_leap(self, year: int) -> bool: ... + @classmethod + def expand(cls, expr_format: Text) -> Tuple[List[List[str]], Dict[str, Any]]: ... + @classmethod + def is_valid(cls, expression: Text) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/_common.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/_common.pyi new file mode 100644 index 000000000..45ebbb827 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/_common.pyi @@ -0,0 +1,13 @@ +from typing import Optional + +class weekday(object): + def __init__(self, weekday: int, n: Optional[int]=...) -> None: ... + + def __call__(self, n: int) -> 'weekday': ... + + def __eq__(self, other) -> bool: ... + + def __repr__(self) -> str: ... + + weekday = ... # type: int + n = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/parser.pyi new file mode 100644 index 000000000..c3287d8f3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/parser.pyi @@ -0,0 +1,44 @@ +from typing import List, Tuple, Optional, Callable, Union, IO, Any, Dict, Mapping, Text +from datetime import datetime, tzinfo + +_FileOrStr = Union[bytes, Text, IO[str], IO[Any]] + + +class parserinfo(object): + JUMP = ... # type: List[str] + WEEKDAYS = ... # type: List[Tuple[str, str]] + MONTHS = ... # type: List[Tuple[str, str]] + HMS = ... # type: List[Tuple[str, str, str]] + AMPM = ... # type: List[Tuple[str, str]] + UTCZONE = ... # type: List[str] + PERTAIN = ... # type: List[str] + TZOFFSET = ... # type: Dict[str, int] + + def __init__(self, dayfirst: bool=..., yearfirst: bool=...) -> None: ... + def jump(self, name: Text) -> bool: ... + def weekday(self, name: Text) -> Optional[int]: ... + def month(self, name: Text) -> Optional[int]: ... + def hms(self, name: Text) -> Optional[int]: ... + def ampm(self, name: Text) -> Optional[int]: ... + def pertain(self, name: Text) -> bool: ... + def utczone(self, name: Text) -> bool: ... + def tzoffset(self, name: Text) -> Optional[int]: ... + def convertyear(self, year: int) -> int: ... + def validate(self, res: datetime) -> bool: ... + +class parser(object): + def __init__(self, info: Optional[parserinfo] = ...) -> None: ... + def parse(self, timestr: _FileOrStr, + default: Optional[datetime] = ..., + ignoretz: bool = ..., tzinfos: Optional[Mapping[Text, tzinfo]] = ..., + **kwargs: Any) -> datetime: ... + +DEFAULTPARSER = ... # type: parser +def parse(timestr: _FileOrStr, parserinfo: Optional[parserinfo] = ..., **kwargs: Any) -> datetime: ... +class _tzparser: ... + +DEFAULTTZPARSER = ... # type: _tzparser + +class InvalidDatetimeError(ValueError): ... +class InvalidDateError(InvalidDatetimeError): ... +class InvalidTimeError(InvalidDatetimeError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/relativedelta.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/relativedelta.pyi new file mode 100644 index 000000000..d6f3d6585 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/relativedelta.pyi @@ -0,0 +1,71 @@ +from typing import overload, Any, List, Optional, SupportsFloat, TypeVar, Union +from datetime import date, datetime, timedelta + +from ._common import weekday + + +_SelfT = TypeVar('_SelfT', bound=relativedelta) +_DateT = TypeVar('_DateT', date, datetime) + +MO = ... # type: weekday +TU = ... # type: weekday +WE = ... # type: weekday +TH = ... # type: weekday +FR = ... # type: weekday +SA = ... # type: weekday +SU = ... # type: weekday + + +class relativedelta(object): + def __init__(self, + dt1: Optional[date]=..., + dt2: Optional[date]=..., + years: Optional[int]=..., months: Optional[int]=..., + days: Optional[int]=..., leapdays: Optional[int]=..., + weeks: Optional[int]=..., + hours: Optional[int]=..., minutes: Optional[int]=..., + seconds: Optional[int]=..., microseconds: Optional[int]=..., + year: Optional[int]=..., month: Optional[int]=..., + day: Optional[int]=..., + weekday: Optional[Union[int, weekday]]=..., + yearday: Optional[int]=..., + nlyearday: Optional[int]=..., + hour: Optional[int]=..., minute: Optional[int]=..., + second: Optional[int]=..., + microsecond: Optional[int]=...) -> None: ... + @property + def weeks(self) -> int: ... + @weeks.setter + def weeks(self, value: int) -> None: ... + def normalized(self: _SelfT) -> _SelfT: ... + # TODO: use Union when mypy will handle it properly in overloaded operator + # methods (#2129, #1442, #1264 in mypy) + @overload + def __add__(self: _SelfT, other: relativedelta) -> _SelfT: ... + @overload + def __add__(self: _SelfT, other: timedelta) -> _SelfT: ... + @overload + def __add__(self, other: _DateT) -> _DateT: ... + @overload + def __radd__(self: _SelfT, other: relativedelta) -> _SelfT: ... + @overload + def __radd__(self: _SelfT, other: timedelta) -> _SelfT: ... + @overload + def __radd__(self, other: _DateT) -> _DateT: ... + @overload + def __rsub__(self: _SelfT, other: relativedelta) -> _SelfT: ... + @overload + def __rsub__(self: _SelfT, other: timedelta) -> _SelfT: ... + @overload + def __rsub__(self, other: _DateT) -> _DateT: ... + def __sub__(self: _SelfT, other: relativedelta) -> _SelfT: ... + def __neg__(self: _SelfT) -> _SelfT: ... + def __bool__(self) -> bool: ... + def __nonzero__(self) -> bool: ... + def __mul__(self: _SelfT, other: SupportsFloat) -> _SelfT: ... + def __rmul__(self: _SelfT, other: SupportsFloat) -> _SelfT: ... + def __eq__(self, other) -> bool: ... + def __ne__(self, other: object) -> bool: ... + def __div__(self: _SelfT, other: SupportsFloat) -> _SelfT: ... + def __truediv__(self: _SelfT, other: SupportsFloat) -> _SelfT: ... + def __repr__(self) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/rrule.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/rrule.pyi new file mode 100644 index 000000000..f8ab9d29a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/rrule.pyi @@ -0,0 +1,103 @@ +from ._common import weekday as weekdaybase +from typing import Any, Iterable, Optional, Union +import datetime + +YEARLY: int +MONTHLY: int +WEEKLY: int +DAILY: int +HOURLY: int +MINUTELY: int +SECONDLY: int + +class weekday(weekdaybase): + ... + +MO: weekday +TU: weekday +WE: weekday +TH: weekday +FR: weekday +SA: weekday +SU: weekday + +class rrulebase: + def __init__(self, cache: bool = ...) -> None: ... + def __iter__(self): ... + def __getitem__(self, item): ... + def __contains__(self, item): ... + def count(self): ... + def before(self, dt, inc: bool = ...): ... + def after(self, dt, inc: bool = ...): ... + def xafter(self, dt, count: Optional[Any] = ..., inc: bool = ...): ... + def between(self, after, before, inc: bool = ..., count: int = ...): ... + +class rrule(rrulebase): + def __init__(self, + freq, + dtstart: Optional[datetime.datetime] = ..., + interval: int = ..., + wkst: Optional[Union[weekday, int]] = ..., + count: Optional[int] = ..., + until: Optional[Union[datetime.datetime, int]] = ..., + bysetpos: Optional[Union[int, Iterable[int]]] = ..., + bymonth: Optional[Union[int, Iterable[int]]] = ..., + bymonthday: Optional[Union[int, Iterable[int]]] = ..., + byyearday: Optional[Union[int, Iterable[int]]] = ..., + byeaster: Optional[Union[int, Iterable[int]]] = ..., + byweekno: Optional[Union[int, Iterable[int]]] = ..., + byweekday: Optional[Union[int, Iterable[int]]] = ..., + byhour: Optional[Union[int, Iterable[int]]] = ..., + byminute: Optional[Union[int, Iterable[int]]] = ..., + bysecond: Optional[Union[int, Iterable[int]]] = ..., + cache: bool = ...) -> None: ... + def replace(self, **kwargs): ... + +class _iterinfo: + rrule: Any = ... + def __init__(self, rrule) -> None: ... + yearlen: int = ... + nextyearlen: int = ... + yearordinal: int = ... + yearweekday: int = ... + mmask: Any = ... + mdaymask: Any = ... + nmdaymask: Any = ... + wdaymask: Any = ... + mrange: Any = ... + wnomask: Any = ... + nwdaymask: Any = ... + eastermask: Any = ... + lastyear: int = ... + lastmonth: int = ... + def rebuild(self, year, month): ... + def ydayset(self, year, month, day): ... + def mdayset(self, year, month, day): ... + def wdayset(self, year, month, day): ... + def ddayset(self, year, month, day): ... + def htimeset(self, hour, minute, second): ... + def mtimeset(self, hour, minute, second): ... + def stimeset(self, hour, minute, second): ... + +class rruleset(rrulebase): + class _genitem: + dt: Any = ... + genlist: Any = ... + gen: Any = ... + def __init__(self, genlist, gen) -> None: ... + def __next__(self): ... + next: Any = ... + def __lt__(self, other): ... + def __gt__(self, other): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def __init__(self, cache: bool = ...) -> None: ... + def rrule(self, rrule): ... + def rdate(self, rdate): ... + def exrule(self, exrule): ... + def exdate(self, exdate): ... + +class _rrulestr: + def __call__(self, s, **kwargs): ... + +rrulestr: _rrulestr diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/__init__.pyi new file mode 100644 index 000000000..68cfb9e2b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/__init__.pyi @@ -0,0 +1,12 @@ +from .tz import ( + tzutc as tzutc, + tzoffset as tzoffset, + tzlocal as tzlocal, + tzfile as tzfile, + tzrange as tzrange, + tzstr as tzstr, + tzical as tzical, + gettz as gettz, + datetime_exists as datetime_exists, + datetime_ambiguous as datetime_ambiguous, +) diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/_common.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/_common.pyi new file mode 100644 index 000000000..383218d60 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/_common.pyi @@ -0,0 +1,24 @@ +from typing import Any, Optional +from datetime import datetime, tzinfo, timedelta + +def tzname_in_python2(namefunc): ... +def enfold(dt: datetime, fold: int = ...): ... + +class _DatetimeWithFold(datetime): + @property + def fold(self): ... + +class _tzinfo(tzinfo): + def is_ambiguous(self, dt: datetime) -> bool: ... + def fromutc(self, dt: datetime) -> datetime: ... + +class tzrangebase(_tzinfo): + def __init__(self) -> None: ... + def utcoffset(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def dst(self, dt: Optional[datetime]) -> Optional[timedelta]: ... + def tzname(self, dt: Optional[datetime]) -> str: ... + def fromutc(self, dt: datetime) -> datetime: ... + def is_ambiguous(self, dt: datetime) -> bool: ... + __hash__ = ... # type: Any + def __ne__(self, other): ... + __reduce__ = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/tz.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/tz.pyi new file mode 100644 index 000000000..5fbc932bb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/dateutil/tz/tz.pyi @@ -0,0 +1,83 @@ +from typing import Any, Optional, Union, IO, Text, Tuple, List +import datetime +from ._common import tzname_in_python2 as tzname_in_python2, _tzinfo as _tzinfo +from ._common import tzrangebase as tzrangebase, enfold as enfold +from ..relativedelta import relativedelta + +_FileObj = Union[str, Text, IO[str], IO[Text]] + +ZERO = ... # type: datetime.timedelta +EPOCH = ... # type: datetime.datetime +EPOCHORDINAL = ... # type: int + +class tzutc(datetime.tzinfo): + def utcoffset(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def dst(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def tzname(self, dt: Optional[datetime.datetime]) -> str: ... + def is_ambiguous(self, dt: Optional[datetime.datetime]) -> bool: ... + def __eq__(self, other): ... + __hash__ = ... # type: Any + def __ne__(self, other): ... + __reduce__ = ... # type: Any + +class tzoffset(datetime.tzinfo): + def __init__(self, name, offset) -> None: ... + def utcoffset(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def dst(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def is_ambiguous(self, dt: Optional[datetime.datetime]) -> bool: ... + def tzname(self, dt: Optional[datetime.datetime]) -> str: ... + def __eq__(self, other): ... + __hash__ = ... # type: Any + def __ne__(self, other): ... + __reduce__ = ... # type: Any + +class tzlocal(_tzinfo): + def __init__(self) -> None: ... + def utcoffset(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def dst(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def tzname(self, dt: Optional[datetime.datetime]) -> str: ... + def is_ambiguous(self, dt: Optional[datetime.datetime]) -> bool: ... + def __eq__(self, other): ... + __hash__ = ... # type: Any + def __ne__(self, other): ... + __reduce__ = ... # type: Any + +class _ttinfo: + def __init__(self) -> None: ... + def __eq__(self, other): ... + __hash__ = ... # type: Any + def __ne__(self, other): ... + +class tzfile(_tzinfo): + def __init__(self, fileobj: _FileObj, filename: Optional[Text] = ...) -> None: ... + def is_ambiguous(self, dt: Optional[datetime.datetime], idx: Optional[int] = ...) -> bool: ... + def utcoffset(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def dst(self, dt: Optional[datetime.datetime]) -> Optional[datetime.timedelta]: ... + def tzname(self, dt: Optional[datetime.datetime]) -> str: ... + def __eq__(self, other): ... + __hash__ = ... # type: Any + def __ne__(self, other): ... + def __reduce__(self): ... + def __reduce_ex__(self, protocol): ... + +class tzrange(tzrangebase): + hasdst = ... # type: bool + def __init__(self, stdabbr: Text, stdoffset: Union[int, datetime.timedelta, None] = ..., dstabbr: Optional[Text] = ..., dstoffset: Union[int, datetime.timedelta, None] = ..., start: Optional[relativedelta] = ..., end: Optional[relativedelta] = ...) -> None: ... + def transitions(self, year: int) -> Tuple[datetime.datetime, datetime.datetime]: ... + def __eq__(self, other): ... + +class tzstr(tzrange): + hasdst = ... # type: bool + def __init__(self, s: Union[bytes, _FileObj], posix_offset: bool = ...) -> None: ... + +class tzical: + def __init__(self, fileobj: _FileObj) -> None: ... + def keys(self): ... + def get(self, tzid: Optional[Any] = ...): ... + +TZFILES = ... # type: List[str] +TZPATHS = ... # type: List[str] + +def gettz(name: Optional[Text] = ...) -> Optional[datetime.tzinfo]: ... +def datetime_exists(dt: datetime.datetime, tz: Optional[datetime.tzinfo] = ...) -> bool: ... +def datetime_ambiguous(dt: datetime.datetime, tz: Optional[datetime.tzinfo] = ...) -> bool: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/emoji.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/emoji.pyi new file mode 100644 index 000000000..53fb5793c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/emoji.pyi @@ -0,0 +1,18 @@ +from typing import Tuple, Pattern, List, Dict, Union + +_DEFAULT_DELIMITER = ... # type: str + +def emojize( + string: str, + use_aliases: bool=..., + delimiters: Tuple[str, str]=... +) -> str: ... + +def demojize( + string: str, + delimiters: Tuple[str, str]=... +) -> str: ... + +def get_emoji_regexp() -> Pattern: ... + +def emoji_lis(string: str) -> List[Dict[str, Union[int, str]]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/first.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/first.pyi new file mode 100644 index 000000000..f03f3a35b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/first.pyi @@ -0,0 +1,13 @@ +from typing import Any, Callable, Iterable, Optional, overload, TypeVar, Union + +_T = TypeVar('_T') +_S = TypeVar('_S') + +@overload +def first(iterable: Iterable[_T]) -> Optional[_T]: ... +@overload +def first(iterable: Iterable[_T], default: _S) -> Union[_T, _S]: ... +@overload +def first(iterable: Iterable[_T], default: _S, key: Optional[Callable[[_T], Any]]) -> Union[_T, _S]: ... +@overload +def first(iterable: Iterable[_T], *, key: Optional[Callable[[_T], Any]]) -> Optional[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/__init__.pyi new file mode 100644 index 000000000..535c1f762 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/__init__.pyi @@ -0,0 +1 @@ +__version__ = ... # type: bytes diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/any_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/any_pb2.pyi new file mode 100644 index 000000000..ca69cf421 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/any_pb2.pyi @@ -0,0 +1,22 @@ +from google.protobuf.message import ( + Message, +) +from google.protobuf.internal import well_known_types + +from typing import ( + Optional, + Text, +) + + +class Any(Message, well_known_types.Any_): + type_url = ... # type: Text + value = ... # type: bytes + + def __init__(self, + type_url: Optional[Text] = ..., + value: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/any_test_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/any_test_pb2.pyi new file mode 100644 index 000000000..580178226 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/any_test_pb2.pyi @@ -0,0 +1,32 @@ +from google.protobuf.any_pb2 import ( + Any, +) +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from typing import ( + Iterable, + Optional, +) + + +class TestAny(Message): + int32_value = ... # type: int + + @property + def any_value(self) -> Any: ... + + @property + def repeated_any_value(self) -> RepeatedCompositeFieldContainer[Any]: ... + + def __init__(self, + int32_value: Optional[int] = ..., + any_value: Optional[Any] = ..., + repeated_any_value: Optional[Iterable[Any]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAny: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/api_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/api_pb2.pyi new file mode 100644 index 000000000..0ff4be52c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/api_pb2.pyi @@ -0,0 +1,87 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.source_context_pb2 import ( + SourceContext, +) +from google.protobuf.type_pb2 import ( + Option, + Syntax, +) +from typing import ( + Iterable, + Optional, + Text, +) + + +class Api(Message): + name = ... # type: Text + version = ... # type: Text + syntax = ... # type: Syntax + + @property + def methods(self) -> RepeatedCompositeFieldContainer[Method]: ... + + @property + def options(self) -> RepeatedCompositeFieldContainer[Option]: ... + + @property + def source_context(self) -> SourceContext: ... + + @property + def mixins(self) -> RepeatedCompositeFieldContainer[Mixin]: ... + + def __init__(self, + name: Optional[Text] = ..., + methods: Optional[Iterable[Method]] = ..., + options: Optional[Iterable[Option]] = ..., + version: Optional[Text] = ..., + source_context: Optional[SourceContext] = ..., + mixins: Optional[Iterable[Mixin]] = ..., + syntax: Optional[Syntax] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Api: ... + + +class Method(Message): + name = ... # type: Text + request_type_url = ... # type: Text + request_streaming = ... # type: bool + response_type_url = ... # type: Text + response_streaming = ... # type: bool + syntax = ... # type: Syntax + + @property + def options(self) -> RepeatedCompositeFieldContainer[Option]: ... + + def __init__(self, + name: Optional[Text] = ..., + request_type_url: Optional[Text] = ..., + request_streaming: Optional[bool] = ..., + response_type_url: Optional[Text] = ..., + response_streaming: Optional[bool] = ..., + options: Optional[Iterable[Option]] = ..., + syntax: Optional[Syntax] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Method: ... + + +class Mixin(Message): + name = ... # type: Text + root = ... # type: Text + + def __init__(self, + name: Optional[Text] = ..., + root: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Mixin: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/compiler/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/compiler/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/compiler/plugin_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/compiler/plugin_pb2.pyi new file mode 100644 index 000000000..874c79678 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/compiler/plugin_pb2.pyi @@ -0,0 +1,82 @@ +from google.protobuf.descriptor_pb2 import ( + FileDescriptorProto, +) +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from typing import ( + Iterable, + Optional, + Text, +) + + +class Version(Message): + major = ... # type: int + minor = ... # type: int + patch = ... # type: int + suffix = ... # type: Text + + def __init__(self, + major: Optional[int] = ..., + minor: Optional[int] = ..., + patch: Optional[int] = ..., + suffix: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Version: ... + + +class CodeGeneratorRequest(Message): + file_to_generate = ... # type: RepeatedScalarFieldContainer[Text] + parameter = ... # type: Text + + @property + def proto_file(self) -> RepeatedCompositeFieldContainer[FileDescriptorProto]: ... + + @property + def compiler_version(self) -> Version: ... + + def __init__(self, + file_to_generate: Optional[Iterable[Text]] = ..., + parameter: Optional[Text] = ..., + proto_file: Optional[Iterable[FileDescriptorProto]] = ..., + compiler_version: Optional[Version] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CodeGeneratorRequest: ... + + +class CodeGeneratorResponse(Message): + + class File(Message): + name = ... # type: Text + insertion_point = ... # type: Text + content = ... # type: Text + + def __init__(self, + name: Optional[Text] = ..., + insertion_point: Optional[Text] = ..., + content: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CodeGeneratorResponse.File: ... + error = ... # type: Text + + @property + def file(self) -> RepeatedCompositeFieldContainer[CodeGeneratorResponse.File]: ... + + def __init__(self, + error: Optional[Text] = ..., + file: Optional[Iterable[CodeGeneratorResponse.File]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CodeGeneratorResponse: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor.pyi new file mode 100644 index 000000000..7acdd2ed1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor.pyi @@ -0,0 +1,161 @@ +from typing import Any + +from .message import Message + +class Error(Exception): ... +class TypeTransformationError(Error): ... + +class DescriptorMetaclass(type): + def __instancecheck__(cls, obj): ... + +class DescriptorBase: + __metaclass__ = DescriptorMetaclass + has_options = ... # type: Any + def __init__(self, options, options_class_name) -> None: ... + def GetOptions(self): ... + +class _NestedDescriptorBase(DescriptorBase): + name = ... # type: Any + full_name = ... # type: Any + file = ... # type: Any + containing_type = ... # type: Any + def __init__(self, options, options_class_name, name, full_name, file, containing_type, serialized_start=..., serialized_end=...) -> None: ... + def GetTopLevelContainingType(self): ... + def CopyToProto(self, proto): ... + +class Descriptor(_NestedDescriptorBase): + def __new__(cls, name, full_name, filename, containing_type, fields, nested_types, enum_types, extensions, options=..., is_extendable=..., extension_ranges=..., oneofs=..., file=..., serialized_start=..., serialized_end=..., syntax=...): ... + fields = ... # type: Any + fields_by_number = ... # type: Any + fields_by_name = ... # type: Any + nested_types = ... # type: Any + nested_types_by_name = ... # type: Any + enum_types = ... # type: Any + enum_types_by_name = ... # type: Any + enum_values_by_name = ... # type: Any + extensions = ... # type: Any + extensions_by_name = ... # type: Any + is_extendable = ... # type: Any + extension_ranges = ... # type: Any + oneofs = ... # type: Any + oneofs_by_name = ... # type: Any + syntax = ... # type: Any + def __init__(self, name, full_name, filename, containing_type, fields, nested_types, enum_types, extensions, options=..., is_extendable=..., extension_ranges=..., oneofs=..., file=..., serialized_start=..., serialized_end=..., syntax=...) -> None: ... + def EnumValueName(self, enum, value): ... + def CopyToProto(self, proto): ... + +class FieldDescriptor(DescriptorBase): + TYPE_DOUBLE = ... # type: Any + TYPE_FLOAT = ... # type: Any + TYPE_INT64 = ... # type: Any + TYPE_UINT64 = ... # type: Any + TYPE_INT32 = ... # type: Any + TYPE_FIXED64 = ... # type: Any + TYPE_FIXED32 = ... # type: Any + TYPE_BOOL = ... # type: Any + TYPE_STRING = ... # type: Any + TYPE_GROUP = ... # type: Any + TYPE_MESSAGE = ... # type: Any + TYPE_BYTES = ... # type: Any + TYPE_UINT32 = ... # type: Any + TYPE_ENUM = ... # type: Any + TYPE_SFIXED32 = ... # type: Any + TYPE_SFIXED64 = ... # type: Any + TYPE_SINT32 = ... # type: Any + TYPE_SINT64 = ... # type: Any + MAX_TYPE = ... # type: Any + CPPTYPE_INT32 = ... # type: Any + CPPTYPE_INT64 = ... # type: Any + CPPTYPE_UINT32 = ... # type: Any + CPPTYPE_UINT64 = ... # type: Any + CPPTYPE_DOUBLE = ... # type: Any + CPPTYPE_FLOAT = ... # type: Any + CPPTYPE_BOOL = ... # type: Any + CPPTYPE_ENUM = ... # type: Any + CPPTYPE_STRING = ... # type: Any + CPPTYPE_MESSAGE = ... # type: Any + MAX_CPPTYPE = ... # type: Any + LABEL_OPTIONAL = ... # type: Any + LABEL_REQUIRED = ... # type: Any + LABEL_REPEATED = ... # type: Any + MAX_LABEL = ... # type: Any + MAX_FIELD_NUMBER = ... # type: Any + FIRST_RESERVED_FIELD_NUMBER = ... # type: Any + LAST_RESERVED_FIELD_NUMBER = ... # type: Any + def __new__(cls, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=..., file=..., has_default_value=..., containing_oneof=...): ... + name = ... # type: Any + full_name = ... # type: Any + index = ... # type: Any + number = ... # type: Any + type = ... # type: Any + cpp_type = ... # type: Any + label = ... # type: Any + has_default_value = ... # type: Any + default_value = ... # type: Any + containing_type = ... # type: Any + message_type = ... # type: Any + enum_type = ... # type: Any + is_extension = ... # type: Any + extension_scope = ... # type: Any + containing_oneof = ... # type: Any + def __init__(self, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=..., file=..., has_default_value=..., containing_oneof=...) -> None: ... + @staticmethod + def ProtoTypeToCppProtoType(proto_type): ... + +class EnumDescriptor(_NestedDescriptorBase): + def __new__(cls, name, full_name, filename, values, containing_type=..., options=..., file=..., serialized_start=..., serialized_end=...): ... + values = ... # type: Any + values_by_name = ... # type: Any + values_by_number = ... # type: Any + def __init__(self, name, full_name, filename, values, containing_type=..., options=..., file=..., serialized_start=..., serialized_end=...) -> None: ... + def CopyToProto(self, proto): ... + +class EnumValueDescriptor(DescriptorBase): + def __new__(cls, name, index, number, type=..., options=...): ... + name = ... # type: Any + index = ... # type: Any + number = ... # type: Any + type = ... # type: Any + def __init__(self, name, index, number, type=..., options=...) -> None: ... + +class OneofDescriptor: + def __new__(cls, name, full_name, index, containing_type, fields): ... + name = ... # type: Any + full_name = ... # type: Any + index = ... # type: Any + containing_type = ... # type: Any + fields = ... # type: Any + def __init__(self, name, full_name, index, containing_type, fields) -> None: ... + +class ServiceDescriptor(_NestedDescriptorBase): + index = ... # type: Any + methods = ... # type: Any + def __init__(self, name, full_name, index, methods, options=..., file=..., serialized_start=..., serialized_end=...) -> None: ... + def FindMethodByName(self, name): ... + def CopyToProto(self, proto): ... + +class MethodDescriptor(DescriptorBase): + name = ... # type: Any + full_name = ... # type: Any + index = ... # type: Any + containing_service = ... # type: Any + input_type = ... # type: Any + output_type = ... # type: Any + def __init__(self, name, full_name, index, containing_service, input_type, output_type, options=...) -> None: ... + +class FileDescriptor(DescriptorBase): + def __new__(cls, name, package, options=..., serialized_pb=..., dependencies=..., syntax=...): ... + _options = ... # type: Any + message_types_by_name = ... # type: Any + name = ... # type: Any + package = ... # type: Any + syntax = ... # type: Any + serialized_pb = ... # type: Any + enum_types_by_name = ... # type: Any + extensions_by_name = ... # type: Any + dependencies = ... # type: Any + def __init__(self, name, package, options=..., serialized_pb=..., dependencies=..., syntax=...) -> None: ... + def CopyToProto(self, proto): ... + +def MakeDescriptor(desc_proto, package=..., build_file_if_cpp=..., syntax=...): ... +def _ParseOptions(message: Message, string: bytes) -> Message: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor_pb2.pyi new file mode 100644 index 000000000..424755d1f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor_pb2.pyi @@ -0,0 +1,732 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from typing import ( + Iterable, + List, + Optional, + Text, + Tuple, + cast, +) + + +class FileDescriptorSet(Message): + + @property + def file(self) -> RepeatedCompositeFieldContainer[FileDescriptorProto]: ... + + def __init__(self, + file: Optional[Iterable[FileDescriptorProto]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FileDescriptorSet: ... + + +class FileDescriptorProto(Message): + name = ... # type: Text + package = ... # type: Text + dependency = ... # type: RepeatedScalarFieldContainer[Text] + public_dependency = ... # type: RepeatedScalarFieldContainer[int] + weak_dependency = ... # type: RepeatedScalarFieldContainer[int] + syntax = ... # type: Text + + @property + def message_type( + self) -> RepeatedCompositeFieldContainer[DescriptorProto]: ... + + @property + def enum_type( + self) -> RepeatedCompositeFieldContainer[EnumDescriptorProto]: ... + + @property + def service( + self) -> RepeatedCompositeFieldContainer[ServiceDescriptorProto]: ... + + @property + def extension( + self) -> RepeatedCompositeFieldContainer[FieldDescriptorProto]: ... + + @property + def options(self) -> FileOptions: ... + + @property + def source_code_info(self) -> SourceCodeInfo: ... + + def __init__(self, + name: Optional[Text] = ..., + package: Optional[Text] = ..., + dependency: Optional[Iterable[Text]] = ..., + public_dependency: Optional[Iterable[int]] = ..., + weak_dependency: Optional[Iterable[int]] = ..., + message_type: Optional[Iterable[DescriptorProto]] = ..., + enum_type: Optional[Iterable[EnumDescriptorProto]] = ..., + service: Optional[Iterable[ServiceDescriptorProto]] = ..., + extension: Optional[Iterable[FieldDescriptorProto]] = ..., + options: Optional[FileOptions] = ..., + source_code_info: Optional[SourceCodeInfo] = ..., + syntax: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FileDescriptorProto: ... + + +class DescriptorProto(Message): + + class ExtensionRange(Message): + start = ... # type: int + end = ... # type: int + + @property + def options(self) -> ExtensionRangeOptions: ... + + def __init__(self, + start: Optional[int] = ..., + end: Optional[int] = ..., + options: Optional[ExtensionRangeOptions] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> DescriptorProto.ExtensionRange: ... + + class ReservedRange(Message): + start = ... # type: int + end = ... # type: int + + def __init__(self, + start: Optional[int] = ..., + end: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> DescriptorProto.ReservedRange: ... + name = ... # type: Text + reserved_name = ... # type: RepeatedScalarFieldContainer[Text] + + @property + def field( + self) -> RepeatedCompositeFieldContainer[FieldDescriptorProto]: ... + + @property + def extension( + self) -> RepeatedCompositeFieldContainer[FieldDescriptorProto]: ... + + @property + def nested_type( + self) -> RepeatedCompositeFieldContainer[DescriptorProto]: ... + + @property + def enum_type( + self) -> RepeatedCompositeFieldContainer[EnumDescriptorProto]: ... + + @property + def extension_range( + self) -> RepeatedCompositeFieldContainer[DescriptorProto.ExtensionRange]: ... + + @property + def oneof_decl( + self) -> RepeatedCompositeFieldContainer[OneofDescriptorProto]: ... + + @property + def options(self) -> MessageOptions: ... + + @property + def reserved_range( + self) -> RepeatedCompositeFieldContainer[DescriptorProto.ReservedRange]: ... + + def __init__(self, + name: Optional[Text] = ..., + field: Optional[Iterable[FieldDescriptorProto]] = ..., + extension: Optional[Iterable[FieldDescriptorProto]] = ..., + nested_type: Optional[Iterable[DescriptorProto]] = ..., + enum_type: Optional[Iterable[EnumDescriptorProto]] = ..., + extension_range: Optional[Iterable[DescriptorProto.ExtensionRange]] = ..., + oneof_decl: Optional[Iterable[OneofDescriptorProto]] = ..., + options: Optional[MessageOptions] = ..., + reserved_range: Optional[Iterable[DescriptorProto.ReservedRange]] = ..., + reserved_name: Optional[Iterable[Text]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> DescriptorProto: ... + + +class ExtensionRangeOptions(Message): + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ExtensionRangeOptions: ... + + +class FieldDescriptorProto(Message): + + class Type(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> FieldDescriptorProto.Type: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[FieldDescriptorProto.Type]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, FieldDescriptorProto.Type]]: ... + TYPE_DOUBLE: Type + TYPE_FLOAT: Type + TYPE_INT64: Type + TYPE_UINT64: Type + TYPE_INT32: Type + TYPE_FIXED64: Type + TYPE_FIXED32: Type + TYPE_BOOL: Type + TYPE_STRING: Type + TYPE_GROUP: Type + TYPE_MESSAGE: Type + TYPE_BYTES: Type + TYPE_UINT32: Type + TYPE_ENUM: Type + TYPE_SFIXED32: Type + TYPE_SFIXED64: Type + TYPE_SINT32: Type + TYPE_SINT64: Type + + class Label(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> FieldDescriptorProto.Label: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[FieldDescriptorProto.Label]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, FieldDescriptorProto.Label]]: ... + LABEL_OPTIONAL: Label + LABEL_REQUIRED: Label + LABEL_REPEATED: Label + name = ... # type: Text + number = ... # type: int + label = ... # type: FieldDescriptorProto.Label + type = ... # type: FieldDescriptorProto.Type + type_name = ... # type: Text + extendee = ... # type: Text + default_value = ... # type: Text + oneof_index = ... # type: int + json_name = ... # type: Text + + @property + def options(self) -> FieldOptions: ... + + def __init__(self, + name: Optional[Text] = ..., + number: Optional[int] = ..., + label: Optional[FieldDescriptorProto.Label] = ..., + type: Optional[FieldDescriptorProto.Type] = ..., + type_name: Optional[Text] = ..., + extendee: Optional[Text] = ..., + default_value: Optional[Text] = ..., + oneof_index: Optional[int] = ..., + json_name: Optional[Text] = ..., + options: Optional[FieldOptions] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FieldDescriptorProto: ... + + +class OneofDescriptorProto(Message): + name = ... # type: Text + + @property + def options(self) -> OneofOptions: ... + + def __init__(self, + name: Optional[Text] = ..., + options: Optional[OneofOptions] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> OneofDescriptorProto: ... + + +class EnumDescriptorProto(Message): + + class EnumReservedRange(Message): + start = ... # type: int + end = ... # type: int + + def __init__(self, + start: Optional[int] = ..., + end: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> EnumDescriptorProto.EnumReservedRange: ... + name = ... # type: Text + reserved_name = ... # type: RepeatedScalarFieldContainer[Text] + + @property + def value( + self) -> RepeatedCompositeFieldContainer[EnumValueDescriptorProto]: ... + + @property + def options(self) -> EnumOptions: ... + + @property + def reserved_range( + self) -> RepeatedCompositeFieldContainer[EnumDescriptorProto.EnumReservedRange]: ... + + def __init__(self, + name: Optional[Text] = ..., + value: Optional[Iterable[EnumValueDescriptorProto]] = ..., + options: Optional[EnumOptions] = ..., + reserved_range: Optional[Iterable[EnumDescriptorProto.EnumReservedRange]] = ..., + reserved_name: Optional[Iterable[Text]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> EnumDescriptorProto: ... + + +class EnumValueDescriptorProto(Message): + name = ... # type: Text + number = ... # type: int + + @property + def options(self) -> EnumValueOptions: ... + + def __init__(self, + name: Optional[Text] = ..., + number: Optional[int] = ..., + options: Optional[EnumValueOptions] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> EnumValueDescriptorProto: ... + + +class ServiceDescriptorProto(Message): + name = ... # type: Text + + @property + def method( + self) -> RepeatedCompositeFieldContainer[MethodDescriptorProto]: ... + + @property + def options(self) -> ServiceOptions: ... + + def __init__(self, + name: Optional[Text] = ..., + method: Optional[Iterable[MethodDescriptorProto]] = ..., + options: Optional[ServiceOptions] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ServiceDescriptorProto: ... + + +class MethodDescriptorProto(Message): + name = ... # type: Text + input_type = ... # type: Text + output_type = ... # type: Text + client_streaming = ... # type: bool + server_streaming = ... # type: bool + + @property + def options(self) -> MethodOptions: ... + + def __init__(self, + name: Optional[Text] = ..., + input_type: Optional[Text] = ..., + output_type: Optional[Text] = ..., + options: Optional[MethodOptions] = ..., + client_streaming: Optional[bool] = ..., + server_streaming: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MethodDescriptorProto: ... + + +class FileOptions(Message): + + class OptimizeMode(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> FileOptions.OptimizeMode: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[FileOptions.OptimizeMode]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, FileOptions.OptimizeMode]]: ... + SPEED: OptimizeMode + CODE_SIZE: OptimizeMode + LITE_RUNTIME: OptimizeMode + java_package = ... # type: Text + java_outer_classname = ... # type: Text + java_multiple_files = ... # type: bool + java_generate_equals_and_hash = ... # type: bool + java_string_check_utf8 = ... # type: bool + optimize_for = ... # type: FileOptions.OptimizeMode + go_package = ... # type: Text + cc_generic_services = ... # type: bool + java_generic_services = ... # type: bool + py_generic_services = ... # type: bool + php_generic_services = ... # type: bool + deprecated = ... # type: bool + cc_enable_arenas = ... # type: bool + objc_class_prefix = ... # type: Text + csharp_namespace = ... # type: Text + swift_prefix = ... # type: Text + php_class_prefix = ... # type: Text + php_namespace = ... # type: Text + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + java_package: Optional[Text] = ..., + java_outer_classname: Optional[Text] = ..., + java_multiple_files: Optional[bool] = ..., + java_generate_equals_and_hash: Optional[bool] = ..., + java_string_check_utf8: Optional[bool] = ..., + optimize_for: Optional[FileOptions.OptimizeMode] = ..., + go_package: Optional[Text] = ..., + cc_generic_services: Optional[bool] = ..., + java_generic_services: Optional[bool] = ..., + py_generic_services: Optional[bool] = ..., + php_generic_services: Optional[bool] = ..., + deprecated: Optional[bool] = ..., + cc_enable_arenas: Optional[bool] = ..., + objc_class_prefix: Optional[Text] = ..., + csharp_namespace: Optional[Text] = ..., + swift_prefix: Optional[Text] = ..., + php_class_prefix: Optional[Text] = ..., + php_namespace: Optional[Text] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FileOptions: ... + + +class MessageOptions(Message): + message_set_wire_format = ... # type: bool + no_standard_descriptor_accessor = ... # type: bool + deprecated = ... # type: bool + map_entry = ... # type: bool + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + message_set_wire_format: Optional[bool] = ..., + no_standard_descriptor_accessor: Optional[bool] = ..., + deprecated: Optional[bool] = ..., + map_entry: Optional[bool] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MessageOptions: ... + + +class FieldOptions(Message): + + class CType(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> FieldOptions.CType: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[FieldOptions.CType]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, FieldOptions.CType]]: ... + STRING: CType + CORD: CType + STRING_PIECE: CType + + class JSType(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> FieldOptions.JSType: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[FieldOptions.JSType]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, FieldOptions.JSType]]: ... + JS_NORMAL: JSType + JS_STRING: JSType + JS_NUMBER: JSType + ctype = ... # type: FieldOptions.CType + packed = ... # type: bool + jstype = ... # type: FieldOptions.JSType + lazy = ... # type: bool + deprecated = ... # type: bool + weak = ... # type: bool + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + ctype: Optional[FieldOptions.CType] = ..., + packed: Optional[bool] = ..., + jstype: Optional[FieldOptions.JSType] = ..., + lazy: Optional[bool] = ..., + deprecated: Optional[bool] = ..., + weak: Optional[bool] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FieldOptions: ... + + +class OneofOptions(Message): + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> OneofOptions: ... + + +class EnumOptions(Message): + allow_alias = ... # type: bool + deprecated = ... # type: bool + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + allow_alias: Optional[bool] = ..., + deprecated: Optional[bool] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> EnumOptions: ... + + +class EnumValueOptions(Message): + deprecated = ... # type: bool + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + deprecated: Optional[bool] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> EnumValueOptions: ... + + +class ServiceOptions(Message): + deprecated = ... # type: bool + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + deprecated: Optional[bool] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ServiceOptions: ... + + +class MethodOptions(Message): + + class IdempotencyLevel(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> MethodOptions.IdempotencyLevel: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[MethodOptions.IdempotencyLevel]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, MethodOptions.IdempotencyLevel]]: ... + IDEMPOTENCY_UNKNOWN: IdempotencyLevel + NO_SIDE_EFFECTS: IdempotencyLevel + IDEMPOTENT: IdempotencyLevel + deprecated = ... # type: bool + idempotency_level = ... # type: MethodOptions.IdempotencyLevel + + @property + def uninterpreted_option( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ... + + def __init__(self, + deprecated: Optional[bool] = ..., + idempotency_level: Optional[MethodOptions.IdempotencyLevel] = ..., + uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MethodOptions: ... + + +class UninterpretedOption(Message): + + class NamePart(Message): + name_part = ... # type: Text + is_extension = ... # type: bool + + def __init__(self, + name_part: Text, + is_extension: bool, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> UninterpretedOption.NamePart: ... + identifier_value = ... # type: Text + positive_int_value = ... # type: int + negative_int_value = ... # type: int + double_value = ... # type: float + string_value = ... # type: bytes + aggregate_value = ... # type: Text + + @property + def name( + self) -> RepeatedCompositeFieldContainer[UninterpretedOption.NamePart]: ... + + def __init__(self, + name: Optional[Iterable[UninterpretedOption.NamePart]] = ..., + identifier_value: Optional[Text] = ..., + positive_int_value: Optional[int] = ..., + negative_int_value: Optional[int] = ..., + double_value: Optional[float] = ..., + string_value: Optional[bytes] = ..., + aggregate_value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> UninterpretedOption: ... + + +class SourceCodeInfo(Message): + + class Location(Message): + path = ... # type: RepeatedScalarFieldContainer[int] + span = ... # type: RepeatedScalarFieldContainer[int] + leading_comments = ... # type: Text + trailing_comments = ... # type: Text + leading_detached_comments = ... # type: RepeatedScalarFieldContainer[Text] + + def __init__(self, + path: Optional[Iterable[int]] = ..., + span: Optional[Iterable[int]] = ..., + leading_comments: Optional[Text] = ..., + trailing_comments: Optional[Text] = ..., + leading_detached_comments: Optional[Iterable[Text]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> SourceCodeInfo.Location: ... + + @property + def location( + self) -> RepeatedCompositeFieldContainer[SourceCodeInfo.Location]: ... + + def __init__(self, + location: Optional[Iterable[SourceCodeInfo.Location]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> SourceCodeInfo: ... + + +class GeneratedCodeInfo(Message): + + class Annotation(Message): + path = ... # type: RepeatedScalarFieldContainer[int] + source_file = ... # type: Text + begin = ... # type: int + end = ... # type: int + + def __init__(self, + path: Optional[Iterable[int]] = ..., + source_file: Optional[Text] = ..., + begin: Optional[int] = ..., + end: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> GeneratedCodeInfo.Annotation: ... + + @property + def annotation( + self) -> RepeatedCompositeFieldContainer[GeneratedCodeInfo.Annotation]: ... + + def __init__(self, + annotation: Optional[Iterable[GeneratedCodeInfo.Annotation]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> GeneratedCodeInfo: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor_pool.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor_pool.pyi new file mode 100644 index 000000000..f1ade5261 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/descriptor_pool.pyi @@ -0,0 +1,18 @@ +from typing import Any, Optional + +class DescriptorPool: + def __new__(cls, descriptor_db: Optional[Any] = ...): ... + def __init__(self, descriptor_db: Optional[Any] = ...) -> None: ... + def Add(self, file_desc_proto): ... + def AddSerializedFile(self, serialized_file_desc_proto): ... + def AddDescriptor(self, desc): ... + def AddEnumDescriptor(self, enum_desc): ... + def AddFileDescriptor(self, file_desc): ... + def FindFileByName(self, file_name): ... + def FindFileContainingSymbol(self, symbol): ... + def FindMessageTypeByName(self, full_name): ... + def FindEnumTypeByName(self, full_name): ... + def FindFieldByName(self, full_name): ... + def FindExtensionByName(self, full_name): ... + +def Default(): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/duration_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/duration_pb2.pyi new file mode 100644 index 000000000..9d8fc6664 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/duration_pb2.pyi @@ -0,0 +1,21 @@ +from google.protobuf.message import ( + Message, +) +from google.protobuf.internal import well_known_types + +from typing import ( + Optional, +) + + +class Duration(Message, well_known_types.Duration): + seconds = ... # type: int + nanos = ... # type: int + + def __init__(self, + seconds: Optional[int] = ..., + nanos: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Duration: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/empty_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/empty_pb2.pyi new file mode 100644 index 000000000..295ebfa93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/empty_pb2.pyi @@ -0,0 +1,12 @@ +from google.protobuf.message import ( + Message, +) + + +class Empty(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Empty: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/field_mask_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/field_mask_pb2.pyi new file mode 100644 index 000000000..e90f95058 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/field_mask_pb2.pyi @@ -0,0 +1,24 @@ +from google.protobuf.internal.containers import ( + RepeatedScalarFieldContainer, +) +from google.protobuf.internal import well_known_types + +from google.protobuf.message import ( + Message, +) +from typing import ( + Iterable, + Optional, + Text, +) + + +class FieldMask(Message, well_known_types.FieldMask): + paths = ... # type: RepeatedScalarFieldContainer[Text] + + def __init__(self, + paths: Optional[Iterable[Text]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FieldMask: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/containers.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/containers.pyi new file mode 100644 index 000000000..33e603c93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/containers.pyi @@ -0,0 +1,54 @@ +from google.protobuf.descriptor import Descriptor +from google.protobuf.internal.message_listener import MessageListener +from google.protobuf.message import Message +from typing import ( + Sequence, TypeVar, Generic, Any, Iterator, Iterable, + Union, Optional, Callable, overload, List +) + +_T = TypeVar('_T') +class BaseContainer(Sequence[_T]): + def __init__(self, message_listener: MessageListener) -> None: ... + def __len__(self) -> int: ... + def __ne__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... + def __repr__(self) -> str: ... + def sort(self, *, key: Optional[Callable[[_T], Any]] = ..., reverse: bool = ...) -> None: ... + @overload + def __getitem__(self, key: int) -> _T: ... + @overload + def __getitem__(self, key: slice) -> List[_T]: ... + +class RepeatedScalarFieldContainer(BaseContainer[_T]): + def __init__(self, message_listener: MessageListener, message_descriptor: Descriptor) -> None: ... + def append(self, value: _T) -> None: ... + def insert(self, key: int, value: _T) -> None: ... + def extend(self, elem_seq: Optional[Iterable[_T]]) -> None: ... + def MergeFrom(self, other: RepeatedScalarFieldContainer[_T]) -> None: ... + def remove(self, elem: _T) -> None: ... + def pop(self, key: int = ...) -> _T: ... + @overload + def __setitem__(self, key: int, value: _T) -> None: ... + @overload + def __setitem__(self, key: slice, value: Iterable[_T]) -> None: ... + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + def __setslice__(self, start: int, stop: int, values: Iterable[_T]) -> None: ... + def __delitem__(self, key: Union[int, slice]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + +class RepeatedCompositeFieldContainer(BaseContainer[_T]): + def __init__(self, message_listener: MessageListener, type_checker: Any) -> None: ... + def add(self, **kwargs: Any) -> _T: ... + def extend(self, elem_seq: Iterable[_T]) -> None: ... + def MergeFrom(self, other: RepeatedCompositeFieldContainer[_T]) -> None: ... + def remove(self, elem: _T) -> None: ... + def pop(self, key: int = ...) -> _T: ... + def __getslice__(self, start: int, stop: int) -> List[_T]: ... + def __delitem__(self, key: Union[int, slice]) -> None: ... + def __delslice__(self, start: int, stop: int) -> None: ... + +# Classes not yet typed +class Mapping(Any): ... +class MutableMapping(Mapping): ... +class ScalarMap(MutableMapping): ... +class MessageMap(MutableMapping): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/decoder.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/decoder.pyi new file mode 100644 index 000000000..24918b251 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/decoder.pyi @@ -0,0 +1,30 @@ +from typing import Any + +def ReadTag(buffer, pos): ... +def EnumDecoder(field_number, is_repeated, is_packed, key, new_default): ... + +Int32Decoder = ... # type: Any +Int64Decoder = ... # type: Any +UInt32Decoder = ... # type: Any +UInt64Decoder = ... # type: Any +SInt32Decoder = ... # type: Any +SInt64Decoder = ... # type: Any +Fixed32Decoder = ... # type: Any +Fixed64Decoder = ... # type: Any +SFixed32Decoder = ... # type: Any +SFixed64Decoder = ... # type: Any +FloatDecoder = ... # type: Any +DoubleDecoder = ... # type: Any +BoolDecoder = ... # type: Any + +def StringDecoder(field_number, is_repeated, is_packed, key, new_default): ... +def BytesDecoder(field_number, is_repeated, is_packed, key, new_default): ... +def GroupDecoder(field_number, is_repeated, is_packed, key, new_default): ... +def MessageDecoder(field_number, is_repeated, is_packed, key, new_default): ... + +MESSAGE_SET_ITEM_TAG = ... # type: Any + +def MessageSetItemDecoder(extensions_by_number): ... +def MapDecoder(field_descriptor, new_default, is_message_map): ... + +SkipField = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/encoder.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/encoder.pyi new file mode 100644 index 000000000..a29caf4d5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/encoder.pyi @@ -0,0 +1,34 @@ +from typing import Any + +Int32Sizer = ... # type: Any +UInt32Sizer = ... # type: Any +SInt32Sizer = ... # type: Any +Fixed32Sizer = ... # type: Any +Fixed64Sizer = ... # type: Any +BoolSizer = ... # type: Any + +def StringSizer(field_number, is_repeated, is_packed): ... +def BytesSizer(field_number, is_repeated, is_packed): ... +def GroupSizer(field_number, is_repeated, is_packed): ... +def MessageSizer(field_number, is_repeated, is_packed): ... +def MessageSetItemSizer(field_number): ... +def MapSizer(field_descriptor): ... +def TagBytes(field_number, wire_type): ... + +Int32Encoder = ... # type: Any +UInt32Encoder = ... # type: Any +SInt32Encoder = ... # type: Any +Fixed32Encoder = ... # type: Any +Fixed64Encoder = ... # type: Any +SFixed32Encoder = ... # type: Any +SFixed64Encoder = ... # type: Any +FloatEncoder = ... # type: Any +DoubleEncoder = ... # type: Any + +def BoolEncoder(field_number, is_repeated, is_packed): ... +def StringEncoder(field_number, is_repeated, is_packed): ... +def BytesEncoder(field_number, is_repeated, is_packed): ... +def GroupEncoder(field_number, is_repeated, is_packed): ... +def MessageEncoder(field_number, is_repeated, is_packed): ... +def MessageSetItemEncoder(field_number): ... +def MapEncoder(field_descriptor): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/enum_type_wrapper.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/enum_type_wrapper.pyi new file mode 100644 index 000000000..61d6ea10c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/enum_type_wrapper.pyi @@ -0,0 +1,11 @@ +from typing import Any, List, Tuple + +class EnumTypeWrapper(object): + def __init__(self, enum_type: Any) -> None: ... + def Name(self, number: int) -> bytes: ... + def Value(self, name: bytes) -> int: ... + def keys(self) -> List[bytes]: ... + def values(self) -> List[int]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, int]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/message_listener.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/message_listener.pyi new file mode 100644 index 000000000..e8d33a5a1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/message_listener.pyi @@ -0,0 +1,5 @@ +class MessageListener(object): + def Modified(self) -> None: ... + +class NullMessageListener(MessageListener): + def Modified(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/well_known_types.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/well_known_types.pyi new file mode 100644 index 000000000..695d9d193 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/well_known_types.pyi @@ -0,0 +1,91 @@ +from typing import Any, Optional + +class Error(Exception): ... +class ParseError(Error): ... + +# This is named 'Any' in the original, but that conflicts with typing.Any, +# and we really only need this file to mix in. +class Any_: + type_url: Any = ... + value: Any = ... + def Pack(self, msg: Any, type_url_prefix: bytes = ..., deterministic: Optional[Any] = ...) -> None: ... + def Unpack(self, msg: Any): ... + def TypeName(self): ... + def Is(self, descriptor: Any): ... + +class Timestamp: + def ToJsonString(self): ... + seconds: Any = ... + nanos: Any = ... + def FromJsonString(self, value: Any) -> None: ... + def GetCurrentTime(self) -> None: ... + def ToNanoseconds(self): ... + def ToMicroseconds(self): ... + def ToMilliseconds(self): ... + def ToSeconds(self): ... + def FromNanoseconds(self, nanos: Any) -> None: ... + def FromMicroseconds(self, micros: Any) -> None: ... + def FromMilliseconds(self, millis: Any) -> None: ... + def FromSeconds(self, seconds: Any) -> None: ... + def ToDatetime(self): ... + def FromDatetime(self, dt: Any) -> None: ... + +class Duration: + def ToJsonString(self): ... + seconds: Any = ... + nanos: Any = ... + def FromJsonString(self, value: Any) -> None: ... + def ToNanoseconds(self): ... + def ToMicroseconds(self): ... + def ToMilliseconds(self): ... + def ToSeconds(self): ... + def FromNanoseconds(self, nanos: Any) -> None: ... + def FromMicroseconds(self, micros: Any) -> None: ... + def FromMilliseconds(self, millis: Any) -> None: ... + def FromSeconds(self, seconds: Any) -> None: ... + def ToTimedelta(self): ... + def FromTimedelta(self, td: Any) -> None: ... + +class FieldMask: + def ToJsonString(self): ... + def FromJsonString(self, value: Any) -> None: ... + def IsValidForDescriptor(self, message_descriptor: Any): ... + def AllFieldsFromDescriptor(self, message_descriptor: Any) -> None: ... + def CanonicalFormFromMask(self, mask: Any) -> None: ... + def Union(self, mask1: Any, mask2: Any) -> None: ... + def Intersect(self, mask1: Any, mask2: Any) -> None: ... + def MergeMessage(self, source: Any, destination: Any, replace_message_field: bool = ..., replace_repeated_field: bool = ...) -> None: ... + +class _FieldMaskTree: + def __init__(self, field_mask: Optional[Any] = ...) -> None: ... + def MergeFromFieldMask(self, field_mask: Any) -> None: ... + def AddPath(self, path: Any): ... + def ToFieldMask(self, field_mask: Any) -> None: ... + def IntersectPath(self, path: Any, intersection: Any): ... + def AddLeafNodes(self, prefix: Any, node: Any) -> None: ... + def MergeMessage(self, source: Any, destination: Any, replace_message: Any, replace_repeated: Any) -> None: ... + +class Struct: + def __getitem__(self, key: Any): ... + def __contains__(self, item: Any): ... + def __setitem__(self, key: Any, value: Any) -> None: ... + def __delitem__(self, key: Any) -> None: ... + def __len__(self): ... + def __iter__(self): ... + def keys(self): ... + def values(self): ... + def items(self): ... + def get_or_create_list(self, key: Any): ... + def get_or_create_struct(self, key: Any): ... + def update(self, dictionary: Any) -> None: ... + +class ListValue: + def __len__(self): ... + def append(self, value: Any) -> None: ... + def extend(self, elem_seq: Any) -> None: ... + def __getitem__(self, index: Any): ... + def __setitem__(self, index: Any, value: Any) -> None: ... + def __delitem__(self, key: Any) -> None: ... + def items(self) -> None: ... + def add_struct(self): ... + def add_list(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/wire_format.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/wire_format.pyi new file mode 100644 index 000000000..0025a2ce9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/internal/wire_format.pyi @@ -0,0 +1,50 @@ +from typing import Any + +TAG_TYPE_BITS = ... # type: Any +TAG_TYPE_MASK = ... # type: Any +WIRETYPE_VARINT = ... # type: Any +WIRETYPE_FIXED64 = ... # type: Any +WIRETYPE_LENGTH_DELIMITED = ... # type: Any +WIRETYPE_START_GROUP = ... # type: Any +WIRETYPE_END_GROUP = ... # type: Any +WIRETYPE_FIXED32 = ... # type: Any +INT32_MAX = ... # type: Any +INT32_MIN = ... # type: Any +UINT32_MAX = ... # type: Any +INT64_MAX = ... # type: Any +INT64_MIN = ... # type: Any +UINT64_MAX = ... # type: Any +FORMAT_UINT32_LITTLE_ENDIAN = ... # type: Any +FORMAT_UINT64_LITTLE_ENDIAN = ... # type: Any +FORMAT_FLOAT_LITTLE_ENDIAN = ... # type: Any +FORMAT_DOUBLE_LITTLE_ENDIAN = ... # type: Any + +def PackTag(field_number, wire_type): ... +def UnpackTag(tag): ... +def ZigZagEncode(value): ... +def ZigZagDecode(value): ... +def Int32ByteSize(field_number, int32): ... +def Int32ByteSizeNoTag(int32): ... +def Int64ByteSize(field_number, int64): ... +def UInt32ByteSize(field_number, uint32): ... +def UInt64ByteSize(field_number, uint64): ... +def SInt32ByteSize(field_number, int32): ... +def SInt64ByteSize(field_number, int64): ... +def Fixed32ByteSize(field_number, fixed32): ... +def Fixed64ByteSize(field_number, fixed64): ... +def SFixed32ByteSize(field_number, sfixed32): ... +def SFixed64ByteSize(field_number, sfixed64): ... +def FloatByteSize(field_number, flt): ... +def DoubleByteSize(field_number, double): ... +def BoolByteSize(field_number, b): ... +def EnumByteSize(field_number, enum): ... +def StringByteSize(field_number, string): ... +def BytesByteSize(field_number, b): ... +def GroupByteSize(field_number, message): ... +def MessageByteSize(field_number, message): ... +def MessageSetItemByteSize(field_number, msg): ... +def TagByteSize(field_number): ... + +NON_PACKABLE_TYPES = ... # type: Any + +def IsTypePackable(field_type): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/map_proto2_unittest_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/map_proto2_unittest_pb2.pyi new file mode 100644 index 000000000..c7f87e5be --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/map_proto2_unittest_pb2.pyi @@ -0,0 +1,428 @@ +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_import_pb2 import ( + ImportEnumForMap, +) +from typing import ( + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class Proto2MapEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> Proto2MapEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[Proto2MapEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, Proto2MapEnum]]: ... +PROTO2_MAP_ENUM_FOO: Proto2MapEnum +PROTO2_MAP_ENUM_BAR: Proto2MapEnum +PROTO2_MAP_ENUM_BAZ: Proto2MapEnum + + +class Proto2MapEnumPlusExtra(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> Proto2MapEnumPlusExtra: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[Proto2MapEnumPlusExtra]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, Proto2MapEnumPlusExtra]]: ... +E_PROTO2_MAP_ENUM_FOO: Proto2MapEnumPlusExtra +E_PROTO2_MAP_ENUM_BAR: Proto2MapEnumPlusExtra +E_PROTO2_MAP_ENUM_BAZ: Proto2MapEnumPlusExtra +E_PROTO2_MAP_ENUM_EXTRA: Proto2MapEnumPlusExtra + + +class TestEnumMap(Message): + + class KnownMapFieldEntry(Message): + key = ... # type: int + value = ... # type: Proto2MapEnum + + def __init__(self, + key: Optional[int] = ..., + value: Optional[Proto2MapEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumMap.KnownMapFieldEntry: ... + + class UnknownMapFieldEntry(Message): + key = ... # type: int + value = ... # type: Proto2MapEnum + + def __init__(self, + key: Optional[int] = ..., + value: Optional[Proto2MapEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumMap.UnknownMapFieldEntry: ... + + @property + def known_map_field(self) -> MutableMapping[int, Proto2MapEnum]: ... + + @property + def unknown_map_field(self) -> MutableMapping[int, Proto2MapEnum]: ... + + def __init__(self, + known_map_field: Optional[Mapping[int, Proto2MapEnum]]=..., + unknown_map_field: Optional[Mapping[int, Proto2MapEnum]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumMap: ... + + +class TestEnumMapPlusExtra(Message): + + class KnownMapFieldEntry(Message): + key = ... # type: int + value = ... # type: Proto2MapEnumPlusExtra + + def __init__(self, + key: Optional[int] = ..., + value: Optional[Proto2MapEnumPlusExtra] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumMapPlusExtra.KnownMapFieldEntry: ... + + class UnknownMapFieldEntry(Message): + key = ... # type: int + value = ... # type: Proto2MapEnumPlusExtra + + def __init__(self, + key: Optional[int] = ..., + value: Optional[Proto2MapEnumPlusExtra] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumMapPlusExtra.UnknownMapFieldEntry: ... + + @property + def known_map_field(self) -> MutableMapping[int, Proto2MapEnumPlusExtra]: ... + + @property + def unknown_map_field(self) -> MutableMapping[int, Proto2MapEnumPlusExtra]: ... + + def __init__(self, + known_map_field: Optional[Mapping[int, Proto2MapEnumPlusExtra]]=..., + unknown_map_field: Optional[Mapping[int, Proto2MapEnumPlusExtra]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumMapPlusExtra: ... + + +class TestImportEnumMap(Message): + + class ImportEnumAmpEntry(Message): + key = ... # type: int + value = ... # type: ImportEnumForMap + + def __init__(self, + key: Optional[int] = ..., + value: Optional[ImportEnumForMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestImportEnumMap.ImportEnumAmpEntry: ... + + @property + def import_enum_amp(self) -> MutableMapping[int, ImportEnumForMap]: ... + + def __init__(self, + import_enum_amp: Optional[Mapping[int, ImportEnumForMap]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestImportEnumMap: ... + + +class TestIntIntMap(Message): + + class MEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestIntIntMap.MEntry: ... + + @property + def m(self) -> MutableMapping[int, int]: ... + + def __init__(self, + m: Optional[Mapping[int, int]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestIntIntMap: ... + + +class TestMaps(Message): + + class MInt32Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MInt32Entry: ... + + class MInt64Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MInt64Entry: ... + + class MUint32Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MUint32Entry: ... + + class MUint64Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MUint64Entry: ... + + class MSint32Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MSint32Entry: ... + + class MSint64Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MSint64Entry: ... + + class MFixed32Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MFixed32Entry: ... + + class MFixed64Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MFixed64Entry: ... + + class MSfixed32Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MSfixed32Entry: ... + + class MSfixed64Entry(Message): + key = ... # type: int + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MSfixed64Entry: ... + + class MBoolEntry(Message): + key = ... # type: bool + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MBoolEntry: ... + + class MStringEntry(Message): + key = ... # type: Text + + @property + def value(self) -> TestIntIntMap: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestIntIntMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps.MStringEntry: ... + + @property + def m_int32(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_int64(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_uint32(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_uint64(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_sint32(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_sint64(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_fixed32(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_fixed64(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_sfixed32(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_sfixed64(self) -> MutableMapping[int, TestIntIntMap]: ... + + @property + def m_bool(self) -> MutableMapping[bool, TestIntIntMap]: ... + + @property + def m_string(self) -> MutableMapping[Text, TestIntIntMap]: ... + + def __init__(self, + m_int32: Optional[Mapping[int, TestIntIntMap]]=..., + m_int64: Optional[Mapping[int, TestIntIntMap]]=..., + m_uint32: Optional[Mapping[int, TestIntIntMap]]=..., + m_uint64: Optional[Mapping[int, TestIntIntMap]]=..., + m_sint32: Optional[Mapping[int, TestIntIntMap]]=..., + m_sint64: Optional[Mapping[int, TestIntIntMap]]=..., + m_fixed32: Optional[Mapping[int, TestIntIntMap]]=..., + m_fixed64: Optional[Mapping[int, TestIntIntMap]]=..., + m_sfixed32: Optional[Mapping[int, TestIntIntMap]]=..., + m_sfixed64: Optional[Mapping[int, TestIntIntMap]]=..., + m_bool: Optional[Mapping[bool, TestIntIntMap]]=..., + m_string: Optional[Mapping[Text, TestIntIntMap]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMaps: ... + + +class TestSubmessageMaps(Message): + + @property + def m(self) -> TestMaps: ... + + def __init__(self, + m: Optional[TestMaps] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestSubmessageMaps: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/map_unittest_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/map_unittest_pb2.pyi new file mode 100644 index 000000000..e0137d570 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/map_unittest_pb2.pyi @@ -0,0 +1,882 @@ +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_no_arena_pb2 import ( + ForeignMessage, +) +from google.protobuf.unittest_pb2 import ( + ForeignMessage as ForeignMessage1, + TestAllTypes, + TestRequired, +) +from typing import ( + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class MapEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> MapEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[MapEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, MapEnum]]: ... + + +MAP_ENUM_FOO: MapEnum +MAP_ENUM_BAR: MapEnum +MAP_ENUM_BAZ: MapEnum + + +class TestMap(Message): + + class MapInt32Int32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32Int32Entry: ... + + class MapInt64Int64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt64Int64Entry: ... + + class MapUint32Uint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapUint32Uint32Entry: ... + + class MapUint64Uint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapUint64Uint64Entry: ... + + class MapSint32Sint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapSint32Sint32Entry: ... + + class MapSint64Sint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapSint64Sint64Entry: ... + + class MapFixed32Fixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapFixed32Fixed32Entry: ... + + class MapFixed64Fixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapFixed64Fixed64Entry: ... + + class MapSfixed32Sfixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapSfixed32Sfixed32Entry: ... + + class MapSfixed64Sfixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapSfixed64Sfixed64Entry: ... + + class MapInt32FloatEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32FloatEntry: ... + + class MapInt32DoubleEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32DoubleEntry: ... + + class MapBoolBoolEntry(Message): + key = ... # type: bool + value = ... # type: bool + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapBoolBoolEntry: ... + + class MapStringStringEntry(Message): + key = ... # type: Text + value = ... # type: Text + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapStringStringEntry: ... + + class MapInt32BytesEntry(Message): + key = ... # type: int + value = ... # type: bytes + + def __init__(self, + key: Optional[int] = ..., + value: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32BytesEntry: ... + + class MapInt32EnumEntry(Message): + key = ... # type: int + value = ... # type: MapEnum + + def __init__(self, + key: Optional[int] = ..., + value: Optional[MapEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32EnumEntry: ... + + class MapInt32ForeignMessageEntry(Message): + key = ... # type: int + + @property + def value(self) -> ForeignMessage1: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[ForeignMessage1] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32ForeignMessageEntry: ... + + class MapStringForeignMessageEntry(Message): + key = ... # type: Text + + @property + def value(self) -> ForeignMessage1: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[ForeignMessage1] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestMap.MapStringForeignMessageEntry: ... + + class MapInt32AllTypesEntry(Message): + key = ... # type: int + + @property + def value(self) -> TestAllTypes: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.MapInt32AllTypesEntry: ... + + @property + def map_int32_int32(self) -> MutableMapping[int, int]: ... + + @property + def map_int64_int64(self) -> MutableMapping[int, int]: ... + + @property + def map_uint32_uint32(self) -> MutableMapping[int, int]: ... + + @property + def map_uint64_uint64(self) -> MutableMapping[int, int]: ... + + @property + def map_sint32_sint32(self) -> MutableMapping[int, int]: ... + + @property + def map_sint64_sint64(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed32_fixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed64_fixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed32_sfixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed64_sfixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_int32_float(self) -> MutableMapping[int, float]: ... + + @property + def map_int32_double(self) -> MutableMapping[int, float]: ... + + @property + def map_bool_bool(self) -> MutableMapping[bool, bool]: ... + + @property + def map_string_string(self) -> MutableMapping[Text, Text]: ... + + @property + def map_int32_bytes(self) -> MutableMapping[int, bytes]: ... + + @property + def map_int32_enum(self) -> MutableMapping[int, MapEnum]: ... + + @property + def map_int32_foreign_message( + self) -> MutableMapping[int, ForeignMessage1]: ... + + @property + def map_string_foreign_message( + self) -> MutableMapping[Text, ForeignMessage1]: ... + + @property + def map_int32_all_types(self) -> MutableMapping[int, TestAllTypes]: ... + + def __init__(self, + map_int32_int32: Optional[Mapping[int, int]]=..., + map_int64_int64: Optional[Mapping[int, int]]=..., + map_uint32_uint32: Optional[Mapping[int, int]]=..., + map_uint64_uint64: Optional[Mapping[int, int]]=..., + map_sint32_sint32: Optional[Mapping[int, int]]=..., + map_sint64_sint64: Optional[Mapping[int, int]]=..., + map_fixed32_fixed32: Optional[Mapping[int, int]]=..., + map_fixed64_fixed64: Optional[Mapping[int, int]]=..., + map_sfixed32_sfixed32: Optional[Mapping[int, int]]=..., + map_sfixed64_sfixed64: Optional[Mapping[int, int]]=..., + map_int32_float: Optional[Mapping[int, float]]=..., + map_int32_double: Optional[Mapping[int, float]]=..., + map_bool_bool: Optional[Mapping[bool, bool]]=..., + map_string_string: Optional[Mapping[Text, Text]]=..., + map_int32_bytes: Optional[Mapping[int, bytes]]=..., + map_int32_enum: Optional[Mapping[int, MapEnum]]=..., + map_int32_foreign_message: Optional[Mapping[int, ForeignMessage1]]=..., + map_string_foreign_message: Optional[Mapping[Text, ForeignMessage1]]=..., + map_int32_all_types: Optional[Mapping[int, TestAllTypes]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap: ... + + +class TestMapSubmessage(Message): + + @property + def test_map(self) -> TestMap: ... + + def __init__(self, + test_map: Optional[TestMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMapSubmessage: ... + + +class TestMessageMap(Message): + + class MapInt32MessageEntry(Message): + key = ... # type: int + + @property + def value(self) -> TestAllTypes: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageMap.MapInt32MessageEntry: ... + + @property + def map_int32_message(self) -> MutableMapping[int, TestAllTypes]: ... + + def __init__(self, + map_int32_message: Optional[Mapping[int, TestAllTypes]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageMap: ... + + +class TestSameTypeMap(Message): + + class Map1Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestSameTypeMap.Map1Entry: ... + + class Map2Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestSameTypeMap.Map2Entry: ... + + @property + def map1(self) -> MutableMapping[int, int]: ... + + @property + def map2(self) -> MutableMapping[int, int]: ... + + def __init__(self, + map1: Optional[Mapping[int, int]]=..., + map2: Optional[Mapping[int, int]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestSameTypeMap: ... + + +class TestRequiredMessageMap(Message): + + class MapFieldEntry(Message): + key = ... # type: int + + @property + def value(self) -> TestRequired: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[TestRequired] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestRequiredMessageMap.MapFieldEntry: ... + + @property + def map_field(self) -> MutableMapping[int, TestRequired]: ... + + def __init__(self, + map_field: Optional[Mapping[int, TestRequired]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRequiredMessageMap: ... + + +class TestArenaMap(Message): + + class MapInt32Int32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapInt32Int32Entry: ... + + class MapInt64Int64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapInt64Int64Entry: ... + + class MapUint32Uint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapUint32Uint32Entry: ... + + class MapUint64Uint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapUint64Uint64Entry: ... + + class MapSint32Sint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapSint32Sint32Entry: ... + + class MapSint64Sint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapSint64Sint64Entry: ... + + class MapFixed32Fixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapFixed32Fixed32Entry: ... + + class MapFixed64Fixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapFixed64Fixed64Entry: ... + + class MapSfixed32Sfixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestArenaMap.MapSfixed32Sfixed32Entry: ... + + class MapSfixed64Sfixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestArenaMap.MapSfixed64Sfixed64Entry: ... + + class MapInt32FloatEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapInt32FloatEntry: ... + + class MapInt32DoubleEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapInt32DoubleEntry: ... + + class MapBoolBoolEntry(Message): + key = ... # type: bool + value = ... # type: bool + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapBoolBoolEntry: ... + + class MapStringStringEntry(Message): + key = ... # type: Text + value = ... # type: Text + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapStringStringEntry: ... + + class MapInt32BytesEntry(Message): + key = ... # type: int + value = ... # type: bytes + + def __init__(self, + key: Optional[int] = ..., + value: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapInt32BytesEntry: ... + + class MapInt32EnumEntry(Message): + key = ... # type: int + value = ... # type: MapEnum + + def __init__(self, + key: Optional[int] = ..., + value: Optional[MapEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap.MapInt32EnumEntry: ... + + class MapInt32ForeignMessageEntry(Message): + key = ... # type: int + + @property + def value(self) -> ForeignMessage1: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[ForeignMessage1] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestArenaMap.MapInt32ForeignMessageEntry: ... + + class MapInt32ForeignMessageNoArenaEntry(Message): + key = ... # type: int + + @property + def value(self) -> ForeignMessage: ... + + def __init__(self, + key: Optional[int] = ..., + value: Optional[ForeignMessage] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestArenaMap.MapInt32ForeignMessageNoArenaEntry: ... + + @property + def map_int32_int32(self) -> MutableMapping[int, int]: ... + + @property + def map_int64_int64(self) -> MutableMapping[int, int]: ... + + @property + def map_uint32_uint32(self) -> MutableMapping[int, int]: ... + + @property + def map_uint64_uint64(self) -> MutableMapping[int, int]: ... + + @property + def map_sint32_sint32(self) -> MutableMapping[int, int]: ... + + @property + def map_sint64_sint64(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed32_fixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed64_fixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed32_sfixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed64_sfixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_int32_float(self) -> MutableMapping[int, float]: ... + + @property + def map_int32_double(self) -> MutableMapping[int, float]: ... + + @property + def map_bool_bool(self) -> MutableMapping[bool, bool]: ... + + @property + def map_string_string(self) -> MutableMapping[Text, Text]: ... + + @property + def map_int32_bytes(self) -> MutableMapping[int, bytes]: ... + + @property + def map_int32_enum(self) -> MutableMapping[int, MapEnum]: ... + + @property + def map_int32_foreign_message( + self) -> MutableMapping[int, ForeignMessage1]: ... + + @property + def map_int32_foreign_message_no_arena( + self) -> MutableMapping[int, ForeignMessage]: ... + + def __init__(self, + map_int32_int32: Optional[Mapping[int, int]]=..., + map_int64_int64: Optional[Mapping[int, int]]=..., + map_uint32_uint32: Optional[Mapping[int, int]]=..., + map_uint64_uint64: Optional[Mapping[int, int]]=..., + map_sint32_sint32: Optional[Mapping[int, int]]=..., + map_sint64_sint64: Optional[Mapping[int, int]]=..., + map_fixed32_fixed32: Optional[Mapping[int, int]]=..., + map_fixed64_fixed64: Optional[Mapping[int, int]]=..., + map_sfixed32_sfixed32: Optional[Mapping[int, int]]=..., + map_sfixed64_sfixed64: Optional[Mapping[int, int]]=..., + map_int32_float: Optional[Mapping[int, float]]=..., + map_int32_double: Optional[Mapping[int, float]]=..., + map_bool_bool: Optional[Mapping[bool, bool]]=..., + map_string_string: Optional[Mapping[Text, Text]]=..., + map_int32_bytes: Optional[Mapping[int, bytes]]=..., + map_int32_enum: Optional[Mapping[int, MapEnum]]=..., + map_int32_foreign_message: Optional[Mapping[int, ForeignMessage1]]=..., + map_int32_foreign_message_no_arena: Optional[Mapping[int, ForeignMessage]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestArenaMap: ... + + +class MessageContainingEnumCalledType(Message): + + class Type(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> MessageContainingEnumCalledType.Type: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[MessageContainingEnumCalledType.Type]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, + MessageContainingEnumCalledType.Type]]: ... + TYPE_FOO: Type + + class TypeEntry(Message): + key = ... # type: Text + + @property + def value(self) -> MessageContainingEnumCalledType: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[MessageContainingEnumCalledType] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> MessageContainingEnumCalledType.TypeEntry: ... + + @property + def type(self) -> MutableMapping[Text, + MessageContainingEnumCalledType]: ... + + def __init__(self, + type: Optional[Mapping[Text, MessageContainingEnumCalledType]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MessageContainingEnumCalledType: ... + + +class MessageContainingMapCalledEntry(Message): + + class EntryEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> MessageContainingMapCalledEntry.EntryEntry: ... + + @property + def entry(self) -> MutableMapping[int, int]: ... + + def __init__(self, + entry: Optional[Mapping[int, int]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MessageContainingMapCalledEntry: ... + + +class TestRecursiveMapMessage(Message): + + class AEntry(Message): + key = ... # type: Text + + @property + def value(self) -> TestRecursiveMapMessage: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestRecursiveMapMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRecursiveMapMessage.AEntry: ... + + @property + def a(self) -> MutableMapping[Text, TestRecursiveMapMessage]: ... + + def __init__(self, + a: Optional[Mapping[Text, TestRecursiveMapMessage]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRecursiveMapMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/message.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/message.pyi new file mode 100644 index 000000000..b164a7621 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/message.pyi @@ -0,0 +1,32 @@ +from typing import Any, Sequence, Optional, Text, Tuple + +from .descriptor import FieldDescriptor + +class Error(Exception): ... +class DecodeError(Error): ... +class EncodeError(Error): ... + +class Message: + DESCRIPTOR = ... # type: Any + def __deepcopy__(self, memo=...): ... + def __eq__(self, other_msg): ... + def __ne__(self, other_msg): ... + def MergeFrom(self, other_msg: Message) -> None: ... + def CopyFrom(self, other_msg: Message) -> None: ... + def Clear(self) -> None: ... + def SetInParent(self) -> None: ... + def IsInitialized(self) -> bool: ... + def MergeFromString(self, serialized: Any) -> int: ... # TODO: we need to be able to call buffer() on serialized + def ParseFromString(self, serialized: Any) -> None: ... + def SerializeToString(self) -> bytes: ... + def SerializePartialToString(self) -> bytes: ... + def ListFields(self) -> Sequence[Tuple[FieldDescriptor, Any]]: ... + def HasField(self, field_name: Text) -> bool: ... + def ClearField(self, field_name: Text) -> None: ... + def WhichOneof(self, oneof_group) -> Optional[Text]: ... + def HasExtension(self, extension_handle): ... + def ClearExtension(self, extension_handle): ... + def ByteSize(self) -> int: ... + + # TODO: check kwargs + def __init__(self, **kwargs) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/message_factory.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/message_factory.pyi new file mode 100644 index 000000000..c51c1364b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/message_factory.pyi @@ -0,0 +1,13 @@ +from typing import Any, Dict, Iterable, Optional, Type + +from .message import Message +from .descriptor import Descriptor +from .descriptor_pool import DescriptorPool + +class MessageFactory: + pool = ... # type: Any + def __init__(self, pool: Optional[DescriptorPool] = ...) -> None: ... + def GetPrototype(self, descriptor: Descriptor) -> Type[Message]: ... + def GetMessages(self, files: Iterable[bytes]) -> Dict[bytes, Type[Message]]: ... + +def GetMessages(file_protos: Iterable[bytes]) -> Dict[bytes, Type[Message]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/reflection.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/reflection.pyi new file mode 100644 index 000000000..d32a93dc0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/reflection.pyi @@ -0,0 +1,6 @@ +class GeneratedProtocolMessageType(type): + def __new__(cls, name, bases, dictionary): ... + def __init__(cls, name, bases, dictionary) -> None: ... + +def ParseMessage(descriptor, byte_str): ... +def MakeClass(descriptor): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/service.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/service.pyi new file mode 100644 index 000000000..4874d5356 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/service.pyi @@ -0,0 +1,39 @@ +from concurrent.futures import Future +from typing import Callable, Optional, Text, Type + +from google.protobuf.descriptor import MethodDescriptor, ServiceDescriptor +from google.protobuf.message import Message + +class RpcException(Exception): ... + +class Service: + @staticmethod + def GetDescriptor() -> ServiceDescriptor: ... + def CallMethod( + self, + method_descriptor: MethodDescriptor, + rpc_controller: RpcController, + request: Message, + done: Optional[Callable[[Message], None]], + ) -> Optional[Future[Message]]: ... + def GetRequestClass(self, method_descriptor: MethodDescriptor) -> Type[Message]: ... + def GetResponseClass(self, method_descriptor: MethodDescriptor) -> Type[Message]: ... + +class RpcController: + def Reset(self) -> None: ... + def Failed(self) -> bool: ... + def ErrorText(self) -> Optional[Text]: ... + def StartCancel(self) -> None: ... + def SetFailed(self, reason: Text) -> None: ... + def IsCanceled(self) -> bool: ... + def NotifyOnCancel(self, callback: Callable[[], None]) -> None: ... + +class RpcChannel: + def CallMethod( + self, + method_descriptor: MethodDescriptor, + rpc_controller: RpcController, + request: Message, + response_class: Type[Message], + done: Optional[Callable[[Message], None]], + ) -> Optional[Future[Message]]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/source_context_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/source_context_pb2.pyi new file mode 100644 index 000000000..7c2575730 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/source_context_pb2.pyi @@ -0,0 +1,18 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + Optional, + Text, +) + + +class SourceContext(Message): + file_name = ... # type: Text + + def __init__(self, + file_name: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> SourceContext: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/struct_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/struct_pb2.pyi new file mode 100644 index 000000000..01a3a67a1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/struct_pb2.pyi @@ -0,0 +1,105 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, +) +from google.protobuf.internal import well_known_types + +from google.protobuf.message import ( + Message, +) +from typing import ( + Iterable, + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class NullValue(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> NullValue: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[NullValue]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, NullValue]]: ... + + +NULL_VALUE: NullValue + + +class Struct(Message, well_known_types.Struct): + class FieldsEntry(Message): + key = ... # type: Text + + @property + def value(self) -> Value: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[Value] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Struct.FieldsEntry: ... + + @property + def fields(self) -> MutableMapping[Text, Value]: ... + + def __init__(self, + fields: Optional[Mapping[Text, Value]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Struct: ... + + +class _Value(Message): + null_value = ... # type: NullValue + number_value = ... # type: float + string_value = ... # type: Text + bool_value = ... # type: bool + + @property + def struct_value(self) -> Struct: ... + + @property + def list_value(self) -> ListValue: ... + + def __init__(self, + null_value: Optional[NullValue] = ..., + number_value: Optional[float] = ..., + string_value: Optional[Text] = ..., + bool_value: Optional[bool] = ..., + struct_value: Optional[Struct] = ..., + list_value: Optional[ListValue] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> _Value: ... + + +Value = _Value + + +class ListValue(Message, well_known_types.ListValue): + + @property + def values(self) -> RepeatedCompositeFieldContainer[Value]: ... + + def __init__(self, + values: Optional[Iterable[Value]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ListValue: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/symbol_database.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/symbol_database.pyi new file mode 100644 index 000000000..477d80e9f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/symbol_database.pyi @@ -0,0 +1,14 @@ +from typing import Dict, Iterable, Type + +from .descriptor import EnumDescriptor, FileDescriptor +from .message import Message +from .message_factory import MessageFactory + +class SymbolDatabase(MessageFactory): + def RegisterMessage(self, message: Type[Message]) -> Type[Message]: ... + def RegisterEnumDescriptor(self, enum_descriptor: Type[EnumDescriptor]) -> EnumDescriptor: ... + def RegisterFileDescriptor(self, file_descriptor: Type[FileDescriptor]) -> FileDescriptor: ... + def GetSymbol(self, symbol: bytes) -> Type[Message]: ... + def GetMessages(self, files: Iterable[bytes]) -> Dict[bytes, Type[Message]]: ... + +def Default(): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/test_messages_proto2_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/test_messages_proto2_pb2.pyi new file mode 100644 index 000000000..1dd097f0b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/test_messages_proto2_pb2.pyi @@ -0,0 +1,627 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +import builtins +from typing import ( + Iterable, + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class ForeignEnumProto2(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ForeignEnumProto2: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ForeignEnumProto2]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ForeignEnumProto2]]: ... + + +FOREIGN_FOO: ForeignEnumProto2 +FOREIGN_BAR: ForeignEnumProto2 +FOREIGN_BAZ: ForeignEnumProto2 + + +class TestAllTypesProto2(Message): + + class NestedEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestAllTypesProto2.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestAllTypesProto2.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestAllTypesProto2.NestedEnum]]: ... + FOO: NestedEnum + BAR: NestedEnum + BAZ: NestedEnum + NEG: NestedEnum + + class NestedMessage(Message): + a = ... # type: int + + @property + def corecursive(self) -> TestAllTypesProto2: ... + + def __init__(self, + a: Optional[int] = ..., + corecursive: Optional[TestAllTypesProto2] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto2.NestedMessage: ... + + class MapInt32Int32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapInt32Int32Entry: ... + + class MapInt64Int64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapInt64Int64Entry: ... + + class MapUint32Uint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapUint32Uint32Entry: ... + + class MapUint64Uint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapUint64Uint64Entry: ... + + class MapSint32Sint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapSint32Sint32Entry: ... + + class MapSint64Sint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapSint64Sint64Entry: ... + + class MapFixed32Fixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapFixed32Fixed32Entry: ... + + class MapFixed64Fixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapFixed64Fixed64Entry: ... + + class MapSfixed32Sfixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapSfixed32Sfixed32Entry: ... + + class MapSfixed64Sfixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapSfixed64Sfixed64Entry: ... + + class MapInt32FloatEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapInt32FloatEntry: ... + + class MapInt32DoubleEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapInt32DoubleEntry: ... + + class MapBoolBoolEntry(Message): + key = ... # type: bool + value = ... # type: bool + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto2.MapBoolBoolEntry: ... + + class MapStringStringEntry(Message): + key = ... # type: Text + value = ... # type: Text + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapStringStringEntry: ... + + class MapStringBytesEntry(Message): + key = ... # type: Text + value = ... # type: bytes + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapStringBytesEntry: ... + + class MapStringNestedMessageEntry(Message): + key = ... # type: Text + + @property + def value(self) -> TestAllTypesProto2.NestedMessage: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestAllTypesProto2.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapStringNestedMessageEntry: ... + + class MapStringForeignMessageEntry(Message): + key = ... # type: Text + + @property + def value(self) -> ForeignMessageProto2: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[ForeignMessageProto2] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapStringForeignMessageEntry: ... + + class MapStringNestedEnumEntry(Message): + key = ... # type: Text + value = ... # type: TestAllTypesProto2.NestedEnum + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestAllTypesProto2.NestedEnum] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapStringNestedEnumEntry: ... + + class MapStringForeignEnumEntry(Message): + key = ... # type: Text + value = ... # type: ForeignEnumProto2 + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[ForeignEnumProto2] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MapStringForeignEnumEntry: ... + + class Data(Message): + group_int32 = ... # type: int + group_uint32 = ... # type: int + + def __init__(self, + group_int32: Optional[int] = ..., + group_uint32: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto2.Data: ... + + class MessageSetCorrect(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MessageSetCorrect: ... + + class MessageSetCorrectExtension1(Message): + bytes = ... # type: Text + + def __init__(self, + bytes: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: builtins.bytes) -> TestAllTypesProto2.MessageSetCorrectExtension1: ... + + class MessageSetCorrectExtension2(Message): + i = ... # type: int + + def __init__(self, + i: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestAllTypesProto2.MessageSetCorrectExtension2: ... + optional_int32 = ... # type: int + optional_int64 = ... # type: int + optional_uint32 = ... # type: int + optional_uint64 = ... # type: int + optional_sint32 = ... # type: int + optional_sint64 = ... # type: int + optional_fixed32 = ... # type: int + optional_fixed64 = ... # type: int + optional_sfixed32 = ... # type: int + optional_sfixed64 = ... # type: int + optional_float = ... # type: float + optional_double = ... # type: float + optional_bool = ... # type: bool + optional_string = ... # type: Text + optional_bytes = ... # type: bytes + optional_nested_enum = ... # type: TestAllTypesProto2.NestedEnum + optional_foreign_enum = ... # type: ForeignEnumProto2 + optional_string_piece = ... # type: Text + optional_cord = ... # type: Text + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_double = ... # type: RepeatedScalarFieldContainer[float] + repeated_bool = ... # type: RepeatedScalarFieldContainer[bool] + repeated_string = ... # type: RepeatedScalarFieldContainer[Text] + repeated_bytes = ... # type: RepeatedScalarFieldContainer[bytes] + repeated_nested_enum = ... # type: RepeatedScalarFieldContainer[TestAllTypesProto2.NestedEnum] + repeated_foreign_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnumProto2] + repeated_string_piece = ... # type: RepeatedScalarFieldContainer[Text] + repeated_cord = ... # type: RepeatedScalarFieldContainer[Text] + oneof_uint32 = ... # type: int + oneof_string = ... # type: Text + oneof_bytes = ... # type: bytes + oneof_bool = ... # type: bool + oneof_uint64 = ... # type: int + oneof_float = ... # type: float + oneof_double = ... # type: float + oneof_enum = ... # type: TestAllTypesProto2.NestedEnum + fieldname1 = ... # type: int + field_name2 = ... # type: int + _field_name3 = ... # type: int + field__name4_ = ... # type: int + field0name5 = ... # type: int + field_0_name6 = ... # type: int + fieldName7 = ... # type: int + FieldName8 = ... # type: int + field_Name9 = ... # type: int + Field_Name10 = ... # type: int + FIELD_NAME11 = ... # type: int + FIELD_name12 = ... # type: int + __field_name13 = ... # type: int + __Field_name14 = ... # type: int + field__name15 = ... # type: int + field__Name16 = ... # type: int + field_name17__ = ... # type: int + Field_name18__ = ... # type: int + + @property + def optional_nested_message(self) -> TestAllTypesProto2.NestedMessage: ... + + @property + def optional_foreign_message(self) -> ForeignMessageProto2: ... + + @property + def recursive_message(self) -> TestAllTypesProto2: ... + + @property + def repeated_nested_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypesProto2.NestedMessage]: ... + + @property + def repeated_foreign_message( + self) -> RepeatedCompositeFieldContainer[ForeignMessageProto2]: ... + + @property + def map_int32_int32(self) -> MutableMapping[int, int]: ... + + @property + def map_int64_int64(self) -> MutableMapping[int, int]: ... + + @property + def map_uint32_uint32(self) -> MutableMapping[int, int]: ... + + @property + def map_uint64_uint64(self) -> MutableMapping[int, int]: ... + + @property + def map_sint32_sint32(self) -> MutableMapping[int, int]: ... + + @property + def map_sint64_sint64(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed32_fixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed64_fixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed32_sfixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed64_sfixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_int32_float(self) -> MutableMapping[int, float]: ... + + @property + def map_int32_double(self) -> MutableMapping[int, float]: ... + + @property + def map_bool_bool(self) -> MutableMapping[bool, bool]: ... + + @property + def map_string_string(self) -> MutableMapping[Text, Text]: ... + + @property + def map_string_bytes(self) -> MutableMapping[Text, bytes]: ... + + @property + def map_string_nested_message( + self) -> MutableMapping[Text, TestAllTypesProto2.NestedMessage]: ... + + @property + def map_string_foreign_message( + self) -> MutableMapping[Text, ForeignMessageProto2]: ... + + @property + def map_string_nested_enum( + self) -> MutableMapping[Text, TestAllTypesProto2.NestedEnum]: ... + + @property + def map_string_foreign_enum( + self) -> MutableMapping[Text, ForeignEnumProto2]: ... + + @property + def oneof_nested_message(self) -> TestAllTypesProto2.NestedMessage: ... + + @property + def data(self) -> TestAllTypesProto2.Data: ... + + def __init__(self, + optional_int32: Optional[int] = ..., + optional_int64: Optional[int] = ..., + optional_uint32: Optional[int] = ..., + optional_uint64: Optional[int] = ..., + optional_sint32: Optional[int] = ..., + optional_sint64: Optional[int] = ..., + optional_fixed32: Optional[int] = ..., + optional_fixed64: Optional[int] = ..., + optional_sfixed32: Optional[int] = ..., + optional_sfixed64: Optional[int] = ..., + optional_float: Optional[float] = ..., + optional_double: Optional[float] = ..., + optional_bool: Optional[bool] = ..., + optional_string: Optional[Text] = ..., + optional_bytes: Optional[bytes] = ..., + optional_nested_message: Optional[TestAllTypesProto2.NestedMessage] = ..., + optional_foreign_message: Optional[ForeignMessageProto2] = ..., + optional_nested_enum: Optional[TestAllTypesProto2.NestedEnum] = ..., + optional_foreign_enum: Optional[ForeignEnumProto2] = ..., + optional_string_piece: Optional[Text] = ..., + optional_cord: Optional[Text] = ..., + recursive_message: Optional[TestAllTypesProto2] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_uint32: Optional[Iterable[int]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + repeated_sint32: Optional[Iterable[int]] = ..., + repeated_sint64: Optional[Iterable[int]] = ..., + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_sfixed32: Optional[Iterable[int]] = ..., + repeated_sfixed64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_double: Optional[Iterable[float]] = ..., + repeated_bool: Optional[Iterable[bool]] = ..., + repeated_string: Optional[Iterable[Text]] = ..., + repeated_bytes: Optional[Iterable[bytes]] = ..., + repeated_nested_message: Optional[Iterable[TestAllTypesProto2.NestedMessage]] = ..., + repeated_foreign_message: Optional[Iterable[ForeignMessageProto2]] = ..., + repeated_nested_enum: Optional[Iterable[TestAllTypesProto2.NestedEnum]] = ..., + repeated_foreign_enum: Optional[Iterable[ForeignEnumProto2]] = ..., + repeated_string_piece: Optional[Iterable[Text]] = ..., + repeated_cord: Optional[Iterable[Text]] = ..., + map_int32_int32: Optional[Mapping[int, int]]=..., + map_int64_int64: Optional[Mapping[int, int]]=..., + map_uint32_uint32: Optional[Mapping[int, int]]=..., + map_uint64_uint64: Optional[Mapping[int, int]]=..., + map_sint32_sint32: Optional[Mapping[int, int]]=..., + map_sint64_sint64: Optional[Mapping[int, int]]=..., + map_fixed32_fixed32: Optional[Mapping[int, int]]=..., + map_fixed64_fixed64: Optional[Mapping[int, int]]=..., + map_sfixed32_sfixed32: Optional[Mapping[int, int]]=..., + map_sfixed64_sfixed64: Optional[Mapping[int, int]]=..., + map_int32_float: Optional[Mapping[int, float]]=..., + map_int32_double: Optional[Mapping[int, float]]=..., + map_bool_bool: Optional[Mapping[bool, bool]]=..., + map_string_string: Optional[Mapping[Text, Text]]=..., + map_string_bytes: Optional[Mapping[Text, bytes]]=..., + map_string_nested_message: Optional[Mapping[Text, TestAllTypesProto2.NestedMessage]]=..., + map_string_foreign_message: Optional[Mapping[Text, ForeignMessageProto2]]=..., + map_string_nested_enum: Optional[Mapping[Text, TestAllTypesProto2.NestedEnum]]=..., + map_string_foreign_enum: Optional[Mapping[Text, ForeignEnumProto2]]=..., + oneof_uint32: Optional[int] = ..., + oneof_nested_message: Optional[TestAllTypesProto2.NestedMessage] = ..., + oneof_string: Optional[Text] = ..., + oneof_bytes: Optional[bytes] = ..., + oneof_bool: Optional[bool] = ..., + oneof_uint64: Optional[int] = ..., + oneof_float: Optional[float] = ..., + oneof_double: Optional[float] = ..., + oneof_enum: Optional[TestAllTypesProto2.NestedEnum] = ..., + data: Optional[TestAllTypesProto2.Data] = ..., + fieldname1: Optional[int] = ..., + field_name2: Optional[int] = ..., + _field_name3: Optional[int] = ..., + field__name4_: Optional[int] = ..., + field0name5: Optional[int] = ..., + field_0_name6: Optional[int] = ..., + fieldName7: Optional[int] = ..., + FieldName8: Optional[int] = ..., + field_Name9: Optional[int] = ..., + Field_Name10: Optional[int] = ..., + FIELD_NAME11: Optional[int] = ..., + FIELD_name12: Optional[int] = ..., + __field_name13: Optional[int] = ..., + __Field_name14: Optional[int] = ..., + field__name15: Optional[int] = ..., + field__Name16: Optional[int] = ..., + field_name17__: Optional[int] = ..., + Field_name18__: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto2: ... + + +class ForeignMessageProto2(Message): + c = ... # type: int + + def __init__(self, + c: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ForeignMessageProto2: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/test_messages_proto3_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/test_messages_proto3_pb2.pyi new file mode 100644 index 000000000..2389a2c38 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/test_messages_proto3_pb2.pyi @@ -0,0 +1,700 @@ +from google.protobuf.any_pb2 import ( + Any, +) +from google.protobuf.duration_pb2 import ( + Duration, +) +from google.protobuf.field_mask_pb2 import ( + FieldMask, +) +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.struct_pb2 import ( + Struct, + Value, +) +from google.protobuf.timestamp_pb2 import ( + Timestamp, +) +from google.protobuf.wrappers_pb2 import ( + BoolValue, + BytesValue, + DoubleValue, + FloatValue, + Int32Value, + Int64Value, + StringValue, + UInt32Value, + UInt64Value, +) +from typing import ( + Iterable, + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class ForeignEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ForeignEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ForeignEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ForeignEnum]]: ... +FOREIGN_FOO: ForeignEnum +FOREIGN_BAR: ForeignEnum +FOREIGN_BAZ: ForeignEnum + + +class TestAllTypesProto3(Message): + + class NestedEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestAllTypesProto3.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestAllTypesProto3.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestAllTypesProto3.NestedEnum]]: ... + FOO: NestedEnum + BAR: NestedEnum + BAZ: NestedEnum + NEG: NestedEnum + + class NestedMessage(Message): + a = ... # type: int + + @property + def corecursive(self) -> TestAllTypesProto3: ... + + def __init__(self, + a: Optional[int] = ..., + corecursive: Optional[TestAllTypesProto3] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.NestedMessage: ... + + class MapInt32Int32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapInt32Int32Entry: ... + + class MapInt64Int64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapInt64Int64Entry: ... + + class MapUint32Uint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapUint32Uint32Entry: ... + + class MapUint64Uint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapUint64Uint64Entry: ... + + class MapSint32Sint32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapSint32Sint32Entry: ... + + class MapSint64Sint64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapSint64Sint64Entry: ... + + class MapFixed32Fixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapFixed32Fixed32Entry: ... + + class MapFixed64Fixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapFixed64Fixed64Entry: ... + + class MapSfixed32Sfixed32Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapSfixed32Sfixed32Entry: ... + + class MapSfixed64Sfixed64Entry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapSfixed64Sfixed64Entry: ... + + class MapInt32FloatEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapInt32FloatEntry: ... + + class MapInt32DoubleEntry(Message): + key = ... # type: int + value = ... # type: float + + def __init__(self, + key: Optional[int] = ..., + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapInt32DoubleEntry: ... + + class MapBoolBoolEntry(Message): + key = ... # type: bool + value = ... # type: bool + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapBoolBoolEntry: ... + + class MapStringStringEntry(Message): + key = ... # type: Text + value = ... # type: Text + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapStringStringEntry: ... + + class MapStringBytesEntry(Message): + key = ... # type: Text + value = ... # type: bytes + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapStringBytesEntry: ... + + class MapStringNestedMessageEntry(Message): + key = ... # type: Text + + @property + def value(self) -> TestAllTypesProto3.NestedMessage: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestAllTypesProto3.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapStringNestedMessageEntry: ... + + class MapStringForeignMessageEntry(Message): + key = ... # type: Text + + @property + def value(self) -> ForeignMessage: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[ForeignMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapStringForeignMessageEntry: ... + + class MapStringNestedEnumEntry(Message): + key = ... # type: Text + value = ... # type: TestAllTypesProto3.NestedEnum + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestAllTypesProto3.NestedEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapStringNestedEnumEntry: ... + + class MapStringForeignEnumEntry(Message): + key = ... # type: Text + value = ... # type: ForeignEnum + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[ForeignEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3.MapStringForeignEnumEntry: ... + optional_int32 = ... # type: int + optional_int64 = ... # type: int + optional_uint32 = ... # type: int + optional_uint64 = ... # type: int + optional_sint32 = ... # type: int + optional_sint64 = ... # type: int + optional_fixed32 = ... # type: int + optional_fixed64 = ... # type: int + optional_sfixed32 = ... # type: int + optional_sfixed64 = ... # type: int + optional_float = ... # type: float + optional_double = ... # type: float + optional_bool = ... # type: bool + optional_string = ... # type: Text + optional_bytes = ... # type: bytes + optional_nested_enum = ... # type: TestAllTypesProto3.NestedEnum + optional_foreign_enum = ... # type: ForeignEnum + optional_string_piece = ... # type: Text + optional_cord = ... # type: Text + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_double = ... # type: RepeatedScalarFieldContainer[float] + repeated_bool = ... # type: RepeatedScalarFieldContainer[bool] + repeated_string = ... # type: RepeatedScalarFieldContainer[Text] + repeated_bytes = ... # type: RepeatedScalarFieldContainer[bytes] + repeated_nested_enum = ... # type: RepeatedScalarFieldContainer[TestAllTypesProto3.NestedEnum] + repeated_foreign_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + repeated_string_piece = ... # type: RepeatedScalarFieldContainer[Text] + repeated_cord = ... # type: RepeatedScalarFieldContainer[Text] + oneof_uint32 = ... # type: int + oneof_string = ... # type: Text + oneof_bytes = ... # type: bytes + oneof_bool = ... # type: bool + oneof_uint64 = ... # type: int + oneof_float = ... # type: float + oneof_double = ... # type: float + oneof_enum = ... # type: TestAllTypesProto3.NestedEnum + fieldname1 = ... # type: int + field_name2 = ... # type: int + _field_name3 = ... # type: int + field__name4_ = ... # type: int + field0name5 = ... # type: int + field_0_name6 = ... # type: int + fieldName7 = ... # type: int + FieldName8 = ... # type: int + field_Name9 = ... # type: int + Field_Name10 = ... # type: int + FIELD_NAME11 = ... # type: int + FIELD_name12 = ... # type: int + __field_name13 = ... # type: int + __Field_name14 = ... # type: int + field__name15 = ... # type: int + field__Name16 = ... # type: int + field_name17__ = ... # type: int + Field_name18__ = ... # type: int + + @property + def optional_nested_message(self) -> TestAllTypesProto3.NestedMessage: ... + + @property + def optional_foreign_message(self) -> ForeignMessage: ... + + @property + def recursive_message(self) -> TestAllTypesProto3: ... + + @property + def repeated_nested_message(self) -> RepeatedCompositeFieldContainer[TestAllTypesProto3.NestedMessage]: ... + + @property + def repeated_foreign_message(self) -> RepeatedCompositeFieldContainer[ForeignMessage]: ... + + @property + def map_int32_int32(self) -> MutableMapping[int, int]: ... + + @property + def map_int64_int64(self) -> MutableMapping[int, int]: ... + + @property + def map_uint32_uint32(self) -> MutableMapping[int, int]: ... + + @property + def map_uint64_uint64(self) -> MutableMapping[int, int]: ... + + @property + def map_sint32_sint32(self) -> MutableMapping[int, int]: ... + + @property + def map_sint64_sint64(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed32_fixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_fixed64_fixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed32_sfixed32(self) -> MutableMapping[int, int]: ... + + @property + def map_sfixed64_sfixed64(self) -> MutableMapping[int, int]: ... + + @property + def map_int32_float(self) -> MutableMapping[int, float]: ... + + @property + def map_int32_double(self) -> MutableMapping[int, float]: ... + + @property + def map_bool_bool(self) -> MutableMapping[bool, bool]: ... + + @property + def map_string_string(self) -> MutableMapping[Text, Text]: ... + + @property + def map_string_bytes(self) -> MutableMapping[Text, bytes]: ... + + @property + def map_string_nested_message(self) -> MutableMapping[Text, TestAllTypesProto3.NestedMessage]: ... + + @property + def map_string_foreign_message(self) -> MutableMapping[Text, ForeignMessage]: ... + + @property + def map_string_nested_enum(self) -> MutableMapping[Text, TestAllTypesProto3.NestedEnum]: ... + + @property + def map_string_foreign_enum(self) -> MutableMapping[Text, ForeignEnum]: ... + + @property + def oneof_nested_message(self) -> TestAllTypesProto3.NestedMessage: ... + + @property + def optional_bool_wrapper(self) -> BoolValue: ... + + @property + def optional_int32_wrapper(self) -> Int32Value: ... + + @property + def optional_int64_wrapper(self) -> Int64Value: ... + + @property + def optional_uint32_wrapper(self) -> UInt32Value: ... + + @property + def optional_uint64_wrapper(self) -> UInt64Value: ... + + @property + def optional_float_wrapper(self) -> FloatValue: ... + + @property + def optional_double_wrapper(self) -> DoubleValue: ... + + @property + def optional_string_wrapper(self) -> StringValue: ... + + @property + def optional_bytes_wrapper(self) -> BytesValue: ... + + @property + def repeated_bool_wrapper(self) -> RepeatedCompositeFieldContainer[BoolValue]: ... + + @property + def repeated_int32_wrapper(self) -> RepeatedCompositeFieldContainer[Int32Value]: ... + + @property + def repeated_int64_wrapper(self) -> RepeatedCompositeFieldContainer[Int64Value]: ... + + @property + def repeated_uint32_wrapper(self) -> RepeatedCompositeFieldContainer[UInt32Value]: ... + + @property + def repeated_uint64_wrapper(self) -> RepeatedCompositeFieldContainer[UInt64Value]: ... + + @property + def repeated_float_wrapper(self) -> RepeatedCompositeFieldContainer[FloatValue]: ... + + @property + def repeated_double_wrapper(self) -> RepeatedCompositeFieldContainer[DoubleValue]: ... + + @property + def repeated_string_wrapper(self) -> RepeatedCompositeFieldContainer[StringValue]: ... + + @property + def repeated_bytes_wrapper(self) -> RepeatedCompositeFieldContainer[BytesValue]: ... + + @property + def optional_duration(self) -> Duration: ... + + @property + def optional_timestamp(self) -> Timestamp: ... + + @property + def optional_field_mask(self) -> FieldMask: ... + + @property + def optional_struct(self) -> Struct: ... + + @property + def optional_any(self) -> Any: ... + + @property + def optional_value(self) -> Value: ... + + @property + def repeated_duration(self) -> RepeatedCompositeFieldContainer[Duration]: ... + + @property + def repeated_timestamp(self) -> RepeatedCompositeFieldContainer[Timestamp]: ... + + @property + def repeated_fieldmask(self) -> RepeatedCompositeFieldContainer[FieldMask]: ... + + @property + def repeated_struct(self) -> RepeatedCompositeFieldContainer[Struct]: ... + + @property + def repeated_any(self) -> RepeatedCompositeFieldContainer[Any]: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[Value]: ... + + def __init__(self, + optional_int32: Optional[int] = ..., + optional_int64: Optional[int] = ..., + optional_uint32: Optional[int] = ..., + optional_uint64: Optional[int] = ..., + optional_sint32: Optional[int] = ..., + optional_sint64: Optional[int] = ..., + optional_fixed32: Optional[int] = ..., + optional_fixed64: Optional[int] = ..., + optional_sfixed32: Optional[int] = ..., + optional_sfixed64: Optional[int] = ..., + optional_float: Optional[float] = ..., + optional_double: Optional[float] = ..., + optional_bool: Optional[bool] = ..., + optional_string: Optional[Text] = ..., + optional_bytes: Optional[bytes] = ..., + optional_nested_message: Optional[TestAllTypesProto3.NestedMessage] = ..., + optional_foreign_message: Optional[ForeignMessage] = ..., + optional_nested_enum: Optional[TestAllTypesProto3.NestedEnum] = ..., + optional_foreign_enum: Optional[ForeignEnum] = ..., + optional_string_piece: Optional[Text] = ..., + optional_cord: Optional[Text] = ..., + recursive_message: Optional[TestAllTypesProto3] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_uint32: Optional[Iterable[int]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + repeated_sint32: Optional[Iterable[int]] = ..., + repeated_sint64: Optional[Iterable[int]] = ..., + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_sfixed32: Optional[Iterable[int]] = ..., + repeated_sfixed64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_double: Optional[Iterable[float]] = ..., + repeated_bool: Optional[Iterable[bool]] = ..., + repeated_string: Optional[Iterable[Text]] = ..., + repeated_bytes: Optional[Iterable[bytes]] = ..., + repeated_nested_message: Optional[Iterable[TestAllTypesProto3.NestedMessage]] = ..., + repeated_foreign_message: Optional[Iterable[ForeignMessage]] = ..., + repeated_nested_enum: Optional[Iterable[TestAllTypesProto3.NestedEnum]] = ..., + repeated_foreign_enum: Optional[Iterable[ForeignEnum]] = ..., + repeated_string_piece: Optional[Iterable[Text]] = ..., + repeated_cord: Optional[Iterable[Text]] = ..., + map_int32_int32: Optional[Mapping[int, int]]=..., + map_int64_int64: Optional[Mapping[int, int]]=..., + map_uint32_uint32: Optional[Mapping[int, int]]=..., + map_uint64_uint64: Optional[Mapping[int, int]]=..., + map_sint32_sint32: Optional[Mapping[int, int]]=..., + map_sint64_sint64: Optional[Mapping[int, int]]=..., + map_fixed32_fixed32: Optional[Mapping[int, int]]=..., + map_fixed64_fixed64: Optional[Mapping[int, int]]=..., + map_sfixed32_sfixed32: Optional[Mapping[int, int]]=..., + map_sfixed64_sfixed64: Optional[Mapping[int, int]]=..., + map_int32_float: Optional[Mapping[int, float]]=..., + map_int32_double: Optional[Mapping[int, float]]=..., + map_bool_bool: Optional[Mapping[bool, bool]]=..., + map_string_string: Optional[Mapping[Text, Text]]=..., + map_string_bytes: Optional[Mapping[Text, bytes]]=..., + map_string_nested_message: Optional[Mapping[Text, TestAllTypesProto3.NestedMessage]]=..., + map_string_foreign_message: Optional[Mapping[Text, ForeignMessage]]=..., + map_string_nested_enum: Optional[Mapping[Text, TestAllTypesProto3.NestedEnum]]=..., + map_string_foreign_enum: Optional[Mapping[Text, ForeignEnum]]=..., + oneof_uint32: Optional[int] = ..., + oneof_nested_message: Optional[TestAllTypesProto3.NestedMessage] = ..., + oneof_string: Optional[Text] = ..., + oneof_bytes: Optional[bytes] = ..., + oneof_bool: Optional[bool] = ..., + oneof_uint64: Optional[int] = ..., + oneof_float: Optional[float] = ..., + oneof_double: Optional[float] = ..., + oneof_enum: Optional[TestAllTypesProto3.NestedEnum] = ..., + optional_bool_wrapper: Optional[BoolValue] = ..., + optional_int32_wrapper: Optional[Int32Value] = ..., + optional_int64_wrapper: Optional[Int64Value] = ..., + optional_uint32_wrapper: Optional[UInt32Value] = ..., + optional_uint64_wrapper: Optional[UInt64Value] = ..., + optional_float_wrapper: Optional[FloatValue] = ..., + optional_double_wrapper: Optional[DoubleValue] = ..., + optional_string_wrapper: Optional[StringValue] = ..., + optional_bytes_wrapper: Optional[BytesValue] = ..., + repeated_bool_wrapper: Optional[Iterable[BoolValue]] = ..., + repeated_int32_wrapper: Optional[Iterable[Int32Value]] = ..., + repeated_int64_wrapper: Optional[Iterable[Int64Value]] = ..., + repeated_uint32_wrapper: Optional[Iterable[UInt32Value]] = ..., + repeated_uint64_wrapper: Optional[Iterable[UInt64Value]] = ..., + repeated_float_wrapper: Optional[Iterable[FloatValue]] = ..., + repeated_double_wrapper: Optional[Iterable[DoubleValue]] = ..., + repeated_string_wrapper: Optional[Iterable[StringValue]] = ..., + repeated_bytes_wrapper: Optional[Iterable[BytesValue]] = ..., + optional_duration: Optional[Duration] = ..., + optional_timestamp: Optional[Timestamp] = ..., + optional_field_mask: Optional[FieldMask] = ..., + optional_struct: Optional[Struct] = ..., + optional_any: Optional[Any] = ..., + optional_value: Optional[Value] = ..., + repeated_duration: Optional[Iterable[Duration]] = ..., + repeated_timestamp: Optional[Iterable[Timestamp]] = ..., + repeated_fieldmask: Optional[Iterable[FieldMask]] = ..., + repeated_struct: Optional[Iterable[Struct]] = ..., + repeated_any: Optional[Iterable[Any]] = ..., + repeated_value: Optional[Iterable[Value]] = ..., + fieldname1: Optional[int] = ..., + field_name2: Optional[int] = ..., + _field_name3: Optional[int] = ..., + field__name4_: Optional[int] = ..., + field0name5: Optional[int] = ..., + field_0_name6: Optional[int] = ..., + fieldName7: Optional[int] = ..., + FieldName8: Optional[int] = ..., + field_Name9: Optional[int] = ..., + Field_Name10: Optional[int] = ..., + FIELD_NAME11: Optional[int] = ..., + FIELD_name12: Optional[int] = ..., + __field_name13: Optional[int] = ..., + __Field_name14: Optional[int] = ..., + field__name15: Optional[int] = ..., + field__Name16: Optional[int] = ..., + field_name17__: Optional[int] = ..., + Field_name18__: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypesProto3: ... + + +class ForeignMessage(Message): + c = ... # type: int + + def __init__(self, + c: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ForeignMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/timestamp_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/timestamp_pb2.pyi new file mode 100644 index 000000000..a037d0f84 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/timestamp_pb2.pyi @@ -0,0 +1,21 @@ +from google.protobuf.message import ( + Message, +) +from google.protobuf.internal import well_known_types + +from typing import ( + Optional, +) + + +class Timestamp(Message, well_known_types.Timestamp): + seconds = ... # type: int + nanos = ... # type: int + + def __init__(self, + seconds: Optional[int] = ..., + nanos: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Timestamp: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/type_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/type_pb2.pyi new file mode 100644 index 000000000..86e8dc0fe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/type_pb2.pyi @@ -0,0 +1,215 @@ +from google.protobuf.any_pb2 import ( + Any, +) +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.source_context_pb2 import ( + SourceContext, +) +from typing import ( + Iterable, + List, + Optional, + Text, + Tuple, + cast, +) + + +class Syntax(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> Syntax: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[Syntax]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, Syntax]]: ... + + +SYNTAX_PROTO2: Syntax +SYNTAX_PROTO3: Syntax + + +class Type(Message): + name = ... # type: Text + oneofs = ... # type: RepeatedScalarFieldContainer[Text] + syntax = ... # type: Syntax + + @property + def fields(self) -> RepeatedCompositeFieldContainer[Field]: ... + + @property + def options(self) -> RepeatedCompositeFieldContainer[Option]: ... + + @property + def source_context(self) -> SourceContext: ... + + def __init__(self, + name: Optional[Text] = ..., + fields: Optional[Iterable[Field]] = ..., + oneofs: Optional[Iterable[Text]] = ..., + options: Optional[Iterable[Option]] = ..., + source_context: Optional[SourceContext] = ..., + syntax: Optional[Syntax] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Type: ... + + +class Field(Message): + + class Kind(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> Field.Kind: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[Field.Kind]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, Field.Kind]]: ... + TYPE_UNKNOWN: Kind + TYPE_DOUBLE: Kind + TYPE_FLOAT: Kind + TYPE_INT64: Kind + TYPE_UINT64: Kind + TYPE_INT32: Kind + TYPE_FIXED64: Kind + TYPE_FIXED32: Kind + TYPE_BOOL: Kind + TYPE_STRING: Kind + TYPE_GROUP: Kind + TYPE_MESSAGE: Kind + TYPE_BYTES: Kind + TYPE_UINT32: Kind + TYPE_ENUM: Kind + TYPE_SFIXED32: Kind + TYPE_SFIXED64: Kind + TYPE_SINT32: Kind + TYPE_SINT64: Kind + + class Cardinality(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> Field.Cardinality: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[Field.Cardinality]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, Field.Cardinality]]: ... + CARDINALITY_UNKNOWN: Cardinality + CARDINALITY_OPTIONAL: Cardinality + CARDINALITY_REQUIRED: Cardinality + CARDINALITY_REPEATED: Cardinality + kind = ... # type: Field.Kind + cardinality = ... # type: Field.Cardinality + number = ... # type: int + name = ... # type: Text + type_url = ... # type: Text + oneof_index = ... # type: int + packed = ... # type: bool + json_name = ... # type: Text + default_value = ... # type: Text + + @property + def options(self) -> RepeatedCompositeFieldContainer[Option]: ... + + def __init__(self, + kind: Optional[Field.Kind] = ..., + cardinality: Optional[Field.Cardinality] = ..., + number: Optional[int] = ..., + name: Optional[Text] = ..., + type_url: Optional[Text] = ..., + oneof_index: Optional[int] = ..., + packed: Optional[bool] = ..., + options: Optional[Iterable[Option]] = ..., + json_name: Optional[Text] = ..., + default_value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Field: ... + + +class Enum(Message): + name = ... # type: Text + syntax = ... # type: Syntax + + @property + def enumvalue(self) -> RepeatedCompositeFieldContainer[EnumValue]: ... + + @property + def options(self) -> RepeatedCompositeFieldContainer[Option]: ... + + @property + def source_context(self) -> SourceContext: ... + + def __init__(self, + name: Optional[Text] = ..., + enumvalue: Optional[Iterable[EnumValue]] = ..., + options: Optional[Iterable[Option]] = ..., + source_context: Optional[SourceContext] = ..., + syntax: Optional[Syntax] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Enum: ... + + +class EnumValue(Message): + name = ... # type: Text + number = ... # type: int + + @property + def options(self) -> RepeatedCompositeFieldContainer[Option]: ... + + def __init__(self, + name: Optional[Text] = ..., + number: Optional[int] = ..., + options: Optional[Iterable[Option]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> EnumValue: ... + + +class Option(Message): + name = ... # type: Text + + @property + def value(self) -> Any: ... + + def __init__(self, + name: Optional[Text] = ..., + value: Optional[Any] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Option: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_arena_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_arena_pb2.pyi new file mode 100644 index 000000000..ba6a31703 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_arena_pb2.pyi @@ -0,0 +1,43 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_no_arena_import_pb2 import ( + ImportNoArenaNestedMessage, +) +from typing import ( + Iterable, + Optional, +) + + +class NestedMessage(Message): + d = ... # type: int + + def __init__(self, + d: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> NestedMessage: ... + + +class ArenaMessage(Message): + + @property + def repeated_nested_message( + self) -> RepeatedCompositeFieldContainer[NestedMessage]: ... + + @property + def repeated_import_no_arena_message( + self) -> RepeatedCompositeFieldContainer[ImportNoArenaNestedMessage]: ... + + def __init__(self, + repeated_nested_message: Optional[Iterable[NestedMessage]] = ..., + repeated_import_no_arena_message: Optional[Iterable[ImportNoArenaNestedMessage]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ArenaMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_custom_options_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_custom_options_pb2.pyi new file mode 100644 index 000000000..25c779fe4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_custom_options_pb2.pyi @@ -0,0 +1,472 @@ +from google.protobuf.descriptor_pb2 import ( + FileOptions, +) +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from typing import ( + Iterable, + List, + Optional, + Text, + Tuple, + cast, +) + + +class MethodOpt1(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> MethodOpt1: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[MethodOpt1]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, MethodOpt1]]: ... + + +METHODOPT1_VAL1: MethodOpt1 +METHODOPT1_VAL2: MethodOpt1 + + +class AggregateEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> AggregateEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[AggregateEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, AggregateEnum]]: ... + + +VALUE: AggregateEnum + + +class TestMessageWithCustomOptions(Message): + + class AnEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestMessageWithCustomOptions.AnEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestMessageWithCustomOptions.AnEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, + TestMessageWithCustomOptions.AnEnum]]: ... + ANENUM_VAL1: AnEnum + ANENUM_VAL2: AnEnum + field1 = ... # type: Text + oneof_field = ... # type: int + + def __init__(self, + field1: Optional[Text] = ..., + oneof_field: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageWithCustomOptions: ... + + +class CustomOptionFooRequest(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionFooRequest: ... + + +class CustomOptionFooResponse(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionFooResponse: ... + + +class CustomOptionFooClientMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionFooClientMessage: ... + + +class CustomOptionFooServerMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionFooServerMessage: ... + + +class DummyMessageContainingEnum(Message): + + class TestEnumType(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> DummyMessageContainingEnum.TestEnumType: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[DummyMessageContainingEnum.TestEnumType]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, + DummyMessageContainingEnum.TestEnumType]]: ... + TEST_OPTION_ENUM_TYPE1: TestEnumType + TEST_OPTION_ENUM_TYPE2: TestEnumType + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> DummyMessageContainingEnum: ... + + +class DummyMessageInvalidAsOptionType(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> DummyMessageInvalidAsOptionType: ... + + +class CustomOptionMinIntegerValues(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionMinIntegerValues: ... + + +class CustomOptionMaxIntegerValues(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionMaxIntegerValues: ... + + +class CustomOptionOtherValues(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> CustomOptionOtherValues: ... + + +class SettingRealsFromPositiveInts(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> SettingRealsFromPositiveInts: ... + + +class SettingRealsFromNegativeInts(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> SettingRealsFromNegativeInts: ... + + +class ComplexOptionType1(Message): + foo = ... # type: int + foo2 = ... # type: int + foo3 = ... # type: int + foo4 = ... # type: RepeatedScalarFieldContainer[int] + + def __init__(self, + foo: Optional[int] = ..., + foo2: Optional[int] = ..., + foo3: Optional[int] = ..., + foo4: Optional[Iterable[int]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ComplexOptionType1: ... + + +class ComplexOptionType2(Message): + + class ComplexOptionType4(Message): + waldo = ... # type: int + + def __init__(self, + waldo: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> ComplexOptionType2.ComplexOptionType4: ... + baz = ... # type: int + + @property + def bar(self) -> ComplexOptionType1: ... + + @property + def fred(self) -> ComplexOptionType2.ComplexOptionType4: ... + + @property + def barney( + self) -> RepeatedCompositeFieldContainer[ComplexOptionType2.ComplexOptionType4]: ... + + def __init__(self, + bar: Optional[ComplexOptionType1] = ..., + baz: Optional[int] = ..., + fred: Optional[ComplexOptionType2.ComplexOptionType4] = ..., + barney: Optional[Iterable[ComplexOptionType2.ComplexOptionType4]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ComplexOptionType2: ... + + +class ComplexOptionType3(Message): + + class ComplexOptionType5(Message): + plugh = ... # type: int + + def __init__(self, + plugh: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> ComplexOptionType3.ComplexOptionType5: ... + qux = ... # type: int + + @property + def complexoptiontype5(self) -> ComplexOptionType3.ComplexOptionType5: ... + + def __init__(self, + qux: Optional[int] = ..., + complexoptiontype5: Optional[ComplexOptionType3.ComplexOptionType5] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ComplexOptionType3: ... + + +class ComplexOpt6(Message): + xyzzy = ... # type: int + + def __init__(self, + xyzzy: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ComplexOpt6: ... + + +class VariousComplexOptions(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> VariousComplexOptions: ... + + +class AggregateMessageSet(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> AggregateMessageSet: ... + + +class AggregateMessageSetElement(Message): + s = ... # type: Text + + def __init__(self, + s: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> AggregateMessageSetElement: ... + + +class Aggregate(Message): + i = ... # type: int + s = ... # type: Text + + @property + def sub(self) -> Aggregate: ... + + @property + def file(self) -> FileOptions: ... + + @property + def mset(self) -> AggregateMessageSet: ... + + def __init__(self, + i: Optional[int] = ..., + s: Optional[Text] = ..., + sub: Optional[Aggregate] = ..., + file: Optional[FileOptions] = ..., + mset: Optional[AggregateMessageSet] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Aggregate: ... + + +class AggregateMessage(Message): + fieldname = ... # type: int + + def __init__(self, + fieldname: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> AggregateMessage: ... + + +class NestedOptionType(Message): + + class NestedEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> NestedOptionType.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[NestedOptionType.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, NestedOptionType.NestedEnum]]: ... + NESTED_ENUM_VALUE: NestedEnum + + class NestedMessage(Message): + nested_field = ... # type: int + + def __init__(self, + nested_field: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> NestedOptionType.NestedMessage: ... + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> NestedOptionType: ... + + +class OldOptionType(Message): + + class TestEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> OldOptionType.TestEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[OldOptionType.TestEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, OldOptionType.TestEnum]]: ... + OLD_VALUE: TestEnum + value = ... # type: OldOptionType.TestEnum + + def __init__(self, + value: OldOptionType.TestEnum, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> OldOptionType: ... + + +class NewOptionType(Message): + + class TestEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> NewOptionType.TestEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[NewOptionType.TestEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, NewOptionType.TestEnum]]: ... + OLD_VALUE: TestEnum + NEW_VALUE: TestEnum + value = ... # type: NewOptionType.TestEnum + + def __init__(self, + value: NewOptionType.TestEnum, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> NewOptionType: ... + + +class TestMessageWithRequiredEnumOption(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageWithRequiredEnumOption: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_import_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_import_pb2.pyi new file mode 100644 index 000000000..cc5e71047 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_import_pb2.pyi @@ -0,0 +1,66 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + List, + Optional, + Tuple, + cast, +) + + +class ImportEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ImportEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ImportEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ImportEnum]]: ... + + +IMPORT_FOO: ImportEnum +IMPORT_BAR: ImportEnum +IMPORT_BAZ: ImportEnum + + +class ImportEnumForMap(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ImportEnumForMap: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ImportEnumForMap]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ImportEnumForMap]]: ... + + +UNKNOWN: ImportEnumForMap +FOO: ImportEnumForMap +BAR: ImportEnumForMap + + +class ImportMessage(Message): + d = ... # type: int + + def __init__(self, + d: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ImportMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_import_public_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_import_public_pb2.pyi new file mode 100644 index 000000000..2ea64454d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_import_public_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + Optional, +) + + +class PublicImportMessage(Message): + e = ... # type: int + + def __init__(self, + e: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> PublicImportMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_mset_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_mset_pb2.pyi new file mode 100644 index 000000000..9ca738e56 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_mset_pb2.pyi @@ -0,0 +1,75 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_mset_wire_format_pb2 import ( + TestMessageSet, +) +import builtins +from typing import ( + Iterable, + Optional, + Text, +) + + +class TestMessageSetContainer(Message): + + @property + def message_set(self) -> TestMessageSet: ... + + def __init__(self, + message_set: Optional[TestMessageSet] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageSetContainer: ... + + +class TestMessageSetExtension1(Message): + i = ... # type: int + + def __init__(self, + i: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageSetExtension1: ... + + +class TestMessageSetExtension2(Message): + str = ... # type: Text + + def __init__(self, + bytes: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: builtins.bytes) -> TestMessageSetExtension2: ... + + +class RawMessageSet(Message): + + class Item(Message): + type_id = ... # type: int + message = ... # type: bytes + + def __init__(self, + type_id: int, + message: bytes, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> RawMessageSet.Item: ... + + @property + def item(self) -> RepeatedCompositeFieldContainer[RawMessageSet.Item]: ... + + def __init__(self, + item: Optional[Iterable[RawMessageSet.Item]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> RawMessageSet: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_mset_wire_format_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_mset_wire_format_pb2.pyi new file mode 100644 index 000000000..acb24a46f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_mset_wire_format_pb2.pyi @@ -0,0 +1,28 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + Optional, +) + + +class TestMessageSet(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageSet: ... + + +class TestMessageSetWireFormatContainer(Message): + + @property + def message_set(self) -> TestMessageSet: ... + + def __init__(self, + message_set: Optional[TestMessageSet] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessageSetWireFormatContainer: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_arena_import_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_arena_import_pb2.pyi new file mode 100644 index 000000000..bbe40511a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_arena_import_pb2.pyi @@ -0,0 +1,17 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + Optional, +) + + +class ImportNoArenaNestedMessage(Message): + d = ... # type: int + + def __init__(self, + d: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ImportNoArenaNestedMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_arena_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_arena_pb2.pyi new file mode 100644 index 000000000..bae53f08d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_arena_pb2.pyi @@ -0,0 +1,315 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_arena_pb2 import ( + ArenaMessage, +) +from google.protobuf.unittest_import_pb2 import ( + ImportEnum, + ImportMessage, +) +from google.protobuf.unittest_import_public_pb2 import ( + PublicImportMessage, +) +from typing import ( + Iterable, + List, + Optional, + Text, + Tuple, + cast, +) + + +class ForeignEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ForeignEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ForeignEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ForeignEnum]]: ... + + +FOREIGN_FOO: ForeignEnum +FOREIGN_BAR: ForeignEnum +FOREIGN_BAZ: ForeignEnum + + +class TestAllTypes(Message): + + class NestedEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestAllTypes.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestAllTypes.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestAllTypes.NestedEnum]]: ... + FOO: NestedEnum + BAR: NestedEnum + BAZ: NestedEnum + NEG: NestedEnum + + class NestedMessage(Message): + bb = ... # type: int + + def __init__(self, + bb: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.NestedMessage: ... + + class OptionalGroup(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.OptionalGroup: ... + + class RepeatedGroup(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.RepeatedGroup: ... + optional_int32 = ... # type: int + optional_int64 = ... # type: int + optional_uint32 = ... # type: int + optional_uint64 = ... # type: int + optional_sint32 = ... # type: int + optional_sint64 = ... # type: int + optional_fixed32 = ... # type: int + optional_fixed64 = ... # type: int + optional_sfixed32 = ... # type: int + optional_sfixed64 = ... # type: int + optional_float = ... # type: float + optional_double = ... # type: float + optional_bool = ... # type: bool + optional_string = ... # type: Text + optional_bytes = ... # type: bytes + optional_nested_enum = ... # type: TestAllTypes.NestedEnum + optional_foreign_enum = ... # type: ForeignEnum + optional_import_enum = ... # type: ImportEnum + optional_string_piece = ... # type: Text + optional_cord = ... # type: Text + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_double = ... # type: RepeatedScalarFieldContainer[float] + repeated_bool = ... # type: RepeatedScalarFieldContainer[bool] + repeated_string = ... # type: RepeatedScalarFieldContainer[Text] + repeated_bytes = ... # type: RepeatedScalarFieldContainer[bytes] + repeated_nested_enum = ... # type: RepeatedScalarFieldContainer[TestAllTypes.NestedEnum] + repeated_foreign_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + repeated_import_enum = ... # type: RepeatedScalarFieldContainer[ImportEnum] + repeated_string_piece = ... # type: RepeatedScalarFieldContainer[Text] + repeated_cord = ... # type: RepeatedScalarFieldContainer[Text] + default_int32 = ... # type: int + default_int64 = ... # type: int + default_uint32 = ... # type: int + default_uint64 = ... # type: int + default_sint32 = ... # type: int + default_sint64 = ... # type: int + default_fixed32 = ... # type: int + default_fixed64 = ... # type: int + default_sfixed32 = ... # type: int + default_sfixed64 = ... # type: int + default_float = ... # type: float + default_double = ... # type: float + default_bool = ... # type: bool + default_string = ... # type: Text + default_bytes = ... # type: bytes + default_nested_enum = ... # type: TestAllTypes.NestedEnum + default_foreign_enum = ... # type: ForeignEnum + default_import_enum = ... # type: ImportEnum + default_string_piece = ... # type: Text + default_cord = ... # type: Text + oneof_uint32 = ... # type: int + oneof_string = ... # type: Text + oneof_bytes = ... # type: bytes + + @property + def optionalgroup(self) -> TestAllTypes.OptionalGroup: ... + + @property + def optional_nested_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def optional_foreign_message(self) -> ForeignMessage: ... + + @property + def optional_import_message(self) -> ImportMessage: ... + + @property + def optional_public_import_message(self) -> PublicImportMessage: ... + + @property + def optional_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def repeatedgroup( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.RepeatedGroup]: ... + + @property + def repeated_nested_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.NestedMessage]: ... + + @property + def repeated_foreign_message( + self) -> RepeatedCompositeFieldContainer[ForeignMessage]: ... + + @property + def repeated_import_message( + self) -> RepeatedCompositeFieldContainer[ImportMessage]: ... + + @property + def repeated_lazy_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.NestedMessage]: ... + + @property + def oneof_nested_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def lazy_oneof_nested_message(self) -> TestAllTypes.NestedMessage: ... + + def __init__(self, + optional_int32: Optional[int] = ..., + optional_int64: Optional[int] = ..., + optional_uint32: Optional[int] = ..., + optional_uint64: Optional[int] = ..., + optional_sint32: Optional[int] = ..., + optional_sint64: Optional[int] = ..., + optional_fixed32: Optional[int] = ..., + optional_fixed64: Optional[int] = ..., + optional_sfixed32: Optional[int] = ..., + optional_sfixed64: Optional[int] = ..., + optional_float: Optional[float] = ..., + optional_double: Optional[float] = ..., + optional_bool: Optional[bool] = ..., + optional_string: Optional[Text] = ..., + optional_bytes: Optional[bytes] = ..., + optionalgroup: Optional[TestAllTypes.OptionalGroup] = ..., + optional_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + optional_foreign_message: Optional[ForeignMessage] = ..., + optional_import_message: Optional[ImportMessage] = ..., + optional_nested_enum: Optional[TestAllTypes.NestedEnum] = ..., + optional_foreign_enum: Optional[ForeignEnum] = ..., + optional_import_enum: Optional[ImportEnum] = ..., + optional_string_piece: Optional[Text] = ..., + optional_cord: Optional[Text] = ..., + optional_public_import_message: Optional[PublicImportMessage] = ..., + optional_message: Optional[TestAllTypes.NestedMessage] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_uint32: Optional[Iterable[int]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + repeated_sint32: Optional[Iterable[int]] = ..., + repeated_sint64: Optional[Iterable[int]] = ..., + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_sfixed32: Optional[Iterable[int]] = ..., + repeated_sfixed64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_double: Optional[Iterable[float]] = ..., + repeated_bool: Optional[Iterable[bool]] = ..., + repeated_string: Optional[Iterable[Text]] = ..., + repeated_bytes: Optional[Iterable[bytes]] = ..., + repeatedgroup: Optional[Iterable[TestAllTypes.RepeatedGroup]] = ..., + repeated_nested_message: Optional[Iterable[TestAllTypes.NestedMessage]] = ..., + repeated_foreign_message: Optional[Iterable[ForeignMessage]] = ..., + repeated_import_message: Optional[Iterable[ImportMessage]] = ..., + repeated_nested_enum: Optional[Iterable[TestAllTypes.NestedEnum]] = ..., + repeated_foreign_enum: Optional[Iterable[ForeignEnum]] = ..., + repeated_import_enum: Optional[Iterable[ImportEnum]] = ..., + repeated_string_piece: Optional[Iterable[Text]] = ..., + repeated_cord: Optional[Iterable[Text]] = ..., + repeated_lazy_message: Optional[Iterable[TestAllTypes.NestedMessage]] = ..., + default_int32: Optional[int] = ..., + default_int64: Optional[int] = ..., + default_uint32: Optional[int] = ..., + default_uint64: Optional[int] = ..., + default_sint32: Optional[int] = ..., + default_sint64: Optional[int] = ..., + default_fixed32: Optional[int] = ..., + default_fixed64: Optional[int] = ..., + default_sfixed32: Optional[int] = ..., + default_sfixed64: Optional[int] = ..., + default_float: Optional[float] = ..., + default_double: Optional[float] = ..., + default_bool: Optional[bool] = ..., + default_string: Optional[Text] = ..., + default_bytes: Optional[bytes] = ..., + default_nested_enum: Optional[TestAllTypes.NestedEnum] = ..., + default_foreign_enum: Optional[ForeignEnum] = ..., + default_import_enum: Optional[ImportEnum] = ..., + default_string_piece: Optional[Text] = ..., + default_cord: Optional[Text] = ..., + oneof_uint32: Optional[int] = ..., + oneof_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + oneof_string: Optional[Text] = ..., + oneof_bytes: Optional[bytes] = ..., + lazy_oneof_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes: ... + + +class ForeignMessage(Message): + c = ... # type: int + + def __init__(self, + c: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ForeignMessage: ... + + +class TestNoArenaMessage(Message): + + @property + def arena_message(self) -> ArenaMessage: ... + + def __init__(self, + arena_message: Optional[ArenaMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNoArenaMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_generic_services_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_generic_services_pb2.pyi new file mode 100644 index 000000000..02ac3be06 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_no_generic_services_pb2.pyi @@ -0,0 +1,40 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + List, + Optional, + Tuple, + cast, +) + + +class TestEnum(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestEnum]]: ... + + +FOO: TestEnum + + +class TestMessage(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_pb2.pyi new file mode 100644 index 000000000..73792b46d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_pb2.pyi @@ -0,0 +1,1777 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_import_pb2 import ( + ImportEnum, + ImportMessage, +) +from google.protobuf.unittest_import_public_pb2 import ( + PublicImportMessage, +) +from typing import ( + Iterable, + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class ForeignEnum(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ForeignEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ForeignEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ForeignEnum]]: ... + + +FOREIGN_FOO: ForeignEnum +FOREIGN_BAR: ForeignEnum +FOREIGN_BAZ: ForeignEnum + + +class TestEnumWithDupValue(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestEnumWithDupValue: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestEnumWithDupValue]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestEnumWithDupValue]]: ... + + +FOO1: TestEnumWithDupValue +BAR1: TestEnumWithDupValue +BAZ: TestEnumWithDupValue +FOO2: TestEnumWithDupValue +BAR2: TestEnumWithDupValue + + +class TestSparseEnum(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestSparseEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestSparseEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestSparseEnum]]: ... + + +SPARSE_A: TestSparseEnum +SPARSE_B: TestSparseEnum +SPARSE_C: TestSparseEnum +SPARSE_D: TestSparseEnum +SPARSE_E: TestSparseEnum +SPARSE_F: TestSparseEnum +SPARSE_G: TestSparseEnum + + +class TestAllTypes(Message): + class NestedEnum(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestAllTypes.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestAllTypes.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestAllTypes.NestedEnum]]: ... + FOO: NestedEnum + BAR: NestedEnum + BAZ: NestedEnum + NEG: NestedEnum + + class NestedMessage(Message): + bb = ... # type: int + + def __init__(self, + bb: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.NestedMessage: ... + + class OptionalGroup(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.OptionalGroup: ... + + class RepeatedGroup(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.RepeatedGroup: ... + optional_int32 = ... # type: int + optional_int64 = ... # type: int + optional_uint32 = ... # type: int + optional_uint64 = ... # type: int + optional_sint32 = ... # type: int + optional_sint64 = ... # type: int + optional_fixed32 = ... # type: int + optional_fixed64 = ... # type: int + optional_sfixed32 = ... # type: int + optional_sfixed64 = ... # type: int + optional_float = ... # type: float + optional_double = ... # type: float + optional_bool = ... # type: bool + optional_string = ... # type: Text + optional_bytes = ... # type: bytes + optional_nested_enum = ... # type: TestAllTypes.NestedEnum + optional_foreign_enum = ... # type: ForeignEnum + optional_import_enum = ... # type: ImportEnum + optional_string_piece = ... # type: Text + optional_cord = ... # type: Text + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_double = ... # type: RepeatedScalarFieldContainer[float] + repeated_bool = ... # type: RepeatedScalarFieldContainer[bool] + repeated_string = ... # type: RepeatedScalarFieldContainer[Text] + repeated_bytes = ... # type: RepeatedScalarFieldContainer[bytes] + repeated_nested_enum = ... # type: RepeatedScalarFieldContainer[TestAllTypes.NestedEnum] + repeated_foreign_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + repeated_import_enum = ... # type: RepeatedScalarFieldContainer[ImportEnum] + repeated_string_piece = ... # type: RepeatedScalarFieldContainer[Text] + repeated_cord = ... # type: RepeatedScalarFieldContainer[Text] + default_int32 = ... # type: int + default_int64 = ... # type: int + default_uint32 = ... # type: int + default_uint64 = ... # type: int + default_sint32 = ... # type: int + default_sint64 = ... # type: int + default_fixed32 = ... # type: int + default_fixed64 = ... # type: int + default_sfixed32 = ... # type: int + default_sfixed64 = ... # type: int + default_float = ... # type: float + default_double = ... # type: float + default_bool = ... # type: bool + default_string = ... # type: Text + default_bytes = ... # type: bytes + default_nested_enum = ... # type: TestAllTypes.NestedEnum + default_foreign_enum = ... # type: ForeignEnum + default_import_enum = ... # type: ImportEnum + default_string_piece = ... # type: Text + default_cord = ... # type: Text + oneof_uint32 = ... # type: int + oneof_string = ... # type: Text + oneof_bytes = ... # type: bytes + + @property + def optionalgroup(self) -> TestAllTypes.OptionalGroup: ... + + @property + def optional_nested_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def optional_foreign_message(self) -> ForeignMessage: ... + + @property + def optional_import_message(self) -> ImportMessage: ... + + @property + def optional_public_import_message(self) -> PublicImportMessage: ... + + @property + def optional_lazy_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def repeatedgroup( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.RepeatedGroup]: ... + + @property + def repeated_nested_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.NestedMessage]: ... + + @property + def repeated_foreign_message( + self) -> RepeatedCompositeFieldContainer[ForeignMessage]: ... + + @property + def repeated_import_message( + self) -> RepeatedCompositeFieldContainer[ImportMessage]: ... + + @property + def repeated_lazy_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.NestedMessage]: ... + + @property + def oneof_nested_message(self) -> TestAllTypes.NestedMessage: ... + + def __init__(self, + optional_int32: Optional[int] = ..., + optional_int64: Optional[int] = ..., + optional_uint32: Optional[int] = ..., + optional_uint64: Optional[int] = ..., + optional_sint32: Optional[int] = ..., + optional_sint64: Optional[int] = ..., + optional_fixed32: Optional[int] = ..., + optional_fixed64: Optional[int] = ..., + optional_sfixed32: Optional[int] = ..., + optional_sfixed64: Optional[int] = ..., + optional_float: Optional[float] = ..., + optional_double: Optional[float] = ..., + optional_bool: Optional[bool] = ..., + optional_string: Optional[Text] = ..., + optional_bytes: Optional[bytes] = ..., + optionalgroup: Optional[TestAllTypes.OptionalGroup] = ..., + optional_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + optional_foreign_message: Optional[ForeignMessage] = ..., + optional_import_message: Optional[ImportMessage] = ..., + optional_nested_enum: Optional[TestAllTypes.NestedEnum] = ..., + optional_foreign_enum: Optional[ForeignEnum] = ..., + optional_import_enum: Optional[ImportEnum] = ..., + optional_string_piece: Optional[Text] = ..., + optional_cord: Optional[Text] = ..., + optional_public_import_message: Optional[PublicImportMessage] = ..., + optional_lazy_message: Optional[TestAllTypes.NestedMessage] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_uint32: Optional[Iterable[int]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + repeated_sint32: Optional[Iterable[int]] = ..., + repeated_sint64: Optional[Iterable[int]] = ..., + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_sfixed32: Optional[Iterable[int]] = ..., + repeated_sfixed64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_double: Optional[Iterable[float]] = ..., + repeated_bool: Optional[Iterable[bool]] = ..., + repeated_string: Optional[Iterable[Text]] = ..., + repeated_bytes: Optional[Iterable[bytes]] = ..., + repeatedgroup: Optional[Iterable[TestAllTypes.RepeatedGroup]] = ..., + repeated_nested_message: Optional[Iterable[TestAllTypes.NestedMessage]] = ..., + repeated_foreign_message: Optional[Iterable[ForeignMessage]] = ..., + repeated_import_message: Optional[Iterable[ImportMessage]] = ..., + repeated_nested_enum: Optional[Iterable[TestAllTypes.NestedEnum]] = ..., + repeated_foreign_enum: Optional[Iterable[ForeignEnum]] = ..., + repeated_import_enum: Optional[Iterable[ImportEnum]] = ..., + repeated_string_piece: Optional[Iterable[Text]] = ..., + repeated_cord: Optional[Iterable[Text]] = ..., + repeated_lazy_message: Optional[Iterable[TestAllTypes.NestedMessage]] = ..., + default_int32: Optional[int] = ..., + default_int64: Optional[int] = ..., + default_uint32: Optional[int] = ..., + default_uint64: Optional[int] = ..., + default_sint32: Optional[int] = ..., + default_sint64: Optional[int] = ..., + default_fixed32: Optional[int] = ..., + default_fixed64: Optional[int] = ..., + default_sfixed32: Optional[int] = ..., + default_sfixed64: Optional[int] = ..., + default_float: Optional[float] = ..., + default_double: Optional[float] = ..., + default_bool: Optional[bool] = ..., + default_string: Optional[Text] = ..., + default_bytes: Optional[bytes] = ..., + default_nested_enum: Optional[TestAllTypes.NestedEnum] = ..., + default_foreign_enum: Optional[ForeignEnum] = ..., + default_import_enum: Optional[ImportEnum] = ..., + default_string_piece: Optional[Text] = ..., + default_cord: Optional[Text] = ..., + oneof_uint32: Optional[int] = ..., + oneof_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + oneof_string: Optional[Text] = ..., + oneof_bytes: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes: ... + + +class NestedTestAllTypes(Message): + + @property + def child(self) -> NestedTestAllTypes: ... + + @property + def payload(self) -> TestAllTypes: ... + + @property + def repeated_child( + self) -> RepeatedCompositeFieldContainer[NestedTestAllTypes]: ... + + def __init__(self, + child: Optional[NestedTestAllTypes] = ..., + payload: Optional[TestAllTypes] = ..., + repeated_child: Optional[Iterable[NestedTestAllTypes]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> NestedTestAllTypes: ... + + +class TestDeprecatedFields(Message): + deprecated_int32 = ... # type: int + deprecated_int32_in_oneof = ... # type: int + + def __init__(self, + deprecated_int32: Optional[int] = ..., + deprecated_int32_in_oneof: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDeprecatedFields: ... + + +class TestDeprecatedMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDeprecatedMessage: ... + + +class ForeignMessage(Message): + c = ... # type: int + d = ... # type: int + + def __init__(self, + c: Optional[int] = ..., + d: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ForeignMessage: ... + + +class TestReservedFields(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestReservedFields: ... + + +class TestAllExtensions(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllExtensions: ... + + +class OptionalGroup_extension(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> OptionalGroup_extension: ... + + +class RepeatedGroup_extension(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> RepeatedGroup_extension: ... + + +class TestGroup(Message): + class OptionalGroup(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestGroup.OptionalGroup: ... + optional_foreign_enum = ... # type: ForeignEnum + + @property + def optionalgroup(self) -> TestGroup.OptionalGroup: ... + + def __init__(self, + optionalgroup: Optional[TestGroup.OptionalGroup] = ..., + optional_foreign_enum: Optional[ForeignEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestGroup: ... + + +class TestGroupExtension(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestGroupExtension: ... + + +class TestNestedExtension(Message): + class OptionalGroup_extension(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestNestedExtension.OptionalGroup_extension: ... + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedExtension: ... + + +class TestRequired(Message): + a = ... # type: int + dummy2 = ... # type: int + b = ... # type: int + dummy4 = ... # type: int + dummy5 = ... # type: int + dummy6 = ... # type: int + dummy7 = ... # type: int + dummy8 = ... # type: int + dummy9 = ... # type: int + dummy10 = ... # type: int + dummy11 = ... # type: int + dummy12 = ... # type: int + dummy13 = ... # type: int + dummy14 = ... # type: int + dummy15 = ... # type: int + dummy16 = ... # type: int + dummy17 = ... # type: int + dummy18 = ... # type: int + dummy19 = ... # type: int + dummy20 = ... # type: int + dummy21 = ... # type: int + dummy22 = ... # type: int + dummy23 = ... # type: int + dummy24 = ... # type: int + dummy25 = ... # type: int + dummy26 = ... # type: int + dummy27 = ... # type: int + dummy28 = ... # type: int + dummy29 = ... # type: int + dummy30 = ... # type: int + dummy31 = ... # type: int + dummy32 = ... # type: int + c = ... # type: int + + def __init__(self, + a: int, + b: int, + c: int, + dummy2: Optional[int] = ..., + dummy4: Optional[int] = ..., + dummy5: Optional[int] = ..., + dummy6: Optional[int] = ..., + dummy7: Optional[int] = ..., + dummy8: Optional[int] = ..., + dummy9: Optional[int] = ..., + dummy10: Optional[int] = ..., + dummy11: Optional[int] = ..., + dummy12: Optional[int] = ..., + dummy13: Optional[int] = ..., + dummy14: Optional[int] = ..., + dummy15: Optional[int] = ..., + dummy16: Optional[int] = ..., + dummy17: Optional[int] = ..., + dummy18: Optional[int] = ..., + dummy19: Optional[int] = ..., + dummy20: Optional[int] = ..., + dummy21: Optional[int] = ..., + dummy22: Optional[int] = ..., + dummy23: Optional[int] = ..., + dummy24: Optional[int] = ..., + dummy25: Optional[int] = ..., + dummy26: Optional[int] = ..., + dummy27: Optional[int] = ..., + dummy28: Optional[int] = ..., + dummy29: Optional[int] = ..., + dummy30: Optional[int] = ..., + dummy31: Optional[int] = ..., + dummy32: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRequired: ... + + +class TestRequiredForeign(Message): + dummy = ... # type: int + + @property + def optional_message(self) -> TestRequired: ... + + @property + def repeated_message( + self) -> RepeatedCompositeFieldContainer[TestRequired]: ... + + def __init__(self, + optional_message: Optional[TestRequired] = ..., + repeated_message: Optional[Iterable[TestRequired]] = ..., + dummy: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRequiredForeign: ... + + +class TestRequiredMessage(Message): + + @property + def optional_message(self) -> TestRequired: ... + + @property + def repeated_message( + self) -> RepeatedCompositeFieldContainer[TestRequired]: ... + + @property + def required_message(self) -> TestRequired: ... + + def __init__(self, + required_message: TestRequired, + optional_message: Optional[TestRequired] = ..., + repeated_message: Optional[Iterable[TestRequired]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRequiredMessage: ... + + +class TestForeignNested(Message): + + @property + def foreign_nested(self) -> TestAllTypes.NestedMessage: ... + + def __init__(self, + foreign_nested: Optional[TestAllTypes.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestForeignNested: ... + + +class TestEmptyMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEmptyMessage: ... + + +class TestEmptyMessageWithExtensions(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEmptyMessageWithExtensions: ... + + +class TestMultipleExtensionRanges(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMultipleExtensionRanges: ... + + +class TestReallyLargeTagNumber(Message): + a = ... # type: int + bb = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + bb: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestReallyLargeTagNumber: ... + + +class TestRecursiveMessage(Message): + i = ... # type: int + + @property + def a(self) -> TestRecursiveMessage: ... + + def __init__(self, + a: Optional[TestRecursiveMessage] = ..., + i: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRecursiveMessage: ... + + +class TestMutualRecursionA(Message): + class SubMessage(Message): + + @property + def b(self) -> TestMutualRecursionB: ... + + def __init__(self, + b: Optional[TestMutualRecursionB] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMutualRecursionA.SubMessage: ... + + class SubGroup(Message): + + @property + def sub_message(self) -> TestMutualRecursionA.SubMessage: ... + + @property + def not_in_this_scc(self) -> TestAllTypes: ... + + def __init__(self, + sub_message: Optional[TestMutualRecursionA.SubMessage] = ..., + not_in_this_scc: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMutualRecursionA.SubGroup: ... + + @property + def bb(self) -> TestMutualRecursionB: ... + + @property + def subgroup(self) -> TestMutualRecursionA.SubGroup: ... + + def __init__(self, + bb: Optional[TestMutualRecursionB] = ..., + subgroup: Optional[TestMutualRecursionA.SubGroup] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMutualRecursionA: ... + + +class TestMutualRecursionB(Message): + optional_int32 = ... # type: int + + @property + def a(self) -> TestMutualRecursionA: ... + + def __init__(self, + a: Optional[TestMutualRecursionA] = ..., + optional_int32: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMutualRecursionB: ... + + +class TestIsInitialized(Message): + class SubMessage(Message): + class SubGroup(Message): + i = ... # type: int + + def __init__(self, + i: int, + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestIsInitialized.SubMessage.SubGroup: ... + + @property + def subgroup(self) -> TestIsInitialized.SubMessage.SubGroup: ... + + def __init__(self, + subgroup: Optional[TestIsInitialized.SubMessage.SubGroup] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestIsInitialized.SubMessage: ... + + @property + def sub_message(self) -> TestIsInitialized.SubMessage: ... + + def __init__(self, + sub_message: Optional[TestIsInitialized.SubMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestIsInitialized: ... + + +class TestDupFieldNumber(Message): + class Foo(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDupFieldNumber.Foo: ... + + class Bar(Message): + a = ... # type: int + + def __init__(self, + a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDupFieldNumber.Bar: ... + a = ... # type: int + + @property + def foo(self) -> TestDupFieldNumber.Foo: ... + + @property + def bar(self) -> TestDupFieldNumber.Bar: ... + + def __init__(self, + a: Optional[int] = ..., + foo: Optional[TestDupFieldNumber.Foo] = ..., + bar: Optional[TestDupFieldNumber.Bar] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDupFieldNumber: ... + + +class TestEagerMessage(Message): + + @property + def sub_message(self) -> TestAllTypes: ... + + def __init__(self, + sub_message: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEagerMessage: ... + + +class TestLazyMessage(Message): + + @property + def sub_message(self) -> TestAllTypes: ... + + def __init__(self, + sub_message: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestLazyMessage: ... + + +class TestNestedMessageHasBits(Message): + class NestedMessage(Message): + nestedmessage_repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + + @property + def nestedmessage_repeated_foreignmessage( + self) -> RepeatedCompositeFieldContainer[ForeignMessage]: ... + + def __init__(self, + nestedmessage_repeated_int32: Optional[Iterable[int]] = ..., + nestedmessage_repeated_foreignmessage: Optional[Iterable[ForeignMessage]] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestNestedMessageHasBits.NestedMessage: ... + + @property + def optional_nested_message( + self) -> TestNestedMessageHasBits.NestedMessage: ... + + def __init__(self, + optional_nested_message: Optional[TestNestedMessageHasBits.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMessageHasBits: ... + + +class TestCamelCaseFieldNames(Message): + PrimitiveField = ... # type: int + StringField = ... # type: Text + EnumField = ... # type: ForeignEnum + StringPieceField = ... # type: Text + CordField = ... # type: Text + RepeatedPrimitiveField = ... # type: RepeatedScalarFieldContainer[int] + RepeatedStringField = ... # type: RepeatedScalarFieldContainer[Text] + RepeatedEnumField = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + RepeatedStringPieceField = ... # type: RepeatedScalarFieldContainer[Text] + RepeatedCordField = ... # type: RepeatedScalarFieldContainer[Text] + + @property + def MessageField(self) -> ForeignMessage: ... + + @property + def RepeatedMessageField( + self) -> RepeatedCompositeFieldContainer[ForeignMessage]: ... + + def __init__(self, + PrimitiveField: Optional[int] = ..., + StringField: Optional[Text] = ..., + EnumField: Optional[ForeignEnum] = ..., + MessageField: Optional[ForeignMessage] = ..., + StringPieceField: Optional[Text] = ..., + CordField: Optional[Text] = ..., + RepeatedPrimitiveField: Optional[Iterable[int]] = ..., + RepeatedStringField: Optional[Iterable[Text]] = ..., + RepeatedEnumField: Optional[Iterable[ForeignEnum]] = ..., + RepeatedMessageField: Optional[Iterable[ForeignMessage]] = ..., + RepeatedStringPieceField: Optional[Iterable[Text]] = ..., + RepeatedCordField: Optional[Iterable[Text]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestCamelCaseFieldNames: ... + + +class TestFieldOrderings(Message): + class NestedMessage(Message): + oo = ... # type: int + bb = ... # type: int + + def __init__(self, + oo: Optional[int] = ..., + bb: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestFieldOrderings.NestedMessage: ... + my_string = ... # type: Text + my_int = ... # type: int + my_float = ... # type: float + + @property + def optional_nested_message(self) -> TestFieldOrderings.NestedMessage: ... + + def __init__(self, + my_string: Optional[Text] = ..., + my_int: Optional[int] = ..., + my_float: Optional[float] = ..., + optional_nested_message: Optional[TestFieldOrderings.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestFieldOrderings: ... + + +class TestExtensionOrderings1(Message): + my_string = ... # type: Text + + def __init__(self, + my_string: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestExtensionOrderings1: ... + + +class TestExtensionOrderings2(Message): + class TestExtensionOrderings3(Message): + my_string = ... # type: Text + + def __init__(self, + my_string: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestExtensionOrderings2.TestExtensionOrderings3: ... + my_string = ... # type: Text + + def __init__(self, + my_string: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestExtensionOrderings2: ... + + +class TestExtremeDefaultValues(Message): + escaped_bytes = ... # type: bytes + large_uint32 = ... # type: int + large_uint64 = ... # type: int + small_int32 = ... # type: int + small_int64 = ... # type: int + really_small_int32 = ... # type: int + really_small_int64 = ... # type: int + utf8_string = ... # type: Text + zero_float = ... # type: float + one_float = ... # type: float + small_float = ... # type: float + negative_one_float = ... # type: float + negative_float = ... # type: float + large_float = ... # type: float + small_negative_float = ... # type: float + inf_double = ... # type: float + neg_inf_double = ... # type: float + nan_double = ... # type: float + inf_float = ... # type: float + neg_inf_float = ... # type: float + nan_float = ... # type: float + cpp_trigraph = ... # type: Text + string_with_zero = ... # type: Text + bytes_with_zero = ... # type: bytes + string_piece_with_zero = ... # type: Text + cord_with_zero = ... # type: Text + replacement_string = ... # type: Text + + def __init__(self, + escaped_bytes: Optional[bytes] = ..., + large_uint32: Optional[int] = ..., + large_uint64: Optional[int] = ..., + small_int32: Optional[int] = ..., + small_int64: Optional[int] = ..., + really_small_int32: Optional[int] = ..., + really_small_int64: Optional[int] = ..., + utf8_string: Optional[Text] = ..., + zero_float: Optional[float] = ..., + one_float: Optional[float] = ..., + small_float: Optional[float] = ..., + negative_one_float: Optional[float] = ..., + negative_float: Optional[float] = ..., + large_float: Optional[float] = ..., + small_negative_float: Optional[float] = ..., + inf_double: Optional[float] = ..., + neg_inf_double: Optional[float] = ..., + nan_double: Optional[float] = ..., + inf_float: Optional[float] = ..., + neg_inf_float: Optional[float] = ..., + nan_float: Optional[float] = ..., + cpp_trigraph: Optional[Text] = ..., + string_with_zero: Optional[Text] = ..., + bytes_with_zero: Optional[bytes] = ..., + string_piece_with_zero: Optional[Text] = ..., + cord_with_zero: Optional[Text] = ..., + replacement_string: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestExtremeDefaultValues: ... + + +class SparseEnumMessage(Message): + sparse_enum = ... # type: TestSparseEnum + + def __init__(self, + sparse_enum: Optional[TestSparseEnum] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> SparseEnumMessage: ... + + +class OneString(Message): + data = ... # type: Text + + def __init__(self, + data: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> OneString: ... + + +class MoreString(Message): + data = ... # type: RepeatedScalarFieldContainer[Text] + + def __init__(self, + data: Optional[Iterable[Text]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MoreString: ... + + +class OneBytes(Message): + data = ... # type: bytes + + def __init__(self, + data: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> OneBytes: ... + + +class MoreBytes(Message): + data = ... # type: RepeatedScalarFieldContainer[bytes] + + def __init__(self, + data: Optional[Iterable[bytes]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MoreBytes: ... + + +class Int32Message(Message): + data = ... # type: int + + def __init__(self, + data: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Int32Message: ... + + +class Uint32Message(Message): + data = ... # type: int + + def __init__(self, + data: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Uint32Message: ... + + +class Int64Message(Message): + data = ... # type: int + + def __init__(self, + data: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Int64Message: ... + + +class Uint64Message(Message): + data = ... # type: int + + def __init__(self, + data: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Uint64Message: ... + + +class BoolMessage(Message): + data = ... # type: bool + + def __init__(self, + data: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> BoolMessage: ... + + +class TestOneof(Message): + class FooGroup(Message): + a = ... # type: int + b = ... # type: Text + + def __init__(self, + a: Optional[int] = ..., + b: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneof.FooGroup: ... + foo_int = ... # type: int + foo_string = ... # type: Text + + @property + def foo_message(self) -> TestAllTypes: ... + + @property + def foogroup(self) -> TestOneof.FooGroup: ... + + def __init__(self, + foo_int: Optional[int] = ..., + foo_string: Optional[Text] = ..., + foo_message: Optional[TestAllTypes] = ..., + foogroup: Optional[TestOneof.FooGroup] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneof: ... + + +class TestOneofBackwardsCompatible(Message): + class FooGroup(Message): + a = ... # type: int + b = ... # type: Text + + def __init__(self, + a: Optional[int] = ..., + b: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestOneofBackwardsCompatible.FooGroup: ... + foo_int = ... # type: int + foo_string = ... # type: Text + + @property + def foo_message(self) -> TestAllTypes: ... + + @property + def foogroup(self) -> TestOneofBackwardsCompatible.FooGroup: ... + + def __init__(self, + foo_int: Optional[int] = ..., + foo_string: Optional[Text] = ..., + foo_message: Optional[TestAllTypes] = ..., + foogroup: Optional[TestOneofBackwardsCompatible.FooGroup] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneofBackwardsCompatible: ... + + +class TestOneof2(Message): + class NestedEnum(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestOneof2.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestOneof2.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestOneof2.NestedEnum]]: ... + FOO: NestedEnum + BAR: NestedEnum + BAZ: NestedEnum + + class FooGroup(Message): + a = ... # type: int + b = ... # type: Text + + def __init__(self, + a: Optional[int] = ..., + b: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneof2.FooGroup: ... + + class NestedMessage(Message): + qux_int = ... # type: int + corge_int = ... # type: RepeatedScalarFieldContainer[int] + + def __init__(self, + qux_int: Optional[int] = ..., + corge_int: Optional[Iterable[int]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneof2.NestedMessage: ... + foo_int = ... # type: int + foo_string = ... # type: Text + foo_cord = ... # type: Text + foo_string_piece = ... # type: Text + foo_bytes = ... # type: bytes + foo_enum = ... # type: TestOneof2.NestedEnum + bar_int = ... # type: int + bar_string = ... # type: Text + bar_cord = ... # type: Text + bar_string_piece = ... # type: Text + bar_bytes = ... # type: bytes + bar_enum = ... # type: TestOneof2.NestedEnum + baz_int = ... # type: int + baz_string = ... # type: Text + + @property + def foo_message(self) -> TestOneof2.NestedMessage: ... + + @property + def foogroup(self) -> TestOneof2.FooGroup: ... + + @property + def foo_lazy_message(self) -> TestOneof2.NestedMessage: ... + + def __init__(self, + foo_int: Optional[int] = ..., + foo_string: Optional[Text] = ..., + foo_cord: Optional[Text] = ..., + foo_string_piece: Optional[Text] = ..., + foo_bytes: Optional[bytes] = ..., + foo_enum: Optional[TestOneof2.NestedEnum] = ..., + foo_message: Optional[TestOneof2.NestedMessage] = ..., + foogroup: Optional[TestOneof2.FooGroup] = ..., + foo_lazy_message: Optional[TestOneof2.NestedMessage] = ..., + bar_int: Optional[int] = ..., + bar_string: Optional[Text] = ..., + bar_cord: Optional[Text] = ..., + bar_string_piece: Optional[Text] = ..., + bar_bytes: Optional[bytes] = ..., + bar_enum: Optional[TestOneof2.NestedEnum] = ..., + baz_int: Optional[int] = ..., + baz_string: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneof2: ... + + +class TestRequiredOneof(Message): + class NestedMessage(Message): + required_double = ... # type: float + + def __init__(self, + required_double: float, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRequiredOneof.NestedMessage: ... + foo_int = ... # type: int + foo_string = ... # type: Text + + @property + def foo_message(self) -> TestRequiredOneof.NestedMessage: ... + + def __init__(self, + foo_int: Optional[int] = ..., + foo_string: Optional[Text] = ..., + foo_message: Optional[TestRequiredOneof.NestedMessage] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRequiredOneof: ... + + +class TestPackedTypes(Message): + packed_int32 = ... # type: RepeatedScalarFieldContainer[int] + packed_int64 = ... # type: RepeatedScalarFieldContainer[int] + packed_uint32 = ... # type: RepeatedScalarFieldContainer[int] + packed_uint64 = ... # type: RepeatedScalarFieldContainer[int] + packed_sint32 = ... # type: RepeatedScalarFieldContainer[int] + packed_sint64 = ... # type: RepeatedScalarFieldContainer[int] + packed_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + packed_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + packed_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + packed_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + packed_float = ... # type: RepeatedScalarFieldContainer[float] + packed_double = ... # type: RepeatedScalarFieldContainer[float] + packed_bool = ... # type: RepeatedScalarFieldContainer[bool] + packed_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + + def __init__(self, + packed_int32: Optional[Iterable[int]] = ..., + packed_int64: Optional[Iterable[int]] = ..., + packed_uint32: Optional[Iterable[int]] = ..., + packed_uint64: Optional[Iterable[int]] = ..., + packed_sint32: Optional[Iterable[int]] = ..., + packed_sint64: Optional[Iterable[int]] = ..., + packed_fixed32: Optional[Iterable[int]] = ..., + packed_fixed64: Optional[Iterable[int]] = ..., + packed_sfixed32: Optional[Iterable[int]] = ..., + packed_sfixed64: Optional[Iterable[int]] = ..., + packed_float: Optional[Iterable[float]] = ..., + packed_double: Optional[Iterable[float]] = ..., + packed_bool: Optional[Iterable[bool]] = ..., + packed_enum: Optional[Iterable[ForeignEnum]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestPackedTypes: ... + + +class TestUnpackedTypes(Message): + unpacked_int32 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_int64 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_uint32 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_uint64 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_sint32 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_sint64 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + unpacked_float = ... # type: RepeatedScalarFieldContainer[float] + unpacked_double = ... # type: RepeatedScalarFieldContainer[float] + unpacked_bool = ... # type: RepeatedScalarFieldContainer[bool] + unpacked_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + + def __init__(self, + unpacked_int32: Optional[Iterable[int]] = ..., + unpacked_int64: Optional[Iterable[int]] = ..., + unpacked_uint32: Optional[Iterable[int]] = ..., + unpacked_uint64: Optional[Iterable[int]] = ..., + unpacked_sint32: Optional[Iterable[int]] = ..., + unpacked_sint64: Optional[Iterable[int]] = ..., + unpacked_fixed32: Optional[Iterable[int]] = ..., + unpacked_fixed64: Optional[Iterable[int]] = ..., + unpacked_sfixed32: Optional[Iterable[int]] = ..., + unpacked_sfixed64: Optional[Iterable[int]] = ..., + unpacked_float: Optional[Iterable[float]] = ..., + unpacked_double: Optional[Iterable[float]] = ..., + unpacked_bool: Optional[Iterable[bool]] = ..., + unpacked_enum: Optional[Iterable[ForeignEnum]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestUnpackedTypes: ... + + +class TestPackedExtensions(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestPackedExtensions: ... + + +class TestUnpackedExtensions(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestUnpackedExtensions: ... + + +class TestDynamicExtensions(Message): + class DynamicEnumType(int): + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestDynamicExtensions.DynamicEnumType: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestDynamicExtensions.DynamicEnumType]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, + TestDynamicExtensions.DynamicEnumType]]: ... + DYNAMIC_FOO: DynamicEnumType + DYNAMIC_BAR: DynamicEnumType + DYNAMIC_BAZ: DynamicEnumType + + class DynamicMessageType(Message): + dynamic_field = ... # type: int + + def __init__(self, + dynamic_field: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestDynamicExtensions.DynamicMessageType: ... + scalar_extension = ... # type: int + enum_extension = ... # type: ForeignEnum + dynamic_enum_extension = ... # type: TestDynamicExtensions.DynamicEnumType + repeated_extension = ... # type: RepeatedScalarFieldContainer[Text] + packed_extension = ... # type: RepeatedScalarFieldContainer[int] + + @property + def message_extension(self) -> ForeignMessage: ... + + @property + def dynamic_message_extension( + self) -> TestDynamicExtensions.DynamicMessageType: ... + + def __init__(self, + scalar_extension: Optional[int] = ..., + enum_extension: Optional[ForeignEnum] = ..., + dynamic_enum_extension: Optional[TestDynamicExtensions.DynamicEnumType] = ..., + message_extension: Optional[ForeignMessage] = ..., + dynamic_message_extension: Optional[TestDynamicExtensions.DynamicMessageType] = ..., + repeated_extension: Optional[Iterable[Text]] = ..., + packed_extension: Optional[Iterable[int]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDynamicExtensions: ... + + +class TestRepeatedScalarDifferentTagSizes(Message): + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + + def __init__(self, + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestRepeatedScalarDifferentTagSizes: ... + + +class TestParsingMerge(Message): + class RepeatedFieldsGenerator(Message): + class Group1(Message): + + @property + def field1(self) -> TestAllTypes: ... + + def __init__(self, + field1: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestParsingMerge.RepeatedFieldsGenerator.Group1: ... + + class Group2(Message): + + @property + def field1(self) -> TestAllTypes: ... + + def __init__(self, + field1: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestParsingMerge.RepeatedFieldsGenerator.Group2: ... + + @property + def field1(self) -> RepeatedCompositeFieldContainer[TestAllTypes]: ... + + @property + def field2(self) -> RepeatedCompositeFieldContainer[TestAllTypes]: ... + + @property + def field3(self) -> RepeatedCompositeFieldContainer[TestAllTypes]: ... + + @property + def group1( + self) -> RepeatedCompositeFieldContainer[TestParsingMerge.RepeatedFieldsGenerator.Group1]: ... + + @property + def group2( + self) -> RepeatedCompositeFieldContainer[TestParsingMerge.RepeatedFieldsGenerator.Group2]: ... + + @property + def ext1(self) -> RepeatedCompositeFieldContainer[TestAllTypes]: ... + + @property + def ext2(self) -> RepeatedCompositeFieldContainer[TestAllTypes]: ... + + def __init__(self, + field1: Optional[Iterable[TestAllTypes]] = ..., + field2: Optional[Iterable[TestAllTypes]] = ..., + field3: Optional[Iterable[TestAllTypes]] = ..., + group1: Optional[Iterable[TestParsingMerge.RepeatedFieldsGenerator.Group1]] = ..., + group2: Optional[Iterable[TestParsingMerge.RepeatedFieldsGenerator.Group2]] = ..., + ext1: Optional[Iterable[TestAllTypes]] = ..., + ext2: Optional[Iterable[TestAllTypes]] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestParsingMerge.RepeatedFieldsGenerator: ... + + class OptionalGroup(Message): + + @property + def optional_group_all_types(self) -> TestAllTypes: ... + + def __init__(self, + optional_group_all_types: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestParsingMerge.OptionalGroup: ... + + class RepeatedGroup(Message): + + @property + def repeated_group_all_types(self) -> TestAllTypes: ... + + def __init__(self, + repeated_group_all_types: Optional[TestAllTypes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestParsingMerge.RepeatedGroup: ... + + @property + def required_all_types(self) -> TestAllTypes: ... + + @property + def optional_all_types(self) -> TestAllTypes: ... + + @property + def repeated_all_types( + self) -> RepeatedCompositeFieldContainer[TestAllTypes]: ... + + @property + def optionalgroup(self) -> TestParsingMerge.OptionalGroup: ... + + @property + def repeatedgroup( + self) -> RepeatedCompositeFieldContainer[TestParsingMerge.RepeatedGroup]: ... + + def __init__(self, + required_all_types: TestAllTypes, + optional_all_types: Optional[TestAllTypes] = ..., + repeated_all_types: Optional[Iterable[TestAllTypes]] = ..., + optionalgroup: Optional[TestParsingMerge.OptionalGroup] = ..., + repeatedgroup: Optional[Iterable[TestParsingMerge.RepeatedGroup]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestParsingMerge: ... + + +class TestCommentInjectionMessage(Message): + a = ... # type: Text + + def __init__(self, + a: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestCommentInjectionMessage: ... + + +class FooRequest(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FooRequest: ... + + +class FooResponse(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FooResponse: ... + + +class FooClientMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FooClientMessage: ... + + +class FooServerMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FooServerMessage: ... + + +class BarRequest(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> BarRequest: ... + + +class BarResponse(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> BarResponse: ... + + +class TestJsonName(Message): + field_name1 = ... # type: int + fieldName2 = ... # type: int + FieldName3 = ... # type: int + _field_name4 = ... # type: int + FIELD_NAME5 = ... # type: int + field_name6 = ... # type: int + + def __init__(self, + field_name1: Optional[int] = ..., + fieldName2: Optional[int] = ..., + FieldName3: Optional[int] = ..., + _field_name4: Optional[int] = ..., + FIELD_NAME5: Optional[int] = ..., + field_name6: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestJsonName: ... + + +class TestHugeFieldNumbers(Message): + class OptionalGroup(Message): + group_a = ... # type: int + + def __init__(self, + group_a: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestHugeFieldNumbers.OptionalGroup: ... + + class StringStringMapEntry(Message): + key = ... # type: Text + value = ... # type: Text + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString( + cls, s: bytes) -> TestHugeFieldNumbers.StringStringMapEntry: ... + optional_int32 = ... # type: int + fixed_32 = ... # type: int + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + packed_int32 = ... # type: RepeatedScalarFieldContainer[int] + optional_enum = ... # type: ForeignEnum + optional_string = ... # type: Text + optional_bytes = ... # type: bytes + oneof_uint32 = ... # type: int + oneof_string = ... # type: Text + oneof_bytes = ... # type: bytes + + @property + def optional_message(self) -> ForeignMessage: ... + + @property + def optionalgroup(self) -> TestHugeFieldNumbers.OptionalGroup: ... + + @property + def string_string_map(self) -> MutableMapping[Text, Text]: ... + + @property + def oneof_test_all_types(self) -> TestAllTypes: ... + + def __init__(self, + optional_int32: Optional[int] = ..., + fixed_32: Optional[int] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + packed_int32: Optional[Iterable[int]] = ..., + optional_enum: Optional[ForeignEnum] = ..., + optional_string: Optional[Text] = ..., + optional_bytes: Optional[bytes] = ..., + optional_message: Optional[ForeignMessage] = ..., + optionalgroup: Optional[TestHugeFieldNumbers.OptionalGroup] = ..., + string_string_map: Optional[Mapping[Text, Text]] = ..., + oneof_uint32: Optional[int] = ..., + oneof_test_all_types: Optional[TestAllTypes] = ..., + oneof_string: Optional[Text] = ..., + oneof_bytes: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestHugeFieldNumbers: ... + + +class TestExtensionInsideTable(Message): + field1 = ... # type: int + field2 = ... # type: int + field3 = ... # type: int + field4 = ... # type: int + field6 = ... # type: int + field7 = ... # type: int + field8 = ... # type: int + field9 = ... # type: int + field10 = ... # type: int + + def __init__(self, + field1: Optional[int] = ..., + field2: Optional[int] = ..., + field3: Optional[int] = ..., + field4: Optional[int] = ..., + field6: Optional[int] = ..., + field7: Optional[int] = ..., + field8: Optional[int] = ..., + field9: Optional[int] = ..., + field10: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestExtensionInsideTable: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_proto3_arena_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_proto3_arena_pb2.pyi new file mode 100644 index 000000000..de9c41270 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/unittest_proto3_arena_pb2.pyi @@ -0,0 +1,332 @@ +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.unittest_import_pb2 import ( + ImportMessage, +) +from google.protobuf.unittest_import_public_pb2 import ( + PublicImportMessage, +) +from typing import ( + Iterable, + List, + Optional, + Text, + Tuple, + cast, +) + + +class ForeignEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> ForeignEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[ForeignEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, ForeignEnum]]: ... + + +FOREIGN_ZERO: ForeignEnum +FOREIGN_FOO: ForeignEnum +FOREIGN_BAR: ForeignEnum +FOREIGN_BAZ: ForeignEnum + + +class TestAllTypes(Message): + + class NestedEnum(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> TestAllTypes.NestedEnum: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[TestAllTypes.NestedEnum]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, TestAllTypes.NestedEnum]]: ... + ZERO: NestedEnum + FOO: NestedEnum + BAR: NestedEnum + BAZ: NestedEnum + NEG: NestedEnum + + class NestedMessage(Message): + bb = ... # type: int + + def __init__(self, + bb: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes.NestedMessage: ... + optional_int32 = ... # type: int + optional_int64 = ... # type: int + optional_uint32 = ... # type: int + optional_uint64 = ... # type: int + optional_sint32 = ... # type: int + optional_sint64 = ... # type: int + optional_fixed32 = ... # type: int + optional_fixed64 = ... # type: int + optional_sfixed32 = ... # type: int + optional_sfixed64 = ... # type: int + optional_float = ... # type: float + optional_double = ... # type: float + optional_bool = ... # type: bool + optional_string = ... # type: Text + optional_bytes = ... # type: bytes + optional_nested_enum = ... # type: TestAllTypes.NestedEnum + optional_foreign_enum = ... # type: ForeignEnum + optional_string_piece = ... # type: Text + optional_cord = ... # type: Text + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_double = ... # type: RepeatedScalarFieldContainer[float] + repeated_bool = ... # type: RepeatedScalarFieldContainer[bool] + repeated_string = ... # type: RepeatedScalarFieldContainer[Text] + repeated_bytes = ... # type: RepeatedScalarFieldContainer[bytes] + repeated_nested_enum = ... # type: RepeatedScalarFieldContainer[TestAllTypes.NestedEnum] + repeated_foreign_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + repeated_string_piece = ... # type: RepeatedScalarFieldContainer[Text] + repeated_cord = ... # type: RepeatedScalarFieldContainer[Text] + oneof_uint32 = ... # type: int + oneof_string = ... # type: Text + oneof_bytes = ... # type: bytes + + @property + def optional_nested_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def optional_foreign_message(self) -> ForeignMessage: ... + + @property + def optional_import_message(self) -> ImportMessage: ... + + @property + def optional_public_import_message(self) -> PublicImportMessage: ... + + @property + def optional_lazy_message(self) -> TestAllTypes.NestedMessage: ... + + @property + def optional_lazy_import_message(self) -> ImportMessage: ... + + @property + def repeated_nested_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.NestedMessage]: ... + + @property + def repeated_foreign_message( + self) -> RepeatedCompositeFieldContainer[ForeignMessage]: ... + + @property + def repeated_import_message( + self) -> RepeatedCompositeFieldContainer[ImportMessage]: ... + + @property + def repeated_lazy_message( + self) -> RepeatedCompositeFieldContainer[TestAllTypes.NestedMessage]: ... + + @property + def oneof_nested_message(self) -> TestAllTypes.NestedMessage: ... + + def __init__(self, + optional_int32: Optional[int] = ..., + optional_int64: Optional[int] = ..., + optional_uint32: Optional[int] = ..., + optional_uint64: Optional[int] = ..., + optional_sint32: Optional[int] = ..., + optional_sint64: Optional[int] = ..., + optional_fixed32: Optional[int] = ..., + optional_fixed64: Optional[int] = ..., + optional_sfixed32: Optional[int] = ..., + optional_sfixed64: Optional[int] = ..., + optional_float: Optional[float] = ..., + optional_double: Optional[float] = ..., + optional_bool: Optional[bool] = ..., + optional_string: Optional[Text] = ..., + optional_bytes: Optional[bytes] = ..., + optional_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + optional_foreign_message: Optional[ForeignMessage] = ..., + optional_import_message: Optional[ImportMessage] = ..., + optional_nested_enum: Optional[TestAllTypes.NestedEnum] = ..., + optional_foreign_enum: Optional[ForeignEnum] = ..., + optional_string_piece: Optional[Text] = ..., + optional_cord: Optional[Text] = ..., + optional_public_import_message: Optional[PublicImportMessage] = ..., + optional_lazy_message: Optional[TestAllTypes.NestedMessage] = ..., + optional_lazy_import_message: Optional[ImportMessage] = ..., + repeated_int32: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_uint32: Optional[Iterable[int]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + repeated_sint32: Optional[Iterable[int]] = ..., + repeated_sint64: Optional[Iterable[int]] = ..., + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_sfixed32: Optional[Iterable[int]] = ..., + repeated_sfixed64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_double: Optional[Iterable[float]] = ..., + repeated_bool: Optional[Iterable[bool]] = ..., + repeated_string: Optional[Iterable[Text]] = ..., + repeated_bytes: Optional[Iterable[bytes]] = ..., + repeated_nested_message: Optional[Iterable[TestAllTypes.NestedMessage]] = ..., + repeated_foreign_message: Optional[Iterable[ForeignMessage]] = ..., + repeated_import_message: Optional[Iterable[ImportMessage]] = ..., + repeated_nested_enum: Optional[Iterable[TestAllTypes.NestedEnum]] = ..., + repeated_foreign_enum: Optional[Iterable[ForeignEnum]] = ..., + repeated_string_piece: Optional[Iterable[Text]] = ..., + repeated_cord: Optional[Iterable[Text]] = ..., + repeated_lazy_message: Optional[Iterable[TestAllTypes.NestedMessage]] = ..., + oneof_uint32: Optional[int] = ..., + oneof_nested_message: Optional[TestAllTypes.NestedMessage] = ..., + oneof_string: Optional[Text] = ..., + oneof_bytes: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAllTypes: ... + + +class TestPackedTypes(Message): + packed_int32 = ... # type: RepeatedScalarFieldContainer[int] + packed_int64 = ... # type: RepeatedScalarFieldContainer[int] + packed_uint32 = ... # type: RepeatedScalarFieldContainer[int] + packed_uint64 = ... # type: RepeatedScalarFieldContainer[int] + packed_sint32 = ... # type: RepeatedScalarFieldContainer[int] + packed_sint64 = ... # type: RepeatedScalarFieldContainer[int] + packed_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + packed_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + packed_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + packed_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + packed_float = ... # type: RepeatedScalarFieldContainer[float] + packed_double = ... # type: RepeatedScalarFieldContainer[float] + packed_bool = ... # type: RepeatedScalarFieldContainer[bool] + packed_enum = ... # type: RepeatedScalarFieldContainer[ForeignEnum] + + def __init__(self, + packed_int32: Optional[Iterable[int]] = ..., + packed_int64: Optional[Iterable[int]] = ..., + packed_uint32: Optional[Iterable[int]] = ..., + packed_uint64: Optional[Iterable[int]] = ..., + packed_sint32: Optional[Iterable[int]] = ..., + packed_sint64: Optional[Iterable[int]] = ..., + packed_fixed32: Optional[Iterable[int]] = ..., + packed_fixed64: Optional[Iterable[int]] = ..., + packed_sfixed32: Optional[Iterable[int]] = ..., + packed_sfixed64: Optional[Iterable[int]] = ..., + packed_float: Optional[Iterable[float]] = ..., + packed_double: Optional[Iterable[float]] = ..., + packed_bool: Optional[Iterable[bool]] = ..., + packed_enum: Optional[Iterable[ForeignEnum]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestPackedTypes: ... + + +class TestUnpackedTypes(Message): + repeated_int32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sint64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_fixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed32 = ... # type: RepeatedScalarFieldContainer[int] + repeated_sfixed64 = ... # type: RepeatedScalarFieldContainer[int] + repeated_float = ... # type: RepeatedScalarFieldContainer[float] + repeated_double = ... # type: RepeatedScalarFieldContainer[float] + repeated_bool = ... # type: RepeatedScalarFieldContainer[bool] + repeated_nested_enum = ... # type: RepeatedScalarFieldContainer[TestAllTypes.NestedEnum] + + def __init__(self, + repeated_int32: Optional[Iterable[int]] = ..., + repeated_int64: Optional[Iterable[int]] = ..., + repeated_uint32: Optional[Iterable[int]] = ..., + repeated_uint64: Optional[Iterable[int]] = ..., + repeated_sint32: Optional[Iterable[int]] = ..., + repeated_sint64: Optional[Iterable[int]] = ..., + repeated_fixed32: Optional[Iterable[int]] = ..., + repeated_fixed64: Optional[Iterable[int]] = ..., + repeated_sfixed32: Optional[Iterable[int]] = ..., + repeated_sfixed64: Optional[Iterable[int]] = ..., + repeated_float: Optional[Iterable[float]] = ..., + repeated_double: Optional[Iterable[float]] = ..., + repeated_bool: Optional[Iterable[bool]] = ..., + repeated_nested_enum: Optional[Iterable[TestAllTypes.NestedEnum]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestUnpackedTypes: ... + + +class NestedTestAllTypes(Message): + + @property + def child(self) -> NestedTestAllTypes: ... + + @property + def payload(self) -> TestAllTypes: ... + + @property + def repeated_child( + self) -> RepeatedCompositeFieldContainer[NestedTestAllTypes]: ... + + def __init__(self, + child: Optional[NestedTestAllTypes] = ..., + payload: Optional[TestAllTypes] = ..., + repeated_child: Optional[Iterable[NestedTestAllTypes]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> NestedTestAllTypes: ... + + +class ForeignMessage(Message): + c = ... # type: int + + def __init__(self, + c: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> ForeignMessage: ... + + +class TestEmptyMessage(Message): + + def __init__(self, + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEmptyMessage: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/util/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/util/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/util/json_format_proto3_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/util/json_format_proto3_pb2.pyi new file mode 100644 index 000000000..0921ce84c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/util/json_format_proto3_pb2.pyi @@ -0,0 +1,659 @@ +from google.protobuf.any_pb2 import ( + Any, +) +from google.protobuf.duration_pb2 import ( + Duration, +) +from google.protobuf.field_mask_pb2 import ( + FieldMask, +) +from google.protobuf.internal.containers import ( + RepeatedCompositeFieldContainer, + RepeatedScalarFieldContainer, +) +from google.protobuf.message import ( + Message, +) +from google.protobuf.struct_pb2 import ( + ListValue, + Struct, + Value, +) +from google.protobuf.timestamp_pb2 import ( + Timestamp, +) +from google.protobuf.unittest_pb2 import ( + TestAllExtensions, +) +from google.protobuf.wrappers_pb2 import ( + BoolValue, + BytesValue, + DoubleValue, + FloatValue, + Int32Value, + Int64Value, + StringValue, + UInt32Value, + UInt64Value, +) +from typing import ( + Iterable, + List, + Mapping, + MutableMapping, + Optional, + Text, + Tuple, + cast, +) + + +class EnumType(int): + + @classmethod + def Name(cls, number: int) -> bytes: ... + + @classmethod + def Value(cls, name: bytes) -> EnumType: ... + + @classmethod + def keys(cls) -> List[bytes]: ... + + @classmethod + def values(cls) -> List[EnumType]: ... + + @classmethod + def items(cls) -> List[Tuple[bytes, EnumType]]: ... + + +FOO: EnumType +BAR: EnumType + + +class MessageType(Message): + value = ... # type: int + + def __init__(self, + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> MessageType: ... + + +class TestMessage(Message): + bool_value = ... # type: bool + int32_value = ... # type: int + int64_value = ... # type: int + uint32_value = ... # type: int + uint64_value = ... # type: int + float_value = ... # type: float + double_value = ... # type: float + string_value = ... # type: Text + bytes_value = ... # type: bytes + enum_value = ... # type: EnumType + repeated_bool_value = ... # type: RepeatedScalarFieldContainer[bool] + repeated_int32_value = ... # type: RepeatedScalarFieldContainer[int] + repeated_int64_value = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint32_value = ... # type: RepeatedScalarFieldContainer[int] + repeated_uint64_value = ... # type: RepeatedScalarFieldContainer[int] + repeated_float_value = ... # type: RepeatedScalarFieldContainer[float] + repeated_double_value = ... # type: RepeatedScalarFieldContainer[float] + repeated_string_value = ... # type: RepeatedScalarFieldContainer[Text] + repeated_bytes_value = ... # type: RepeatedScalarFieldContainer[bytes] + repeated_enum_value = ... # type: RepeatedScalarFieldContainer[EnumType] + + @property + def message_value(self) -> MessageType: ... + + @property + def repeated_message_value( + self) -> RepeatedCompositeFieldContainer[MessageType]: ... + + def __init__(self, + bool_value: Optional[bool] = ..., + int32_value: Optional[int] = ..., + int64_value: Optional[int] = ..., + uint32_value: Optional[int] = ..., + uint64_value: Optional[int] = ..., + float_value: Optional[float] = ..., + double_value: Optional[float] = ..., + string_value: Optional[Text] = ..., + bytes_value: Optional[bytes] = ..., + enum_value: Optional[EnumType] = ..., + message_value: Optional[MessageType] = ..., + repeated_bool_value: Optional[Iterable[bool]] = ..., + repeated_int32_value: Optional[Iterable[int]] = ..., + repeated_int64_value: Optional[Iterable[int]] = ..., + repeated_uint32_value: Optional[Iterable[int]] = ..., + repeated_uint64_value: Optional[Iterable[int]] = ..., + repeated_float_value: Optional[Iterable[float]] = ..., + repeated_double_value: Optional[Iterable[float]] = ..., + repeated_string_value: Optional[Iterable[Text]] = ..., + repeated_bytes_value: Optional[Iterable[bytes]] = ..., + repeated_enum_value: Optional[Iterable[EnumType]] = ..., + repeated_message_value: Optional[Iterable[MessageType]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMessage: ... + + +class TestOneof(Message): + oneof_int32_value = ... # type: int + oneof_string_value = ... # type: Text + oneof_bytes_value = ... # type: bytes + oneof_enum_value = ... # type: EnumType + + @property + def oneof_message_value(self) -> MessageType: ... + + def __init__(self, + oneof_int32_value: Optional[int] = ..., + oneof_string_value: Optional[Text] = ..., + oneof_bytes_value: Optional[bytes] = ..., + oneof_enum_value: Optional[EnumType] = ..., + oneof_message_value: Optional[MessageType] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestOneof: ... + + +class TestMap(Message): + + class BoolMapEntry(Message): + key = ... # type: bool + value = ... # type: int + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.BoolMapEntry: ... + + class Int32MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.Int32MapEntry: ... + + class Int64MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.Int64MapEntry: ... + + class Uint32MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.Uint32MapEntry: ... + + class Uint64MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.Uint64MapEntry: ... + + class StringMapEntry(Message): + key = ... # type: Text + value = ... # type: int + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap.StringMapEntry: ... + + @property + def bool_map(self) -> MutableMapping[bool, int]: ... + + @property + def int32_map(self) -> MutableMapping[int, int]: ... + + @property + def int64_map(self) -> MutableMapping[int, int]: ... + + @property + def uint32_map(self) -> MutableMapping[int, int]: ... + + @property + def uint64_map(self) -> MutableMapping[int, int]: ... + + @property + def string_map(self) -> MutableMapping[Text, int]: ... + + def __init__(self, + bool_map: Optional[Mapping[bool, int]]=..., + int32_map: Optional[Mapping[int, int]]=..., + int64_map: Optional[Mapping[int, int]]=..., + uint32_map: Optional[Mapping[int, int]]=..., + uint64_map: Optional[Mapping[int, int]]=..., + string_map: Optional[Mapping[Text, int]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestMap: ... + + +class TestNestedMap(Message): + + class BoolMapEntry(Message): + key = ... # type: bool + value = ... # type: int + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.BoolMapEntry: ... + + class Int32MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.Int32MapEntry: ... + + class Int64MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.Int64MapEntry: ... + + class Uint32MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.Uint32MapEntry: ... + + class Uint64MapEntry(Message): + key = ... # type: int + value = ... # type: int + + def __init__(self, + key: Optional[int] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.Uint64MapEntry: ... + + class StringMapEntry(Message): + key = ... # type: Text + value = ... # type: int + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.StringMapEntry: ... + + class MapMapEntry(Message): + key = ... # type: Text + + @property + def value(self) -> TestNestedMap: ... + + def __init__(self, + key: Optional[Text] = ..., + value: Optional[TestNestedMap] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap.MapMapEntry: ... + + @property + def bool_map(self) -> MutableMapping[bool, int]: ... + + @property + def int32_map(self) -> MutableMapping[int, int]: ... + + @property + def int64_map(self) -> MutableMapping[int, int]: ... + + @property + def uint32_map(self) -> MutableMapping[int, int]: ... + + @property + def uint64_map(self) -> MutableMapping[int, int]: ... + + @property + def string_map(self) -> MutableMapping[Text, int]: ... + + @property + def map_map(self) -> MutableMapping[Text, TestNestedMap]: ... + + def __init__(self, + bool_map: Optional[Mapping[bool, int]]=..., + int32_map: Optional[Mapping[int, int]]=..., + int64_map: Optional[Mapping[int, int]]=..., + uint32_map: Optional[Mapping[int, int]]=..., + uint64_map: Optional[Mapping[int, int]]=..., + string_map: Optional[Mapping[Text, int]]=..., + map_map: Optional[Mapping[Text, TestNestedMap]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestNestedMap: ... + + +class TestWrapper(Message): + + @property + def bool_value(self) -> BoolValue: ... + + @property + def int32_value(self) -> Int32Value: ... + + @property + def int64_value(self) -> Int64Value: ... + + @property + def uint32_value(self) -> UInt32Value: ... + + @property + def uint64_value(self) -> UInt64Value: ... + + @property + def float_value(self) -> FloatValue: ... + + @property + def double_value(self) -> DoubleValue: ... + + @property + def string_value(self) -> StringValue: ... + + @property + def bytes_value(self) -> BytesValue: ... + + @property + def repeated_bool_value( + self) -> RepeatedCompositeFieldContainer[BoolValue]: ... + + @property + def repeated_int32_value( + self) -> RepeatedCompositeFieldContainer[Int32Value]: ... + + @property + def repeated_int64_value( + self) -> RepeatedCompositeFieldContainer[Int64Value]: ... + + @property + def repeated_uint32_value( + self) -> RepeatedCompositeFieldContainer[UInt32Value]: ... + + @property + def repeated_uint64_value( + self) -> RepeatedCompositeFieldContainer[UInt64Value]: ... + + @property + def repeated_float_value( + self) -> RepeatedCompositeFieldContainer[FloatValue]: ... + + @property + def repeated_double_value( + self) -> RepeatedCompositeFieldContainer[DoubleValue]: ... + + @property + def repeated_string_value( + self) -> RepeatedCompositeFieldContainer[StringValue]: ... + + @property + def repeated_bytes_value( + self) -> RepeatedCompositeFieldContainer[BytesValue]: ... + + def __init__(self, + bool_value: Optional[BoolValue] = ..., + int32_value: Optional[Int32Value] = ..., + int64_value: Optional[Int64Value] = ..., + uint32_value: Optional[UInt32Value] = ..., + uint64_value: Optional[UInt64Value] = ..., + float_value: Optional[FloatValue] = ..., + double_value: Optional[DoubleValue] = ..., + string_value: Optional[StringValue] = ..., + bytes_value: Optional[BytesValue] = ..., + repeated_bool_value: Optional[Iterable[BoolValue]] = ..., + repeated_int32_value: Optional[Iterable[Int32Value]] = ..., + repeated_int64_value: Optional[Iterable[Int64Value]] = ..., + repeated_uint32_value: Optional[Iterable[UInt32Value]] = ..., + repeated_uint64_value: Optional[Iterable[UInt64Value]] = ..., + repeated_float_value: Optional[Iterable[FloatValue]] = ..., + repeated_double_value: Optional[Iterable[DoubleValue]] = ..., + repeated_string_value: Optional[Iterable[StringValue]] = ..., + repeated_bytes_value: Optional[Iterable[BytesValue]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestWrapper: ... + + +class TestTimestamp(Message): + + @property + def value(self) -> Timestamp: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[Timestamp]: ... + + def __init__(self, + value: Optional[Timestamp] = ..., + repeated_value: Optional[Iterable[Timestamp]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestTimestamp: ... + + +class TestDuration(Message): + + @property + def value(self) -> Duration: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[Duration]: ... + + def __init__(self, + value: Optional[Duration] = ..., + repeated_value: Optional[Iterable[Duration]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestDuration: ... + + +class TestFieldMask(Message): + + @property + def value(self) -> FieldMask: ... + + def __init__(self, + value: Optional[FieldMask] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestFieldMask: ... + + +class TestStruct(Message): + + @property + def value(self) -> Struct: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[Struct]: ... + + def __init__(self, + value: Optional[Struct] = ..., + repeated_value: Optional[Iterable[Struct]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestStruct: ... + + +class TestAny(Message): + + @property + def value(self) -> Any: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[Any]: ... + + def __init__(self, + value: Optional[Any] = ..., + repeated_value: Optional[Iterable[Any]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestAny: ... + + +class TestValue(Message): + + @property + def value(self) -> Value: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[Value]: ... + + def __init__(self, + value: Optional[Value] = ..., + repeated_value: Optional[Iterable[Value]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestValue: ... + + +class TestListValue(Message): + + @property + def value(self) -> ListValue: ... + + @property + def repeated_value(self) -> RepeatedCompositeFieldContainer[ListValue]: ... + + def __init__(self, + value: Optional[ListValue] = ..., + repeated_value: Optional[Iterable[ListValue]] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestListValue: ... + + +class TestBoolValue(Message): + + class BoolMapEntry(Message): + key = ... # type: bool + value = ... # type: int + + def __init__(self, + key: Optional[bool] = ..., + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestBoolValue.BoolMapEntry: ... + bool_value = ... # type: bool + + @property + def bool_map(self) -> MutableMapping[bool, int]: ... + + def __init__(self, + bool_value: Optional[bool] = ..., + bool_map: Optional[Mapping[bool, int]]=..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestBoolValue: ... + + +class TestCustomJsonName(Message): + value = ... # type: int + + def __init__(self, + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestCustomJsonName: ... + + +class TestExtensions(Message): + + @property + def extensions(self) -> TestAllExtensions: ... + + def __init__(self, + extensions: Optional[TestAllExtensions] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestExtensions: ... + + +class TestEnumValue(Message): + enum_value1 = ... # type: EnumType + enum_value2 = ... # type: EnumType + enum_value3 = ... # type: EnumType + + def __init__(self, + enum_value1: Optional[EnumType] = ..., + enum_value2: Optional[EnumType] = ..., + enum_value3: Optional[EnumType] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> TestEnumValue: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/wrappers_pb2.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/wrappers_pb2.pyi new file mode 100644 index 000000000..ded665202 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/google/protobuf/wrappers_pb2.pyi @@ -0,0 +1,106 @@ +from google.protobuf.message import ( + Message, +) +from typing import ( + Optional, + Text, +) + + +class DoubleValue(Message): + value = ... # type: float + + def __init__(self, + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> DoubleValue: ... + + +class FloatValue(Message): + value = ... # type: float + + def __init__(self, + value: Optional[float] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> FloatValue: ... + + +class Int64Value(Message): + value = ... # type: int + + def __init__(self, + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Int64Value: ... + + +class UInt64Value(Message): + value = ... # type: int + + def __init__(self, + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> UInt64Value: ... + + +class Int32Value(Message): + value = ... # type: int + + def __init__(self, + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> Int32Value: ... + + +class UInt32Value(Message): + value = ... # type: int + + def __init__(self, + value: Optional[int] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> UInt32Value: ... + + +class BoolValue(Message): + value = ... # type: bool + + def __init__(self, + value: Optional[bool] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> BoolValue: ... + + +class StringValue(Message): + value = ... # type: Text + + def __init__(self, + value: Optional[Text] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> StringValue: ... + + +class BytesValue(Message): + value = ... # type: bytes + + def __init__(self, + value: Optional[bytes] = ..., + ) -> None: ... + + @classmethod + def FromString(cls, s: bytes) -> BytesValue: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/__init__.pyi new file mode 100644 index 000000000..063f73d8d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/__init__.pyi @@ -0,0 +1,7 @@ +from jinja2.environment import Environment as Environment, Template as Template +from jinja2.loaders import BaseLoader as BaseLoader, FileSystemLoader as FileSystemLoader, PackageLoader as PackageLoader, DictLoader as DictLoader, FunctionLoader as FunctionLoader, PrefixLoader as PrefixLoader, ChoiceLoader as ChoiceLoader, ModuleLoader as ModuleLoader +from jinja2.bccache import BytecodeCache as BytecodeCache, FileSystemBytecodeCache as FileSystemBytecodeCache, MemcachedBytecodeCache as MemcachedBytecodeCache +from jinja2.runtime import Undefined as Undefined, DebugUndefined as DebugUndefined, StrictUndefined as StrictUndefined, make_logging_undefined as make_logging_undefined +from jinja2.exceptions import TemplateError as TemplateError, UndefinedError as UndefinedError, TemplateNotFound as TemplateNotFound, TemplatesNotFound as TemplatesNotFound, TemplateSyntaxError as TemplateSyntaxError, TemplateAssertionError as TemplateAssertionError +from jinja2.filters import environmentfilter as environmentfilter, contextfilter as contextfilter, evalcontextfilter as evalcontextfilter +from jinja2.utils import Markup as Markup, escape as escape, clear_caches as clear_caches, environmentfunction as environmentfunction, evalcontextfunction as evalcontextfunction, contextfunction as contextfunction, is_undefined as is_undefined, select_autoescape as select_autoescape diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/_compat.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/_compat.pyi new file mode 100644 index 000000000..86283185e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/_compat.pyi @@ -0,0 +1,34 @@ +from typing import Any, Optional +import sys + +if sys.version_info[0] >= 3: + from io import BytesIO + from urllib.parse import quote_from_bytes as url_quote +else: + from cStringIO import StringIO as BytesIO + from urllib import quote as url_quote + +PY2 = ... # type: Any +PYPY = ... # type: Any +unichr = ... # type: Any +range_type = ... # type: Any +text_type = ... # type: Any +string_types = ... # type: Any +integer_types = ... # type: Any +iterkeys = ... # type: Any +itervalues = ... # type: Any +iteritems = ... # type: Any +NativeStringIO = ... # type: Any + +def reraise(tp, value, tb: Optional[Any] = ...): ... + +ifilter = ... # type: Any +imap = ... # type: Any +izip = ... # type: Any +intern = ... # type: Any +implements_iterator = ... # type: Any +implements_to_string = ... # type: Any +encode_filename = ... # type: Any +get_next = ... # type: Any + +def with_metaclass(meta, *bases): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/_stringdefs.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/_stringdefs.pyi new file mode 100644 index 000000000..26f798b2c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/_stringdefs.pyi @@ -0,0 +1,40 @@ +from typing import Any + +Cc = ... # type: str +Cf = ... # type: str +Cn = ... # type: str +Co = ... # type: str +Cs = ... # type: Any +Ll = ... # type: str +Lm = ... # type: str +Lo = ... # type: str +Lt = ... # type: str +Lu = ... # type: str +Mc = ... # type: str +Me = ... # type: str +Mn = ... # type: str +Nd = ... # type: str +Nl = ... # type: str +No = ... # type: str +Pc = ... # type: str +Pd = ... # type: str +Pe = ... # type: str +Pf = ... # type: str +Pi = ... # type: str +Po = ... # type: str +Ps = ... # type: str +Sc = ... # type: str +Sk = ... # type: str +Sm = ... # type: str +So = ... # type: str +Zl = ... # type: str +Zp = ... # type: str +Zs = ... # type: str +cats = ... # type: Any + +def combine(*args): ... + +xid_start = ... # type: str +xid_continue = ... # type: str + +def allexcept(*args): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/bccache.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/bccache.pyi new file mode 100644 index 000000000..58a6ea39a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/bccache.pyi @@ -0,0 +1,44 @@ +from typing import Any, Optional + +marshal_dump = ... # type: Any +marshal_load = ... # type: Any +bc_version = ... # type: int +bc_magic = ... # type: Any + +class Bucket: + environment = ... # type: Any + key = ... # type: Any + checksum = ... # type: Any + def __init__(self, environment, key, checksum) -> None: ... + code = ... # type: Any + def reset(self): ... + def load_bytecode(self, f): ... + def write_bytecode(self, f): ... + def bytecode_from_string(self, string): ... + def bytecode_to_string(self): ... + +class BytecodeCache: + def load_bytecode(self, bucket): ... + def dump_bytecode(self, bucket): ... + def clear(self): ... + def get_cache_key(self, name, filename: Optional[Any] = ...): ... + def get_source_checksum(self, source): ... + def get_bucket(self, environment, name, filename, source): ... + def set_bucket(self, bucket): ... + +class FileSystemBytecodeCache(BytecodeCache): + directory = ... # type: Any + pattern = ... # type: Any + def __init__(self, directory: Optional[Any] = ..., pattern: str = ...) -> None: ... + def load_bytecode(self, bucket): ... + def dump_bytecode(self, bucket): ... + def clear(self): ... + +class MemcachedBytecodeCache(BytecodeCache): + client = ... # type: Any + prefix = ... # type: Any + timeout = ... # type: Any + ignore_memcache_errors = ... # type: Any + def __init__(self, client, prefix: str = ..., timeout: Optional[Any] = ..., ignore_memcache_errors: bool = ...) -> None: ... + def load_bytecode(self, bucket): ... + def dump_bytecode(self, bucket): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/compiler.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/compiler.pyi new file mode 100644 index 000000000..09883e82c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/compiler.pyi @@ -0,0 +1,176 @@ +from typing import Any, Optional +from keyword import iskeyword as is_python_keyword +from jinja2.visitor import NodeVisitor + +operators = ... # type: Any +dict_item_iter = ... # type: str + +unoptimize_before_dead_code = ... # type: bool + +def generate(node, environment, name, filename, stream: Optional[Any] = ..., defer_init: bool = ...): ... +def has_safe_repr(value): ... +def find_undeclared(nodes, names): ... + +class Identifiers: + declared = ... # type: Any + outer_undeclared = ... # type: Any + undeclared = ... # type: Any + declared_locally = ... # type: Any + declared_parameter = ... # type: Any + def __init__(self) -> None: ... + def add_special(self, name): ... + def is_declared(self, name): ... + def copy(self): ... + +class Frame: + eval_ctx = ... # type: Any + identifiers = ... # type: Any + toplevel = ... # type: bool + rootlevel = ... # type: bool + require_output_check = ... # type: Any + buffer = ... # type: Any + block = ... # type: Any + assigned_names = ... # type: Any + parent = ... # type: Any + def __init__(self, eval_ctx, parent: Optional[Any] = ...) -> None: ... + def copy(self): ... + def inspect(self, nodes): ... + def find_shadowed(self, extra: Any = ...): ... + def inner(self): ... + def soft(self): ... + __copy__ = ... # type: Any + +class VisitorExit(RuntimeError): ... + +class DependencyFinderVisitor(NodeVisitor): + filters = ... # type: Any + tests = ... # type: Any + def __init__(self) -> None: ... + def visit_Filter(self, node): ... + def visit_Test(self, node): ... + def visit_Block(self, node): ... + +class UndeclaredNameVisitor(NodeVisitor): + names = ... # type: Any + undeclared = ... # type: Any + def __init__(self, names) -> None: ... + def visit_Name(self, node): ... + def visit_Block(self, node): ... + +class FrameIdentifierVisitor(NodeVisitor): + identifiers = ... # type: Any + def __init__(self, identifiers) -> None: ... + def visit_Name(self, node): ... + def visit_If(self, node): ... + def visit_Macro(self, node): ... + def visit_Import(self, node): ... + def visit_FromImport(self, node): ... + def visit_Assign(self, node): ... + def visit_For(self, node): ... + def visit_CallBlock(self, node): ... + def visit_FilterBlock(self, node): ... + def visit_AssignBlock(self, node): ... + def visit_Scope(self, node): ... + def visit_Block(self, node): ... + +class CompilerExit(Exception): ... + +class CodeGenerator(NodeVisitor): + environment = ... # type: Any + name = ... # type: Any + filename = ... # type: Any + stream = ... # type: Any + created_block_context = ... # type: bool + defer_init = ... # type: Any + import_aliases = ... # type: Any + blocks = ... # type: Any + extends_so_far = ... # type: int + has_known_extends = ... # type: bool + code_lineno = ... # type: int + tests = ... # type: Any + filters = ... # type: Any + debug_info = ... # type: Any + def __init__(self, environment, name, filename, stream: Optional[Any] = ..., defer_init: bool = ...) -> None: ... + def fail(self, msg, lineno): ... + def temporary_identifier(self): ... + def buffer(self, frame): ... + def return_buffer_contents(self, frame): ... + def indent(self): ... + def outdent(self, step: int = ...): ... + def start_write(self, frame, node: Optional[Any] = ...): ... + def end_write(self, frame): ... + def simple_write(self, s, frame, node: Optional[Any] = ...): ... + def blockvisit(self, nodes, frame): ... + def write(self, x): ... + def writeline(self, x, node: Optional[Any] = ..., extra: int = ...): ... + def newline(self, node: Optional[Any] = ..., extra: int = ...): ... + def signature(self, node, frame, extra_kwargs: Optional[Any] = ...): ... + def pull_locals(self, frame): ... + def pull_dependencies(self, nodes): ... + def unoptimize_scope(self, frame): ... + def push_scope(self, frame, extra_vars: Any = ...): ... + def pop_scope(self, aliases, frame): ... + def function_scoping(self, node, frame, children: Optional[Any] = ..., find_special: bool = ...): ... + def macro_body(self, node, frame, children: Optional[Any] = ...): ... + def macro_def(self, node, frame): ... + def position(self, node): ... + def visit_Template(self, node, frame: Optional[Any] = ...): ... + def visit_Block(self, node, frame): ... + def visit_Extends(self, node, frame): ... + def visit_Include(self, node, frame): ... + def visit_Import(self, node, frame): ... + def visit_FromImport(self, node, frame): ... + def visit_For(self, node, frame): ... + def visit_If(self, node, frame): ... + def visit_Macro(self, node, frame): ... + def visit_CallBlock(self, node, frame): ... + def visit_FilterBlock(self, node, frame): ... + def visit_ExprStmt(self, node, frame): ... + def visit_Output(self, node, frame): ... + def make_assignment_frame(self, frame): ... + def export_assigned_vars(self, frame, assignment_frame): ... + def visit_Assign(self, node, frame): ... + def visit_AssignBlock(self, node, frame): ... + def visit_Name(self, node, frame): ... + def visit_Const(self, node, frame): ... + def visit_TemplateData(self, node, frame): ... + def visit_Tuple(self, node, frame): ... + def visit_List(self, node, frame): ... + def visit_Dict(self, node, frame): ... + def binop(operator, interceptable: bool = ...): ... + def uaop(operator, interceptable: bool = ...): ... + visit_Add = ... # type: Any + visit_Sub = ... # type: Any + visit_Mul = ... # type: Any + visit_Div = ... # type: Any + visit_FloorDiv = ... # type: Any + visit_Pow = ... # type: Any + visit_Mod = ... # type: Any + visit_And = ... # type: Any + visit_Or = ... # type: Any + visit_Pos = ... # type: Any + visit_Neg = ... # type: Any + visit_Not = ... # type: Any + def visit_Concat(self, node, frame): ... + def visit_Compare(self, node, frame): ... + def visit_Operand(self, node, frame): ... + def visit_Getattr(self, node, frame): ... + def visit_Getitem(self, node, frame): ... + def visit_Slice(self, node, frame): ... + def visit_Filter(self, node, frame): ... + def visit_Test(self, node, frame): ... + def visit_CondExpr(self, node, frame): ... + def visit_Call(self, node, frame, forward_caller: bool = ...): ... + def visit_Keyword(self, node, frame): ... + def visit_MarkSafe(self, node, frame): ... + def visit_MarkSafeIfAutoescape(self, node, frame): ... + def visit_EnvironmentAttribute(self, node, frame): ... + def visit_ExtensionAttribute(self, node, frame): ... + def visit_ImportedName(self, node, frame): ... + def visit_InternalName(self, node, frame): ... + def visit_ContextReference(self, node, frame): ... + def visit_Continue(self, node, frame): ... + def visit_Break(self, node, frame): ... + def visit_Scope(self, node, frame): ... + def visit_EvalContextModifier(self, node, frame): ... + def visit_ScopedEvalContextModifier(self, node, frame): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/constants.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/constants.pyi new file mode 100644 index 000000000..dfb7539ed --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/constants.pyi @@ -0,0 +1 @@ +LOREM_IPSUM_WORDS = ... # type: str diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/debug.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/debug.pyi new file mode 100644 index 000000000..db0af4637 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/debug.pyi @@ -0,0 +1,37 @@ +from typing import Any, Optional + +tproxy = ... # type: Any +raise_helper = ... # type: str + +class TracebackFrameProxy: + tb = ... # type: Any + def __init__(self, tb) -> None: ... + @property + def tb_next(self): ... + def set_next(self, next): ... + @property + def is_jinja_frame(self): ... + def __getattr__(self, name): ... + +def make_frame_proxy(frame): ... + +class ProcessedTraceback: + exc_type = ... # type: Any + exc_value = ... # type: Any + frames = ... # type: Any + def __init__(self, exc_type, exc_value, frames) -> None: ... + def render_as_text(self, limit: Optional[Any] = ...): ... + def render_as_html(self, full: bool = ...): ... + @property + def is_template_syntax_error(self): ... + @property + def exc_info(self): ... + @property + def standard_exc_info(self): ... + +def make_traceback(exc_info, source_hint: Optional[Any] = ...): ... +def translate_syntax_error(error, source: Optional[Any] = ...): ... +def translate_exception(exc_info, initial_skip: int = ...): ... +def fake_exc_info(exc_info, filename, lineno): ... + +tb_set_next = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/defaults.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/defaults.pyi new file mode 100644 index 000000000..3f440066c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/defaults.pyi @@ -0,0 +1,21 @@ +from typing import Any +from jinja2.filters import FILTERS as DEFAULT_FILTERS +from jinja2.tests import TESTS as DEFAULT_TESTS + +BLOCK_START_STRING = ... # type: str +BLOCK_END_STRING = ... # type: str +VARIABLE_START_STRING = ... # type: str +VARIABLE_END_STRING = ... # type: str +COMMENT_START_STRING = ... # type: str +COMMENT_END_STRING = ... # type: str +LINE_STATEMENT_PREFIX = ... # type: Any +LINE_COMMENT_PREFIX = ... # type: Any +TRIM_BLOCKS = ... # type: bool +LSTRIP_BLOCKS = ... # type: bool +NEWLINE_SEQUENCE = ... # type: str +KEEP_TRAILING_NEWLINE = ... # type: bool +DEFAULT_NAMESPACE = ... # type: Any + +# Names in __all__ with no definition: +# DEFAULT_FILTERS +# DEFAULT_TESTS diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/environment.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/environment.pyi new file mode 100644 index 000000000..8101093cb --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/environment.pyi @@ -0,0 +1,125 @@ +import sys +from typing import Any, Callable, Dict, Iterator, List, Optional, Text, Type, Union + +from .bccache import BytecodeCache +from .loaders import BaseLoader +from .runtime import Context, Undefined + +if sys.version_info >= (3, 6): + from typing import Awaitable, AsyncIterator + +def get_spontaneous_environment(*args): ... +def create_cache(size): ... +def copy_cache(cache): ... +def load_extensions(environment, extensions): ... + +class Environment: + sandboxed = ... # type: bool + overlayed = ... # type: bool + linked_to = ... # type: Any + shared = ... # type: bool + exception_handler = ... # type: Any + exception_formatter = ... # type: Any + code_generator_class = ... # type: Any + context_class = ... # type: Any + block_start_string = ... # type: Text + block_end_string = ... # type: Text + variable_start_string = ... # type: Text + variable_end_string = ... # type: Text + comment_start_string = ... # type: Text + comment_end_string = ... # type: Text + line_statement_prefix = ... # type: Text + line_comment_prefix = ... # type: Text + trim_blocks = ... # type: bool + lstrip_blocks = ... # type: Any + newline_sequence = ... # type: Text + keep_trailing_newline = ... # type: bool + undefined = ... # type: Type[Undefined] + optimized = ... # type: bool + finalize = ... # type: Callable + autoescape = ... # type: Any + filters = ... # type: Any + tests = ... # type: Any + globals = ... # type: Dict[str, Any] + loader = ... # type: BaseLoader + cache = ... # type: Any + bytecode_cache = ... # type: BytecodeCache + auto_reload = ... # type: bool + extensions = ... # type: List + def __init__(self, block_start_string: Text = ..., block_end_string: Text = ..., variable_start_string: Text = ..., variable_end_string: Text = ..., comment_start_string: Any = ..., comment_end_string: Text = ..., line_statement_prefix: Text = ..., line_comment_prefix: Text = ..., trim_blocks: bool = ..., lstrip_blocks: bool = ..., newline_sequence: Text = ..., keep_trailing_newline: bool = ..., extensions: List = ..., optimized: bool = ..., undefined: Type[Undefined] = ..., finalize: Optional[Callable] = ..., autoescape: Union[bool, Callable[[str], bool]] = ..., loader: Optional[BaseLoader] = ..., cache_size: int = ..., auto_reload: bool = ..., bytecode_cache: Optional[BytecodeCache] = ..., enable_async: bool = ...) -> None: ... + def add_extension(self, extension): ... + def extend(self, **attributes): ... + def overlay(self, block_start_string: Text = ..., block_end_string: Text = ..., variable_start_string: Text = ..., variable_end_string: Text = ..., comment_start_string: Any = ..., comment_end_string: Text = ..., line_statement_prefix: Text = ..., line_comment_prefix: Text = ..., trim_blocks: bool = ..., lstrip_blocks: bool = ..., extensions: List = ..., optimized: bool = ..., undefined: Type[Undefined] = ..., finalize: Callable = ..., autoescape: bool = ..., loader: Optional[BaseLoader] = ..., cache_size: int = ..., auto_reload: bool = ..., bytecode_cache: Optional[BytecodeCache] = ...): ... + lexer = ... # type: Any + def iter_extensions(self): ... + def getitem(self, obj, argument): ... + def getattr(self, obj, attribute): ... + def call_filter(self, name, value, args: Optional[Any] = ..., kwargs: Optional[Any] = ..., context: Optional[Any] = ..., eval_ctx: Optional[Any] = ...): ... + def call_test(self, name, value, args: Optional[Any] = ..., kwargs: Optional[Any] = ...): ... + def parse(self, source, name: Optional[Any] = ..., filename: Optional[Any] = ...): ... + def lex(self, source, name: Optional[Any] = ..., filename: Optional[Any] = ...): ... + def preprocess(self, source: Text, name: Optional[Any] = ..., filename: Optional[Any] = ...): ... + def compile(self, source, name: Optional[Any] = ..., filename: Optional[Any] = ..., raw: bool = ..., defer_init: bool = ...): ... + def compile_expression(self, source: Text, undefined_to_none: bool = ...): ... + def compile_templates(self, target, extensions: Optional[Any] = ..., filter_func: Optional[Any] = ..., zip: str = ..., log_function: Optional[Any] = ..., ignore_errors: bool = ..., py_compile: bool = ...): ... + def list_templates(self, extensions: Optional[Any] = ..., filter_func: Optional[Any] = ...): ... + def handle_exception(self, exc_info: Optional[Any] = ..., rendered: bool = ..., source_hint: Optional[Any] = ...): ... + def join_path(self, template: Union[Template, Text], parent: Text) -> Text: ... + def get_template(self, name: Union[Template, Text], parent: Optional[Text] = ..., globals: Optional[Any] = ...) -> Template: ... + def select_template(self, names: List[Union[Template, Text]], parent: Optional[Text] = ..., globals: Optional[Dict[str, Any]] = ...) -> Template: ... + def get_or_select_template(self, template_name_or_list: Union[Union[Template, Text], List[Union[Template, Text]]], parent: Optional[Text] = ..., globals: Optional[Dict[str, Any]] = ...) -> Template: ... + def from_string(self, source: Text, globals: Optional[Dict[str, Any]] = ..., template_class: Optional[Type[Template]] = ...) -> Template: ... + def make_globals(self, d: Optional[Dict[str, Any]]) -> Dict[str, Any]: ... + + # Frequently added extensions are included here: + # from InternationalizationExtension: + def install_gettext_translations(self, translations: Any, newstyle: Optional[bool]): ... + def install_null_translations(self, newstyle: Optional[bool]): ... + def install_gettext_callables(self, gettext: Callable, ngettext: Callable, + newstyle: Optional[bool]): ... + def uninstall_gettext_translations(self, translations: Any): ... + def extract_translations(self, source: Any, gettext_functions: Any): ... + newstyle_gettext = ... # type: bool + +class Template: + def __new__(cls, source, block_start_string: Any = ..., block_end_string: Any = ..., variable_start_string: Any = ..., variable_end_string: Any = ..., comment_start_string: Any = ..., comment_end_string: Any = ..., line_statement_prefix: Any = ..., line_comment_prefix: Any = ..., trim_blocks: Any = ..., lstrip_blocks: Any = ..., newline_sequence: Any = ..., keep_trailing_newline: Any = ..., extensions: Any = ..., optimized: bool = ..., undefined: Any = ..., finalize: Optional[Any] = ..., autoescape: bool = ...): ... + environment: Environment = ... + @classmethod + def from_code(cls, environment, code, globals, uptodate: Optional[Any] = ...): ... + @classmethod + def from_module_dict(cls, environment, module_dict, globals): ... + def render(self, *args, **kwargs) -> Text: ... + def stream(self, *args, **kwargs) -> TemplateStream: ... + def generate(self, *args, **kwargs) -> Iterator[Text]: ... + def new_context(self, vars: Optional[Dict[str, Any]] = ..., shared: bool = ..., locals: Optional[Dict[str, Any]] = ...) -> Context: ... + def make_module(self, vars: Optional[Dict[str, Any]] = ..., shared: bool = ..., locals: Optional[Dict[str, Any]] = ...) -> Context: ... + @property + def module(self) -> Any: ... + def get_corresponding_lineno(self, lineno): ... + @property + def is_up_to_date(self) -> bool: ... + @property + def debug_info(self): ... + + if sys.version_info >= (3, 6): + def render_async(self, *args, **kwargs) -> Awaitable[Text]: ... + def generate_async(self, *args, **kwargs) -> AsyncIterator[Text]: ... + + +class TemplateModule: + __name__ = ... # type: Any + def __init__(self, template, context) -> None: ... + def __html__(self): ... + +class TemplateExpression: + def __init__(self, template, undefined_to_none) -> None: ... + def __call__(self, *args, **kwargs): ... + +class TemplateStream: + def __init__(self, gen) -> None: ... + def dump(self, fp, encoding: Optional[Text] = ..., errors: Text = ...): ... + buffered = ... # type: bool + def disable_buffering(self) -> None: ... + def enable_buffering(self, size: int = ...) -> None: ... + def __iter__(self): ... + def __next__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/exceptions.pyi new file mode 100644 index 000000000..861e6bc41 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/exceptions.pyi @@ -0,0 +1,33 @@ +from typing import Any, Optional, Text + +class TemplateError(Exception): + def __init__(self, message: Optional[Text] = ...) -> None: ... + @property + def message(self): ... + def __unicode__(self): ... + @property + def message(self): ... + +class TemplateNotFound(IOError, LookupError, TemplateError): + message = ... # type: Any + name = ... # type: Any + templates = ... # type: Any + def __init__(self, name, message: Optional[Text] = ...) -> None: ... + +class TemplatesNotFound(TemplateNotFound): + templates = ... # type: Any + def __init__(self, names: Any = ..., message: Optional[Text] = ...) -> None: ... + +class TemplateSyntaxError(TemplateError): + lineno = ... # type: int + name = ... # type: Text + filename = ... # type: Text + source = ... # type: Text + translated = ... # type: bool + def __init__(self, message: Text, lineno: int, name: Optional[Text] = ..., filename: Optional[Text] = ...) -> None: ... + +class TemplateAssertionError(TemplateSyntaxError): ... +class TemplateRuntimeError(TemplateError): ... +class UndefinedError(TemplateRuntimeError): ... +class SecurityError(TemplateRuntimeError): ... +class FilterArgumentError(TemplateRuntimeError): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/ext.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/ext.pyi new file mode 100644 index 000000000..4fa28c7c0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/ext.pyi @@ -0,0 +1,58 @@ +from typing import Any, Optional + +GETTEXT_FUNCTIONS = ... # type: Any + +class ExtensionRegistry(type): + def __new__(cls, name, bases, d): ... + +class Extension: + tags = ... # type: Any + priority = ... # type: int + environment = ... # type: Any + def __init__(self, environment) -> None: ... + def bind(self, environment): ... + def preprocess(self, source, name, filename: Optional[Any] = ...): ... + def filter_stream(self, stream): ... + def parse(self, parser): ... + def attr(self, name, lineno: Optional[Any] = ...): ... + def call_method(self, name, args: Optional[Any] = ..., kwargs: Optional[Any] = ..., dyn_args: Optional[Any] = ..., dyn_kwargs: Optional[Any] = ..., lineno: Optional[Any] = ...): ... + +class InternationalizationExtension(Extension): + tags = ... # type: Any + def __init__(self, environment) -> None: ... + def parse(self, parser): ... + +class ExprStmtExtension(Extension): + tags = ... # type: Any + def parse(self, parser): ... + +class LoopControlExtension(Extension): + tags = ... # type: Any + def parse(self, parser): ... + +class WithExtension(Extension): + tags = ... # type: Any + def parse(self, parser): ... + +class AutoEscapeExtension(Extension): + tags = ... # type: Any + def parse(self, parser): ... + +def extract_from_ast(node, gettext_functions: Any = ..., babel_style: bool = ...): ... + +class _CommentFinder: + tokens = ... # type: Any + comment_tags = ... # type: Any + offset = ... # type: int + last_lineno = ... # type: int + def __init__(self, tokens, comment_tags) -> None: ... + def find_backwards(self, offset): ... + def find_comments(self, lineno): ... + +def babel_extract(fileobj, keywords, comment_tags, options): ... + +i18n = ... # type: Any +do = ... # type: Any +loopcontrols = ... # type: Any +with_ = ... # type: Any +autoescape = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/filters.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/filters.pyi new file mode 100644 index 000000000..d77fc22a5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/filters.pyi @@ -0,0 +1,57 @@ +from typing import Any, Optional + +def contextfilter(f): ... +def evalcontextfilter(f): ... +def environmentfilter(f): ... +def make_attrgetter(environment, attribute): ... +def do_forceescape(value): ... +def do_urlencode(value): ... +def do_replace(eval_ctx, s, old, new, count: Optional[Any] = ...): ... +def do_upper(s): ... +def do_lower(s): ... +def do_xmlattr(_eval_ctx, d, autospace: bool = ...): ... +def do_capitalize(s): ... +def do_title(s): ... +def do_dictsort(value, case_sensitive: bool = ..., by: str = ...): ... +def do_sort(environment, value, reverse: bool = ..., case_sensitive: bool = ..., attribute: Optional[Any] = ...): ... +def do_default(value, default_value: str = ..., boolean: bool = ...): ... +def do_join(eval_ctx, value, d: str = ..., attribute: Optional[Any] = ...): ... +def do_center(value, width: int = ...): ... +def do_first(environment, seq): ... +def do_last(environment, seq): ... +def do_random(environment, seq): ... +def do_filesizeformat(value, binary: bool = ...): ... +def do_pprint(value, verbose: bool = ...): ... +def do_urlize(eval_ctx, value, trim_url_limit: Optional[Any] = ..., nofollow: bool = ..., target: Optional[Any] = ...): ... +def do_indent(s, width: int = ..., indentfirst: bool = ...): ... +def do_truncate(s, length: int = ..., killwords: bool = ..., end: str = ...): ... +def do_wordwrap(environment, s, width: int = ..., break_long_words: bool = ..., wrapstring: Optional[Any] = ...): ... +def do_wordcount(s): ... +def do_int(value, default: int = ..., base: int = ...): ... +def do_float(value, default: float = ...): ... +def do_format(value, *args, **kwargs): ... +def do_trim(value): ... +def do_striptags(value): ... +def do_slice(value, slices, fill_with: Optional[Any] = ...): ... +def do_batch(value, linecount, fill_with: Optional[Any] = ...): ... +def do_round(value, precision: int = ..., method: str = ...): ... +def do_groupby(environment, value, attribute): ... + +class _GroupTuple(tuple): + grouper = ... # type: Any + list = ... # type: Any + def __new__(cls, xxx_todo_changeme): ... + +def do_sum(environment, iterable, attribute: Optional[Any] = ..., start: int = ...): ... +def do_list(value): ... +def do_mark_safe(value): ... +def do_mark_unsafe(value): ... +def do_reverse(value): ... +def do_attr(environment, obj, name): ... +def do_map(*args, **kwargs): ... +def do_select(*args, **kwargs): ... +def do_reject(*args, **kwargs): ... +def do_selectattr(*args, **kwargs): ... +def do_rejectattr(*args, **kwargs): ... + +FILTERS = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/lexer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/lexer.pyi new file mode 100644 index 000000000..89bf20d61 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/lexer.pyi @@ -0,0 +1,117 @@ +from typing import Any, Optional + +whitespace_re = ... # type: Any +string_re = ... # type: Any +integer_re = ... # type: Any +name_re = ... # type: Any +float_re = ... # type: Any +newline_re = ... # type: Any +TOKEN_ADD = ... # type: Any +TOKEN_ASSIGN = ... # type: Any +TOKEN_COLON = ... # type: Any +TOKEN_COMMA = ... # type: Any +TOKEN_DIV = ... # type: Any +TOKEN_DOT = ... # type: Any +TOKEN_EQ = ... # type: Any +TOKEN_FLOORDIV = ... # type: Any +TOKEN_GT = ... # type: Any +TOKEN_GTEQ = ... # type: Any +TOKEN_LBRACE = ... # type: Any +TOKEN_LBRACKET = ... # type: Any +TOKEN_LPAREN = ... # type: Any +TOKEN_LT = ... # type: Any +TOKEN_LTEQ = ... # type: Any +TOKEN_MOD = ... # type: Any +TOKEN_MUL = ... # type: Any +TOKEN_NE = ... # type: Any +TOKEN_PIPE = ... # type: Any +TOKEN_POW = ... # type: Any +TOKEN_RBRACE = ... # type: Any +TOKEN_RBRACKET = ... # type: Any +TOKEN_RPAREN = ... # type: Any +TOKEN_SEMICOLON = ... # type: Any +TOKEN_SUB = ... # type: Any +TOKEN_TILDE = ... # type: Any +TOKEN_WHITESPACE = ... # type: Any +TOKEN_FLOAT = ... # type: Any +TOKEN_INTEGER = ... # type: Any +TOKEN_NAME = ... # type: Any +TOKEN_STRING = ... # type: Any +TOKEN_OPERATOR = ... # type: Any +TOKEN_BLOCK_BEGIN = ... # type: Any +TOKEN_BLOCK_END = ... # type: Any +TOKEN_VARIABLE_BEGIN = ... # type: Any +TOKEN_VARIABLE_END = ... # type: Any +TOKEN_RAW_BEGIN = ... # type: Any +TOKEN_RAW_END = ... # type: Any +TOKEN_COMMENT_BEGIN = ... # type: Any +TOKEN_COMMENT_END = ... # type: Any +TOKEN_COMMENT = ... # type: Any +TOKEN_LINESTATEMENT_BEGIN = ... # type: Any +TOKEN_LINESTATEMENT_END = ... # type: Any +TOKEN_LINECOMMENT_BEGIN = ... # type: Any +TOKEN_LINECOMMENT_END = ... # type: Any +TOKEN_LINECOMMENT = ... # type: Any +TOKEN_DATA = ... # type: Any +TOKEN_INITIAL = ... # type: Any +TOKEN_EOF = ... # type: Any +operators = ... # type: Any +reverse_operators = ... # type: Any +operator_re = ... # type: Any +ignored_tokens = ... # type: Any +ignore_if_empty = ... # type: Any + +def describe_token(token): ... +def describe_token_expr(expr): ... +def count_newlines(value): ... +def compile_rules(environment): ... + +class Failure: + message = ... # type: Any + error_class = ... # type: Any + def __init__(self, message, cls: Any = ...) -> None: ... + def __call__(self, lineno, filename): ... + +class Token(tuple): + lineno = ... # type: Any + type = ... # type: Any + value = ... # type: Any + def __new__(cls, lineno, type, value): ... + def test(self, expr): ... + def test_any(self, *iterable): ... + +class TokenStreamIterator: + stream = ... # type: Any + def __init__(self, stream) -> None: ... + def __iter__(self): ... + def __next__(self): ... + +class TokenStream: + name = ... # type: Any + filename = ... # type: Any + closed = ... # type: bool + current = ... # type: Any + def __init__(self, generator, name, filename) -> None: ... + def __iter__(self): ... + def __bool__(self): ... + __nonzero__ = ... # type: Any + eos = ... # type: Any + def push(self, token): ... + def look(self): ... + def skip(self, n: int = ...): ... + def next_if(self, expr): ... + def skip_if(self, expr): ... + def __next__(self): ... + def close(self): ... + def expect(self, expr): ... + +def get_lexer(environment): ... + +class Lexer: + newline_sequence = ... # type: Any + keep_trailing_newline = ... # type: Any + rules = ... # type: Any + def __init__(self, environment) -> None: ... + def tokenize(self, source, name: Optional[Any] = ..., filename: Optional[Any] = ..., state: Optional[Any] = ...): ... + def wrap(self, stream, name: Optional[Any] = ..., filename: Optional[Any] = ...): ... + def tokeniter(self, source, name, filename: Optional[Any] = ..., state: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/loaders.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/loaders.pyi new file mode 100644 index 000000000..203390650 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/loaders.pyi @@ -0,0 +1,70 @@ +from typing import Any, Callable, Iterable, List, Optional, Text, Tuple, Union +from types import ModuleType + +from .environment import Environment + +def split_template_path(template: Text) -> List[Text]: ... + +class BaseLoader: + has_source_access = ... # type: bool + def get_source(self, environment, template): ... + def list_templates(self): ... + def load(self, environment, name, globals: Optional[Any] = ...): ... + +class FileSystemLoader(BaseLoader): + searchpath = ... # type: Text + encoding = ... # type: Any + followlinks = ... # type: Any + def __init__(self, searchpath: Union[Text, Iterable[Text]], encoding: Text = ..., followlinks: bool = ...) -> None: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def list_templates(self): ... + +class PackageLoader(BaseLoader): + encoding = ... # type: Text + manager = ... # type: Any + filesystem_bound = ... # type: Any + provider = ... # type: Any + package_path = ... # type: Any + def __init__(self, package_name: Text, package_path: Text = ..., encoding: Text = ...) -> None: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def list_templates(self): ... + +class DictLoader(BaseLoader): + mapping = ... # type: Any + def __init__(self, mapping) -> None: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def list_templates(self): ... + +class FunctionLoader(BaseLoader): + load_func = ... # type: Any + def __init__(self, load_func) -> None: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Optional[Text], Optional[Callable]]: ... + +class PrefixLoader(BaseLoader): + mapping = ... # type: Any + delimiter = ... # type: Any + def __init__(self, mapping, delimiter: str = ...) -> None: ... + def get_loader(self, template): ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def load(self, environment, name, globals: Optional[Any] = ...): ... + def list_templates(self): ... + +class ChoiceLoader(BaseLoader): + loaders = ... # type: Any + def __init__(self, loaders) -> None: ... + def get_source(self, environment: Environment, template: Text) -> Tuple[Text, Text, Callable]: ... + def load(self, environment, name, globals: Optional[Any] = ...): ... + def list_templates(self): ... + +class _TemplateModule(ModuleType): ... + +class ModuleLoader(BaseLoader): + has_source_access = ... # type: bool + module = ... # type: Any + package_name = ... # type: Any + def __init__(self, path) -> None: ... + @staticmethod + def get_template_key(name): ... + @staticmethod + def get_module_filename(name): ... + def load(self, environment, name, globals: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/meta.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/meta.pyi new file mode 100644 index 000000000..0e0b8499a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/meta.pyi @@ -0,0 +1,11 @@ +from typing import Any +from jinja2.compiler import CodeGenerator + +class TrackingCodeGenerator(CodeGenerator): + undeclared_identifiers = ... # type: Any + def __init__(self, environment) -> None: ... + def write(self, x): ... + def pull_locals(self, frame): ... + +def find_undeclared_variables(ast): ... +def find_referenced_templates(ast): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/nodes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/nodes.pyi new file mode 100644 index 000000000..bbc315bbf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/nodes.pyi @@ -0,0 +1,250 @@ +from typing import Any, Optional + +class Impossible(Exception): ... + +class NodeType(type): + def __new__(cls, name, bases, d): ... + +class EvalContext: + environment = ... # type: Any + autoescape = ... # type: Any + volatile = ... # type: bool + def __init__(self, environment, template_name: Optional[Any] = ...) -> None: ... + def save(self): ... + def revert(self, old): ... + +def get_eval_context(node, ctx): ... + +class Node: + fields = ... # type: Any + attributes = ... # type: Any + abstract = ... # type: bool + def __init__(self, *fields, **attributes) -> None: ... + def iter_fields(self, exclude: Optional[Any] = ..., only: Optional[Any] = ...): ... + def iter_child_nodes(self, exclude: Optional[Any] = ..., only: Optional[Any] = ...): ... + def find(self, node_type): ... + def find_all(self, node_type): ... + def set_ctx(self, ctx): ... + def set_lineno(self, lineno, override: bool = ...): ... + def set_environment(self, environment): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + __hash__ = ... # type: Any + +class Stmt(Node): + abstract = ... # type: bool + +class Helper(Node): + abstract = ... # type: bool + +class Template(Node): + fields = ... # type: Any + +class Output(Stmt): + fields = ... # type: Any + +class Extends(Stmt): + fields = ... # type: Any + +class For(Stmt): + fields = ... # type: Any + +class If(Stmt): + fields = ... # type: Any + +class Macro(Stmt): + fields = ... # type: Any + +class CallBlock(Stmt): + fields = ... # type: Any + +class FilterBlock(Stmt): + fields = ... # type: Any + +class Block(Stmt): + fields = ... # type: Any + +class Include(Stmt): + fields = ... # type: Any + +class Import(Stmt): + fields = ... # type: Any + +class FromImport(Stmt): + fields = ... # type: Any + +class ExprStmt(Stmt): + fields = ... # type: Any + +class Assign(Stmt): + fields = ... # type: Any + +class AssignBlock(Stmt): + fields = ... # type: Any + +class Expr(Node): + abstract = ... # type: bool + def as_const(self, eval_ctx: Optional[Any] = ...): ... + def can_assign(self): ... + +class BinExpr(Expr): + fields = ... # type: Any + operator = ... # type: Any + abstract = ... # type: bool + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class UnaryExpr(Expr): + fields = ... # type: Any + operator = ... # type: Any + abstract = ... # type: bool + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Name(Expr): + fields = ... # type: Any + def can_assign(self): ... + +class Literal(Expr): + abstract = ... # type: bool + +class Const(Literal): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + @classmethod + def from_untrusted(cls, value, lineno: Optional[Any] = ..., environment: Optional[Any] = ...): ... + +class TemplateData(Literal): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Tuple(Literal): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + def can_assign(self): ... + +class List(Literal): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Dict(Literal): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Pair(Helper): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Keyword(Helper): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class CondExpr(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Filter(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Test(Expr): + fields = ... # type: Any + +class Call(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Getitem(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + def can_assign(self): ... + +class Getattr(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + def can_assign(self): ... + +class Slice(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Concat(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Compare(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Operand(Helper): + fields = ... # type: Any + +class Mul(BinExpr): + operator = ... # type: str + +class Div(BinExpr): + operator = ... # type: str + +class FloorDiv(BinExpr): + operator = ... # type: str + +class Add(BinExpr): + operator = ... # type: str + +class Sub(BinExpr): + operator = ... # type: str + +class Mod(BinExpr): + operator = ... # type: str + +class Pow(BinExpr): + operator = ... # type: str + +class And(BinExpr): + operator = ... # type: str + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Or(BinExpr): + operator = ... # type: str + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class Not(UnaryExpr): + operator = ... # type: str + +class Neg(UnaryExpr): + operator = ... # type: str + +class Pos(UnaryExpr): + operator = ... # type: str + +class EnvironmentAttribute(Expr): + fields = ... # type: Any + +class ExtensionAttribute(Expr): + fields = ... # type: Any + +class ImportedName(Expr): + fields = ... # type: Any + +class InternalName(Expr): + fields = ... # type: Any + def __init__(self) -> None: ... + +class MarkSafe(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class MarkSafeIfAutoescape(Expr): + fields = ... # type: Any + def as_const(self, eval_ctx: Optional[Any] = ...): ... + +class ContextReference(Expr): ... +class Continue(Stmt): ... +class Break(Stmt): ... + +class Scope(Stmt): + fields = ... # type: Any + +class EvalContextModifier(Stmt): + fields = ... # type: Any + +class ScopedEvalContextModifier(EvalContextModifier): + fields = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/optimizer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/optimizer.pyi new file mode 100644 index 000000000..dc23f728b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/optimizer.pyi @@ -0,0 +1,29 @@ +from typing import Any +from jinja2.visitor import NodeTransformer + +def optimize(node, environment): ... + +class Optimizer(NodeTransformer): + environment = ... # type: Any + def __init__(self, environment) -> None: ... + def visit_If(self, node): ... + def fold(self, node): ... + visit_Add = ... # type: Any + visit_Sub = ... # type: Any + visit_Mul = ... # type: Any + visit_Div = ... # type: Any + visit_FloorDiv = ... # type: Any + visit_Pow = ... # type: Any + visit_Mod = ... # type: Any + visit_And = ... # type: Any + visit_Or = ... # type: Any + visit_Pos = ... # type: Any + visit_Neg = ... # type: Any + visit_Not = ... # type: Any + visit_Compare = ... # type: Any + visit_Getitem = ... # type: Any + visit_Getattr = ... # type: Any + visit_Call = ... # type: Any + visit_Filter = ... # type: Any + visit_Test = ... # type: Any + visit_CondExpr = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/parser.pyi new file mode 100644 index 000000000..f698085a1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/parser.pyi @@ -0,0 +1,60 @@ +from typing import Any, Optional + +class Parser: + environment = ... # type: Any + stream = ... # type: Any + name = ... # type: Any + filename = ... # type: Any + closed = ... # type: bool + extensions = ... # type: Any + def __init__(self, environment, source, name: Optional[Any] = ..., filename: Optional[Any] = ..., state: Optional[Any] = ...) -> None: ... + def fail(self, msg, lineno: Optional[Any] = ..., exc: Any = ...): ... + def fail_unknown_tag(self, name, lineno: Optional[Any] = ...): ... + def fail_eof(self, end_tokens: Optional[Any] = ..., lineno: Optional[Any] = ...): ... + def is_tuple_end(self, extra_end_rules: Optional[Any] = ...): ... + def free_identifier(self, lineno: Optional[Any] = ...): ... + def parse_statement(self): ... + def parse_statements(self, end_tokens, drop_needle: bool = ...): ... + def parse_set(self): ... + def parse_for(self): ... + def parse_if(self): ... + def parse_block(self): ... + def parse_extends(self): ... + def parse_import_context(self, node, default): ... + def parse_include(self): ... + def parse_import(self): ... + def parse_from(self): ... + def parse_signature(self, node): ... + def parse_call_block(self): ... + def parse_filter_block(self): ... + def parse_macro(self): ... + def parse_print(self): ... + def parse_assign_target(self, with_tuple: bool = ..., name_only: bool = ..., extra_end_rules: Optional[Any] = ...): ... + def parse_expression(self, with_condexpr: bool = ...): ... + def parse_condexpr(self): ... + def parse_or(self): ... + def parse_and(self): ... + def parse_not(self): ... + def parse_compare(self): ... + def parse_add(self): ... + def parse_sub(self): ... + def parse_concat(self): ... + def parse_mul(self): ... + def parse_div(self): ... + def parse_floordiv(self): ... + def parse_mod(self): ... + def parse_pow(self): ... + def parse_unary(self, with_filter: bool = ...): ... + def parse_primary(self): ... + def parse_tuple(self, simplified: bool = ..., with_condexpr: bool = ..., extra_end_rules: Optional[Any] = ..., explicit_parentheses: bool = ...): ... + def parse_list(self): ... + def parse_dict(self): ... + def parse_postfix(self, node): ... + def parse_filter_expr(self, node): ... + def parse_subscript(self, node): ... + def parse_subscribed(self): ... + def parse_call(self, node): ... + def parse_filter(self, node, start_inline: bool = ...): ... + def parse_test(self, node): ... + def subparse(self, end_tokens: Optional[Any] = ...): ... + def parse(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/runtime.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/runtime.pyi new file mode 100644 index 000000000..34d06f4cd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/runtime.pyi @@ -0,0 +1,130 @@ +from typing import Any, Dict, Optional, Text, Union +from jinja2.utils import Markup as Markup, escape as escape, missing as missing, concat as concat +from jinja2.exceptions import TemplateRuntimeError as TemplateRuntimeError, TemplateNotFound as TemplateNotFound + +from jinja2.environment import Environment + +to_string = ... # type: Any +identity = ... # type: Any + +def markup_join(seq): ... +def unicode_join(seq): ... + +class TemplateReference: + def __init__(self, context) -> None: ... + def __getitem__(self, name): ... + +class Context: + parent = ... # type: Union[Context, Dict[str, Any]] + vars = ... # type: Dict[str, Any] + environment = ... # type: Environment + eval_ctx = ... # type: Any + exported_vars = ... # type: Any + name = ... # type: Text + blocks = ... # type: Dict[str, Any] + def __init__(self, environment: Environment, parent: Union[Context, Dict[str, Any]], name: Text, blocks: Dict[str, Any]) -> None: ... + def super(self, name, current): ... + def get(self, key, default: Optional[Any] = ...): ... + def resolve(self, key): ... + def get_exported(self): ... + def get_all(self): ... + def call(__self, __obj, *args, **kwargs): ... + def derived(self, locals: Optional[Any] = ...): ... + keys = ... # type: Any + values = ... # type: Any + items = ... # type: Any + iterkeys = ... # type: Any + itervalues = ... # type: Any + iteritems = ... # type: Any + def __contains__(self, name): ... + def __getitem__(self, key): ... + +class BlockReference: + name = ... # type: Any + def __init__(self, name, context, stack, depth) -> None: ... + @property + def super(self): ... + def __call__(self): ... + +class LoopContext: + index0 = ... # type: int + depth0 = ... # type: Any + def __init__(self, iterable, recurse: Optional[Any] = ..., depth0: int = ...) -> None: ... + def cycle(self, *args): ... + first = ... # type: Any + last = ... # type: Any + index = ... # type: Any + revindex = ... # type: Any + revindex0 = ... # type: Any + depth = ... # type: Any + def __len__(self): ... + def __iter__(self): ... + def loop(self, iterable): ... + __call__ = ... # type: Any + @property + def length(self): ... + +class LoopContextIterator: + context = ... # type: Any + def __init__(self, context) -> None: ... + def __iter__(self): ... + def __next__(self): ... + +class Macro: + name = ... # type: Any + arguments = ... # type: Any + defaults = ... # type: Any + catch_kwargs = ... # type: Any + catch_varargs = ... # type: Any + caller = ... # type: Any + def __init__(self, environment, func, name, arguments, defaults, catch_kwargs, catch_varargs, caller) -> None: ... + def __call__(self, *args, **kwargs): ... + +class Undefined: + def __init__(self, hint: Optional[Any] = ..., obj: Any = ..., name: Optional[Any] = ..., exc: Any = ...) -> None: ... + def __getattr__(self, name): ... + __add__ = ... # type: Any + __radd__ = ... # type: Any + __mul__ = ... # type: Any + __rmul__ = ... # type: Any + __div__ = ... # type: Any + __rdiv__ = ... # type: Any + __truediv__ = ... # type: Any + __rtruediv__ = ... # type: Any + __floordiv__ = ... # type: Any + __rfloordiv__ = ... # type: Any + __mod__ = ... # type: Any + __rmod__ = ... # type: Any + __pos__ = ... # type: Any + __neg__ = ... # type: Any + __call__ = ... # type: Any + __getitem__ = ... # type: Any + __lt__ = ... # type: Any + __le__ = ... # type: Any + __gt__ = ... # type: Any + __ge__ = ... # type: Any + __int__ = ... # type: Any + __float__ = ... # type: Any + __complex__ = ... # type: Any + __pow__ = ... # type: Any + __rpow__ = ... # type: Any + def __eq__(self, other): ... + def __ne__(self, other): ... + def __hash__(self): ... + def __len__(self): ... + def __iter__(self): ... + def __nonzero__(self): ... + __bool__ = ... # type: Any + +def make_logging_undefined(logger: Optional[Any] = ..., base: Optional[Any] = ...): ... + +class DebugUndefined(Undefined): ... + +class StrictUndefined(Undefined): + __iter__ = ... # type: Any + __len__ = ... # type: Any + __nonzero__ = ... # type: Any + __eq__ = ... # type: Any + __ne__ = ... # type: Any + __bool__ = ... # type: Any + __hash__ = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/sandbox.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/sandbox.pyi new file mode 100644 index 000000000..3c8a18896 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/sandbox.pyi @@ -0,0 +1,34 @@ +from typing import Any +from jinja2.environment import Environment + +MAX_RANGE = ... # type: int +UNSAFE_FUNCTION_ATTRIBUTES = ... # type: Any +UNSAFE_METHOD_ATTRIBUTES = ... # type: Any +UNSAFE_GENERATOR_ATTRIBUTES = ... # type: Any + +def safe_range(*args): ... +def unsafe(f): ... +def is_internal_attribute(obj, attr): ... +def modifies_known_mutable(obj, attr): ... + +class SandboxedEnvironment(Environment): + sandboxed = ... # type: bool + default_binop_table = ... # type: Any + default_unop_table = ... # type: Any + intercepted_binops = ... # type: Any + intercepted_unops = ... # type: Any + def intercept_unop(self, operator): ... + binop_table = ... # type: Any + unop_table = ... # type: Any + def __init__(self, *args, **kwargs) -> None: ... + def is_safe_attribute(self, obj, attr, value): ... + def is_safe_callable(self, obj): ... + def call_binop(self, context, operator, left, right): ... + def call_unop(self, context, operator, arg): ... + def getitem(self, obj, argument): ... + def getattr(self, obj, attribute): ... + def unsafe_undefined(self, obj, attribute): ... + def call(__self, __context, __obj, *args, **kwargs): ... + +class ImmutableSandboxedEnvironment(SandboxedEnvironment): + def is_safe_attribute(self, obj, attr, value): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/tests.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/tests.pyi new file mode 100644 index 000000000..db67c2563 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/tests.pyi @@ -0,0 +1,24 @@ +from typing import Any + +number_re = ... # type: Any +regex_type = ... # type: Any +test_callable = ... # type: Any + +def test_odd(value): ... +def test_even(value): ... +def test_divisibleby(value, num): ... +def test_defined(value): ... +def test_undefined(value): ... +def test_none(value): ... +def test_lower(value): ... +def test_upper(value): ... +def test_string(value): ... +def test_mapping(value): ... +def test_number(value): ... +def test_sequence(value): ... +def test_equalto(value, other): ... +def test_sameas(value, other): ... +def test_iterable(value): ... +def test_escaped(value): ... + +TESTS = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/utils.pyi new file mode 100644 index 000000000..196bab32c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/utils.pyi @@ -0,0 +1,61 @@ +from typing import Any, Callable, Iterable, Optional + +from markupsafe import Markup as Markup, escape as escape, soft_unicode as soft_unicode + +missing = ... # type: Any +internal_code = ... # type: Any +concat = ... # type: Any + +def contextfunction(f): ... +def evalcontextfunction(f): ... +def environmentfunction(f): ... +def internalcode(f): ... +def is_undefined(obj): ... +def select_autoescape(enabled_extensions: Iterable[str] = ..., disabled_extensions: Iterable[str] = ..., default_for_string: bool = ..., default: bool = ...) -> Callable[[str], bool]: ... +def consume(iterable): ... +def clear_caches(): ... +def import_string(import_name, silent: bool = ...): ... +def open_if_exists(filename, mode: str = ...): ... +def object_type_repr(obj): ... +def pformat(obj, verbose: bool = ...): ... +def urlize(text, trim_url_limit: Optional[Any] = ..., nofollow: bool = ..., target: Optional[Any] = ...): ... +def generate_lorem_ipsum(n: int = ..., html: bool = ..., min: int = ..., max: int = ...): ... +def unicode_urlencode(obj, charset: str = ..., for_qs: bool = ...): ... + +class LRUCache: + capacity = ... # type: Any + def __init__(self, capacity) -> None: ... + def __getnewargs__(self): ... + def copy(self): ... + def get(self, key, default: Optional[Any] = ...): ... + def setdefault(self, key, default: Optional[Any] = ...): ... + def clear(self): ... + def __contains__(self, key): ... + def __len__(self): ... + def __getitem__(self, key): ... + def __setitem__(self, key, value): ... + def __delitem__(self, key): ... + def items(self): ... + def iteritems(self): ... + def values(self): ... + def itervalue(self): ... + def keys(self): ... + def iterkeys(self): ... + __iter__ = ... # type: Any + def __reversed__(self): ... + __copy__ = ... # type: Any + +class Cycler: + items = ... # type: Any + def __init__(self, *items) -> None: ... + pos = ... # type: int + def reset(self): ... + @property + def current(self): ... + def __next__(self): ... + +class Joiner: + sep = ... # type: Any + used = ... # type: bool + def __init__(self, sep: str = ...) -> None: ... + def __call__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/visitor.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/visitor.pyi new file mode 100644 index 000000000..ef34328df --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/jinja2/visitor.pyi @@ -0,0 +1,8 @@ +class NodeVisitor: + def get_visitor(self, node): ... + def visit(self, node, *args, **kwargs): ... + def generic_visit(self, node, *args, **kwargs): ... + +class NodeTransformer(NodeVisitor): + def generic_visit(self, node, *args, **kwargs): ... + def visit_list(self, node, *args, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/__init__.pyi new file mode 100644 index 000000000..21878ed37 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/__init__.pyi @@ -0,0 +1,54 @@ +import sys + +from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Text, Tuple, Union +from collections import Mapping +from markupsafe._compat import text_type +import string +from markupsafe._speedups import escape as escape, escape_silent as escape_silent, soft_unicode as soft_unicode +from markupsafe._native import escape as escape, escape_silent as escape_silent, soft_unicode as soft_unicode + +class Markup(text_type): + def __new__(cls, base: Text = ..., encoding: Optional[Text] = ..., errors: Text = ...) -> Markup: ... + def __html__(self) -> Markup: ... + def __add__(self, other: text_type) -> Markup: ... + def __radd__(self, other: text_type) -> Markup: ... + def __mul__(self, num: int) -> Markup: ... + def __rmul__(self, num: int) -> Markup: ... + def __mod__(self, *args: Any) -> Markup: ... + def join(self, seq: Iterable[text_type]): ... + def split(self, sep: Optional[text_type] = ..., maxsplit: int = ...) -> List[text_type]: ... + def rsplit(self, sep: Optional[text_type] = ..., maxsplit: int = ...) -> List[text_type]: ... + def splitlines(self, keepends: bool = ...) -> List[text_type]: ... + def unescape(self) -> Text: ... + def striptags(self) -> Text: ... + @classmethod + def escape(cls, s: text_type) -> Markup: ... + def partition(self, sep: text_type) -> Tuple[Markup, Markup, Markup]: ... + def rpartition(self, sep: text_type) -> Tuple[Markup, Markup, Markup]: ... + def format(*args, **kwargs) -> Markup: ... + def __html_format__(self, format_spec) -> Markup: ... + def __getslice__(self, start: int, stop: int) -> Markup: ... + def __getitem__(self, i: Union[int, slice]) -> Markup: ... + def capitalize(self) -> Markup: ... + def title(self) -> Markup: ... + def lower(self) -> Markup: ... + def upper(self) -> Markup: ... + def swapcase(self) -> Markup: ... + def replace(self, old: text_type, new: text_type, count: int = ...) -> Markup: ... + def ljust(self, width: int, fillchar: text_type = ...) -> Markup: ... + def rjust(self, width: int, fillchar: text_type = ...) -> Markup: ... + def lstrip(self, chars: Optional[text_type] = ...) -> Markup: ... + def rstrip(self, chars: Optional[text_type] = ...) -> Markup: ... + def strip(self, chars: Optional[text_type] = ...) -> Markup: ... + def center(self, width: int, fillchar: text_type = ...) -> Markup: ... + def zfill(self, width: int) -> Markup: ... + def translate(self, table: Union[Mapping[int, Union[int, text_type, None]], Sequence[Union[int, text_type, None]]]) -> Markup: ... + def expandtabs(self, tabsize: int = ...) -> Markup: ... + +class EscapeFormatter(string.Formatter): + escape = ... # type: Callable[[text_type], Markup] + def __init__(self, escape: Callable[[text_type], Markup]) -> None: ... + def format_field(self, value: text_type, format_spec: text_type) -> Markup: ... + +if sys.version_info[0] >= 3: + soft_str = soft_unicode diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_compat.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_compat.pyi new file mode 100644 index 000000000..bb9a860a9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_compat.pyi @@ -0,0 +1,19 @@ +import sys + +from typing import Any, Iterator, Mapping, Text, Tuple, TypeVar + +_K = TypeVar('_K') +_V = TypeVar('_V') + +PY2 = ... # type: bool +def iteritems(d: Mapping[_K, _V]) -> Iterator[Tuple[_K, _V]]: ... +if sys.version_info[0] >= 3: + text_type = str + string_types = str, + unichr = chr + int_types = int, +else: + text_type = unicode + string_types = (str, unicode) + unichr = __builtins__.unichr + int_types = (int, long) diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_constants.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_constants.pyi new file mode 100644 index 000000000..65ace32e5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_constants.pyi @@ -0,0 +1,3 @@ +from typing import Any, Dict, Text + +HTML_ENTITIES = ... # type: Dict[Text, int] diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_native.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_native.pyi new file mode 100644 index 000000000..ecf20c607 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_native.pyi @@ -0,0 +1,7 @@ +from . import Markup +from ._compat import text_type, string_types +from typing import Union, Text + +def escape(s: Union[Markup, Text]) -> Markup: ... +def escape_silent(s: Union[None, Markup, Text]) -> Markup: ... +def soft_unicode(s: Text) -> text_type: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_speedups.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_speedups.pyi new file mode 100644 index 000000000..ecf20c607 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/markupsafe/_speedups.pyi @@ -0,0 +1,7 @@ +from . import Markup +from ._compat import text_type, string_types +from typing import Union, Text + +def escape(s: Union[Markup, Text]) -> Markup: ... +def escape_silent(s: Union[None, Markup, Text]) -> Markup: ... +def soft_unicode(s: Text) -> text_type: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/mock.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/mock.pyi new file mode 100644 index 000000000..259e583e5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/mock.pyi @@ -0,0 +1,146 @@ +# Stubs for mock + +import sys +from typing import Any, Optional, Text, Type + +FILTER_DIR = ... # type: Any + +class _slotted: ... + +class _SentinelObject: + name = ... # type: Any + def __init__(self, name: Any) -> None: ... + +class _Sentinel: + def __init__(self) -> None: ... + def __getattr__(self, name: str) -> Any: ... + +sentinel = ... # type: Any +DEFAULT = ... # type: Any + +class _CallList(list): + def __contains__(self, value: Any) -> bool: ... + +class _MockIter: + obj = ... # type: Any + def __init__(self, obj: Any) -> None: ... + def __iter__(self) -> Any: ... + def __next__(self) -> Any: ... + +class Base: + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + +# TODO: Defining this and other mock classes as classes in this stub causes +# many false positives with mypy and production code. See if we can +# improve mypy somehow and use a class with an "Any" base class. +NonCallableMock: Any + +class CallableMixin(Base): + side_effect = ... # type: Any + def __init__(self, spec: Optional[Any] = ..., side_effect: Optional[Any] = ..., return_value: Any = ..., wraps: Optional[Any] = ..., name: Optional[Any] = ..., spec_set: Optional[Any] = ..., parent: Optional[Any] = ..., _spec_state: Optional[Any] = ..., _new_name: Any = ..., _new_parent: Optional[Any] = ..., **kwargs: Any) -> None: ... + def __call__(_mock_self, *args: Any, **kwargs: Any) -> Any: ... + +Mock: Any + +class _patch: + attribute_name = ... # type: Any + getter = ... # type: Any + attribute = ... # type: Any + new = ... # type: Any + new_callable = ... # type: Any + spec = ... # type: Any + create = ... # type: bool + has_local = ... # type: Any + spec_set = ... # type: Any + autospec = ... # type: Any + kwargs = ... # type: Any + additional_patchers = ... # type: Any + def __init__(self, getter: Any, attribute: Any, new: Any, spec: Any, create: Any, spec_set: Any, autospec: Any, new_callable: Any, kwargs: Any) -> None: ... + def copy(self) -> Any: ... + def __call__(self, func: Any) -> Any: ... + def decorate_class(self, klass: Any) -> Any: ... + def decorate_callable(self, func: Any) -> Any: ... + def get_original(self) -> Any: ... + target = ... # type: Any + temp_original = ... # type: Any + is_local = ... # type: Any + def __enter__(self) -> Any: ... + def __exit__(self, *exc_info: Any) -> Any: ... + def start(self) -> Any: ... + def stop(self) -> Any: ... + +class _patch_dict: + in_dict = ... # type: Any + values = ... # type: Any + clear = ... # type: Any + def __init__(self, in_dict: Any, values: Any = ..., clear: Any = ..., **kwargs: Any) -> None: ... + def __call__(self, f: Any) -> Any: ... + def decorate_class(self, klass: Any) -> Any: ... + def __enter__(self) -> Any: ... + def __exit__(self, *args: Any) -> Any: ... + start = ... # type: Any + stop = ... # type: Any + +class _patcher: + TEST_PREFIX = ... # type: str + dict = ... # type: Type[_patch_dict] + def __call__(self, target: Any, new: Optional[Any] = ..., spec: Optional[Any] = ..., create: bool = ..., spec_set: Optional[Any] = ..., autospec: Optional[Any] = ..., new_callable: Optional[Any] = ..., **kwargs: Any) -> Any: ... + def object(self, target: Any, attribute: Text, new: Optional[Any] = ..., spec: Optional[Any] = ..., create: bool = ..., spec_set: Optional[Any] = ..., autospec: Optional[Any] = ..., new_callable: Optional[Any] = ..., **kwargs: Any) -> _patch: ... + def multiple(self, target: Any, spec: Optional[Any] = ..., create: bool = ..., spec_set: Optional[Any] = ..., autospec: Optional[Any] = ..., new_callable: Optional[Any] = ..., **kwargs: Any) -> Any: ... + def stopall(self) -> None: ... + +patch = ... # type: _patcher + +class MagicMixin: + def __init__(self, *args: Any, **kw: Any) -> None: ... + +NonCallableMagicMock: Any +MagicMock: Any + +class MagicProxy: + name = ... # type: Any + parent = ... # type: Any + def __init__(self, name: Any, parent: Any) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def create_mock(self) -> Any: ... + def __get__(self, obj: Any, _type: Optional[Any] = ...) -> Any: ... + +class _ANY: + def __eq__(self, other: Any) -> bool: ... + def __ne__(self, other: Any) -> bool: ... + +ANY = ... # type: Any + +class _Call(tuple): + def __new__(cls, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> Any: ... + name = ... # type: Any + parent = ... # type: Any + from_kall = ... # type: Any + def __init__(self, value: Any = ..., name: Optional[Any] = ..., parent: Optional[Any] = ..., two: bool = ..., from_kall: bool = ...) -> None: ... + def __eq__(self, other: Any) -> bool: ... + __ne__ = ... # type: Any + def __call__(self, *args: Any, **kwargs: Any) -> Any: ... + def __getattr__(self, attr: Any) -> Any: ... + def count(self, *args: Any, **kwargs: Any) -> Any: ... + def index(self, *args: Any, **kwargs: Any) -> Any: ... + def call_list(self) -> Any: ... + +call = ... # type: Any + +def create_autospec(spec: Any, spec_set: Any = ..., instance: Any = ..., _parent: Optional[Any] = ..., _name: Optional[Any] = ..., **kwargs: Any) -> Any: ... + +class _SpecState: + spec = ... # type: Any + ids = ... # type: Any + spec_set = ... # type: Any + parent = ... # type: Any + instance = ... # type: Any + name = ... # type: Any + def __init__(self, spec: Any, spec_set: Any = ..., parent: Optional[Any] = ..., name: Optional[Any] = ..., ids: Optional[Any] = ..., instance: Any = ...) -> None: ... + +def mock_open(mock: Optional[Any] = ..., read_data: Any = ...) -> Any: ... + +PropertyMock: Any + +if sys.version_info >= (3, 7): + def seal(mock: Any) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/mypy_extensions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/mypy_extensions.pyi new file mode 100644 index 000000000..e4687e9b1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/mypy_extensions.pyi @@ -0,0 +1,17 @@ +from typing import Dict, Type, TypeVar, Optional, Union + +_T = TypeVar('_T') + +def TypedDict(typename: str, fields: Dict[str, Type[_T]], total: bool = ...) -> Type[dict]: ... + +def Arg(type: _T = ..., name: Optional[str] = ...) -> _T: ... +def DefaultArg(type: _T = ..., name: Optional[str] = ...) -> _T: ... +def NamedArg(type: _T = ..., name: Optional[str] = ...) -> _T: ... +def DefaultNamedArg(type: _T = ..., name: Optional[str] = ...) -> _T: ... +def VarArg(type: _T = ...) -> _T: ... +def KwArg(type: _T = ...) -> _T: ... + +# Return type that indicates a function does not return. +# This type is equivalent to the None type, but the no-op Union is necessary to +# distinguish the None type from the None value. +NoReturn = Union[None] # Deprecated: Use typing.NoReturn instead. diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/__init__.pyi new file mode 100644 index 000000000..dd58ff9d0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/__init__.pyi @@ -0,0 +1,35 @@ +from typing import Union, Tuple, Callable +from .connections import Connection +from .constants import FIELD_TYPE as FIELD_TYPE +from .converters import escape_dict as escape_dict, escape_sequence as escape_sequence, escape_string as escape_string +from .err import Warning as Warning, Error as Error, InterfaceError as InterfaceError, DataError as DataError, DatabaseError as DatabaseError, OperationalError as OperationalError, IntegrityError as IntegrityError, InternalError as InternalError, NotSupportedError as NotSupportedError, ProgrammingError as ProgrammingError, MySQLError as MySQLError +from .times import Date as Date, Time as Time, Timestamp as Timestamp, DateFromTicks as DateFromTicks, TimeFromTicks as TimeFromTicks, TimestampFromTicks as TimestampFromTicks + +threadsafety = ... # type: int +apilevel = ... # type: str +paramstyle = ... # type: str + +class DBAPISet(frozenset): + def __ne__(self, other) -> bool: ... + def __eq__(self, other) -> bool: ... + def __hash__(self) -> int: ... + +STRING = ... # type: DBAPISet +BINARY = ... # type: DBAPISet +NUMBER = ... # type: DBAPISet +DATE = ... # type: DBAPISet +TIME = ... # type: DBAPISet +TIMESTAMP = ... # type: DBAPISet +ROWID = ... # type: DBAPISet + +def Binary(x) -> Union[bytearray, bytes]: ... +def Connect(*args, **kwargs) -> Connection: ... +def get_client_info() -> str: ... + +connect = ... # type: Callable[..., Connection] + + +version_info = ... # type: Tuple[int, int, int, str, int] +NULL = ... # type: str + +def install_as_MySQLdb() -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/charset.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/charset.pyi new file mode 100644 index 000000000..916e6a366 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/charset.pyi @@ -0,0 +1,16 @@ +from typing import Any + +MBLENGTH = ... # type: Any + +class Charset: + is_default = ... # type: Any + def __init__(self, id, name, collation, is_default): ... + +class Charsets: + def __init__(self): ... + def add(self, c): ... + def by_id(self, id): ... + def by_name(self, name): ... + +def charset_by_name(name): ... +def charset_by_id(id): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/connections.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/connections.pyi new file mode 100644 index 000000000..3789924b8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/connections.pyi @@ -0,0 +1,140 @@ +from typing import Any, Optional, Type +from .charset import MBLENGTH as MBLENGTH, charset_by_name as charset_by_name, charset_by_id as charset_by_id +from .cursors import Cursor as Cursor +from .constants import FIELD_TYPE as FIELD_TYPE, FLAG as FLAG +from .constants import SERVER_STATUS as SERVER_STATUS +from .constants import CLIENT as CLIENT +from .constants import COMMAND as COMMAND +from .util import join_bytes as join_bytes, byte2int as byte2int, int2byte as int2byte +from .converters import escape_item as escape_item, encoders as encoders, decoders as decoders +from .err import raise_mysql_exception as raise_mysql_exception, Warning as Warning, Error as Error, InterfaceError as InterfaceError, DataError as DataError, DatabaseError as DatabaseError, OperationalError as OperationalError, IntegrityError as IntegrityError, InternalError as InternalError, NotSupportedError as NotSupportedError, ProgrammingError as ProgrammingError + +sha_new = ... # type: Any +SSL_ENABLED = ... # type: Any +DEFAULT_USER = ... # type: Any +DEBUG = ... # type: Any +NULL_COLUMN = ... # type: Any +UNSIGNED_CHAR_COLUMN = ... # type: Any +UNSIGNED_SHORT_COLUMN = ... # type: Any +UNSIGNED_INT24_COLUMN = ... # type: Any +UNSIGNED_INT64_COLUMN = ... # type: Any +UNSIGNED_CHAR_LENGTH = ... # type: Any +UNSIGNED_SHORT_LENGTH = ... # type: Any +UNSIGNED_INT24_LENGTH = ... # type: Any +UNSIGNED_INT64_LENGTH = ... # type: Any +DEFAULT_CHARSET = ... # type: Any + +def dump_packet(data): ... + +SCRAMBLE_LENGTH_323 = ... # type: Any + +class RandStruct_323: + max_value = ... # type: Any + seed1 = ... # type: Any + seed2 = ... # type: Any + def __init__(self, seed1, seed2): ... + def my_rnd(self): ... + +def pack_int24(n): ... +def unpack_uint16(n): ... +def unpack_int24(n): ... +def unpack_int32(n): ... +def unpack_int64(n): ... +def defaulterrorhandler(connection, cursor, errorclass, errorvalue): ... + +class MysqlPacket: + connection = ... # type: Any + def __init__(self, connection): ... + def packet_number(self): ... + def get_all_data(self): ... + def read(self, size): ... + def read_all(self): ... + def advance(self, length): ... + def rewind(self, position=0): ... + def peek(self, size): ... + def get_bytes(self, position, length=1): ... + def read_length_coded_binary(self): ... + def read_length_coded_string(self): ... + def is_ok_packet(self): ... + def is_eof_packet(self): ... + def is_resultset_packet(self): ... + def is_error_packet(self): ... + def check_error(self): ... + def dump(self): ... + +class FieldDescriptorPacket(MysqlPacket): + def __init__(self, *args): ... + def description(self): ... + def get_column_length(self): ... + +class Connection: + errorhandler = ... # type: Any + ssl = ... # type: Any + host = ... # type: Any + port = ... # type: Any + user = ... # type: Any + password = ... # type: Any + db = ... # type: Any + unix_socket = ... # type: Any + charset = ... # type: Any + use_unicode = ... # type: Any + client_flag = ... # type: Any + cursorclass = ... # type: Any + connect_timeout = ... # type: Any + messages = ... # type: Any + encoders = ... # type: Any + decoders = ... # type: Any + host_info = ... # type: Any + def __init__(self, host='', user=None, passwd='', db=None, port=3306, unix_socket=None, charset='', sql_mode=None, read_default_file=None, conv=..., use_unicode=None, client_flag=0, cursorclass=..., init_command=None, connect_timeout=None, ssl=None, read_default_group=None, compress=None, named_pipe=None): ... + socket = ... # type: Any + rfile = ... # type: Any + wfile = ... # type: Any + def close(self): ... + def autocommit(self, value): ... + def commit(self): ... + def begin(self) -> None: ... + def rollback(self): ... + def escape(self, obj): ... + def literal(self, obj): ... + def cursor(self, cursor: Optional[Type[Cursor]] = ...): ... + def __enter__(self): ... + def __exit__(self, exc, value, traceback): ... + def query(self, sql): ... + def next_result(self, unbuffered: bool = ...): ... + def affected_rows(self): ... + def kill(self, thread_id): ... + def ping(self, reconnect: bool = ...): ... + def set_charset(self, charset): ... + def read_packet(self, packet_type=...): ... + def insert_id(self): ... + def thread_id(self): ... + def character_set_name(self): ... + def get_host_info(self): ... + def get_proto_info(self): ... + def get_server_info(self): ... + def show_warnings(self): ... + Warning = ... # type: Any + Error = ... # type: Any + InterfaceError = ... # type: Any + DatabaseError = ... # type: Any + DataError = ... # type: Any + OperationalError = ... # type: Any + IntegrityError = ... # type: Any + InternalError = ... # type: Any + ProgrammingError = ... # type: Any + NotSupportedError = ... # type: Any + +class MySQLResult: + connection = ... # type: Any + affected_rows = ... # type: Any + insert_id = ... # type: Any + server_status = ... # type: Any + warning_count = ... # type: Any + message = ... # type: Any + field_count = ... # type: Any + description = ... # type: Any + rows = ... # type: Any + has_next = ... # type: Any + def __init__(self, connection): ... + first_packet = ... # type: Any + def read(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/CLIENT.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/CLIENT.pyi new file mode 100644 index 000000000..cdb11b32d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/CLIENT.pyi @@ -0,0 +1,20 @@ +from typing import Any + +LONG_PASSWORD = ... # type: Any +FOUND_ROWS = ... # type: Any +LONG_FLAG = ... # type: Any +CONNECT_WITH_DB = ... # type: Any +NO_SCHEMA = ... # type: Any +COMPRESS = ... # type: Any +ODBC = ... # type: Any +LOCAL_FILES = ... # type: Any +IGNORE_SPACE = ... # type: Any +PROTOCOL_41 = ... # type: Any +INTERACTIVE = ... # type: Any +SSL = ... # type: Any +IGNORE_SIGPIPE = ... # type: Any +TRANSACTIONS = ... # type: Any +SECURE_CONNECTION = ... # type: Any +MULTI_STATEMENTS = ... # type: Any +MULTI_RESULTS = ... # type: Any +CAPABILITIES = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/COMMAND.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/COMMAND.pyi new file mode 100644 index 000000000..0cfa0c260 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/COMMAND.pyi @@ -0,0 +1,24 @@ +from typing import Any + +COM_SLEEP = ... # type: Any +COM_QUIT = ... # type: Any +COM_INIT_DB = ... # type: Any +COM_QUERY = ... # type: Any +COM_FIELD_LIST = ... # type: Any +COM_CREATE_DB = ... # type: Any +COM_DROP_DB = ... # type: Any +COM_REFRESH = ... # type: Any +COM_SHUTDOWN = ... # type: Any +COM_STATISTICS = ... # type: Any +COM_PROCESS_INFO = ... # type: Any +COM_CONNECT = ... # type: Any +COM_PROCESS_KILL = ... # type: Any +COM_DEBUG = ... # type: Any +COM_PING = ... # type: Any +COM_TIME = ... # type: Any +COM_DELAYED_INSERT = ... # type: Any +COM_CHANGE_USER = ... # type: Any +COM_BINLOG_DUMP = ... # type: Any +COM_TABLE_DUMP = ... # type: Any +COM_CONNECT_OUT = ... # type: Any +COM_REGISTER_SLAVE = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/ER.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/ER.pyi new file mode 100644 index 000000000..811f6a214 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/ER.pyi @@ -0,0 +1,473 @@ +from typing import Any + +ERROR_FIRST = ... # type: Any +HASHCHK = ... # type: Any +NISAMCHK = ... # type: Any +NO = ... # type: Any +YES = ... # type: Any +CANT_CREATE_FILE = ... # type: Any +CANT_CREATE_TABLE = ... # type: Any +CANT_CREATE_DB = ... # type: Any +DB_CREATE_EXISTS = ... # type: Any +DB_DROP_EXISTS = ... # type: Any +DB_DROP_DELETE = ... # type: Any +DB_DROP_RMDIR = ... # type: Any +CANT_DELETE_FILE = ... # type: Any +CANT_FIND_SYSTEM_REC = ... # type: Any +CANT_GET_STAT = ... # type: Any +CANT_GET_WD = ... # type: Any +CANT_LOCK = ... # type: Any +CANT_OPEN_FILE = ... # type: Any +FILE_NOT_FOUND = ... # type: Any +CANT_READ_DIR = ... # type: Any +CANT_SET_WD = ... # type: Any +CHECKREAD = ... # type: Any +DISK_FULL = ... # type: Any +DUP_KEY = ... # type: Any +ERROR_ON_CLOSE = ... # type: Any +ERROR_ON_READ = ... # type: Any +ERROR_ON_RENAME = ... # type: Any +ERROR_ON_WRITE = ... # type: Any +FILE_USED = ... # type: Any +FILSORT_ABORT = ... # type: Any +FORM_NOT_FOUND = ... # type: Any +GET_ERRNO = ... # type: Any +ILLEGAL_HA = ... # type: Any +KEY_NOT_FOUND = ... # type: Any +NOT_FORM_FILE = ... # type: Any +NOT_KEYFILE = ... # type: Any +OLD_KEYFILE = ... # type: Any +OPEN_AS_READONLY = ... # type: Any +OUTOFMEMORY = ... # type: Any +OUT_OF_SORTMEMORY = ... # type: Any +UNEXPECTED_EOF = ... # type: Any +CON_COUNT_ERROR = ... # type: Any +OUT_OF_RESOURCES = ... # type: Any +BAD_HOST_ERROR = ... # type: Any +HANDSHAKE_ERROR = ... # type: Any +DBACCESS_DENIED_ERROR = ... # type: Any +ACCESS_DENIED_ERROR = ... # type: Any +NO_DB_ERROR = ... # type: Any +UNKNOWN_COM_ERROR = ... # type: Any +BAD_NULL_ERROR = ... # type: Any +BAD_DB_ERROR = ... # type: Any +TABLE_EXISTS_ERROR = ... # type: Any +BAD_TABLE_ERROR = ... # type: Any +NON_UNIQ_ERROR = ... # type: Any +SERVER_SHUTDOWN = ... # type: Any +BAD_FIELD_ERROR = ... # type: Any +WRONG_FIELD_WITH_GROUP = ... # type: Any +WRONG_GROUP_FIELD = ... # type: Any +WRONG_SUM_SELECT = ... # type: Any +WRONG_VALUE_COUNT = ... # type: Any +TOO_LONG_IDENT = ... # type: Any +DUP_FIELDNAME = ... # type: Any +DUP_KEYNAME = ... # type: Any +DUP_ENTRY = ... # type: Any +WRONG_FIELD_SPEC = ... # type: Any +PARSE_ERROR = ... # type: Any +EMPTY_QUERY = ... # type: Any +NONUNIQ_TABLE = ... # type: Any +INVALID_DEFAULT = ... # type: Any +MULTIPLE_PRI_KEY = ... # type: Any +TOO_MANY_KEYS = ... # type: Any +TOO_MANY_KEY_PARTS = ... # type: Any +TOO_LONG_KEY = ... # type: Any +KEY_COLUMN_DOES_NOT_EXITS = ... # type: Any +BLOB_USED_AS_KEY = ... # type: Any +TOO_BIG_FIELDLENGTH = ... # type: Any +WRONG_AUTO_KEY = ... # type: Any +READY = ... # type: Any +NORMAL_SHUTDOWN = ... # type: Any +GOT_SIGNAL = ... # type: Any +SHUTDOWN_COMPLETE = ... # type: Any +FORCING_CLOSE = ... # type: Any +IPSOCK_ERROR = ... # type: Any +NO_SUCH_INDEX = ... # type: Any +WRONG_FIELD_TERMINATORS = ... # type: Any +BLOBS_AND_NO_TERMINATED = ... # type: Any +TEXTFILE_NOT_READABLE = ... # type: Any +FILE_EXISTS_ERROR = ... # type: Any +LOAD_INFO = ... # type: Any +ALTER_INFO = ... # type: Any +WRONG_SUB_KEY = ... # type: Any +CANT_REMOVE_ALL_FIELDS = ... # type: Any +CANT_DROP_FIELD_OR_KEY = ... # type: Any +INSERT_INFO = ... # type: Any +UPDATE_TABLE_USED = ... # type: Any +NO_SUCH_THREAD = ... # type: Any +KILL_DENIED_ERROR = ... # type: Any +NO_TABLES_USED = ... # type: Any +TOO_BIG_SET = ... # type: Any +NO_UNIQUE_LOGFILE = ... # type: Any +TABLE_NOT_LOCKED_FOR_WRITE = ... # type: Any +TABLE_NOT_LOCKED = ... # type: Any +BLOB_CANT_HAVE_DEFAULT = ... # type: Any +WRONG_DB_NAME = ... # type: Any +WRONG_TABLE_NAME = ... # type: Any +TOO_BIG_SELECT = ... # type: Any +UNKNOWN_ERROR = ... # type: Any +UNKNOWN_PROCEDURE = ... # type: Any +WRONG_PARAMCOUNT_TO_PROCEDURE = ... # type: Any +WRONG_PARAMETERS_TO_PROCEDURE = ... # type: Any +UNKNOWN_TABLE = ... # type: Any +FIELD_SPECIFIED_TWICE = ... # type: Any +INVALID_GROUP_FUNC_USE = ... # type: Any +UNSUPPORTED_EXTENSION = ... # type: Any +TABLE_MUST_HAVE_COLUMNS = ... # type: Any +RECORD_FILE_FULL = ... # type: Any +UNKNOWN_CHARACTER_SET = ... # type: Any +TOO_MANY_TABLES = ... # type: Any +TOO_MANY_FIELDS = ... # type: Any +TOO_BIG_ROWSIZE = ... # type: Any +STACK_OVERRUN = ... # type: Any +WRONG_OUTER_JOIN = ... # type: Any +NULL_COLUMN_IN_INDEX = ... # type: Any +CANT_FIND_UDF = ... # type: Any +CANT_INITIALIZE_UDF = ... # type: Any +UDF_NO_PATHS = ... # type: Any +UDF_EXISTS = ... # type: Any +CANT_OPEN_LIBRARY = ... # type: Any +CANT_FIND_DL_ENTRY = ... # type: Any +FUNCTION_NOT_DEFINED = ... # type: Any +HOST_IS_BLOCKED = ... # type: Any +HOST_NOT_PRIVILEGED = ... # type: Any +PASSWORD_ANONYMOUS_USER = ... # type: Any +PASSWORD_NOT_ALLOWED = ... # type: Any +PASSWORD_NO_MATCH = ... # type: Any +UPDATE_INFO = ... # type: Any +CANT_CREATE_THREAD = ... # type: Any +WRONG_VALUE_COUNT_ON_ROW = ... # type: Any +CANT_REOPEN_TABLE = ... # type: Any +INVALID_USE_OF_NULL = ... # type: Any +REGEXP_ERROR = ... # type: Any +MIX_OF_GROUP_FUNC_AND_FIELDS = ... # type: Any +NONEXISTING_GRANT = ... # type: Any +TABLEACCESS_DENIED_ERROR = ... # type: Any +COLUMNACCESS_DENIED_ERROR = ... # type: Any +ILLEGAL_GRANT_FOR_TABLE = ... # type: Any +GRANT_WRONG_HOST_OR_USER = ... # type: Any +NO_SUCH_TABLE = ... # type: Any +NONEXISTING_TABLE_GRANT = ... # type: Any +NOT_ALLOWED_COMMAND = ... # type: Any +SYNTAX_ERROR = ... # type: Any +DELAYED_CANT_CHANGE_LOCK = ... # type: Any +TOO_MANY_DELAYED_THREADS = ... # type: Any +ABORTING_CONNECTION = ... # type: Any +NET_PACKET_TOO_LARGE = ... # type: Any +NET_READ_ERROR_FROM_PIPE = ... # type: Any +NET_FCNTL_ERROR = ... # type: Any +NET_PACKETS_OUT_OF_ORDER = ... # type: Any +NET_UNCOMPRESS_ERROR = ... # type: Any +NET_READ_ERROR = ... # type: Any +NET_READ_INTERRUPTED = ... # type: Any +NET_ERROR_ON_WRITE = ... # type: Any +NET_WRITE_INTERRUPTED = ... # type: Any +TOO_LONG_STRING = ... # type: Any +TABLE_CANT_HANDLE_BLOB = ... # type: Any +TABLE_CANT_HANDLE_AUTO_INCREMENT = ... # type: Any +DELAYED_INSERT_TABLE_LOCKED = ... # type: Any +WRONG_COLUMN_NAME = ... # type: Any +WRONG_KEY_COLUMN = ... # type: Any +WRONG_MRG_TABLE = ... # type: Any +DUP_UNIQUE = ... # type: Any +BLOB_KEY_WITHOUT_LENGTH = ... # type: Any +PRIMARY_CANT_HAVE_NULL = ... # type: Any +TOO_MANY_ROWS = ... # type: Any +REQUIRES_PRIMARY_KEY = ... # type: Any +NO_RAID_COMPILED = ... # type: Any +UPDATE_WITHOUT_KEY_IN_SAFE_MODE = ... # type: Any +KEY_DOES_NOT_EXITS = ... # type: Any +CHECK_NO_SUCH_TABLE = ... # type: Any +CHECK_NOT_IMPLEMENTED = ... # type: Any +CANT_DO_THIS_DURING_AN_TRANSACTION = ... # type: Any +ERROR_DURING_COMMIT = ... # type: Any +ERROR_DURING_ROLLBACK = ... # type: Any +ERROR_DURING_FLUSH_LOGS = ... # type: Any +ERROR_DURING_CHECKPOINT = ... # type: Any +NEW_ABORTING_CONNECTION = ... # type: Any +DUMP_NOT_IMPLEMENTED = ... # type: Any +FLUSH_MASTER_BINLOG_CLOSED = ... # type: Any +INDEX_REBUILD = ... # type: Any +MASTER = ... # type: Any +MASTER_NET_READ = ... # type: Any +MASTER_NET_WRITE = ... # type: Any +FT_MATCHING_KEY_NOT_FOUND = ... # type: Any +LOCK_OR_ACTIVE_TRANSACTION = ... # type: Any +UNKNOWN_SYSTEM_VARIABLE = ... # type: Any +CRASHED_ON_USAGE = ... # type: Any +CRASHED_ON_REPAIR = ... # type: Any +WARNING_NOT_COMPLETE_ROLLBACK = ... # type: Any +TRANS_CACHE_FULL = ... # type: Any +SLAVE_MUST_STOP = ... # type: Any +SLAVE_NOT_RUNNING = ... # type: Any +BAD_SLAVE = ... # type: Any +MASTER_INFO = ... # type: Any +SLAVE_THREAD = ... # type: Any +TOO_MANY_USER_CONNECTIONS = ... # type: Any +SET_CONSTANTS_ONLY = ... # type: Any +LOCK_WAIT_TIMEOUT = ... # type: Any +LOCK_TABLE_FULL = ... # type: Any +READ_ONLY_TRANSACTION = ... # type: Any +DROP_DB_WITH_READ_LOCK = ... # type: Any +CREATE_DB_WITH_READ_LOCK = ... # type: Any +WRONG_ARGUMENTS = ... # type: Any +NO_PERMISSION_TO_CREATE_USER = ... # type: Any +UNION_TABLES_IN_DIFFERENT_DIR = ... # type: Any +LOCK_DEADLOCK = ... # type: Any +TABLE_CANT_HANDLE_FT = ... # type: Any +CANNOT_ADD_FOREIGN = ... # type: Any +NO_REFERENCED_ROW = ... # type: Any +ROW_IS_REFERENCED = ... # type: Any +CONNECT_TO_MASTER = ... # type: Any +QUERY_ON_MASTER = ... # type: Any +ERROR_WHEN_EXECUTING_COMMAND = ... # type: Any +WRONG_USAGE = ... # type: Any +WRONG_NUMBER_OF_COLUMNS_IN_SELECT = ... # type: Any +CANT_UPDATE_WITH_READLOCK = ... # type: Any +MIXING_NOT_ALLOWED = ... # type: Any +DUP_ARGUMENT = ... # type: Any +USER_LIMIT_REACHED = ... # type: Any +SPECIFIC_ACCESS_DENIED_ERROR = ... # type: Any +LOCAL_VARIABLE = ... # type: Any +GLOBAL_VARIABLE = ... # type: Any +NO_DEFAULT = ... # type: Any +WRONG_VALUE_FOR_VAR = ... # type: Any +WRONG_TYPE_FOR_VAR = ... # type: Any +VAR_CANT_BE_READ = ... # type: Any +CANT_USE_OPTION_HERE = ... # type: Any +NOT_SUPPORTED_YET = ... # type: Any +MASTER_FATAL_ERROR_READING_BINLOG = ... # type: Any +SLAVE_IGNORED_TABLE = ... # type: Any +INCORRECT_GLOBAL_LOCAL_VAR = ... # type: Any +WRONG_FK_DEF = ... # type: Any +KEY_REF_DO_NOT_MATCH_TABLE_REF = ... # type: Any +OPERAND_COLUMNS = ... # type: Any +SUBQUERY_NO_1_ROW = ... # type: Any +UNKNOWN_STMT_HANDLER = ... # type: Any +CORRUPT_HELP_DB = ... # type: Any +CYCLIC_REFERENCE = ... # type: Any +AUTO_CONVERT = ... # type: Any +ILLEGAL_REFERENCE = ... # type: Any +DERIVED_MUST_HAVE_ALIAS = ... # type: Any +SELECT_REDUCED = ... # type: Any +TABLENAME_NOT_ALLOWED_HERE = ... # type: Any +NOT_SUPPORTED_AUTH_MODE = ... # type: Any +SPATIAL_CANT_HAVE_NULL = ... # type: Any +COLLATION_CHARSET_MISMATCH = ... # type: Any +SLAVE_WAS_RUNNING = ... # type: Any +SLAVE_WAS_NOT_RUNNING = ... # type: Any +TOO_BIG_FOR_UNCOMPRESS = ... # type: Any +ZLIB_Z_MEM_ERROR = ... # type: Any +ZLIB_Z_BUF_ERROR = ... # type: Any +ZLIB_Z_DATA_ERROR = ... # type: Any +CUT_VALUE_GROUP_CONCAT = ... # type: Any +WARN_TOO_FEW_RECORDS = ... # type: Any +WARN_TOO_MANY_RECORDS = ... # type: Any +WARN_NULL_TO_NOTNULL = ... # type: Any +WARN_DATA_OUT_OF_RANGE = ... # type: Any +WARN_DATA_TRUNCATED = ... # type: Any +WARN_USING_OTHER_HANDLER = ... # type: Any +CANT_AGGREGATE_2COLLATIONS = ... # type: Any +DROP_USER = ... # type: Any +REVOKE_GRANTS = ... # type: Any +CANT_AGGREGATE_3COLLATIONS = ... # type: Any +CANT_AGGREGATE_NCOLLATIONS = ... # type: Any +VARIABLE_IS_NOT_STRUCT = ... # type: Any +UNKNOWN_COLLATION = ... # type: Any +SLAVE_IGNORED_SSL_PARAMS = ... # type: Any +SERVER_IS_IN_SECURE_AUTH_MODE = ... # type: Any +WARN_FIELD_RESOLVED = ... # type: Any +BAD_SLAVE_UNTIL_COND = ... # type: Any +MISSING_SKIP_SLAVE = ... # type: Any +UNTIL_COND_IGNORED = ... # type: Any +WRONG_NAME_FOR_INDEX = ... # type: Any +WRONG_NAME_FOR_CATALOG = ... # type: Any +WARN_QC_RESIZE = ... # type: Any +BAD_FT_COLUMN = ... # type: Any +UNKNOWN_KEY_CACHE = ... # type: Any +WARN_HOSTNAME_WONT_WORK = ... # type: Any +UNKNOWN_STORAGE_ENGINE = ... # type: Any +WARN_DEPRECATED_SYNTAX = ... # type: Any +NON_UPDATABLE_TABLE = ... # type: Any +FEATURE_DISABLED = ... # type: Any +OPTION_PREVENTS_STATEMENT = ... # type: Any +DUPLICATED_VALUE_IN_TYPE = ... # type: Any +TRUNCATED_WRONG_VALUE = ... # type: Any +TOO_MUCH_AUTO_TIMESTAMP_COLS = ... # type: Any +INVALID_ON_UPDATE = ... # type: Any +UNSUPPORTED_PS = ... # type: Any +GET_ERRMSG = ... # type: Any +GET_TEMPORARY_ERRMSG = ... # type: Any +UNKNOWN_TIME_ZONE = ... # type: Any +WARN_INVALID_TIMESTAMP = ... # type: Any +INVALID_CHARACTER_STRING = ... # type: Any +WARN_ALLOWED_PACKET_OVERFLOWED = ... # type: Any +CONFLICTING_DECLARATIONS = ... # type: Any +SP_NO_RECURSIVE_CREATE = ... # type: Any +SP_ALREADY_EXISTS = ... # type: Any +SP_DOES_NOT_EXIST = ... # type: Any +SP_DROP_FAILED = ... # type: Any +SP_STORE_FAILED = ... # type: Any +SP_LILABEL_MISMATCH = ... # type: Any +SP_LABEL_REDEFINE = ... # type: Any +SP_LABEL_MISMATCH = ... # type: Any +SP_UNINIT_VAR = ... # type: Any +SP_BADSELECT = ... # type: Any +SP_BADRETURN = ... # type: Any +SP_BADSTATEMENT = ... # type: Any +UPDATE_LOG_DEPRECATED_IGNORED = ... # type: Any +UPDATE_LOG_DEPRECATED_TRANSLATED = ... # type: Any +QUERY_INTERRUPTED = ... # type: Any +SP_WRONG_NO_OF_ARGS = ... # type: Any +SP_COND_MISMATCH = ... # type: Any +SP_NORETURN = ... # type: Any +SP_NORETURNEND = ... # type: Any +SP_BAD_CURSOR_QUERY = ... # type: Any +SP_BAD_CURSOR_SELECT = ... # type: Any +SP_CURSOR_MISMATCH = ... # type: Any +SP_CURSOR_ALREADY_OPEN = ... # type: Any +SP_CURSOR_NOT_OPEN = ... # type: Any +SP_UNDECLARED_VAR = ... # type: Any +SP_WRONG_NO_OF_FETCH_ARGS = ... # type: Any +SP_FETCH_NO_DATA = ... # type: Any +SP_DUP_PARAM = ... # type: Any +SP_DUP_VAR = ... # type: Any +SP_DUP_COND = ... # type: Any +SP_DUP_CURS = ... # type: Any +SP_CANT_ALTER = ... # type: Any +SP_SUBSELECT_NYI = ... # type: Any +STMT_NOT_ALLOWED_IN_SF_OR_TRG = ... # type: Any +SP_VARCOND_AFTER_CURSHNDLR = ... # type: Any +SP_CURSOR_AFTER_HANDLER = ... # type: Any +SP_CASE_NOT_FOUND = ... # type: Any +FPARSER_TOO_BIG_FILE = ... # type: Any +FPARSER_BAD_HEADER = ... # type: Any +FPARSER_EOF_IN_COMMENT = ... # type: Any +FPARSER_ERROR_IN_PARAMETER = ... # type: Any +FPARSER_EOF_IN_UNKNOWN_PARAMETER = ... # type: Any +VIEW_NO_EXPLAIN = ... # type: Any +FRM_UNKNOWN_TYPE = ... # type: Any +WRONG_OBJECT = ... # type: Any +NONUPDATEABLE_COLUMN = ... # type: Any +VIEW_SELECT_DERIVED = ... # type: Any +VIEW_SELECT_CLAUSE = ... # type: Any +VIEW_SELECT_VARIABLE = ... # type: Any +VIEW_SELECT_TMPTABLE = ... # type: Any +VIEW_WRONG_LIST = ... # type: Any +WARN_VIEW_MERGE = ... # type: Any +WARN_VIEW_WITHOUT_KEY = ... # type: Any +VIEW_INVALID = ... # type: Any +SP_NO_DROP_SP = ... # type: Any +SP_GOTO_IN_HNDLR = ... # type: Any +TRG_ALREADY_EXISTS = ... # type: Any +TRG_DOES_NOT_EXIST = ... # type: Any +TRG_ON_VIEW_OR_TEMP_TABLE = ... # type: Any +TRG_CANT_CHANGE_ROW = ... # type: Any +TRG_NO_SUCH_ROW_IN_TRG = ... # type: Any +NO_DEFAULT_FOR_FIELD = ... # type: Any +DIVISION_BY_ZERO = ... # type: Any +TRUNCATED_WRONG_VALUE_FOR_FIELD = ... # type: Any +ILLEGAL_VALUE_FOR_TYPE = ... # type: Any +VIEW_NONUPD_CHECK = ... # type: Any +VIEW_CHECK_FAILED = ... # type: Any +PROCACCESS_DENIED_ERROR = ... # type: Any +RELAY_LOG_FAIL = ... # type: Any +PASSWD_LENGTH = ... # type: Any +UNKNOWN_TARGET_BINLOG = ... # type: Any +IO_ERR_LOG_INDEX_READ = ... # type: Any +BINLOG_PURGE_PROHIBITED = ... # type: Any +FSEEK_FAIL = ... # type: Any +BINLOG_PURGE_FATAL_ERR = ... # type: Any +LOG_IN_USE = ... # type: Any +LOG_PURGE_UNKNOWN_ERR = ... # type: Any +RELAY_LOG_INIT = ... # type: Any +NO_BINARY_LOGGING = ... # type: Any +RESERVED_SYNTAX = ... # type: Any +WSAS_FAILED = ... # type: Any +DIFF_GROUPS_PROC = ... # type: Any +NO_GROUP_FOR_PROC = ... # type: Any +ORDER_WITH_PROC = ... # type: Any +LOGGING_PROHIBIT_CHANGING_OF = ... # type: Any +NO_FILE_MAPPING = ... # type: Any +WRONG_MAGIC = ... # type: Any +PS_MANY_PARAM = ... # type: Any +KEY_PART_0 = ... # type: Any +VIEW_CHECKSUM = ... # type: Any +VIEW_MULTIUPDATE = ... # type: Any +VIEW_NO_INSERT_FIELD_LIST = ... # type: Any +VIEW_DELETE_MERGE_VIEW = ... # type: Any +CANNOT_USER = ... # type: Any +XAER_NOTA = ... # type: Any +XAER_INVAL = ... # type: Any +XAER_RMFAIL = ... # type: Any +XAER_OUTSIDE = ... # type: Any +XAER_RMERR = ... # type: Any +XA_RBROLLBACK = ... # type: Any +NONEXISTING_PROC_GRANT = ... # type: Any +PROC_AUTO_GRANT_FAIL = ... # type: Any +PROC_AUTO_REVOKE_FAIL = ... # type: Any +DATA_TOO_LONG = ... # type: Any +SP_BAD_SQLSTATE = ... # type: Any +STARTUP = ... # type: Any +LOAD_FROM_FIXED_SIZE_ROWS_TO_VAR = ... # type: Any +CANT_CREATE_USER_WITH_GRANT = ... # type: Any +WRONG_VALUE_FOR_TYPE = ... # type: Any +TABLE_DEF_CHANGED = ... # type: Any +SP_DUP_HANDLER = ... # type: Any +SP_NOT_VAR_ARG = ... # type: Any +SP_NO_RETSET = ... # type: Any +CANT_CREATE_GEOMETRY_OBJECT = ... # type: Any +FAILED_ROUTINE_BREAK_BINLOG = ... # type: Any +BINLOG_UNSAFE_ROUTINE = ... # type: Any +BINLOG_CREATE_ROUTINE_NEED_SUPER = ... # type: Any +EXEC_STMT_WITH_OPEN_CURSOR = ... # type: Any +STMT_HAS_NO_OPEN_CURSOR = ... # type: Any +COMMIT_NOT_ALLOWED_IN_SF_OR_TRG = ... # type: Any +NO_DEFAULT_FOR_VIEW_FIELD = ... # type: Any +SP_NO_RECURSION = ... # type: Any +TOO_BIG_SCALE = ... # type: Any +TOO_BIG_PRECISION = ... # type: Any +M_BIGGER_THAN_D = ... # type: Any +WRONG_LOCK_OF_SYSTEM_TABLE = ... # type: Any +CONNECT_TO_FOREIGN_DATA_SOURCE = ... # type: Any +QUERY_ON_FOREIGN_DATA_SOURCE = ... # type: Any +FOREIGN_DATA_SOURCE_DOESNT_EXIST = ... # type: Any +FOREIGN_DATA_STRING_INVALID_CANT_CREATE = ... # type: Any +FOREIGN_DATA_STRING_INVALID = ... # type: Any +CANT_CREATE_FEDERATED_TABLE = ... # type: Any +TRG_IN_WRONG_SCHEMA = ... # type: Any +STACK_OVERRUN_NEED_MORE = ... # type: Any +TOO_LONG_BODY = ... # type: Any +WARN_CANT_DROP_DEFAULT_KEYCACHE = ... # type: Any +TOO_BIG_DISPLAYWIDTH = ... # type: Any +XAER_DUPID = ... # type: Any +DATETIME_FUNCTION_OVERFLOW = ... # type: Any +CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG = ... # type: Any +VIEW_PREVENT_UPDATE = ... # type: Any +PS_NO_RECURSION = ... # type: Any +SP_CANT_SET_AUTOCOMMIT = ... # type: Any +MALFORMED_DEFINER = ... # type: Any +VIEW_FRM_NO_USER = ... # type: Any +VIEW_OTHER_USER = ... # type: Any +NO_SUCH_USER = ... # type: Any +FORBID_SCHEMA_CHANGE = ... # type: Any +ROW_IS_REFERENCED_2 = ... # type: Any +NO_REFERENCED_ROW_2 = ... # type: Any +SP_BAD_VAR_SHADOW = ... # type: Any +TRG_NO_DEFINER = ... # type: Any +OLD_FILE_FORMAT = ... # type: Any +SP_RECURSION_LIMIT = ... # type: Any +SP_PROC_TABLE_CORRUPT = ... # type: Any +SP_WRONG_NAME = ... # type: Any +TABLE_NEEDS_UPGRADE = ... # type: Any +SP_NO_AGGREGATE = ... # type: Any +MAX_PREPARED_STMT_COUNT_REACHED = ... # type: Any +VIEW_RECURSIVE = ... # type: Any +NON_GROUPING_FIELD_USED = ... # type: Any +TABLE_CANT_HANDLE_SPKEYS = ... # type: Any +NO_TRIGGERS_ON_SYSTEM_SCHEMA = ... # type: Any +USERNAME = ... # type: Any +HOSTNAME = ... # type: Any +WRONG_STRING_LENGTH = ... # type: Any +ERROR_LAST = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/FIELD_TYPE.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/FIELD_TYPE.pyi new file mode 100644 index 000000000..e05bd6c2b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/FIELD_TYPE.pyi @@ -0,0 +1,31 @@ +from typing import Any + +DECIMAL = ... # type: Any +TINY = ... # type: Any +SHORT = ... # type: Any +LONG = ... # type: Any +FLOAT = ... # type: Any +DOUBLE = ... # type: Any +NULL = ... # type: Any +TIMESTAMP = ... # type: Any +LONGLONG = ... # type: Any +INT24 = ... # type: Any +DATE = ... # type: Any +TIME = ... # type: Any +DATETIME = ... # type: Any +YEAR = ... # type: Any +NEWDATE = ... # type: Any +VARCHAR = ... # type: Any +BIT = ... # type: Any +NEWDECIMAL = ... # type: Any +ENUM = ... # type: Any +SET = ... # type: Any +TINY_BLOB = ... # type: Any +MEDIUM_BLOB = ... # type: Any +LONG_BLOB = ... # type: Any +BLOB = ... # type: Any +VAR_STRING = ... # type: Any +STRING = ... # type: Any +GEOMETRY = ... # type: Any +CHAR = ... # type: Any +INTERVAL = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/FLAG.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/FLAG.pyi new file mode 100644 index 000000000..869a987d3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/FLAG.pyi @@ -0,0 +1,17 @@ +from typing import Any + +NOT_NULL = ... # type: Any +PRI_KEY = ... # type: Any +UNIQUE_KEY = ... # type: Any +MULTIPLE_KEY = ... # type: Any +BLOB = ... # type: Any +UNSIGNED = ... # type: Any +ZEROFILL = ... # type: Any +BINARY = ... # type: Any +ENUM = ... # type: Any +AUTO_INCREMENT = ... # type: Any +TIMESTAMP = ... # type: Any +SET = ... # type: Any +PART_KEY = ... # type: Any +GROUP = ... # type: Any +UNIQUE = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/SERVER_STATUS.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/SERVER_STATUS.pyi new file mode 100644 index 000000000..ae81f046c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/SERVER_STATUS.pyi @@ -0,0 +1,12 @@ +from typing import Any + +SERVER_STATUS_IN_TRANS = ... # type: Any +SERVER_STATUS_AUTOCOMMIT = ... # type: Any +SERVER_MORE_RESULTS_EXISTS = ... # type: Any +SERVER_QUERY_NO_GOOD_INDEX_USED = ... # type: Any +SERVER_QUERY_NO_INDEX_USED = ... # type: Any +SERVER_STATUS_CURSOR_EXISTS = ... # type: Any +SERVER_STATUS_LAST_ROW_SENT = ... # type: Any +SERVER_STATUS_DB_DROPPED = ... # type: Any +SERVER_STATUS_NO_BACKSLASH_ESCAPES = ... # type: Any +SERVER_STATUS_METADATA_CHANGED = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/constants/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/converters.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/converters.pyi new file mode 100644 index 000000000..94ba99a06 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/converters.pyi @@ -0,0 +1,46 @@ +from typing import Any +from .constants import FIELD_TYPE as FIELD_TYPE, FLAG as FLAG +from .charset import charset_by_id as charset_by_id + +PYTHON3 = ... # type: Any +ESCAPE_REGEX = ... # type: Any +ESCAPE_MAP = ... # type: Any + +def escape_item(val, charset): ... +def escape_dict(val, charset): ... +def escape_sequence(val, charset): ... +def escape_set(val, charset): ... +def escape_bool(value): ... +def escape_object(value): ... + +escape_int = ... # type: Any + +escape_long = ... # type: Any + +def escape_float(value): ... +def escape_string(value): ... +def escape_unicode(value): ... +def escape_None(value): ... +def escape_timedelta(obj): ... +def escape_time(obj): ... +def escape_datetime(obj): ... +def escape_date(obj): ... +def escape_struct_time(obj): ... +def convert_datetime(connection, field, obj): ... +def convert_timedelta(connection, field, obj): ... +def convert_time(connection, field, obj): ... +def convert_date(connection, field, obj): ... +def convert_mysql_timestamp(connection, field, timestamp): ... +def convert_set(s): ... +def convert_bit(connection, field, b): ... +def convert_characters(connection, field, data): ... +def convert_int(connection, field, data): ... +def convert_long(connection, field, data): ... +def convert_float(connection, field, data): ... + +encoders = ... # type: Any +decoders = ... # type: Any +conversions = ... # type: Any + +def convert_decimal(connection, field, data): ... +def escape_decimal(obj): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/cursors.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/cursors.pyi new file mode 100644 index 000000000..80f37c101 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/cursors.pyi @@ -0,0 +1,46 @@ +from typing import Union, Tuple, Any, Dict, Optional, Text, Iterator, List +from .connections import Connection + +Gen = Union[Tuple[Any, ...], Dict[str, Any]] + +class Cursor: + connection = ... # type: Connection + description = ... # type: Tuple[Text, ...] + rownumber = ... # type: int + rowcount = ... # type: int + arraysize = ... # type: int + messages = ... # type: Any + errorhandler = ... # type: Any + lastrowid = ... # type: int + def __init__(self, connection: Connection) -> None: ... + def __del__(self) -> None: ... + def close(self) -> None: ... + def setinputsizes(self, *args): ... + def setoutputsizes(self, *args): ... + def nextset(self): ... + def execute(self, query: str, args=None) -> int: ... + def executemany(self, query: str, args) -> int: ... + def callproc(self, procname, args=...): ... + def fetchone(self) -> Optional[Gen]: ... + def fetchmany(self, size: Optional[int] = ...) -> Union[Optional[Gen], List[Gen]]: ... + def fetchall(self) -> Optional[Tuple[Gen, ...]]: ... + def scroll(self, value: int, mode: str = ...): ... + def __iter__(self): ... + +class DictCursor(Cursor): + def fetchone(self) -> Optional[Dict[str, Any]]: ... + def fetchmany(self, size: Optional[int] = ...) -> Optional[Tuple[Dict[str, Any], ...]]: ... + def fetchall(self) -> Optional[Tuple[Dict[str, Any], ...]]: ... + +class DictCursorMixin: + dict_type = ... # type: Any + +class SSCursor(Cursor): + # fetchall return type is incompatible with the supertype. + def fetchall(self) -> List[Gen]: ... # type: ignore + def fetchall_unbuffered(self) -> Iterator[Tuple[Gen, ...]]: ... + def __iter__(self) -> Iterator[Tuple[Gen, ...]]: ... + def fetchmany(self, size: Optional[int] = ...) -> List[Gen]: ... + def scroll(self, value: int, mode: str = ...) -> None: ... + +class SSDictCursor(DictCursorMixin, SSCursor): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/err.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/err.pyi new file mode 100644 index 000000000..c0320a62e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/err.pyi @@ -0,0 +1,18 @@ +from typing import Dict +from .constants import ER as ER + +class MySQLError(Exception): ... +class Warning(MySQLError): ... +class Error(MySQLError): ... +class InterfaceError(Error): ... +class DatabaseError(Error): ... +class DataError(DatabaseError): ... +class OperationalError(DatabaseError): ... +class IntegrityError(DatabaseError): ... +class InternalError(DatabaseError): ... +class ProgrammingError(DatabaseError): ... +class NotSupportedError(DatabaseError): ... + +error_map = ... # type: Dict + +def raise_mysql_exception(data) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/times.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/times.pyi new file mode 100644 index 000000000..4cc207af5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/times.pyi @@ -0,0 +1,10 @@ +from typing import Any + +Date = ... # type: Any +Time = ... # type: Any +TimeDelta = ... # type: Any +Timestamp = ... # type: Any + +def DateFromTicks(ticks): ... +def TimeFromTicks(ticks): ... +def TimestampFromTicks(ticks): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/util.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/util.pyi new file mode 100644 index 000000000..3d9a65b4b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pymysql/util.pyi @@ -0,0 +1,3 @@ +def byte2int(b): ... +def int2byte(i): ... +def join_bytes(bs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/__init__.pyi new file mode 100644 index 000000000..83e691d7a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/__init__.pyi @@ -0,0 +1 @@ +__license__: str diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/attributes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/attributes.pyi new file mode 100644 index 000000000..f2a2c8e82 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/attributes.pyi @@ -0,0 +1,96 @@ +from typing import Any, Callable, Dict, Generic, Iterable, List, Mapping, Optional, Text, Type, TypeVar, Union, Set + +from datetime import datetime + +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') +_MT = TypeVar('_MT', bound='MapAttribute') + +class Attribute(Generic[_T]): + attr_name: Optional[Text] + attr_type: Text + null: bool + default: Any + is_hash_key: bool + is_range_key: bool + def __init__(self, hash_key: bool = ..., range_key: bool = ..., null: Optional[bool] = ..., default: Optional[Union[_T, Callable[..., _T]]] = ..., attr_name: Optional[Text] = ...) -> None: ... + def __set__(self, instance: Any, value: Optional[_T]) -> None: ... + def serialize(self, value: Any) -> Any: ... + def deserialize(self, value: Any) -> Any: ... + def get_value(self, value: Any) -> Any: ... + def between(self, lower: Any, upper: Any) -> Any: ... + def is_in(self, *values: Any) -> Any: ... + def exists(self) -> Any: ... + def does_not_exist(self) -> Any: ... + def is_type(self) -> Any: ... + def startswith(self, prefix: str) -> Any: ... + def contains(self, item: Any) -> Any: ... + def append(self, other: Any) -> Any: ... + def prepend(self, other: Any) -> Any: ... + def set(self, value: Any) -> Any: ... + def remove(self) -> Any: ... + def add(self, *values: Any) -> Any: ... + def delete(self, *values: Any) -> Any: ... + +class SetMixin(object): + def serialize(self, value): ... + def deserialize(self, value): ... + +class BinaryAttribute(Attribute[bytes]): + def __get__(self, instance: Any, owner: Any) -> bytes: ... + +class BinarySetAttribute(SetMixin, Attribute[Set[bytes]]): + def __get__(self, instance: Any, owner: Any) -> Set[bytes]: ... + +class UnicodeSetAttribute(SetMixin, Attribute[Set[Text]]): + def element_serialize(self, value: Any) -> Any: ... + def element_deserialize(self, value: Any) -> Any: ... + def __get__(self, instance: Any, owner: Any) -> Set[Text]: ... + +class UnicodeAttribute(Attribute[Text]): + def __get__(self, instance: Any, owner: Any) -> Text: ... + +class JSONAttribute(Attribute[Any]): + def __get__(self, instance: Any, owner: Any) -> Any: ... + +class LegacyBooleanAttribute(Attribute[bool]): + def __get__(self, instance: Any, owner: Any) -> bool: ... + +class BooleanAttribute(Attribute[bool]): + def __get__(self, instance: Any, owner: Any) -> bool: ... + +class NumberSetAttribute(SetMixin, Attribute[Set[float]]): + def __get__(self, instance: Any, owner: Any) -> Set[float]: ... + +class NumberAttribute(Attribute[float]): + def __get__(self, instance: Any, owner: Any) -> float: ... + +class UTCDateTimeAttribute(Attribute[datetime]): + def __get__(self, instance: Any, owner: Any) -> datetime: ... + +class NullAttribute(Attribute[None]): + def __get__(self, instance: Any, owner: Any) -> None: ... + +class MapAttributeMeta(type): + def __init__(cls, name, bases, attrs) -> None: ... + +class MapAttribute(Generic[_KT, _VT], Attribute[Mapping[_KT, _VT]], metaclass=MapAttributeMeta): + attribute_values: Any + def __init__(self, hash_key: bool = ..., range_key: bool = ..., null: Optional[bool] = ..., default: Optional[Union[Any, Callable[..., Any]]] = ..., attr_name: Optional[Text] = ..., **attrs) -> None: ... + def __iter__(self) -> Iterable[_VT]: ... + def __getattr__(self, attr: str) -> _VT: ... + def __getitem__(self, item: _KT) -> _VT: ... + def __set__(self, instance: Any, value: Union[None, MapAttribute[_KT, _VT], Mapping[_KT, _VT]]) -> None: ... + def __get__(self: _MT, instance: Any, owner: Any) -> _MT: ... + def is_type_safe(self, key: Any, value: Any) -> bool: ... + def validate(self) -> bool: ... + +class ListAttribute(Generic[_T], Attribute[List[_T]]): + element_type: Any + def __init__(self, hash_key: bool = ..., range_key: bool = ..., null: Optional[bool] = ..., default: Optional[Union[Any, Callable[..., Any]]] = ..., attr_name: Optional[Text] = ..., of: Optional[Type[_T]] = ...) -> None: ... + def __get__(self, instance: Any, owner: Any) -> List[_T]: ... + +DESERIALIZE_CLASS_MAP: Dict[Text, Attribute] +SERIALIZE_CLASS_MAP: Dict[Type, Attribute] +SERIALIZE_KEY_MAP: Dict[Type, Text] diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/__init__.pyi new file mode 100644 index 000000000..1860736ba --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/__init__.pyi @@ -0,0 +1,2 @@ +from pynamodb.connection.base import Connection as Connection +from pynamodb.connection.table import TableConnection as TableConnection diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/base.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/base.pyi new file mode 100644 index 000000000..b0f023c71 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/base.pyi @@ -0,0 +1,55 @@ +from typing import Any, Dict, Optional, Text + +BOTOCORE_EXCEPTIONS: Any +log: Any + +class MetaTable: + data: Dict + def __init__(self, data: Dict) -> None: ... + @property + def range_keyname(self) -> Optional[Text]: ... + @property + def hash_keyname(self) -> Text: ... + def get_index_hash_keyname(self, index_name: Text) -> Optional[Text]: ... + def get_item_attribute_map(self, attributes, item_key: Any = ..., pythonic_key: bool = ...): ... + def get_attribute_type(self, attribute_name, value: Optional[Any] = ...): ... + def get_identifier_map(self, hash_key, range_key: Optional[Any] = ..., key: Any = ...): ... + def get_exclusive_start_key_map(self, exclusive_start_key): ... + +class Connection: + host: Any + region: Any + session_cls: Any + def __init__(self, region: Optional[Any] = ..., host: Optional[Any] = ..., session_cls: Optional[Any] = ..., request_timeout_seconds: Optional[Any] = ..., max_retry_attempts: Optional[Any] = ..., base_backoff_ms: Optional[Any] = ...) -> None: ... + def dispatch(self, operation_name, operation_kwargs): ... + @property + def session(self): ... + @property + def requests_session(self): ... + @property + def client(self): ... + def get_meta_table(self, table_name: Text, refresh: bool = ...): ... + def create_table(self, table_name: Text, attribute_definitions: Optional[Any] = ..., key_schema: Optional[Any] = ..., read_capacity_units: Optional[Any] = ..., write_capacity_units: Optional[Any] = ..., global_secondary_indexes: Optional[Any] = ..., local_secondary_indexes: Optional[Any] = ..., stream_specification: Optional[Any] = ...): ... + def delete_table(self, table_name: Text): ... + def update_table(self, table_name: Text, read_capacity_units: Optional[Any] = ..., write_capacity_units: Optional[Any] = ..., global_secondary_index_updates: Optional[Any] = ...): ... + def list_tables(self, exclusive_start_table_name: Optional[Any] = ..., limit: Optional[Any] = ...): ... + def describe_table(self, table_name: Text): ... + def get_conditional_operator(self, operator): ... + def get_item_attribute_map(self, table_name: Text, attributes, item_key: Any = ..., pythonic_key: bool = ...): ... + def get_expected_map(self, table_name: Text, expected): ... + def parse_attribute(self, attribute, return_type: bool = ...): ... + def get_attribute_type(self, table_name: Text, attribute_name, value: Optional[Any] = ...): ... + def get_identifier_map(self, table_name: Text, hash_key, range_key: Optional[Any] = ..., key: Any = ...): ... + def get_query_filter_map(self, table_name: Text, query_filters): ... + def get_consumed_capacity_map(self, return_consumed_capacity): ... + def get_return_values_map(self, return_values): ... + def get_item_collection_map(self, return_item_collection_metrics): ... + def get_exclusive_start_key_map(self, table_name: Text, exclusive_start_key): ... + def delete_item(self, table_name: Text, hash_key, range_key: Optional[Any] = ..., expected: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., return_values: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ...): ... + def update_item(self, table_name: Text, hash_key, range_key: Optional[Any] = ..., attribute_updates: Optional[Any] = ..., expected: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ..., return_values: Optional[Any] = ...): ... + def put_item(self, table_name: Text, hash_key, range_key: Optional[Any] = ..., attributes: Optional[Any] = ..., expected: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., return_values: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ...): ... + def batch_write_item(self, table_name: Text, put_items: Optional[Any] = ..., delete_items: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ...): ... + def batch_get_item(self, table_name: Text, keys, consistent_read: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., attributes_to_get: Optional[Any] = ...): ... + def get_item(self, table_name: Text, hash_key, range_key: Optional[Any] = ..., consistent_read: bool = ..., attributes_to_get: Optional[Any] = ...): ... + def scan(self, table_name: Text, attributes_to_get: Optional[Any] = ..., limit: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., scan_filter: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., exclusive_start_key: Optional[Any] = ..., segment: Optional[Any] = ..., total_segments: Optional[Any] = ...): ... + def query(self, table_name: Text, hash_key, attributes_to_get: Optional[Any] = ..., consistent_read: bool = ..., exclusive_start_key: Optional[Any] = ..., index_name: Optional[Any] = ..., key_conditions: Optional[Any] = ..., query_filters: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., limit: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., scan_index_forward: Optional[Any] = ..., select: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/table.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/table.pyi new file mode 100644 index 000000000..0f820af9d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/table.pyi @@ -0,0 +1,18 @@ +from typing import Any, Optional + +class TableConnection: + table_name: Any + connection: Any + def __init__(self, table_name, region: Optional[Any] = ..., host: Optional[Any] = ..., session_cls: Optional[Any] = ..., request_timeout_seconds: Optional[Any] = ..., max_retry_attempts: Optional[Any] = ..., base_backoff_ms: Optional[Any] = ...) -> None: ... + def delete_item(self, hash_key, range_key: Optional[Any] = ..., expected: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., return_values: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ...): ... + def update_item(self, hash_key, range_key: Optional[Any] = ..., attribute_updates: Optional[Any] = ..., expected: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ..., return_values: Optional[Any] = ...): ... + def put_item(self, hash_key, range_key: Optional[Any] = ..., attributes: Optional[Any] = ..., expected: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., return_values: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ...): ... + def batch_write_item(self, put_items: Optional[Any] = ..., delete_items: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., return_item_collection_metrics: Optional[Any] = ...): ... + def batch_get_item(self, keys, consistent_read: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., attributes_to_get: Optional[Any] = ...): ... + def get_item(self, hash_key, range_key: Optional[Any] = ..., consistent_read: bool = ..., attributes_to_get: Optional[Any] = ...): ... + def scan(self, attributes_to_get: Optional[Any] = ..., limit: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., scan_filter: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., segment: Optional[Any] = ..., total_segments: Optional[Any] = ..., exclusive_start_key: Optional[Any] = ...): ... + def query(self, hash_key, attributes_to_get: Optional[Any] = ..., consistent_read: bool = ..., exclusive_start_key: Optional[Any] = ..., index_name: Optional[Any] = ..., key_conditions: Optional[Any] = ..., query_filters: Optional[Any] = ..., limit: Optional[Any] = ..., return_consumed_capacity: Optional[Any] = ..., scan_index_forward: Optional[Any] = ..., conditional_operator: Optional[Any] = ..., select: Optional[Any] = ...): ... + def describe_table(self): ... + def delete_table(self): ... + def update_table(self, read_capacity_units: Optional[Any] = ..., write_capacity_units: Optional[Any] = ..., global_secondary_index_updates: Optional[Any] = ...): ... + def create_table(self, attribute_definitions: Optional[Any] = ..., key_schema: Optional[Any] = ..., read_capacity_units: Optional[Any] = ..., write_capacity_units: Optional[Any] = ..., global_secondary_indexes: Optional[Any] = ..., local_secondary_indexes: Optional[Any] = ..., stream_specification: Optional[Any] = ...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/util.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/util.pyi new file mode 100644 index 000000000..20635c69f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/connection/util.pyi @@ -0,0 +1,3 @@ +from typing import Text + +def pythonic(var_name: Text) -> Text: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/constants.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/constants.pyi new file mode 100644 index 000000000..7c26cd619 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/constants.pyi @@ -0,0 +1,166 @@ +from typing import Any + +BATCH_WRITE_ITEM: str +DESCRIBE_TABLE: str +BATCH_GET_ITEM: str +CREATE_TABLE: str +UPDATE_TABLE: str +DELETE_TABLE: str +LIST_TABLES: str +UPDATE_ITEM: str +DELETE_ITEM: str +GET_ITEM: str +PUT_ITEM: str +QUERY: str +SCAN: str +GLOBAL_SECONDARY_INDEX_UPDATES: str +RETURN_ITEM_COLL_METRICS: str +EXCLUSIVE_START_TABLE_NAME: str +RETURN_CONSUMED_CAPACITY: str +COMPARISON_OPERATOR: str +SCAN_INDEX_FORWARD: str +ATTR_DEFINITIONS: str +ATTR_VALUE_LIST: str +TABLE_DESCRIPTION: str +UNPROCESSED_KEYS: str +UNPROCESSED_ITEMS: str +CONSISTENT_READ: str +DELETE_REQUEST: str +RETURN_VALUES: str +REQUEST_ITEMS: str +ATTRS_TO_GET: str +ATTR_UPDATES: str +TABLE_STATUS: str +SCAN_FILTER: str +TABLE_NAME: str +KEY_SCHEMA: str +ATTR_NAME: str +ATTR_TYPE: str +ITEM_COUNT: str +CAMEL_COUNT: str +PUT_REQUEST: str +INDEX_NAME: str +ATTRIBUTES: str +TABLE_KEY: str +RESPONSES: str +RANGE_KEY: str +KEY_TYPE: str +ACTION: str +UPDATE: str +EXISTS: str +SELECT: str +ACTIVE: str +LIMIT: str +ITEMS: str +ITEM: str +KEYS: str +UTC: str +KEY: str +DEFAULT_ENCODING: str +DEFAULT_REGION: str +DATETIME_FORMAT: str +SERVICE_NAME: str +HTTP_OK: int +HTTP_BAD_REQUEST: int +PROVISIONED_THROUGHPUT: str +READ_CAPACITY_UNITS: str +WRITE_CAPACITY_UNITS: str +STRING_SHORT: str +STRING_SET_SHORT: str +NUMBER_SHORT: str +NUMBER_SET_SHORT: str +BINARY_SHORT: str +BINARY_SET_SHORT: str +MAP_SHORT: str +LIST_SHORT: str +BOOLEAN: str +BOOLEAN_SHORT: str +STRING: str +STRING_SET: str +NUMBER: str +NUMBER_SET: str +BINARY: str +BINARY_SET: str +MAP: str +LIST: str +SHORT_ATTR_TYPES: Any +ATTR_TYPE_MAP: Any +LOCAL_SECONDARY_INDEX: str +LOCAL_SECONDARY_INDEXES: str +GLOBAL_SECONDARY_INDEX: str +GLOBAL_SECONDARY_INDEXES: str +PROJECTION: str +PROJECTION_TYPE: str +NON_KEY_ATTRIBUTES: str +KEYS_ONLY: str +ALL: str +INCLUDE: str +STREAM_VIEW_TYPE: str +STREAM_SPECIFICATION: str +STREAM_ENABLED: str +STREAM_NEW_IMAGE: str +STREAM_OLD_IMAGE: str +STREAM_NEW_AND_OLD_IMAGE: str +STREAM_KEYS_ONLY: str +EXCLUSIVE_START_KEY: str +LAST_EVALUATED_KEY: str +QUERY_FILTER: str +BEGINS_WITH: str +BETWEEN: str +EQ: str +NE: str +LE: str +LT: str +GE: str +GT: str +IN: str +KEY_CONDITIONS: str +COMPARISON_OPERATOR_VALUES: Any +QUERY_OPERATOR_MAP: Any +NOT_NULL: str +NULL: str +CONTAINS: str +NOT_CONTAINS: str +ALL_ATTRIBUTES: str +ALL_PROJECTED_ATTRIBUTES: str +SPECIFIC_ATTRIBUTES: str +COUNT: str +SELECT_VALUES: Any +SCAN_OPERATOR_MAP: Any +QUERY_FILTER_OPERATOR_MAP: Any +DELETE_FILTER_OPERATOR_MAP: Any +UPDATE_FILTER_OPERATOR_MAP: Any +PUT_FILTER_OPERATOR_MAP: Any +SEGMENT: str +TOTAL_SEGMENTS: str +SCAN_FILTER_VALUES: Any +QUERY_FILTER_VALUES: Any +DELETE_FILTER_VALUES: Any +VALUE: str +EXPECTED: str +CONSUMED_CAPACITY: str +CAPACITY_UNITS: str +INDEXES: str +TOTAL: str +NONE: str +RETURN_CONSUMED_CAPACITY_VALUES: Any +SIZE: str +RETURN_ITEM_COLL_METRICS_VALUES: Any +ALL_OLD: str +UPDATED_OLD: str +ALL_NEW: str +UPDATED_NEW: str +RETURN_VALUES_VALUES: Any +PUT: str +DELETE: str +ADD: str +ATTR_UPDATE_ACTIONS: Any +BATCH_GET_PAGE_LIMIT: int +BATCH_WRITE_PAGE_LIMIT: int +META_CLASS_NAME: str +REGION: str +HOST: str +CONDITIONAL_OPERATOR: str +AND: str +OR: str +CONDITIONAL_OPERATORS: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/exceptions.pyi new file mode 100644 index 000000000..728db4a7b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/exceptions.pyi @@ -0,0 +1,23 @@ +from typing import Any, Optional, Text + +class PynamoDBException(Exception): + msg: str + cause: Any + def __init__(self, msg: Optional[Text] = ..., cause: Optional[Exception] = ...) -> None: ... + +class PynamoDBConnectionError(PynamoDBException): ... +class DeleteError(PynamoDBConnectionError): ... +class QueryError(PynamoDBConnectionError): ... +class ScanError(PynamoDBConnectionError): ... +class PutError(PynamoDBConnectionError): ... +class UpdateError(PynamoDBConnectionError): ... +class GetError(PynamoDBConnectionError): ... +class TableError(PynamoDBConnectionError): ... +class DoesNotExist(PynamoDBException): ... + +class TableDoesNotExist(PynamoDBException): + def __init__(self, table_name) -> None: ... + +class VerboseClientError(Exception): + MSG_TEMPLATE: Any + def __init__(self, error_response, operation_name, verbose_properties: Optional[Any] = ...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/indexes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/indexes.pyi new file mode 100644 index 000000000..35506d097 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/indexes.pyi @@ -0,0 +1,30 @@ +from typing import Any, Optional + +class IndexMeta(type): + def __init__(cls, name, bases, attrs) -> None: ... + +class Index(metaclass=IndexMeta): + Meta: Any + def __init__(self) -> None: ... + @classmethod + def count(cls, hash_key, consistent_read: bool = ..., **filters) -> int: ... + @classmethod + def query(self, hash_key, scan_index_forward: Optional[Any] = ..., consistent_read: bool = ..., limit: Optional[Any] = ..., last_evaluated_key: Optional[Any] = ..., attributes_to_get: Optional[Any] = ..., **filters): ... + +class GlobalSecondaryIndex(Index): ... +class LocalSecondaryIndex(Index): ... + +class Projection(object): + projection_type: Any + non_key_attributes: Any + +class KeysOnlyProjection(Projection): + projection_type: Any + +class IncludeProjection(Projection): + projection_type: Any + non_key_attributes: Any + def __init__(self, non_attr_keys: Optional[Any] = ...) -> None: ... + +class AllProjection(Projection): + projection_type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/models.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/models.pyi new file mode 100644 index 000000000..ee728d41e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/models.pyi @@ -0,0 +1,104 @@ +from .exceptions import DoesNotExist as DoesNotExist +from typing import Any, Dict, Generic, Iterable, Iterator, List, Optional, Sequence, Tuple, Type, TypeVar, Text, Union + +log: Any + +class DefaultMeta: ... + +class ResultSet(Iterable): + results: Any + operation: Any + arguments: Any + def __init__(self, results, operation, arguments) -> None: ... + def __iter__(self): ... + +class MetaModel(type): + def __init__(self, name: Text, bases: Tuple[type, ...], attrs: Dict[Any, Any]) -> None: ... + +_T = TypeVar('_T', bound='Model') +KeyType = Union[Text, bytes, float, int, Tuple] + +class Model(metaclass=MetaModel): + DoesNotExist = DoesNotExist + attribute_values: Dict[Text, Any] + def __init__(self, hash_key: Optional[KeyType] = ..., range_key: Optional[Any] = ..., **attrs) -> None: ... + @classmethod + def has_map_or_list_attributes(cls: Type[_T]) -> bool: ... + @classmethod + def batch_get(cls: Type[_T], items: Iterable[Union[KeyType, Iterable[KeyType]]], consistent_read: Optional[bool] = ..., attributes_to_get: Optional[Sequence[Text]] = ...) -> Iterator[_T]: ... + @classmethod + def batch_write(cls: Type[_T], auto_commit: bool = ...) -> BatchWrite[_T]: ... + def delete(self, condition: Optional[Any] = ..., conditional_operator: Optional[Text] = ..., **expected_values) -> Any: ... + def update(self, attributes: Optional[Dict[Text, Dict[Text, Any]]] = ..., actions: Optional[List[Any]] = ..., condition: Optional[Any] = ..., conditional_operator: Optional[Text] = ..., **expected_values) -> Any: ... + def update_item(self, attribute: Text, value: Optional[Any] = ..., action: Optional[Text] = ..., conditional_operator: Optional[Text] = ..., **expected_values): ... + def save(self, condition: Optional[Any] = ..., conditional_operator: Optional[Text] = ..., **expected_values) -> Dict[str, Any]: ... + def refresh(self, consistent_read: bool = ...): ... + @classmethod + def get(cls: Type[_T], hash_key: KeyType, range_key: Optional[KeyType] = ..., consistent_read: bool = ...) -> _T: ... + @classmethod + def from_raw_data(cls: Type[_T], data) -> _T: ... + @classmethod + def count(cls: Type[_T], hash_key: Optional[KeyType] = ..., consistent_read: bool = ..., index_name: Optional[Text] = ..., limit: Optional[int] = ..., **filters) -> int: ... + @classmethod + def query(cls: Type[_T], hash_key: KeyType, consistent_read: bool = ..., index_name: Optional[Text] = ..., scan_index_forward: Optional[Any] = ..., conditional_operator: Optional[Text] = ..., limit: Optional[int] = ..., last_evaluated_key: Optional[Any] = ..., attributes_to_get: Optional[Iterable[Text]] = ..., page_size: Optional[int] = ..., **filters) -> Iterator[_T]: ... + @classmethod + def rate_limited_scan( + cls: Type[_T], + # TODO: annotate Condition class + filter_condition: Optional[Any] = ..., + attributes_to_get: Optional[Sequence[Text]] = ..., + segment: Optional[int] = ..., + total_segments: Optional[int] = ..., + limit: Optional[int] = ..., + conditional_operator: Optional[Text] = ..., + last_evaluated_key: Optional[Any] = ..., + page_size: Optional[int] = ..., + timeout_seconds: Optional[int] = ..., + read_capacity_to_consume_per_second: int = ..., + allow_rate_limited_scan_without_consumed_capacity: Optional[bool] = ..., + max_sleep_between_retry: int = ..., + max_consecutive_exceptions: int = ..., + consistent_read: Optional[bool] = ..., + index_name: Optional[str] = ..., + **filters: Any + ) -> Iterator[_T]: ... + @classmethod + def scan(cls: Type[_T], segment: Optional[int] = ..., total_segments: Optional[int] = ..., limit: Optional[int] = ..., conditional_operator: Optional[Text] = ..., last_evaluated_key: Optional[Any] = ..., page_size: Optional[int] = ..., **filters) -> Iterator[_T]: ... + @classmethod + def exists(cls: Type[_T]) -> bool: ... + @classmethod + def delete_table(cls): ... + @classmethod + def describe_table(cls): ... + @classmethod + def create_table(cls: Type[_T], wait: bool = ..., read_capacity_units: Optional[Any] = ..., write_capacity_units: Optional[Any] = ...): ... + @classmethod + def dumps(cls): ... + @classmethod + def dump(cls, filename): ... + @classmethod + def loads(cls, data): ... + @classmethod + def load(cls, filename): ... + @classmethod + def add_throttle_record(cls, records): ... + @classmethod + def get_throttle(cls): ... + @classmethod + def _get_attributes(cls) -> Dict[str, Any]: ... + +class ModelContextManager(Generic[_T]): + model: Type[_T] + auto_commit: bool + max_operations: int + pending_operations: List[Dict[Text, Any]] + def __init__(self, model: Type[_T], auto_commit: bool = ...) -> None: ... + def __enter__(self) -> ModelContextManager[_T]: ... + +class BatchWrite(Generic[_T], ModelContextManager[_T]): + def save(self, put_item: _T) -> None: ... + def delete(self, del_item: _T) -> None: ... + def __enter__(self) -> BatchWrite[_T]: ... + def __exit__(self, exc_type, exc_val, exc_tb) -> None: ... + pending_operations: Any + def commit(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/settings.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/settings.pyi new file mode 100644 index 000000000..76fc4172f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/settings.pyi @@ -0,0 +1,8 @@ +from typing import Any + +log: Any +default_settings_dict: Any +OVERRIDE_SETTINGS_PATH: Any +override_settings: Any + +def get_settings_value(key): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/throttle.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/throttle.pyi new file mode 100644 index 000000000..6948b6896 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/throttle.pyi @@ -0,0 +1,19 @@ +from typing import Any, Optional + +log: Any + +class ThrottleBase: + capacity: Any + window: Any + records: Any + sleep_interval: Any + def __init__(self, capacity, window: int = ..., initial_sleep: Optional[Any] = ...) -> None: ... + def add_record(self, record): ... + def throttle(self): ... + +class NoThrottle(ThrottleBase): + def __init__(self) -> None: ... + def add_record(self, record): ... + +class Throttle(ThrottleBase): + def throttle(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/types.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/types.pyi new file mode 100644 index 000000000..14195f04f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pynamodb/types.pyi @@ -0,0 +1,5 @@ +STRING: str +NUMBER: str +BINARY: str +HASH: str +RANGE: str diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pytz/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pytz/__init__.pyi new file mode 100644 index 000000000..79b46a1cf --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pytz/__init__.pyi @@ -0,0 +1,41 @@ +# Stubs for pytz (Python 3.5) + +import datetime +from typing import Optional, List, Set, Dict, Union + +all_timezones = ... # type: List +all_timezones_set = ... # type: Set +common_timezones = ... # type: List +common_timezones_set = ... # type: Set +country_timezones = ... # type: Dict +country_names = ... # type: Dict + + +class _UTCclass(datetime.tzinfo): + zone = ... # type: str + def fromutc(self, dt: datetime.datetime) -> datetime.datetime: ... + def utcoffset(self, dt: Optional[datetime.datetime]) -> datetime.timedelta: ... + def tzname(self, dt: Optional[datetime.datetime]) -> str: ... + def dst(self, dt: Optional[datetime.datetime]) -> datetime.timedelta: ... + def localize(self, dt: datetime.datetime, is_dst: bool = ...) -> datetime.datetime: ... + def normalize(self, dt: datetime.datetime, is_dst: bool = ...) -> datetime.datetime: ... + +utc: _UTCclass +UTC: _UTCclass +ZERO: datetime.timedelta +HOUR: datetime.timedelta + + +class _BaseTzInfo(datetime.tzinfo): + zone = ... # type: str + + def fromutc(self, dt: datetime.datetime) -> datetime.datetime: ... + def localize(self, dt: datetime.datetime, is_dst: Optional[bool] = ...) -> datetime.datetime: ... + def normalize(self, dt: datetime.datetime) -> datetime.datetime: ... + + +class _StaticTzInfo(_BaseTzInfo): + def normalize(self, dt: datetime.datetime, is_dst: Optional[bool] = ...) -> datetime.datetime: ... + + +def timezone(zone: str) -> _BaseTzInfo: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pytz/lazy.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pytz/lazy.pyi new file mode 100644 index 000000000..795ed0427 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/pytz/lazy.pyi @@ -0,0 +1,14 @@ +from typing import Iterator, List, Set, TypeVar +from collections import Mapping + +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +class LazyDict(Mapping[_KT, _VT]): + def __getitem__(self, key: _KT) -> _VT: ... + def __iter__(self) -> Iterator[_KT]: ... + def __len__(self) -> int: ... + +class LazyList(List[_T]): ... +class LazySet(Set[_T]): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/__init__.pyi new file mode 100644 index 000000000..97b540572 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/__init__.pyi @@ -0,0 +1,40 @@ +# Stubs for requests (based on version 2.6.0, Python 3) + +from typing import Any +from . import models +from . import api +from . import sessions +from . import status_codes +from . import exceptions +from . import packages +import logging + +__title__ = ... # type: Any +__build__ = ... # type: Any +__license__ = ... # type: Any +__copyright__ = ... # type: Any +__version__ = ... # type: Any + +Request = models.Request +Response = models.Response +PreparedRequest = models.PreparedRequest +request = api.request +get = api.get +head = api.head +post = api.post +patch = api.patch +put = api.put +delete = api.delete +options = api.options +session = sessions.session +Session = sessions.Session +codes = status_codes.codes +RequestException = exceptions.RequestException +Timeout = exceptions.Timeout +URLRequired = exceptions.URLRequired +TooManyRedirects = exceptions.TooManyRedirects +HTTPError = exceptions.HTTPError +ConnectionError = exceptions.ConnectionError + +class NullHandler(logging.Handler): + def emit(self, record): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/adapters.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/adapters.pyi new file mode 100644 index 000000000..fe7e1162b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/adapters.pyi @@ -0,0 +1,72 @@ +# Stubs for requests.adapters (Python 3) + +from typing import Any, Container, Union, Text, Tuple +from . import models +from .packages.urllib3 import poolmanager +from .packages.urllib3 import response +from .packages.urllib3.util import retry +from . import compat +from . import utils +from . import structures +from .packages.urllib3 import exceptions as urllib3_exceptions +from . import cookies +from . import exceptions +from . import auth + +PreparedRequest = models.PreparedRequest +Response = models.Response +PoolManager = poolmanager.PoolManager +proxy_from_url = poolmanager.proxy_from_url +HTTPResponse = response.HTTPResponse +Retry = retry.Retry +DEFAULT_CA_BUNDLE_PATH = utils.DEFAULT_CA_BUNDLE_PATH +get_encoding_from_headers = utils.get_encoding_from_headers +prepend_scheme_if_needed = utils.prepend_scheme_if_needed +get_auth_from_url = utils.get_auth_from_url +urldefragauth = utils.urldefragauth +CaseInsensitiveDict = structures.CaseInsensitiveDict +ConnectTimeoutError = urllib3_exceptions.ConnectTimeoutError +MaxRetryError = urllib3_exceptions.MaxRetryError +ProtocolError = urllib3_exceptions.ProtocolError +ReadTimeoutError = urllib3_exceptions.ReadTimeoutError +ResponseError = urllib3_exceptions.ResponseError +extract_cookies_to_jar = cookies.extract_cookies_to_jar +ConnectionError = exceptions.ConnectionError +ConnectTimeout = exceptions.ConnectTimeout +ReadTimeout = exceptions.ReadTimeout +SSLError = exceptions.SSLError +ProxyError = exceptions.ProxyError +RetryError = exceptions.RetryError + +DEFAULT_POOLBLOCK = ... # type: Any +DEFAULT_POOLSIZE = ... # type: Any +DEFAULT_RETRIES = ... # type: Any + +class BaseAdapter: + def __init__(self) -> None: ... + def send(self, request: PreparedRequest, stream: bool = ..., + timeout: Union[None, float, Tuple[float, float]] = ..., + verify: bool = ..., + cert: Union[None, Union[bytes, Text], Container[Union[bytes, Text]]] = ... + ) -> Response: ... + def close(self) -> None: ... +class HTTPAdapter(BaseAdapter): + __attrs__ = ... # type: Any + max_retries = ... # type: Any + config = ... # type: Any + proxy_manager = ... # type: Any + def __init__(self, pool_connections=..., pool_maxsize=..., max_retries=..., + pool_block=...) -> None: ... + poolmanager = ... # type: Any + def init_poolmanager(self, connections, maxsize, block=..., **pool_kwargs): ... + def proxy_manager_for(self, proxy, **proxy_kwargs): ... + def cert_verify(self, conn, url, verify, cert): ... + def build_response(self, req, resp): ... + def get_connection(self, url, proxies=...): ... + def close(self): ... + def request_url(self, request, proxies): ... + def add_headers(self, request, **kwargs): ... + def proxy_headers(self, proxy): ... + # TODO: "request" is not actually optional, modified to please mypy. + def send(self, request=..., stream=..., timeout=..., verify=..., cert=..., + proxies=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/api.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/api.pyi new file mode 100644 index 000000000..49637a47f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/api.pyi @@ -0,0 +1,40 @@ +# Stubs for requests.api (Python 3) + +import sys +from typing import Optional, Union, Any, Iterable, Mapping, MutableMapping, Tuple, IO, Text + +from .models import Response + +if sys.version_info >= (3,): + _Text = str +else: + _Text = Union[str, Text] + +_ParamsMappingValueType = Union[_Text, bytes, int, float, Iterable[Union[_Text, bytes, int, float]]] +_Data = Union[ + None, + _Text, + bytes, + MutableMapping[str, Any], + MutableMapping[Text, Any], + Iterable[Tuple[_Text, Optional[_Text]]], + IO +] + +def request(method: str, url: str, **kwargs) -> Response: ... +def get(url: Union[_Text, bytes], + params: Optional[ + Union[Mapping[Union[_Text, bytes, int, float], _ParamsMappingValueType], + Union[_Text, bytes], + Tuple[Union[_Text, bytes, int, float], _ParamsMappingValueType], + Mapping[_Text, _ParamsMappingValueType], + Mapping[bytes, _ParamsMappingValueType], + Mapping[int, _ParamsMappingValueType], + Mapping[float, _ParamsMappingValueType]]] = ..., + **kwargs) -> Response: ... +def options(url: _Text, **kwargs) -> Response: ... +def head(url: _Text, **kwargs) -> Response: ... +def post(url: _Text, data: _Data=..., json=..., **kwargs) -> Response: ... +def put(url: _Text, data: _Data=..., json=..., **kwargs) -> Response: ... +def patch(url: _Text, data: _Data=..., json=..., **kwargs) -> Response: ... +def delete(url: _Text, **kwargs) -> Response: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/auth.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/auth.pyi new file mode 100644 index 000000000..09a6df76b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/auth.pyi @@ -0,0 +1,44 @@ +# Stubs for requests.auth (Python 3) + +from typing import Any, Text, Union +from . import compat +from . import cookies +from . import models +from . import utils +from . import status_codes + +extract_cookies_to_jar = cookies.extract_cookies_to_jar +parse_dict_header = utils.parse_dict_header +to_native_string = utils.to_native_string +codes = status_codes.codes + +CONTENT_TYPE_FORM_URLENCODED = ... # type: Any +CONTENT_TYPE_MULTI_PART = ... # type: Any + +def _basic_auth_str(username: Union[bytes, Text], password: Union[bytes, Text]) -> str: ... + +class AuthBase: + def __call__(self, r: models.Request) -> models.Request: ... + +class HTTPBasicAuth(AuthBase): + username = ... # type: Any + password = ... # type: Any + def __init__(self, username, password) -> None: ... + def __call__(self, r): ... + +class HTTPProxyAuth(HTTPBasicAuth): + def __call__(self, r): ... + +class HTTPDigestAuth(AuthBase): + username = ... # type: Any + password = ... # type: Any + last_nonce = ... # type: Any + nonce_count = ... # type: Any + chal = ... # type: Any + pos = ... # type: Any + num_401_calls = ... # type: Any + def __init__(self, username, password) -> None: ... + def build_digest_header(self, method, url): ... + def handle_redirect(self, r, **kwargs): ... + def handle_401(self, r, **kwargs): ... + def __call__(self, r): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/compat.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/compat.pyi new file mode 100644 index 000000000..63b92f6fe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/compat.pyi @@ -0,0 +1,6 @@ +# Stubs for requests.compat (Python 3.4) + +from typing import Any +import collections + +OrderedDict = collections.OrderedDict diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/cookies.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/cookies.pyi new file mode 100644 index 000000000..66650210e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/cookies.pyi @@ -0,0 +1,67 @@ +# Stubs for requests.cookies (Python 3) + +import sys +from typing import Any, MutableMapping +import collections +from . import compat + +if sys.version_info < (3, 0): + from cookielib import CookieJar +else: + from http.cookiejar import CookieJar + +class MockRequest: + type = ... # type: Any + def __init__(self, request) -> None: ... + def get_type(self): ... + def get_host(self): ... + def get_origin_req_host(self): ... + def get_full_url(self): ... + def is_unverifiable(self): ... + def has_header(self, name): ... + def get_header(self, name, default=...): ... + def add_header(self, key, val): ... + def add_unredirected_header(self, name, value): ... + def get_new_headers(self): ... + @property + def unverifiable(self): ... + @property + def origin_req_host(self): ... + @property + def host(self): ... + +class MockResponse: + def __init__(self, headers) -> None: ... + def info(self): ... + def getheaders(self, name): ... + +def extract_cookies_to_jar(jar, request, response): ... +def get_cookie_header(jar, request): ... +def remove_cookie_by_name(cookiejar, name, domain=..., path=...): ... + +class CookieConflictError(RuntimeError): ... + +class RequestsCookieJar(CookieJar, MutableMapping): + def get(self, name, default=..., domain=..., path=...): ... + def set(self, name, value, **kwargs): ... + def iterkeys(self): ... + def keys(self): ... + def itervalues(self): ... + def values(self): ... + def iteritems(self): ... + def items(self): ... + def list_domains(self): ... + def list_paths(self): ... + def multiple_domains(self): ... + def get_dict(self, domain=..., path=...): ... + def __getitem__(self, name): ... + def __setitem__(self, name, value): ... + def __delitem__(self, name): ... + def set_cookie(self, cookie, *args, **kwargs): ... + def update(self, other): ... + def copy(self): ... + +def create_cookie(name, value, **kwargs): ... +def morsel_to_cookie(morsel): ... +def cookiejar_from_dict(cookie_dict, cookiejar=..., overwrite=...): ... +def merge_cookies(cookiejar, cookies): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/exceptions.pyi new file mode 100644 index 000000000..ff0c32883 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/exceptions.pyi @@ -0,0 +1,26 @@ +# Stubs for requests.exceptions (Python 3) + +from typing import Any +from .packages.urllib3.exceptions import HTTPError as BaseHTTPError + +class RequestException(IOError): + response = ... # type: Any + request = ... # type: Any + def __init__(self, *args, **kwargs) -> None: ... + +class HTTPError(RequestException): ... +class ConnectionError(RequestException): ... +class ProxyError(ConnectionError): ... +class SSLError(ConnectionError): ... +class Timeout(RequestException): ... +class ConnectTimeout(ConnectionError, Timeout): ... +class ReadTimeout(Timeout): ... +class URLRequired(RequestException): ... +class TooManyRedirects(RequestException): ... +class MissingSchema(RequestException, ValueError): ... +class InvalidSchema(RequestException, ValueError): ... +class InvalidURL(RequestException, ValueError): ... +class ChunkedEncodingError(RequestException): ... +class ContentDecodingError(RequestException, BaseHTTPError): ... +class StreamConsumedError(RequestException, TypeError): ... +class RetryError(RequestException): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/hooks.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/hooks.pyi new file mode 100644 index 000000000..3367d9a48 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/hooks.pyi @@ -0,0 +1,8 @@ +# Stubs for requests.hooks (Python 3) + +from typing import Any + +HOOKS = ... # type: Any + +def default_hooks(): ... +def dispatch_hook(key, hooks, hook_data, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/models.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/models.pyi new file mode 100644 index 000000000..cdd8ab296 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/models.pyi @@ -0,0 +1,139 @@ +# Stubs for requests.models (Python 3) + +from typing import (Any, Dict, Iterator, List, MutableMapping, Optional, Text, + Union) +import datetime +import types + +from . import hooks +from . import structures +from . import auth +from . import cookies +from .cookies import RequestsCookieJar +from .packages.urllib3 import fields +from .packages.urllib3 import filepost +from .packages.urllib3 import util +from .packages.urllib3 import exceptions as urllib3_exceptions +from . import exceptions +from . import utils +from . import compat +from . import status_codes + + +default_hooks = hooks.default_hooks +CaseInsensitiveDict = structures.CaseInsensitiveDict +HTTPBasicAuth = auth.HTTPBasicAuth +cookiejar_from_dict = cookies.cookiejar_from_dict +get_cookie_header = cookies.get_cookie_header +RequestField = fields.RequestField +encode_multipart_formdata = filepost.encode_multipart_formdata +parse_url = util.parse_url +DecodeError = urllib3_exceptions.DecodeError +ReadTimeoutError = urllib3_exceptions.ReadTimeoutError +ProtocolError = urllib3_exceptions.ProtocolError +LocationParseError = urllib3_exceptions.LocationParseError +HTTPError = exceptions.HTTPError +MissingSchema = exceptions.MissingSchema +InvalidURL = exceptions.InvalidURL +ChunkedEncodingError = exceptions.ChunkedEncodingError +ContentDecodingError = exceptions.ContentDecodingError +ConnectionError = exceptions.ConnectionError +StreamConsumedError = exceptions.StreamConsumedError +guess_filename = utils.guess_filename +get_auth_from_url = utils.get_auth_from_url +requote_uri = utils.requote_uri +stream_decode_response_unicode = utils.stream_decode_response_unicode +to_key_val_list = utils.to_key_val_list +parse_header_links = utils.parse_header_links +iter_slices = utils.iter_slices +guess_json_utf = utils.guess_json_utf +super_len = utils.super_len +to_native_string = utils.to_native_string +codes = status_codes.codes + +REDIRECT_STATI = ... # type: Any +DEFAULT_REDIRECT_LIMIT = ... # type: Any +CONTENT_CHUNK_SIZE = ... # type: Any +ITER_CHUNK_SIZE = ... # type: Any +json_dumps = ... # type: Any + +class RequestEncodingMixin: + @property + def path_url(self): ... + +class RequestHooksMixin: + def register_hook(self, event, hook): ... + def deregister_hook(self, event, hook): ... + +class Request(RequestHooksMixin): + hooks = ... # type: Any + method = ... # type: Any + url = ... # type: Any + headers = ... # type: Any + files = ... # type: Any + data = ... # type: Any + json = ... # type: Any + params = ... # type: Any + auth = ... # type: Any + cookies = ... # type: Any + def __init__(self, method=..., url=..., headers=..., files=..., data=..., params=..., + auth=..., cookies=..., hooks=..., json=...) -> None: ... + def prepare(self): ... + +class PreparedRequest(RequestEncodingMixin, RequestHooksMixin): + method = ... # type: Optional[Union[str, Text]] + url = ... # type: Optional[Union[str, Text]] + headers = ... # type: CaseInsensitiveDict + body = ... # type: Optional[Union[bytes, Text]] + hooks = ... # type: Any + def __init__(self) -> None: ... + def prepare(self, method=..., url=..., headers=..., files=..., data=..., params=..., + auth=..., cookies=..., hooks=..., json=...): ... + def copy(self): ... + def prepare_method(self, method): ... + def prepare_url(self, url, params): ... + def prepare_headers(self, headers): ... + def prepare_body(self, data, files, json=...): ... + def prepare_content_length(self, body): ... + def prepare_auth(self, auth, url=...): ... + def prepare_cookies(self, cookies): ... + def prepare_hooks(self, hooks): ... + +class Response: + __attrs__ = ... # type: Any + status_code = ... # type: int + headers = ... # type: MutableMapping[str, str] + raw = ... # type: Any + url = ... # type: str + encoding = ... # type: str + history = ... # type: List[Response] + reason = ... # type: str + cookies = ... # type: RequestsCookieJar + elapsed = ... # type: datetime.timedelta + request = ... # type: PreparedRequest + def __init__(self) -> None: ... + def __bool__(self) -> bool: ... + def __nonzero__(self) -> bool: ... + def __iter__(self) -> Iterator[bytes]: ... + def __enter__(self) -> Response: ... + def __exit__(self, *args: Any) -> None: ... + @property + def ok(self) -> bool: ... + @property + def is_redirect(self) -> bool: ... + @property + def is_permanent_redirect(self) -> bool: ... + @property + def apparent_encoding(self) -> str: ... + def iter_content(self, chunk_size: Optional[int] = ..., + decode_unicode: bool = ...) -> Iterator[Any]: ... + def iter_lines(self, chunk_size=..., decode_unicode=..., delimiter=...): ... + @property + def content(self) -> bytes: ... + @property + def text(self) -> str: ... + def json(self, **kwargs) -> Any: ... + @property + def links(self) -> Dict[Any, Any]: ... + def raise_for_status(self) -> None: ... + def close(self) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/sessions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/sessions.pyi new file mode 100644 index 000000000..c01b5e15d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/sessions.pyi @@ -0,0 +1,114 @@ +# Stubs for requests.sessions (Python 3) + +from typing import Any, Union, List, MutableMapping, Text, Optional, IO, Tuple, Callable, Iterable +from . import adapters +from . import auth as _auth +from . import compat +from . import cookies +from . import models +from .models import Response +from . import hooks +from . import utils +from . import exceptions +from .packages.urllib3 import _collections +from . import structures +from . import adapters +from . import status_codes + +BaseAdapter = adapters.BaseAdapter +OrderedDict = compat.OrderedDict +cookiejar_from_dict = cookies.cookiejar_from_dict +extract_cookies_to_jar = cookies.extract_cookies_to_jar +RequestsCookieJar = cookies.RequestsCookieJar +merge_cookies = cookies.merge_cookies +Request = models.Request +PreparedRequest = models.PreparedRequest +DEFAULT_REDIRECT_LIMIT = models.DEFAULT_REDIRECT_LIMIT +default_hooks = hooks.default_hooks +dispatch_hook = hooks.dispatch_hook +to_key_val_list = utils.to_key_val_list +default_headers = utils.default_headers +to_native_string = utils.to_native_string +TooManyRedirects = exceptions.TooManyRedirects +InvalidSchema = exceptions.InvalidSchema +ChunkedEncodingError = exceptions.ChunkedEncodingError +ContentDecodingError = exceptions.ContentDecodingError +RecentlyUsedContainer = _collections.RecentlyUsedContainer +CaseInsensitiveDict = structures.CaseInsensitiveDict +HTTPAdapter = adapters.HTTPAdapter +requote_uri = utils.requote_uri +get_environ_proxies = utils.get_environ_proxies +get_netrc_auth = utils.get_netrc_auth +should_bypass_proxies = utils.should_bypass_proxies +get_auth_from_url = utils.get_auth_from_url +codes = status_codes.codes +REDIRECT_STATI = models.REDIRECT_STATI + +REDIRECT_CACHE_SIZE = ... # type: Any + +def merge_setting(request_setting, session_setting, dict_class=...): ... +def merge_hooks(request_hooks, session_hooks, dict_class=...): ... + +class SessionRedirectMixin: + def resolve_redirects(self, resp, req, stream=..., timeout=..., verify=..., cert=..., + proxies=...): ... + def rebuild_auth(self, prepared_request, response): ... + def rebuild_proxies(self, prepared_request, proxies): ... + +_Data = Union[None, bytes, MutableMapping[Text, Text], IO] + +_Hook = Callable[[Response], Any] +_Hooks = MutableMapping[Text, List[_Hook]] +_HooksInput = MutableMapping[Text, Union[Iterable[_Hook], _Hook]] + +class Session(SessionRedirectMixin): + __attrs__ = ... # type: Any + headers = ... # type: MutableMapping[Text, Text] + auth = ... # type: Union[None, Tuple[Text, Text], _auth.AuthBase, Callable[[Request], Request]] + proxies = ... # type: MutableMapping[Text, Text] + hooks = ... # type: _Hooks + params = ... # type: Union[bytes, MutableMapping[Text, Text]] + stream = ... # type: bool + verify = ... # type: Union[None, bool, Text] + cert = ... # type: Union[None, Text, Tuple[Text, Text]] + max_redirects = ... # type: int + trust_env = ... # type: bool + cookies = ... # type: Union[RequestsCookieJar, MutableMapping[Text, Text]] + adapters = ... # type: MutableMapping + redirect_cache = ... # type: RecentlyUsedContainer + def __init__(self) -> None: ... + def __enter__(self) -> 'Session': ... + def __exit__(self, *args) -> None: ... + def prepare_request(self, request): ... + def request(self, method: str, url: str, + params: Union[None, bytes, MutableMapping[Text, Text]] = ..., + data: _Data = ..., + headers: Optional[MutableMapping[Text, Text]] = ..., + cookies: Union[None, RequestsCookieJar, MutableMapping[Text, Text]] = ..., + files: Optional[MutableMapping[Text, IO]] = ..., + auth: Union[None, Tuple[Text, Text], _auth.AuthBase, Callable[[Request], Request]] = ..., + timeout: Union[None, float, Tuple[float, float]] = ..., + allow_redirects: Optional[bool] = ..., + proxies: Optional[MutableMapping[Text, Text]] = ..., + hooks: Optional[_HooksInput] = ..., + stream: Optional[bool] = ..., + verify: Union[None, bool, Text] = ..., + cert: Union[Text, Tuple[Text, Text], None] = ..., + json: Optional[MutableMapping] = ..., + ) -> Response: ... + def get(self, url: Union[Text, bytes], **kwargs) -> Response: ... + def options(self, url: Union[Text, bytes], **kwargs) -> Response: ... + def head(self, url: Union[Text, bytes], **kwargs) -> Response: ... + def post(self, url: Union[Text, bytes], data: _Data = ..., json: Optional[MutableMapping] = ..., **kwargs) -> Response: ... + def put(self, url: Union[Text, bytes], data: _Data = ..., **kwargs) -> Response: ... + def patch(self, url: Union[Text, bytes], data: _Data = ..., **kwargs) -> Response: ... + def delete(self, url: Union[Text, bytes], **kwargs) -> Response: ... + def send(self, request, **kwargs): ... + def merge_environment_settings(self, url, proxies, stream, verify, cert): ... + def get_adapter(self, url): ... + def close(self) -> None: ... + def mount(self, prefix: + Union[Text, bytes], + adapter: BaseAdapter) -> None: ... + +def session() -> Session: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/status_codes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/status_codes.pyi new file mode 100644 index 000000000..02d5c62e9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/status_codes.pyi @@ -0,0 +1,4 @@ +from typing import Any +from .structures import LookupDict + +codes = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/structures.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/structures.pyi new file mode 100644 index 000000000..92cf27aa1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/structures.pyi @@ -0,0 +1,19 @@ +from typing import Any, Dict, Iterable, Iterator, Mapping, MutableMapping, Optional, Tuple, TypeVar, Union, Generic + +_VT = TypeVar('_VT') + +class CaseInsensitiveDict(MutableMapping[str, _VT], Generic[_VT]): + def __init__(self, data: Optional[Union[Mapping[str, _VT], Iterable[Tuple[str, _VT]]]] = ..., **kwargs: _VT) -> None: ... + def lower_items(self) -> Iterator[Tuple[str, _VT]]: ... + def __setitem__(self, key: str, value: _VT) -> None: ... + def __getitem__(self, key: str) -> _VT: ... + def __delitem__(self, key: str) -> None: ... + def __iter__(self) -> Iterator[str]: ... + def __len__(self) -> int: ... + +class LookupDict(Dict[str, _VT]): + name: Any + def __init__(self, name: Any = ...) -> None: ... + def __getitem__(self, key: str) -> Optional[_VT]: ... # type: ignore + def __getattr__(self, attr: str) -> _VT: ... + def __setattr__(self, attr: str, value: _VT) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/utils.pyi new file mode 100644 index 000000000..9c03929f6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/requests/utils.pyi @@ -0,0 +1,53 @@ +# Stubs for requests.utils (Python 3) + +from typing import Any +from . import compat +from . import cookies +from . import structures +from . import exceptions + +OrderedDict = compat.OrderedDict +RequestsCookieJar = cookies.RequestsCookieJar +cookiejar_from_dict = cookies.cookiejar_from_dict +CaseInsensitiveDict = structures.CaseInsensitiveDict +InvalidURL = exceptions.InvalidURL + +NETRC_FILES = ... # type: Any +DEFAULT_CA_BUNDLE_PATH = ... # type: Any + +def dict_to_sequence(d): ... +def super_len(o): ... +def get_netrc_auth(url): ... +def guess_filename(obj): ... +def from_key_val_list(value): ... +def to_key_val_list(value): ... +def parse_list_header(value): ... +def parse_dict_header(value): ... +def unquote_header_value(value, is_filename=...): ... +def dict_from_cookiejar(cj): ... +def add_dict_to_cookiejar(cj, cookie_dict): ... +def get_encodings_from_content(content): ... +def get_encoding_from_headers(headers): ... +def stream_decode_response_unicode(iterator, r): ... +def iter_slices(string, slice_length): ... +def get_unicode_from_response(r): ... + +UNRESERVED_SET = ... # type: Any + +def unquote_unreserved(uri): ... +def requote_uri(uri): ... +def address_in_network(ip, net): ... +def dotted_netmask(mask): ... +def is_ipv4_address(string_ip): ... +def is_valid_cidr(string_network): ... +def set_environ(env_name, value): ... +def should_bypass_proxies(url): ... +def get_environ_proxies(url): ... +def default_user_agent(name=...): ... +def default_headers(): ... +def parse_header_links(value): ... +def guess_json_utf(data): ... +def prepend_scheme_if_needed(url, new_scheme): ... +def get_auth_from_url(url): ... +def to_native_string(string, encoding=...): ... +def urldefragauth(url): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/__init__.pyi new file mode 100644 index 000000000..452a4ffc7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/__init__.pyi @@ -0,0 +1,10 @@ +from typing import Any, IO, Text + +from simplejson.scanner import JSONDecodeError as JSONDecodeError +from simplejson.decoder import JSONDecoder as JSONDecoder +from simplejson.encoder import JSONEncoder as JSONEncoder, JSONEncoderForHTML as JSONEncoderForHTML + +def dumps(obj: Any, *args: Any, **kwds: Any) -> str: ... +def dump(obj: Any, fp: IO[str], *args: Any, **kwds: Any) -> None: ... +def loads(s: Text, **kwds: Any) -> Any: ... +def load(fp: IO[str], **kwds: Any) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/decoder.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/decoder.pyi new file mode 100644 index 000000000..59111ce66 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/decoder.pyi @@ -0,0 +1,6 @@ +from typing import Any, Match + +class JSONDecoder(object): + def __init__(self, **kwargs): ... + def decode(self, s: str, _w: Match[str], _PY3: bool): ... + def raw_decode(self, s: str, idx: int, _w: Match[str], _PY3: bool): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/encoder.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/encoder.pyi new file mode 100644 index 000000000..0e3180661 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/encoder.pyi @@ -0,0 +1,9 @@ +from typing import Any, IO + +class JSONEncoder(object): + def __init__(self, *args, **kwargs): ... + def encode(self, o: Any): ... + def default(self, o: Any): ... + def iterencode(self, o: Any, _one_shot: bool): ... + +class JSONEncoderForHTML(JSONEncoder): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/scanner.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/scanner.pyi new file mode 100644 index 000000000..5de484a07 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/simplejson/scanner.pyi @@ -0,0 +1,11 @@ +from typing import Optional + +class JSONDecodeError(ValueError): + msg: str = ... + doc: str = ... + pos: int = ... + end: Optional[int] = ... + lineno: int = ... + colno: int = ... + endlineno: Optional[int] = ... + endcolno: Optional[int] = ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/singledispatch.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/singledispatch.pyi new file mode 100644 index 000000000..ed24b7f1f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/singledispatch.pyi @@ -0,0 +1,17 @@ +from typing import Any, Callable, Generic, Mapping, Optional, TypeVar, overload + + +_T = TypeVar("_T") + + +class _SingleDispatchCallable(Generic[_T]): + registry = ... # type: Mapping[Any, Callable[..., _T]] + def dispatch(self, cls: Any) -> Callable[..., _T]: ... + @overload + def register(self, cls: Any) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... + @overload + def register(self, cls: Any, func: Callable[..., _T]) -> Callable[..., _T]: ... + def _clear_cache(self) -> None: ... + def __call__(self, *args: Any, **kwargs: Any) -> _T: ... + +def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/termcolor.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/termcolor.pyi new file mode 100644 index 000000000..e1ad18b8a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/termcolor.pyi @@ -0,0 +1,21 @@ +# Stub for termcolor: https://pypi.python.org/pypi/termcolor +from typing import Any, Iterable, Optional, Text + + +def colored( + text: Text, + color: Optional[Text] = ..., + on_color: Optional[Text] = ..., + attrs: Optional[Iterable[Text]] = ..., +) -> Text: + ... + + +def cprint( + text: Text, + color: Optional[Text] = ..., + on_color: Optional[Text] = ..., + attrs: Optional[Iterable[Text]] = ..., + **kwargs: Any, +) -> None: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/typing_extensions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/typing_extensions.pyi new file mode 100644 index 000000000..23cb4af45 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/typing_extensions.pyi @@ -0,0 +1,33 @@ +import sys +import typing +from typing import ClassVar as ClassVar +from typing import ContextManager as ContextManager +from typing import Counter as Counter +from typing import DefaultDict as DefaultDict +from typing import Deque as Deque +from typing import NewType as NewType +from typing import NoReturn as NoReturn +from typing import overload as overload +from typing import Text as Text +from typing import Type as Type +from typing import TYPE_CHECKING as TYPE_CHECKING +from typing import TypeVar, Any + +_TC = TypeVar('_TC', bound=Type[object]) +class _SpecialForm: + def __getitem__(self, typeargs: Any) -> Any: ... +def runtime(cls: _TC) -> _TC: ... +Protocol: _SpecialForm = ... + +if sys.version_info >= (3, 3): + from typing import ChainMap as ChainMap + +if sys.version_info >= (3, 5): + from typing import AsyncIterable as AsyncIterable + from typing import AsyncIterator as AsyncIterator + from typing import AsyncContextManager as AsyncContextManager + from typing import Awaitable as Awaitable + from typing import Coroutine as Coroutine + +if sys.version_info >= (3, 6): + from typing import AsyncGenerator as AsyncGenerator diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/ujson.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/ujson.pyi new file mode 100644 index 000000000..4c8540d19 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/ujson.pyi @@ -0,0 +1,51 @@ +# Stubs for ujson +# See: https://pypi.python.org/pypi/ujson +from typing import Any, AnyStr, IO, Optional + +__version__ = ... # type: str + +def encode( + obj: Any, + ensure_ascii: bool = ..., + double_precision: int = ..., + encode_html_chars: bool = ..., + escape_forward_slashes: bool = ..., + sort_keys: bool = ..., + indent: int = ..., +) -> str: ... + +def dumps( + obj: Any, + ensure_ascii: bool = ..., + double_precision: int = ..., + encode_html_chars: bool = ..., + escape_forward_slashes: bool = ..., + sort_keys: bool = ..., + indent: int = ..., +) -> str: ... + +def dump( + obj: Any, + fp: IO[str], + ensure_ascii: bool = ..., + double_precision: int = ..., + encode_html_chars: bool = ..., + escape_forward_slashes: bool = ..., + sort_keys: bool = ..., + indent: int = ..., +) -> None: ... + +def decode( + s: AnyStr, + precise_float: bool = ..., +) -> Any: ... + +def loads( + s: AnyStr, + precise_float: bool = ..., +) -> Any: ... + +def load( + fp: IO[AnyStr], + precise_float: bool = ..., +) -> Any: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/__init__.pyi new file mode 100644 index 000000000..fc27b0902 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/__init__.pyi @@ -0,0 +1,150 @@ +from types import ModuleType +from typing import Any + +from werkzeug import _internal +from werkzeug import datastructures +from werkzeug import debug +from werkzeug import exceptions +from werkzeug import formparser +from werkzeug import http +from werkzeug import local +from werkzeug import security +from werkzeug import serving +from werkzeug import test +from werkzeug import testapp +from werkzeug import urls +from werkzeug import useragents +from werkzeug import utils +from werkzeug import wrappers +from werkzeug import wsgi + +class module(ModuleType): + def __getattr__(self, name): ... + def __dir__(self): ... + + +__version__ = ... # type: Any + +run_simple = serving.run_simple +test_app = testapp.test_app +UserAgent = useragents.UserAgent +_easteregg = _internal._easteregg +DebuggedApplication = debug.DebuggedApplication +MultiDict = datastructures.MultiDict +CombinedMultiDict = datastructures.CombinedMultiDict +Headers = datastructures.Headers +EnvironHeaders = datastructures.EnvironHeaders +ImmutableList = datastructures.ImmutableList +ImmutableDict = datastructures.ImmutableDict +ImmutableMultiDict = datastructures.ImmutableMultiDict +TypeConversionDict = datastructures.TypeConversionDict +ImmutableTypeConversionDict = datastructures.ImmutableTypeConversionDict +Accept = datastructures.Accept +MIMEAccept = datastructures.MIMEAccept +CharsetAccept = datastructures.CharsetAccept +LanguageAccept = datastructures.LanguageAccept +RequestCacheControl = datastructures.RequestCacheControl +ResponseCacheControl = datastructures.ResponseCacheControl +ETags = datastructures.ETags +HeaderSet = datastructures.HeaderSet +WWWAuthenticate = datastructures.WWWAuthenticate +Authorization = datastructures.Authorization +FileMultiDict = datastructures.FileMultiDict +CallbackDict = datastructures.CallbackDict +FileStorage = datastructures.FileStorage +OrderedMultiDict = datastructures.OrderedMultiDict +ImmutableOrderedMultiDict = datastructures.ImmutableOrderedMultiDict +escape = utils.escape +environ_property = utils.environ_property +append_slash_redirect = utils.append_slash_redirect +redirect = utils.redirect +cached_property = utils.cached_property +import_string = utils.import_string +dump_cookie = http.dump_cookie +parse_cookie = http.parse_cookie +unescape = utils.unescape +format_string = utils.format_string +find_modules = utils.find_modules +header_property = utils.header_property +html = utils.html +xhtml = utils.xhtml +HTMLBuilder = utils.HTMLBuilder +validate_arguments = utils.validate_arguments +ArgumentValidationError = utils.ArgumentValidationError +bind_arguments = utils.bind_arguments +secure_filename = utils.secure_filename +BaseResponse = wrappers.BaseResponse +BaseRequest = wrappers.BaseRequest +Request = wrappers.Request +Response = wrappers.Response +AcceptMixin = wrappers.AcceptMixin +ETagRequestMixin = wrappers.ETagRequestMixin +ETagResponseMixin = wrappers.ETagResponseMixin +ResponseStreamMixin = wrappers.ResponseStreamMixin +CommonResponseDescriptorsMixin = wrappers.CommonResponseDescriptorsMixin +UserAgentMixin = wrappers.UserAgentMixin +AuthorizationMixin = wrappers.AuthorizationMixin +WWWAuthenticateMixin = wrappers.WWWAuthenticateMixin +CommonRequestDescriptorsMixin = wrappers.CommonRequestDescriptorsMixin +Local = local.Local +LocalManager = local.LocalManager +LocalProxy = local.LocalProxy +LocalStack = local.LocalStack +release_local = local.release_local +generate_password_hash = security.generate_password_hash +check_password_hash = security.check_password_hash +Client = test.Client +EnvironBuilder = test.EnvironBuilder +create_environ = test.create_environ +run_wsgi_app = test.run_wsgi_app +get_current_url = wsgi.get_current_url +get_host = wsgi.get_host +pop_path_info = wsgi.pop_path_info +peek_path_info = wsgi.peek_path_info +SharedDataMiddleware = wsgi.SharedDataMiddleware +DispatcherMiddleware = wsgi.DispatcherMiddleware +ClosingIterator = wsgi.ClosingIterator +FileWrapper = wsgi.FileWrapper +make_line_iter = wsgi.make_line_iter +LimitedStream = wsgi.LimitedStream +responder = wsgi.responder +wrap_file = wsgi.wrap_file +extract_path_info = wsgi.extract_path_info +parse_etags = http.parse_etags +parse_date = http.parse_date +http_date = http.http_date +cookie_date = http.cookie_date +parse_cache_control_header = http.parse_cache_control_header +is_resource_modified = http.is_resource_modified +parse_accept_header = http.parse_accept_header +parse_set_header = http.parse_set_header +quote_etag = http.quote_etag +unquote_etag = http.unquote_etag +generate_etag = http.generate_etag +dump_header = http.dump_header +parse_list_header = http.parse_list_header +parse_dict_header = http.parse_dict_header +parse_authorization_header = http.parse_authorization_header +parse_www_authenticate_header = http.parse_www_authenticate_header +remove_entity_headers = http.remove_entity_headers +is_entity_header = http.is_entity_header +remove_hop_by_hop_headers = http.remove_hop_by_hop_headers +parse_options_header = http.parse_options_header +dump_options_header = http.dump_options_header +is_hop_by_hop_header = http.is_hop_by_hop_header +unquote_header_value = http.unquote_header_value +quote_header_value = http.quote_header_value +HTTP_STATUS_CODES = http.HTTP_STATUS_CODES +url_decode = urls.url_decode +url_encode = urls.url_encode +url_quote = urls.url_quote +url_quote_plus = urls.url_quote_plus +url_unquote = urls.url_unquote +url_unquote_plus = urls.url_unquote_plus +url_fix = urls.url_fix +Href = urls.Href +iri_to_uri = urls.iri_to_uri +uri_to_iri = urls.uri_to_iri +parse_form_data = formparser.parse_form_data +abort = exceptions.Aborter +Aborter = exceptions.Aborter diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_compat.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_compat.pyi new file mode 100644 index 000000000..74981331c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_compat.pyi @@ -0,0 +1,48 @@ +import sys +from typing import Any + +if sys.version_info < (3,): + import StringIO as BytesIO +else: + from io import StringIO as BytesIO + +PY2 = ... # type: Any +WIN = ... # type: Any +unichr = ... # type: Any +text_type = ... # type: Any +string_types = ... # type: Any +integer_types = ... # type: Any +iterkeys = ... # type: Any +itervalues = ... # type: Any +iteritems = ... # type: Any +iterlists = ... # type: Any +iterlistvalues = ... # type: Any +int_to_byte = ... # type: Any +iter_bytes = ... # type: Any + +def fix_tuple_repr(obj): ... +def implements_iterator(cls): ... +def implements_to_string(cls): ... +def native_string_result(func): ... +def implements_bool(cls): ... + +range_type = ... # type: Any +NativeStringIO = ... # type: Any + +def make_literal_wrapper(reference): ... +def normalize_string_tuple(tup): ... +def try_coerce_native(s): ... + +wsgi_get_bytes = ... # type: Any + +def wsgi_decoding_dance(s, charset='', errors=''): ... +def wsgi_encoding_dance(s, charset='', errors=''): ... +def to_bytes(x, charset=..., errors=''): ... +def to_native(x, charset=..., errors=''): ... +def reraise(tp, value, tb=None): ... + +imap = ... # type: Any +izip = ... # type: Any +ifilter = ... # type: Any + +def to_unicode(x, charset=..., errors='', allow_none_charset=False): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_internal.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_internal.pyi new file mode 100644 index 000000000..6fddbdd77 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_internal.pyi @@ -0,0 +1,18 @@ +from typing import Any + +class _Missing: + def __reduce__(self): ... + +class _DictAccessorProperty: + read_only = ... # type: Any + name = ... # type: Any + default = ... # type: Any + load_func = ... # type: Any + dump_func = ... # type: Any + __doc__ = ... # type: Any + def __init__(self, name, default=None, load_func=None, dump_func=None, read_only=None, doc=None): ... + def __get__(self, obj, type=None): ... + def __set__(self, obj, value): ... + def __delete__(self, obj): ... + +def _easteregg(app=None): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_reloader.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_reloader.pyi new file mode 100644 index 000000000..55a560d2f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/_reloader.pyi @@ -0,0 +1,29 @@ +from typing import Any + +class ReloaderLoop: + name = ... # type: Any + extra_files = ... # type: Any + interval = ... # type: Any + def __init__(self, extra_files=None, interval=1): ... + def run(self): ... + def restart_with_reloader(self): ... + def trigger_reload(self, filename): ... + def log_reload(self, filename): ... + +class StatReloaderLoop(ReloaderLoop): + name = ... # type: Any + def run(self): ... + +class WatchdogReloaderLoop(ReloaderLoop): + observable_paths = ... # type: Any + name = ... # type: Any + observer_class = ... # type: Any + event_handler = ... # type: Any + should_reload = ... # type: Any + def __init__(self, *args, **kwargs): ... + def trigger_reload(self, filename): ... + def run(self): ... + +reloader_loops = ... # type: Any + +def run_with_reloader(main_func, extra_files=None, interval=1, reloader_type=''): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/atom.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/atom.pyi new file mode 100644 index 000000000..1e2787363 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/atom.pyi @@ -0,0 +1,50 @@ +from typing import Any + +XHTML_NAMESPACE = ... # type: Any + +def format_iso8601(obj): ... + +class AtomFeed: + default_generator = ... # type: Any + title = ... # type: Any + title_type = ... # type: Any + url = ... # type: Any + feed_url = ... # type: Any + id = ... # type: Any + updated = ... # type: Any + author = ... # type: Any + icon = ... # type: Any + logo = ... # type: Any + rights = ... # type: Any + rights_type = ... # type: Any + subtitle = ... # type: Any + subtitle_type = ... # type: Any + generator = ... # type: Any + links = ... # type: Any + entries = ... # type: Any + def __init__(self, title=None, entries=None, **kwargs): ... + def add(self, *args, **kwargs): ... + def generate(self): ... + def to_string(self): ... + def get_response(self): ... + def __call__(self, environ, start_response): ... + +class FeedEntry: + title = ... # type: Any + title_type = ... # type: Any + content = ... # type: Any + content_type = ... # type: Any + url = ... # type: Any + id = ... # type: Any + updated = ... # type: Any + summary = ... # type: Any + summary_type = ... # type: Any + author = ... # type: Any + published = ... # type: Any + rights = ... # type: Any + links = ... # type: Any + categories = ... # type: Any + xml_base = ... # type: Any + def __init__(self, title=None, content=None, feed_url=None, **kwargs): ... + def generate(self): ... + def to_string(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/cache.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/cache.pyi new file mode 100644 index 000000000..2b8abb767 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/cache.pyi @@ -0,0 +1,83 @@ +from typing import Any + +class BaseCache: + default_timeout = ... # type: Any + def __init__(self, default_timeout=300): ... + def get(self, key): ... + def delete(self, key): ... + def get_many(self, *keys): ... + def get_dict(self, *keys): ... + def set(self, key, value, timeout=None): ... + def add(self, key, value, timeout=None): ... + def set_many(self, mapping, timeout=None): ... + def delete_many(self, *keys): ... + def has(self, key): ... + def clear(self): ... + def inc(self, key, delta=1): ... + def dec(self, key, delta=1): ... + +class NullCache(BaseCache): ... + +class SimpleCache(BaseCache): + clear = ... # type: Any + def __init__(self, threshold=500, default_timeout=300): ... + def get(self, key): ... + def set(self, key, value, timeout=None): ... + def add(self, key, value, timeout=None): ... + def delete(self, key): ... + def has(self, key): ... + +class MemcachedCache(BaseCache): + key_prefix = ... # type: Any + def __init__(self, servers=None, default_timeout=300, key_prefix=None): ... + def get(self, key): ... + def get_dict(self, *keys): ... + def add(self, key, value, timeout=None): ... + def set(self, key, value, timeout=None): ... + def get_many(self, *keys): ... + def set_many(self, mapping, timeout=None): ... + def delete(self, key): ... + def delete_many(self, *keys): ... + def has(self, key): ... + def clear(self): ... + def inc(self, key, delta=1): ... + def dec(self, key, delta=1): ... + def import_preferred_memcache_lib(self, servers): ... + +GAEMemcachedCache = ... # type: Any + +class RedisCache(BaseCache): + key_prefix = ... # type: Any + def __init__(self, host='', port=6379, password=None, db=0, default_timeout=300, key_prefix=None, **kwargs): ... + def dump_object(self, value): ... + def load_object(self, value): ... + def get(self, key): ... + def get_many(self, *keys): ... + def set(self, key, value, timeout=None): ... + def add(self, key, value, timeout=None): ... + def set_many(self, mapping, timeout=None): ... + def delete(self, key): ... + def delete_many(self, *keys): ... + def has(self, key): ... + def clear(self): ... + def inc(self, key, delta=1): ... + def dec(self, key, delta=1): ... + +class FileSystemCache(BaseCache): + def __init__(self, cache_dir, threshold=500, default_timeout=300, mode=384): ... + def clear(self): ... + def get(self, key): ... + def add(self, key, value, timeout=None): ... + def set(self, key, value, timeout=None): ... + def delete(self, key): ... + def has(self, key): ... + +class UWSGICache(BaseCache): + cache = ... # type: Any + def __init__(self, default_timeout=300, cache=''): ... + def get(self, key): ... + def delete(self, key): ... + def set(self, key, value, timeout=None): ... + def add(self, key, value, timeout=None): ... + def clear(self): ... + def has(self, key): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/fixers.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/fixers.pyi new file mode 100644 index 000000000..a45c661c9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/fixers.pyi @@ -0,0 +1,37 @@ +from typing import Any + +class CGIRootFix: + app = ... # type: Any + app_root = ... # type: Any + def __init__(self, app, app_root=''): ... + def __call__(self, environ, start_response): ... + +LighttpdCGIRootFix = ... # type: Any + +class PathInfoFromRequestUriFix: + app = ... # type: Any + def __init__(self, app): ... + def __call__(self, environ, start_response): ... + +class ProxyFix: + app = ... # type: Any + num_proxies = ... # type: Any + def __init__(self, app, num_proxies=1): ... + def get_remote_addr(self, forwarded_for): ... + def __call__(self, environ, start_response): ... + +class HeaderRewriterFix: + app = ... # type: Any + remove_headers = ... # type: Any + add_headers = ... # type: Any + def __init__(self, app, remove_headers=None, add_headers=None): ... + def __call__(self, environ, start_response): ... + +class InternetExplorerFix: + app = ... # type: Any + fix_vary = ... # type: Any + fix_attach = ... # type: Any + def __init__(self, app, fix_vary=True, fix_attach=True): ... + def fix_headers(self, environ, headers, status=None): ... + def run_fixed(self, environ, start_response): ... + def __call__(self, environ, start_response): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/iterio.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/iterio.pyi new file mode 100644 index 000000000..33da95600 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/iterio.pyi @@ -0,0 +1,38 @@ +from typing import Any + +greenlet = ... # type: Any + +class IterIO: + def __new__(cls, obj, sentinel=''): ... + def __iter__(self): ... + def tell(self): ... + def isatty(self): ... + def seek(self, pos, mode=0): ... + def truncate(self, size=None): ... + def write(self, s): ... + def writelines(self, list): ... + def read(self, n=-1): ... + def readlines(self, sizehint=0): ... + def readline(self, length=None): ... + def flush(self): ... + def __next__(self): ... + +class IterI(IterIO): + def __new__(cls, func, sentinel=''): ... + closed = ... # type: Any + def close(self): ... + def write(self, s): ... + def writelines(self, list): ... + def flush(self): ... + +class IterO(IterIO): + sentinel = ... # type: Any + closed = ... # type: Any + pos = ... # type: Any + def __new__(cls, gen, sentinel=''): ... + def __iter__(self): ... + def close(self): ... + def seek(self, pos, mode=0): ... + def read(self, n=-1): ... + def readline(self, length=None): ... + def readlines(self, sizehint=0): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/jsrouting.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/jsrouting.pyi new file mode 100644 index 000000000..a9cc8c2a1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/jsrouting.pyi @@ -0,0 +1,10 @@ +from typing import Any + +def dumps(*args): ... +def render_template(name_parts, rules, converters): ... +def generate_map(map, name=''): ... +def generate_adapter(adapter, name='', map_name=''): ... +def js_to_url_function(converter): ... +def NumberConverter_js_to_url(conv): ... + +js_to_url_functions = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/limiter.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/limiter.pyi new file mode 100644 index 000000000..52501c6ee --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/limiter.pyi @@ -0,0 +1,7 @@ +from typing import Any + +class StreamLimitMiddleware: + app = ... # type: Any + maximum_size = ... # type: Any + def __init__(self, app, maximum_size=...): ... + def __call__(self, environ, start_response): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/lint.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/lint.pyi new file mode 100644 index 000000000..f89c12092 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/lint.pyi @@ -0,0 +1,43 @@ +from typing import Any + +class WSGIWarning(Warning): ... +class HTTPWarning(Warning): ... + +def check_string(context, obj, stacklevel=3): ... + +class InputStream: + def __init__(self, stream): ... + def read(self, *args): ... + def readline(self, *args): ... + def __iter__(self): ... + def close(self): ... + +class ErrorStream: + def __init__(self, stream): ... + def write(self, s): ... + def flush(self): ... + def writelines(self, seq): ... + def close(self): ... + +class GuardedWrite: + def __init__(self, write, chunks): ... + def __call__(self, s): ... + +class GuardedIterator: + closed = ... # type: Any + headers_set = ... # type: Any + chunks = ... # type: Any + def __init__(self, iterator, headers_set, chunks): ... + def __iter__(self): ... + def next(self): ... + def close(self): ... + def __del__(self): ... + +class LintMiddleware: + app = ... # type: Any + def __init__(self, app): ... + def check_environ(self, environ): ... + def check_start_response(self, status, headers, exc_info): ... + def check_headers(self, headers): ... + def check_iterator(self, app_iter): ... + def __call__(self, *args, **kwargs): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/profiler.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/profiler.pyi new file mode 100644 index 000000000..db1eacbf6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/profiler.pyi @@ -0,0 +1,14 @@ +from typing import Any + +available = ... # type: Any + +class MergeStream: + streams = ... # type: Any + def __init__(self, *streams): ... + def write(self, data): ... + +class ProfilerMiddleware: + def __init__(self, app, stream=None, sort_by=..., restrictions=..., profile_dir=None): ... + def __call__(self, environ, start_response): ... + +def make_action(app_factory, hostname='', port=5000, threaded=False, processes=1, stream=None, sort_by=..., restrictions=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/securecookie.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/securecookie.pyi new file mode 100644 index 000000000..219356f64 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/securecookie.pyi @@ -0,0 +1,26 @@ +from typing import Any +from hmac import new as hmac +from hashlib import sha1 as _default_hash +from werkzeug.contrib.sessions import ModificationTrackingDict + +class UnquoteError(Exception): ... + +class SecureCookie(ModificationTrackingDict): + hash_method = ... # type: Any + serialization_method = ... # type: Any + quote_base64 = ... # type: Any + secret_key = ... # type: Any + new = ... # type: Any + def __init__(self, data=None, secret_key=None, new=True): ... + @property + def should_save(self): ... + @classmethod + def quote(cls, value): ... + @classmethod + def unquote(cls, value): ... + def serialize(self, expires=None): ... + @classmethod + def unserialize(cls, string, secret_key): ... + @classmethod + def load_cookie(cls, request, key='', secret_key=None): ... + def save_cookie(self, response, key='', expires=None, session_expires=None, max_age=None, path='', domain=None, secure=None, httponly=False, force=False): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/sessions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/sessions.pyi new file mode 100644 index 000000000..aa3f8fc27 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/sessions.pyi @@ -0,0 +1,54 @@ +from typing import Any +from werkzeug.datastructures import CallbackDict + +def generate_key(salt=None): ... + +class ModificationTrackingDict(CallbackDict): + modified = ... # type: Any + def __init__(self, *args, **kwargs): ... + def copy(self): ... + def __copy__(self): ... + +class Session(ModificationTrackingDict): + sid = ... # type: Any + new = ... # type: Any + def __init__(self, data, sid, new=False): ... + @property + def should_save(self): ... + +class SessionStore: + session_class = ... # type: Any + def __init__(self, session_class=None): ... + def is_valid_key(self, key): ... + def generate_key(self, salt=None): ... + def new(self): ... + def save(self, session): ... + def save_if_modified(self, session): ... + def delete(self, session): ... + def get(self, sid): ... + +class FilesystemSessionStore(SessionStore): + path = ... # type: Any + filename_template = ... # type: Any + renew_missing = ... # type: Any + mode = ... # type: Any + def __init__(self, path=None, filename_template='', session_class=None, renew_missing=False, mode=420): ... + def get_session_filename(self, sid): ... + def save(self, session): ... + def delete(self, session): ... + def get(self, sid): ... + def list(self): ... + +class SessionMiddleware: + app = ... # type: Any + store = ... # type: Any + cookie_name = ... # type: Any + cookie_age = ... # type: Any + cookie_expires = ... # type: Any + cookie_path = ... # type: Any + cookie_domain = ... # type: Any + cookie_secure = ... # type: Any + cookie_httponly = ... # type: Any + environ_key = ... # type: Any + def __init__(self, app, store, cookie_name='', cookie_age=None, cookie_expires=None, cookie_path='', cookie_domain=None, cookie_secure=None, cookie_httponly=False, environ_key=''): ... + def __call__(self, environ, start_response): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/testtools.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/testtools.pyi new file mode 100644 index 000000000..860ebb7af --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/testtools.pyi @@ -0,0 +1,9 @@ +from typing import Any +from werkzeug.wrappers import Response + +class ContentAccessors: + def xml(self): ... + def lxml(self): ... + def json(self): ... + +class TestResponse(Response, ContentAccessors): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/wrappers.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/wrappers.pyi new file mode 100644 index 000000000..4ebc7e80d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/contrib/wrappers.pyi @@ -0,0 +1,27 @@ +from typing import Any + +def is_known_charset(charset): ... + +class JSONRequestMixin: + def json(self): ... + +class ProtobufRequestMixin: + protobuf_check_initialization = ... # type: Any + def parse_protobuf(self, proto_type): ... + +class RoutingArgsRequestMixin: + routing_args = ... # type: Any + routing_vars = ... # type: Any + +class ReverseSlashBehaviorRequestMixin: + def path(self): ... + def script_root(self): ... + +class DynamicCharsetRequestMixin: + default_charset = ... # type: Any + def unknown_charset(self, charset): ... + def charset(self): ... + +class DynamicCharsetResponseMixin: + default_charset = ... # type: Any + charset = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/datastructures.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/datastructures.pyi new file mode 100644 index 000000000..bc0b3610c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/datastructures.pyi @@ -0,0 +1,385 @@ +from typing import Any +from collections import Container, Iterable, Mapping, MutableSet + +def is_immutable(self): ... +def iter_multi_items(mapping): ... +def native_itermethods(names): ... + +class ImmutableListMixin: + def __hash__(self): ... + def __reduce_ex__(self, protocol): ... + def __delitem__(self, key): ... + def __delslice__(self, i, j): ... + def __iadd__(self, other): ... + __imul__ = ... # type: Any + def __setitem__(self, key, value): ... + def __setslice__(self, i, j, value): ... + def append(self, item): ... + remove = ... # type: Any + def extend(self, iterable): ... + def insert(self, pos, value): ... + def pop(self, index=-1): ... + def reverse(self): ... + def sort(self, cmp=None, key=None, reverse=None): ... + +class ImmutableList(ImmutableListMixin, list): ... + +class ImmutableDictMixin: + @classmethod + def fromkeys(cls, *args, **kwargs): ... + def __reduce_ex__(self, protocol): ... + def __hash__(self): ... + def setdefault(self, key, default=None): ... + def update(self, *args, **kwargs): ... + def pop(self, key, default=None): ... + def popitem(self): ... + def __setitem__(self, key, value): ... + def __delitem__(self, key): ... + def clear(self): ... + +class ImmutableMultiDictMixin(ImmutableDictMixin): + def __reduce_ex__(self, protocol): ... + def add(self, key, value): ... + def popitemlist(self): ... + def poplist(self, key): ... + def setlist(self, key, new_list): ... + def setlistdefault(self, key, default_list=None): ... + +class UpdateDictMixin: + on_update = ... # type: Any + def calls_update(name): ... + def setdefault(self, key, default=None): ... + def pop(self, key, default=...): ... + __setitem__ = ... # type: Any + __delitem__ = ... # type: Any + clear = ... # type: Any + popitem = ... # type: Any + update = ... # type: Any + +class TypeConversionDict(dict): + def get(self, key, default=None, type=None): ... + +class ImmutableTypeConversionDict(ImmutableDictMixin, TypeConversionDict): + def copy(self): ... + def __copy__(self): ... + +class ViewItems: + def __init__(self, multi_dict, method, repr_name, *a, **kw): ... + def __iter__(self): ... + +class MultiDict(TypeConversionDict): + def __init__(self, mapping=None): ... + def __getitem__(self, key): ... + def __setitem__(self, key, value): ... + def add(self, key, value): ... + def getlist(self, key, type=None): ... + def setlist(self, key, new_list): ... + def setdefault(self, key, default=None): ... + def setlistdefault(self, key, default_list=None): ... + def items(self, multi=False): ... + def lists(self): ... + def keys(self): ... + __iter__ = ... # type: Any + def values(self): ... + def listvalues(self): ... + def copy(self): ... + def deepcopy(self, memo=None): ... + def to_dict(self, flat=True): ... + def update(self, other_dict): ... + def pop(self, key, default=...): ... + def popitem(self): ... + def poplist(self, key): ... + def popitemlist(self): ... + def __copy__(self): ... + def __deepcopy__(self, memo): ... + +class _omd_bucket: + prev = ... # type: Any + key = ... # type: Any + value = ... # type: Any + next = ... # type: Any + def __init__(self, omd, key, value): ... + def unlink(self, omd): ... + +class OrderedMultiDict(MultiDict): + def __init__(self, mapping=None): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def __reduce_ex__(self, protocol): ... + def __getitem__(self, key): ... + def __setitem__(self, key, value): ... + def __delitem__(self, key): ... + def keys(self): ... + __iter__ = ... # type: Any + def values(self): ... + def items(self, multi=False): ... + def lists(self): ... + def listvalues(self): ... + def add(self, key, value): ... + def getlist(self, key, type=None): ... + def setlist(self, key, new_list): ... + def setlistdefault(self, key, default_list=None): ... + def update(self, mapping): ... + def poplist(self, key): ... + def pop(self, key, default=...): ... + def popitem(self): ... + def popitemlist(self): ... + +class Headers(Mapping): + def __init__(self, defaults=None): ... + def __getitem__(self, key, _get_mode=False): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + def get(self, key, default=None, type=None, as_bytes=False): ... + def getlist(self, key, type=None, as_bytes=False): ... + def get_all(self, name): ... + def items(self, lower=False): ... + def keys(self, lower=False): ... + def values(self): ... + def extend(self, iterable): ... + def __delitem__(self, key: Any) -> None: ... + def remove(self, key): ... + def pop(self, **kwargs): ... + def popitem(self): ... + def __contains__(self, key): ... + has_key = ... # type: Any + def __iter__(self): ... + def __len__(self): ... + def add(self, _key, _value, **kw): ... + def add_header(self, _key, _value, **_kw): ... + def clear(self): ... + def set(self, _key, _value, **kw): ... + def setdefault(self, key, value): ... + def __setitem__(self, key, value): ... + def to_list(self, charset=''): ... + def to_wsgi_list(self): ... + def copy(self): ... + def __copy__(self): ... + +class ImmutableHeadersMixin: + def __delitem__(self, key: str) -> None: ... + def __setitem__(self, key, value): ... + set = ... # type: Any + def add(self, *args, **kwargs): ... + remove = ... # type: Any + add_header = ... # type: Any + def extend(self, iterable): ... + def insert(self, pos, value): ... + def pop(self, **kwargs): ... + def popitem(self): ... + def setdefault(self, key, default): ... + +class EnvironHeaders(ImmutableHeadersMixin, Headers): + environ = ... # type: Any + def __init__(self, environ): ... + def __eq__(self, other): ... + def __getitem__(self, key, _get_mode=False): ... + def __len__(self): ... + def __iter__(self): ... + def copy(self): ... + +class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict): + def __reduce_ex__(self, protocol): ... + dicts = ... # type: Any + def __init__(self, dicts=None): ... + @classmethod + def fromkeys(cls): ... + def __getitem__(self, key): ... + def get(self, key, default=None, type=None): ... + def getlist(self, key, type=None): ... + def keys(self): ... + __iter__ = ... # type: Any + def items(self, multi=False): ... + def values(self): ... + def lists(self): ... + def listvalues(self): ... + def copy(self): ... + def to_dict(self, flat=True): ... + def __len__(self): ... + def __contains__(self, key): ... + has_key = ... # type: Any + +class FileMultiDict(MultiDict): + def add_file(self, name, file, filename=None, content_type=None): ... + +class ImmutableDict(ImmutableDictMixin, dict): + def copy(self): ... + def __copy__(self): ... + +class ImmutableMultiDict(ImmutableMultiDictMixin, MultiDict): + def copy(self): ... + def __copy__(self): ... + +class ImmutableOrderedMultiDict(ImmutableMultiDictMixin, OrderedMultiDict): + def copy(self): ... + def __copy__(self): ... + +class Accept(ImmutableList): + provided = ... # type: Any + def __init__(self, values=...): ... + def __getitem__(self, key): ... + def quality(self, key): ... + def __contains__(self, value): ... + def index(self, key): ... + def find(self, key): ... + def values(self): ... + def to_header(self): ... + def best_match(self, matches, default=None): ... + @property + def best(self): ... + +class MIMEAccept(Accept): + @property + def accept_html(self): ... + @property + def accept_xhtml(self): ... + @property + def accept_json(self): ... + +class LanguageAccept(Accept): ... +class CharsetAccept(Accept): ... + +def cache_property(key, empty, type): ... + +class _CacheControl(UpdateDictMixin, dict): + no_cache = ... # type: Any + no_store = ... # type: Any + max_age = ... # type: Any + no_transform = ... # type: Any + on_update = ... # type: Any + provided = ... # type: Any + def __init__(self, values=..., on_update=None): ... + def to_header(self): ... + +class RequestCacheControl(ImmutableDictMixin, _CacheControl): + max_stale = ... # type: Any + min_fresh = ... # type: Any + no_transform = ... # type: Any + only_if_cached = ... # type: Any + +class ResponseCacheControl(_CacheControl): + public = ... # type: Any + private = ... # type: Any + must_revalidate = ... # type: Any + proxy_revalidate = ... # type: Any + s_maxage = ... # type: Any + +class CallbackDict(UpdateDictMixin, dict): + on_update = ... # type: Any + def __init__(self, initial=None, on_update=None): ... + +class HeaderSet(MutableSet): + on_update = ... # type: Any + def __init__(self, headers=None, on_update=None): ... + def add(self, header): ... + def remove(self, header): ... + def update(self, iterable): ... + def discard(self, header): ... + def find(self, header): ... + def index(self, header): ... + def clear(self): ... + def as_set(self, preserve_casing=False): ... + def to_header(self): ... + def __getitem__(self, idx): ... + def __delitem__(self, idx): ... + def __setitem__(self, idx, value): ... + def __contains__(self, header): ... + def __len__(self): ... + def __iter__(self): ... + def __nonzero__(self): ... + +class ETags(Container, Iterable): + star_tag = ... # type: Any + def __init__(self, strong_etags=None, weak_etags=None, star_tag=False): ... + def as_set(self, include_weak=False): ... + def is_weak(self, etag): ... + def contains_weak(self, etag): ... + def contains(self, etag): ... + def contains_raw(self, etag): ... + def to_header(self): ... + def __call__(self, etag=None, data=None, include_weak=False): ... + def __bool__(self): ... + __nonzero__ = ... # type: Any + def __iter__(self): ... + def __contains__(self, etag): ... + +class IfRange: + etag = ... # type: Any + date = ... # type: Any + def __init__(self, etag=None, date=None): ... + def to_header(self): ... + +class Range: + units = ... # type: Any + ranges = ... # type: Any + def __init__(self, units, ranges): ... + def range_for_length(self, length): ... + def make_content_range(self, length): ... + def to_header(self): ... + def to_content_range_header(self, length): ... + +class ContentRange: + on_update = ... # type: Any + def __init__(self, units, start, stop, length=None, on_update=None): ... + units = ... # type: Any + start = ... # type: Any + stop = ... # type: Any + length = ... # type: Any + def set(self, start, stop, length=None, units=''): ... + def unset(self): ... + def to_header(self): ... + def __nonzero__(self): ... + __bool__ = ... # type: Any + +class Authorization(ImmutableDictMixin, dict): + type = ... # type: Any + def __init__(self, auth_type, data=None): ... + username = ... # type: Any + password = ... # type: Any + realm = ... # type: Any + nonce = ... # type: Any + uri = ... # type: Any + nc = ... # type: Any + cnonce = ... # type: Any + response = ... # type: Any + opaque = ... # type: Any + @property + def qop(self): ... + +class WWWAuthenticate(UpdateDictMixin, dict): + on_update = ... # type: Any + def __init__(self, auth_type=None, values=None, on_update=None): ... + def set_basic(self, realm=''): ... + def set_digest(self, realm, nonce, qop=..., opaque=None, algorithm=None, stale=False): ... + def to_header(self): ... + @staticmethod + def auth_property(name, doc=None): ... + type = ... # type: Any + realm = ... # type: Any + domain = ... # type: Any + nonce = ... # type: Any + opaque = ... # type: Any + algorithm = ... # type: Any + qop = ... # type: Any + stale = ... # type: Any + +class FileStorage: + name = ... # type: Any + stream = ... # type: Any + filename = ... # type: Any + headers = ... # type: Any + def __init__(self, stream=None, filename=None, name=None, content_type=None, content_length=None, headers=None): ... + @property + def content_type(self): ... + @property + def content_length(self): ... + @property + def mimetype(self): ... + @property + def mimetype_params(self): ... + def save(self, dst, buffer_size=16384): ... + def close(self): ... + def __nonzero__(self): ... + __bool__ = ... # type: Any + def __getattr__(self, name): ... + def __iter__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/__init__.pyi new file mode 100644 index 000000000..0c949f91d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/__init__.pyi @@ -0,0 +1,39 @@ +from typing import Any +from werkzeug.wrappers import BaseRequest as Request, BaseResponse as Response + +PIN_TIME = ... # type: Any + +def hash_pin(pin): ... +def get_machine_id(): ... + +class _ConsoleFrame: + console = ... # type: Any + id = ... # type: Any + def __init__(self, namespace): ... + +def get_pin_and_cookie_name(app): ... + +class DebuggedApplication: + app = ... # type: Any + evalex = ... # type: Any + frames = ... # type: Any + tracebacks = ... # type: Any + request_key = ... # type: Any + console_path = ... # type: Any + console_init_func = ... # type: Any + show_hidden_frames = ... # type: Any + secret = ... # type: Any + pin_logging = ... # type: Any + pin = ... # type: Any + def __init__(self, app, evalex=False, request_key='', console_path='', console_init_func=None, show_hidden_frames=False, lodgeit_url=None, pin_security=True, pin_logging=True): ... + @property + def pin_cookie_name(self): ... + def debug_application(self, environ, start_response): ... + def execute_command(self, request, command, frame): ... + def display_console(self, request): ... + def paste_traceback(self, request, traceback): ... + def get_resource(self, request, filename): ... + def check_pin_trust(self, environ): ... + def pin_auth(self, request): ... + def log_pin_request(self): ... + def __call__(self, environ, start_response): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/console.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/console.pyi new file mode 100644 index 000000000..5046a519c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/console.pyi @@ -0,0 +1,44 @@ +from typing import Any +import code + +class HTMLStringO: + def __init__(self): ... + def isatty(self): ... + def close(self): ... + def flush(self): ... + def seek(self, n, mode=0): ... + def readline(self): ... + def reset(self): ... + def write(self, x): ... + def writelines(self, x): ... + +class ThreadedStream: + @staticmethod + def push(): ... + @staticmethod + def fetch(): ... + @staticmethod + def displayhook(obj): ... + def __setattr__(self, name, value): ... + def __dir__(self): ... + def __getattribute__(self, name): ... + +class _ConsoleLoader: + def __init__(self): ... + def register(self, code, source): ... + def get_source_by_code(self, code): ... + +class _InteractiveConsole(code.InteractiveInterpreter): + globals = ... # type: Any + more = ... # type: Any + buffer = ... # type: Any + def __init__(self, globals, locals): ... + def runsource(self, source): ... + def runcode(self, code): ... + def showtraceback(self): ... + def showsyntaxerror(self, filename=None): ... + def write(self, data): ... + +class Console: + def __init__(self, globals=None, locals=None): ... + def eval(self, code): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/repr.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/repr.pyi new file mode 100644 index 000000000..fe3faef8e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/repr.pyi @@ -0,0 +1,33 @@ +from typing import Any + +deque = ... # type: Any +missing = ... # type: Any +RegexType = ... # type: Any +HELP_HTML = ... # type: Any +OBJECT_DUMP_HTML = ... # type: Any + +def debug_repr(obj): ... +def dump(obj=...): ... + +class _Helper: + def __call__(self, topic=None): ... + +helper = ... # type: Any + +class DebugReprGenerator: + def __init__(self): ... + list_repr = ... # type: Any + tuple_repr = ... # type: Any + set_repr = ... # type: Any + frozenset_repr = ... # type: Any + deque_repr = ... # type: Any + def regex_repr(self, obj): ... + def string_repr(self, obj, limit=70): ... + def dict_repr(self, d, recursive, limit=5): ... + def object_repr(self, obj): ... + def dispatch_repr(self, obj, recursive): ... + def fallback_repr(self): ... + def repr(self, obj): ... + def dump_object(self, obj): ... + def dump_locals(self, d): ... + def render_object_dump(self, items, title, repr=None): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/tbtools.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/tbtools.pyi new file mode 100644 index 000000000..7c0cd584b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/debug/tbtools.pyi @@ -0,0 +1,63 @@ +from typing import Any + +UTF8_COOKIE = ... # type: Any +system_exceptions = ... # type: Any +HEADER = ... # type: Any +FOOTER = ... # type: Any +PAGE_HTML = ... # type: Any +CONSOLE_HTML = ... # type: Any +SUMMARY_HTML = ... # type: Any +FRAME_HTML = ... # type: Any +SOURCE_LINE_HTML = ... # type: Any + +def render_console_html(secret, evalex_trusted=True): ... +def get_current_traceback(ignore_system_exceptions=False, show_hidden_frames=False, skip=0): ... + +class Line: + lineno = ... # type: Any + code = ... # type: Any + in_frame = ... # type: Any + current = ... # type: Any + def __init__(self, lineno, code): ... + def classes(self): ... + def render(self): ... + +class Traceback: + exc_type = ... # type: Any + exc_value = ... # type: Any + exception_type = ... # type: Any + frames = ... # type: Any + def __init__(self, exc_type, exc_value, tb): ... + def filter_hidden_frames(self): ... + def is_syntax_error(self): ... + def exception(self): ... + def log(self, logfile=None): ... + def paste(self): ... + def render_summary(self, include_title=True): ... + def render_full(self, evalex=False, secret=None, evalex_trusted=True): ... + def generate_plaintext_traceback(self): ... + def plaintext(self): ... + id = ... # type: Any + +class Frame: + lineno = ... # type: Any + function_name = ... # type: Any + locals = ... # type: Any + globals = ... # type: Any + filename = ... # type: Any + module = ... # type: Any + loader = ... # type: Any + code = ... # type: Any + hide = ... # type: Any + info = ... # type: Any + def __init__(self, exc_type, exc_value, tb): ... + def render(self): ... + def render_line_context(self): ... + def get_annotated_lines(self): ... + def eval(self, code, mode=''): ... + def sourcelines(self): ... + def get_context_lines(self, context=5): ... + @property + def current_line(self): ... + def console(self): ... + id = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/exceptions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/exceptions.pyi new file mode 100644 index 000000000..44ffbc054 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/exceptions.pyi @@ -0,0 +1,152 @@ +from typing import Any, Dict, NoReturn + +class HTTPException(Exception): + code = ... # type: Any + description = ... # type: Any + response = ... # type: Any + def __init__(self, description=None, response=None): ... + @classmethod + def wrap(cls, exception, name=None): ... + @property + def name(self): ... + def get_description(self, environ=None): ... + def get_body(self, environ=None): ... + def get_headers(self, environ=None): ... + def get_response(self, environ=None): ... + def __call__(self, environ, start_response): ... + +default_exceptions: Dict[int, HTTPException] + +class BadRequest(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class ClientDisconnected(BadRequest): ... +class SecurityError(BadRequest): ... +class BadHost(BadRequest): ... + +class Unauthorized(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class Forbidden(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class NotFound(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class MethodNotAllowed(HTTPException): + code = ... # type: Any + description = ... # type: Any + valid_methods = ... # type: Any + def __init__(self, valid_methods=None, description=None): ... + def get_headers(self, environ): ... + +class NotAcceptable(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class RequestTimeout(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class Conflict(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class Gone(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class LengthRequired(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class PreconditionFailed(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class RequestEntityTooLarge(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class RequestURITooLarge(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class UnsupportedMediaType(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class RequestedRangeNotSatisfiable(HTTPException): + code = ... # type: Any + description = ... # type: Any + length = ... # type: Any + units = ... # type: Any + def __init__(self, length=None, units='', description=None): ... + def get_headers(self, environ): ... + +class ExpectationFailed(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class ImATeapot(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class UnprocessableEntity(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class Locked(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class PreconditionRequired(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class TooManyRequests(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class RequestHeaderFieldsTooLarge(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class UnavailableForLegalReasons(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class InternalServerError(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class NotImplemented(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class BadGateway(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class ServiceUnavailable(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class GatewayTimeout(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class HTTPVersionNotSupported(HTTPException): + code = ... # type: Any + description = ... # type: Any + +class Aborter: + mapping = ... # type: Any + def __init__(self, mapping=None, extra=None): ... + def __call__(self, code, *args, **kwargs) -> NoReturn: ... + +def abort(status: Any, *args: Any, **kwargs: Any) -> NoReturn: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/filesystem.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/filesystem.pyi new file mode 100644 index 000000000..80913ca66 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/filesystem.pyi @@ -0,0 +1,7 @@ +from typing import Any + +has_likely_buggy_unicode_filesystem = ... # type: Any + +class BrokenFilesystemWarning(RuntimeWarning, UnicodeWarning): ... + +def get_filesystem_encoding(): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/formparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/formparser.pyi new file mode 100644 index 000000000..96c7f22dc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/formparser.pyi @@ -0,0 +1,40 @@ +from typing import Any + +def default_stream_factory(total_content_length, filename, content_type, content_length=None): ... +def parse_form_data(environ, stream_factory=None, charset='', errors='', max_form_memory_size=None, max_content_length=None, cls=None, silent=True): ... +def exhaust_stream(f): ... + +class FormDataParser: + stream_factory = ... # type: Any + charset = ... # type: Any + errors = ... # type: Any + max_form_memory_size = ... # type: Any + max_content_length = ... # type: Any + cls = ... # type: Any + silent = ... # type: Any + def __init__(self, stream_factory=None, charset='', errors='', max_form_memory_size=None, max_content_length=None, cls=None, silent=True): ... + def get_parse_func(self, mimetype, options): ... + def parse_from_environ(self, environ): ... + def parse(self, stream, mimetype, content_length, options=None): ... + parse_functions = ... # type: Any + +def is_valid_multipart_boundary(boundary): ... +def parse_multipart_headers(iterable): ... + +class MultiPartParser: + charset = ... # type: Any + errors = ... # type: Any + max_form_memory_size = ... # type: Any + stream_factory = ... # type: Any + cls = ... # type: Any + buffer_size = ... # type: Any + def __init__(self, stream_factory=None, charset='', errors='', max_form_memory_size=None, cls=None, buffer_size=...): ... + def fail(self, message): ... + def get_part_encoding(self, headers): ... + def get_part_charset(self, headers): ... + def start_file_streaming(self, filename, headers, total_content_length): ... + def in_memory_threshold_reached(self, bytes): ... + def validate_boundary(self, boundary): ... + def parse_lines(self, file, boundary, content_length, cap_at_buffer=True): ... + def parse_parts(self, file, boundary, content_length): ... + def parse(self, file, boundary, content_length): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/http.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/http.pyi new file mode 100644 index 000000000..33334f836 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/http.pyi @@ -0,0 +1,36 @@ +from typing import Any + +HTTP_STATUS_CODES = ... # type: Any + +def wsgi_to_bytes(data): ... +def bytes_to_wsgi(data): ... +def quote_header_value(value, extra_chars='', allow_token=True): ... +def unquote_header_value(value, is_filename=False): ... +def dump_options_header(header, options): ... +def dump_header(iterable, allow_token=True): ... +def parse_list_header(value): ... +def parse_dict_header(value, cls=...): ... +def parse_options_header(value, multiple=False): ... +def parse_accept_header(value, cls=None): ... +def parse_cache_control_header(value, on_update=None, cls=None): ... +def parse_set_header(value, on_update=None): ... +def parse_authorization_header(value): ... +def parse_www_authenticate_header(value, on_update=None): ... +def parse_if_range_header(value): ... +def parse_range_header(value, make_inclusive=True): ... +def parse_content_range_header(value, on_update=None): ... +def quote_etag(etag, weak=False): ... +def unquote_etag(etag): ... +def parse_etags(value): ... +def generate_etag(data): ... +def parse_date(value): ... +def cookie_date(expires=None): ... +def http_date(timestamp=None): ... +def is_resource_modified(environ, etag=None, data=None, last_modified=None, ignore_if_range=True): ... +def remove_entity_headers(headers, allowed=...): ... +def remove_hop_by_hop_headers(headers): ... +def is_entity_header(header): ... +def is_hop_by_hop_header(header): ... +def parse_cookie(header, charset='', errors='', cls=None): ... +def dump_cookie(key, value='', max_age=None, expires=None, path='', domain=None, secure=False, httponly=False, charset='', sync_expires=True): ... +def is_byte_range_valid(start, stop, length): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/local.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/local.pyi new file mode 100644 index 000000000..f1d167ac7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/local.pyi @@ -0,0 +1,100 @@ +from typing import Any + +def release_local(local): ... + +class Local: + def __init__(self): ... + def __iter__(self): ... + def __call__(self, proxy): ... + def __release_local__(self): ... + def __getattr__(self, name): ... + def __setattr__(self, name, value): ... + def __delattr__(self, name): ... + +class LocalStack: + def __init__(self): ... + def __release_local__(self): ... + def _get__ident_func__(self): ... + def _set__ident_func__(self, value): ... + __ident_func__ = ... # type: Any + def __call__(self): ... + def push(self, obj): ... + def pop(self): ... + @property + def top(self): ... + +class LocalManager: + locals = ... # type: Any + ident_func = ... # type: Any + def __init__(self, locals=None, ident_func=None): ... + def get_ident(self): ... + def cleanup(self): ... + def make_middleware(self, app): ... + def middleware(self, func): ... + +class LocalProxy: + def __init__(self, local, name=None): ... + @property + def __dict__(self): ... + def __bool__(self): ... + def __unicode__(self): ... + def __dir__(self): ... + def __getattr__(self, name): ... + def __setitem__(self, key, value): ... + def __delitem__(self, key): ... + __getslice__ = ... # type: Any + def __setslice__(self, i, j, seq): ... + def __delslice__(self, i, j): ... + __setattr__ = ... # type: Any + __delattr__ = ... # type: Any + __lt__ = ... # type: Any + __le__ = ... # type: Any + __eq__ = ... # type: Any + __ne__ = ... # type: Any + __gt__ = ... # type: Any + __ge__ = ... # type: Any + __cmp__ = ... # type: Any + __hash__ = ... # type: Any + __call__ = ... # type: Any + __len__ = ... # type: Any + __getitem__ = ... # type: Any + __iter__ = ... # type: Any + __contains__ = ... # type: Any + __add__ = ... # type: Any + __sub__ = ... # type: Any + __mul__ = ... # type: Any + __floordiv__ = ... # type: Any + __mod__ = ... # type: Any + __divmod__ = ... # type: Any + __pow__ = ... # type: Any + __lshift__ = ... # type: Any + __rshift__ = ... # type: Any + __and__ = ... # type: Any + __xor__ = ... # type: Any + __or__ = ... # type: Any + __div__ = ... # type: Any + __truediv__ = ... # type: Any + __neg__ = ... # type: Any + __pos__ = ... # type: Any + __abs__ = ... # type: Any + __invert__ = ... # type: Any + __complex__ = ... # type: Any + __int__ = ... # type: Any + __long__ = ... # type: Any + __float__ = ... # type: Any + __oct__ = ... # type: Any + __hex__ = ... # type: Any + __index__ = ... # type: Any + __coerce__ = ... # type: Any + __enter__ = ... # type: Any + __exit__ = ... # type: Any + __radd__ = ... # type: Any + __rsub__ = ... # type: Any + __rmul__ = ... # type: Any + __rdiv__ = ... # type: Any + __rtruediv__ = ... # type: Any + __rfloordiv__ = ... # type: Any + __rmod__ = ... # type: Any + __rdivmod__ = ... # type: Any + __copy__ = ... # type: Any + __deepcopy__ = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/posixemulation.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/posixemulation.pyi new file mode 100644 index 000000000..b490ab42b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/posixemulation.pyi @@ -0,0 +1,7 @@ +from typing import Any +from ._compat import to_unicode as to_unicode +from .filesystem import get_filesystem_encoding as get_filesystem_encoding + +can_rename_open_file = ... # type: Any + +def rename(src, dst): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/routing.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/routing.pyi new file mode 100644 index 000000000..3d80624d8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/routing.pyi @@ -0,0 +1,179 @@ +from typing import Any, Optional +from werkzeug.exceptions import HTTPException + +def parse_converter_args(argstr): ... +def parse_rule(rule): ... + +class RoutingException(Exception): ... + +class RequestRedirect(HTTPException, RoutingException): + code = ... # type: Any + new_url = ... # type: Any + def __init__(self, new_url): ... + def get_response(self, environ): ... + +class RequestSlash(RoutingException): ... + +class RequestAliasRedirect(RoutingException): + matched_values = ... # type: Any + def __init__(self, matched_values): ... + +class BuildError(RoutingException, LookupError): + endpoint = ... # type: Any + values = ... # type: Any + method = ... # type: Any + adapter: Optional[MapAdapter] + def __init__(self, endpoint, values, method, adapter: Optional[MapAdapter] = ...) -> None: ... + @property + def suggested(self) -> Optional[Rule]: ... + def closest_rule(self, adapter: Optional[MapAdapter]) -> Optional[Rule]: ... + +class ValidationError(ValueError): ... + +class RuleFactory: + def get_rules(self, map): ... + +class Subdomain(RuleFactory): + subdomain = ... # type: Any + rules = ... # type: Any + def __init__(self, subdomain, rules): ... + def get_rules(self, map): ... + +class Submount(RuleFactory): + path = ... # type: Any + rules = ... # type: Any + def __init__(self, path, rules): ... + def get_rules(self, map): ... + +class EndpointPrefix(RuleFactory): + prefix = ... # type: Any + rules = ... # type: Any + def __init__(self, prefix, rules): ... + def get_rules(self, map): ... + +class RuleTemplate: + rules = ... # type: Any + def __init__(self, rules): ... + def __call__(self, *args, **kwargs): ... + +class RuleTemplateFactory(RuleFactory): + rules = ... # type: Any + context = ... # type: Any + def __init__(self, rules, context): ... + def get_rules(self, map): ... + +class Rule(RuleFactory): + rule = ... # type: Any + is_leaf = ... # type: Any + map = ... # type: Any + strict_slashes = ... # type: Any + subdomain = ... # type: Any + host = ... # type: Any + defaults = ... # type: Any + build_only = ... # type: Any + alias = ... # type: Any + methods = ... # type: Any + endpoint = ... # type: Any + redirect_to = ... # type: Any + arguments = ... # type: Any + def __init__(self, string, defaults=None, subdomain=None, methods=None, build_only=False, endpoint=None, strict_slashes=None, redirect_to=None, alias=False, host=None): ... + def empty(self): ... + def get_empty_kwargs(self): ... + def get_rules(self, map): ... + def refresh(self): ... + def bind(self, map, rebind=False): ... + def get_converter(self, variable_name, converter_name, args, kwargs): ... + def compile(self): ... + def match(self, path, method=None): ... + def build(self, values, append_unknown=True): ... + def provides_defaults_for(self, rule): ... + def suitable_for(self, values, method=None): ... + def match_compare_key(self): ... + def build_compare_key(self): ... + def __eq__(self, other): ... + def __ne__(self, other): ... + +class BaseConverter: + regex = ... # type: Any + weight = ... # type: Any + map = ... # type: Any + def __init__(self, map): ... + def to_python(self, value): ... + def to_url(self, value): ... + +class UnicodeConverter(BaseConverter): + regex = ... # type: Any + def __init__(self, map, minlength=1, maxlength=None, length=None): ... + +class AnyConverter(BaseConverter): + regex = ... # type: Any + def __init__(self, map, *items): ... + +class PathConverter(BaseConverter): + regex = ... # type: Any + weight = ... # type: Any + +class NumberConverter(BaseConverter): + weight = ... # type: Any + fixed_digits = ... # type: Any + min = ... # type: Any + max = ... # type: Any + def __init__(self, map, fixed_digits=0, min=None, max=None): ... + def to_python(self, value): ... + def to_url(self, value): ... + +class IntegerConverter(NumberConverter): + regex = ... # type: Any + num_convert = ... # type: Any + +class FloatConverter(NumberConverter): + regex = ... # type: Any + num_convert = ... # type: Any + def __init__(self, map, min=None, max=None): ... + +class UUIDConverter(BaseConverter): + regex = ... # type: Any + def to_python(self, value): ... + def to_url(self, value): ... + +DEFAULT_CONVERTERS = ... # type: Any + +class Map: + default_converters = ... # type: Any + default_subdomain = ... # type: Any + charset = ... # type: Any + encoding_errors = ... # type: Any + strict_slashes = ... # type: Any + redirect_defaults = ... # type: Any + host_matching = ... # type: Any + converters = ... # type: Any + sort_parameters = ... # type: Any + sort_key = ... # type: Any + def __init__(self, rules=None, default_subdomain='', charset='', strict_slashes=True, redirect_defaults=True, converters=None, sort_parameters=False, sort_key=None, encoding_errors='', host_matching=False): ... + def is_endpoint_expecting(self, endpoint, *arguments): ... + def iter_rules(self, endpoint=None): ... + def add(self, rulefactory): ... + def bind(self, server_name, script_name=None, subdomain=None, url_scheme='', default_method='', path_info=None, query_args=None): ... + def bind_to_environ(self, environ, server_name=None, subdomain=None): ... + def update(self): ... + +class MapAdapter: + map = ... # type: Any + server_name = ... # type: Any + script_name = ... # type: Any + subdomain = ... # type: Any + url_scheme = ... # type: Any + path_info = ... # type: Any + default_method = ... # type: Any + query_args = ... # type: Any + def __init__(self, map, server_name, script_name, subdomain, url_scheme, path_info, default_method, query_args=None): ... + def dispatch(self, view_func, path_info=None, method=None, catch_http_exceptions=False): ... + def match(self, path_info=None, method=None, return_rule=False, query_args=None): ... + def test(self, path_info=None, method=None): ... + def allowed_methods(self, path_info=None): ... + def get_host(self, domain_part): ... + def get_default_redirect(self, rule, method, values, query_args): ... + def encode_query_args(self, query_args): ... + def make_redirect_url(self, path_info, query_args=None, domain_part=None): ... + def make_alias_redirect_url(self, path, endpoint, values, method, query_args): ... + def build(self, endpoint, values=None, method=None, force_external=False, append_unknown=True): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/script.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/script.pyi new file mode 100644 index 000000000..758378d3b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/script.pyi @@ -0,0 +1,12 @@ +from typing import Any + +argument_types = ... # type: Any +converters = ... # type: Any + +def run(namespace=None, action_prefix='', args=None): ... +def fail(message, code=-1): ... +def find_actions(namespace, action_prefix): ... +def print_usage(actions): ... +def analyse_action(func): ... +def make_shell(init_func=None, banner=None, use_ipython=True): ... +def make_runserver(app_factory, hostname='', port=5000, use_reloader=False, use_debugger=False, use_evalex=True, threaded=False, processes=1, static_files=None, extra_files=None, ssl_context=None): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/security.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/security.pyi new file mode 100644 index 000000000..dde9fe1df --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/security.pyi @@ -0,0 +1,12 @@ +from typing import Any + +SALT_CHARS = ... # type: Any +DEFAULT_PBKDF2_ITERATIONS = ... # type: Any + +def pbkdf2_hex(data, salt, iterations=..., keylen=None, hashfunc=None): ... +def pbkdf2_bin(data, salt, iterations=..., keylen=None, hashfunc=None): ... +def safe_str_cmp(a, b): ... +def gen_salt(length): ... +def generate_password_hash(password, method='', salt_length=8): ... +def check_password_hash(pwhash, password): ... +def safe_join(directory, filename): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/serving.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/serving.pyi new file mode 100644 index 000000000..9ef8e0969 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/serving.pyi @@ -0,0 +1,86 @@ +import sys +from typing import Any + +if sys.version_info < (3,): + from SocketServer import ThreadingMixIn, ForkingMixIn + from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler +else: + from socketserver import ThreadingMixIn, ForkingMixIn + from http.server import HTTPServer, BaseHTTPRequestHandler + +class _SslDummy: + def __getattr__(self, name): ... + +ssl = ... # type: Any +LISTEN_QUEUE = ... # type: Any +can_open_by_fd = ... # type: Any + +class WSGIRequestHandler(BaseHTTPRequestHandler): + @property + def server_version(self): ... + def make_environ(self): ... + environ = ... # type: Any + close_connection = ... # type: Any + def run_wsgi(self): ... + def handle(self): ... + def initiate_shutdown(self): ... + def connection_dropped(self, error, environ=None): ... + raw_requestline = ... # type: Any + def handle_one_request(self): ... + def send_response(self, code, message=None): ... + def version_string(self): ... + def address_string(self): ... + def port_integer(self): ... + def log_request(self, code='', size=''): ... + def log_error(self, *args): ... + def log_message(self, format, *args): ... + def log(self, type, message, *args): ... + +BaseRequestHandler = ... # type: Any + +def generate_adhoc_ssl_pair(cn=None): ... +def make_ssl_devcert(base_path, host=None, cn=None): ... +def generate_adhoc_ssl_context(): ... +def load_ssl_context(cert_file, pkey_file=None, protocol=None): ... + +class _SSLContext: + def __init__(self, protocol): ... + def load_cert_chain(self, certfile, keyfile=None, password=None): ... + def wrap_socket(self, sock, **kwargs): ... + +def is_ssl_error(error=None): ... +def select_ip_version(host, port): ... + +class BaseWSGIServer(HTTPServer): + multithread = ... # type: Any + multiprocess = ... # type: Any + request_queue_size = ... # type: Any + address_family = ... # type: Any + app = ... # type: Any + passthrough_errors = ... # type: Any + shutdown_signal = ... # type: Any + host = ... # type: Any + port = ... # type: Any + socket = ... # type: Any + server_address = ... # type: Any + ssl_context = ... # type: Any + def __init__(self, host, port, app, handler=None, passthrough_errors=False, ssl_context=None, fd=None): ... + def log(self, type, message, *args): ... + def serve_forever(self): ... + def handle_error(self, request, client_address): ... + def get_request(self): ... + +class ThreadedWSGIServer(ThreadingMixIn, BaseWSGIServer): + multithread = ... # type: Any + daemon_threads = ... # type: Any + +class ForkingWSGIServer(ForkingMixIn, BaseWSGIServer): + multiprocess = ... # type: Any + max_children = ... # type: Any + def __init__(self, host, port, app, processes=40, handler=None, passthrough_errors=False, ssl_context=None, fd=None): ... + +def make_server(host=None, port=None, app=None, threaded=False, processes=1, request_handler=None, passthrough_errors=False, ssl_context=None, fd=None): ... +def is_running_from_reloader(): ... +def run_simple(hostname, port, application, use_reloader=False, use_debugger=False, use_evalex=True, extra_files=None, reloader_interval=1, reloader_type='', threaded=False, processes=1, request_handler=None, static_files=None, passthrough_errors=False, ssl_context=None): ... +def run_with_reloader(*args, **kwargs): ... +def main(): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/test.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/test.pyi new file mode 100644 index 000000000..5a42552c1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/test.pyi @@ -0,0 +1,87 @@ +import sys +from typing import Any + +if sys.version_info < (3,): + from urllib2 import Request as U2Request + from cookielib import CookieJar +else: + from urllib.request import Request as U2Request + from http.cookiejar import CookieJar + +def stream_encode_multipart(values, use_tempfile=True, threshold=..., boundary=None, charset=''): ... +def encode_multipart(values, boundary=None, charset=''): ... +def File(fd, filename=None, mimetype=None): ... + +class _TestCookieHeaders: + headers = ... # type: Any + def __init__(self, headers): ... + def getheaders(self, name): ... + def get_all(self, name, default=None): ... + +class _TestCookieResponse: + headers = ... # type: Any + def __init__(self, headers): ... + def info(self): ... + +class _TestCookieJar(CookieJar): + def inject_wsgi(self, environ): ... + def extract_wsgi(self, environ, headers): ... + +class EnvironBuilder: + server_protocol = ... # type: Any + wsgi_version = ... # type: Any + request_class = ... # type: Any + charset = ... # type: Any + path = ... # type: Any + base_url = ... # type: Any + query_string = ... # type: Any + args = ... # type: Any + method = ... # type: Any + headers = ... # type: Any + content_type = ... # type: Any + errors_stream = ... # type: Any + multithread = ... # type: Any + multiprocess = ... # type: Any + run_once = ... # type: Any + environ_base = ... # type: Any + environ_overrides = ... # type: Any + input_stream = ... # type: Any + content_length = ... # type: Any + closed = ... # type: Any + def __init__(self, path='', base_url=None, query_string=None, method='', input_stream=None, content_type=None, content_length=None, errors_stream=None, multithread=False, multiprocess=False, run_once=False, headers=None, data=None, environ_base=None, environ_overrides=None, charset=''): ... + def form_property(name, storage, doc): ... + form = ... # type: Any + files = ... # type: Any + @property + def server_name(self): ... + @property + def server_port(self): ... + def __del__(self): ... + def close(self): ... + def get_environ(self): ... + def get_request(self, cls=None): ... + +class ClientRedirectError(Exception): ... + +class Client: + application = ... # type: Any + response_wrapper = ... # type: Any + cookie_jar = ... # type: Any + allow_subdomain_redirects = ... # type: Any + def __init__(self, application, response_wrapper=None, use_cookies=True, allow_subdomain_redirects=False): ... + def set_cookie(self, server_name, key, value='', max_age=None, expires=None, path='', domain=None, secure=None, httponly=False, charset=''): ... + def delete_cookie(self, server_name, key, path='', domain=None): ... + def run_wsgi_app(self, environ, buffered=False): ... + def resolve_redirect(self, response, new_location, environ, buffered=False): ... + def open(self, *args, **kwargs): ... + def get(self, *args, **kw): ... + def patch(self, *args, **kw): ... + def post(self, *args, **kw): ... + def head(self, *args, **kw): ... + def put(self, *args, **kw): ... + def delete(self, *args, **kw): ... + def options(self, *args, **kw): ... + def trace(self, *args, **kw): ... + +def create_environ(*args, **kwargs): ... +def run_wsgi_app(app, environ, buffered=False): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/testapp.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/testapp.pyi new file mode 100644 index 000000000..4e1763385 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/testapp.pyi @@ -0,0 +1,9 @@ +from typing import Any +from werkzeug.wrappers import BaseRequest as Request, BaseResponse as Response + +logo = ... # type: Any +TEMPLATE = ... # type: Any + +def iter_sys_path(): ... +def render_testapp(req): ... +def test_app(environ, start_response): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/urls.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/urls.pyi new file mode 100644 index 000000000..e2f724437 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/urls.pyi @@ -0,0 +1,67 @@ +from collections import namedtuple +from typing import Any + + +_URLTuple = namedtuple( + '_URLTuple', + ['scheme', 'netloc', 'path', 'query', 'fragment'] +) + + +class BaseURL(_URLTuple): + def replace(self, **kwargs): ... + @property + def host(self): ... + @property + def ascii_host(self): ... + @property + def port(self): ... + @property + def auth(self): ... + @property + def username(self): ... + @property + def raw_username(self): ... + @property + def password(self): ... + @property + def raw_password(self): ... + def decode_query(self, *args, **kwargs): ... + def join(self, *args, **kwargs): ... + def to_url(self): ... + def decode_netloc(self): ... + def to_uri_tuple(self): ... + def to_iri_tuple(self): ... + def get_file_location(self, pathformat=None): ... + +class URL(BaseURL): + def encode_netloc(self): ... + def encode(self, charset='', errors=''): ... + +class BytesURL(BaseURL): + def encode_netloc(self): ... + def decode(self, charset='', errors=''): ... + +def url_parse(url, scheme=None, allow_fragments=True): ... +def url_quote(string, charset='', errors='', safe='', unsafe=''): ... +def url_quote_plus(string, charset='', errors='', safe=''): ... +def url_unparse(components): ... +def url_unquote(string, charset='', errors='', unsafe=''): ... +def url_unquote_plus(s, charset='', errors=''): ... +def url_fix(s, charset=''): ... +def uri_to_iri(uri, charset='', errors=''): ... +def iri_to_uri(iri, charset='', errors='', safe_conversion=False): ... +def url_decode(s, charset='', decode_keys=False, include_empty=True, errors='', separator='', cls=None): ... +def url_decode_stream(stream, charset='', decode_keys=False, include_empty=True, errors='', separator='', cls=None, limit=None, return_iterator=False): ... +def url_encode(obj, charset='', encode_keys=False, sort=False, key=None, separator: bytes = ...): ... +def url_encode_stream(obj, stream=None, charset='', encode_keys=False, sort=False, key=None, separator: bytes = ...): ... +def url_join(base, url, allow_fragments=True): ... + +class Href: + base = ... # type: Any + charset = ... # type: Any + sort = ... # type: Any + key = ... # type: Any + def __init__(self, base='', charset='', sort=False, key=None): ... + def __getattr__(self, name): ... + def __call__(self, *path, **query): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/useragents.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/useragents.pyi new file mode 100644 index 000000000..2ca2705e4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/useragents.pyi @@ -0,0 +1,14 @@ +from typing import Any + +class UserAgentParser: + platforms = ... # type: Any + browsers = ... # type: Any + def __init__(self): ... + def __call__(self, user_agent): ... + +class UserAgent: + string = ... # type: Any + def __init__(self, environ_or_string): ... + def to_header(self): ... + def __nonzero__(self): ... + __bool__ = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/utils.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/utils.pyi new file mode 100644 index 000000000..8e2e6b9e7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/utils.pyi @@ -0,0 +1,49 @@ +from typing import Any +from werkzeug._internal import _DictAccessorProperty + +class cached_property(property): + __name__ = ... # type: Any + __module__ = ... # type: Any + __doc__ = ... # type: Any + func = ... # type: Any + def __init__(self, func, name=None, doc=None): ... + def __set__(self, obj, value): ... + def __get__(self, obj, type=None): ... + +class environ_property(_DictAccessorProperty): + read_only = ... # type: Any + def lookup(self, obj): ... + +class header_property(_DictAccessorProperty): + def lookup(self, obj): ... + +class HTMLBuilder: + def __init__(self, dialect): ... + def __call__(self, s): ... + def __getattr__(self, tag): ... + +html = ... # type: Any +xhtml = ... # type: Any + +def get_content_type(mimetype, charset): ... +def format_string(string, context): ... +def secure_filename(filename): ... +def escape(s, quote=None): ... +def unescape(s): ... +def redirect(location, code=302, Response=None): ... +def append_slash_redirect(environ, code=301): ... +def import_string(import_name, silent=False): ... +def find_modules(import_path, include_packages=False, recursive=False): ... +def validate_arguments(func, args, kwargs, drop_extra=True): ... +def bind_arguments(func, args, kwargs): ... + +class ArgumentValidationError(ValueError): + missing = ... # type: Any + extra = ... # type: Any + extra_positional = ... # type: Any + def __init__(self, missing=None, extra=None, extra_positional=None): ... + +class ImportStringError(ImportError): + import_name = ... # type: Any + exception = ... # type: Any + def __init__(self, import_name, exception): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/wrappers.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/wrappers.pyi new file mode 100644 index 000000000..3785124dd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/wrappers.pyi @@ -0,0 +1,225 @@ +from datetime import datetime +from typing import ( + Any, Callable, Iterable, Iterator, Mapping, MutableMapping, Optional, Sequence, Text, Tuple, Type, TypeVar, Union, +) + +from wsgiref.types import WSGIEnvironment, InputStream + +from .datastructures import ( + Authorization, CombinedMultiDict, EnvironHeaders, Headers, ImmutableMultiDict, + MultiDict, TypeConversionDict, HeaderSet, +) + +class BaseRequest: + charset = ... # type: str + encoding_errors = ... # type: str + max_content_length = ... # type: int + max_form_memory_size = ... # type: int + parameter_storage_class = ... # type: Type + list_storage_class = ... # type: Type + dict_storage_class = ... # type: Type + form_data_parser_class = ... # type: Type + trusted_hosts = ... # type: Optional[Sequence[Text]] + disable_data_descriptor = ... # type: Any + environ: WSGIEnvironment = ... + shallow = ... # type: Any + def __init__(self, environ: WSGIEnvironment, populate_request: bool = ..., shallow: bool = ...) -> None: ... + @property + def url_charset(self) -> str: ... + @classmethod + def from_values(cls, *args, **kwargs) -> 'BaseRequest': ... + @classmethod + def application(cls, f): ... + @property + def want_form_data_parsed(self): ... + def make_form_data_parser(self): ... + def close(self) -> None: ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, tb): ... + @property + def stream(self) -> InputStream: ... + input_stream: InputStream + args = ... # type: ImmutableMultiDict + @property + def data(self) -> bytes: ... + def get_data(self, cache: bool = ..., as_text: bool = ..., parse_form_data: bool = ...) -> bytes: ... + form = ... # type: ImmutableMultiDict + values = ... # type: CombinedMultiDict + files = ... # type: MultiDict + cookies = ... # type: TypeConversionDict + headers = ... # type: EnvironHeaders + path = ... # type: Text + full_path = ... # type: Text + script_root = ... # type: Text + url = ... # type: Text + base_url = ... # type: Text + url_root = ... # type: Text + host_url = ... # type: Text + host = ... # type: Text + query_string = ... # type: bytes + method = ... # type: Text + def access_route(self): ... + @property + def remote_addr(self) -> str: ... + remote_user = ... # type: Text + scheme = ... # type: str + is_xhr = ... # type: bool + is_secure = ... # type: bool + is_multithread = ... # type: bool + is_multiprocess = ... # type: bool + is_run_once = ... # type: bool + +_OnCloseT = TypeVar('_OnCloseT', bound=Callable[[], Any]) +_SelfT = TypeVar('_SelfT', bound=BaseResponse) + +class BaseResponse: + charset = ... # type: str + default_status = ... # type: int + default_mimetype = ... # type: str + implicit_sequence_conversion = ... # type: bool + autocorrect_location_header = ... # type: bool + automatically_set_content_length = ... # type: bool + headers = ... # type: Headers + status_code = ... # type: int + status = ... # type: str + direct_passthrough = ... # type: bool + response = ... # type: Iterable[bytes] + def __init__(self, response: Optional[Union[str, bytes, bytearray, Iterable[str], Iterable[bytes]]] = ..., + status: Optional[Union[Text, int]] = ..., + headers: Optional[Union[Headers, + Mapping[Text, Text], + Sequence[Tuple[Text, Text]]]] = ..., + mimetype: Optional[Text] = ..., + content_type: Optional[Text] = ..., + direct_passthrough: bool = ...) -> None: ... + def call_on_close(self, func: _OnCloseT) -> _OnCloseT: ... + @classmethod + def force_type(cls: Type[_SelfT], response: object, environ: Optional[WSGIEnvironment] = ...) -> _SelfT: ... + @classmethod + def from_app(cls: Type[_SelfT], app: Any, environ: WSGIEnvironment, buffered: bool = ...) -> _SelfT: ... + def get_data(self, as_text: bool = ...) -> Any: ... # returns bytes if as_text is False (the default), else Text + def set_data(self, value: Union[bytes, Text]) -> None: ... + data = ... # type: Any + def calculate_content_length(self) -> Optional[int]: ... + def make_sequence(self) -> None: ... + def iter_encoded(self) -> Iterator[bytes]: ... + def set_cookie(self, key, value='', max_age=None, expires=None, path='', domain=None, secure=False, httponly=False): ... + def delete_cookie(self, key, path='', domain=None): ... + @property + def is_streamed(self) -> bool: ... + @property + def is_sequence(self) -> bool: ... + def close(self) -> None: ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, tb): ... + # The no_etag argument if fictional, but required for compatibility with + # ETagResponseMixin + def freeze(self, no_etag: bool = ...) -> None: ... + def get_wsgi_headers(self, environ): ... + def get_app_iter(self, environ): ... + def get_wsgi_response(self, environ): ... + def __call__(self, environ, start_response): ... + +class AcceptMixin: + def accept_mimetypes(self): ... + def accept_charsets(self): ... + def accept_encodings(self): ... + def accept_languages(self): ... + +class ETagRequestMixin: + def cache_control(self): ... + def if_match(self): ... + def if_none_match(self): ... + def if_modified_since(self): ... + def if_unmodified_since(self): ... + def if_range(self): ... + def range(self): ... + +class UserAgentMixin: + def user_agent(self): ... + +class AuthorizationMixin: + @property + def authorization(self) -> Optional[Authorization]: ... + +class StreamOnlyMixin: + disable_data_descriptor = ... # type: Any + want_form_data_parsed = ... # type: Any + +class ETagResponseMixin: + @property + def cache_control(self): ... + status_code = ... # type: Any + def make_conditional(self, request_or_environ, accept_ranges=False, complete_length=None): ... + def add_etag(self, overwrite=False, weak=False): ... + def set_etag(self, etag, weak=False): ... + def get_etag(self): ... + def freeze(self, no_etag: bool = ...) -> None: ... + accept_ranges = ... # type: Any + content_range = ... # type: Any + +class ResponseStream: + mode = ... # type: Any + response = ... # type: Any + closed = ... # type: Any + def __init__(self, response): ... + def write(self, value): ... + def writelines(self, seq): ... + def close(self): ... + def flush(self): ... + def isatty(self): ... + @property + def encoding(self): ... + +class ResponseStreamMixin: + @property + def stream(self) -> ResponseStream: ... + +class CommonRequestDescriptorsMixin: + @property + def content_type(self) -> Optional[str]: ... + @property + def content_length(self) -> Optional[int]: ... + @property + def content_encoding(self) -> Optional[str]: ... + @property + def content_md5(self) -> Optional[str]: ... + @property + def referrer(self) -> Optional[str]: ... + @property + def date(self) -> Optional[datetime]: ... + @property + def max_forwards(self) -> Optional[int]: ... + @property + def mimetype(self) -> str: ... + @property + def mimetype_params(self) -> Mapping[str, str]: ... + @property + def pragma(self) -> HeaderSet: ... + +class CommonResponseDescriptorsMixin: + mimetype: Optional[str] = ... + @property + def mimetype_params(self) -> MutableMapping[str, str]: ... + location: Optional[str] = ... + age: Any = ... # get: Optional[datetime.timedelta] + content_type: Optional[str] = ... + content_length: Optional[int] = ... + content_location: Optional[str] = ... + content_encoding: Optional[str] = ... + content_md5: Optional[str] = ... + date: Any = ... # get: Optional[datetime.datetime] + expires: Any = ... # get: Optional[datetime.datetime] + last_modified: Any = ... # get: Optional[datetime.datetime] + retry_after: Any = ... # get: Optional[datetime.datetime] + vary: Optional[str] = ... + content_language: Optional[str] = ... + allow: Optional[str] = ... + +class WWWAuthenticateMixin: + @property + def www_authenticate(self): ... + +class Request(BaseRequest, AcceptMixin, ETagRequestMixin, UserAgentMixin, AuthorizationMixin, CommonRequestDescriptorsMixin): ... +class PlainRequest(StreamOnlyMixin, Request): ... +class Response(BaseResponse, ETagResponseMixin, ResponseStreamMixin, CommonResponseDescriptorsMixin, WWWAuthenticateMixin): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/wsgi.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/wsgi.pyi new file mode 100644 index 000000000..5adc153cc --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/werkzeug/wsgi.pyi @@ -0,0 +1,85 @@ +from typing import Any, Optional +from wsgiref.types import WSGIEnvironment, InputStream + +def responder(f): ... +def get_current_url(environ, root_only=False, strip_querystring=False, host_only=False, trusted_hosts=None): ... +def host_is_trusted(hostname, trusted_list): ... +def get_host(environ, trusted_hosts=None): ... +def get_content_length(environ: WSGIEnvironment) -> Optional[int]: ... +def get_input_stream(environ: WSGIEnvironment, safe_fallback: bool = ...) -> InputStream: ... +def get_query_string(environ): ... +def get_path_info(environ, charset='', errors=''): ... +def get_script_name(environ, charset='', errors=''): ... +def pop_path_info(environ, charset='', errors=''): ... +def peek_path_info(environ, charset='', errors=''): ... +def extract_path_info(environ_or_baseurl, path_or_url, charset='', errors='', collapse_http_schemes=True): ... + +class SharedDataMiddleware: + app = ... # type: Any + exports = ... # type: Any + cache = ... # type: Any + cache_timeout = ... # type: Any + fallback_mimetype = ... # type: Any + def __init__(self, app, exports, disallow=None, cache=True, cache_timeout=..., fallback_mimetype=''): ... + def is_allowed(self, filename): ... + def get_file_loader(self, filename): ... + def get_package_loader(self, package, package_path): ... + def get_directory_loader(self, directory): ... + def generate_etag(self, mtime, file_size, real_filename): ... + def __call__(self, environ, start_response): ... + +class DispatcherMiddleware: + app = ... # type: Any + mounts = ... # type: Any + def __init__(self, app, mounts=None): ... + def __call__(self, environ, start_response): ... + +class ClosingIterator: + def __init__(self, iterable, callbacks=None): ... + def __iter__(self): ... + def __next__(self): ... + def close(self): ... + +def wrap_file(environ, file, buffer_size=8192): ... + +class FileWrapper: + file = ... # type: Any + buffer_size = ... # type: Any + def __init__(self, file, buffer_size=8192): ... + def close(self): ... + def seekable(self): ... + def seek(self, *args): ... + def tell(self): ... + def __iter__(self): ... + def __next__(self): ... + +class _RangeWrapper: + iterable = ... # type: Any + byte_range = ... # type: Any + start_byte = ... # type: Any + end_byte = ... # type: Any + read_length = ... # type: Any + seekable = ... # type: Any + end_reached = ... # type: Any + def __init__(self, iterable, start_byte=0, byte_range=None): ... + def __iter__(self): ... + def __next__(self): ... + def close(self): ... + +def make_line_iter(stream, limit=None, buffer_size=..., cap_at_buffer=False): ... +def make_chunk_iter(stream, separator, limit=None, buffer_size=..., cap_at_buffer=False): ... + +class LimitedStream: + limit = ... # type: Any + def __init__(self, stream, limit): ... + def __iter__(self): ... + @property + def is_exhausted(self): ... + def on_exhausted(self): ... + def on_disconnect(self): ... + def exhaust(self, chunk_size=...): ... + def read(self, size=None): ... + def readline(self, size=None): ... + def readlines(self, size=None): ... + def tell(self): ... + def __next__(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/__init__.pyi new file mode 100644 index 000000000..4a5d2cda5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/__init__.pyi @@ -0,0 +1,48 @@ +from typing import Any, Iterator, Sequence, Union, IO +from yaml.error import * # noqa: F403 +from yaml.tokens import * # noqa: F403 +from yaml.events import * # noqa: F403 +from yaml.nodes import * # noqa: F403 +from yaml.loader import * # noqa: F403 +from yaml.dumper import * # noqa: F403 +from . import resolver # Help mypy a bit; this is implied by loader and dumper +# TODO: stubs for cyaml? +# from cyaml import * + +__with_libyaml__ = ... # type: Any + +def scan(stream, Loader=...): ... +def parse(stream, Loader=...): ... +def compose(stream, Loader=...): ... +def compose_all(stream, Loader=...): ... +def load(stream: Union[str, IO[str]], Loader=...) -> Any: ... +def load_all(stream: Union[str, IO[str]], Loader=...) -> Iterator[Any]: ... +def safe_load(stream: Union[str, IO[str]]) -> Any: ... +def safe_load_all(stream: Union[str, IO[str]]) -> Iterator[Any]: ... +def emit(events, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=...): ... +def serialize_all(nodes, stream=..., Dumper=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...): ... +def serialize(node, stream=..., Dumper=..., **kwds): ... +def dump_all(documents: Sequence[Any], stream: IO[str]=..., Dumper=..., default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> Any: ... +def dump(data: Any, stream: IO[str]=..., Dumper=..., **kwds) -> Any: ... +def safe_dump_all(documents: Sequence[Any], stream: IO[str]=..., **kwds) -> Any: ... +def safe_dump(data: Any, stream: IO[str]=..., **kwds) -> Any: ... +def add_implicit_resolver(tag, regexp, first=..., Loader=..., Dumper=...): ... +def add_path_resolver(tag, path, kind=..., Loader=..., Dumper=...): ... +def add_constructor(tag, constructor, Loader=...): ... +def add_multi_constructor(tag_prefix, multi_constructor, Loader=...): ... +def add_representer(data_type, representer, Dumper=...): ... +def add_multi_representer(data_type, multi_representer, Dumper=...): ... + +class YAMLObjectMetaclass(type): + def __init__(cls, name, bases, kwds) -> None: ... + +class YAMLObject: + __metaclass__ = YAMLObjectMetaclass + yaml_loader = ... # type: Any + yaml_dumper = ... # type: Any + yaml_tag = ... # type: Any + yaml_flow_style = ... # type: Any + @classmethod + def from_yaml(cls, loader, node): ... + @classmethod + def to_yaml(cls, dumper, data): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/composer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/composer.pyi new file mode 100644 index 000000000..20719e053 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/composer.pyi @@ -0,0 +1,17 @@ +from typing import Any +from yaml.error import Mark, YAMLError, MarkedYAMLError +from yaml.nodes import Node, ScalarNode, CollectionNode, SequenceNode, MappingNode + +class ComposerError(MarkedYAMLError): ... + +class Composer: + anchors = ... # type: Any + def __init__(self) -> None: ... + def check_node(self): ... + def get_node(self): ... + def get_single_node(self): ... + def compose_document(self): ... + def compose_node(self, parent, index): ... + def compose_scalar_node(self, anchor): ... + def compose_sequence_node(self, anchor): ... + def compose_mapping_node(self, anchor): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/constructor.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/constructor.pyi new file mode 100644 index 000000000..40e9ea2f8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/constructor.pyi @@ -0,0 +1,68 @@ +from yaml.error import Mark, YAMLError, MarkedYAMLError +from yaml.nodes import Node, ScalarNode, CollectionNode, SequenceNode, MappingNode + +from typing import Any + +class ConstructorError(MarkedYAMLError): ... + +class BaseConstructor: + yaml_constructors = ... # type: Any + yaml_multi_constructors = ... # type: Any + constructed_objects = ... # type: Any + recursive_objects = ... # type: Any + state_generators = ... # type: Any + deep_construct = ... # type: Any + def __init__(self) -> None: ... + def check_data(self): ... + def get_data(self): ... + def get_single_data(self): ... + def construct_document(self, node): ... + def construct_object(self, node, deep=...): ... + def construct_scalar(self, node): ... + def construct_sequence(self, node, deep=...): ... + def construct_mapping(self, node, deep=...): ... + def construct_pairs(self, node, deep=...): ... + @classmethod + def add_constructor(cls, tag, constructor): ... + @classmethod + def add_multi_constructor(cls, tag_prefix, multi_constructor): ... + +class SafeConstructor(BaseConstructor): + def construct_scalar(self, node): ... + def flatten_mapping(self, node): ... + def construct_mapping(self, node, deep=...): ... + def construct_yaml_null(self, node): ... + bool_values = ... # type: Any + def construct_yaml_bool(self, node): ... + def construct_yaml_int(self, node): ... + inf_value = ... # type: Any + nan_value = ... # type: Any + def construct_yaml_float(self, node): ... + def construct_yaml_binary(self, node): ... + timestamp_regexp = ... # type: Any + def construct_yaml_timestamp(self, node): ... + def construct_yaml_omap(self, node): ... + def construct_yaml_pairs(self, node): ... + def construct_yaml_set(self, node): ... + def construct_yaml_str(self, node): ... + def construct_yaml_seq(self, node): ... + def construct_yaml_map(self, node): ... + def construct_yaml_object(self, node, cls): ... + def construct_undefined(self, node): ... + +class Constructor(SafeConstructor): + def construct_python_str(self, node): ... + def construct_python_unicode(self, node): ... + def construct_python_long(self, node): ... + def construct_python_complex(self, node): ... + def construct_python_tuple(self, node): ... + def find_python_module(self, name, mark): ... + def find_python_name(self, name, mark): ... + def construct_python_name(self, suffix, node): ... + def construct_python_module(self, suffix, node): ... + class classobj: ... + def make_python_instance(self, suffix, node, args=..., kwds=..., newobj=...): ... + def set_python_instance_state(self, instance, state): ... + def construct_python_object(self, suffix, node): ... + def construct_python_object_apply(self, suffix, node, newobj=...): ... + def construct_python_object_new(self, suffix, node): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/dumper.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/dumper.pyi new file mode 100644 index 000000000..0586f1313 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/dumper.pyi @@ -0,0 +1,13 @@ +from yaml.emitter import Emitter +from yaml.serializer import Serializer +from yaml.representer import BaseRepresenter, Representer, SafeRepresenter +from yaml.resolver import BaseResolver, Resolver + +class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver): + def __init__(self, stream, default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ... + +class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver): + def __init__(self, stream, default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ... + +class Dumper(Emitter, Serializer, Representer, Resolver): + def __init__(self, stream, default_style=..., default_flow_style=..., canonical=..., indent=..., width=..., allow_unicode=..., line_break=..., encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/emitter.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/emitter.pyi new file mode 100644 index 000000000..a090c6d87 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/emitter.pyi @@ -0,0 +1,106 @@ +from typing import Any +from yaml.error import YAMLError + +class EmitterError(YAMLError): ... + +class ScalarAnalysis: + scalar = ... # type: Any + empty = ... # type: Any + multiline = ... # type: Any + allow_flow_plain = ... # type: Any + allow_block_plain = ... # type: Any + allow_single_quoted = ... # type: Any + allow_double_quoted = ... # type: Any + allow_block = ... # type: Any + def __init__(self, scalar, empty, multiline, allow_flow_plain, allow_block_plain, allow_single_quoted, allow_double_quoted, allow_block) -> None: ... + +class Emitter: + DEFAULT_TAG_PREFIXES = ... # type: Any + stream = ... # type: Any + encoding = ... # type: Any + states = ... # type: Any + state = ... # type: Any + events = ... # type: Any + event = ... # type: Any + indents = ... # type: Any + indent = ... # type: Any + flow_level = ... # type: Any + root_context = ... # type: Any + sequence_context = ... # type: Any + mapping_context = ... # type: Any + simple_key_context = ... # type: Any + line = ... # type: Any + column = ... # type: Any + whitespace = ... # type: Any + indention = ... # type: Any + open_ended = ... # type: Any + canonical = ... # type: Any + allow_unicode = ... # type: Any + best_indent = ... # type: Any + best_width = ... # type: Any + best_line_break = ... # type: Any + tag_prefixes = ... # type: Any + prepared_anchor = ... # type: Any + prepared_tag = ... # type: Any + analysis = ... # type: Any + style = ... # type: Any + def __init__(self, stream, canonical=..., indent=..., width=..., allow_unicode=..., line_break=...) -> None: ... + def dispose(self): ... + def emit(self, event): ... + def need_more_events(self): ... + def need_events(self, count): ... + def increase_indent(self, flow=..., indentless=...): ... + def expect_stream_start(self): ... + def expect_nothing(self): ... + def expect_first_document_start(self): ... + def expect_document_start(self, first=...): ... + def expect_document_end(self): ... + def expect_document_root(self): ... + def expect_node(self, root=..., sequence=..., mapping=..., simple_key=...): ... + def expect_alias(self): ... + def expect_scalar(self): ... + def expect_flow_sequence(self): ... + def expect_first_flow_sequence_item(self): ... + def expect_flow_sequence_item(self): ... + def expect_flow_mapping(self): ... + def expect_first_flow_mapping_key(self): ... + def expect_flow_mapping_key(self): ... + def expect_flow_mapping_simple_value(self): ... + def expect_flow_mapping_value(self): ... + def expect_block_sequence(self): ... + def expect_first_block_sequence_item(self): ... + def expect_block_sequence_item(self, first=...): ... + def expect_block_mapping(self): ... + def expect_first_block_mapping_key(self): ... + def expect_block_mapping_key(self, first=...): ... + def expect_block_mapping_simple_value(self): ... + def expect_block_mapping_value(self): ... + def check_empty_sequence(self): ... + def check_empty_mapping(self): ... + def check_empty_document(self): ... + def check_simple_key(self): ... + def process_anchor(self, indicator): ... + def process_tag(self): ... + def choose_scalar_style(self): ... + def process_scalar(self): ... + def prepare_version(self, version): ... + def prepare_tag_handle(self, handle): ... + def prepare_tag_prefix(self, prefix): ... + def prepare_tag(self, tag): ... + def prepare_anchor(self, anchor): ... + def analyze_scalar(self, scalar): ... + def flush_stream(self): ... + def write_stream_start(self): ... + def write_stream_end(self): ... + def write_indicator(self, indicator, need_whitespace, whitespace=..., indention=...): ... + def write_indent(self): ... + def write_line_break(self, data=...): ... + def write_version_directive(self, version_text): ... + def write_tag_directive(self, handle_text, prefix_text): ... + def write_single_quoted(self, text, split=...): ... + ESCAPE_REPLACEMENTS = ... # type: Any + def write_double_quoted(self, text, split=...): ... + def determine_block_hints(self, text): ... + def write_folded(self, text): ... + def write_literal(self, text): ... + def write_plain(self, text, split=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/error.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/error.pyi new file mode 100644 index 000000000..4e799df48 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/error.pyi @@ -0,0 +1,21 @@ +from typing import Any + +class Mark: + name = ... # type: Any + index = ... # type: Any + line = ... # type: Any + column = ... # type: Any + buffer = ... # type: Any + pointer = ... # type: Any + def __init__(self, name, index, line, column, buffer, pointer) -> None: ... + def get_snippet(self, indent=..., max_length=...): ... + +class YAMLError(Exception): ... + +class MarkedYAMLError(YAMLError): + context = ... # type: Any + context_mark = ... # type: Any + problem = ... # type: Any + problem_mark = ... # type: Any + note = ... # type: Any + def __init__(self, context=..., context_mark=..., problem=..., problem_mark=..., note=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/events.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/events.pyi new file mode 100644 index 000000000..4c055c775 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/events.pyi @@ -0,0 +1,62 @@ +from typing import Any + +class Event: + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, start_mark=..., end_mark=...) -> None: ... + +class NodeEvent(Event): + anchor = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, anchor, start_mark=..., end_mark=...) -> None: ... + +class CollectionStartEvent(NodeEvent): + anchor = ... # type: Any + tag = ... # type: Any + implicit = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + flow_style = ... # type: Any + def __init__(self, anchor, tag, implicit, start_mark=..., end_mark=..., flow_style=...) -> None: ... + +class CollectionEndEvent(Event): ... + +class StreamStartEvent(Event): + start_mark = ... # type: Any + end_mark = ... # type: Any + encoding = ... # type: Any + def __init__(self, start_mark=..., end_mark=..., encoding=...) -> None: ... + +class StreamEndEvent(Event): ... + +class DocumentStartEvent(Event): + start_mark = ... # type: Any + end_mark = ... # type: Any + explicit = ... # type: Any + version = ... # type: Any + tags = ... # type: Any + def __init__(self, start_mark=..., end_mark=..., explicit=..., version=..., tags=...) -> None: ... + +class DocumentEndEvent(Event): + start_mark = ... # type: Any + end_mark = ... # type: Any + explicit = ... # type: Any + def __init__(self, start_mark=..., end_mark=..., explicit=...) -> None: ... + +class AliasEvent(NodeEvent): ... + +class ScalarEvent(NodeEvent): + anchor = ... # type: Any + tag = ... # type: Any + implicit = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + style = ... # type: Any + def __init__(self, anchor, tag, implicit, value, start_mark=..., end_mark=..., style=...) -> None: ... + +class SequenceStartEvent(CollectionStartEvent): ... +class SequenceEndEvent(CollectionEndEvent): ... +class MappingStartEvent(CollectionStartEvent): ... +class MappingEndEvent(CollectionEndEvent): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/loader.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/loader.pyi new file mode 100644 index 000000000..0e9afeac1 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/loader.pyi @@ -0,0 +1,15 @@ +from yaml.reader import Reader +from yaml.scanner import Scanner +from yaml.parser import Parser +from yaml.composer import Composer +from yaml.constructor import BaseConstructor, SafeConstructor, Constructor +from yaml.resolver import BaseResolver, Resolver + +class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, BaseResolver): + def __init__(self, stream) -> None: ... + +class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, Resolver): + def __init__(self, stream) -> None: ... + +class Loader(Reader, Scanner, Parser, Composer, Constructor, Resolver): + def __init__(self, stream) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/nodes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/nodes.pyi new file mode 100644 index 000000000..6e3836e79 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/nodes.pyi @@ -0,0 +1,31 @@ +from typing import Any + +class Node: + tag = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, tag, value, start_mark, end_mark) -> None: ... + +class ScalarNode(Node): + id = ... # type: Any + tag = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + style = ... # type: Any + def __init__(self, tag, value, start_mark=..., end_mark=..., style=...) -> None: ... + +class CollectionNode(Node): + tag = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + flow_style = ... # type: Any + def __init__(self, tag, value, start_mark=..., end_mark=..., flow_style=...) -> None: ... + +class SequenceNode(CollectionNode): + id = ... # type: Any + +class MappingNode(CollectionNode): + id = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/parser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/parser.pyi new file mode 100644 index 000000000..094a4ea94 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/parser.pyi @@ -0,0 +1,44 @@ +from typing import Any +from yaml.error import MarkedYAMLError + +class ParserError(MarkedYAMLError): ... + +class Parser: + DEFAULT_TAGS = ... # type: Any + current_event = ... # type: Any + yaml_version = ... # type: Any + tag_handles = ... # type: Any + states = ... # type: Any + marks = ... # type: Any + state = ... # type: Any + def __init__(self) -> None: ... + def dispose(self): ... + def check_event(self, *choices): ... + def peek_event(self): ... + def get_event(self): ... + def parse_stream_start(self): ... + def parse_implicit_document_start(self): ... + def parse_document_start(self): ... + def parse_document_end(self): ... + def parse_document_content(self): ... + def process_directives(self): ... + def parse_block_node(self): ... + def parse_flow_node(self): ... + def parse_block_node_or_indentless_sequence(self): ... + def parse_node(self, block=..., indentless_sequence=...): ... + def parse_block_sequence_first_entry(self): ... + def parse_block_sequence_entry(self): ... + def parse_indentless_sequence_entry(self): ... + def parse_block_mapping_first_key(self): ... + def parse_block_mapping_key(self): ... + def parse_block_mapping_value(self): ... + def parse_flow_sequence_first_entry(self): ... + def parse_flow_sequence_entry(self, first=...): ... + def parse_flow_sequence_entry_mapping_key(self): ... + def parse_flow_sequence_entry_mapping_value(self): ... + def parse_flow_sequence_entry_mapping_end(self): ... + def parse_flow_mapping_first_key(self): ... + def parse_flow_mapping_key(self, first=...): ... + def parse_flow_mapping_value(self): ... + def parse_flow_mapping_empty_value(self): ... + def process_empty_scalar(self, mark): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/reader.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/reader.pyi new file mode 100644 index 000000000..9b08631ec --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/reader.pyi @@ -0,0 +1,34 @@ +from typing import Any +from yaml.error import YAMLError + +class ReaderError(YAMLError): + name = ... # type: Any + character = ... # type: Any + position = ... # type: Any + encoding = ... # type: Any + reason = ... # type: Any + def __init__(self, name, position, character, encoding, reason) -> None: ... + +class Reader: + name = ... # type: Any + stream = ... # type: Any + stream_pointer = ... # type: Any + eof = ... # type: Any + buffer = ... # type: Any + pointer = ... # type: Any + raw_buffer = ... # type: Any + raw_decode = ... # type: Any + encoding = ... # type: Any + index = ... # type: Any + line = ... # type: Any + column = ... # type: Any + def __init__(self, stream) -> None: ... + def peek(self, index=...): ... + def prefix(self, length=...): ... + def forward(self, length=...): ... + def get_mark(self): ... + def determine_encoding(self): ... + NON_PRINTABLE = ... # type: Any + def check_printable(self, data): ... + def update(self, length): ... + def update_raw(self, size=...): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/representer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/representer.pyi new file mode 100644 index 000000000..b10f36de7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/representer.pyi @@ -0,0 +1,54 @@ +from typing import Any +from yaml.error import YAMLError + +class RepresenterError(YAMLError): ... + +class BaseRepresenter: + yaml_representers = ... # type: Any + yaml_multi_representers = ... # type: Any + default_style = ... # type: Any + default_flow_style = ... # type: Any + represented_objects = ... # type: Any + object_keeper = ... # type: Any + alias_key = ... # type: Any + def __init__(self, default_style=..., default_flow_style=...) -> None: ... + def represent(self, data): ... + def get_classobj_bases(self, cls): ... + def represent_data(self, data): ... + @classmethod + def add_representer(cls, data_type, representer): ... + @classmethod + def add_multi_representer(cls, data_type, representer): ... + def represent_scalar(self, tag, value, style=...): ... + def represent_sequence(self, tag, sequence, flow_style=...): ... + def represent_mapping(self, tag, mapping, flow_style=...): ... + def ignore_aliases(self, data): ... + +class SafeRepresenter(BaseRepresenter): + def ignore_aliases(self, data): ... + def represent_none(self, data): ... + def represent_str(self, data): ... + def represent_unicode(self, data): ... + def represent_bool(self, data): ... + def represent_int(self, data): ... + def represent_long(self, data): ... + inf_value = ... # type: Any + def represent_float(self, data): ... + def represent_list(self, data): ... + def represent_dict(self, data): ... + def represent_set(self, data): ... + def represent_date(self, data): ... + def represent_datetime(self, data): ... + def represent_yaml_object(self, tag, data, cls, flow_style=...): ... + def represent_undefined(self, data): ... + +class Representer(SafeRepresenter): + def represent_str(self, data): ... + def represent_unicode(self, data): ... + def represent_long(self, data): ... + def represent_complex(self, data): ... + def represent_tuple(self, data): ... + def represent_name(self, data): ... + def represent_module(self, data): ... + def represent_instance(self, data): ... + def represent_object(self, data): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/resolver.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/resolver.pyi new file mode 100644 index 000000000..0b5641e20 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/resolver.pyi @@ -0,0 +1,24 @@ +from typing import Any +from yaml.error import YAMLError + +class ResolverError(YAMLError): ... + +class BaseResolver: + DEFAULT_SCALAR_TAG = ... # type: Any + DEFAULT_SEQUENCE_TAG = ... # type: Any + DEFAULT_MAPPING_TAG = ... # type: Any + yaml_implicit_resolvers = ... # type: Any + yaml_path_resolvers = ... # type: Any + resolver_exact_paths = ... # type: Any + resolver_prefix_paths = ... # type: Any + def __init__(self) -> None: ... + @classmethod + def add_implicit_resolver(cls, tag, regexp, first): ... + @classmethod + def add_path_resolver(cls, tag, path, kind=...): ... + def descend_resolver(self, current_node, current_index): ... + def ascend_resolver(self): ... + def check_resolver_prefix(self, depth, path, kind, current_node, current_index): ... + def resolve(self, kind, value, implicit): ... + +class Resolver(BaseResolver): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/scanner.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/scanner.pyi new file mode 100644 index 000000000..81acb5863 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/scanner.pyi @@ -0,0 +1,96 @@ +from typing import Any +from yaml.error import MarkedYAMLError + +class ScannerError(MarkedYAMLError): ... + +class SimpleKey: + token_number = ... # type: Any + required = ... # type: Any + index = ... # type: Any + line = ... # type: Any + column = ... # type: Any + mark = ... # type: Any + def __init__(self, token_number, required, index, line, column, mark) -> None: ... + +class Scanner: + done = ... # type: Any + flow_level = ... # type: Any + tokens = ... # type: Any + tokens_taken = ... # type: Any + indent = ... # type: Any + indents = ... # type: Any + allow_simple_key = ... # type: Any + possible_simple_keys = ... # type: Any + def __init__(self) -> None: ... + def check_token(self, *choices): ... + def peek_token(self): ... + def get_token(self): ... + def need_more_tokens(self): ... + def fetch_more_tokens(self): ... + def next_possible_simple_key(self): ... + def stale_possible_simple_keys(self): ... + def save_possible_simple_key(self): ... + def remove_possible_simple_key(self): ... + def unwind_indent(self, column): ... + def add_indent(self, column): ... + def fetch_stream_start(self): ... + def fetch_stream_end(self): ... + def fetch_directive(self): ... + def fetch_document_start(self): ... + def fetch_document_end(self): ... + def fetch_document_indicator(self, TokenClass): ... + def fetch_flow_sequence_start(self): ... + def fetch_flow_mapping_start(self): ... + def fetch_flow_collection_start(self, TokenClass): ... + def fetch_flow_sequence_end(self): ... + def fetch_flow_mapping_end(self): ... + def fetch_flow_collection_end(self, TokenClass): ... + def fetch_flow_entry(self): ... + def fetch_block_entry(self): ... + def fetch_key(self): ... + def fetch_value(self): ... + def fetch_alias(self): ... + def fetch_anchor(self): ... + def fetch_tag(self): ... + def fetch_literal(self): ... + def fetch_folded(self): ... + def fetch_block_scalar(self, style): ... + def fetch_single(self): ... + def fetch_double(self): ... + def fetch_flow_scalar(self, style): ... + def fetch_plain(self): ... + def check_directive(self): ... + def check_document_start(self): ... + def check_document_end(self): ... + def check_block_entry(self): ... + def check_key(self): ... + def check_value(self): ... + def check_plain(self): ... + def scan_to_next_token(self): ... + def scan_directive(self): ... + def scan_directive_name(self, start_mark): ... + def scan_yaml_directive_value(self, start_mark): ... + def scan_yaml_directive_number(self, start_mark): ... + def scan_tag_directive_value(self, start_mark): ... + def scan_tag_directive_handle(self, start_mark): ... + def scan_tag_directive_prefix(self, start_mark): ... + def scan_directive_ignored_line(self, start_mark): ... + def scan_anchor(self, TokenClass): ... + def scan_tag(self): ... + def scan_block_scalar(self, style): ... + def scan_block_scalar_indicators(self, start_mark): ... + def scan_block_scalar_ignored_line(self, start_mark): ... + def scan_block_scalar_indentation(self): ... + def scan_block_scalar_breaks(self, indent): ... + def scan_flow_scalar(self, style): ... + ESCAPE_REPLACEMENTS = ... # type: Any + ESCAPE_CODES = ... # type: Any + def scan_flow_scalar_non_spaces(self, double, start_mark): ... + def scan_flow_scalar_spaces(self, double, start_mark): ... + def scan_flow_scalar_breaks(self, double, start_mark): ... + def scan_plain(self): ... + def scan_plain_spaces(self, indent, start_mark): ... + def scan_tag_handle(self, name, start_mark): ... + def scan_tag_uri(self, name, start_mark): ... + def scan_uri_escapes(self, name, start_mark): ... + def scan_line_break(self): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/serializer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/serializer.pyi new file mode 100644 index 000000000..c6cdb4985 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/serializer.pyi @@ -0,0 +1,23 @@ +from typing import Any +from yaml.error import YAMLError + +class SerializerError(YAMLError): ... + +class Serializer: + ANCHOR_TEMPLATE = ... # type: Any + use_encoding = ... # type: Any + use_explicit_start = ... # type: Any + use_explicit_end = ... # type: Any + use_version = ... # type: Any + use_tags = ... # type: Any + serialized_nodes = ... # type: Any + anchors = ... # type: Any + last_anchor_id = ... # type: Any + closed = ... # type: Any + def __init__(self, encoding=..., explicit_start=..., explicit_end=..., version=..., tags=...) -> None: ... + def open(self): ... + def close(self): ... + def serialize(self, node): ... + def anchor_node(self, node): ... + def generate_anchor(self, node): ... + def serialize_node(self, node, parent, index): ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/tokens.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/tokens.pyi new file mode 100644 index 000000000..a25cbe530 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/2and3/yaml/tokens.pyi @@ -0,0 +1,93 @@ +from typing import Any + +class Token: + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, start_mark, end_mark) -> None: ... + +class DirectiveToken(Token): + id = ... # type: Any + name = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, name, value, start_mark, end_mark) -> None: ... + +class DocumentStartToken(Token): + id = ... # type: Any + +class DocumentEndToken(Token): + id = ... # type: Any + +class StreamStartToken(Token): + id = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + encoding = ... # type: Any + def __init__(self, start_mark=..., end_mark=..., encoding=...) -> None: ... + +class StreamEndToken(Token): + id = ... # type: Any + +class BlockSequenceStartToken(Token): + id = ... # type: Any + +class BlockMappingStartToken(Token): + id = ... # type: Any + +class BlockEndToken(Token): + id = ... # type: Any + +class FlowSequenceStartToken(Token): + id = ... # type: Any + +class FlowMappingStartToken(Token): + id = ... # type: Any + +class FlowSequenceEndToken(Token): + id = ... # type: Any + +class FlowMappingEndToken(Token): + id = ... # type: Any + +class KeyToken(Token): + id = ... # type: Any + +class ValueToken(Token): + id = ... # type: Any + +class BlockEntryToken(Token): + id = ... # type: Any + +class FlowEntryToken(Token): + id = ... # type: Any + +class AliasToken(Token): + id = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, value, start_mark, end_mark) -> None: ... + +class AnchorToken(Token): + id = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, value, start_mark, end_mark) -> None: ... + +class TagToken(Token): + id = ... # type: Any + value = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + def __init__(self, value, start_mark, end_mark) -> None: ... + +class ScalarToken(Token): + id = ... # type: Any + value = ... # type: Any + plain = ... # type: Any + start_mark = ... # type: Any + end_mark = ... # type: Any + style = ... # type: Any + def __init__(self, value, plain, start_mark, end_mark, style=...) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/__init__.pyi new file mode 100644 index 000000000..eb1ae458f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/__init__.pyi @@ -0,0 +1 @@ +... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/examples.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/examples.pyi new file mode 100644 index 000000000..0abfc7b45 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/examples.pyi @@ -0,0 +1,3 @@ +from typing import Any + +html_parts = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/nodes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/nodes.pyi new file mode 100644 index 000000000..f747fb108 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/nodes.pyi @@ -0,0 +1,8 @@ +from typing import Any, List + +class reference: + def __init__(self, + rawsource: str = ..., + text: str = ..., + *children: List[Any], + **attributes) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/__init__.pyi new file mode 100644 index 000000000..eb1ae458f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/__init__.pyi @@ -0,0 +1 @@ +... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/nodes.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/nodes.pyi new file mode 100644 index 000000000..eb1ae458f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/nodes.pyi @@ -0,0 +1 @@ +... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/roles.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/roles.pyi new file mode 100644 index 000000000..7307e587b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/roles.pyi @@ -0,0 +1,10 @@ +import docutils.nodes +import docutils.parsers.rst.states + +from typing import Callable, Any, List, Dict, Tuple + +def register_local_role(name: str, + role_fn: Callable[[str, str, str, int, docutils.parsers.rst.states.Inliner, Dict, List], + Tuple[List[docutils.nodes.reference], List[docutils.nodes.reference]]] + ) -> None: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/states.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/states.pyi new file mode 100644 index 000000000..e39d2bcf6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/docutils/parsers/rst/states.pyi @@ -0,0 +1,5 @@ +import typing + +class Inliner: + def __init__(self) -> None: + ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/enum.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/enum.pyi new file mode 100644 index 000000000..6ca467b27 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/enum.pyi @@ -0,0 +1,65 @@ +# NB: third_party/3/enum.pyi and stdlib/3.4/enum.pyi must remain consistent! +import sys +from typing import Any, Iterator, List, Mapping, Type, TypeVar, Union +from abc import ABCMeta + +_T = TypeVar('_T') +_S = TypeVar('_S', bound=Type[Enum]) + +# Note: EnumMeta actually subclasses type directly, not ABCMeta. +# This is a temporary workaround to allow multiple creation of enums with builtins +# such as str as mixins, which due to the handling of ABCs of builtin types, cause +# spurious inconsistent metaclass structure. See #1595. +# Structurally: Iterable[T], Reversible[T], Container[T] where T is the enum itself +class EnumMeta(ABCMeta): + def __iter__(self: Type[_T]) -> Iterator[_T]: ... + def __reversed__(self: Type[_T]) -> Iterator[_T]: ... + def __contains__(self: Type[_T], member: Any) -> bool: ... + def __getitem__(self: Type[_T], name: str) -> _T: ... + @property + def __members__(self: Type[_T]) -> Mapping[str, _T]: ... + def __len__(self) -> int: ... + +class Enum(metaclass=EnumMeta): + def __new__(cls: Type[_T], value: Any) -> _T: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __dir__(self) -> List[str]: ... + def __format__(self, format_spec: str) -> str: ... + def __hash__(self) -> Any: ... + def __reduce_ex__(self, proto: Any) -> Any: ... + + name = ... # type: str + value = ... # type: Any + +class IntEnum(int, Enum): + value = ... # type: int + +def unique(enumeration: _S) -> _S: ... + +if sys.version_info >= (3, 6): + _auto_null = ... # type: Any + + # subclassing IntFlag so it picks up all implemented base functions, best modeling behavior of enum.auto() + class auto(IntFlag): + value = ... # type: Any + + class Flag(Enum): + def __contains__(self: _T, other: _T) -> bool: ... + def __repr__(self) -> str: ... + def __str__(self) -> str: ... + def __bool__(self) -> bool: ... + def __or__(self: _T, other: _T) -> _T: ... + def __and__(self: _T, other: _T) -> _T: ... + def __xor__(self: _T, other: _T) -> _T: ... + def __invert__(self: _T) -> _T: ... + + # The `type: ignore` comment is needed because mypy considers the type + # signatures of several methods defined in int and Flag to be incompatible. + class IntFlag(int, Flag): # type: ignore + def __or__(self: _T, other: Union[int, _T]) -> _T: ... + def __and__(self: _T, other: Union[int, _T]) -> _T: ... + def __xor__(self: _T, other: Union[int, _T]) -> _T: ... + __ror__ = __or__ + __rand__ = __and__ + __rxor__ = __xor__ diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/itsdangerous.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/itsdangerous.pyi new file mode 100644 index 000000000..96d7ccfee --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/itsdangerous.pyi @@ -0,0 +1,153 @@ +from datetime import datetime +from typing import Any, Callable, IO, MutableMapping, Optional, Text, Tuple, TypeVar, Union + +PY2: bool +text_type = str +int_to_byte = Callable[[int], bytes] +number_types = (int, float) +izip = zip + +_bytes_like = Union[bytearray, bytes] +_str_like = Union[str, bytes] +_can_become_bytes = Union[str, bytes, bytearray] +_comparable_bytes = TypeVar('_comparable_bytes', str, _bytes_like) +_serializer = Any # must be an object that has "dumps" and "loads" attributes (e.g. the json module) + +class _CompactJSON: + def loads(self, payload: Text) -> Any: ... + def dumps(self, obj: Any) -> Text: ... + +compact_json = _CompactJSON +EPOCH = ... # type: int + +def want_bytes(s: _can_become_bytes, encoding: str = ..., errors: str = ...) -> bytes: ... +def is_text_serializer(serializer: _serializer) -> bool: ... +def constant_time_compare(val1: _comparable_bytes, val2: _comparable_bytes) -> bool: ... + +class BadData(Exception): + message = ... # type: str + def __init__(self, message: str) -> None: ... + +class BadPayload(BadData): + original_error = ... # type: Optional[Exception] + def __init__(self, message: str, original_error: Optional[Exception] = ...) -> None: ... + +class BadSignature(BadData): + payload = ... # type: Optional[Any] + def __init__(self, message: str, payload: Optional[Any] = ...) -> None: ... + +class BadTimeSignature(BadSignature): + date_signed = ... # type: Optional[int] + def __init__(self, message: str, payload: Optional[Any] = ..., date_signed: Optional[int] = ...) -> None: ... + +class BadHeader(BadSignature): + header = ... # type: Any + original_error = ... # type: Any + def __init__(self, message, payload=None, header=None, original_error=None) -> None: ... + +class SignatureExpired(BadTimeSignature): ... + +def base64_encode(string: _can_become_bytes) -> bytes: ... +def base64_decode(string: _can_become_bytes) -> bytes: ... +def int_to_bytes(num: int) -> bytes: ... +def bytes_to_int(bytestr: _can_become_bytes) -> bytes: ... + +class SigningAlgorithm: + def get_signature(self, key: _bytes_like, value: _bytes_like) -> bytes: ... + def verify_signature(self, key: _bytes_like, value: _bytes_like, sig: _can_become_bytes) -> bool: ... + +class NoneAlgorithm(SigningAlgorithm): + def get_signature(self, key: _bytes_like, value: _bytes_like) -> bytes: ... + +class HMACAlgorithm(SigningAlgorithm): + default_digest_method = ... # type: Callable + digest_method = ... # type: Callable + def __init__(self, digest_method: Optional[Callable] = ...) -> None: ... + def get_signature(self, key: _bytes_like, value: _bytes_like) -> bytes: ... + +class Signer: + default_digest_method = ... # type: Callable + default_key_derivation = ... # type: str + secret_key = ... # type: _can_become_bytes + sep = ... # type: _can_become_bytes + salt = ... # type: _can_become_bytes + key_derivation = ... # type: str + digest_method = ... # type: Callable + algorithm = ... # type: SigningAlgorithm + def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., sep: Optional[_can_become_bytes] = ..., + key_derivation: Optional[str] = ..., + digest_method: Optional[Callable] = ..., + algorithm: Optional[SigningAlgorithm] = ...) -> None: ... + def derive_key(self) -> bytes: ... + def get_signature(self, value: _bytes_like) -> bytes: ... + def sign(self, value: _bytes_like) -> bytes: ... + def verify_signature(self, value: _bytes_like, sig: _can_become_bytes) -> bool: ... + def unsign(self, signed_value: _bytes_like) -> bytes: ... + def validate(self, signed_value: _can_become_bytes) -> bool: ... + +class TimestampSigner(Signer): + def get_timestamp(self) -> int: ... + def timestamp_to_datetime(self, ts: int) -> datetime: ... + def sign(self, value: _bytes_like) -> bytes: ... + def unsign(self, value: _can_become_bytes, max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ... + def validate(self, signed_value: _can_become_bytes, max_age: Optional[int] = ...) -> bool: ... + +class Serializer: + default_serializer = ... # type: _serializer + default_signer = ... # type: Callable[..., Signer] + secret_key = ... # type: Any + salt = ... # type: _can_become_bytes + serializer = ... # type: _serializer + is_text_serializer = ... # type: bool + signer = ... # type: Signer + signer_kwargs = ... # type: MutableMapping + def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ...) -> None: ... + def load_payload(self, payload: Any, serializer: Optional[_serializer] = ...) -> Any: ... + def dump_payload(self, *args, **kwargs) -> bytes: ... + def make_signer(self, salt: Optional[_can_become_bytes] = ...) -> Signer: ... + def dumps(self, obj: Any, salt: Optional[_can_become_bytes] = ...) -> _str_like: ... + def dump(self, obj: Any, f: IO, salt: Optional[_can_become_bytes] = ...) -> None: ... + def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ...) -> Any: ... + def load(self, f: IO, salt: Optional[_can_become_bytes] = ...): ... + def loads_unsafe(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ...) -> Tuple[bool, Any]: ... + def load_unsafe(self, f: IO, *args, **kwargs) -> Tuple[bool, Any]: ... + +class TimedSerializer(Serializer): + default_signer = ... # type: Callable[..., TimestampSigner] + def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., max_age: Optional[int] = ..., return_timestamp: bool = ...) -> Any: ... + def loads_unsafe(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., max_age: Optional[int] = ...) -> Tuple[bool, Any]: ... + +class JSONWebSignatureSerializer(Serializer): + jws_algorithms = ... # type: MutableMapping[str, SigningAlgorithm] + default_algorithm = ... # type: str + default_serializer = ... # type: Any + algorithm_name = ... # type: str + algorithm = ... # type: Any + def __init__(self, secret_key: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., serializer: Optional[_serializer] = ..., signer: Optional[Callable[..., Signer]] = ..., signer_kwargs: Optional[MutableMapping] = ..., algorithm_name: Optional[str] = ...) -> None: ... + def load_payload(self, payload: Any, serializer: Optional[_serializer] = ..., return_header: bool = ...) -> Any: ... + def dump_payload(self, *args, **kwargs) -> bytes: ... + def make_algorithm(self, algorithm_name: str) -> SigningAlgorithm: ... + def make_signer(self, salt: Optional[_can_become_bytes] = ..., algorithm_name: Optional[str] = ...) -> Signer: ... + def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ... + def dumps(self, obj: Any, salt: Optional[_can_become_bytes] = ..., header_fields: Optional[MutableMapping]=...) -> str: ... + def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., return_header: bool = ...) -> Any: ... + def loads_unsafe(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., return_header: bool = ...) -> Tuple[bool, Any]: ... + +class TimedJSONWebSignatureSerializer(JSONWebSignatureSerializer): + DEFAULT_EXPIRES_IN = ... # type: int + expires_in = ... # type: int + def __init__(self, secret_key: _can_become_bytes, expires_in: Optional[int] = ..., **kwargs) -> None: ... + def make_header(self, header_fields=Optional[MutableMapping]) -> MutableMapping: ... + def loads(self, s: _can_become_bytes, salt: Optional[_can_become_bytes] = ..., return_header: bool = ...) -> Any: ... + def get_issue_date(self, header: MutableMapping) -> Optional[datetime]: ... + def now(self) -> int: ... + +class URLSafeSerializerMixin: + def load_payload(self, payload: Any, serializer: Any = ..., **kwargs) -> Any: ... + def dump_payload(self, *args, **kwargs) -> bytes: ... + +class URLSafeSerializer(URLSafeSerializerMixin, Serializer): + default_serializer = ... # type: Any + +class URLSafeTimedSerializer(URLSafeSerializerMixin, TimedSerializer): + default_serializer = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/__init__.pyi new file mode 100644 index 000000000..3fca1103b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/__init__.pyi @@ -0,0 +1,41 @@ +from typing import Mapping, Any, Optional, Union + +from . import algorithms + +def decode(jwt: Union[str, bytes], key: Union[str, bytes] = ..., + verify: bool = ..., algorithms: Optional[Any] = ..., + options: Optional[Mapping[Any, Any]] = ..., + **kwargs: Any) -> Mapping[str, Any]: ... + +def encode(payload: Mapping[str, Any], key: Union[str, bytes], + algorithm: str = ..., headers: Optional[Mapping[str, Any]] = ..., + json_encoder: Optional[Any] = ...) -> bytes: ... + +def register_algorithm(alg_id: str, + alg_obj: algorithms.Algorithm) -> None: ... + +def unregister_algorithm(alg_id: str) -> None: ... + +class InvalidTokenError(Exception): ... +class DecodeError(InvalidTokenError): ... +class ExpiredSignatureError(InvalidTokenError): ... +class InvalidAudienceError(InvalidTokenError): ... +class InvalidIssuerError(InvalidTokenError): ... +class InvalidIssuedAtError(InvalidTokenError): ... +class ImmatureSignatureError(InvalidTokenError): ... +class InvalidKeyError(Exception): ... +class InvalidAlgorithmError(InvalidTokenError): ... +class MissingRequiredClaimError(InvalidTokenError): ... + +# Compatibility aliases (deprecated) +ExpiredSignature = ExpiredSignatureError +InvalidAudience = InvalidAudienceError +InvalidIssuer = InvalidIssuerError + +# These aren't actually documented, but the package +# exports them in __init__.py, so we should at least +# make sure that mypy doesn't raise spurious errors +# if they're used. +get_unverified_header = ... # type: Any +PyJWT = ... # type: Any +PyJWS = ... # type: Any diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/algorithms.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/algorithms.pyi new file mode 100644 index 000000000..4576b4169 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/algorithms.pyi @@ -0,0 +1,3 @@ +from typing import Any + +class Algorithm(Any): ... # type: ignore diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/__init__.pyi new file mode 100644 index 000000000..b2bb1f643 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/__init__.pyi @@ -0,0 +1 @@ +from hashlib import _Hash as _HashAlg diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi new file mode 100644 index 000000000..cd2926f42 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/py_ecdsa.pyi @@ -0,0 +1,10 @@ +from typing import Any +from jwt.algorithms import Algorithm + +from . import _HashAlg + +class ECAlgorithm(Algorithm): + SHA256 = ... # type: _HashAlg + SHA384 = ... # type: _HashAlg + SHA512 = ... # type: _HashAlg + def __init__(self, hash_alg: _HashAlg) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/pycrypto.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/pycrypto.pyi new file mode 100644 index 000000000..08ae8ba2d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/jwt/contrib/algorithms/pycrypto.pyi @@ -0,0 +1,10 @@ +from typing import Any +from jwt.algorithms import Algorithm + +from . import _HashAlg + +class RSAAlgorithm(Algorithm): + SHA256 = ... # type: _HashAlg + SHA384 = ... # type: _HashAlg + SHA512 = ... # type: _HashAlg + def __init__(self, hash_alg: _HashAlg) -> None: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/pkg_resources.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/pkg_resources.pyi new file mode 100644 index 000000000..f0e1163ff --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/pkg_resources.pyi @@ -0,0 +1,310 @@ +# Stubs for pkg_resources (Python 3.4) + +from typing import ( + Any, Callable, Dict, IO, Iterable, Generator, Optional, Sequence, Tuple, + List, Union, + TypeVar, overload, +) +from abc import ABCMeta +import importlib.abc +import types +import zipimport + +_T = TypeVar('_T') +_NestedStr = Union[str, Iterable[Union[str, Iterable[Any]]]] +_InstallerType = Callable[[Requirement], Optional[Distribution]] +_EPDistType = Union[Distribution, Requirement, str] +_MetadataType = Optional[IResourceProvider] +_PkgReqType = Union[str, Requirement] +_DistFinderType = Callable[[str, _Importer, bool], + Generator[Distribution, None, None]] +_NSHandlerType = Callable[[_Importer, str, str, types.ModuleType], str] + +def declare_namespace(name: str) -> None: ... +def fixup_namespace_packages(path_item: str) -> None: ... + + +class WorkingSet: + entries = ... # type: List[str] + def __init__(self, entries: Optional[Iterable[str]] = ...) -> None: ... + def require(self, *requirements: _NestedStr) -> Sequence[Distribution]: ... + def run_script(self, requires: str, script_name: str) -> None: ... + def iter_entry_points(self, group: str, name: Optional[str] = ...) \ + -> Generator[EntryPoint, None, None]: ... + def add_entry(self, entry: str) -> None: ... + def __contains__(self, dist: Distribution) -> bool: ... + def __iter__(self) -> Generator[Distribution, None, None]: ... + def find(self, req: Requirement) -> Optional[Distribution]: ... + def resolve(self, requirements: Sequence[Requirement], + env: Optional[Environment] = ..., + installer: Optional[_InstallerType] = ...) \ + -> List[Distribution]: ... + def add(self, dist: Distribution, entry: Optional[str] = ..., + insert: bool = ..., replace: bool = ...) -> None: ... + def subscribe(self, callback: Callable[[Distribution], None]) -> None: ... + def find_plugins(self, plugin_env: Environment, + full_env: Optional[Environment] = ..., + fallback: bool = ...) \ + -> Tuple[List[Distribution], + Dict[Distribution, Exception]]: ... + +working_set = ... # type: WorkingSet + +def require( + *requirements: Union[str, Sequence[str]] +) -> Sequence[Distribution]: ... +def run_script(requires: str, script_name: str) -> None: ... +def iter_entry_points( + group: str, name: Optional[str] = ... +) -> Generator[EntryPoint, None, None]: ... +def add_activation_listener( + callback: Callable[[Distribution], None] +) -> None: ... + + +class Environment: + def __init__(self, search_path: Optional[Sequence[str]] = ..., + platform: Optional[str] = ..., + python: Optional[str] = ...) -> None: ... + def __getitem__(self, project_name: str) -> List[Distribution]: ... + def __iter__(self) -> Generator[str, None, None]: ... + def add(self, dist: Distribution) -> None: ... + def remove(self, dist: Distribution) -> None: ... + def can_add(self, dist: Distribution) -> bool: ... + def __add__(self, + other: Union[Distribution, Environment]) -> Environment: ... + def __iadd__(self, + other: Union[Distribution, Environment]) -> Environment: ... + @overload + def best_match(self, req: Requirement, working_set: WorkingSet) -> Distribution: ... + @overload + def best_match(self, req: Requirement, working_set: WorkingSet, + installer: Callable[[Requirement], _T] = ...) -> _T: ... + @overload + def obtain(self, requirement: Requirement) -> None: ... + @overload + def obtain(self, requirement: Requirement, + installer: Callable[[Requirement], _T] = ...) -> _T: ... + def scan(self, search_path: Optional[Sequence[str]] = ...) -> None: ... + + +def parse_requirements(strs: Union[str, Iterable[str]]) -> Generator[Requirement, None, None]: ... + +class Requirement: + project_name = ... # type: str + key = ... # type: str + extras = ... # type: Tuple[str, ...] + specs = ... # type: List[Tuple[str, str]] + @staticmethod + def parse(s: Union[str, Iterable[str]]) -> Requirement: ... + def __contains__(self, + item: Union[Distribution, str, Tuple[str, ...]]) \ + -> bool: ... + def __eq__(self, other_requirement: Any) -> bool: ... + +def load_entry_point(dist: _EPDistType, group: str, name: str) -> None: ... +def get_entry_info(dist: _EPDistType, group: str, + name: str) -> Optional[EntryPoint]: ... +@overload +def get_entry_map(dist: _EPDistType) -> Dict[str, Dict[str, EntryPoint]]: ... +@overload +def get_entry_map(dist: _EPDistType, group: str) -> Dict[str, EntryPoint]: ... + +class EntryPoint: + name = ... # type: str + module_name = ... # type: str + attrs = ... # type: Tuple[str, ...] + extras = ... # type: Tuple[str, ...] + dist = ... # type: Optional[Distribution] + def __init__(self, name: str, module_name: str, + attrs: Tuple[str, ...] = ..., extras: Tuple[str, ...] = ..., + dist: Optional[Distribution] = ...) -> None: ... + @classmethod + def parse(cls, src: str, dist: Optional[Distribution] = ...) -> EntryPoint: ... + @classmethod + def parse_group(cls, group: str, lines: Union[str, Sequence[str]], + dist: Optional[Distribution] = ...) -> Dict[str, EntryPoint]: ... + @classmethod + def parse_map(cls, data: Union[Dict[str, Union[str, Sequence[str]]], + str, Sequence[str]], + dist: Optional[Distribution] = ...) -> Dict[str, EntryPoint]: ... + def load(self, require: bool = ..., env: Optional[Environment] = ..., + installer: Optional[_InstallerType] = ...) -> Any: ... + def require(self, env: Optional[Environment] = ..., + installer: Optional[_InstallerType] = ...) -> None: ... + + +def find_distributions( + path_item: str, only: bool = ... +) -> Generator[Distribution, None, None]: ... +def get_distribution(dist: Union[Requirement, str, Distribution]) -> Distribution: ... + +class Distribution(IResourceProvider, IMetadataProvider): + location = ... # type: str + project_name = ... # type: str + key = ... # type: str + extras = ... # type: List[str] + version = ... # type: str + parsed_version = ... # type: Tuple[str, ...] + py_version = ... # type: str + platform = ... # type: Optional[str] + precedence = ... # type: int + def __init__(self, location: Optional[str] = ..., + metadata: Optional[str] = ..., + project_name: Optional[str] = ..., + version: Optional[str] = ..., py_version: str = ..., + platform: Optional[str] = ..., + precedence: int = ...) -> None: ... + @classmethod + def from_location(cls, location: str, basename: str, + metadata: Optional[str] = ..., + **kw: Union[str, None, int]) -> Distribution: ... + @classmethod + def from_filename(cls, filename: str, metadata: Optional[str] = ..., + **kw: Union[str, None, int]) -> Distribution: ... + def activate(self, path: Optional[List[str]] = ...) -> None: ... + def as_requirement(self) -> Requirement: ... + def requires(self, extras: Tuple[str, ...] = ...) -> List[Requirement]: ... + def clone(self, **kw: Union[str, int, None]) -> Requirement: ... + def egg_name(self) -> str: ... + def __cmp__(self, other: Any) -> bool: ... + def get_entry_info(dist: _EPDistType, group: str, + name: str) -> Optional[EntryPoint]: ... + @overload + def get_entry_map(dist: _EPDistType) \ + -> Dict[str, Dict[str, EntryPoint]]: ... + @overload + def get_entry_map(dist: _EPDistType, group: str) \ + -> Dict[str, EntryPoint]: ... + def load_entry_point(dist: _EPDistType, group: str, name: str) -> None: ... + +EGG_DIST = ... # type: int +BINARY_DIST = ... # type: int +SOURCE_DIST = ... # type: int +CHECKOUT_DIST = ... # type: int +DEVELOP_DIST = ... # type: int + + +def resource_exists(package_or_requirement: _PkgReqType, + resource_name: str) -> bool: ... +def resource_stream(package_or_requirement: _PkgReqType, + resource_name: str) -> IO[bytes]: ... +def resource_string(package_or_requirement: _PkgReqType, + resource_name: str) -> bytes: ... +def resource_isdir(package_or_requirement: _PkgReqType, + resource_name: str) -> bool: ... +def resource_listdir(package_or_requirement: _PkgReqType, + resource_name: str) -> List[str]: ... + +def resource_filename(package_or_requirement: _PkgReqType, + resource_name: str) -> str: ... +def set_extraction_path(path: str) -> None: ... +def cleanup_resources(force: bool = ...) -> List[str]: ... + +class IResourceManager: + def resource_exists(self, package_or_requirement: _PkgReqType, + resource_name: str) -> bool: ... + def resource_stream(self, package_or_requirement: _PkgReqType, + resource_name: str) -> IO[bytes]: ... + def resource_string(self, package_or_requirement: _PkgReqType, + resource_name: str) -> bytes: ... + def resource_isdir(self, package_or_requirement: _PkgReqType, + resource_name: str) -> bool: ... + def resource_listdir(self, package_or_requirement: _PkgReqType, + resource_name: str) -> List[str]: ... + def resource_filename(self, package_or_requirement: _PkgReqType, + resource_name: str) -> str: ... + def set_extraction_path(self, path: str) -> None: ... + def cleanup_resources(self, force: bool = ...) -> List[str]: ... + def get_cache_path(self, archive_name: str, + names: Tuple[str, ...] = ...) -> str: ... + def extraction_error(self) -> None: ... + def postprocess(self, tempname: str, filename: str) -> None: ... + + +@overload +def get_provider(package_or_requirement: str) -> IResourceProvider: ... +@overload +def get_provider(package_or_requirement: Requirement) -> Distribution: ... + +class IMetadataProvider: + def has_metadata(self, name: str) -> bool: ... + def metadata_isdir(self, name: str) -> bool: ... + def metadata_listdir(self, name: str) -> List[str]: ... + def get_metadata(self, name: str) -> str: ... + def get_metadata_lines(self, name: str) -> Generator[List[str], None, None]: ... + def run_script(self, script_name: str, namespace: Dict[str, Any]) -> None: ... + + +class ResolutionError(Exception): ... +class DistributionNotFound(ResolutionError): ... +class VersionConflict(ResolutionError): ... +class UnknownExtra(ResolutionError): ... + +class ExtractionError(Exception): + manager = ... # type: IResourceManager + cache_path = ... # type: str + original_error = ... # type: Exception + + +class _Importer(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader, metaclass=ABCMeta): ... + +def register_finder(importer_type: type, + distribution_finder: _DistFinderType) -> None: ... +def register_loader_type( + loader_type: type, + provider_factory: Callable[[types.ModuleType], IResourceProvider] +) -> None: ... +def register_namespace_handler(importer_type: type, + namespace_handler: _NSHandlerType) -> None: ... + + +class IResourceProvider(IMetadataProvider): ... + + +class NullProvider: ... + +class EggProvider(NullProvider): ... + +class DefaultProvider(EggProvider): ... + +class PathMetadata(DefaultProvider, IResourceProvider): + def __init__(self, path: str, egg_info: str) -> None: ... + +class ZipProvider(EggProvider): ... + +class EggMetadata(ZipProvider, IResourceProvider): + def __init__(self, zipimporter: zipimport.zipimporter) -> None: ... + +class EmptyProvider(NullProvider): ... + +empty_provider = ... # type: EmptyProvider + +class FileMetadata(EmptyProvider, IResourceProvider): + def __init__(self, path_to_pkg_info: str) -> None: ... + + +def parse_version(v: str) -> Tuple[str, ...]: ... +def yield_lines(strs: _NestedStr) -> Generator[str, None, None]: ... +def split_sections( + strs: _NestedStr +) -> Generator[Tuple[Optional[str], str], None, None]: ... +def safe_name(name: str) -> str: ... +def safe_version(version: str) -> str: ... +def safe_extra(extra: str) -> str: ... +def to_filename(name_or_version: str) -> str: ... + + +def get_build_platform() -> str: ... +def get_platform() -> str: ... +def get_supported_platform() -> str: ... +def compatible_platforms(provided: Optional[str], + required: Optional[str]) -> bool: ... +def get_default_cache() -> str: ... + + +def get_importer(path_item: str) -> _Importer: ... + + +def ensure_directory(path: str) -> None: ... +def normalize_path(filename: str) -> str: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/__init__.pyi new file mode 100644 index 000000000..4eedd5b40 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/__init__.pyi @@ -0,0 +1,104 @@ +# Stubs for six (Python 3.5) + +from __future__ import print_function + +from typing import ( + Any, + AnyStr, + Callable, + Dict, + ItemsView, + Iterable, + KeysView, + Mapping, + NoReturn, + Optional, + Pattern, + Tuple, + Type, + TypeVar, + Union, + ValuesView, + overload, +) +import types +import typing +import unittest + +# Exports +from io import StringIO as StringIO, BytesIO as BytesIO +from builtins import next as next +from functools import wraps as wraps +from . import moves + +_T = TypeVar('_T') +_K = TypeVar('_K') +_V = TypeVar('_V') + +# TODO make constant, then move this stub to 2and3 +# https://github.com/python/typeshed/issues/17 +PY2 = False +PY3 = True +PY34 = ... # type: bool + +string_types = str, +integer_types = int, +class_types = type, +text_type = str +binary_type = bytes + +MAXSIZE = ... # type: int + +# def add_move +# def remove_move + +def callable(obj: object) -> bool: ... + +def get_unbound_function(unbound: types.FunctionType) -> types.FunctionType: ... +def create_bound_method(func: types.FunctionType, obj: object) -> types.MethodType: ... +def create_unbound_method(func: types.FunctionType, cls: type) -> types.FunctionType: ... + +Iterator = object + +def get_method_function(meth: types.MethodType) -> types.FunctionType: ... +def get_method_self(meth: types.MethodType) -> Optional[object]: ... +def get_function_closure(fun: types.FunctionType) -> Optional[Tuple[types._Cell, ...]]: ... +def get_function_code(fun: types.FunctionType) -> types.CodeType: ... +def get_function_defaults(fun: types.FunctionType) -> Optional[Tuple[Any, ...]]: ... +def get_function_globals(fun: types.FunctionType) -> Dict[str, Any]: ... + +def iterkeys(d: Mapping[_K, _V]) -> typing.Iterator[_K]: ... +def itervalues(d: Mapping[_K, _V]) -> typing.Iterator[_V]: ... +def iteritems(d: Mapping[_K, _V]) -> typing.Iterator[Tuple[_K, _V]]: ... +# def iterlists + +def viewkeys(d: Mapping[_K, _V]) -> KeysView[_K]: ... +def viewvalues(d: Mapping[_K, _V]) -> ValuesView[_V]: ... +def viewitems(d: Mapping[_K, _V]) -> ItemsView[_K, _V]: ... + +def b(s: str) -> binary_type: ... +def u(s: str) -> text_type: ... + +unichr = chr +def int2byte(i: int) -> bytes: ... +def byte2int(bs: binary_type) -> int: ... +def indexbytes(buf: binary_type, i: int) -> int: ... +def iterbytes(buf: binary_type) -> typing.Iterator[int]: ... + +def assertCountEqual(self: unittest.TestCase, first: Iterable[_T], second: Iterable[_T], msg: Optional[str] = ...) -> None: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, msg: Optional[str] = ...) -> Any: ... +@overload +def assertRaisesRegex(self: unittest.TestCase, callable_obj: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... +def assertRegex(self: unittest.TestCase, text: AnyStr, expected_regex: Union[AnyStr, Pattern[AnyStr]], msg: Optional[str] = ...) -> None: ... + +exec_ = exec + +def reraise(tp: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[types.TracebackType] = ...) -> NoReturn: ... +def raise_from(value: BaseException, from_value: Optional[BaseException]) -> NoReturn: ... + +print_ = print + +def with_metaclass(meta: type, *bases: type) -> type: ... +def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ... +def python_2_unicode_compatible(klass: _T) -> _T: ... diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/BaseHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/BaseHTTPServer.pyi new file mode 100644 index 000000000..0e1ad7131 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/BaseHTTPServer.pyi @@ -0,0 +1 @@ +from http.server import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/CGIHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/CGIHTTPServer.pyi new file mode 100644 index 000000000..0e1ad7131 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/CGIHTTPServer.pyi @@ -0,0 +1 @@ +from http.server import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/SimpleHTTPServer.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/SimpleHTTPServer.pyi new file mode 100644 index 000000000..0e1ad7131 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/SimpleHTTPServer.pyi @@ -0,0 +1 @@ +from http.server import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/__init__.pyi new file mode 100644 index 000000000..3d6efced3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/__init__.pyi @@ -0,0 +1,69 @@ +# Stubs for six.moves +# +# Note: Commented out items means they weren't implemented at the time. +# Uncomment them when the modules have been added to the typeshed. +import sys + +from io import StringIO as cStringIO +from builtins import filter as filter +from itertools import filterfalse as filterfalse +from builtins import input as input +from sys import intern as intern +from builtins import map as map +from os import getcwd as getcwd +from os import getcwdb as getcwdb +from builtins import range as range +from functools import reduce as reduce +from shlex import quote as shlex_quote +from io import StringIO as StringIO +from collections import UserDict as UserDict +from collections import UserList as UserList +from collections import UserString as UserString +from builtins import range as xrange +from builtins import zip as zip +from itertools import zip_longest as zip_longest +from . import builtins +from . import configparser +# import copyreg as copyreg +# import dbm.gnu as dbm_gnu +from . import _dummy_thread +from . import http_cookiejar +from . import http_cookies +from . import html_entities +from . import html_parser +from . import http_client +from . import email_mime_multipart +from . import email_mime_nonmultipart +from . import email_mime_text +from . import email_mime_base +from . import BaseHTTPServer +from . import CGIHTTPServer +from . import SimpleHTTPServer +from . import cPickle +from . import queue +from . import reprlib +from . import socketserver +from . import _thread +from . import tkinter +from . import tkinter_dialog +from . import tkinter_filedialog +# import tkinter.scrolledtext as tkinter_scrolledtext +# import tkinter.simpledialog as tkinter_simpledialog +# import tkinter.tix as tkinter_tix +from . import tkinter_ttk +from . import tkinter_constants +# import tkinter.dnd as tkinter_dnd +# import tkinter.colorchooser as tkinter_colorchooser +from . import tkinter_commondialog +from . import tkinter_tkfiledialog +# import tkinter.font as tkinter_font +# import tkinter.messagebox as tkinter_messagebox +# import tkinter.simpledialog as tkinter_tksimpledialog +from . import urllib_parse +from . import urllib_error +from . import urllib +from . import urllib_robotparser +# import xmlrpc.client as xmlrpc_client +# import xmlrpc.server as xmlrpc_server + +from importlib import reload as reload_module diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/_dummy_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/_dummy_thread.pyi new file mode 100644 index 000000000..24879612a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/_dummy_thread.pyi @@ -0,0 +1 @@ +from _dummy_thread import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/_thread.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/_thread.pyi new file mode 100644 index 000000000..25952a614 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/_thread.pyi @@ -0,0 +1 @@ +from _thread import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/builtins.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/builtins.pyi new file mode 100644 index 000000000..9596ba032 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/builtins.pyi @@ -0,0 +1 @@ +from builtins import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/cPickle.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/cPickle.pyi new file mode 100644 index 000000000..2b944b59d --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/cPickle.pyi @@ -0,0 +1 @@ +from pickle import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/configparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/configparser.pyi new file mode 100644 index 000000000..044861ce0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/configparser.pyi @@ -0,0 +1 @@ +from configparser import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_base.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_base.pyi new file mode 100644 index 000000000..4df155c93 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_base.pyi @@ -0,0 +1 @@ +from email.mime.base import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_multipart.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_multipart.pyi new file mode 100644 index 000000000..4f312412b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_multipart.pyi @@ -0,0 +1 @@ +from email.mime.multipart import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_nonmultipart.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_nonmultipart.pyi new file mode 100644 index 000000000..c15c8c044 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_nonmultipart.pyi @@ -0,0 +1 @@ +from email.mime.nonmultipart import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_text.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_text.pyi new file mode 100644 index 000000000..51e147387 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/email_mime_text.pyi @@ -0,0 +1 @@ +from email.mime.text import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/html_entities.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/html_entities.pyi new file mode 100644 index 000000000..c1244ddbe --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/html_entities.pyi @@ -0,0 +1 @@ +from html.entities import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/html_parser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/html_parser.pyi new file mode 100644 index 000000000..6db6dd83f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/html_parser.pyi @@ -0,0 +1 @@ +from html.parser import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_client.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_client.pyi new file mode 100644 index 000000000..36d29b955 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_client.pyi @@ -0,0 +1 @@ +from http.client import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_cookiejar.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_cookiejar.pyi new file mode 100644 index 000000000..88a1aed6c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_cookiejar.pyi @@ -0,0 +1 @@ +from http.cookiejar import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_cookies.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_cookies.pyi new file mode 100644 index 000000000..9c59a5397 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/http_cookies.pyi @@ -0,0 +1 @@ +from http.cookies import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/queue.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/queue.pyi new file mode 100644 index 000000000..fe7be53a3 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/queue.pyi @@ -0,0 +1 @@ +from queue import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/reprlib.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/reprlib.pyi new file mode 100644 index 000000000..c329846fd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/reprlib.pyi @@ -0,0 +1 @@ +from reprlib import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/socketserver.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/socketserver.pyi new file mode 100644 index 000000000..6101c8bb0 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/socketserver.pyi @@ -0,0 +1 @@ +from socketserver import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter.pyi new file mode 100644 index 000000000..fc4d53a5a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter.pyi @@ -0,0 +1 @@ +from tkinter import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_commondialog.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_commondialog.pyi new file mode 100644 index 000000000..34eb41961 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_commondialog.pyi @@ -0,0 +1 @@ +from tkinter.commondialog import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_constants.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_constants.pyi new file mode 100644 index 000000000..3c04f6d84 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_constants.pyi @@ -0,0 +1 @@ +from tkinter.constants import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_dialog.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_dialog.pyi new file mode 100644 index 000000000..0da73c27a --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_dialog.pyi @@ -0,0 +1 @@ +from tkinter.dialog import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_filedialog.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_filedialog.pyi new file mode 100644 index 000000000..c4cc7c48b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_filedialog.pyi @@ -0,0 +1 @@ +from tkinter.filedialog import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_tkfiledialog.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_tkfiledialog.pyi new file mode 100644 index 000000000..c4cc7c48b --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_tkfiledialog.pyi @@ -0,0 +1 @@ +from tkinter.filedialog import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_ttk.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_ttk.pyi new file mode 100644 index 000000000..14576f61c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/tkinter_ttk.pyi @@ -0,0 +1 @@ +from tkinter.ttk import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/__init__.pyi new file mode 100644 index 000000000..d08209c51 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/__init__.pyi @@ -0,0 +1,5 @@ +import six.moves.urllib.error as error +import six.moves.urllib.parse as parse +import six.moves.urllib.request as request +import six.moves.urllib.response as response +import six.moves.urllib.robotparser as robotparser diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/error.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/error.pyi new file mode 100644 index 000000000..83f0d22d4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/error.pyi @@ -0,0 +1,3 @@ +from urllib.error import URLError as URLError +from urllib.error import HTTPError as HTTPError +from urllib.error import ContentTooShortError as ContentTooShortError diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/parse.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/parse.pyi new file mode 100644 index 000000000..8b4310a4e --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/parse.pyi @@ -0,0 +1,27 @@ +# Stubs for six.moves.urllib.parse +# +# Note: Commented out items means they weren't implemented at the time. +# Uncomment them when the modules have been added to the typeshed. +from urllib.parse import ParseResult as ParseResult +from urllib.parse import SplitResult as SplitResult +from urllib.parse import parse_qs as parse_qs +from urllib.parse import parse_qsl as parse_qsl +from urllib.parse import urldefrag as urldefrag +from urllib.parse import urljoin as urljoin +from urllib.parse import urlparse as urlparse +from urllib.parse import urlsplit as urlsplit +from urllib.parse import urlunparse as urlunparse +from urllib.parse import urlunsplit as urlunsplit +from urllib.parse import quote as quote +from urllib.parse import quote_plus as quote_plus +from urllib.parse import unquote as unquote +from urllib.parse import unquote_plus as unquote_plus +from urllib.parse import urlencode as urlencode +# from urllib.parse import splitquery as splitquery +# from urllib.parse import splittag as splittag +# from urllib.parse import splituser as splituser +from urllib.parse import uses_fragment as uses_fragment +from urllib.parse import uses_netloc as uses_netloc +from urllib.parse import uses_params as uses_params +from urllib.parse import uses_query as uses_query +from urllib.parse import uses_relative as uses_relative diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/request.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/request.pyi new file mode 100644 index 000000000..718a819cd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/request.pyi @@ -0,0 +1,37 @@ +# Stubs for six.moves.urllib.request +# +# Note: Commented out items means they weren't implemented at the time. +# Uncomment them when the modules have been added to the typeshed. +from urllib.request import urlopen as urlopen +from urllib.request import install_opener as install_opener +from urllib.request import build_opener as build_opener +from urllib.request import pathname2url as pathname2url +from urllib.request import url2pathname as url2pathname +from urllib.request import getproxies as getproxies +from urllib.request import Request as Request +from urllib.request import OpenerDirector as OpenerDirector +from urllib.request import HTTPDefaultErrorHandler as HTTPDefaultErrorHandler +from urllib.request import HTTPRedirectHandler as HTTPRedirectHandler +from urllib.request import HTTPCookieProcessor as HTTPCookieProcessor +from urllib.request import ProxyHandler as ProxyHandler +from urllib.request import BaseHandler as BaseHandler +from urllib.request import HTTPPasswordMgr as HTTPPasswordMgr +from urllib.request import HTTPPasswordMgrWithDefaultRealm as HTTPPasswordMgrWithDefaultRealm +from urllib.request import AbstractBasicAuthHandler as AbstractBasicAuthHandler +from urllib.request import HTTPBasicAuthHandler as HTTPBasicAuthHandler +from urllib.request import ProxyBasicAuthHandler as ProxyBasicAuthHandler +from urllib.request import AbstractDigestAuthHandler as AbstractDigestAuthHandler +from urllib.request import HTTPDigestAuthHandler as HTTPDigestAuthHandler +from urllib.request import ProxyDigestAuthHandler as ProxyDigestAuthHandler +from urllib.request import HTTPHandler as HTTPHandler +from urllib.request import HTTPSHandler as HTTPSHandler +from urllib.request import FileHandler as FileHandler +from urllib.request import FTPHandler as FTPHandler +from urllib.request import CacheFTPHandler as CacheFTPHandler +from urllib.request import UnknownHandler as UnknownHandler +from urllib.request import HTTPErrorProcessor as HTTPErrorProcessor +from urllib.request import urlretrieve as urlretrieve +from urllib.request import urlcleanup as urlcleanup +from urllib.request import URLopener as URLopener +from urllib.request import FancyURLopener as FancyURLopener +# from urllib.request import proxy_bypass as proxy_bypass diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/response.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/response.pyi new file mode 100644 index 000000000..9f681ea33 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/response.pyi @@ -0,0 +1,8 @@ +# Stubs for six.moves.urllib.response +# +# Note: Commented out items means they weren't implemented at the time. +# Uncomment them when the modules have been added to the typeshed. +# from urllib.response import addbase as addbase +# from urllib.response import addclosehook as addclosehook +# from urllib.response import addinfo as addinfo +from urllib.response import addinfourl as addinfourl diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/robotparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/robotparser.pyi new file mode 100644 index 000000000..bccda14b4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib/robotparser.pyi @@ -0,0 +1 @@ +from urllib.robotparser import RobotFileParser as RobotFileParser diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_error.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_error.pyi new file mode 100644 index 000000000..272007222 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_error.pyi @@ -0,0 +1 @@ +from urllib.error import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_parse.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_parse.pyi new file mode 100644 index 000000000..b557bbbb6 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_parse.pyi @@ -0,0 +1 @@ +from urllib.parse import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_robotparser.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_robotparser.pyi new file mode 100644 index 000000000..bbf5c3ce4 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/six/moves/urllib_robotparser.pyi @@ -0,0 +1 @@ +from urllib.robotparser import * diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/__init__.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/__init__.pyi new file mode 100644 index 000000000..f260032dd --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/__init__.pyi @@ -0,0 +1,2 @@ +# This module is a fork of the CPython 2 and 3 ast modules with PEP 484 support. +# See: https://github.com/python/typed_ast diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/ast27.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/ast27.pyi new file mode 100644 index 000000000..c4bf4f6b8 --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/ast27.pyi @@ -0,0 +1,360 @@ +import typing +from typing import Any, Optional, Union, Generic, Iterator + +class NodeVisitor(): + def visit(self, node: AST) -> Any: ... + def generic_visit(self, node: AST) -> None: ... + +class NodeTransformer(NodeVisitor): + def generic_visit(self, node: AST) -> None: ... + +def parse(source: Union[str, bytes], filename: Union[str, bytes] = ..., mode: str = ...) -> AST: ... +def copy_location(new_node: AST, old_node: AST) -> AST: ... +def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ... +def fix_missing_locations(node: AST) -> AST: ... +def get_docstring(node: AST, clean: bool = ...) -> Optional[bytes]: ... +def increment_lineno(node: AST, n: int = ...) -> AST: ... +def iter_child_nodes(node: AST) -> Iterator[AST]: ... +def iter_fields(node: AST) -> Iterator[typing.Tuple[str, Any]]: ... +def literal_eval(node_or_string: Union[str, AST]) -> Any: ... +def walk(node: AST) -> Iterator[AST]: ... + +PyCF_ONLY_AST = ... # type: int + +# ast classes + +identifier = str + +class AST: + _attributes = ... # type: typing.Tuple[str, ...] + _fields = ... # type: typing.Tuple[str, ...] + def __init__(self, *args, **kwargs) -> None: ... + +class mod(AST): + ... + +class Module(mod): + body = ... # type: typing.List[stmt] + type_ignores = ... # type: typing.List[TypeIgnore] + +class Interactive(mod): + body = ... # type: typing.List[stmt] + +class Expression(mod): + body = ... # type: expr + +class FunctionType(mod): + argtypes = ... # type: typing.List[expr] + returns = ... # type: expr + +class Suite(mod): + body = ... # type: typing.List[stmt] + + +class stmt(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class FunctionDef(stmt): + name = ... # type: identifier + args = ... # type: arguments + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + type_comment = ... # type: Optional[str] + +class ClassDef(stmt): + name = ... # type: identifier + bases = ... # type: typing.List[expr] + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + +class Return(stmt): + value = ... # type: Optional[expr] + +class Delete(stmt): + targets = ... # type: typing.List[expr] + +class Assign(stmt): + targets = ... # type: typing.List[expr] + value = ... # type: expr + type_comment = ... # type: Optional[str] + +class AugAssign(stmt): + target = ... # type: expr + op = ... # type: operator + value = ... # type: expr + +class Print(stmt): + dest = ... # type: Optional[expr] + values = ... # type: typing.List[expr] + nl = ... # type: bool + +class For(stmt): + target = ... # type: expr + iter = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + type_comment = ... # type: Optional[str] + +class While(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class If(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class With(stmt): + context_expr = ... # type: expr + optional_vars = ... # type: Optional[expr] + body = ... # type: typing.List[stmt] + type_comment = ... # type: Optional[str] + +class Raise(stmt): + type = ... # type: Optional[expr] + inst = ... # type: Optional[expr] + tback = ... # type: Optional[expr] + +class TryExcept(stmt): + body = ... # type: typing.List[stmt] + handlers = ... # type: typing.List[ExceptHandler] + orelse = ... # type: typing.List[stmt] + +class TryFinally(stmt): + body = ... # type: typing.List[stmt] + finalbody = ... # type: typing.List[stmt] + +class Assert(stmt): + test = ... # type: expr + msg = ... # type: Optional[expr] + +class Import(stmt): + names = ... # type: typing.List[alias] + +class ImportFrom(stmt): + module = ... # type: Optional[identifier] + names = ... # type: typing.List[alias] + level = ... # type: Optional[int] + +class Exec(stmt): + body = ... # type: expr + globals = ... # type: Optional[expr] + locals = ... # type: Optional[expr] + +class Global(stmt): + names = ... # type: typing.List[identifier] + +class Expr(stmt): + value = ... # type: expr + +class Pass(stmt): ... +class Break(stmt): ... +class Continue(stmt): ... + + +class slice(AST): + ... + +_slice = slice # this lets us type the variable named 'slice' below + +class Slice(slice): + lower = ... # type: Optional[expr] + upper = ... # type: Optional[expr] + step = ... # type: Optional[expr] + +class ExtSlice(slice): + dims = ... # type: typing.List[slice] + +class Index(slice): + value = ... # type: expr + +class Ellipsis(slice): ... + + +class expr(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class BoolOp(expr): + op = ... # type: boolop + values = ... # type: typing.List[expr] + +class BinOp(expr): + left = ... # type: expr + op = ... # type: operator + right = ... # type: expr + +class UnaryOp(expr): + op = ... # type: unaryop + operand = ... # type: expr + +class Lambda(expr): + args = ... # type: arguments + body = ... # type: expr + +class IfExp(expr): + test = ... # type: expr + body = ... # type: expr + orelse = ... # type: expr + +class Dict(expr): + keys = ... # type: typing.List[expr] + values = ... # type: typing.List[expr] + +class Set(expr): + elts = ... # type: typing.List[expr] + +class ListComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class SetComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class DictComp(expr): + key = ... # type: expr + value = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class GeneratorExp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class Yield(expr): + value = ... # type: Optional[expr] + +class Compare(expr): + left = ... # type: expr + ops = ... # type: typing.List[cmpop] + comparators = ... # type: typing.List[expr] + +class Call(expr): + func = ... # type: expr + args = ... # type: typing.List[expr] + keywords = ... # type: typing.List[keyword] + starargs = ... # type: Optional[expr] + kwargs = ... # type: Optional[expr] + +class Repr(expr): + value = ... # type: expr + +class Num(expr): + n = ... # type: Union[int, float, complex] + +class Str(expr): + s = ... # type: bytes + +class Attribute(expr): + value = ... # type: expr + attr = ... # type: identifier + ctx = ... # type: expr_context + +class Subscript(expr): + value = ... # type: expr + slice = ... # type: _slice + ctx = ... # type: expr_context + +class Name(expr): + id = ... # type: identifier + ctx = ... # type: expr_context + +class List(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + +class Tuple(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + + +class expr_context(AST): + ... + +class AugLoad(expr_context): ... +class AugStore(expr_context): ... +class Del(expr_context): ... +class Load(expr_context): ... +class Param(expr_context): ... +class Store(expr_context): ... + + +class boolop(AST): + ... + +class And(boolop): ... +class Or(boolop): ... + +class operator(AST): + ... + +class Add(operator): ... +class BitAnd(operator): ... +class BitOr(operator): ... +class BitXor(operator): ... +class Div(operator): ... +class FloorDiv(operator): ... +class LShift(operator): ... +class Mod(operator): ... +class Mult(operator): ... +class Pow(operator): ... +class RShift(operator): ... +class Sub(operator): ... + +class unaryop(AST): + ... + +class Invert(unaryop): ... +class Not(unaryop): ... +class UAdd(unaryop): ... +class USub(unaryop): ... + +class cmpop(AST): + ... + +class Eq(cmpop): ... +class Gt(cmpop): ... +class GtE(cmpop): ... +class In(cmpop): ... +class Is(cmpop): ... +class IsNot(cmpop): ... +class Lt(cmpop): ... +class LtE(cmpop): ... +class NotEq(cmpop): ... +class NotIn(cmpop): ... + + +class comprehension(AST): + target = ... # type: expr + iter = ... # type: expr + ifs = ... # type: typing.List[expr] + + +class ExceptHandler(AST): + type = ... # type: Optional[expr] + name = ... # type: Optional[expr] + body = ... # type: typing.List[stmt] + lineno = ... # type: int + col_offset = ... # type: int + + +class arguments(AST): + args = ... # type: typing.List[expr] + vararg = ... # type: Optional[identifier] + kwarg = ... # type: Optional[identifier] + defaults = ... # type: typing.List[expr] + type_comments = ... # type: typing.List[str] + +class keyword(AST): + arg = ... # type: identifier + value = ... # type: expr + +class alias(AST): + name = ... # type: identifier + asname = ... # type: Optional[identifier] + + +class TypeIgnore(AST): + lineno = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/ast3.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/ast3.pyi new file mode 100644 index 000000000..1e96daf0c --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/ast3.pyi @@ -0,0 +1,412 @@ +import typing +from typing import Any, Optional, Union, Generic, Iterator + +class NodeVisitor(): + def visit(self, node: AST) -> Any: ... + def generic_visit(self, node: AST) -> None: ... + +class NodeTransformer(NodeVisitor): + def generic_visit(self, node: AST) -> None: ... + +def parse(source: Union[str, bytes], + filename: Union[str, bytes] = ..., + mode: str = ..., + feature_version: int = ...) -> AST: ... +def copy_location(new_node: AST, old_node: AST) -> AST: ... +def dump(node: AST, annotate_fields: bool = ..., include_attributes: bool = ...) -> str: ... +def fix_missing_locations(node: AST) -> AST: ... +def get_docstring(node: AST, clean: bool = ...) -> str: ... +def increment_lineno(node: AST, n: int = ...) -> AST: ... +def iter_child_nodes(node: AST) -> Iterator[AST]: ... +def iter_fields(node: AST) -> Iterator[typing.Tuple[str, Any]]: ... +def literal_eval(node_or_string: Union[str, AST]) -> Any: ... +def walk(node: AST) -> Iterator[AST]: ... + +PyCF_ONLY_AST = ... # type: int + +# ast classes + +identifier = str + +class AST: + _attributes = ... # type: typing.Tuple[str, ...] + _fields = ... # type: typing.Tuple[str, ...] + def __init__(self, *args, **kwargs) -> None: ... + +class mod(AST): + ... + +class Module(mod): + body = ... # type: typing.List[stmt] + type_ignores = ... # type: typing.List[TypeIgnore] + +class Interactive(mod): + body = ... # type: typing.List[stmt] + +class Expression(mod): + body = ... # type: expr + +class FunctionType(mod): + argtypes = ... # type: typing.List[expr] + returns = ... # type: expr + +class Suite(mod): + body = ... # type: typing.List[stmt] + + +class stmt(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class FunctionDef(stmt): + name = ... # type: identifier + args = ... # type: arguments + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + returns = ... # type: Optional[expr] + type_comment = ... # type: Optional[str] + +class AsyncFunctionDef(stmt): + name = ... # type: identifier + args = ... # type: arguments + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + returns = ... # type: Optional[expr] + type_comment = ... # type: Optional[str] + +class ClassDef(stmt): + name = ... # type: identifier + bases = ... # type: typing.List[expr] + keywords = ... # type: typing.List[keyword] + body = ... # type: typing.List[stmt] + decorator_list = ... # type: typing.List[expr] + +class Return(stmt): + value = ... # type: Optional[expr] + +class Delete(stmt): + targets = ... # type: typing.List[expr] + +class Assign(stmt): + targets = ... # type: typing.List[expr] + value = ... # type: expr + type_comment = ... # type: Optional[str] + +class AugAssign(stmt): + target = ... # type: expr + op = ... # type: operator + value = ... # type: expr + +class AnnAssign(stmt): + target = ... # type: expr + annotation = ... # type: expr + value = ... # type: Optional[expr] + simple = ... # type: int + +class For(stmt): + target = ... # type: expr + iter = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + type_comment = ... # type: Optional[str] + +class AsyncFor(stmt): + target = ... # type: expr + iter = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + type_comment = ... # type: Optional[str] + +class While(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class If(stmt): + test = ... # type: expr + body = ... # type: typing.List[stmt] + orelse = ... # type: typing.List[stmt] + +class With(stmt): + items = ... # type: typing.List[withitem] + body = ... # type: typing.List[stmt] + type_comment = ... # type: Optional[str] + +class AsyncWith(stmt): + items = ... # type: typing.List[withitem] + body = ... # type: typing.List[stmt] + type_comment = ... # type: Optional[str] + +class Raise(stmt): + exc = ... # type: Optional[expr] + cause = ... # type: Optional[expr] + +class Try(stmt): + body = ... # type: typing.List[stmt] + handlers = ... # type: typing.List[ExceptHandler] + orelse = ... # type: typing.List[stmt] + finalbody = ... # type: typing.List[stmt] + +class Assert(stmt): + test = ... # type: expr + msg = ... # type: Optional[expr] + +class Import(stmt): + names = ... # type: typing.List[alias] + +class ImportFrom(stmt): + module = ... # type: Optional[identifier] + names = ... # type: typing.List[alias] + level = ... # type: Optional[int] + +class Global(stmt): + names = ... # type: typing.List[identifier] + +class Nonlocal(stmt): + names = ... # type: typing.List[identifier] + +class Expr(stmt): + value = ... # type: expr + +class Pass(stmt): ... +class Break(stmt): ... +class Continue(stmt): ... + + +class slice(AST): + ... + +_slice = slice # this lets us type the variable named 'slice' below + +class Slice(slice): + lower = ... # type: Optional[expr] + upper = ... # type: Optional[expr] + step = ... # type: Optional[expr] + +class ExtSlice(slice): + dims = ... # type: typing.List[slice] + +class Index(slice): + value = ... # type: expr + + +class expr(AST): + lineno = ... # type: int + col_offset = ... # type: int + +class BoolOp(expr): + op = ... # type: boolop + values = ... # type: typing.List[expr] + +class BinOp(expr): + left = ... # type: expr + op = ... # type: operator + right = ... # type: expr + +class UnaryOp(expr): + op = ... # type: unaryop + operand = ... # type: expr + +class Lambda(expr): + args = ... # type: arguments + body = ... # type: expr + +class IfExp(expr): + test = ... # type: expr + body = ... # type: expr + orelse = ... # type: expr + +class Dict(expr): + keys = ... # type: typing.List[expr] + values = ... # type: typing.List[expr] + +class Set(expr): + elts = ... # type: typing.List[expr] + +class ListComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class SetComp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class DictComp(expr): + key = ... # type: expr + value = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class GeneratorExp(expr): + elt = ... # type: expr + generators = ... # type: typing.List[comprehension] + +class Await(expr): + value = ... # type: expr + +class Yield(expr): + value = ... # type: Optional[expr] + +class YieldFrom(expr): + value = ... # type: expr + +class Compare(expr): + left = ... # type: expr + ops = ... # type: typing.List[cmpop] + comparators = ... # type: typing.List[expr] + +class Call(expr): + func = ... # type: expr + args = ... # type: typing.List[expr] + keywords = ... # type: typing.List[keyword] + +class Num(expr): + n = ... # type: Union[int, float] + +class Str(expr): + s = ... # type: str + +class FormattedValue(expr): + value = ... # type: expr + conversion = ... # type: typing.Optional[int] + format_spec = ... # type: typing.Optional[expr] + +class JoinedStr(expr): + values = ... # type: typing.List[expr] + +class Bytes(expr): + s = ... # type: bytes + +class NameConstant(expr): + value = ... # type: Any + +class Ellipsis(expr): ... + +class Attribute(expr): + value = ... # type: expr + attr = ... # type: identifier + ctx = ... # type: expr_context + +class Subscript(expr): + value = ... # type: expr + slice = ... # type: _slice + ctx = ... # type: expr_context + +class Starred(expr): + value = ... # type: expr + ctx = ... # type: expr_context + +class Name(expr): + id = ... # type: identifier + ctx = ... # type: expr_context + +class List(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + +class Tuple(expr): + elts = ... # type: typing.List[expr] + ctx = ... # type: expr_context + + +class expr_context(AST): + ... + +class AugLoad(expr_context): ... +class AugStore(expr_context): ... +class Del(expr_context): ... +class Load(expr_context): ... +class Param(expr_context): ... +class Store(expr_context): ... + + +class boolop(AST): + ... + +class And(boolop): ... +class Or(boolop): ... + +class operator(AST): + ... + +class Add(operator): ... +class BitAnd(operator): ... +class BitOr(operator): ... +class BitXor(operator): ... +class Div(operator): ... +class FloorDiv(operator): ... +class LShift(operator): ... +class Mod(operator): ... +class Mult(operator): ... +class MatMult(operator): ... +class Pow(operator): ... +class RShift(operator): ... +class Sub(operator): ... + +class unaryop(AST): + ... + +class Invert(unaryop): ... +class Not(unaryop): ... +class UAdd(unaryop): ... +class USub(unaryop): ... + +class cmpop(AST): + ... + +class Eq(cmpop): ... +class Gt(cmpop): ... +class GtE(cmpop): ... +class In(cmpop): ... +class Is(cmpop): ... +class IsNot(cmpop): ... +class Lt(cmpop): ... +class LtE(cmpop): ... +class NotEq(cmpop): ... +class NotIn(cmpop): ... + + +class comprehension(AST): + target = ... # type: expr + iter = ... # type: expr + ifs = ... # type: typing.List[expr] + is_async = ... # type: int + + +class ExceptHandler(AST): + type = ... # type: Optional[expr] + name = ... # type: Optional[identifier] + body = ... # type: typing.List[stmt] + lineno = ... # type: int + col_offset = ... # type: int + + +class arguments(AST): + args = ... # type: typing.List[arg] + vararg = ... # type: Optional[arg] + kwonlyargs = ... # type: typing.List[arg] + kw_defaults = ... # type: typing.List[expr] + kwarg = ... # type: Optional[arg] + defaults = ... # type: typing.List[expr] + +class arg(AST): + arg = ... # type: identifier + annotation = ... # type: Optional[expr] + lineno = ... # type: int + col_offset = ... # type: int + type_comment = ... # type: typing.Optional[str] + +class keyword(AST): + arg = ... # type: Optional[identifier] + value = ... # type: expr + +class alias(AST): + name = ... # type: identifier + asname = ... # type: Optional[identifier] + +class withitem(AST): + context_expr = ... # type: expr + optional_vars = ... # type: Optional[expr] + + +class TypeIgnore(AST): + lineno = ... # type: int diff --git a/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/conversions.pyi b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/conversions.pyi new file mode 100644 index 000000000..d5f18299f --- /dev/null +++ b/src/Analysis/Ast/Impl/Typeshed/third_party/3/typed_ast/conversions.pyi @@ -0,0 +1,4 @@ +from . import ast27 +from . import ast3 + +def py2to3(ast: ast27.AST) -> ast3.AST: ... diff --git a/src/Analysis/Ast/Impl/Utilities/CodeFormatter.cs b/src/Analysis/Ast/Impl/Utilities/CodeFormatter.cs new file mode 100644 index 000000000..72c0fadef --- /dev/null +++ b/src/Analysis/Ast/Impl/Utilities/CodeFormatter.cs @@ -0,0 +1,41 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. } + +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Analysis.Utilities { + internal static class CodeFormatter { + public static string FormatSequence(string sequenceName, char openBrace, IEnumerable types) + => FormatSequence(sequenceName, openBrace, types.Select(t => t.Name)); + + public static string FormatSequence(string sequenceName, char openBrace, IEnumerable names) { + var sb = new StringBuilder(sequenceName); + sb.Append(openBrace); + var i = 0; + foreach (var name in names) { + sb.AppendIf(i > 0, ", "); + sb.Append(name); + i++; + } + sb.AppendIf(openBrace == '[', ']'); + sb.AppendIf(openBrace == '(', ')'); + return sb.ToString(); + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonCollection.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonCollection.cs new file mode 100644 index 000000000..ae80e2c02 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonCollection.cs @@ -0,0 +1,76 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values.Collections { + internal class PythonCollection : PythonInstance, IPythonCollection { + /// + /// Creates collection of the supplied types. + /// + /// Collection type. + /// Contents of the collection (typically elements from the initialization). + /// Declaring location. + /// If true and contents is a single element + /// and is a sequence, the sequence elements are copied rather than creating + /// a sequence of sequences with a single element. + public PythonCollection( + IPythonType collectionType, + LocationInfo location, + IReadOnlyList contents, + bool flatten = true + ) : base(collectionType, location) { + var c = contents ?? Array.Empty(); + if (flatten && c.Count == 1 && c[0] is IPythonCollection seq) { + Contents = seq.Contents; + } else { + Contents = c; + } + } + + /// + /// Invokes indexer the instance. + /// + public override IMember Index(object index) { + var n = GetIndex(index); + if (n < 0) { + n = Contents.Count + n; // -1 means last, etc. + } + if (n >= 0 && n < Contents.Count) { + return Contents[n]; + } + return Type.DeclaringModule.Interpreter.UnknownType; + } + + public IReadOnlyList Contents { get; protected set; } + public override IPythonIterator GetIterator() => new PythonIterator(BuiltinTypeId.ListIterator, this); + + public static int GetIndex(object index) { + switch (index) { + case IPythonConstant c when c.Type.TypeId == BuiltinTypeId.Int || c.Type.TypeId == BuiltinTypeId.Long: + return (int)c.Value; + case int i: + return i; + case long l: + return (int)l; + default: + // TODO: report bad index type. + return 0; + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonDictionary.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonDictionary.cs new file mode 100644 index 000000000..2ec752de2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonDictionary.cs @@ -0,0 +1,113 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; + +namespace Microsoft.Python.Analysis.Values.Collections { + /// + /// Default mutable list with mixed content. + /// + internal class PythonDictionary : PythonCollection, IPythonDictionary { + private readonly Dictionary _contents = new Dictionary(new KeyComparer()); + private readonly IPythonInterpreter _interpreter; + + public PythonDictionary(PythonDictionaryType dictType, LocationInfo location, IReadOnlyDictionary contents) : + base(dictType, location, contents.Keys.ToArray()) { + foreach (var kvp in contents) { + _contents[kvp.Key] = kvp.Value; + } + _interpreter = dictType.DeclaringModule.Interpreter; + } + + public PythonDictionary(IPythonInterpreter interpreter, LocationInfo location, IMember contents) : + base(new PythonDictionaryType(interpreter), location, Array.Empty()) { + if (contents is IPythonDictionary dict) { + foreach (var key in dict.Keys) { + _contents[key] = dict[key]; + } + Contents = _contents.Keys.ToArray(); + } + _interpreter = interpreter; + } + + public PythonDictionary(IPythonInterpreter interpreter, LocationInfo location, IReadOnlyDictionary contents) : + this(new PythonDictionaryType(interpreter), location, contents) { + _interpreter = interpreter; + } + + public IEnumerable Keys => _contents.Keys.ToArray(); + public IEnumerable Values => _contents.Values.ToArray(); + + public IReadOnlyList Items + => _contents.Select(kvp => PythonCollectionType.CreateTuple(Type.DeclaringModule.Interpreter, Location, new[] { kvp.Key, kvp.Value })).ToArray(); + + public IMember this[IMember key] => + _contents.TryGetValue(key, out var value) ? value : UnknownType; + + public override IPythonIterator GetIterator() => Call(@"iterkeys", ArgumentSet.Empty) as IPythonIterator; + + public override IMember Index(object key) => key is IMember m ? this[m] : UnknownType; + + public override IMember Call(string memberName, IArgumentSet args) { + // Specializations + switch (memberName) { + case @"get": + return args.Arguments.Count > 1 ? Index(args.Arguments[1].Value) : _interpreter.UnknownType; + case @"items": + return CreateList(Items); + case @"keys": + return CreateList(Keys.ToArray()); + case @"values": + return CreateList(Values.ToArray()); + case @"iterkeys": + return CreateList(Keys.ToArray()).GetIterator(); + case @"itervalues": + return CreateList(Values.ToArray()).GetIterator(); + case @"iteritems": + return CreateList(Items).GetIterator(); + case @"pop": + return Values.FirstOrDefault() ?? _interpreter.UnknownType; + case @"popitem": + return Items.Count > 0 ? Items[0] as IMember : _interpreter.UnknownType; + } + return base.Call(memberName, args); + } + + private IPythonCollection CreateList(IReadOnlyList items) + => PythonCollectionType.CreateList(Type.DeclaringModule.Interpreter, LocationInfo.Empty, items, false); + + private sealed class KeyComparer : IEqualityComparer { + public bool Equals(IMember x, IMember y) { + if (x is IPythonConstant cx && y is IPythonConstant cy) { + return cx.Value.Equals(cy.Value); + } + return x?.Equals(y) == true; + } + + public int GetHashCode(IMember obj) => 0; // Force call to Equals. + } + + public IEnumerator> GetEnumerator() => _contents.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _contents.GetEnumerator(); + public int Count => _contents.Count; + public bool ContainsKey(IMember key) => _contents.ContainsKey(key); + public bool TryGetValue(IMember key, out IMember value) => _contents.TryGetValue(key, out value); + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonGenerator.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonGenerator.cs new file mode 100644 index 000000000..9112115af --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonGenerator.cs @@ -0,0 +1,35 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values.Collections { + /// + /// Simple specialized generator that yields same value. + /// + internal sealed class PythonGenerator : PythonRepeatingIterator { + private readonly IPythonInterpreter _interpreter; + private readonly IMember _yieldValue; + + public PythonGenerator(IPythonInterpreter interpreter, IMember yieldValue) + : base(interpreter.GetBuiltinType(BuiltinTypeId.Generator), yieldValue) { + _interpreter = interpreter; + _yieldValue = yieldValue; + } + + public override IPythonIterator GetIterator() + => new PythonRepeatingIterator(_interpreter.GetBuiltinType(BuiltinTypeId.SetIterator), _yieldValue); + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonInstanceIterator.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonInstanceIterator.cs new file mode 100644 index 000000000..ed4148f67 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonInstanceIterator.cs @@ -0,0 +1,44 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; + +namespace Microsoft.Python.Analysis.Values.Collections { + /// + /// Iterator that uses custom definitions of __iter__ + /// and __next__ in the supplied instance type. + /// + internal sealed class PythonInstanceIterator : PythonInstance, IPythonIterator { + private readonly IPythonFunctionType __next__; + + public PythonInstanceIterator(IMember instance, IPythonInterpreter interpreter) + : base(new PythonIteratorType(BuiltinTypeId.SetIterator, interpreter)) { + __next__ = instance.GetPythonType().GetMember(@"__next__") as IPythonFunctionType; + } + + public IMember Next => __next__?.Call(null, @"__next__", ArgumentSet.Empty) ?? UnknownType; + + public override IMember Call(string memberName, IArgumentSet args) { + // Specializations + switch (memberName) { + case @"__next__": + case @"next": + return Next; + } + return base.Call(memberName, args); + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonIterator.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonIterator.cs new file mode 100644 index 000000000..13c403a37 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonIterator.cs @@ -0,0 +1,48 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values.Collections { + /// + /// Collection iterator. + /// + internal class PythonIterator : PythonInstance, IPythonIterator { + private int _index; + + protected IPythonCollection Collection { get; } + + public PythonIterator(BuiltinTypeId iteratorTypeId, IPythonCollection collection) + : base(collection.Type.DeclaringModule.Interpreter.GetBuiltinType(iteratorTypeId)) { + Collection = collection; + } + + public PythonIterator(IPythonType iteratorType, IPythonCollection collection) : base(iteratorType) { + Collection = collection; + } + + public virtual IMember Next => Collection.Index(_index++) ?? UnknownType; + + public override IMember Call(string memberName, IArgumentSet args) { + // Specializations + switch (memberName) { + case @"__next__": + case @"next": + return Next; + } + return base.Call(memberName, args); + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonRepeatingIterator.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonRepeatingIterator.cs new file mode 100644 index 000000000..d17564da5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonRepeatingIterator.cs @@ -0,0 +1,40 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values.Collections { + /// + /// Simple iterator that repeats same value. + /// + internal class PythonRepeatingIterator : PythonInstance, IPythonIterator { + public PythonRepeatingIterator(IPythonType iteratorType, IMember value) : base(iteratorType) { + Next = value; + } + + public IMember Next { get; } + + public override IMember Call(string memberName, IArgumentSet args) { + // Specializations + switch (memberName) { + case @"__next__": + case @"next": + case @"send": + return Next; + } + return base.Call(memberName, args); + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Collections/PythonTypeIterator.cs b/src/Analysis/Ast/Impl/Values/Collections/PythonTypeIterator.cs new file mode 100644 index 000000000..05bf9fa76 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Collections/PythonTypeIterator.cs @@ -0,0 +1,53 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Types.Collections; + +namespace Microsoft.Python.Analysis.Values.Collections { + internal sealed class PythonTypeIterator : PythonInstance, IPythonIterator { + private readonly BuiltinTypeId _contentType; + public PythonTypeIterator(BuiltinTypeId iteratorType, BuiltinTypeId contentType, IPythonInterpreter interpreter) + : base(new PythonIteratorType(iteratorType, interpreter)) { + _contentType = contentType; + } + + public IMember Next => Type.DeclaringModule.Interpreter.GetBuiltinType(_contentType); + + public static IPythonIterator FromTypeId(IPythonInterpreter interpreter, BuiltinTypeId typeId) { + switch (typeId) { + case BuiltinTypeId.Str: + return new PythonTypeIterator(BuiltinTypeId.StrIterator, BuiltinTypeId.Str, interpreter); + case BuiltinTypeId.Bytes: + return new PythonTypeIterator(BuiltinTypeId.BytesIterator, BuiltinTypeId.Bytes, interpreter); + case BuiltinTypeId.Unicode: + return new PythonTypeIterator(BuiltinTypeId.UnicodeIterator, BuiltinTypeId.Unicode, interpreter); + default: + // TODO: Add more? + return null; + } + } + + public override IMember Call(string memberName, IArgumentSet args) { + // Specializations + switch (memberName) { + case @"__next__": + case @"next": + return Next; + } + return base.Call(memberName, args); + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IGlobalScope.cs b/src/Analysis/Ast/Impl/Values/Definitions/IGlobalScope.cs new file mode 100644 index 000000000..fda5f6b2b --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IGlobalScope.cs @@ -0,0 +1,22 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + public interface IGlobalScope: IScope { + IPythonModule Module { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IPythonBoundType.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonBoundType.cs new file mode 100644 index 000000000..126aac82f --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonBoundType.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents type with the associated class instance. + /// + public interface IPythonBoundType: IPythonInstance { + IPythonInstance Self { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IPythonCollection.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonCollection.cs new file mode 100644 index 000000000..3d20c8fef --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonCollection.cs @@ -0,0 +1,29 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents an instance of a sequence. + /// + public interface IPythonCollection : IPythonInstance { + /// + /// Collection contents + /// + IReadOnlyList Contents { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IPythonConstant.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonConstant.cs new file mode 100644 index 000000000..44d1bc6cf --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonConstant.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; + +namespace Microsoft.Python.Analysis.Values { + public interface IPythonConstant: IPythonInstance { + object Value { get; } + bool TryGetValue(out T value); + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IPythonDictionary.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonDictionary.cs new file mode 100644 index 000000000..feaa98d60 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonDictionary.cs @@ -0,0 +1,26 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents instance of a dictionary. + /// + public interface IPythonDictionary: IPythonInstance, IReadOnlyDictionary { + IReadOnlyList Items { get; } + } +} diff --git a/src/Analysis/Engine/Impl/LanguageServer/ILanguageServerExtensionProvider.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonInstance.cs similarity index 50% rename from src/Analysis/Engine/Impl/LanguageServer/ILanguageServerExtensionProvider.cs rename to src/Analysis/Ast/Impl/Values/Definitions/IPythonInstance.cs index 65528f5bd..046c90545 100644 --- a/src/Analysis/Engine/Impl/LanguageServer/ILanguageServerExtensionProvider.cs +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonInstance.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,30 +8,34 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; +using Microsoft.Python.Analysis.Types; -namespace Microsoft.PythonTools.Analysis.LanguageServer { +namespace Microsoft.Python.Analysis.Values { /// - /// Implemented on a class that can create a language server extension. - /// This class must have a default constructor. + /// Represents instance of a type. /// - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public interface ILanguageServerExtensionProvider { + public interface IPythonInstance : ILocatedMember, IPythonIterable { /// - /// Called when the extension is loaded for a language server. + /// Type of the object the instance represents. /// - Task CreateAsync( - IServer server, - IReadOnlyDictionary properties, - CancellationToken cancellationToken - ); + IPythonType Type { get; } + + /// + /// Invokes method or property on the instance. + /// + /// Method name. + /// Call arguments. + IMember Call(string memberName, IArgumentSet args); + + /// + /// Invokes indexer the instance. + /// + IMember Index(object index); } } diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IPythonIterable.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonIterable.cs new file mode 100644 index 000000000..022929db7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonIterable.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Analysis.Values { + public interface IPythonIterable { + /// + /// Retrieves iterator for the collection. + /// + IPythonIterator GetIterator(); + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IPythonIterator.cs b/src/Analysis/Ast/Impl/Values/Definitions/IPythonIterator.cs new file mode 100644 index 000000000..2f3753106 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IPythonIterator.cs @@ -0,0 +1,25 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents iterator that can enumerate items in a set. + /// + public interface IPythonIterator : IPythonInstance { + IMember Next { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IScope.cs b/src/Analysis/Ast/Impl/Values/Definitions/IScope.cs new file mode 100644 index 000000000..df1f2cdeb --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IScope.cs @@ -0,0 +1,38 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents scope where variables can be declared. + /// + public interface IScope { + string Name { get; } + ScopeStatement Node { get; } + IScope OuterScope { get; } + IGlobalScope GlobalScope { get; } + bool VisibleToChildren { get; } + IReadOnlyList Children { get; } + IEnumerable EnumerateTowardsGlobal { get; } + IEnumerable EnumerateFromGlobal { get; } + IVariableCollection Variables { get; } + IVariableCollection NonLocals { get; } + IVariableCollection Globals { get; } + void DeclareVariable(string name, IMember value, LocationInfo location); + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IVariable.cs b/src/Analysis/Ast/Impl/Values/Definitions/IVariable.cs new file mode 100644 index 000000000..c4ebe7557 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IVariable.cs @@ -0,0 +1,26 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents a variable. + /// + public interface IVariable: ILocatedMember { + string Name { get; } + IMember Value { get; set; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Definitions/IVariableCollection.cs b/src/Analysis/Ast/Impl/Values/Definitions/IVariableCollection.cs new file mode 100644 index 000000000..0ae5b635a --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Definitions/IVariableCollection.cs @@ -0,0 +1,26 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + public interface IVariableCollection: IReadOnlyCollection { + IVariable this[string name] { get; } + bool Contains(string name); + bool TryGetVariable(string name, out IVariable variable); + IReadOnlyList Names { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/GlobalScope.cs b/src/Analysis/Ast/Impl/Values/GlobalScope.cs new file mode 100644 index 000000000..80d55ec47 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/GlobalScope.cs @@ -0,0 +1,27 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + internal sealed class GlobalScope: Scope, IGlobalScope { + public GlobalScope(IPythonModule module): + base(null, null, true) { + Module = module; + } + + public IPythonModule Module { get; } + } +} diff --git a/src/Analysis/Ast/Impl/Values/PythonBoundType.cs b/src/Analysis/Ast/Impl/Values/PythonBoundType.cs new file mode 100644 index 000000000..588db96da --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/PythonBoundType.cs @@ -0,0 +1,32 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Diagnostics; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents type that is bound to an instance. + /// Typically property or a function. + /// + [DebuggerDisplay("Type {Type.Name} bound to {Self.Type.Name}")] + internal sealed class PythonBoundType : PythonInstance, IPythonBoundType { + public IPythonInstance Self { get; } + + public PythonBoundType(IPythonType fn, IPythonInstance self, LocationInfo location) : base(fn, location) { + Self = self; + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/PythonConstant.cs b/src/Analysis/Ast/Impl/Values/PythonConstant.cs new file mode 100644 index 000000000..39763dad9 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/PythonConstant.cs @@ -0,0 +1,43 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + internal class PythonConstant : PythonInstance, IPythonConstant, IEquatable { + public PythonConstant(object value, IPythonType type, LocationInfo location) + : base(type, location) { + Value = value; + } + public object Value { get; } + + public bool TryGetValue(out T value) { + if (Value is T variable) { + value = variable; + return true; + } + value = default; + return false; + } + + public bool Equals(IPythonConstant other) { + if(!base.Equals(other)) { + return false; + } + return Value?.Equals(other?.Value) == true; + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/PythonInstance.cs b/src/Analysis/Ast/Impl/Values/PythonInstance.cs new file mode 100644 index 000000000..07f2cf17d --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/PythonInstance.cs @@ -0,0 +1,68 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values.Collections; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents an instance of type or the type information. + /// Actual instance has set to . + /// Type information is marked as the type it describes, such as . + /// + [DebuggerDisplay("Instance of {Type.Name}")] + internal class PythonInstance : IPythonInstance, IEquatable { + public PythonInstance(IPythonType type, LocationInfo location = null) { + Type = type ?? throw new ArgumentNullException(nameof(type)); + Location = location ?? LocationInfo.Empty; + } + + public virtual IPythonType Type { get; } + public LocationInfo Location { get; } + public virtual PythonMemberType MemberType => PythonMemberType.Instance; + + public virtual IMember Call(string memberName, IArgumentSet args) { + var t = Type.GetMember(memberName).GetPythonType(); + switch (t) { + case IPythonFunctionType fn: + return fn.Call(this, null, args); + case IPythonPropertyType prop: + return prop.Call(this, null, args); + case IPythonClassType cls: + return cls.Call(this, null, args); + } + // Do NOT call type unless it is specific (see above) since by default Python type + // implementation delegates down to the instance and this will yield stack overflow. + return this; + } + + public virtual IMember Index(object index) => this; // Helps with str slicing + + protected IMember UnknownType => Type.DeclaringModule.Interpreter.UnknownType; + + public virtual IPythonIterator GetIterator() { + var iteratorFunc = Type.GetMember(@"__iter__") as IPythonFunctionType; + var o = iteratorFunc?.Overloads.FirstOrDefault(); + var instance = o?.GetReturnValue(LocationInfo.Empty, ArgumentSet.Empty); + return instance != null ? new PythonInstanceIterator(instance, Type.DeclaringModule.Interpreter) : null; + } + + public bool Equals(IPythonInstance other) => Type?.Equals(other?.Type) == true; + } +} diff --git a/src/Analysis/Ast/Impl/Values/PythonString.cs b/src/Analysis/Ast/Impl/Values/PythonString.cs new file mode 100644 index 000000000..c9bbc1f90 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/PythonString.cs @@ -0,0 +1,35 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Python ASCII (bytes) string (default string in 2.x). + /// + internal sealed class PythonAsciiString : PythonConstant { + public PythonAsciiString(AsciiString s, IPythonInterpreter interpreter, LocationInfo location = null) + : base(s, interpreter.GetBuiltinType(interpreter.GetAsciiTypeId()), location) { } + } + + /// + /// Python Unicode string (default string in 3.x+) + /// + internal sealed class PythonUnicodeString : PythonConstant { + public PythonUnicodeString(string s, IPythonInterpreter interpreter, LocationInfo location = null) + : base(s, interpreter.GetBuiltinType(interpreter.GetUnicodeTypeId()), location) { } + } +} diff --git a/src/Analysis/Ast/Impl/Values/PythonUnion.cs b/src/Analysis/Ast/Impl/Values/PythonUnion.cs new file mode 100644 index 000000000..4f7f994a5 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/PythonUnion.cs @@ -0,0 +1,28 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. } + +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents basic union type. This is not a typing Union. + /// Primarily used to describe multiple types that a function + /// may be returning in different cases. + /// + internal sealed class PythonUnion: PythonInstance { + public PythonUnion(IPythonUnionType unionType, LocationInfo location = null) + : base(unionType, location) { } + } +} diff --git a/src/Analysis/Ast/Impl/Values/Scope.cs b/src/Analysis/Ast/Impl/Values/Scope.cs new file mode 100644 index 000000000..8815f27c7 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Scope.cs @@ -0,0 +1,103 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Ast; + +namespace Microsoft.Python.Analysis.Values { + /// + /// Represents scope where variables can be declared. + /// + internal class Scope : IScope { + private VariableCollection _variables; + private VariableCollection _nonLocals; + private VariableCollection _globals; + private List _childScopes; + + public Scope(ScopeStatement node, IScope outerScope, bool visibleToChildren = true) { + Node = node; + OuterScope = outerScope; + VisibleToChildren = visibleToChildren; + } + + #region IScope + public string Name => Node?.Name ?? ""; + public ScopeStatement Node { get; } + public IScope OuterScope { get; } + public bool VisibleToChildren { get; } + + public IReadOnlyList Children => _childScopes ?? Array.Empty() as IReadOnlyList; + public IVariableCollection Variables => _variables ?? VariableCollection.Empty; + public IVariableCollection NonLocals => _nonLocals ?? VariableCollection.Empty; + public IVariableCollection Globals => _globals ?? VariableCollection.Empty; + + public IGlobalScope GlobalScope { + get { + IScope scope = this; + while (scope.OuterScope != null) { + scope = scope.OuterScope; + } + Debug.Assert(scope is IGlobalScope); + return scope as IGlobalScope; + } + } + + public IEnumerable EnumerateTowardsGlobal { + get { + for (IScope scope = this; scope != null; scope = scope.OuterScope) { + yield return scope; + } + } + } + + public IEnumerable EnumerateFromGlobal => EnumerateTowardsGlobal.Reverse(); + public void DeclareVariable(string name, IMember value, LocationInfo location) + => (_variables ?? (_variables = new VariableCollection())).DeclareVariable(name, value, location); + public void DeclareNonLocal(string name, LocationInfo location) + => (_nonLocals ?? (_nonLocals = new VariableCollection())).DeclareVariable(name, null, location); + public void DeclareGlobal(string name, LocationInfo location) + => (_globals ?? (_globals = new VariableCollection())).DeclareVariable(name, null, location); + #endregion + + public void AddChildScope(Scope s) => (_childScopes ?? (_childScopes = new List())).Add(s); + public IReadOnlyList ToChainTowardsGlobal() => EnumerateTowardsGlobal.OfType().ToList(); + } + + internal class EmptyGlobalScope : IGlobalScope { + public EmptyGlobalScope(IPythonModule module) { + GlobalScope = this; + Module = module; + } + public IPythonModule Module { get; } + public string Name => string.Empty; + public ScopeStatement Node => null; + public IScope OuterScope => null; + public IGlobalScope GlobalScope { get; protected set; } + public bool VisibleToChildren => true; + public IReadOnlyList Children => Array.Empty(); + public IEnumerable EnumerateTowardsGlobal => Enumerable.Repeat(this, 1); + public IEnumerable EnumerateFromGlobal => Enumerable.Repeat(this, 1); + public IVariableCollection Variables => VariableCollection.Empty; + public IVariableCollection NonLocals => VariableCollection.Empty; + public IVariableCollection Globals => VariableCollection.Empty; + + public void DeclareVariable(string name, IMember value, LocationInfo location) { } + + } +} diff --git a/src/Analysis/Ast/Impl/Values/Variable.cs b/src/Analysis/Ast/Impl/Values/Variable.cs new file mode 100644 index 000000000..3af65884d --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/Variable.cs @@ -0,0 +1,50 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Diagnostics; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + [DebuggerDisplay("{DebuggerDisplay}")] + internal sealed class Variable : IVariable { + public Variable(string name, IMember value, LocationInfo location = null) { + Name = name; + Value = value; + if (location != null) { + Location = location; + } else { + Location = value is ILocatedMember lm ? lm.Location : LocationInfo.Empty; + } + } + + public string Name { get; } + public IMember Value { get; set; } + public LocationInfo Location { get; } + public PythonMemberType MemberType => PythonMemberType.Variable; + + private string DebuggerDisplay { + get { + switch (Value) { + case IPythonInstance pi: + return $"{Name} : instance of {pi.Type.Name}"; + case IPythonType pt: + return $"{Name} : typeInfo of {pt.Name}"; + default: + return $"{Name} : member {Value?.MemberType}"; + } + } + } + } +} diff --git a/src/Analysis/Ast/Impl/Values/VariableCollection.cs b/src/Analysis/Ast/Impl/Values/VariableCollection.cs new file mode 100644 index 000000000..b3d73bfe2 --- /dev/null +++ b/src/Analysis/Ast/Impl/Values/VariableCollection.cs @@ -0,0 +1,51 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Values { + [DebuggerDisplay("Count: {Count}")] + internal sealed class VariableCollection : IVariableCollection { + public static readonly IVariableCollection Empty = new VariableCollection(); + private readonly ConcurrentDictionary _variables = new ConcurrentDictionary(); + + #region ICollection + public int Count => _variables.Count; + public IEnumerator GetEnumerator() => _variables.Values.ToList().GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + #endregion + + #region IVariableCollection + public IVariable this[string name] => _variables.TryGetValue(name, out var v) ? v : null; + public bool Contains(string name) => _variables.ContainsKey(name); + public bool TryGetVariable(string key, out IVariable value) => _variables.TryGetValue(key, out value); + public IReadOnlyList Names => _variables.Keys.ToArray(); + #endregion + + #region IMemberContainer + public IMember GetMember(string name) => _variables.TryGetValue(name, out var v) ? v : null; + public IEnumerable GetMemberNames() => _variables.Keys.ToArray(); + #endregion + + internal void DeclareVariable(string name, IMember value, LocationInfo location) + => _variables[name] = new Variable(name, value, location); + } +} diff --git a/src/Analysis/Ast/Impl/get_search_paths.py b/src/Analysis/Ast/Impl/get_search_paths.py new file mode 100644 index 000000000..290662f48 --- /dev/null +++ b/src/Analysis/Ast/Impl/get_search_paths.py @@ -0,0 +1,72 @@ +# Python Tools for Visual Studio +# Copyright(c) Microsoft Corporation +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the License); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +# MERCHANTABLITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. + +__author__ = "Microsoft Corporation " +__version__ = "3.2" + +import sys + +# HACK: macOS sets __cached__ to None for __main__ +# but site.main() cannot handle it. So we force it to a str. +__cached__ = '' + +if 'site' in sys.modules: + raise RuntimeError('script must be run with -S') + +BEFORE_SITE = list(sys.path) + +import site +try: + site.main() +except: + import traceback + traceback.print_exc(file=sys.stderr) +AFTER_SITE = list(sys.path) + +import os +def clean(path): + if path: + return os.path.normcase(os.path.abspath(path).rstrip(os.sep)) + return None + +BEFORE_SITE = set(clean(p) for p in BEFORE_SITE) +AFTER_SITE = set(clean(p) for p in AFTER_SITE) + +for prefix in [ + sys.prefix, + sys.exec_prefix, + getattr(sys, 'real_prefix', ''), + getattr(sys, 'base_prefix', '') +]: + if not prefix: + continue + + BEFORE_SITE.add(clean(prefix)) + + for subdir in ['DLLs', 'Lib', 'Scripts']: + d = clean(os.path.join(prefix, subdir)) + BEFORE_SITE.add(d) + +BEFORE_SITE.discard(None) +AFTER_SITE.discard(None) + +for p in sys.path: + p = clean(p) + if os.path.isdir(p): + if p in BEFORE_SITE: + print("%s|stdlib|" % p) + elif p in AFTER_SITE: + print("%s||" % p) diff --git a/src/Analysis/Ast/Impl/regenerate.py b/src/Analysis/Ast/Impl/regenerate.py new file mode 100644 index 000000000..93c8e23dc --- /dev/null +++ b/src/Analysis/Ast/Impl/regenerate.py @@ -0,0 +1,54 @@ +import ast +import subprocess +import sys + +from pathlib import Path + +SCRAPE_PY = Path(sys.argv[1]) +OUTPUT = Path(sys.argv[2]) +INTERPRETER = sys.argv[3:] +OUTPUT.mkdir(parents=True, exist_ok=True) + +print(f"Scraping {' '.join(INTERPRETER)} to {OUTPUT}") + +def scrape_one(module_name, out_name=None): + args = INTERPRETER + [str(SCRAPE_PY), '-u8'] + if module_name: + args.append(module_name) + if not out_name: + if not module_name: + raise ValueError("out_name must be provided if no module name") + out_name = f"{module_name}.pyi" + + proc = subprocess.Popen(args, stdout=subprocess.PIPE) + with open(OUTPUT / out_name, 'wb') as f: + b = proc.stdout.read(4096) + while b: + f.write(b) + b = proc.stdout.read(4096) + return OUTPUT / out_name + +def _read_builtin_module_names(pyi_file): + with pyi_file.open('rb') as f: + tree = ast.parse(f.read()) + assigns = [n for n in tree.body if isinstance(n, ast.Assign)] + bmn = next(n for n in assigns if n.targets[0].id == '__builtin_module_names__') + return bmn.value.s.split(',') + +# scrape builtins first +wrote_to = scrape_one(None, f"python.pyi") +print(f"Wrote builtins to {wrote_to}") + +# scrape builtin modules +for mod in _read_builtin_module_names(wrote_to): + fn = scrape_one(mod, f"python.{mod}.pyi") + print(f"Wrote {mod} to {fn}") + +# scrape other modules +INCLUDE_MODULES = [ + 'functools', 'unittest', 'unittest.case', +] + +for mod in INCLUDE_MODULES: + fn = scrape_one(mod) + print(f"Wrote {mod} to {fn}") diff --git a/src/Analysis/Ast/Impl/scrape_module.py b/src/Analysis/Ast/Impl/scrape_module.py new file mode 100644 index 000000000..fc3da8a31 --- /dev/null +++ b/src/Analysis/Ast/Impl/scrape_module.py @@ -0,0 +1,1498 @@ +# Python Tools for Visual Studio +# Copyright(c) Microsoft Corporation +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the License); you may not use +# this file except in compliance with the License. You may obtain a copy of the +# License at http://www.apache.org/licenses/LICENSE-2.0 +# +# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +# MERCHANTABLITY OR NON-INFRINGEMENT. +# +# See the Apache Version 2.0 License for specific language governing +# permissions and limitations under the License. + +from __future__ import print_function + +__author__ = "Microsoft Corporation " +__version__ = "15.8" + +import ast +import keyword +import inspect +import io +import re +import sys +import tokenize +import warnings + +try: + import builtins +except ImportError: + import __builtin__ as builtins + +try: + bytes +except NameError: + bytes = str + +try: + unicode +except NameError: + unicode = str + +class InspectWarning(UserWarning): pass + +def _triple_quote(s): + if "'" not in s: + return "'''" + s + "'''" + if '"' not in s: + return '"""' + s + '"""' + if not s.startswith("'"): + return "'''" + s.replace("'''", "\\'\\'\\'") + " '''" + if not s.startswith('"'): + return '"""' + s.replace('"""', '\\"\\"\\"') + ' """' + return "''' " + s.replace("'''", "\\'\\'\\'") + " '''" + +try: + EXACT_TOKEN_TYPES = tokenize.EXACT_TOKEN_TYPES +except AttributeError: + # Bare minimum that we need here + EXACT_TOKEN_TYPES = { + '(': tokenize.LPAR, + ')': tokenize.RPAR, + '[': tokenize.LSQB, + ']': tokenize.RSQB, + '{': tokenize.LBRACE, + '}': tokenize.RBRACE, + ',': tokenize.COMMA, + ':': tokenize.COLON, + '*': tokenize.STAR, + '**': tokenize.DOUBLESTAR, + '=': tokenize.EQUAL, + } + +SKIP_TYPENAME_FOR_TYPES = bool, str, bytes, int, float +STATICMETHOD_TYPES = () +CLASSMETHOD_TYPES = type(float.fromhex), +PROPERTY_TYPES = type(int.real), type(property.fget) + +INVALID_ARGNAMES = set(keyword.kwlist) | set(('None', 'True', 'False')) + +# These full names are known to be lies. When we encounter +# them while scraping a module, assume that we need to write +# out the full type rather than including them by reference. +LIES_ABOUT_MODULE = frozenset([ + builtins.__name__ + ".weakcallableproxy", + builtins.__name__ + ".weakproxy", + builtins.__name__ + ".weakref", + "ctypes.ArgumentError", + "os.stat_result", + "os.statvfs_result", + "xml.parsers.expat.ExpatError", + + "numpy.broadcast", + "numpy.busdaycalendar", + "numpy.dtype", + "numpy.flagsobj", + "numpy.flatiter", + "numpy.ndarray", + "numpy.nditer", + + # These modules contain multiple members that lie about their + # module. Always write out all members of these in full. + "_asyncio.*", + "_bsddb.*", + "_decimal.*", + "_elementtree.*", + "_socket.*", + "_sqlite3.*", + "_ssl.*", + "_testmultiphase.*", +]) + +# These type names cause conflicts with their values, so +# we need to forcibly rename them. +SYS_INFO_TYPES = frozenset(( + "float_info", + "hash_info", + "int_info", + "thread_info", + "version_info", +)) + +VALUE_REPR_FIX = { + float('inf'): "float('inf')", + float('-inf'): "float('-inf')", +} + +IMPLICIT_CLASSMETHOD = ( + '__new__', +) + +if sys.version_info[0] < 3: + SKIP_TYPENAME_FOR_TYPES += unicode, long + +def safe_callable(v): + try: + return hasattr(v, '__call__') + except Exception: + return False + +def safe_module_name(n): + if n: + return '_mod_' + n.replace('.', '_') + return n + +class Signature(object): + # These two dictionaries start with Python 3 values. + # There is an update below for Python 2 differences. + # They will be used as fallbacks for known protocols + + KNOWN_RESTYPES = { + "__abs__": "__T__()", + "__add__": "__T__()", + "__and__": "__T__()", + "__annotations__": "{}", + "__base__": "type", + "__bases__": "(type,)", + "__bool__": "False", + "__call__": "Any", + "__ceil__": "__T__()", + "__code__": "object()", + "__contains__": "False", + "__del__": "None", + "__delattr__": "None", + "__delitem__": "None", + "__dict__": "{'': Any}", + "__dir__": "['']", + "__divmod__": "(0, 0)", + "__eq__": "False", + "__format__": "''", + "__float__": "0.0", + "__floor__": "__T__()", + "__floordiv__": "0", + "__ge__": "False", + "__get__": "__T__()", + "__getattribute__": "Any", + "__getitem__": "Any", + "__getnewargs__": "()", + "__getnewargs_ex__": "((), {})", + "__getslice__": "__T__()", + "__globals__": "{}", + "__gt__": "False", + "__hash__": "0", + "__iadd__": "None", + "__iand__": "None", + "__imul__": "None", + "__index__": "0", + "__init__": "", + "__init_subclass__": "None", + "__int__": "0", + "__invert__": "__T__()", + "__ior__": "None", + "__isub__": "None", + "__iter__": "__T__()", + "__ixor__": "None", + "__le__": "False", + "__len__": "0", + "__length_hint__": "0", + "__lshift__": "__T__()", + "__lt__": "False", + "__mod__": "__T__()", + "__mul__": "__T__()", + "__ne__": "False", + "__neg__": "__T__()", + "__next__": "Any", + "__pos__": "__T__()", + "__pow__": "__T__()", + "__or__": "__T__()", + "__radd__": "__T__()", + "__rand__": "__T__()", + "__rdivmod__": "(0, 0)", + "__rfloordiv__": "__T__()", + "__rlshift__": "__T__()", + "__rmod__": "__T__()", + "__rmul__": "__T__()", + "__ror__": "__T__()", + "__round__": "__T__()", + "__rpow__": "__T__()", + "__rrshift__": "__T__()", + "__rshift__": "__T__()", + "__rsub__": "__T__()", + "__rtruediv__": "__T__()", + "__rxor__": "__T__()", + "__reduce__": ["''", "()"], + "__reduce_ex__": ["''", "()"], + "__repr__": "''", + "__set__": "None", + "__setattr__": "None", + "__setitem__": "None", + "__setstate__": "None", + "__sizeof__": "0", + "__str__": "''", + "__sub__": "__T__()", + "__truediv__": "0.0", + "__trunc__": "__T__()", + "__xor__": "__T__()", + "__subclasscheck__": "False", + "__subclasshook__": "False", + } + + KNOWN_ARGSPECS = { + "__contains__": "(self, value)", + "__del__": "(self)", + "__dir__": "(self)", + "__floor__": "(self)", + "__format__": "(self, format_spec)", + "__getitem__": "(self, index)", + "__getnewargs__": "(self)", + "__getnewargs_ex__": "(self)", + "__init_subclass__": "(cls)", + "__instancecheck__": "(self, instance)", + "__length_hint__": "(self)", + "__prepare__": "(cls, name, bases, **kwds)", + "__round__": "(self, ndigits=0)", + "__reduce__": "(self)", + "__reduce_ex__": "(self, protocol)", + "__reversed__": "(self)", + "__setitem__": "(self, index, value)", + "__setstate__": "(self, state)", + "__sizeof__": "(self)", + "__subclasses__": "(cls)", + "__subclasscheck__": "(cls, subclass)", + "__subclasshook__": "(cls, subclass)", + "__trunc__": "(self)", + } + + + def __init__(self, + name, + callable, + scope=None, + defaults=None, + scope_alias=None, + decorators=None, + module_doc=None, + ): + self.callable = callable + self.name = name + self.scope = scope + self.decorators = decorators or () + self._signature = None + self._defaults = defaults or () + + if scope and '@staticmethod' not in self.decorators: + def_arg = 'cls' if ('@classmethod' in self.decorators or name in IMPLICIT_CLASSMETHOD) else 'self' + if len(self._defaults) == 0 or self._defaults[0] != def_arg: + self._defaults = (def_arg,) + self._defaults + + self.fullsig = None + if self.name in ('__init__', '__new__') and module_doc: + self.fullsig = self._init_argspec_fromdocstring(self._defaults, module_doc, override_name=self.name) + elif not hasattr(self.callable, '__call__') and hasattr(self.callable, '__get__'): + # We have a property + self.decorators = '@property', + self.fullsig = self.name + "(" + ", ".join(self._defaults) + ")" + + self.fullsig = ( + self.fullsig or + # Disable fromsignature() because it doesn't work as well as argspec + #self._init_argspec_fromsignature(self._defaults) or + self._init_argspec_fromargspec(self._defaults) or + self._init_argspec_fromknown(self._defaults, scope_alias) or + self._init_argspec_fromdocstring(self._defaults) or + (self.name + "(" + ", ".join(self._defaults) + ")") + ) + self.restype = ( + self._init_restype_fromsignature() or + self._init_restype_fromknown(scope_alias) or + self._init_restype_fromdocstring() or + 'pass' + ) + + if scope: + self.restype = self.restype.replace('__T__', scope) + + if self.restype in ('return Any', 'return Unknown'): + self.restype = 'pass' + + #Special case for 'with' statement and built-ins like open() or memoryview + if name == '__enter__' and self.restype == 'pass': + self.restype = 'return self' + + def __str__(self): + return self.fullsig + + def _init_argspec_fromsignature(self, defaults): + try: + sig = inspect.signature(self.callable) + except Exception: + return + + new_args = [] + for arg in sig.parameters: + p = sig.parameters[arg] + if p.default != inspect.Signature.empty: + try: + ast.literal_eval(repr(p.default)) + except Exception: + p = p.replace(default=None) + if p.kind == inspect.Parameter.POSITIONAL_ONLY: + p = p.replace(kind=inspect.Parameter.POSITIONAL_OR_KEYWORD) + new_args.append(p) + sig = sig.replace(parameters=new_args) + + return self.name + str(sig) + + def _init_restype_fromsignature(self): + try: + sig = inspect.signature(self.callable) + except Exception: + return + + # If signature has a return annotation, it's in the + # full signature and we don't need it from here. + if not sig or sig.return_annotation == inspect._empty: + return + ann = inspect.formatannotation(sig.return_annotation) + if not ann or not self._can_eval(ann): + return + return 'return ' + ann + + def _init_argspec_fromargspec(self, defaults): + try: + args = (getattr(inspect, 'getfullargspec', None) or inspect.getargspec)(self.callable) + except Exception: + return + + argn = [] + seen_names = set(INVALID_ARGNAMES) + defaults = list(defaults) + default_set = set(defaults) + for a in args.args: + if a in default_set: + default_set.discard(a) + argn.append(self._make_unique_name(a, seen_names)) + if default_set: + argn[:0] = [a for a in defaults if a in default_set] + + if getattr(args, 'varargs', None): + argn.append('*' + args.varargs) + if getattr(args, 'varkw', None): + argn.append('**' + args.varkw) + + if argn and argn[-1] in ('*', '**'): + argn[-1] += self._make_unique_name('_', seen_names) + + return self.name + '(' + ', '.join(argn) + ')' + + def _init_argspec_fromknown(self, defaults, scope_alias): + spec = None + if scope_alias and not spec: + spec = self.KNOWN_ARGSPECS.get(scope_alias + '.' + self.name) + if self.scope and not spec: + spec = self.KNOWN_ARGSPECS.get(self.scope + '.' + self.name) + if not spec: + spec = self.KNOWN_ARGSPECS.get(self.name) + if not spec: + return + + return self.name + spec + + def _init_restype_fromknown(self, scope_alias): + restype = None + if scope_alias and not restype: + restype = self.KNOWN_RESTYPES.get(scope_alias + '.' + self.name) + if self.scope and not restype: + restype = self.KNOWN_RESTYPES.get(self.scope + '.' + self.name) + if not restype: + restype = self.KNOWN_RESTYPES.get(self.name) + if not restype: + return + + if isinstance(restype, list): + return "return " + "; return ".join(restype) + return "return " + restype + + def _init_restype_fromdocstring(self): + doc = getattr(self.callable, '__doc__', None) + if not isinstance(doc, str): + return + + first_line = doc.partition('\n')[0].strip() + if not '->' in first_line: + return + + index = first_line.index('->') + typeName = first_line[index + 2:].strip() + + if typeName.startswith('str'): + return "return ''" + if typeName.startswith('float'): + return "return 1.0" + if typeName.startswith('int'): + return "return 1" + if typeName.startswith('long'): + if sys.version_info[0] < 3: + return "return 1L" + else: + return "return 1" + if typeName.startswith('list'): + return "return list()" + if typeName.startswith('dict'): + return "return dict()" + if typeName.startswith('('): + return "return tuple()" + if typeName.startswith('bool'): + return "return True" + if 'Return a string' in first_line: + return "return ''" + return + + def _init_argspec_fromdocstring(self, defaults, doc=None, override_name=None): + if not doc: + doc = getattr(self.callable, '__doc__', None) + if not isinstance(doc, str): + return + + doc = self._get_first_function_call(doc) + if not doc: + return + + if(override_name): + allow_name_mismatch = override_name not in doc + else: + allow_name_mismatch = False + + return self._parse_funcdef(doc, allow_name_mismatch, defaults, override_name) + + def _make_unique_name(self, name, seen_names): + if name not in seen_names: + seen_names.add(name) + return name + + n = name + '_' + if n not in seen_names: + seen_names.add(n) + return n + + i = 0 + while True: + i += 1 + n = name + '_' + str(i) + if n not in seen_names: + seen_names.add(n) + return n + + raise RuntimeError("Too many arguments in definition") + + def _tokenize(self, expr): + if sys.version_info[0] == 3 and sys.version_info[1] <= 2: + expr = '# coding: utf-8\n' + expr + buf = io.BytesIO(expr.strip().encode('utf-8')) + if sys.version_info[0] == 3: + tokens = tokenize.tokenize(buf.readline) + else: + tokens = tokenize.generate_tokens(buf.readline) + return [(EXACT_TOKEN_TYPES.get(s, tt) if tt == tokenize.OP else tt, s) + for tt, s, _, _, _ in tokens] + + _PAREN_TOKEN_MAP = { + tokenize.LPAR: tokenize.RPAR, + tokenize.LBRACE: tokenize.RBRACE, + tokenize.LSQB: tokenize.RSQB, + } + + def _parse_take_expr(self, tokens, *stop_at): + nesting = [] + expr = [] + while tokens: + tt, s = tokens[0] + if tt == tokenize.LSQB and len(tokens) > 2 and tokens[1][0] in stop_at: + return expr + if tt in self._PAREN_TOKEN_MAP: + expr.append((tt, s)) + nesting.append(self._PAREN_TOKEN_MAP[tt]) + elif nesting and tt == nesting[-1]: + expr.append((tt, s)) + nesting.pop() + elif tt in (tokenize.RPAR, tokenize.RBRACE, tokenize.RSQB): + return expr + elif not nesting and tt in stop_at: + return expr + else: + expr.append((tt, s)) + tokens.pop(0) + return expr + + def _can_eval(self, s): + if not s: + return False + try: + ast.parse(s, mode='eval') + except SyntaxError: + return False + else: + return True + + def _parse_format_arg(self, name, args, defaults): + defaults = list(defaults) + default_set = set(defaults) + seen_names = set(INVALID_ARGNAMES) + parts = [name or '', '('] + arg_parts = [] + any_default = False + + for a_names, a_ann, a_def, a_opt in args: + if not a_names: + continue + a_name = ''.join(a_names) + if a_name in default_set: + default_set.discard(a_name) + + arg_parts.append(self._make_unique_name(a_name, seen_names)) + if self._can_eval(''.join(a_ann)): + arg_parts.append(': ') + arg_parts.extend(a_ann) + if self._can_eval(''.join(a_def)): + arg_parts.append('=') + arg_parts.extend(a_def) + any_default = True + elif a_opt[0] or (any_default and '*' not in a_name and '**' not in a_name): + arg_parts.append('=None') + any_default = True + if a_name.startswith('*'): + any_default = True + arg_parts.append(', ') + + if default_set: + for a in defaults: + if a in default_set: + parts.append(a) + parts.append(', ') + parts.extend(arg_parts) + if parts[-1] == ', ': + parts.pop() + if parts and parts[-1] in ('*', '**'): + parts[-1] += self._make_unique_name('_', seen_names) + + parts.append(')') + + return ''.join(parts) + + def _parse_funcdef(self, expr, allow_name_mismatch, defaults, override_name=None): + '''Takes a call expression that was part of a docstring + and parses the AST as if it were a definition. If the parsed + AST matches the callable we are wrapping, returns the node. + ''' + try: + tokens = self._tokenize(expr) + except (TypeError, tokenize.TokenError): + warnings.warn('failed to tokenize ' + expr, InspectWarning) + return + + name = None + seen_open_paren = False + args = [([], [], [], [False])] + optional = False + + while tokens: + tt, s = tokens.pop(0) + if tt == tokenize.NAME: + if name is None: + name = s + elif seen_open_paren: + args[-1][0].append(s) + args[-1][3][0] = optional + elif tt in (tokenize.STAR, tokenize.DOUBLESTAR): + args[-1][0].append(s) + elif tt == tokenize.COLON: + e = self._parse_take_expr(tokens, tokenize.EQUAL, tokenize.COMMA) + args[-1][1].append(''.join(i[1] for i in e)) + elif tt == tokenize.EQUAL: + e = self._parse_take_expr(tokens, tokenize.COMMA) + args[-1][2].append(''.join(i[1] for i in e)) + elif tt == tokenize.COMMA: + args.append(([], [], [], [False])) + elif tt == tokenize.LSQB: + optional = True + elif tt == tokenize.RSQB: + optional = False + elif tt == tokenize.LPAR: + seen_open_paren = True + elif tt == tokenize.RPAR: + break + elif s in ('->', '...'): + return + + if name and (allow_name_mismatch or name == self.name): + return self._parse_format_arg(override_name or name, args, defaults) + + def _get_first_function_call(self, expr): + '''Scans the string for the first closing parenthesis, + handling nesting, which is the best heuristic we have for + an example call at the start of the docstring.''' + if not expr or ')' not in expr: + return + found = [] + n = 0 + for line in expr.splitlines(): + found_one = False + line = line.strip('\r\n\t ') + if not line: + break + for i, c in enumerate(line): + if c == ')': + n -= 1 + if n == 0: + found.append(line[:i + 1]) + found_one = True + elif c == '(': + n += 1 + + if not found_one: + break + if found: + found.sort(key=len) + return found[-1] + return + +class MemberInfo(object): + NO_VALUE = object() + + def __init__(self, name, value, literal=None, scope=None, module=None, alias=None, module_doc=None, scope_alias=None): + self.name = name + self.value = value + self.literal = literal + self.members = [] + self.values = [] + self.need_imports = () + self.type_name = None + self.scope_name = None + self.bases = () + self.signature = None + self.documentation = getattr(value, '__doc__', None) + self.alias = alias + if not isinstance(self.documentation, str): + self.documentation = None + + # Special case for __init__ that refers to class docs + if self.name == '__init__' and ( + not self.documentation + or 'See help(type(self))' in self.documentation): + self.documentation = module_doc + + if self.name: + self.name = self.name.replace('-', '_') + + value_type = type(value) + if issubclass(value_type, type): + self.need_imports, type_name = self._get_typename(value, module) + if '.' in type_name: + m, s, n = type_name.rpartition('.') + self.literal = safe_module_name(m) + s + n + else: + self.scope_name = self.type_name = type_name + self._collect_bases(value, module, self.type_name) + + elif safe_callable(value): + dec = () + if scope: + if value_type in STATICMETHOD_TYPES: + dec += '@staticmethod', + elif value_type in CLASSMETHOD_TYPES: + dec += '@classmethod', + self.signature = Signature(name, value, scope, scope_alias=scope_alias, decorators=dec, module_doc=module_doc) + elif value is not None: + if value_type in PROPERTY_TYPES: + self.signature = Signature(name, value, scope, scope_alias=scope_alias) + if value_type not in SKIP_TYPENAME_FOR_TYPES: + self.need_imports, self.type_name = self._get_typename(value_type, module) + self._collect_bases(value_type, module, self.type_name) + if isinstance(value, float) and repr(value) == 'nan': + self.literal = "float('nan')" + try: + self.literal = VALUE_REPR_FIX[value] + except Exception: + pass + elif not self.literal: + self.literal = 'None' + + def _collect_bases(self, value_type, module, type_name): + try: + bases = getattr(value_type, '__bases__', ()) + except Exception: + pass + else: + self.bases = [] + self.need_imports = list(self.need_imports) + for ni, t in (self._get_typename(b, module) for b in bases): + if not t: + continue + if t == type_name and module in ni: + continue + self.bases.append(t) + self.need_imports.extend(ni) + + @classmethod + def _get_typename(cls, value_type, in_module): + try: + type_name = value_type.__name__.replace('-', '_') + module = getattr(value_type, '__module__', None) + + # Special workaround for Python 2 exceptions lying about their module + if sys.version_info[0] == 2 and module == 'exceptions' and in_module == builtins.__name__: + module = builtins.__name__ + + # Special workaround for IronPython types that include their module name + if in_module and type_name.startswith(in_module + '.'): + type_name = type_name[len(in_module) + 1:] + module = in_module + + if module and module != '': + if module == in_module: + return (module,), type_name + + fullname = module + '.' + type_name + + if in_module and (fullname in LIES_ABOUT_MODULE or (in_module + '.*') in LIES_ABOUT_MODULE): + # Treat the type as if it came from the current module + return (in_module,), type_name + + return (module,), fullname + + return (), type_name + except Exception: + warnings.warn('could not get type of ' + repr(value_type), InspectWarning) + raise + return (), None + + def _str_from_literal(self, lit): + return self.name + ' = ' + lit + + def _str_from_typename(self, type_name): + mod_name, sep, name = type_name.rpartition('.') + return self.name + ' = ' + safe_module_name(mod_name) + sep + name + '()' + + def _str_from_value(self, v): + return self.name + ' = ' + repr(v) + + def _lines_with_members(self): + if self.bases: + split_bases = [n.rpartition('.') for n in self.bases] + bases = ','.join((safe_module_name(n[0]) + n[1] + n[2]) for n in split_bases) + yield 'class ' + self.name + '(' + bases + '):' + else: + yield 'class ' + self.name + ':' + if self.documentation: + yield ' ' + repr(self.documentation) + if self.members: + for mi in self.members: + if hasattr(mi, 'documentation') and mi.documentation != None and not isinstance(mi.documentation, str): + continue + if mi is not MemberInfo.NO_VALUE: + yield mi.as_str(' ') + else: + yield ' pass' + yield '' + + def _lines_with_signature(self): + seen_decorators = set() + for d in self.signature.decorators: + d = str(d) + if d not in seen_decorators: + seen_decorators.add(d) + yield d + yield 'def ' + str(self.signature) + ':' + if self.documentation: + yield ' ' + repr(self.documentation) + if self.signature.restype: + yield ' ' + self.signature.restype + else: + yield ' pass' + yield '' + + def as_str(self, indent=''): + if self.literal: + return indent + self._str_from_literal(self.literal) + + if self.members: + return '\n'.join(indent + s for s in self._lines_with_members()) + + if self.signature: + return '\n'.join(indent + s for s in self._lines_with_signature()) + + if self.type_name is not None: + return indent + self._str_from_typename(self.type_name) + + if self.value is not None: + return indent + self._str_from_value(self.value) + + return indent + self.name + + +MODULE_MEMBER_SUBSTITUTE = { + '__builtins__': MemberInfo('__builtins__', None, literal='{}'), + '__spec__': None, + '__loader__': None, +} + +CLASS_MEMBER_SUBSTITUTE = { + '__bases__': MemberInfo('__bases__', None, literal='()'), + '__mro__': MemberInfo('__mro__', None, literal='()'), + '__dict__': MemberInfo('__dict__', None, literal='{}'), + '__doc__': None, + '__new__': None, +} + +class ScrapeState(object): + def __init__(self, module_name, module=None): + self.root_module = None + self.module = module + self.module_name = module_name + + self.imports = set() + self.members = [] + + def initial_import(self, search_path=None): + if self.module: + return + + if search_path: + sys.path.insert(0, search_path) + + try: + try: + mod = __import__(self.module_name) + except Exception: + ex_msg = str(sys.exc_info()[1]) + warnings.warn("Working around " + ex_msg, InspectWarning) + if ex_msg == "This must be an MFC application - try 'import win32ui' first": + import win32ui + elif ex_msg == "Could not find TCL routines" or self.module_name == 'matplotlib.backends._tkagg': + if sys.version_info[0] == 2: + import Tkinter + else: + import tkinter + else: + raise + mod = None + if not mod: + # Try the import again, either fixed or without chaining the + # previous exception. + mod = __import__(self.module_name) + finally: + if search_path: + del sys.path[0] + self.root_module = mod + + # __import__ gives us the topmost module. We should generally use + # getattr() from here to find the child module. However, sometimes + # this is unsuccessful. So we work backwards through the full name + # to see what is in sys.modules, then getattr() to go forwards. + mod_name = self.module_name + bits = [] + while mod_name and mod_name not in sys.modules: + mod_name, _, bit = self.module_name.rpartition('.')[0] + bits.insert(0, bit) + + if mod_name: + self.root_module = mod = sys.modules[mod_name] + else: + bits = self.module_name.split('.')[1:] + + for bit in bits: + mod = getattr(mod, bit) + + self.module = mod + + def collect_top_level_members(self): + self._collect_members(self.module, self.members, MODULE_MEMBER_SUBSTITUTE, None) + + if self.module_name == 'sys': + sysinfo = [m for m in self.members if m.type_name in SYS_INFO_TYPES] + for m in sysinfo: + self.members.append(MemberInfo(m.name, None, literal="__" + m.name + "()")) + m.name = m.scope_name = m.type_name = '__' + m.type_name + + m_names = set(m.name for m in self.members) + undeclared = [] + for m in self.members: + if m.value is not None and m.type_name and '.' not in m.type_name and m.type_name not in m_names: + undeclared.append(MemberInfo(m.type_name, type(m.value), module=self.module_name)) + + self.members[:0] = undeclared + + def _should_collect_members(self, member): + if self.module_name in member.need_imports and member.name == member.type_name: + return True + # Support cffi libs + if member.type_name == builtins.__name__ + '.CompiledLib': + return True + + def collect_second_level_members(self): + for mi in self.members: + if self._should_collect_members(mi): + substitutes = dict(CLASS_MEMBER_SUBSTITUTE) + substitutes['__class__'] = MemberInfo('__class__', None, literal=mi.type_name) + self._collect_members(mi.value, mi.members, substitutes, mi) + + if mi.scope_name != mi.type_name: + # When the scope and type names are different, we have a static + # class. To emulate this, we add '@staticmethod' decorators to + # all members. + for mi2 in mi.members: + if mi2.signature: + mi2.signature.decorators += '@staticmethod', + + def _collect_members(self, mod, members, substitutes, outer_member): + '''Fills the members attribute with a dictionary containing + all members from the module.''' + if not mod: + raise RuntimeError("failed to import module") + if mod is MemberInfo.NO_VALUE: + return + + existing_names = set(m.name for m in members) + + if outer_member: + scope = outer_member.scope_name + scope_alias = outer_member.alias + else: + scope, scope_alias = None, None + + mod_scope = (self.module_name + '.' + scope) if scope else self.module_name + mod_doc = getattr(mod, '__doc__', None) + mro = (getattr(mod, '__mro__', None) or ())[1:] + for name in dir(mod): + if keyword.iskeyword(name): + continue + try: + m = substitutes[name] + if m: + members.append(m) + continue + except LookupError: + pass + try: + m = substitutes[mod_scope + '.' + name] + if m: + members.append(m) + continue + except LookupError: + pass + + if name in existing_names: + continue + + try: + value = getattr(mod, name) + except AttributeError: + warnings.warn("attribute " + name + " on " + repr(mod) + " was in dir() but not getattr()", InspectWarning) + except Exception: + warnings.warn("error getting " + name + " for " + repr(mod), InspectWarning) + else: + if not self._should_add_value(value): + continue + if name != '__init__' and self._mro_contains(mro, name, value): + continue + members.append(MemberInfo(name, value, scope=scope, module=self.module_name, module_doc=mod_doc, scope_alias=scope_alias)) + + def _should_add_value(self, value): + try: + value_type = type(value) + mod = getattr(value_type, '__module__', None) + name = value_type.__name__ + except Exception: + warnings.warn("error getting typename", InspectWarning) + return + + if (mod, name) == (builtins.__name__, 'CompiledLib'): + # Always allow CFFI lib + return True + + if issubclass(value_type, (type(sys), type(inspect))): + # Disallow nested modules + return + + # By default, include all values + return True + + def _mro_contains(self, mro, name, value): + for m in mro: + try: + mro_value = getattr(m, name) + except Exception: + pass + else: + if mro_value is value: + return True + + def translate_members(self): + pass + + def dump(self, out): + imports = set() + for value in self.members: + for mod in value.need_imports: + imports.add(mod) + imports.discard(self.module_name) + + if imports: + for mod in sorted(imports): + print("import " + mod + " as " + safe_module_name(mod), file=out) + print("", file=out) + + for value in self.members: + s = value.as_str('') + try: + print(s, file=out) + except TypeError: + print(repr(s), file=sys.stderr) + raise + +def add_builtin_objects(state): + Signature.KNOWN_RESTYPES.update({ + "__Type__.__call__": "cls()", + "__Property__.__delete__": "None", + "__Float__.__getformat__": "''", + "__Bytes__.__getitem__": "__T__()", + "__Unicode__.__getitem__": "__T__()", + "__Type__.__instancecheck__": "False", + "__Tuple__.__iter__": "__TupleIterator__()", + "__List__.__iter__": "__ListIterator__()", + "__Dict__.__iter__": "__DictKeys__()", + "__Set__.__iter__": "__SetIterator__()", + "__FrozenSet__.__iter__": "__SetIterator__()", + "__Bytes__.__iter__": "__BytesIterator__()", + "__Unicode__.__iter__": "__UnicodeIterator__()", + "__BytesIterator__.__next__": "0", + "__UnicodeIterator__.__next__": "__Unicode__()", + "__Type__.__prepare__": "None", + "__List__.__reversed__": "__ListIterator__()", + "__Float__.__setformat__": "None", + "__Type__.__subclasses__": "(cls,)", + "__truediv__": "__Float__()", + "__Type__.__subclasscheck__": "False", + "__subclasshook__": "False", + "all": "False", + "any": "False", + "ascii": "''", + "__Set__.add": "None", + "__List__.append": "None", + "__Float__.as_integer_ratio": "(0, 0)", + "bin": "''", + "__Int__.bit_length": "0", + "callable": "False", + "capitalize": "__T__()", + "casefold": "__T__()", + "center": "__T__()", + "chr": "''", + "clear": "None", + "__Generator__.close": "None", + "conjugate": "__Complex__()", + "copy": "__T__()", + "count": "0", + "__Bytes__.decode": "''", + "__Property__.deleter": "func", + "__Set__.difference": "__T__()", + "__FrozenSet__.difference": "__T__()", + "__Set__.difference_update": "None", + "__Set__.discard": "None", + "divmod": "(0, 0)", + "__Bytes__.encode": "b''", + "__Unicode__.encode": "b''", + "endswith": "False", + "expandtabs": "__T__()", + "__List__.extend": "None", + "find": "0", + "__Unicode__.format": "__T__()", + "__Unicode__.format_map": "__T__()", + "__Bool__.from_bytes": "False", + "__Int__.from_bytes": "0", + "__Long__.from_bytes": "__Long__()", + "__Float__.fromhex": "0.0", + "__Bytes__.fromhex": "b''", + "__Dict__.fromkeys": "{}", + "__Dict__.get": "self[0]", + "__Property__.getter": "func", + "format": "''", + "globals": "__Dict__()", + "hasattr": "False", + "hash": "0", + "hex": "''", + "id": "0", + "index": "0", + "input": "''", + "__List__.insert": "None", + "__Set__.intersection": "__T__()", + "__FrozenSet__.intersection": "__T__()", + "__Set__.intersection_update": "None", + "isalnum": "False", + "isalpha": "False", + "isdecimal": "False", + "isdigit": "False", + "islower": "False", + "isidentifier": "False", + "isnumeric": "False", + "isprintable": "False", + "isspace": "False", + "istitle": "False", + "isupper": "False", + "__Float__.is_integer": "False", + "__Set__.isdisjoint": "False", + "__FrozenSet__.isdisjoint": "False", + "__DictKeys__.isdisjoint": "False", + "__DictItems__.isdisjoint": "False", + "__Set__.issubset": "False", + "__FrozenSet__.issubset": "False", + "__Set__.issuperset": "False", + "__FrozenSet__.issuperset": "False", + "__Dict__.items": "__DictItems__()", + "__Bytes__.join": "b''", + "__Unicode__.join": "''", + "__Dict__.keys": "__DictKeys__()", + "len": "0", + "locals": "__Dict__()", + "lower": "__T__()", + "ljust": "__T__()", + "lstrip": "__T__()", + "__Bytes__.maketrans": "b''", + "__Unicode__.maketrans": "{}", + "__Type__.mro": "[__Type__()]", + "oct": "''", + "partition": "(__T__(), __T__(), __T__())", + "__List__.pop": "self[0]", + "__Dict__.pop": "self.keys()[0]", + "__Set__.pop": "Any", + "__Dict__.popitem": "self.items()[0]", + "remove": "None", + "replace": "__T__()", + "repr": "''", + "rfind": "0", + "__List__.reverse": "None", + "rindex": "0", + "rjust": "__T__()", + "round": "0.0", + "rpartition": "(__T__(), __T__(), __T__())", + "rsplit": "[__T__()]", + "rstrip": "__T__()", + "__Generator__.send": "self.__next__()", + "__Dict__.setdefault": "self[0]", + "__Property__.setter": "func", + "__List__.sort": "None", + "sorted": "__List__()", + "split": "[__T__()]", + "splitlines": "[self()]", + "startswith": "False", + "strip": "__T__()", + "swapcase": "__T__()", + "__Set__.symmetric_difference": "__T__()", + "__FrozenSet__.symmetric_difference": "__T__()", + "__Set__.symmetric_difference_update": "None", + "__Bytes__.translate": "__T__()", + "__Unicode__.translate": "__T__()", + "__Generator__.throw": "None", + "title": "__T__()", + "to_bytes": "b''", + "__Set__.union": "__T__()", + "__FrozenSet__.union": "__T__()", + "__Dict__.update": "None", + "__Set__.update": "None", + "upper": "__T__()", + "__Dict__.values": "__DictValues__()", + "zfill": "__T__()", + }) + + Signature.KNOWN_ARGSPECS.update({ + "__Type__.__call__": "(cls, *args, **kwargs)", + "__Int__.__ceil__": "(self)", + "__Int__.__floor__": "(self)", + "__Float__.__getformat__": "(typestr)", + "__Dict__.__getitem__": "(self, key)", + "__Type__.__instancecheck__": "(self, instance)", + "__Bool__.__init__": "(self, x)", + "__Int__.__init__": "(self, x=0)", + "__List__.__init__": "(self, iterable)", + "__Tuple__.__init__": "(self, iterable)", + "__Type__.__prepare__": "(cls, name, bases, **kwds)", + "__Int__.__round__": "(self, ndigits=0)", + "__Float__.__round__": "(self, ndigits=0)", + "__List__.__reversed__": "(self)", + "__Float__.__setformat__": "(typestr, fmt)", + "__Dict__.__setitem__": "(self, key, value)", + "__Set__.add": "(self, value)", + "__List__.append": "(self, value)", + "__Float__.as_integer_ratio": "(self)", + "__Int__.bit_length": "(self)", + "capitalize": "(self)", + "casefold": "(self)", + "__Bytes__.center": "(self, width, fillbyte=b' ')", + "__Unicode__.center": "(self, width, fillchar=' ')", + "clear": "(self)", + "__Generator__.close": "(self)", + "conjugate": "(self)", + "copy": "(self)", + "count": "(self, x)", + "__Bytes__.count": "(self, sub, start=0, end=-1)", + "__Unicode__.count": "(self, sub, start=0, end=-1)", + "__Bytes__.decode": "(self, encoding='utf-8', errors='strict')", + "__Property__.deleter": "(self, func)", + "__Set__.difference": "(self, other)", + "__FrozenSet__.difference": "(self, other)", + "__Set__.difference_update": "(self, *others)", + "__Set__.discard": "(self, elem)", + "__Unicode__.encode": "(self, encoding='utf-8', errors='strict')", + "endswith": "(self, suffix, start=0, end=-1)", + "expandtabs": "(self, tabsize=8)", + "__List__.extend": "(self, iterable)", + "find": "(self, sub, start=0, end=-1)", + "__Unicode__.format": "(self, *args, **kwargs)", + "__Unicode__.format_map": "(self, mapping)", + "__Bool__.from_bytes": "(bytes, byteorder, *, signed=False)", + "__Int__.from_bytes": "(bytes, byteorder, *, signed=False)", + "__Float__.fromhex": "(string)", + "__Dict__.get": "(self, key, d=None)", + "__Property__.getter": "(self, func)", + "hex": "(self)", + "__List__.insert": "(self, index, value)", + "index": "(self, v)", + "__Bytes__.index": "(self, sub, start=0, end=-1)", + "__Unicode__.index": "(self, sub, start=0, end=-1)", + "__Set__.intersection": "(self, other)", + "__FrozenSet__.intersection": "(self, other)", + "__Set__.intersection_update": "(self, *others)", + "isalnum": "(self)", + "isalpha": "(self)", + "isdecimal": "(self)", + "isdigit": "(self)", + "isidentifier": "(self)", + "islower": "(self)", + "isnumeric": "(self)", + "isprintable": "(self)", + "isspace": "(self)", + "istitle": "(self)", + "isupper": "(self)", + "__Float__.is_integer": "(self)", + "__Set__.isdisjoint": "(self, other)", + "__FrozenSet__.isdisjoint": "(self, other)", + "__DictKeys__.isdisjoint": "(self, other)", + "__DictItems__.isdisjoint": "(self, other)", + "__Set__.issubset": "(self, other)", + "__FrozenSet__.issubset": "(self, other)", + "__Set__.issuperset": "(self, other)", + "__FrozenSet__.issuperset": "(self, other)", + "__Dict__.items": "(self)", + "__Bytes__.join": "(self, iterable)", + "__Unicode__.join": "(self, iterable)", + "__Dict__.keys": "(self)", + "lower": "(self)", + "__Bytes__.ljust": "(self, width, fillbyte=b' ')", + "__Unicode__.ljust": "(self, width, fillchar=' ')", + "lstrip": "(self, chars)", + "__Bytes__.maketrans": "(from_, to)", + "__Unicode__.maketrans": "(x, y, z)", + "__Type__.mro": "(cls)", + "__Bytes__.partition": "(self, sep)", + "__Unicode__.partition": "(self, sep)", + "__List__.pop": "(self, index=-1)", + "__Dict__.pop": "(self, k, d=None)", + "__Set__.pop": "(self)", + "__Dict__.popitem": "(self, k, d=None)", + "__List__.remove": "(self, value)", + "__Set__.remove": "(self, elem)", + "replace": "(self, old, new, count=-1)", + "__List__.reverse": "(self)", + "rfind": "(self, sub, start=0, end=-1)", + "rindex": "(self, sub, start=0, end=-1)", + "__Bytes__.rjust": "(self, width, fillbyte=b' ')", + "__Unicode__.rjust": "(self, width, fillchar=' ')", + "__Bytes__.rpartition": "(self, sep)", + "__Unicode__.rpartition": "(self, sep)", + "rsplit": "(self, sep=None, maxsplit=-1)", + "rstrip": "(self, chars=None)", + "__Generator__.send": "(self, value)", + "__Dict__.setdefault": "(self, k, d)", + "__Property__.setter": "(self, func)", + "__List__.sort": "(self)", + "split": "(self, sep=None, maxsplit=-1)", + "splitlines": "(self, keepends=False)", + "strip": "(self, chars=None)", + "startswith": "(self, prefix, start=0, end=-1)", + "swapcase": "(self)", + "__Set__.symmetric_difference": "(self, other)", + "__FrozenSet__.symmetric_difference": "(self, other)", + "__Set__.symmetric_difference_update": "(self, *others)", + "__Generator__.throw": "(self, type, value=None, traceback=None)", + "title": "(self)", + "__Int__.to_bytes": "(bytes, byteorder, *, signed=False)", + "__Bytes__.translate": "(self, table, delete=b'')", + "__Unicode__.translate": "(self, table)", + "__Set__.union": "(self, *others)", + "__FrozenSet__.union": "(self, *others)", + "__Dict__.update": "(self, d)", + "__Set__.update": "(self, *others)", + "upper": "(self)", + "__Dict__.values": "(self)", + "zfill": "(self, width)", + }) + + if sys.version[0] == '2': + Signature.KNOWN_RESTYPES.update({ + "__BytesIterator__.__next__": None, + "__BytesIterator__.next": "b''", + "__UnicodeIterator__.__next__": None, + "__UnicodeIterator__.next": "u''", + "__Generator__.send": "self.next()", + "__Function__.func_closure": "()", + "__Function__.func_doc": "b''", + "__Function__.func_name": "b''", + "input": None, + "raw_input": "b''", + }) + + Signature.KNOWN_ARGSPECS.update({ + "__BytesIterator__.next": "(self)", + "__UnicodeIterator__.next": "(self)", + }) + + already_added = set() + + def add_simple(name, doc, *members): + mi = MemberInfo(name, MemberInfo.NO_VALUE) + mi.documentation = doc + mi.need_imports = (state.module_name,) + mi.members.extend(members) + state.members.append(mi) + + def add_literal(name, literal): + state.members.append(MemberInfo(name, None, literal=literal)) + + def add_type(alias, type_obj): + if type_obj.__name__ in already_added: + add_literal(alias, type_obj.__name__) + return + already_added.add(type_obj.__name__) + mi = MemberInfo(type_obj.__name__, type_obj, module=builtins.__name__, alias=alias) + state.members.append(mi) + state.members.append(MemberInfo(alias, None, literal=mi.name)) + + add_simple('__Unknown__', '', MemberInfo("__name__", None, literal='""')) + add_simple('__NoneType__', 'the type of the None object', MemberInfo.NO_VALUE) + + # NoneType and None are explicitly defined to avoid parser errors + # because of None being a keyword. + #add_literal('NoneType', '__NoneType__') + #add_literal('None', '__NoneType__()') + + add_type('__Object__', object) + add_type('__Type__', type) + + add_type('__Int__', int) + if type(bool()) is int: + add_literal('__Bool__', '__Int__') + else: + add_type('__Bool__', bool) + + try: + long + except NameError: + add_literal('__Long__', '__Int__') + else: + add_type('__Long__', long) + + add_type("__Float__", float) + add_type("__Complex__", complex) + + add_type("__Tuple__", tuple) + add_type("__List__", list) + add_type("__Dict__", dict) + add_type("__Set__", set) + add_type("__FrozenSet__", frozenset) + + if bytes is not str: + add_type("__Bytes__", bytes) + add_type("__BytesIterator__", type(iter(bytes()))) + add_type("__Unicode__", str) + add_type("__UnicodeIterator__", type(iter(str()))) + add_literal("__Str__", "__Unicode__") + add_literal("__StrIterator__", "__UnicodeIterator__") + + else: + add_type("__Bytes__", str) + add_type("__BytesIterator__", type(iter(str()))) + add_type("__Unicode__", unicode) + add_type("__UnicodeIterator__", type(iter(unicode()))) + add_literal("__Str__", "__Bytes__") + add_literal("__StrIterator__", "__BytesIterator__") + + add_type("__Module__", type(inspect)) + add_type("__Function__", type(add_simple)) + + add_type("__BuiltinMethodDescriptor__", type(object.__hash__)) + add_type("__BuiltinFunction__", type(abs)) + add_type("__Generator__", type((_ for _ in []))) + add_type("__Property__", property) + add_type("__ClassMethod__", classmethod) + add_type("__StaticMethod__", staticmethod) + add_type("__Ellipsis__", type(Ellipsis)) + add_type("__TupleIterator__", type(iter(()))) + add_type("__ListIterator__", type(iter([]))) + add_type("__DictKeys__", type({}.keys())) + add_type("__DictValues__", type({}.values())) + add_type("__DictItems__", type({}.items())) + add_type("__SetIterator__", type(iter(set()))) + add_type("__CallableIterator__", type(iter((lambda: None), None))) + + # Also write out the builtin module names here so that we cache them + try: + builtin_module_names = sys.builtin_module_names + except AttributeError: + pass + else: + add_literal('__builtin_module_names__', '"' + ','.join(builtin_module_names) + '"') + + +if __name__ == '__main__': + EXCLUDED_MEMBERS = () + + outfile = sys.stdout + if '-u8' in sys.argv: + sys.argv.remove('-u8') + try: + b_outfile = outfile.buffer + except AttributeError: + warnings.warn("cannot enable UTF-8 output", InspectWarning) + pass # on Python 2, so hopefully everything is valid ASCII... + else: + import io + outfile = io.TextIOWrapper(b_outfile, encoding='utf-8', errors='replace') + + if len(sys.argv) == 1: + state = ScrapeState(builtins.__name__, builtins) + add_builtin_objects(state) + + EXCLUDED_MEMBERS += ('None', 'False', 'True', '__debug__') + if sys.version_info[0] == 2: + EXCLUDED_MEMBERS += ('print',) + + elif len(sys.argv) >= 2: + state = ScrapeState(sys.argv[1]) + + if len(sys.argv) >= 3: + state.initial_import(sys.argv[2]) + else: + state.initial_import() + + state.collect_top_level_members() + + state.members[:] = [m for m in state.members if m.name not in EXCLUDED_MEMBERS] + + state.collect_second_level_members() + + state.dump(outfile) + #import io + #state.dump(io.BytesIO()) diff --git a/src/Analysis/Ast/Impl/update_typeshed.ps1 b/src/Analysis/Ast/Impl/update_typeshed.ps1 new file mode 100644 index 000000000..3c8b869bc --- /dev/null +++ b/src/Analysis/Ast/Impl/update_typeshed.ps1 @@ -0,0 +1,24 @@ +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +$extract = [IO.Path]::GetTempFileName() +del $extract +$zip = "$extract.zip" +$target = $MyInvocation.MyCommand.Definition | Split-Path -Parent | Join-Path -ChildPath "Typeshed" +mkdir -f $target, $target\stdlib, $target\third_party; + +iwr "https://github.com/python/typeshed/archive/master.zip" -OutFile $zip + +Expand-Archive $zip $extract -Force + + +pushd $extract\typeshed-master +try { + copy -r -fo stdlib, third_party, LICENSE $target +} finally { + popd +} + +rmdir -r -fo $extract +del -fo $zip + +"Latest version of typeshed extracted. Use git add -u to pull in changes." diff --git a/src/Analysis/Ast/Test/AnalysisTestBase.cs b/src/Analysis/Ast/Test/AnalysisTestBase.cs new file mode 100644 index 000000000..8fea80db7 --- /dev/null +++ b/src/Analysis/Ast/Test/AnalysisTestBase.cs @@ -0,0 +1,158 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Analyzer; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Analysis.Dependencies; +using Microsoft.Python.Analysis.Diagnostics; +using Microsoft.Python.Analysis.Documents; +using Microsoft.Python.Analysis.Modules; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.OS; +using Microsoft.Python.Core.Services; +using Microsoft.Python.Core.Shell; +using Microsoft.Python.Core.Tests; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Tests; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + public abstract class AnalysisTestBase { + protected TestLogger TestLogger { get; } = new TestLogger(); + + protected virtual ServiceManager CreateServiceManager() { + var sm = new ServiceManager(); + + var platform = new OSPlatform(); + sm + .AddService(TestLogger) + .AddService(platform) + .AddService(new FileSystem(platform)); + + return sm; + } + + protected string GetAnalysisTestDataFilesPath() => TestData.GetPath(Path.Combine("TestData", "AstAnalysis")); + + internal async Task CreateServicesAsync(string root, InterpreterConfiguration configuration = null) { + configuration = configuration ?? PythonVersions.LatestAvailable; + configuration.AssertInstalled(); + Trace.TraceInformation("Cache Path: " + configuration.ModuleCachePath); + configuration.ModuleCachePath = TestData.GetAstAnalysisCachePath(configuration.Version, true); + configuration.SearchPaths = new[] { GetAnalysisTestDataFilesPath() }; + configuration.TypeshedPath = TestData.GetDefaultTypeshedPath(); + + var sm = CreateServiceManager(); + + sm.AddService(new DiagnosticsService()); + + TestLogger.Log(TraceEventType.Information, "Create TestDependencyResolver"); + var dependencyResolver = new TestDependencyResolver(); + sm.AddService(dependencyResolver); + + TestLogger.Log(TraceEventType.Information, "Create PythonAnalyzer"); + var analyzer = new PythonAnalyzer(sm); + sm.AddService(analyzer); + + TestLogger.Log(TraceEventType.Information, "Create PythonInterpreter"); + var interpreter = await PythonInterpreter.CreateAsync(configuration, root, sm); + sm.AddService(interpreter); + + TestLogger.Log(TraceEventType.Information, "Create RunningDocumentTable"); + var documentTable = new RunningDocumentTable(root, sm); + sm.AddService(documentTable); + + return sm; + } + + internal async Task GetAnalysisAsync( + string code, + InterpreterConfiguration configuration = null, + string moduleName = null, + string modulePath = null) { + + var moduleUri = TestData.GetDefaultModuleUri(); + modulePath = modulePath ?? TestData.GetDefaultModulePath(); + moduleName = Path.GetFileNameWithoutExtension(modulePath); + var moduleDirectory = Path.GetDirectoryName(modulePath); + + var services = await CreateServicesAsync(moduleDirectory, configuration); + return await GetAnalysisAsync(code, services, moduleName, modulePath); + } + + internal async Task GetAnalysisAsync( + string code, + IServiceContainer services, + string moduleName = null, + string modulePath = null) { + + var moduleUri = TestData.GetDefaultModuleUri(); + modulePath = modulePath ?? TestData.GetDefaultModulePath(); + moduleName = moduleName ?? Path.GetFileNameWithoutExtension(modulePath); + + IDocument doc; + var rdt = services.GetService(); + if (rdt != null) { + doc = rdt.AddDocument(moduleUri, code, modulePath); + } else { + var mco = new ModuleCreationOptions { + ModuleName = moduleName, + Content = code, + FilePath = modulePath, + Uri = moduleUri, + ModuleType = ModuleType.User, + LoadOptions = ModuleLoadOptions.Analyze + }; + doc = new PythonModule(mco, services); + } + + TestLogger.Log(TraceEventType.Information, "Ast begin"); + var ast = await doc.GetAstAsync(CancellationToken.None); + ast.Should().NotBeNull(); + TestLogger.Log(TraceEventType.Information, "Ast end"); + + TestLogger.Log(TraceEventType.Information, "Analysis begin"); + var analysis = await doc.GetAnalysisAsync(CancellationToken.None); + analysis.Should().NotBeNull(); + TestLogger.Log(TraceEventType.Information, "Analysis end"); + + return analysis; + } + + private sealed class TestDependencyResolver : IDependencyResolver { + public Task GetDependencyChainAsync(IDocument document, CancellationToken cancellationToken) + => Task.FromResult(new DependencyChainNode(document)); + } + + protected sealed class DiagnosticsService : IDiagnosticsService { + private readonly List _diagnostics = new List(); + + public IReadOnlyList Diagnostics => _diagnostics; + + public void Add(DiagnosticsEntry entry) => _diagnostics.Add(entry); + + public void Add(string message, SourceSpan span, string errorCode, Severity severity) + => Add(new DiagnosticsEntry(message, span, errorCode, severity)); + } + } +} diff --git a/src/Analysis/Ast/Test/ArgumentSetTests.cs b/src/Analysis/Ast/Test/ArgumentSetTests.cs new file mode 100644 index 000000000..7490d781d --- /dev/null +++ b/src/Analysis/Ast/Test/ArgumentSetTests.cs @@ -0,0 +1,374 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Diagnostics; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Parsing.Ast; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ArgumentSetTests: AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task EmptyArgSet() { + const string code = @" +def f(): ... +f() +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(0); + argSet.ListArgument.Should().BeNull(); + argSet.DictionaryArgument.Should().BeNull(); + } + + [TestMethod, Priority(0)] + public async Task KeywordArgs() { + const string code = @" +def f(a, b): ... +f(b=1, a=2) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Arguments[0].Name.Should().Be("a"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[1].Name.Should().Be("b"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.ListArgument.Should().BeNull(); + argSet.DictionaryArgument.Should().BeNull(); + } + + [TestMethod, Priority(0)] + public async Task DefaultArgs() { + const string code = @" +def f(a, b, c='str'): ... +f(b=1, a=2) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(3); + argSet.Arguments[0].Name.Should().Be("a"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[1].Name.Should().Be("b"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[2].Name.Should().Be("c"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().Be("str"); + argSet.ListArgument.Should().BeNull(); + argSet.DictionaryArgument.Should().BeNull(); + } + + [TestMethod, Priority(0)] + public async Task StarArg() { + const string code = @" +def f(a, b, *, c='str', d=True): ... +f(1, 2, d=False) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(4); + argSet.Arguments[0].Name.Should().Be("a"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[1].Name.Should().Be("b"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[2].Name.Should().Be("c"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().Be("str"); + argSet.Arguments[3].Name.Should().Be("d"); + argSet.Arguments[3].Expression.Should().BeOfType().Which.Value.Should().Be(false); + argSet.ListArgument.Should().BeNull(); + argSet.DictionaryArgument.Should().BeNull(); + } + + [TestMethod, Priority(0)] + public async Task StarArgExtraPositionals() { + const string code = @" +def f(a, b, *, c='str'): ... +f(1, 2, 3, 4, c=6) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(3); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.TooManyPositionalArgumentsBeforeStar); + } + + [TestMethod, Priority(0)] + public async Task TwoStarArg() { + const string code = @" +def f(a, b, *, *, c='str'): ... +f(1, 2, 3, 4, 5, c=6) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(0); + } + + [TestMethod, Priority(0)] + public async Task NamedStarArg() { + const string code = @" +def f(a, b, *list, c='str', d=True): ... +f(1, 2, 3, 4, 5, c='a') +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(4); + argSet.Arguments[0].Name.Should().Be("a"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[1].Name.Should().Be("b"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[2].Name.Should().Be("c"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().Be("a"); + argSet.Arguments[3].Name.Should().Be("d"); + argSet.Arguments[3].Expression.Should().BeOfType().Which.Value.Should().Be(true); + argSet.ListArgument.Should().NotBeNull(); + argSet.ListArgument.Name.Should().Be("list"); + argSet.ListArgument.Expressions.OfType().Select(c => c.Value).Should().ContainInOrder(3, 4, 5); + argSet.DictionaryArgument.Should().BeNull(); + } + + [TestMethod, Priority(0)] + public async Task NamedDictArg() { + const string code = @" +def f(a, b, **dict): ... +f(b=1, a=2, c=3, d=4, e='str') +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Arguments[0].Name.Should().Be("a"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[1].Name.Should().Be("b"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.ListArgument.Should().BeNull(); + argSet.DictionaryArgument.Should().NotBeNull(); + argSet.DictionaryArgument.Name.Should().Be("dict"); + argSet.DictionaryArgument.Expressions["c"].Should().BeAssignableTo().Which.Value.Should().Be(3); + argSet.DictionaryArgument.Expressions["d"].Should().BeAssignableTo().Which.Value.Should().Be(4); + argSet.DictionaryArgument.Expressions["e"].Should().BeAssignableTo().Which.Value.Should().Be("str"); + } + + [TestMethod, Priority(0)] + public async Task NamedDictExtraPositionals() { + const string code = @" +def f(a, b, **dict): ... +f(1, 2, 3, 4, 5, c='a') +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.TooManyPositionalArgumentsBeforeStar); + } + + [TestMethod, Priority(0)] + public async Task DoubleKeywordArg() { + const string code = @" +def f(a, b): ... +f(a=1, a=2) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.ParameterAlreadySpecified); + } + + [TestMethod, Priority(0)] + public async Task UnknownKeywordArg() { + const string code = @" +def f(a, b): ... +f(a=1, c=2) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.UnknownParameterName); + } + + [TestMethod, Priority(0)] + public async Task TooManyKeywordArgs() { + const string code = @" +def f(a, b): ... +f(a=1, b=2, a=1) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.ParameterAlreadySpecified); + } + + [TestMethod, Priority(0)] + public async Task TooManyPositionalArgs() { + const string code = @" +def f(a, b): ... +f(1, 2, 1) +"; + var argSet = await GetArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.TooManyFunctionArguments); + } + + [TestMethod, Priority(0)] + public async Task TooFewArgs() { + const string code = @" +def f(a, b): ... +f(1) +"; + var argSet = await GetArgSetAsync(code); + // Collected arguments are optimistically returned even if there are errors; + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(1); + argSet.Errors[0].ErrorCode.Should().Be(ErrorCodes.ParameterMissing); + } + + [TestMethod, Priority(0)] + public async Task Method() { + const string code = @" +class A: + def f(self, a, b): ... + +a = A() +a.f(1, 2) +"; + var argSet = await GetClassArgSetAsync(code); + argSet.Arguments.Count.Should().Be(3); + argSet.Errors.Count.Should().Be(0); + argSet.Arguments[0].Name.Should().Be("self"); + argSet.Arguments[0].Expression.Should().BeNull(); + argSet.Arguments[0].Value.Should().BeAssignableTo(); + argSet.Arguments[1].Name.Should().Be("a"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[2].Name.Should().Be("b"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().Be(2); + } + + [TestMethod, Priority(0)] + public async Task StaticMethod() { + const string code = @" +class A: + @staticmethod + def f(a, b): ... + +A.f(1, 2) +"; + var argSet = await GetClassArgSetAsync(code); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(0); + argSet.Arguments[0].Name.Should().Be("a"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[1].Name.Should().Be("b"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(2); + } + + [TestMethod, Priority(0)] + public async Task ClassMethod() { + const string code = @" +class A: + @classmethod + def f(cls, a, b): ... + +a = A() +a.f(b=1, a=2) +"; + var argSet = await GetClassArgSetAsync(code); + argSet.Arguments.Count.Should().Be(3); + argSet.Errors.Count.Should().Be(0); + argSet.Arguments[0].Name.Should().Be("cls"); + argSet.Arguments[0].Expression.Should().BeNull(); + argSet.Arguments[0].Value.Should().BeAssignableTo(); + argSet.Arguments[1].Name.Should().Be("a"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[2].Name.Should().Be("b"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().Be(1); + } + + [TestMethod, Priority(0)] + public async Task UnboundMethod() { + const string code = @" +class A: + def f(self, a, b): ... + +a = A() +f = A.f +f(a, 1, 2) +"; + var argSet = await GetUnboundArgSetAsync(code); + argSet.Arguments.Count.Should().Be(3); + argSet.Errors.Count.Should().Be(0); + argSet.Arguments[0].Name.Should().Be("self"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Name.Should().Be("a"); + argSet.Arguments[1].Name.Should().Be("a"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[2].Name.Should().Be("b"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().Be(2); + } + + [TestMethod, Priority(0)] + [Ignore("// https://github.com/Microsoft/python-language-server/issues/533")] + public async Task Pow() { + const string code = @" +from builtins import pow + +#def pow(x, y, z=None): +# 'pow(x, y[, z]) -> number\n\nWith two arguments, equivalent to x**y.' +# pass + +pow(1, 2) +"; + var argSet = await GetArgSetAsync(code, "pow"); + argSet.Arguments.Count.Should().Be(2); + argSet.Errors.Count.Should().Be(0); + argSet.Arguments[0].Name.Should().Be("x"); + argSet.Arguments[0].Expression.Should().BeOfType().Which.Value.Should().Be(1); + argSet.Arguments[1].Name.Should().Be("y"); + argSet.Arguments[1].Expression.Should().BeOfType().Which.Value.Should().Be(2); + argSet.Arguments[2].Name.Should().Be("z"); + argSet.Arguments[2].Expression.Should().BeOfType().Which.Value.Should().BeNull(); // Value has not been evaluated yet. + } + + private async Task GetArgSetAsync(string code, string funcName = "f") { + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveFunction(funcName).Which; + var call = GetCall(analysis.Ast); + return new ArgumentSet(f, null, call, analysis.Document, null); + } + + private async Task GetUnboundArgSetAsync(string code, string funcName = "f") { + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveVariable(funcName).Which; + var call = GetCall(analysis.Ast); + return new ArgumentSet(f.Value.GetPythonType(), null, call, analysis.Document, null); + } + + private async Task GetClassArgSetAsync(string code, string className = "A", string funcName = "f") { + var analysis = await GetAnalysisAsync(code); + var cls = analysis.Should().HaveClass(className).Which; + var f = cls.Should().HaveMethod(funcName).Which; + var call = GetCall(analysis.Ast); + return new ArgumentSet(f, new PythonInstance(cls), call, analysis.Document, null); + } + + private CallExpression GetCall(PythonAst ast) { + var statements = (ast.Body as SuiteStatement)?.Statements; + return statements?.OfType().FirstOrDefault(e => e.Expression is CallExpression)?.Expression as CallExpression; + } + } +} diff --git a/src/Analysis/Ast/Test/AssemblySetup.cs b/src/Analysis/Ast/Test/AssemblySetup.cs new file mode 100644 index 000000000..891895df8 --- /dev/null +++ b/src/Analysis/Ast/Test/AssemblySetup.cs @@ -0,0 +1,34 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using Microsoft.Python.Core.Testing; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public sealed class AssemblySetup { + [AssemblyInitialize] + public static void Initialize(TestContext testContext) => AnalysisTestEnvironment.Initialize(); + + private class AnalysisTestEnvironment : TestEnvironmentImpl, ITestEnvironment { + public static void Initialize() { + var instance = new AnalysisTestEnvironment(); + Instance = instance; + TestEnvironment.Current = instance; + } + } + } +} diff --git a/src/Analysis/Ast/Test/AssignmentTests.cs b/src/Analysis/Ast/Test/AssignmentTests.cs new file mode 100644 index 000000000..9e2bf045f --- /dev/null +++ b/src/Analysis/Ast/Test/AssignmentTests.cs @@ -0,0 +1,285 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class AssignmentTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task AssignSelf() { + const string code = @" +class x(object): + def __init__(self): + self.x = 'abc' + def f(self): + pass +"; + var analysis = await GetAnalysisAsync(code); + var cls = analysis.Should().HaveClass("x").Which; + + var xType = cls.Should().HaveMethod("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0) + .Which.Should().HaveName("self").And.HaveType("x").Which; + + xType.Should().HaveMember("x") + .Which.Should().HaveType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task AssignToMissingMember() { + const string code = @" +class test(): + x = 0; + y = 1; +t = test() +t.x, t. = +"; + // This just shouldn't crash, we should handle the malformed code + await GetAnalysisAsync(code); + } + + [TestMethod, Priority(0)] + public async Task Backquote() { + var analysis = await GetAnalysisAsync(@"x = `42`", PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task BadKeywordArguments() { + const string code = @" +def f(a, b): + return a + +x = 100 +z = f(a=42, x)"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("z").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task AssignBytes() { + const string code = @" +x = b'b' +y = u'u' +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Bytes) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task AssignUnicode() { + const string code = @" +x = b'b' +y = u'u' +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y").OfType(BuiltinTypeId.Unicode); + } + + [TestMethod, Priority(0)] + public async Task Ellipsis() { + var analysis = await GetAnalysisAsync(@"x = ..."); + analysis.Should().HaveVariable("x").WithNoTypes(); + } + [TestMethod, Priority(0)] + public async Task NegativeNumbersV2() { + const string code = @" +x = -1 +y = -3.0 +z = -4L +a = z +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Float) + .And.HaveVariable("z").OfType(BuiltinTypeId.Long) + .And.HaveVariable("a").OfType(BuiltinTypeId.Long); + } + + [TestMethod, Priority(0)] + public async Task NegativeNumbersV3() { + const string code = @" +x = -1 +y = -3.0 +z = -4L +a = z +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Float) + .And.HaveVariable("z").OfType(BuiltinTypeId.Int) + .And.HaveVariable("a").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task Tuple() { + const string code = @" +x, y, z = 1, 'str', 3.0 +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("z").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task AnnotatedAssign() { + const string code = @" +x : int = 42 + +class C: + y : int = 42 + + def __init__(self): + self.abc : int = 42 + +a = C() +fob1 = a.abc +fob2 = a.y +fob3 = x +"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("fob1").OfType(BuiltinTypeId.Int) + .And.HaveVariable("fob2").OfType(BuiltinTypeId.Int) + .And.HaveVariable("fob3").OfType(BuiltinTypeId.Int) + .And.HaveVariable("a") + .Which.Should().HaveMembers("abc", "y", "__class__"); + } + + [TestMethod, Priority(0)] + public async Task BaseInstanceVariable() { + const string code = @" +class C: + def __init__(self): + self.abc = 42 + + +class D(C): + def __init__(self): + self.fob = self.abc +"; + var analysis = await GetAnalysisAsync(code); + var d = analysis.Should().HaveClass("D").Which; + + d.Should().HaveMethod("__init__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0).Which.Name.Should().Be("self"); + + d.Should().HaveMember("fob") + .Which.Should().HaveType(BuiltinTypeId.Int); + d.Should().HaveMember("abc") + .Which.Should().HaveType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task LambdaExpression1() { + const string code = @" +x = lambda a: a +y = x(42) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task LambdaExpression2() { + const string code = @" +def f(a): + return a + +x = lambda b: f(b) +y = x(42) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task MemberAssign1() { + const string code = @" +class C: + def func(self): + self.abc = 42 + +a = C() +a.func() +fob = a.abc +"; + var analysis = await GetAnalysisAsync(code); + var intMemberNames = analysis.Document.Interpreter.GetBuiltinType(BuiltinTypeId.Int).GetMemberNames(); + + analysis.Should().HaveVariable("fob").OfType(BuiltinTypeId.Int) + .Which.Should().HaveMembers(intMemberNames); + analysis.Should().HaveVariable("a") + .Which.Should().HaveMembers("abc", "func", "__class__"); + } + + [TestMethod, Priority(0)] + public async Task MemberAssign2() { + const string code = @" +class D: + def func2(self): + a = C() + a.func() + return a.abc + +class C: + def func(self): + self.abc = [2,3,4] + +fob = D().func2() +"; + var analysis = await GetAnalysisAsync(code); + var listMemberNames = analysis.Document.Interpreter.GetBuiltinType(BuiltinTypeId.List).GetMemberNames(); + + analysis.Should().HaveVariable("fob").OfType(BuiltinTypeId.List) + .Which.Should().HaveMembers(listMemberNames); + } + + [TestMethod, Priority(0)] + public async Task StrIndex() { + const string code = @" +a = 'abc' +x = a[0] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + } +} diff --git a/src/Analysis/Ast/Test/BasicTests.cs b/src/Analysis/Ast/Test/BasicTests.cs new file mode 100644 index 000000000..47d47b8cd --- /dev/null +++ b/src/Analysis/Ast/Test/BasicTests.cs @@ -0,0 +1,113 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Tests.Utilities.FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class BasicTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task SmokeTest() { + const string code = @" +x = 'str' + +class C: + def method(self): + return func() + +def func(): + return 2.0 + +c = C() +y = c.method() +"; + var analysis = await GetAnalysisAsync(code); + + var names = analysis.GlobalScope.Variables.Names; + names.Should().OnlyContain("x", "C", "func", "c", "y"); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + analysis.Should().HaveVariable("C").Which.Value.Should().BeAssignableTo(); + + analysis.Should().HaveVariable("func") + .Which.Value.Should().BeAssignableTo(); + + var v = analysis.Should().HaveVariable("c").Which; + var instance = v.Value.Should().BeAssignableTo().Which; + instance.MemberType.Should().Be(PythonMemberType.Instance); + instance.Type.Should().BeAssignableTo(); + + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task ImportTest() { + const string code = @" +import sys +x = sys.path +"; + var analysis = await GetAnalysisAsync(code); + analysis.GlobalScope.Variables.Count.Should().Be(2); + + analysis.Should() + .HaveVariable("sys").OfType(BuiltinTypeId.Module) + .And.HaveVariable("x").OfType(BuiltinTypeId.List); + } + + [TestMethod, Priority(0)] + public async Task BuiltinsTest() { + const string code = @" +x = 1 +"; + var analysis = await GetAnalysisAsync(code); + + var v = analysis.Should().HaveVariable("x").Which; + var t = v.Value.GetPythonType(); + t.Should().BeAssignableTo(); + + var mc = (IMemberContainer)t; + var names = mc.GetMemberNames().ToArray(); + names.Length.Should().BeGreaterThan(50); + } + + [TestMethod, Priority(0)] + public async Task BuiltinsTrueFalse() { + const string code = @" +booltypetrue = True +booltypefalse = False +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable(@"booltypetrue").OfType(BuiltinTypeId.Bool) + .And.HaveVariable(@"booltypefalse").OfType(BuiltinTypeId.Bool); + } + } +} diff --git a/src/Analysis/Ast/Test/CartesianTests.cs b/src/Analysis/Ast/Test/CartesianTests.cs new file mode 100644 index 000000000..d44f15f5c --- /dev/null +++ b/src/Analysis/Ast/Test/CartesianTests.cs @@ -0,0 +1,100 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class CartesianTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task Simple() { + const string code = @" +def f(a): + return a + +x = f(42) +y = f('fob')"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task Closures() { + const string code = @" +def f(a): + def g(): + return a + return g() + +x = f(42) +y = f('fob')"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task Locals() { + const string code = @" +def f(a): + b = a + return b + +x = f(42) +y = f('fob')"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task LocalsIsInstance() { + const string code = @" +def f(a, c): + if isinstance(c, int): + b = a + return b + else: + b = a + return b + + +x = f(42, 'oar') +y = f('fob', 'oar')"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str); + } + } +} diff --git a/src/Analysis/Ast/Test/ClassesTests.cs b/src/Analysis/Ast/Test/ClassesTests.cs new file mode 100644 index 000000000..0bd2bfc5a --- /dev/null +++ b/src/Analysis/Ast/Test/ClassesTests.cs @@ -0,0 +1,492 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Modules; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Parsing.Tests; +using Microsoft.Python.Tests.Utilities.FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ClassesTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task Classes() { + var code = await File.ReadAllTextAsync(Path.Combine(GetAnalysisTestDataFilesPath(), "Classes.py")); + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + var names = analysis.GlobalScope.Variables.Names; + var all = analysis.GlobalScope.Variables.ToArray(); + + names.Should().OnlyContain("C1", "C2", "C3", "C4", "C5", + "D", "E", + "F1", + "f" + ); + + all.First(x => x.Name == "C1").Value.Should().BeAssignableTo(); + all.First(x => x.Name == "C2").Value.Should().BeAssignableTo(); + all.First(x => x.Name == "C3").Value.Should().BeAssignableTo(); + all.First(x => x.Name == "C4").Value.Should().BeAssignableTo(); + + all.First(x => x.Name == "C5") + .Value.Should().BeAssignableTo() + .Which.Name.Should().Be("C1"); + + all.First(x => x.Name == "D").Value.Should().BeAssignableTo(); + all.First(x => x.Name == "E").Value.Should().BeAssignableTo(); + + all.First(x => x.Name == "f").Value.Should().BeAssignableTo(); + + var f1 = all.First(x => x.Name == "F1"); + var c = f1.Value.Should().BeAssignableTo().Which; + + c.GetMemberNames().Should().OnlyContain("F2", "F3", "F6", "__class__", "__bases__"); + c.GetMember("F6").Should().BeAssignableTo() + .Which.Documentation.Should().Be("C1"); + + c.GetMember("F2").Should().BeAssignableTo(); + c.GetMember("F3").Should().BeAssignableTo(); + c.GetMember("__class__").Should().BeAssignableTo(); + c.GetMember("__bases__").Should().BeAssignableTo(); + } + + [TestMethod, Priority(0)] + public async Task Mro() { + using (var s = await CreateServicesAsync(null)) { + var interpreter = s.GetService(); + var m = new SentinelModule("test", s); + + var O = new PythonClassType("O", m); + var A = new PythonClassType("A", m); + var B = new PythonClassType("B", m); + var C = new PythonClassType("C", m); + var D = new PythonClassType("D", m); + var E = new PythonClassType("E", m); + var F = new PythonClassType("F", m); + + F.SetBases(interpreter, new[] { O }); + E.SetBases(interpreter, new[] { O }); + D.SetBases(interpreter, new[] { O }); + C.SetBases(interpreter, new[] { D, F }); + B.SetBases(interpreter, new[] { D, E }); + A.SetBases(interpreter, new[] { B, C }); + + PythonClassType.CalculateMro(A).Should().Equal(new[] { "A", "B", "C", "D", "E", "F", "O" }, (p, n) => p.Name == n); + PythonClassType.CalculateMro(B).Should().Equal(new[] { "B", "D", "E", "O" }, (p, n) => p.Name == n); + PythonClassType.CalculateMro(C).Should().Equal(new[] { "C", "D", "F", "O" }, (p, n) => p.Name == n); + } + } + + [TestMethod, Priority(0)] + public async Task ComparisonTypeInference() { + const string code = @" +class BankAccount(object): + def __init__(self, initial_balance=0): + self.balance = initial_balance + def withdraw(self, amount): + self.balance -= amount + def overdrawn(self): + return self.balance < 0 +"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + + analysis.Should().HaveClass("BankAccount") + .Which.Should().HaveMethod("overdrawn") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveReturnType("bool"); + } + + [TestMethod, Priority(0)] + public async Task MembersAfterError() { + const string code = @" +class X(object): + def f(self): + return self. + + def g(self): + pass + + def h(self): + pass +"; + var analysis = await GetAnalysisAsync(code); + var objectMemberNames = analysis.Document.Interpreter.GetBuiltinType(BuiltinTypeId.Object).GetMemberNames(); + + var cls = analysis.Should().HaveClass("X").Which; + + cls.Should().HaveMethod("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0) + .Which.Should().HaveName("self"); + + cls.Should().HaveMembers(objectMemberNames) + .And.HaveMembers("f", "g", "h"); + } + + [TestMethod, Priority(0)] + public async Task Property() { + const string code = @" +class x(object): + @property + def SomeProp(self): + return 42 + +a = x().SomeProp +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task StaticMethod() { + const string code = @" +class x(object): + @staticmethod + def StaticMethod(value): + return value + +a = x().StaticMethod(4.0) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task InheritedStaticMethod() { + const string code = @" +class x(object): + @staticmethod + def StaticMethod(value): + return value + +class y(x): + pass + +a = y().StaticMethod(4.0) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task InheritedClassMethod() { + const string code = @" +class x(object): + @classmethod + def ClassMethod(cls): + return cls + +class y(x): + pass + +a = y().ClassMethod() +b = y.ClassMethod() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType("y") + .And.HaveVariable("b").OfType("y"); + } + + [TestMethod, Priority(0)] + public async Task ClassMethod() { + const string code = @" +class x(object): + @classmethod + def ClassMethod(cls): + return cls + +a = x().ClassMethod() +b = x.ClassMethod() +"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("a").OfType("x"); + analysis.Should().HaveVariable("b").OfType("x"); + analysis.Should().HaveClass("x") + .Which.Should().HaveMethod("ClassMethod") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0).Which.Should().HaveName("cls").And.HaveType("x"); + } + + [TestMethod, Priority(0)] + public async Task ClassInit() { + const string code = @" +class X: + def __init__(self, value): + self.value = value + +a = X(2) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a") + .Which.Value.Should().BeAssignableTo() + .Which.Type.Name.Should().Be("X"); + + analysis.Should().HaveClass("X") + .Which.Should().HaveMethod("__init__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0).Which.Should().HaveName("self").And.HaveType("X"); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task ClassNew() { + const string code = @" +class X: + def __new__(cls, value: int): + res = object.__new__(cls) + res.value = value + return res + +a = X(2) +"; + var analysis = await GetAnalysisAsync(code); + + var cls = analysis.Should().HaveClass("X").Which; + var o = cls.Should().HaveMethod("__new__").Which.Should().HaveSingleOverload().Which; + + o.Should().HaveParameterAt(0).Which.Should().HaveName("cls").And.HaveType("X"); + o.Should().HaveParameterAt(1).Which.Should().HaveName("value").And.HaveType(BuiltinTypeId.Int); + cls.Should().HaveMember("res").Which.Should().HaveType("X"); + + var v = analysis.Should().HaveVariable("a").OfType("X").Which; + v.Should().HaveMember("value").Which.Should().HaveType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task InstanceCall() { + const string code = @" +class X: + def __call__(self, value): + return value + +x = X() + +a = x(2) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task InstanceMembers() { + const string code = @" +class C: + def f(self): pass + +x = C +y = x() + +f1 = C.f +c = C() +f2 = c.f +"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("x").Which.Value.Should().BeAssignableTo(); + analysis.Should().HaveVariable("y") + .Which.Value.Should().BeAssignableTo() + .And.HaveType(typeof(IPythonClassType)); + + analysis.Should() + .HaveVariable("f1").OfType(BuiltinTypeId.Function).And + .HaveVariable("f2").OfType(BuiltinTypeId.Method); + } + + [TestMethod, Priority(0)] + public async Task UnfinishedDot() { + // the partial dot should be ignored and we shouldn't see g as a member of D + const string code = @" +class D(object): + def func(self): + self. + +def g(a, b, c): pass +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveClass("D") + .Which.Should().HaveMember("func") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0) + .Which.Name.Should().Be("self"); + + analysis.Should().HaveFunction("g").Which.DeclaringType.Should().BeNull(); + } + + [TestMethod, Priority(0)] + public async Task CtorSignatures() { + const string code = @" +class C: pass + +class D(object): pass + +class E(object): + def __init__(self): pass + +class F(object): + def __init__(self, one): pass + +class G(object): + def __new__(cls): pass + +class H(object): + def __new__(cls, one): pass +"; ; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveClass("C") + .Which.Should().NotHaveMembers(); + + analysis.Should().HaveClass("D") + .Which.Should().NotHaveMembers(); + + analysis.Should().HaveClass("E") + .Which.Should().HaveMember("__init__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameters("self"); + + analysis.Should().HaveClass("F") + .Which.Should().HaveMember("__init__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameters("self", "one"); + + analysis.Should().HaveClass("G") + .Which.Should().HaveMember("__new__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameters("cls"); + + analysis.Should().HaveClass("H") + .Which.Should().HaveMember("__new__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameters("cls", "one"); + } + + [TestMethod, Priority(0)] + public async Task NestedMethod() { + const string code = @" +class MyClass: + def func1(self): + def func2(a, b): + return a + return func2('abc', 123) + +x = MyClass().func1() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task UnassignedClassMembers() { + const string code = @" +class Employee: + name: str + id: int = 3 + +e = Employee('Guido') +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("e") + .Which.Should().HaveMembers("name", "id", "__class__"); + } + + [TestMethod, Priority(0)] + public async Task AnnotateToSelf() { + const string code = @" +class A: + def func() -> A: ... + +x = A().func() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x") + .Which.Should().HaveType("A"); + } + + [TestMethod, Priority(0)] + public async Task MutualRecursion() { + const string code = @" +class C: + def f(self, other, depth): + if depth == 0: + return 'abc' + return other.g(self, depth - 1) + +class D: + def g(self, other, depth): + if depth == 0: + return ['d', 'e', 'f'] + + return other.f(self, depth - 1) + +x = D().g(C(), 42) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.List); + } + + [TestMethod, Priority(0)] + public async Task OverrideMember() { + const string code = @" +class x(object): + x: int + def a(self): + return self.x + +class y(x): + x: float + pass + +a = y().a() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task InheritedMember() { + const string code = @" +class x(object): + x: int + +class y(x): + def a(self): + return self.x + +a = y().a() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int); + } + + } +} diff --git a/src/Analysis/Ast/Test/CollectionsTests.cs b/src/Analysis/Ast/Test/CollectionsTests.cs new file mode 100644 index 000000000..8857819f6 --- /dev/null +++ b/src/Analysis/Ast/Test/CollectionsTests.cs @@ -0,0 +1,504 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class CollectionsTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task ListAssign() { + const string code = @" +l1 = [1, 'str', 3.0] +x0 = l1[0] +x1 = l1[1] +x2 = l1[2] +x3 = l1[3] +x4 = l1[x0] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("l1").OfType(BuiltinTypeId.List) + .And.HaveVariable("x0").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("x2").OfType(BuiltinTypeId.Float) + .And.HaveVariable("x3").WithNoTypes() + .And.HaveVariable("x4").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ListCallCtor() { + const string code = @" +import builtins as _mod_builtins +l = list() +l0 = _mod_builtins.list() +l1 = list([1, 'str', 3.0]) +x0 = l1[0] +x1 = l1[1] +x2 = l1[2] +x3 = l1[3] +x4 = l1[x0] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("l").OfType(BuiltinTypeId.List) + .And.HaveVariable("l0").OfType(BuiltinTypeId.List) + .And.HaveVariable("l1").OfType(BuiltinTypeId.List) + .And.HaveVariable("x0").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("x2").OfType(BuiltinTypeId.Float) + .And.HaveVariable("x3").WithNoTypes() + .And.HaveVariable("x4").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ListNegativeIndex() { + const string code = @" +l1 = [1, 'str', 3.0] +x0 = l1[-1] +x1 = l1[-2] +x2 = l1[-3] +x3 = l1[x2] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("l1").OfType(BuiltinTypeId.List) + .And.HaveVariable("x0").OfType(BuiltinTypeId.Float) + .And.HaveVariable("x1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("x2").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x3").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ListSlice() { + const string code = @" +l1 = [1, 'str', 3.0, 2, 3, 4] +l2 = l1[2:4] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("l1").OfType(BuiltinTypeId.List) + .And.HaveVariable("l2").OfType(BuiltinTypeId.List); + } + + [TestMethod, Priority(0)] + public async Task ListRecursion() { + const string code = @" +def f(x): + print abc + return f(list(x)) + +abc = f(()) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("abc"); + } + + [TestMethod, Priority(0)] + public async Task ListSubclass() { + const string code = @" +class C(list): + pass + +a = C() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").Which.Should().HaveMember("count"); + } + + [TestMethod, Priority(0)] + public async Task ConstantIndex() { + const string code = @" +ZERO = 0 +ONE = 1 +TWO = 2 +x = ['abc', 42, True] + + +some_str = x[ZERO] +some_int = x[ONE] +some_bool = x[TWO] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("some_str").OfType(BuiltinTypeId.Str) + .And.HaveVariable("some_int").OfType(BuiltinTypeId.Int) + .And.HaveVariable("some_bool").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + public async Task Slicing() { + var code = @" +x = [2] +y = x[:-1] +z = y[0] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("z").OfType(BuiltinTypeId.Int); + + code = @" +x = (2, 3, 4) +y = x[:-1] +z = y[0] +"; + analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("z").OfType(BuiltinTypeId.Int); + + code = @" +lit = 'abc' +inst = str.lower() + +slit = lit[1:2] +ilit = lit[1] +sinst = inst[1:2] +iinst = inst[1] +"; + analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable(@"slit").OfType(BuiltinTypeId.Str) + .And.HaveVariable(@"ilit").OfType(BuiltinTypeId.Str) + .And.HaveVariable(@"sinst").OfType(BuiltinTypeId.Str) + .And.HaveVariable(@"iinst").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task DictCtor() { + const string code = @" +d1 = dict({2:3}) +x1 = d1[2] + +# d2 = dict(x = 2) +# x2 = d2['x'] + +d3 = dict(**{2:3}) +x3 = d3[2] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x1").OfType(BuiltinTypeId.Int) + //.And.HaveVariable("x2").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x3").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task DictEnum() { + const string code = @" +for x in {42:'abc'}: + print(x) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task DictMethods_V3() { + const string code = @" +x = {42:'abc'} +a = x.items()[0][0] +b = x.items()[0][1] +c = x.keys()[0] +d = x.values()[0] +e = x.pop(1) +f = x.popitem()[0] +g = x.popitem()[1] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x") + .And.HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").OfType(BuiltinTypeId.Str) + .And.HaveVariable("e").OfType(BuiltinTypeId.Str) + .And.HaveVariable("f").OfType(BuiltinTypeId.Int) + .And.HaveVariable("g").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task DictMethods_V2() { + const string code = @" +x = {42:'abc'} +h = x.iterkeys().next() +i = x.itervalues().next() +n = x.iteritems().next(); +j = n[0] +k = n[1] +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("x") + .And.HaveVariable("h").OfType(BuiltinTypeId.Int) + .And.HaveVariable("i").OfType(BuiltinTypeId.Str) + .And.HaveVariable("j").OfType(BuiltinTypeId.Int) + .And.HaveVariable("k").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task DictAssign() { + const string code = @" +x = {'abc': 42} +y = x['abc'] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task DictIterator() { + const string code = @" +x = {'a': 1, 'b': 2, 'c': 3} +y = x.keys() +k = y[1] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.List) + .And.HaveVariable("k").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task DictionaryKeyValues() { + const string code = @" +x = {'abc': 42, 'oar': 'baz'} + +i = x['abc'] +s = x['oar'] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("i").OfType(BuiltinTypeId.Int) + .And.HaveVariable("s").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ForIterator() { + const string code = @" +class X(object): + def __iter__(self): return self + def __next__(self): return 123 + +class Y(object): + def __iter__(self): return X() + +for i in Y(): + pass +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("i").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task ForSequence() { + const string code = @" +x = [('abc', 42, True), ('abc', 23, False)] +for some_str, some_int, some_bool in x: + print some_str + print some_int + print some_bool +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("some_str").OfType(BuiltinTypeId.Str) + .And.HaveVariable("some_int").OfType(BuiltinTypeId.Int) + .And.HaveVariable("some_bool").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + public async Task Generator2X() { + const string code = @" +def f(): + yield 1 + yield 2 + yield 3 + +a = f() +b = a.next() + +for c in f(): + print c +d = a.__next__() +"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").WithNoTypes(); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task GeneratorArgument2X() { + var code = @" +def f(x): + yield x + +a1 = f(42) +b1 = a1.next() +a2 = f('abc') +b2 = a2.next() + +for c in f(): + print c +d = a1.__next__() +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a1").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b1").OfType(BuiltinTypeId.Int) + .And.HaveVariable("a2").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b2").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c").WithNoTypes() + .And.HaveVariable("d").WithNoTypes(); + } + + [TestMethod, Priority(0)] + public async Task GeneratorSend2X() { + const string code = @" +def f(): + yield 1 + x = yield 2 + +a = f() +b = a.next() +c = a.send('abc') +d = a.__next__() +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").WithNoTypes(); + } + + [TestMethod, Priority(0)] + public async Task Generator3X() { + const string code = @" +def f(): + yield 1 + yield 2 + yield 3 + +a = f() +b = a.__next__() + +for c in f(): + print(c) + +d = a.next() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").WithNoTypes(); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task GeneratorArgument3X() { + var code = @" +def f(x): + yield x + +a1 = f(42) +b1 = a1.__next__() +a2 = f('abc') +b2 = a2.__next__() + +for c in f(42): + print(c) +d = a1.next() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a1").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b1").OfType(BuiltinTypeId.Int) + .And.HaveVariable("a2").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b2").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").WithNoTypes(); + } + + [TestMethod, Priority(0)] + public async Task GeneratorSend3X() { + const string code = @" +def f(): + yield 1 + x = yield 2 + +a = f() +b = a.__next__() +c = a.send('abc') +d = a.next() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Generator) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").WithNoTypes() + .And.HaveFunction("f"); + } + + [TestMethod, Priority(0)] + public async Task SetLiteral() { + const string code = @" +x = {2, 3, 4} +for abc in x: + print(abc) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType("set") + .And.HaveVariable("abc").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task DictionaryFunctionTable() { + const string code = @" +def f(a, b): + return a + +def g(a, b): + return a, b + +x = {'fob': f, 'oar' : g} +y1 = x['fob'](42, []) +y2 = x['oar'](42, []) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y1").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y2").OfType(BuiltinTypeId.Tuple); + } + + [TestMethod, Priority(0)] + public async Task DictionaryFunctionTableGet() { + const string code = @" +def f(a, b): + return a + +def g(a, b): + return a, b + +x = {'fob': f, 'oar' : g} + +y1 = x.get('fob')(42, []) +y2 = x.get('oar')(42, []) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y1").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y2").OfType(BuiltinTypeId.Tuple); + } + } +} diff --git a/src/Analysis/Ast/Test/DecoratorsTests.cs b/src/Analysis/Ast/Test/DecoratorsTests.cs new file mode 100644 index 000000000..30d2923de --- /dev/null +++ b/src/Analysis/Ast/Test/DecoratorsTests.cs @@ -0,0 +1,194 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class DecoratorsTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + [Ignore] + public async Task DecoratorClass() { + const string code = @" +def dec1(C): + def sub_method(self): pass + C.sub_method = sub_method + return C + +@dec1 +class MyBaseClass1(object): + def base_method(self): pass + +def dec2(C): + class MySubClass(C): + def sub_method(self): pass + return MySubClass + +@dec2 +class MyBaseClass2(object): + def base_method(self): pass + +mc1 = MyBaseClass1() +mc2 = MyBaseClass2() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("mc1") + .Which.Should().HaveMembers("base_method", "sub_method"); + analysis.Should().HaveVariable("mc2").OfType("MySubClass") + .Which.Should().HaveMembers("sub_method"); + } + + [TestMethod, Priority(0)] + public async Task DecoratorReturnTypes_DecoratorNoParams() { + const string code = @"# with decorator without wrap +def decoratorFunctionTakesArg1(f): + def wrapped_f(arg): + return f(arg) + return wrapped_f + +@decoratorFunctionTakesArg1 +def returnsGivenWithDecorator1(parm): + return parm + +retGivenInt = returnsGivenWithDecorator1(1) +retGivenString = returnsGivenWithDecorator1('str') +retGivenBool = returnsGivenWithDecorator1(True) +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("retGivenInt").OfType(BuiltinTypeId.Int) + .And.HaveVariable("retGivenString").OfType(BuiltinTypeId.Str) + .And.HaveVariable("retGivenBool").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + public async Task DecoratorReturnTypes_DecoratorWithParams() { + const string code = @" +# with decorator with wrap +def decoratorFunctionTakesArg2(): + def wrap(f): + def wrapped_f(arg): + return f(arg) + return wrapped_f + return wrap + +@decoratorFunctionTakesArg2() +def returnsGivenWithDecorator2(parm): + return parm + +retGivenInt = returnsGivenWithDecorator2(1) +retGivenString = returnsGivenWithDecorator2('str') +retGivenBool = returnsGivenWithDecorator2(True)"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("retGivenInt").OfType(BuiltinTypeId.Int) + .And.HaveVariable("retGivenString").OfType(BuiltinTypeId.Str) + .And.HaveVariable("retGivenBool").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + public async Task DecoratorReturnTypes_NoDecorator() { + const string code = @"# without decorator +def returnsGiven(parm): + return parm + +retGivenInt = returnsGiven(1) +retGivenString = returnsGiven('str') +retGivenBool = returnsGiven(True) +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("retGivenInt").OfType(BuiltinTypeId.Int) + .And.HaveVariable("retGivenString").OfType(BuiltinTypeId.Str) + .And.HaveVariable("retGivenBool").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task DecoratorTypes() { + var code = @" +def nop(fn): + def wrap(): + return fn() + wp = wrap + return wp + +@nop +def a_tuple(): + return (1, 2, 3) + +@nop +def a_list(): + return [1, 2, 3] + +@nop +def a_float(): + return 0.1 + +@nop +def a_string(): + return 'abc' + +x = a_tuple() +y = a_list() +z = a_float() +w = a_string() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("y").OfType(BuiltinTypeId.List) + .And.HaveVariable("z").OfType(BuiltinTypeId.Float) + .And.HaveVariable("w").OfType(BuiltinTypeId.Str); + + code = @" +def as_list(fn): + def wrap(v): + if v == 0: + return list(fn()) + elif v == 1: + return set(fn(*args, **kwargs)) + else: + return str(fn()) + return wrap + +@as_list +def items(): + return (1, 2, 3) + +items2 = as_list(lambda: (1, 2, 3)) + +x = items(0) +"; + analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("items").OfType(BuiltinTypeId.Function) + .And.HaveVariable("items2").OfType(BuiltinTypeId.Function) + .And.HaveVariable("x").OfType(BuiltinTypeId.List); + } + } +} diff --git a/src/Analysis/Ast/Test/DocumentBufferTests.cs b/src/Analysis/Ast/Test/DocumentBufferTests.cs new file mode 100644 index 000000000..32d527be3 --- /dev/null +++ b/src/Analysis/Ast/Test/DocumentBufferTests.cs @@ -0,0 +1,108 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using FluentAssertions; +using Microsoft.Python.Analysis.Documents; +using Microsoft.Python.Core.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class DocumentBufferTests { + [TestMethod, Priority(0)] + public void BasicDocumentBuffer() { + var doc = new DocumentBuffer(); + doc.Reset(0, @"def f(x): + return + +def g(y): + return y * 2 +"); + + doc.Update(new DocumentChangeSet(0, 1, new[] { + // We *should* batch adjacent insertions, but we should also + // work fine even if we don't. Note that the insertion point + // tracks backwards with previous insertions in the same version. + // If each of these were in its own array, the location would + // have to change for each. + DocumentChange.Insert(")", new SourceLocation(2, 11)), + DocumentChange.Insert("x", new SourceLocation(2, 11)), + DocumentChange.Insert("(", new SourceLocation(2, 11)), + DocumentChange.Insert("g", new SourceLocation(2, 11)), + DocumentChange.Insert(" ", new SourceLocation(2, 11)) + })); + + doc.Text.Should().Contain("return g(x)"); + Assert.AreEqual(1, doc.Version); + + doc.Update(new[] { + new DocumentChangeSet(1, 2, new [] { + DocumentChange.Delete(new SourceLocation(2, 14), new SourceLocation(2, 15)) + }), + new DocumentChangeSet(2, 3, new [] { + DocumentChange.Insert("x * 2", new SourceLocation(2, 14)) + }) + }); + + doc.Text.Should().Contain("return g(x * 2)"); + + doc.Update(new DocumentChangeSet(3, 4, new[] { + DocumentChange.Replace(new SourceLocation(2, 18), new SourceLocation(2, 19), "300") + })); + + doc.Text.Should().Contain("return g(x * 300)"); + + doc.Update(new DocumentChangeSet(4, 5, new[] { + // Changes are out of order, but we should fix that automatically + DocumentChange.Delete(new SourceLocation(2, 13), new SourceLocation(2, 22)), + DocumentChange.Insert("#", new SourceLocation(2, 7)) + })); + doc.Text.Should().Contain("re#turn g"); + } + + [TestMethod, Priority(0)] + public void ResetDocumentBuffer() { + var doc = new DocumentBuffer(); + + doc.Reset(0, ""); + + Assert.AreEqual("", doc.Text.ToString()); + + doc.Update(new[] { new DocumentChangeSet(0, 1, new[] { + DocumentChange.Insert("text", SourceLocation.MinValue) + }) }); + + Assert.AreEqual("text", doc.Text.ToString()); + + try { + doc.Update(new[] { new DocumentChangeSet(1, 0, new[] { + DocumentChange.Delete(SourceLocation.MinValue, SourceLocation.MinValue.AddColumns(4)) + }) }); + Assert.Fail("expected InvalidOperationException"); + } catch (InvalidOperationException) { + } + Assert.AreEqual("text", doc.Text.ToString()); + Assert.AreEqual(1, doc.Version); + + doc.Update(new[] { new DocumentChangeSet(1, 0, new[] { + new DocumentChange { WholeBuffer = true } + }) }); + + Assert.AreEqual("", doc.Text.ToString()); + Assert.AreEqual(0, doc.Version); + } + } +} diff --git a/src/Analysis/Ast/Test/ExpressionsTests.cs b/src/Analysis/Ast/Test/ExpressionsTests.cs new file mode 100644 index 000000000..01eb942c8 --- /dev/null +++ b/src/Analysis/Ast/Test/ExpressionsTests.cs @@ -0,0 +1,277 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ExpressionsTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task ConstantMathV2() { + const string code = @" +a = 1. + 2. + 3. # no type info for a, b or c +b = 1 + 2. + 3. +c = 1. + 2 + 3. +d = 1. + 2. + 3 # d is 'int', should be 'float' +e = 1 + 1L # e is a 'float', should be 'long' under v2.x (error under v3.x) +f = 1 / 2 # f is 'int', should be 'float' under v3.x"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Float) + .And.HaveVariable("b").OfType(BuiltinTypeId.Float) + .And.HaveVariable("c").OfType(BuiltinTypeId.Float) + .And.HaveVariable("d").OfType(BuiltinTypeId.Float) + .And.HaveVariable("e").OfType(BuiltinTypeId.Long) + .And.HaveVariable("f").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task ConstantMathV3() { + const string code = @" +a = 1. + 2. + 3. # no type info for a, b or c +b = 1 + 2. + 3. +c = 1. + 2 + 3. +d = 1. + 2. + 3 # d is 'int', should be 'float' +f = 1 / 2 # f is 'int', should be 'float' under v3.x"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Float) + .And.HaveVariable("b").OfType(BuiltinTypeId.Float) + .And.HaveVariable("c").OfType(BuiltinTypeId.Float) + .And.HaveVariable("d").OfType(BuiltinTypeId.Float) + .And.HaveVariable("f").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task StringMultiplyV2() { + const string code = @" +x = u'abc %d' +y = x * 100 + +x1 = 'abc %d' +y1 = x1 * 100 + +fob = 'abc %d'.lower() +oar = fob * 100 + +fob2 = u'abc' + u'%d' +oar2 = fob2 * 100"; ; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Unicode) + .And.HaveVariable("y").OfType(BuiltinTypeId.Unicode) + .And.HaveVariable("x1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar").OfType(BuiltinTypeId.Str) + .And.HaveVariable("fob2").OfType(BuiltinTypeId.Unicode) + .And.HaveVariable("oar2").OfType(BuiltinTypeId.Unicode); + } + + [TestMethod, Priority(0)] + public async Task StringMultiplyV3() { + const string code = @" +x = u'abc %d' +y = x * 100 + + +x1 = 'abc %d' +y1 = x1 * 100 + +fob = 'abc %d'.lower() +oar = fob * 100 + +fob2 = u'abc' + u'%d' +oar2 = fob2 * 100"; ; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("x1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar").OfType(BuiltinTypeId.Str) + .And.HaveVariable("fob2").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar2").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task StringConcatenation() { + const string code = @" +x = u'abc' +y = x + u'dEf' + +x1 = 'abc' +y1 = x1 + 'def' + +fob = 'abc'.lower() +oar = fob + 'Def' + +fob2 = u'ab' + u'cd' +oar2 = fob2 + u'ef'"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Unicode) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar2").OfType(BuiltinTypeId.Unicode); + } + + [TestMethod, Priority(0)] + public async Task StringFormattingV2() { + const string code = @" +x = u'abc %d' +y = x % (42, ) + +x1 = 'abc %d' +y1 = x1 % (42, ) + +fob = 'abc %d'.lower() +oar = fob % (42, ) + +fob2 = u'abc' + u'%d' +oar2 = fob2 % (42, ) +"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Unicode) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar").OfType(BuiltinTypeId.Str) + .And.HaveVariable("oar2").OfType(BuiltinTypeId.Unicode); + } + + [TestMethod, Priority(0)] + public async Task StringFormattingV3() { + var code = @" +y = f'abc {42}' +ry = rf'abc {42}' +yr = fr'abc {42}' +fadd = f'abc{42}' + f'{42}' + +def f(val): + print(val) +f'abc {f(42)}' +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("ry").OfType(BuiltinTypeId.Str) + .And.HaveVariable("yr").OfType(BuiltinTypeId.Str) + .And.HaveVariable(@"fadd").OfType(BuiltinTypeId.Str); + // TODO: Enable analysis of f-strings + // .And.HaveVariable("val", BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task RangeIteration() { + const string code = @" +for i in range(5): + pass +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("i") + .Which.Should().HaveType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task Sum() { + const string code = @" +s = sum(i for i in [0,1]) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("s") + .Which.Should().HaveType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task NotOperator() { + const string code = @" +class C(object): + def __nonzero__(self): + pass + + def __bool__(self): + pass + +a = not C() +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + public async Task SequenceConcat() { + const string code = @" +x1 = () +y1 = x1 + () +y1v = y1[0] + +x2 = (1,2,3) +y2 = x2 + (4.0,5.0,6.0) +y2v = y2[0] + +x3 = [1,2,3] +y3 = x3 + [4.0,5.0,6.0] +y3v = y3[0] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x1").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("y1").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("y1v").WithNoTypes() + .And.HaveVariable("y2").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("y2v").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y3").OfType(BuiltinTypeId.List) + .And.HaveVariable("y3v").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task SequenceMultiply() { + var code = @" +x = () +y = x * 100 + +x1 = (1,2,3) +y1 = x1 * 100 + +fob = [1,2,3] +oar = fob * 100 + +fob2 = [] +oar2 = fob2 * 100"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("y").OfType("tuple") + .And.HaveVariable("y1").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("oar").OfType("list") + .And.HaveVariable("oar2").OfType(BuiltinTypeId.List); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/AssertionsFactory.cs b/src/Analysis/Ast/Test/FluentAssertions/AssertionsFactory.cs new file mode 100644 index 000000000..21a2a70a4 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/AssertionsFactory.cs @@ -0,0 +1,36 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Diagnostics.CodeAnalysis; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core.Text; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal static class AssertionsFactory { + public static ScopeAssertions Should(this IScope scope) => new ScopeAssertions(scope); + + public static MemberAssertions Should(this IMember member) => new MemberAssertions(member); + public static PythonFunctionAssertions Should(this IPythonFunctionType f) => new PythonFunctionAssertions(f); + public static PythonFunctionOverloadAssertions Should(this IPythonFunctionOverload f) => new PythonFunctionOverloadAssertions(f); + public static ParameterAssertions Should(this IParameterInfo p) => new ParameterAssertions(p); + + public static DocumentAnalysisAssertions Should(this IDocumentAnalysis analysis) => new DocumentAnalysisAssertions(analysis); + public static VariableAssertions Should(this IVariable v) => new VariableAssertions(v); + + public static RangeAssertions Should(this Range? range) => new RangeAssertions(range); + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/AssertionsUtilities.cs b/src/Analysis/Ast/Test/FluentAssertions/AssertionsUtilities.cs new file mode 100644 index 000000000..96e708c9e --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/AssertionsUtilities.cs @@ -0,0 +1,239 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentAssertions; +using FluentAssertions.Execution; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal static class AssertionsUtilities { + public static bool Is3X(IScope scope) + => scope.GlobalScope.Module.Interpreter.LanguageVersion.Is3x(); + + public static void AssertTypeIds( + IEnumerable actualTypeIds, + IEnumerable typeIds, + string name, bool languageVersionIs3X, string because, + object[] reasonArgs, string itemNameSingle = "type", string itemNamePlural = "types") { + var expected = typeIds.Select(t => { + switch (t) { + case BuiltinTypeId.Str: + return languageVersionIs3X ? BuiltinTypeId.Unicode : BuiltinTypeId.Bytes; + case BuiltinTypeId.StrIterator: + return languageVersionIs3X ? BuiltinTypeId.UnicodeIterator : BuiltinTypeId.BytesIterator; + default: + return t; + } + }).ToArray(); + + var actual = actualTypeIds.ToArray(); + var errorMessage = GetAssertCollectionOnlyContainsMessage(actual, expected, name, itemNameSingle, itemNamePlural); + + Execute.Assertion.ForCondition(errorMessage == null) + .BecauseOf(because, reasonArgs) + .FailWith(errorMessage); + } + + + public static string GetAssertMessage(T actual, T expected, string name) + => !actual.Equals(expected) ? $"Expected {name} to have '{expected}'{{reason}}, but it has {actual}." : null; + + public static string GetAssertCollectionContainsMessage(T[] actual, T[] expected, string name, string itemNameSingle, string itemNamePlural, Func itemsFormatter = null) { + itemsFormatter = itemsFormatter ?? AssertCollectionDefaultItemsFormatter; + var missing = expected.Except(actual).ToArray(); + + if (missing.Length > 0) { + return expected.Length > 1 + ? $"Expected {name} to have {itemNamePlural} {itemsFormatter(expected)}{{reason}}, but it has {itemsFormatter(actual)}, which doesn't include {itemsFormatter(missing)}." + : expected.Length > 0 + ? $"Expected {name} to have {itemNameSingle} '{expected[0]}'{{reason}}, but it has {itemsFormatter(actual)}." + : $"Expected {name} to have no {itemNamePlural}{{reason}}, but it has {itemsFormatter(actual)}."; + } + + return null; + } + + public static string GetAssertCollectionNotContainMessage(T[] actual, T[] expectedMissing, string name, string itemNameSingle, string itemNamePlural, Func itemsFormatter = null) { + itemsFormatter = itemsFormatter ?? AssertCollectionDefaultItemsFormatter; + var intersect = expectedMissing.Intersect(actual).ToArray(); + + if (intersect.Length > 0) { + return expectedMissing.Length > 1 + ? $"Expected {name} to not contain {itemNamePlural} {itemsFormatter(expectedMissing)}{{reason}}, but it contains {itemsFormatter(intersect)}." + : $"Expected {name} to not contain {itemNameSingle} '{expectedMissing[0]}'{{reason}}."; + } + + return null; + } + + public static string GetAssertCollectionOnlyContainsMessage(T[] actual, T[] expected, string name, string itemNameSingle, string itemNamePlural, Func itemsFormatter = null) { + itemsFormatter = itemsFormatter ?? AssertCollectionDefaultItemsFormatter; + var message = GetAssertCollectionContainsMessage(actual, expected, name, itemNameSingle, itemNamePlural, itemsFormatter); + + if (message != null) { + return message; + } + + var excess = expected.Length > 0 ? actual.Except(expected).ToArray() : actual; + if (excess.Length > 0) { + return expected.Length > 1 + ? $"Expected {name} to have only {itemNamePlural} {itemsFormatter(expected)}{{reason}}, but it also has {itemsFormatter(excess)}." + : expected.Length > 0 + ? $"Expected {name} to have only {itemNameSingle} '{expected[0]}'{{reason}}, but it also has {itemsFormatter(excess)}." + : $"Expected {name} to have no {itemNamePlural}{{reason}}, but it has {itemsFormatter(excess)}."; + } + + return null; + } + + public static string GetAssertSequenceEqualMessage(T[] actual, T[] expected, string name, string itemNamePlural, Func itemsFormatter = null) { + itemsFormatter = itemsFormatter ?? AssertCollectionDefaultItemsFormatter; + + for (var i = 0; i < actual.Length && i < expected.Length; i++) { + if (!Equals(actual[i], expected[i])) { + return $"Expected {name} to have {itemNamePlural} {itemsFormatter(expected)}{{reason}}, but it has {itemsFormatter(actual)}, which is different at {i}: '{actual[i]}' instead of '{expected[i]}'."; + } + } + + if (actual.Length > expected.Length) { + return $"Expected {name} to have {itemNamePlural} {itemsFormatter(expected)}{{reason}}, but it also has {itemsFormatter(actual.Skip(expected.Length).ToArray())} at the end."; + } + + if (expected.Length > actual.Length) { + return $"Expected {name} to have {itemNamePlural} {itemsFormatter(expected)}{{reason}}, but it misses {itemsFormatter(expected.Skip(actual.Length).ToArray())} at the end."; + } + + return null; + } + + public static string AssertCollectionDefaultItemsFormatter(T[] items) + => items.Length > 1 + ? "[{0}]".FormatInvariant(string.Join(", ", items)) + : items.Length == 1 ? $"'{items[0]}'" : "none"; + + public static string GetQuotedNames(IEnumerable values) { + return GetQuotedNames(values.Select(GetName)); + } + + public static string GetQuotedNames(IEnumerable names) { + var sb = new StringBuilder(); + string previousName = null; + foreach (var name in names) { + sb.AppendQuotedName(previousName, ", "); + previousName = name; + } + + sb.AppendQuotedName(previousName, " and "); + return sb.ToString(); + } + + private static StringBuilder AppendQuotedName(this StringBuilder stringBuilder, string name, string prefix) { + if (!string.IsNullOrEmpty(name)) { + if (stringBuilder.Length > 0) { + stringBuilder.Append(prefix); + } + + stringBuilder + .Append("'") + .Append(name) + .Append("'"); + } + + return stringBuilder; + } + + public static string GetQuotedName(object value) { + string name; + switch (value) { + case IHasQualifiedName _: + case IPythonModule _: + name = GetName(value); + return string.IsNullOrEmpty(name) ? string.Empty : $"'{name}'"; + default: + name = GetName(value); + return string.IsNullOrEmpty(name) ? string.Empty : $"'{name}'"; + } + } + + public static string GetName(object value) { + switch (value) { + case IHasQualifiedName qualifiedName: + return qualifiedName.FullyQualifiedName; + case IPythonModule pythonModule: + return pythonModule.Name; + case IScope scope: + return scope.Name; + case string str: + return str; + default: + return string.Empty; + } + } + + public static bool RangeEquals(Range r1, Range r2) => PositionEquals(r1.start, r2.start) && PositionEquals(r1.end, r2.end); + public static bool PositionEquals(Position p1, Position p2) => p1.line == p2.line && p1.character == p2.character; + + public static string DoubleEscape(string input) + => input.Replace("\r", "\\\u200Br").Replace("\n", "\\\u200Bn").Replace("\t", @"\t"); + + [CustomAssertion] + public static Continuation AssertIsNotNull(this AssertionScope assertionScope, T instance, string subjectName, string itemName, string accessorName) + where T : class + => assertionScope.ForCondition(!(instance is null)) + .FailWith($"Expected {subjectName} to have {itemName}{{reason}}, but {accessorName} is null."); + + [CustomAssertion] + public static Continuation AssertAtIndex(this AssertionScope assertionScope, IReadOnlyList collection, int index, string subjectName, string itemName) + where T : class => assertionScope.ForCondition(collection.Count > index) + .FailWith($"Expected {subjectName} to have {itemName} of type {typeof(T).Name} at index {index}{{reason}}, but collection has only {collection.Count} items.", subjectName, itemName) + .Then + .ForCondition(collection[index] is TItem) + .FailWith($"Expected {subjectName} to have {itemName} of type `{typeof(T).Name}` at index {index}{{reason}}, but its type is `{collection[index].GetType().Name}`."); + + [CustomAssertion] + public static Continuation AssertHasMember(this AssertionScope assertionScope, IMember m, string memberName, string analysisValueName, string memberPrintName, out IMember member) { + var t = m.GetPythonType(); + t.Should().BeAssignableTo(); + try { + member = ((IMemberContainer)m).GetMember(memberName); + } catch (Exception e) { + member = null; + return assertionScope.FailWith($"Expected {analysisValueName} to have a {memberPrintName}{{reason}}, but {nameof(t.GetMember)} has failed with exception: {e}."); + } + + return assertionScope.ForCondition(!(member is null)) + .FailWith($"Expected {analysisValueName} to have a {memberPrintName}{{reason}}."); + } + + [CustomAssertion] + public static Continuation AssertHasMemberOfType(this AssertionScope assertionScope, IPythonType type, string memberName, string analysisValueName, string memberPrintName, out TMember typedMember) + where TMember : class, IPythonType { + var continuation = assertionScope.AssertHasMember(type, memberName, analysisValueName, memberPrintName, out var member) + .Then + .ForCondition(member is TMember) + .FailWith($"Expected {analysisValueName} to have a {memberPrintName} of type {typeof(TMember)}{{reason}}, but its type is {member.GetType()}."); + typedMember = member as TMember; + return continuation; + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/DocumentAnalysisAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/DocumentAnalysisAssertions.cs new file mode 100644 index 000000000..6f04641b6 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/DocumentAnalysisAssertions.cs @@ -0,0 +1,77 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using FluentAssertions; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal sealed class DocumentAnalysisAssertions : ReferenceTypeAssertions { + private readonly ScopeAssertions _scopeAssertions; + + public DocumentAnalysisAssertions(IDocumentAnalysis analysis) { + Subject = analysis; + _scopeAssertions = new ScopeAssertions(Subject.GlobalScope); + } + + protected override string Identifier => nameof(IDocumentAnalysis); + + public AndWhichConstraint HaveFunction(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + var constraint = _scopeAssertions.HaveFunction(name, because, reasonArgs); + return new AndWhichConstraint(this, constraint.Which); + } + + public AndWhichConstraint HaveClass(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + var constraint = _scopeAssertions.HaveClass(name, because, reasonArgs); + return new AndWhichConstraint(this, constraint.Which); + } + + public AndWhichConstraint HaveVariable(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + var constraint = _scopeAssertions.HaveVariable(name, because, reasonArgs); + return new AndWhichConstraint(this, constraint.Which); + } + + public AndConstraint HaveClassVariables(params string[] classNames) + => HaveClassVariables(classNames, string.Empty); + + public AndConstraint HaveClassVariables(IEnumerable classNames, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + _scopeAssertions.HaveClassVariables(classNames, because, reasonArgs); + return new AndConstraint(this); + } + + public AndConstraint HaveFunctionVariables(params string[] functionNames) + => HaveFunctionVariables(functionNames, string.Empty); + + public AndConstraint HaveFunctionVariables(IEnumerable functionNames, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + _scopeAssertions.HaveFunctionVariables(functionNames, because, reasonArgs); + return new AndConstraint(this); + } + + public AndConstraint NotHaveVariable(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + _scopeAssertions.NotHaveVariable(name, because, reasonArgs); + return new AndConstraint(this); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/MemberAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/MemberAssertions.cs new file mode 100644 index 000000000..6d18b1104 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/MemberAssertions.cs @@ -0,0 +1,159 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; +using static Microsoft.Python.Analysis.Tests.FluentAssertions.AssertionsUtilities; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal class MemberAssertions : ReferenceTypeAssertions { + private IPythonType Type { get; } + public MemberAssertions(IMember member) { + Subject = member; + Type = Subject.GetPythonType(); + } + + protected override string Identifier => nameof(IMember); + + public AndWhichConstraint HaveClass(string name, string because = "", params object[] reasonArgs) + => HaveMember(name, because, reasonArgs).OfMemberType(PythonMemberType.Class); + + public AndWhichConstraint HaveFunction(string name, string because = "", params object[] reasonArgs) + => HaveMember(name, because, reasonArgs).OfMemberType(PythonMemberType.Function); + + public AndWhichConstraint HaveProperty(string name, string because = "", params object[] reasonArgs) + => HaveMember(name, because, reasonArgs).OfMemberType(PythonMemberType.Property); + + public AndWhichConstraint HaveReadOnlyProperty(string name, string because = "", params object[] reasonArgs) { + var constraint = HaveProperty(name, because, reasonArgs); + Execute.Assertion.ForCondition(constraint.Which.IsReadOnly) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName(Subject)} to have a property {name} which is read-only{{reason}}, but it is writable."); + + return constraint; + } + + public AndWhichConstraint HaveDocumentation(string documentation, string because = "", params object[] reasonArgs) { + var t = Subject.GetPythonType(); + Execute.Assertion.ForCondition(t.Documentation == documentation) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName(t)} to have documentation {documentation}, but it has {t.Documentation}."); + + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveMethod(string name, string because = "", params object[] reasonArgs) + => HaveMember(name, because, reasonArgs).OfMemberType(PythonMemberType.Method); + + public AndWhichConstraint HaveMember(string name, + string because = "", params object[] reasonArgs) + where TMember : class, IMember { + NotBeNull(); + + var t = Subject.GetPythonType(); + var mc = (IMemberContainer) t; + Execute.Assertion.ForCondition(mc != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName(t)} to be a member container{{reason}}."); + + var member = mc.GetMember(name); + var typedMember = member as TMember; + Execute.Assertion.ForCondition(member != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName(t)} to have a member {name}{{reason}}.") + .Then + .ForCondition(typedMember != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName(t)} to have a member {name} of type {typeof(TMember)}{{reason}}, but its type is {member?.GetType()}."); + + return new AndWhichConstraint(this, typedMember); + } + + public AndConstraint HaveSameMembersAs(IMember m) { + m.Should().BeAssignableTo(); + return HaveMembers(((IMemberContainer)m).GetMemberNames(), string.Empty); + } + + public AndConstraint HaveMembers(params string[] memberNames) + => HaveMembers(memberNames, string.Empty); + + public AndConstraint HaveMembers(IEnumerable memberNames, string because = "", params object[] reasonArgs) { + var names = Subject.GetPythonType().GetMemberNames().ToArray(); + var expectedNames = memberNames.ToArray(); + var missingNames = expectedNames.Except(names).ToArray(); + + Execute.Assertion.ForCondition(missingNames.Length == 0) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetQuotedName(Subject)} to have members with names {GetQuotedNames(expectedNames)}{{reason}}, but haven't found {GetQuotedNames(missingNames)}"); + + return new AndConstraint(this); + } + + public AndConstraint NotHaveMembers(params string[] memberNames) + => NotHaveMembers(memberNames, string.Empty); + + public AndConstraint NotHaveMembers(IEnumerable memberNames, string because = "", params object[] reasonArgs) { + var names = Subject.GetPythonType().GetMemberNames(); + var missingNames = memberNames.ToArray(); + var existingNames = names.Intersect(missingNames).ToArray(); + + Execute.Assertion.ForCondition(existingNames.Length == 0) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetQuotedName(Subject)} to have no members with names {GetQuotedNames(missingNames)}{{reason}}, but found {GetQuotedNames(existingNames)}"); + + return new AndConstraint(this); + } + + public AndConstraint HaveType(Type t, string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Type != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetQuotedName(Subject)} to have type{{reason}}"); + Type.Should().BeAssignableTo(t, because, reasonArgs); + return new AndConstraint(this); + } + + public AndConstraint HaveType(BuiltinTypeId typeId, string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Type != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetQuotedName(Subject)} to have type{{reason}}"); + Type.TypeId.Should().Be(typeId, because, reasonArgs); + return new AndConstraint(this); + } + + public AndConstraint HaveType(string typeName, string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Type != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetQuotedName(Subject)} to have type{{reason}}"); + Type.Name.Should().Be(typeName, because, reasonArgs); + return new AndConstraint(this); + } + public AndConstraint HaveNoType(string because = "", params object[] reasonArgs) { + Type.IsUnknown().Should().BeTrue(because, reasonArgs); + return new AndConstraint(this); + } + + public AndConstraint HaveMemberType(PythonMemberType memberType, string because = "", params object[] reasonArgs) { + Subject.MemberType.Should().Be(memberType, because, reasonArgs); + return new AndConstraint(this); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs b/src/Analysis/Ast/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs new file mode 100644 index 000000000..ba960e8dc --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs @@ -0,0 +1,36 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Diagnostics.CodeAnalysis; +using FluentAssertions; +using FluentAssertions.Execution; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal static class MemberContainerAssertionsExtensions { + public static AndWhichConstraint OfMemberType + (this AndWhichConstraint constraint, PythonMemberType memberType, + string because = "", params object[] reasonArgs) + where TMember : IPythonType { + + Execute.Assertion.ForCondition(constraint.Which.MemberType == memberType) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {AssertionsUtilities.GetQuotedName(constraint.Which)} to have type '{memberType}', but found '{constraint.Which.MemberType}'"); + + return new AndWhichConstraint(constraint.And, constraint.Which); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/ParameterAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/ParameterAssertions.cs new file mode 100644 index 000000000..34c0a9105 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/ParameterAssertions.cs @@ -0,0 +1,56 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Diagnostics.CodeAnalysis; +using FluentAssertions; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal class ParameterAssertions : ReferenceTypeAssertions { + public ParameterAssertions(IParameterInfo p) { + Subject = p; + } + + protected override string Identifier => nameof(IParameterInfo); + + public AndWhichConstraint HaveName(string name, string because = "", params object[] reasonArgs) { + Subject.Name.Should().Be(name, because, reasonArgs); + return new AndWhichConstraint(this, Subject.Name); + } + + public AndWhichConstraint HaveType(string name, string because = "", params object[] reasonArgs) { + Subject.Type.Should().NotBeNull(because, reasonArgs); + Subject.Type.Name.Should().Be(name); + return new AndWhichConstraint(this, Subject.Type); + } + public AndWhichConstraint HaveType(BuiltinTypeId typeId, string because = "", params object[] reasonArgs) { + Subject.Type.Should().NotBeNull(because, reasonArgs); + Subject.Type.TypeId.Should().Be(typeId, because, reasonArgs); + return new AndWhichConstraint(this, Subject.Type); + } + + public AndWhichConstraint HaveNoDefaultValue(string because = "", params object[] reasonArgs) { + Subject.DefaultValueString.Should().BeNull(because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + public AndWhichConstraint HaveDefaultValue(string value, string because = "", params object[] reasonArgs) { + Subject.DefaultValueString.Should().Be(value, because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/ParameterAssertionsExtensions.cs b/src/Analysis/Ast/Test/FluentAssertions/ParameterAssertionsExtensions.cs new file mode 100644 index 000000000..71e2f8280 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/ParameterAssertionsExtensions.cs @@ -0,0 +1,42 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using FluentAssertions; +using Microsoft.Python.Analysis.Types; +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal static class ParameterAssertionsExtensions { + public static AndWhichConstraint WithName(this AndWhichConstraint constraint, string name, string because = "", params object[] reasonArgs) { + constraint.Which.Should().HaveName(name, because, reasonArgs); + return constraint; + } + + public static AndWhichConstraint WithType(this AndWhichConstraint constraint, string type, string because = "", params object[] reasonArgs) { + constraint.Which.Should().HaveType(type, because, reasonArgs); + return constraint; + } + + public static AndWhichConstraint WithNoDefaultValue(this AndWhichConstraint constraint, string because = "", params object[] reasonArgs) { + constraint.Which.Should().HaveNoDefaultValue(because, reasonArgs); + return constraint; + } + public static AndWhichConstraint WithDefaultValue(this AndWhichConstraint constraint, string value, string because = "", params object[] reasonArgs) { + constraint.Which.Should().HaveDefaultValue(value, because, reasonArgs); + return constraint; + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/PythonFunctionAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/PythonFunctionAssertions.cs new file mode 100644 index 000000000..cd1d846dd --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/PythonFunctionAssertions.cs @@ -0,0 +1,119 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Linq; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Extensions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using static Microsoft.Python.Analysis.Tests.FluentAssertions.AssertionsUtilities; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal class PythonFunctionAssertions : ReferenceTypeAssertions { + public PythonFunctionAssertions(IPythonFunctionType pythonFunction) { + Subject = pythonFunction; + ScopeDescription = $"in a scope {GetQuotedName(Subject.DeclaringType)}"; + } + + protected override string Identifier => nameof(IPythonFunctionType); + protected string ScopeDescription { get; } + + public AndConstraint BeClassMethod(string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Subject.IsClassMethod) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} to be a class method{{reason}}"); + + return new AndConstraint(this); + } + + public AndConstraint HaveOverloads(string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Subject.Overloads.Any()) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have overloads{{reason}}."); + + return new AndConstraint(this); + } + + public AndConstraint HaveOverloadCount(int count, string because = "", params object[] reasonArgs) { + var overloads = Subject.Overloads.ToArray(); + Execute.Assertion.ForCondition(overloads.Length == count) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have {GetOverloadsString(count)}{{reason}}, but it {GetOverloadsString(overloads.Length)}."); + + return new AndConstraint(this); + } + + public AndWhichConstraint HaveSingleOverload(string because = "", params object[] reasonArgs) { + var overloads = Subject.Overloads.ToArray(); + Execute.Assertion.ForCondition(overloads.Length == 1) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have single overload{{reason}}, but it {GetOverloadsString(overloads.Length)}."); + + return new AndWhichConstraint(this, overloads[0]); + } + + public AndWhichConstraint HaveOverloadAt(int index, string because = "", params object[] reasonArgs) { + var overloads = Subject.Overloads.ToArray(); + Execute.Assertion.ForCondition(overloads.Length > index) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have overload at index {index}{{reason}}, but it {GetOverloadsString(overloads.Length)}."); + + return new AndWhichConstraint(this, overloads[index]); + } + + public AndWhichConstraint HaveParameterAt(int index, string because = "", params object[] reasonArgs) { + var overloads = Subject.Overloads.ToArray(); + Execute.Assertion.ForCondition(overloads.Length == 1) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have a single overload {{reason}}, but it has {GetOverloadsString(overloads.Length)}."); + + var o = overloads[0]; + Execute.Assertion.ForCondition(o.Parameters.Count > index) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have parameter at index {index}{{reason}}, but it only has {GetOverloadsString(o.Parameters.Count)}."); + + var oa = new PythonFunctionOverloadAssertions(o); + return new AndWhichConstraint(oa, o.Parameters[index]); + } + + public AndWhichConstraint HaveVariable(string name, string because = "", params object[] reasonArgs) { + var scope = Subject.GetScope(); + Execute.Assertion.ForCondition(scope != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have associated scope {{reason}}, but it has none."); + + var v = scope.Variables[name]; + Execute.Assertion.ForCondition(v != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {GetName()} to have variable {name} {{reason}}, but it has none."); + + var va = new VariableAssertions(v); + return new AndWhichConstraint(va, v); + } + + + private static string GetOverloadsString(int overloadsCount) + => overloadsCount > 1 + ? $"has {overloadsCount} overloads" + : overloadsCount > 0 + ? "has only one overload" + : "has no overloads"; + + protected virtual string GetName() => $"{GetQuotedName(Subject)} {ScopeDescription}"; + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs new file mode 100644 index 000000000..4d2b9268f --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs @@ -0,0 +1,116 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; +using static Microsoft.Python.Analysis.Tests.FluentAssertions.AssertionsUtilities; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal class PythonFunctionOverloadAssertions : ReferenceTypeAssertions { + public PythonFunctionOverloadAssertions(IPythonFunctionOverload pythonFunctionOverload) { + Subject = pythonFunctionOverload; + } + + protected override string Identifier => nameof(IPythonFunctionOverload); + + public AndWhichConstraint HaveReturnType(string because = "", params object[] reasonArgs) { + var returnType = Subject.GetReturnValue(LocationInfo.Empty, ArgumentSet.Empty); + Execute.Assertion.ForCondition(returnType != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} overload to have a return type{{reason}}, but it has none."); + + return new AndWhichConstraint(this, returnType.GetPythonType()); + } + + public AndWhichConstraint HaveReturnType(BuiltinTypeId typeid, string because = "", params object[] reasonArgs) { + Subject.GetReturnValue(LocationInfo.Empty, ArgumentSet.Empty).GetPythonType().TypeId.Should().Be(typeid); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveDocumentation(string documentation, string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Subject.Documentation == documentation) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} overload to have documentation '{documentation}', but it has '{Subject.Documentation}'."); + + return new AndWhichConstraint(this, Subject.Documentation); + } + + public AndWhichConstraint HaveReturnDocumentation(string documentation, string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Subject.ReturnDocumentation == documentation) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} overload to have a return documentation '{documentation}', but it has '{Subject.ReturnDocumentation}'."); + + return new AndWhichConstraint(this, Subject.ReturnDocumentation); + } + + public AndWhichConstraint HaveName(string name, string because = "", params object[] reasonArgs) { + Subject.Name.Should().Be(name); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveParameterAt(int index, string because = "", params object[] reasonArgs) { + var parameters = Subject.Parameters; + Execute.Assertion.ForCondition(parameters.Count > index) + .BecauseOf(because, reasonArgs) + .FailWith(parameters.Count > 0 + ? $"Expected {Subject.Name} to have parameter at index {index}{{reason}}, but it has only {parameters.Count} parameters." + : $"Expected {Subject.Name} to have parameter at index {index}{{reason}}, but it has none."); + + return new AndWhichConstraint(this, parameters[index]); + } + + public AndWhichConstraint HaveSingleParameter(string because = "", params object[] reasonArgs) { + var parameters = Subject.Parameters; + Execute.Assertion.ForCondition(parameters.Count == 1) + .BecauseOf(because, reasonArgs) + .FailWith(parameters.Count > 0 + ? $"Expected {Subject.Name} overload to have only one parameter{{reason}}, but it has {parameters.Count} parameters." + : $"Expected {Subject.Name} overload to have one parameter{{reason}}, but it has none."); + + return new AndWhichConstraint(this, parameters[0]); + } + + public AndConstraint HaveParameters(params string[] parameters) => HaveParameters(parameters, string.Empty); + + public AndConstraint HaveParameters(IEnumerable parameters, string because = "", params object[] reasonArgs) { + var current = Subject.Parameters.Select(pr => pr.Name).ToArray(); + var expected = parameters.ToArray(); + + var message = GetAssertCollectionOnlyContainsMessage(current, expected, Subject.Name, "parameter", "parameters"); + Execute.Assertion.ForCondition(message == null) + .BecauseOf(because, reasonArgs) + .FailWith(message); + + return new AndConstraint(this); + } + + public AndConstraint HaveNoParameters(string because = "", params object[] reasonArgs) + => HaveParameters(Enumerable.Empty(), because, reasonArgs); + + public AndConstraint HaveReturnType(string type, string because = "", params object[] reasonArgs) { + var returnType = Subject.GetReturnValue(LocationInfo.Empty, ArgumentSet.Empty).GetPythonType(); + Execute.Assertion.ForCondition(string.Equals(returnType.Name, type, StringComparison.Ordinal)) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} to have return type [{type}]{{reason}}, but it has [{returnType}]."); + + return new AndConstraint(this); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/PythonTypeAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/PythonTypeAssertions.cs new file mode 100644 index 000000000..30436c7df --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/PythonTypeAssertions.cs @@ -0,0 +1,67 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using static Microsoft.Python.Analysis.Tests.FluentAssertions.AssertionsUtilities; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal sealed class MemberTestInfo { + private readonly IPythonType _member; + private readonly IScope _scope; + public string Name { get; } + + public MemberTestInfo(IPythonType member, string name, IScope scope) { + _member = member; + Name = name; + _scope = scope; + } + + public PythonTypeAssertions Should() => new PythonTypeAssertions(_member, Name, _scope); + } + + internal sealed class PythonTypeAssertions : ReferenceTypeAssertions { + private readonly string _moduleName; + private readonly string _name; + private readonly IScope _scope; + + public PythonTypeAssertions(IPythonType member, string name, IScope scope) { + Subject = member; + _name = name; + _scope = scope; + _moduleName = scope.Name; + } + + protected override string Identifier => nameof(IPythonType); + + public AndConstraint HaveType(BuiltinTypeId typeId, string because = "", params object[] reasonArgs) { + var languageVersionIs3X = Is3X(_scope); + AssertTypeIds(new[] { Subject.TypeId }, new[] { typeId }, $"{_moduleName}.{_name}", languageVersionIs3X, because, reasonArgs); + + return new AndConstraint(this); + } + + public AndConstraint HaveMemberType(PythonMemberType memberType, string because = "", params object[] reasonArgs) { + Execute.Assertion.ForCondition(Subject is IPythonType m && m.MemberType == memberType) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {_moduleName}.{_name} to be {memberType} {{reason}}."); + + return new AndConstraint(this); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/RangeAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/RangeAssertions.cs new file mode 100644 index 000000000..fed68aad7 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/RangeAssertions.cs @@ -0,0 +1,54 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using FluentAssertions; +using FluentAssertions.Execution; +using Microsoft.Python.Core.Text; +using static Microsoft.Python.Analysis.Tests.FluentAssertions.AssertionsUtilities; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal sealed class RangeAssertions { + public Range? Subject { get; } + + public RangeAssertions(Range? range) { + Subject = range; + } + + public AndConstraint Be(int startLine, int startCharacter, int endLine, int endCharacter, string because = "", params object[] becauseArgs) { + var range = new Range { + start = new Position { + line = startLine, + character = startCharacter + }, + end = new Position { + line = endLine, + character = endCharacter + } + }; + + return Be(range, because, becauseArgs); + } + + public AndConstraint Be(Range range, string because = "", params object[] becauseArgs) { + Execute.Assertion.ForCondition(Subject.HasValue && RangeEquals(Subject.Value, range)) + .BecauseOf(because, becauseArgs) + .FailWith($"Expected range to be {range.ToString()}{{reason}}, but found {SubjectString}."); + + return new AndConstraint(this); + } + + private string SubjectString => Subject.HasValue ? Subject.Value.ToString() : "none"; + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/ScopeAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/ScopeAssertions.cs new file mode 100644 index 000000000..7ddf913ad --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/ScopeAssertions.cs @@ -0,0 +1,120 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal sealed class ScopeAssertions : ScopeAssertions { + public ScopeAssertions(IScope scope) : base(scope) { } + } + + [ExcludeFromCodeCoverage] + internal class ScopeAssertions : ReferenceTypeAssertions + where TScope : IScope + where TScopeAssertions : ScopeAssertions { + + public ScopeAssertions(TScope scope) { + Subject = scope; + } + + protected override string Identifier => nameof(IScope); + + [CustomAssertion] + public AndWhichConstraint OnlyHaveChildScope(string because = "", params object[] reasonArgs) + where TChildScope : IScope => HaveChildScopeAt(0, because, reasonArgs); + + [CustomAssertion] + public AndWhichConstraint HaveChildScopeAt(int index, string because = "", params object[] reasonArgs) + where TChildScope : IScope { + NotBeNull(because, reasonArgs); + var childScopes = Subject.Children; + var subjectName = $"scope '{Subject.Name}'"; + Execute.Assertion.BecauseOf(because, reasonArgs) + .AssertIsNotNull(childScopes, subjectName, $"child scope of type '{typeof(TScope).Name}'", $"'{Subject.Name}.Children'") + .Then + .AssertAtIndex(childScopes, index, subjectName, "child scope"); + + return new AndWhichConstraint((TScopeAssertions)this, (TChildScope)childScopes[index]); + } + + public AndWhichConstraint HaveClass(string name, string because = "", params object[] reasonArgs) { + var v = HaveVariable(name, because, reasonArgs).Which; + v.Value.Should().BeAssignableTo(); + + return new AndWhichConstraint((TScopeAssertions)this, (IPythonClassType)v.Value); + } + + public AndWhichConstraint HaveFunction(string name, string because = "", params object[] reasonArgs) { + var f = HaveVariable(name, because, reasonArgs).Which; + f.Value.Should().BeAssignableTo(); + + return new AndWhichConstraint((TScopeAssertions)this, (IPythonFunctionType)f.Value); + } + + public AndWhichConstraint HaveVariable(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + + var v = Subject.Variables[name]; + Execute.Assertion.ForCondition(v != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected scope '{Subject.Name}' to have variable '{name}'{{reason}}."); + + return new AndWhichConstraint((TScopeAssertions)this, v); + } + + public AndConstraint HaveClassVariables(params string[] classNames) + => HaveClassVariables(classNames, string.Empty); + + public AndConstraint HaveClassVariables(IEnumerable classNames, string because = "", params object[] reasonArgs) { + NotBeNull(); + + foreach (var className in classNames) { + HaveVariable(className, because, reasonArgs).OfType(className, because, reasonArgs); + } + + return new AndConstraint((TScopeAssertions)this); + } + + public AndConstraint HaveFunctionVariables(params string[] functionNames) + => HaveFunctionVariables(functionNames, string.Empty); + + public AndConstraint HaveFunctionVariables(IEnumerable functionNames, string because = "", params object[] reasonArgs) { + Subject.Should().NotBeNull(); + + foreach (var functionName in functionNames) { + HaveVariable(functionName, because, reasonArgs).OfType(functionName, because, reasonArgs); + } + + return new AndConstraint((TScopeAssertions)this); + } + + public AndConstraint NotHaveVariable(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + + Execute.Assertion.ForCondition(Subject.Variables[name] == null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected scope '{Subject.Name}' to have no variable '{name}'{{reason}}."); + + return new AndConstraint((TScopeAssertions)this); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/VariableAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/VariableAssertions.cs new file mode 100644 index 000000000..186daa985 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/VariableAssertions.cs @@ -0,0 +1,139 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal sealed class VariableAssertions : ReferenceTypeAssertions { + public IMember Value { get; } + public VariableAssertions(IVariable v) { + Subject = v; + Value = v.Value; + } + + protected override string Identifier => nameof(IVariable); + + public AndWhichConstraint HaveMemberType(PythonMemberType memberType, string because = "", params object[] reasonArgs) { + Value.Should().HaveMemberType(memberType, because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveType(BuiltinTypeId typeId, string because = "", params object[] reasonArgs) { + Value.Should().HaveType(typeId, because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveType(string because = "", params object[] reasonArgs) { + Value.Should().HaveType(typeof(TType), because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveType(string typeName, string because = "", params object[] reasonArgs) { + Value.Should().HaveType(typeName, because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + + public AndConstraint HaveNoType(string because = "", params object[] reasonArgs) { + Value.Should().HaveNoType(because, reasonArgs); + return new AndConstraint(this); + } + + public AndWhichConstraint HaveMember(string name, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + Value.Should().HaveMember(name, because, reasonArgs); + var m = Value.GetPythonType().GetMember(name); + return new AndWhichConstraint(this, m); + } + + public AndWhichConstraint HaveMembers(IEnumerable names, string because = "", params object[] reasonArgs) { + NotBeNull(because, reasonArgs); + Value.Should().HaveMembers(names, because, reasonArgs); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveMembers(params object[] names) { + NotBeNull(); + Value.Should().HaveMembers(names.OfType()); + return new AndWhichConstraint(this, Subject); + } + + public AndWhichConstraint HaveMember(string name, string because = "", params object[] reasonArgs) + where T: class, IPythonType { + NotBeNull(because, reasonArgs); + Value.Should().HaveMember(name, because, reasonArgs); + var m = Value.GetPythonType().GetMember(name).GetPythonType(); + return new AndWhichConstraint(this, m); + } + + public AndWhichConstraint HaveOverloadWithParametersAt(int index, string because = "", params object[] reasonArgs) { + var constraint = HaveOverloadAt(index); + var overload = constraint.Which; + var function = Value.GetPythonType(); + + Execute.Assertion.ForCondition(function != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} to be a function, but it is {Subject.Value}."); + + Execute.Assertion.ForCondition(overload.Parameters.Count > 0) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected overload at index {index} of {function.DeclaringModule.Name}.{function.Name} to have parameters{{reason}}, but it has none."); + + return constraint; + } + + public AndWhichConstraint HaveOverloadAt(int index, string because = "", params object[] reasonArgs) { + var function = Subject.Value.GetPythonType(); + + Execute.Assertion.ForCondition(function != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} to be a function, but it is {Subject.Value}."); + + var overloads = function.Overloads.ToArray(); + Execute.Assertion.ForCondition(overloads.Length > index) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {function.Name} to have overload at index {index}{{reason}}, but it {GetOverloadsString(overloads.Length)}."); + + return new AndWhichConstraint(this, function.Overloads[index]); + } + + private static string GetOverloadsString(int overloadsCount) + => overloadsCount > 1 + ? $"has {overloadsCount} overloads" + : overloadsCount > 0 + ? "has only one overload" + : "has no overloads"; + + public AndWhichConstraint HaveSingleOverload(string because = "", params object[] reasonArgs) { + var f = Subject.Value.GetPythonType(); + + Execute.Assertion.ForCondition(f != null) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} to be a function{{reason}}, but it is {Subject.Value}."); + + var overloads = f.Overloads.ToArray(); + Execute.Assertion.ForCondition(overloads.Length == 1) + .BecauseOf(because, reasonArgs) + .FailWith($"Expected {Subject.Name} to have single overload{{reason}}, but it {GetOverloadsString(overloads.Length)}."); + + return new AndWhichConstraint(this, overloads[0]); + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/VariableAssertionsExtensions.cs b/src/Analysis/Ast/Test/FluentAssertions/VariableAssertionsExtensions.cs new file mode 100644 index 000000000..055b877e7 --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/VariableAssertionsExtensions.cs @@ -0,0 +1,49 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Diagnostics.CodeAnalysis; +using FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + [ExcludeFromCodeCoverage] + internal static class VariableAssertionsExtensions { + public static AndWhichConstraint OfType( + this AndWhichConstraint andWhichConstraint, BuiltinTypeId typeId, string because = "", params object[] reasonArgs) { + andWhichConstraint.Subject.Value.Should().HaveType(typeId, because, reasonArgs); + return andWhichConstraint; + } + + public static AndWhichConstraint OfType( + this AndWhichConstraint andWhichConstraint, string typeName, string because = "", params object[] reasonArgs) { + andWhichConstraint.Subject.Value.Should().HaveType(typeName, because, reasonArgs); + return andWhichConstraint; + } + + public static AndWhichConstraint OfType( + this AndWhichConstraint andWhichConstraint, Type type, string because = "", params object[] reasonArgs) { + andWhichConstraint.Subject.Value.Should().HaveType(type, because, reasonArgs); + return andWhichConstraint; + } + + public static AndWhichConstraint WithNoTypes( + this AndWhichConstraint andWhichConstraint, string because = "", params object[] reasonArgs) { + andWhichConstraint.Subject.Value.Should().HaveNoType(because, reasonArgs); + return andWhichConstraint; + } + } +} diff --git a/src/Analysis/Ast/Test/FluentAssertions/VariableCollectionAssertions.cs b/src/Analysis/Ast/Test/FluentAssertions/VariableCollectionAssertions.cs new file mode 100644 index 000000000..0f1e439dc --- /dev/null +++ b/src/Analysis/Ast/Test/FluentAssertions/VariableCollectionAssertions.cs @@ -0,0 +1,48 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using FluentAssertions.Execution; +using FluentAssertions.Primitives; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Core; +using static Microsoft.Python.Analysis.Tests.FluentAssertions.AssertionsUtilities; + +namespace Microsoft.Python.Analysis.Tests.FluentAssertions { + internal sealed class VariableCollectionAssertions : ReferenceTypeAssertions { + public VariableCollectionAssertions(IVariableCollection collection) { + Subject = collection; + } + + protected override string Identifier => nameof(IVariableCollection); + + public AndConstraint Contain(params object[] expected) { + var actual = Subject.Select(v => v.Name).ToArray(); + var errorMessage = GetAssertCollectionContainsMessage(actual, expected, "collection", "item", "items"); + + Execute.Assertion.ForCondition(errorMessage == null) + .BecauseOf(string.Empty, string.Empty) + .FailWith(errorMessage); + + return new AndConstraint(this); + } + + + public static string GetAssertMessage(IEnumerable actual, IEnumerable expected, string name) where T : class + => !actual.SetEquals(expected) ? $"Expected collection to contain '{expected}'{{reason}}, but it has {actual}." : null; + } +} diff --git a/src/Analysis/Ast/Test/ForwardReferences.cs b/src/Analysis/Ast/Test/ForwardReferences.cs new file mode 100644 index 000000000..d4e9fa75d --- /dev/null +++ b/src/Analysis/Ast/Test/ForwardReferences.cs @@ -0,0 +1,133 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ForwardReferenceTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task ForwardRefGlobalFunction() { + const string code = @" +def func1(): + return func2() + +def func2(): + return func3() + +def func3(): + return 's' + +x = func1() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ForwardRefFunction1() { + const string code = @" +class A(object): + def methodA(self): + return 's' + +class B(object): + def getA(self): + return self.funcA() + + def funcA(self): + return A() + +x = B().getA().methodA() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ForwardRefFunction2() { + const string code = @" +class A(object): + def methodA(self): + return 's' + +class B(object): + def getA(self): + return self.func1() + + def func1(self): + return self.func2() + + def func2(self): + return self.func3() + + def func3(self): + return A() + +x = B().getA().methodA() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ForwardRefClass() { + const string code = @" +class A: + def funcA(self): + return B().methodB() + +class B: + def methodB(self): + return 's' + +x = A().funcA() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ForwardRefClassMember() { + const string code = @" +class A: + def __init__(self): + self.b = B().methodB() + +class B: + def methodB(self): + return 's' + +x = A().b +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + } +} diff --git a/src/Analysis/Ast/Test/FunctionTests.cs b/src/Analysis/Ast/Test/FunctionTests.cs new file mode 100644 index 000000000..5cca02654 --- /dev/null +++ b/src/Analysis/Ast/Test/FunctionTests.cs @@ -0,0 +1,513 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Analysis.Values; +using Microsoft.Python.Parsing.Tests; +using Microsoft.Python.Tests.Utilities.FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class FunctionTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task Functions() { + var code = await File.ReadAllTextAsync(Path.Combine(GetAnalysisTestDataFilesPath(), "Functions.py")); + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + var mod = analysis.Document; + + mod.GetMemberNames().Should().OnlyContain("f", "f2", "g", "h", "C"); + mod.GetMember("f").Should().BeAssignableTo() + .Which.Documentation.Should().Be("f"); + + mod.GetMember("f2").Should().BeAssignableTo() + .Which.Documentation.Should().Be("f"); + + mod.GetMember("g").Should().BeAssignableTo(); + mod.GetMember("h").Should().BeAssignableTo(); + + var c = mod.GetMember("C").Should().BeAssignableTo().Which; + c.GetMemberNames().Should().OnlyContain("i", "j", "C2", "__class__", "__bases__"); + c.GetMember("i").Should().BeAssignableTo(); + c.GetMember("j").Should().BeAssignableTo(); + c.GetMember("__class__").Should().BeAssignableTo(); + c.GetMember("__bases__").Should().BeAssignableTo(); + + var c2 = c.GetMember("C2").Should().BeAssignableTo().Which; + c2.GetMemberNames().Should().OnlyContain("k", "__class__", "__bases__"); + c2.GetMember("k").Should().BeAssignableTo(); + c2.GetMember("__class__").Should().BeAssignableTo(); + c2.GetMember("__bases__").Should().BeAssignableTo(); + } + + [TestMethod, Priority(0)] + public async Task NamedTupleReturnAnnotation() { + const string code = @" +from typing import NamedTuple + +Point = NamedTuple('Point', ['x', 'y']) + +def f(a, b): + return Point(a, b) + +pt = f(1, 2) +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + var pt = analysis.Should().HaveVariable("pt").Which; + pt.Should().HaveType("Point(x, y)").And.HaveMember("x"); + pt.Should().HaveType("Point(x, y)").And.HaveMember("y"); + } + + [TestMethod, Priority(0)] + public async Task TypeAnnotationConversion() { + const string code = @"from ReturnAnnotations import * +x = f() +y = g()"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("f").OfType(BuiltinTypeId.Function) + .Which.Should().HaveSingleOverload() + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("p").And.HaveType("int").And.HaveNoDefaultValue(); + } + + [TestMethod, Priority(0)] + public async Task ParameterAnnotation() { + const string code = @" +s = None +def f(s: s = 123): + return s +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("s").OfType(BuiltinTypeId.NoneType); + analysis.Should().HaveFunction("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("s").And.HaveType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task ParameterAnnotationLambda() { + const string code = @" +s = None +def f(s: lambda s: s > 0 = 123): + return s +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("s").OfType(BuiltinTypeId.NoneType) + .And.HaveFunction("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("s").And.HaveType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task ReturnValueEval() { + const string code = @" +def f(a, b): + return a + b + +x = f('x', 'y') +y = f(1, 2) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should() + .HaveVariable("x").OfType(BuiltinTypeId.Str).And + .HaveVariable("y").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task ReturnValueAnnotated() { + const string code = @" +def f(a, b) -> str: + return a + b + +x = f('x', 'y') +y = f(1, 2) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveReturnType(BuiltinTypeId.Str); + + analysis.Should() + .HaveVariable("x").OfType(BuiltinTypeId.Str).And + .HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task BadMethod() { + const string code = @" +class cls(object): + def f(): + 'help' + return 42 + +abc = cls() +fob = abc.f() +"; + + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("fob").OfType(BuiltinTypeId.Int); + analysis.Should().HaveClass("cls") + .Which.Should().HaveMethod("f") + .Which.Documentation.Should().Be("help"); + } + + [TestMethod, Priority(0)] + public async Task Specializations() { + const string code = @" +class C: + pass + +a = ord('a') +b = abs(5) +c = abs(5.0) +d = eval('') +e = isinstance(d) +f = pow(1) +g = pow(3.0) +h = type(C()) +i = h() + +x = dir() +v = x[0] + +va = vars() +kv = va.keys()[0] +vv = va['a'] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("c").OfType(BuiltinTypeId.Float) + .And.HaveVariable("d").OfType(BuiltinTypeId.Object) + .And.HaveVariable("e").OfType(BuiltinTypeId.Bool) + .And.HaveVariable("f").OfType(BuiltinTypeId.Int) + .And.HaveVariable("g").OfType(BuiltinTypeId.Float) + .And.HaveVariable("h").OfType(BuiltinTypeId.Type) + .And.HaveVariable("i").OfType("C") + .And.HaveVariable("x").OfType("List[str]") + .And.HaveVariable("v").OfType(BuiltinTypeId.Str) + .And.HaveVariable("va").OfType("Dict[str, object]") + .And.HaveVariable("kv").OfType(BuiltinTypeId.Str) + .And.HaveVariable("vv").OfType(BuiltinTypeId.Object); + } + + [TestMethod, Priority(0)] + public async Task Defaults() { + const string code = @" +def f(x = 42): + return x + +a = f() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task OverrideFunction() { + const string code = @" +class oar(object): + def Call(self, xvar, yvar): + return xvar + +class baz(oar): + def Call(self, xvar, yvar): + return 42 + +class Cxxxx(object): + def __init__(self): + self.b = baz() + self.o = oar() + + def CmethB(self, avar, bvar): + return self.b.Call(avar, bvar) + + def CmethO(self, avar, bvar): + return self.o.Call(avar, bvar) + +abc = Cxxxx() +a = abc.CmethB(['fob'], 'oar') +b = abc.CmethO(['fob'], 'oar') +"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.List); + } + + [TestMethod, Priority(0)] + public async Task Decorators() { + const string code = @" +class cls(object): + @property + def a(self): pass + + @staticmethod + def b(): pass + + @abstractproperty + def c(self): pass + + @classmethod + def d(cls): pass + + @abstractclassmethod + def e(cls): pass +"; + + var analysis = await GetAnalysisAsync(code); + var cls = analysis.Should().HaveClass("cls").Which; + + var a = cls.Should().HaveProperty("a").Which; + a.IsAbstract.Should().BeFalse(); + a.IsReadOnly.Should().BeTrue(); + + var b = cls.Should().HaveMethod("b").Which; + b.IsAbstract.Should().BeFalse(); + b.IsStatic.Should().BeTrue(); + + var c = cls.Should().HaveProperty("c").Which; + c.IsAbstract.Should().BeTrue(); + c.IsReadOnly.Should().BeTrue(); + + var d = cls.Should().HaveMethod("d").Which; + d.IsAbstract.Should().BeFalse(); + d.IsStatic.Should().BeFalse(); + d.IsClassMethod.Should().BeTrue(); + + var e = cls.Should().HaveMethod("e").Which; + e.IsAbstract.Should().BeTrue(); + e.IsStatic.Should().BeFalse(); + e.IsClassMethod.Should().BeTrue(); + } + + [TestMethod, Priority(0)] + public async Task OverloadsParamTypeMatch() { + const string code = @" + +def f(a: bool) -> None: ... +def f(a: int) -> float: ... +def f(a: str) -> bytes: ... + +a = True +x = f(a) +y = f(1) +z = f('s') +"; + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveFunction("f").Which; + + f.Should().HaveOverloadAt(0) + .Which.Should().HaveReturnType(BuiltinTypeId.NoneType) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Bool); + + f.Should().HaveOverloadAt(1) + .Which.Should().HaveReturnType(BuiltinTypeId.Float) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Int); + + f.Should().HaveOverloadAt(2) + .Which.Should().HaveReturnType(BuiltinTypeId.Bytes) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Str); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.NoneType) + .And.HaveVariable("y").OfType(BuiltinTypeId.Float) + .And.HaveVariable("z").OfType(BuiltinTypeId.Bytes); + } + + [TestMethod, Priority(0)] + public async Task ReturnFunc() { + const string code = @" +def g(): + return [] + +def f(): + return g + +x = f()() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.List); + } + + [TestMethod, Priority(0)] + public async Task MultipleReturnTypes() { + const string code = @" +def f(): + if True: + return 1 + if False: + return 'a' + +x = f() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveReturnType("Union[int, str]"); + analysis.Should().HaveVariable("x").OfType("Union[int, str]"); + } + + [TestMethod, Priority(0)] + public async Task ParameterDefaults() { + const string code = @" +def f(x = None): pass +def g(x = {}): pass +def h(x = {2:3}): pass +def i(x = []): pass +def j(x = [None]): pass +def k(x = ()): pass +def l(x = (2, )): pass +def m(x = math.atan2(1,0)): pass +"; + var analysis = await GetAnalysisAsync(code); + var tests = new[] { + new { FuncName = "f", DefaultValue = "None" }, + new { FuncName = "g", DefaultValue = "{}" }, + new { FuncName = "h", DefaultValue = "{2:3}" }, + new { FuncName = "i", DefaultValue = "[]" }, + new { FuncName = "j", DefaultValue="[None]" }, + new { FuncName = "k", DefaultValue = "()" }, + new { FuncName = "l", DefaultValue = "(2)" }, + new { FuncName = "m", DefaultValue = "math.atan2(1,0)" }, + }; + + foreach (var test in tests) { + analysis.Should().HaveFunction(test.FuncName) + .Which.Should().HaveSingleOverload() + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("x").And.HaveDefaultValue(test.DefaultValue); + } + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task SpecializedOverride() { + const string code = @" +class simpledict(dict): pass + +class getdict(dict): + def __getitem__(self, index): + return 'abc' + + +d1 = simpledict({2:3}) +x1 = d1[2] + +d2 = simpledict(x = 2) +x2 = d2['x'] + +d3 = simpledict(**{2:3}) +x3 = d3[2] + +d4 = getdict({2:3}) +x4 = d4[2] + +d5 = simpledict(**{2:'blah'}) +x5 = d5[2] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x1").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x2").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x3").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x4").OfType(BuiltinTypeId.Str) + .And.HaveVariable("x5").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ReturnArg() { + const string code = @" +def g(a): + return a + +x = g(1) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task ReturnArgNestedFunction() { + const string code = @" + +def f(a): + def g(): + return a + return g + +x = f(2)() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int); + } + + // Verifies that constructing lists / tuples from more lists/tuples doesn't cause an infinite analysis as we keep creating more lists/tuples. + [TestMethod, Priority(0)] + public async Task ListRecursion() { + const string code = @" +def f(x): + print abc + return f(list(x)) + +abc = f(()) +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("abc"); + } + + [TestMethod, Priority(0)] + public async Task ReturnExpressionOnArg() { + const string code = @" +class C: + x = 123 +class D: + x = 3.14 + +def f(v): + return v.x + +c = f(C()) +d = f(D())"; + + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("c").OfType(BuiltinTypeId.Int) + .And.HaveVariable("d").OfType(BuiltinTypeId.Float); + } + } +} diff --git a/src/Analysis/Ast/Test/ImportTests.cs b/src/Analysis/Ast/Test/ImportTests.cs new file mode 100644 index 000000000..afa93f2a2 --- /dev/null +++ b/src/Analysis/Ast/Test/ImportTests.cs @@ -0,0 +1,163 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Tests; +using Microsoft.Python.Tests.Utilities.FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ImportTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task FromImportValues() { + var analysis = await GetAnalysisAsync("from Values import *"); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("z").OfType(BuiltinTypeId.Bytes) + .And.HaveVariable("pi").OfType(BuiltinTypeId.Float) + .And.HaveVariable("l").OfType(BuiltinTypeId.List) + .And.HaveVariable("t").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("d").OfType(BuiltinTypeId.Dict) + .And.HaveVariable("s").OfType(BuiltinTypeId.Set) + .And.HaveVariable("X").OfType(BuiltinTypeId.Int) + .And.HaveVariable("Y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("Z").OfType(BuiltinTypeId.Bytes) + .And.HaveVariable("PI").OfType(BuiltinTypeId.Float) + .And.HaveVariable("L").OfType(BuiltinTypeId.List) + .And.HaveVariable("T").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("D").OfType(BuiltinTypeId.Dict) + .And.HaveVariable("S").OfType(BuiltinTypeId.Set); + } + + [TestMethod, Priority(0)] + public async Task FromImportMultiValues() { + var analysis = await GetAnalysisAsync("from MultiValues import *"); + + // TODO: track assignments and type changes by position + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("z").OfType(BuiltinTypeId.Bytes) + .And.HaveVariable("l").OfType(BuiltinTypeId.List) + .And.HaveVariable("t").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("s").OfType(BuiltinTypeId.Set) + .And.HaveVariable("XY").OfType(BuiltinTypeId.Str) + .And.HaveVariable("XYZ").OfType(BuiltinTypeId.Str) + .And.HaveVariable("D").OfType(BuiltinTypeId.Dict); + } + + [TestMethod, Priority(0)] + public async Task FromImportSpecificValues() { + var analysis = await GetAnalysisAsync("from Values import D"); + analysis.Should().HaveVariable("D").OfType(BuiltinTypeId.Dict); + } + + [TestMethod, Priority(0)] + public async Task ImportNonExistingModule() { + var code = await File.ReadAllTextAsync(Path.Combine(GetAnalysisTestDataFilesPath(), "Imports.py")); + var analysis = await GetAnalysisAsync(code); + + analysis.GlobalScope.Variables.Names.Should().OnlyContain("version_info", "a_made_up_module"); + } + + [TestMethod, Priority(0)] + public async Task FromImportReturnTypes() { + const string code = @"from ReturnValues import * +R_str = r_str() +R_object = r_object() +R_A1 = A() +R_A2 = A().r_A() +R_A3 = R_A1.r_A()"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveFunctionVariables("r_a", "r_b", "r_str", "r_object") + .And.HaveClassVariables("A") + .And.HaveVariable("R_str").OfType(BuiltinTypeId.Str) + .And.HaveVariable("R_object").OfType(BuiltinTypeId.Object) + .And.HaveVariable("R_A1").OfType("A") + .And.HaveVariable("R_A2").OfType("A") + .And.HaveVariable("R_A3").OfType("A"); + } + [TestMethod, Priority(0)] + public async Task BuiltinImport() { + var analysis = await GetAnalysisAsync(@"import sys"); + + analysis.Should().HaveVariable("sys") + .Which.Should().HaveType(BuiltinTypeId.Module) + .And.HaveMember("platform"); + } + + [TestMethod, Priority(0)] + public async Task BuiltinImportInClass() { + const string code = @" +class C: + import sys +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveClass("C") + .Which.Should().HaveMember("sys") + .Which.Should().HaveMember("platform"); + } + + [TestMethod, Priority(0)] + public async Task BuiltinImportInFunc() { + const string code = @" +def f(): + import sys + return sys.path + +x = f() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.List); + } + + [TestMethod, Priority(0)] + public async Task ImportAs() { + var analysis = await GetAnalysisAsync(@"import sys as s, array as a", PythonVersions.LatestAvailable3X); + + analysis.Should().HaveVariable("s") + .Which.Should().HaveType() + .Which.Should().HaveMember("platform"); + + analysis.Should().HaveVariable("a") + .Which.Should().HaveType() + .Which.Should().HaveMember("ArrayType"); + } + + [TestMethod, Priority(0)] + public async Task OsPathMembers() { + var analysis = await GetAnalysisAsync(@"import os.path as P"); + analysis.Should().HaveVariable("P") + .Which.Should().HaveMembers(@"abspath", @"dirname"); + } + } +} diff --git a/src/Analysis/Ast/Test/InheritanceTests.cs b/src/Analysis/Ast/Test/InheritanceTests.cs new file mode 100644 index 000000000..79df8a128 --- /dev/null +++ b/src/Analysis/Ast/Test/InheritanceTests.cs @@ -0,0 +1,96 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class InheritanceTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void TestCleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task BaseFunctionCall() { + const string code = @" +class Baze: + def foo(self, x): + return 'base' + +class Derived(Baze): + def foo(self, x): + return x + +y = Baze().foo(42.0) +"; + + var analysis = await GetAnalysisAsync(code); + // the class, for which we know parameter type initially + analysis.Should().HaveClass(@"Baze") + .Which.Should().HaveMethod("foo") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(1) + .Which.Should().HaveName("x"); + + // its derived class + analysis.Should().HaveClass("Derived") + .Which.Should().HaveMethod("foo") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(1) + .Which.Should().HaveName("x"); + + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task DerivedFunctionCall() { + const string code = @" +class Baze: + def foo(self, x): + return 'base' + +class Derived(Baze): + def foo(self, x): + return x + +y = Derived().foo(42) +"; + + var analysis = await GetAnalysisAsync(code); + + // the class, for which we know parameter type initially + analysis.Should().HaveClass("Derived").Which.Should().HaveMethod("foo") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(1) + .Which.Should().HaveName("x"); + + // its base class + analysis.Should().HaveClass(@"Baze").Which.Should().HaveMethod("foo") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(1) + .Which.Should().HaveName("x"); + + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Int); + } + } +} diff --git a/src/Analysis/Ast/Test/IteratorTests.cs b/src/Analysis/Ast/Test/IteratorTests.cs new file mode 100644 index 000000000..9734dd38f --- /dev/null +++ b/src/Analysis/Ast/Test/IteratorTests.cs @@ -0,0 +1,183 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading.Tasks; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class IteratorTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task Iterator1_V2() { + const string code = @" +A = [1, 2, 3] +B = 'abc' +C = [1.0, 'a', 3] + +iA = iter(A) +iB = iter(B) +iC = iter(C) + +a = iA.next() +b = iB.next() +c1 = iC.next() +c2 = iC.next() +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + + analysis.Should().HaveVariable("A").OfType(BuiltinTypeId.List) + .And.HaveVariable("B").OfType(BuiltinTypeId.Str) + .And.HaveVariable("C").OfType(BuiltinTypeId.List); + + analysis.Should().HaveVariable("iA").OfType(BuiltinTypeId.ListIterator) + .And.HaveVariable("iB").OfType(BuiltinTypeId.StrIterator) + .And.HaveVariable("iC").OfType(BuiltinTypeId.ListIterator); + + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c1").OfType(BuiltinTypeId.Float) + .And.HaveVariable("c2").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task Iterator2_V2() { + const string code = @" +A = [1, 2, 3] +B = 'abc' +C = [1.0, 'a', 3] + +iA = A.__iter__() +iB = B.__iter__() +iC = C.__iter__() + +a = iA.next() +b = iB.next() +c1 = iC.next() +c2 = iC.next() + +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + + analysis.Should().HaveVariable("A").OfType(BuiltinTypeId.List) + .And.HaveVariable("B").OfType(BuiltinTypeId.Str) + .And.HaveVariable("C").OfType(BuiltinTypeId.List); + + analysis.Should().HaveVariable("iA").OfType(BuiltinTypeId.ListIterator) + .And.HaveVariable("iB").OfType(BuiltinTypeId.StrIterator) + .And.HaveVariable("iC").OfType(BuiltinTypeId.ListIterator); + + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c1").OfType(BuiltinTypeId.Float) + .And.HaveVariable("c2").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task Iterator3_V2() { + const string code = @" +A = [1, 2, 3] +B = 'abc' +C = [1.0, 'a', 3] + +iA, iB, iC = A.__iter__(), B.__iter__(), C.__iter__() +a = iA.next() +b = next(iB) +_next = next +c = _next(iC) +"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c").OfType(BuiltinTypeId.Float); + } + + //[TestMethod, Priority(0)] + public async Task Iterator4_V2() { + const string code = @" +iA = iter(lambda: 1, 2) +iB = iter(lambda: 'abc', None) +iC = iter(lambda: 1, 'abc') + +a = next(iA) +b = next(iB) +c = next(iC) +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task Iterator1_V3() { + const string code = @" +A = [1, 2, 3] +B = 'abc' +C = [1.0, 'a', 3] + +iA, iB, iC = A.__iter__(), B.__iter__(), C.__iter__() +a = iA.__next__() +b = next(iB) +_next = next +c = _next(iC) +"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + + analysis.Should().HaveVariable("A").OfType(BuiltinTypeId.List) + .And.HaveVariable("B").OfType(BuiltinTypeId.Str) + .And.HaveVariable("C").OfType(BuiltinTypeId.List); + + analysis.Should().HaveVariable("iA").OfType(BuiltinTypeId.ListIterator) + .And.HaveVariable("iB").OfType(BuiltinTypeId.StrIterator) + .And.HaveVariable("iC").OfType(BuiltinTypeId.ListIterator); + + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Str) + .And.HaveVariable("c").OfType(BuiltinTypeId.Float); + } + + //[TestMethod, Priority(0)] + public async Task Iterator2_V3() { + const string code = @" +iA = iter(lambda: 1, 2) +iB = iter(lambda: 'abc', None) +iC = iter(lambda: 1, 'abc') + +a = next(iA) +b = next(iB) +c = next(iC) +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Unicode) + .And.HaveVariable("c").OfType(BuiltinTypeId.Int); + } + } +} diff --git a/src/Analysis/Ast/Test/LibraryTests.cs b/src/Analysis/Ast/Test/LibraryTests.cs new file mode 100644 index 000000000..2e25d6b40 --- /dev/null +++ b/src/Analysis/Ast/Test/LibraryTests.cs @@ -0,0 +1,65 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class LibraryTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task Random() { + var analysis = await GetAnalysisAsync("from random import *"); + + foreach (var fnName in new[] { @"seed", @"randrange", @"gauss" }) { + var v = analysis.Should().HaveVariable(fnName).Which; + v.Should().HaveType(BuiltinTypeId.Function); + v.Value.GetPythonType().Documentation.Should().NotBeNullOrEmpty(); + } + } + + [TestMethod, Priority(0)] + public async Task Datetime() { + var analysis = await GetAnalysisAsync("import datetime"); + + var module = analysis.Should().HaveVariable("datetime") + .Which.Should().HaveType().Which; + module.Name.Should().Be("datetime"); + + var dt = module.Should().HaveMember("datetime").Which; + + dt.Should().HaveReadOnlyProperty("day").And.HaveMethod("now") + .Which.Should().BeClassMethod().And.HaveSingleOverload() + .Which.Should().HaveReturnType() + .Which.Should().HaveMembers( + @"astimezone", @"isocalendar", @"resolution", @"fromordinal", @"fromtimestamp", + @"min", @"max", @"date", @"utcnow", "combine", "replace", "second"); + } + } +} diff --git a/src/Analysis/Ast/Test/Microsoft.Python.Analysis.Tests.csproj b/src/Analysis/Ast/Test/Microsoft.Python.Analysis.Tests.csproj new file mode 100644 index 000000000..2772e926b --- /dev/null +++ b/src/Analysis/Ast/Test/Microsoft.Python.Analysis.Tests.csproj @@ -0,0 +1,51 @@ + + + netcoreapp2.1 + Microsoft.Python.Analysis.Tests + Microsoft.Python.Analysis.Tests + + + + 1701;1702$(NoWarn) + 7.2 + + + ..\..\..\PLS.ruleset + + + ..\..\..\PLS.ruleset + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + + + + diff --git a/src/Analysis/Ast/Test/OperatorTests.cs b/src/Analysis/Ast/Test/OperatorTests.cs new file mode 100644 index 000000000..c67dfecd1 --- /dev/null +++ b/src/Analysis/Ast/Test/OperatorTests.cs @@ -0,0 +1,132 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class OperatorTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + + [TestMethod, Priority(0)] + public async Task NotOperator() { + const string code = @" + +class C(object): + def __nonzero__(self): + pass + + def __bool__(self): + pass + +a = not C() +"; + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable2X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Bool); + + analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Bool); + } + + [TestMethod, Priority(0)] + public async Task UnaryOperatorPlus() { + const string code = @" +class Result(object): + pass + +class C(object): + def __pos__(self): + return Result() + +a = +C() +b = ++C() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType("Result") + .And.HaveVariable("b").OfType("Result"); + } + + [TestMethod, Priority(0)] + public async Task UnaryOperatorMinus() { + const string code = @" +class Result(object): + pass + +class C(object): + def __neg__(self): + return Result() + +a = -C() +b = --C() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType("Result") + .And.HaveVariable("b").OfType("Result"); + } + + [TestMethod, Priority(0)] + public async Task UnaryOperatorTilde() { + const string code = @" +class Result(object): + pass + +class C(object): + def __invert__(self): + return Result() + +a = ~C() +b = ~~C() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType("Result") + .And.HaveVariable("b").OfType("Result"); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task TrueDividePython3X() { + const string code = @" +class C: + def __truediv__(self, other): + return 42 + def __rtruediv__(self, other): + return 3.0 + +a = C() +b = a / 'abc' +c = 'abc' / a +"; + + var analysis = await GetAnalysisAsync(code, PythonVersions.LatestAvailable3X); + analysis.Should().HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("c").OfType(BuiltinTypeId.Float); + } + } +} diff --git a/src/Analysis/Ast/Test/ParserTests.cs b/src/Analysis/Ast/Test/ParserTests.cs new file mode 100644 index 000000000..1afa06a09 --- /dev/null +++ b/src/Analysis/Ast/Test/ParserTests.cs @@ -0,0 +1,80 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing.Tests; +using Microsoft.Python.Tests.Utilities.FluentAssertions; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ParserTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task RedeclareGlobal() { + const string code = @" +def testGlobal(self): + # 'global' NAME (',' NAME)* + global a + global a, b +"; + var analysis = await GetAnalysisAsync(code); + var diag = analysis.Document.GetParseErrors().ToArray(); + diag.Should().BeEmpty(); + } + + [TestMethod, Priority(0)] + public async Task RedeclareNonlocal() { + const string code = @" +def test_nonlocal(self): + x = 0 + y = 0 + def f(): + nonlocal x + nonlocal x, y +"; + var analysis = await GetAnalysisAsync(code); + var diag = analysis.Document.GetParseErrors().ToArray(); + diag.Should().BeEmpty(); + } + + [TestMethod, Priority(0)] + public async Task DeclareNonlocalBeforeUse() { + const string code = @" +class TestSuper(unittest.TestCase): + def tearDown(self): + nonlocal __class__ + __class__ = TestSuper +"; + var analysis = await GetAnalysisAsync(code); + var diag = analysis.Document.GetParseErrors().ToArray(); + diag.Should().BeEmpty(); + } + } +} diff --git a/src/Analysis/Ast/Test/ScrapeTests.cs b/src/Analysis/Ast/Test/ScrapeTests.cs new file mode 100644 index 000000000..32019c4b8 --- /dev/null +++ b/src/Analysis/Ast/Test/ScrapeTests.cs @@ -0,0 +1,326 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Analysis.Documents; +using Microsoft.Python.Analysis.Modules; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ScrapeTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task SpecialFloats() { + var analysis = await GetAnalysisAsync("import math; inf = math.inf; nan = math.nan", PythonVersions.LatestAvailable3X); + + analysis.Should().HaveVariable("math") + .And.HaveVariable("inf").OfType(BuiltinTypeId.Float) + .And.HaveVariable("nan").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task CompiledBuiltinScrapeV38x64() => await CompiledBuiltinScrapeAsync(PythonVersions.Python38_x64); + + [TestMethod, Priority(0)] + public async Task CompiledBuiltinScrapeV37x64() => await CompiledBuiltinScrapeAsync(PythonVersions.Python37_x64); + + [TestMethod, Priority(0)] + public async Task CompiledBuiltinScrapeV36x64() => await CompiledBuiltinScrapeAsync(PythonVersions.Python36_x64); + + [TestMethod, Priority(0)] + public async Task CompiledBuiltinScrapeV27x64() => await CompiledBuiltinScrapeAsync(PythonVersions.Python27_x64); + [TestMethod, Priority(0)] + public async Task CompiledBuiltinScrapeV27x86() => await CompiledBuiltinScrapeAsync(PythonVersions.Python27); + + private async Task CompiledBuiltinScrapeAsync(InterpreterConfiguration configuration) { + configuration.AssertInstalled(); + + var moduleUri = TestData.GetDefaultModuleUri(); + var moduleDirectory = Path.GetDirectoryName(moduleUri.LocalPath); + + var services = await CreateServicesAsync(moduleDirectory, configuration); + var interpreter = services.GetService(); + + // TODO: this is Windows only + var dllsDir = Path.Combine(Path.GetDirectoryName(interpreter.Configuration.LibraryPath), "DLLs"); + if (!Directory.Exists(dllsDir)) { + Assert.Inconclusive("Configuration does not have DLLs"); + } + + var report = new List(); + var permittedImports = interpreter.LanguageVersion.Is2x() ? + new[] { interpreter.ModuleResolution.BuiltinModuleName, "exceptions" } : + new[] { interpreter.ModuleResolution.BuiltinModuleName }; + + foreach (var pyd in PathUtils.EnumerateFiles(dllsDir, "*", recurse: false).Where(ModulePath.IsPythonFile)) { + var mp = ModulePath.FromFullPath(pyd); + if (mp.IsDebug) { + continue; + } + + Console.WriteLine("Importing {0} from {1}", mp.ModuleName, mp.SourceFile); + var mod = await interpreter.ModuleResolution.ImportModuleAsync(mp.ModuleName); + Assert.IsInstanceOfType(mod, typeof(CompiledPythonModule)); + + var modPath = interpreter.ModuleResolution.ModuleCache.GetCacheFilePath(pyd); + Assert.IsTrue(File.Exists(modPath), "No cache file created"); + var moduleCache = File.ReadAllText(modPath); + + var doc = (IDocument)mod; + var ast = await doc.GetAstAsync(); + + var errors = doc.GetParseErrors().ToArray(); + foreach (var err in errors) { + Console.WriteLine(err); + } + Assert.AreEqual(0, errors.Count(), "Parse errors occurred"); + + + var imports = ((SuiteStatement)ast.Body).Statements + .OfType() + .SelectMany(s => s.Names) + .Select(n => n.MakeString()) + .Except(permittedImports) + .ToArray(); + + // We expect no imports (after excluding builtins) + report.AddRange(imports.Select(n => $"{mp.ModuleName} imported {n}")); + } + + report.Should().BeEmpty(); + } + + [TestMethod, Priority(0)] + public async Task BuiltinScrapeV38() => await BuiltinScrape(PythonVersions.Python38_x64 ?? PythonVersions.Python38); + + [TestMethod, Priority(0)] + public async Task BuiltinScrapeV37() => await BuiltinScrape(PythonVersions.Python37_x64 ?? PythonVersions.Python37); + + [TestMethod, Priority(0)] + public async Task BuiltinScrapeV36() => await BuiltinScrape(PythonVersions.Python36_x64 ?? PythonVersions.Python36); + + [TestMethod, Priority(0)] + public async Task BuiltinScrapeV27() => await BuiltinScrape(PythonVersions.Python27_x64 ?? PythonVersions.Python27); + + private async Task BuiltinScrape(InterpreterConfiguration configuration) { + configuration.AssertInstalled(); + var moduleUri = TestData.GetDefaultModuleUri(); + var moduleDirectory = Path.GetDirectoryName(moduleUri.LocalPath); + + var services = await CreateServicesAsync(moduleDirectory, configuration); + var interpreter = services.GetService(); + + var mod = await interpreter.ModuleResolution.ImportModuleAsync(interpreter.ModuleResolution.BuiltinModuleName, new CancellationTokenSource(5000).Token); + Assert.IsInstanceOfType(mod, typeof(BuiltinsPythonModule)); + var modPath = interpreter.ModuleResolution.ModuleCache.GetCacheFilePath(interpreter.Configuration.InterpreterPath); + + var doc = mod as IDocument; + var errors = doc.GetParseErrors().ToArray(); + foreach (var err in errors) { + Console.WriteLine(err); + } + Assert.AreEqual(0, errors.Count(), "Parse errors occurred"); + + var ast = await doc.GetAstAsync(); + var seen = new HashSet(); + foreach (var stmt in ((SuiteStatement)ast.Body).Statements) { + if (stmt is ClassDefinition cd) { + Assert.IsTrue(seen.Add(cd.Name), $"Repeated use of {cd.Name} at index {cd.StartIndex} in {modPath}"); + } else if (stmt is FunctionDefinition fd) { + Assert.IsTrue(seen.Add(fd.Name), $"Repeated use of {fd.Name} at index {fd.StartIndex} in {modPath}"); + } else if (stmt is AssignmentStatement assign && assign.Left.FirstOrDefault() is NameExpression n) { + Assert.IsTrue(seen.Add(n.Name), $"Repeated use of {n.Name} at index {n.StartIndex} in {modPath}"); + } + } + + // Ensure we can get all the builtin types + foreach (BuiltinTypeId v in Enum.GetValues(typeof(BuiltinTypeId))) { + var type = interpreter.GetBuiltinType(v); + type.Should().NotBeNull().And.BeAssignableTo($"Did not find {v}"); + type.IsBuiltin.Should().BeTrue(); + } + + // Ensure we cannot see or get builtin types directly + mod.GetMemberNames().Should().NotContain(Enum.GetNames(typeof(BuiltinTypeId)).Select(n => $"__{n}")); + + foreach (var id in Enum.GetNames(typeof(BuiltinTypeId))) { + mod.GetMember($"__{id}").Should().BeNull(id); + } + } + + [TestMethod, TestCategory("60s"), Priority(0)] + public async Task FullStdLibV38() { + var v = PythonVersions.Python38 ?? PythonVersions.Python38_x64; + await FullStdLibTest(v); + } + + [TestMethod, TestCategory("60s"), Priority(0)] + public async Task FullStdLibV37() { + var v = PythonVersions.Python37 ?? PythonVersions.Python37_x64; + await FullStdLibTest(v); + } + + + [TestMethod, TestCategory("60s"), Priority(0)] + public async Task FullStdLibV36() { + var v = PythonVersions.Python36 ?? PythonVersions.Python36_x64; + await FullStdLibTest(v); + } + + [TestMethod, TestCategory("60s"), Priority(0)] + public async Task FullStdLibV27() { + var v = PythonVersions.Python27 ?? PythonVersions.Python27_x64; + await FullStdLibTest(v); + } + + [TestMethod, TestCategory("60s"), Priority(1)] + [Timeout(10 * 60 * 1000)] + public async Task FullStdLibAnaconda3() { + var v = PythonVersions.Anaconda36_x64 ?? PythonVersions.Anaconda36; + await FullStdLibTest(v, + // Crashes Python on import + @"sklearn.linear_model.cd_fast", + // Crashes Python on import + @"sklearn.cluster._k_means_elkan" + ); + } + + [TestMethod, TestCategory("60s"), Priority(1)] + [Timeout(10 * 60 * 1000)] + public async Task FullStdLibAnaconda2() { + var v = PythonVersions.Anaconda27_x64 ?? PythonVersions.Anaconda27; + await FullStdLibTest(v, + // Fails to import due to SxS manifest issues + "dde", + "win32ui" + ); + } + + + private async Task FullStdLibTest(InterpreterConfiguration configuration, params string[] skipModules) { + configuration.AssertInstalled(); + var moduleUri = TestData.GetDefaultModuleUri(); + var moduleDirectory = Path.GetDirectoryName(moduleUri.LocalPath); + + var services = await CreateServicesAsync(moduleDirectory, configuration); + var interpreter = services.GetService(); + + var modules = ModulePath.GetModulesInLib(configuration.LibraryPath, configuration.SitePackagesPath).ToList(); + + var skip = new HashSet(skipModules); + skip.UnionWith(new[] { + @"matplotlib.backends._backend_gdk", + @"matplotlib.backends._backend_gtkagg", + @"matplotlib.backends._gtkagg", + "test.test_pep3131", + "test.test_unicode_identifiers", + "test.test_super" // nonlocal syntax error + }); + skip.UnionWith(modules.Select(m => m.FullName) + .Where(n => n.StartsWith(@"test.badsyntax") || n.StartsWith("test.bad_coding"))); + + var anySuccess = false; + var anyExtensionSuccess = false; + var anyExtensionSeen = false; + var anyParseError = false; + + foreach (var m in skip) { + ((ModuleResolution)interpreter.ModuleResolution).AddUnimportableModule(m); + } + + var set = modules + .Where(m => !skip.Contains(m.ModuleName)) + .GroupBy(m => { + var i = m.FullName.IndexOf('.'); + return i <= 0 ? m.FullName : m.FullName.Remove(i); + }) + .SelectMany(g => g.Select(m => Tuple.Create(m, m.ModuleName))) + .ToArray(); + set = set.Where(x => x.Item2 != null && x.Item2.Contains("grammar")).ToArray(); + + foreach (var r in set) { + var modName = r.Item1; + var mod = await interpreter.ModuleResolution.ImportModuleAsync(r.Item2); + + anyExtensionSeen |= modName.IsNativeExtension; + switch (mod) { + case null: + Trace.TraceWarning("failed to import {0} from {1}", modName.ModuleName, modName.SourceFile); + break; + case CompiledPythonModule _: { + var errors = ((IDocument)mod).GetParseErrors().ToArray(); + if (errors.Any()) { + anyParseError = true; + Trace.TraceError("Parse errors in {0}", modName.SourceFile); + foreach (var e in errors) { + Trace.TraceError(e.Message); + } + } else { + anySuccess = true; + anyExtensionSuccess |= modName.IsNativeExtension; + } + + break; + } + case IPythonModule _: { + var filteredErrors = ((IDocument)mod).GetParseErrors().Where(e => !e.Message.Contains("encoding problem")).ToArray(); + if (filteredErrors.Any()) { + // Do not fail due to errors in installed packages + if (!mod.FilePath.Contains("site-packages")) { + anyParseError = true; + } + Trace.TraceError("Parse errors in {0}", modName.SourceFile); + foreach (var e in filteredErrors) { + Trace.TraceError(e.Message); + } + } else { + anySuccess = true; + anyExtensionSuccess |= modName.IsNativeExtension; + } + + break; + } + } + } + Assert.IsTrue(anySuccess, "failed to import any modules at all"); + Assert.IsTrue(anyExtensionSuccess || !anyExtensionSeen, "failed to import all extension modules"); + Assert.IsFalse(anyParseError, "parse errors occurred"); + } + } +} diff --git a/src/Analysis/Ast/Test/TypeshedTests.cs b/src/Analysis/Ast/Test/TypeshedTests.cs new file mode 100644 index 000000000..fb210de3a --- /dev/null +++ b/src/Analysis/Ast/Test/TypeshedTests.cs @@ -0,0 +1,139 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Core; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Tests; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class TypeshedTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task TypeShedSysExcInfo() { + const string code = @" +import sys +e1, e2, e3 = sys.exc_info() +"; + var analysis = await GetAnalysisAsync(code); + // sys.exc_info() -> (exception_type, exception_value, traceback) + var f = analysis.Should() + .HaveVariable("e1").OfType(BuiltinTypeId.Type) + .And.HaveVariable("e2").OfType("BaseException") + .And.HaveVariable("e3").OfType("TracebackType") + .And.HaveVariable("sys").OfType(BuiltinTypeId.Module) + .Which.Should().HaveMember("exc_info").Which; + + f.Overloads.Should().HaveCount(1); + f.Overloads[0].ReturnDocumentation + .Should().Be(@"Tuple[ (Optional[Type[BaseException]],Optional[BaseException],Optional[TracebackType])]"); + } + + [TestMethod, Priority(0)] + public async Task TypeShedJsonMakeScanner() { + var code = @"import _json +scanner = _json.make_scanner()"; + var analysis = await GetAnalysisAsync(code); + + var v0 = analysis.Should().HaveVariable("scanner").Which; + + v0.Should().HaveMember("__call__") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveName("__call__") + .And.HaveParameters("self", "string", "index") + .And.HaveParameterAt(1).WithName("string").WithType("str").WithNoDefaultValue() + .And.HaveParameterAt(2).WithName("index").WithType("int").WithNoDefaultValue() + .And.HaveReturnDocumentation("Tuple[ (Any,int)]"); + } + + [TestMethod, Priority(0)] + public async Task MergeStubs() { + var analysis = await GetAnalysisAsync("import Package.Module\n\nc = Package.Module.Class()"); + + analysis.Should() + .HaveVariable("Package") + .Which.Value.Should().HaveMember("Module"); + + analysis.Should().HaveVariable("c") + .Which.Value.Should().HaveMembers("untyped_method", "inferred_method", "typed_method") + .And.NotHaveMembers("typed_method_2"); + } + + [TestMethod, Priority(0)] + public async Task TypeStubConditionalDefine() { + var seen = new HashSet(); + + var code = @"import sys + +if sys.version_info < (2, 7): + LT_2_7 : bool = ... +if sys.version_info <= (2, 7): + LE_2_7 : bool = ... +if sys.version_info > (2, 7): + GT_2_7 : bool = ... +if sys.version_info >= (2, 7): + GE_2_7 : bool = ... + +"; + + var fullSet = new[] { "LT_2_7", "LE_2_7", "GT_2_7", "GE_2_7" }; + + foreach (var ver in PythonVersions.Versions) { + if (!seen.Add(ver.Version)) { + continue; + } + + Console.WriteLine(@"Testing with {0}", ver.InterpreterPath); + using (var s = await CreateServicesAsync(TestData.Root, ver)) { + var analysis = await GetAnalysisAsync(code, s, @"testmodule", TestData.GetTestSpecificPath(@"testmodule.pyi")); + + var expected = new List(); + var pythonVersion = ver.Version.ToLanguageVersion(); + if (pythonVersion.Is3x()) { + expected.Add("GT_2_7"); + expected.Add("GE_2_7"); + } else if (pythonVersion == PythonLanguageVersion.V27) { + expected.Add("GE_2_7"); + expected.Add("LE_2_7"); + } else { + expected.Add("LT_2_7"); + expected.Add("LE_2_7"); + } + + analysis.GlobalScope.Variables.Select(m => m.Name).Where(n => n.EndsWithOrdinal("2_7")) + .Should().Contain(expected) + .And.NotContain(fullSet.Except(expected)); + } + } + } + } +} diff --git a/src/Analysis/Ast/Test/TypingTests.cs b/src/Analysis/Ast/Test/TypingTests.cs new file mode 100644 index 000000000..19b68f89a --- /dev/null +++ b/src/Analysis/Ast/Test/TypingTests.cs @@ -0,0 +1,694 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Specializations.Typing; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class TypingTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task ListContent() { + const string code = @" +from typing import List + +lstr: List[str] +x = lstr[0] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable(@"lstr").OfType("List[str]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task ListOfLists() { + const string code = @" +from typing import List + +lst: List[List[int]] +x = lst[0] +y = x[0] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable(@"lst").OfType("List[List[int]]") + .And.HaveVariable("x").OfType("List[int]") + .And.HaveVariable("y").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task GenericListArg() { + const string code = @" +from typing import List + +def func(a: List[str]): + pass +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("func").Which + .Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0) + .Which.Should().HaveName("a").And.HaveType("List[str]"); + } + + [TestMethod, Priority(0)] + public async Task FunctionAnnotatedToList() { + const string code = @" +from typing import List + +def f() -> List[str]: ... +x = f()[0] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveReturnDocumentation("List[str]"); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task FunctionWithListArgument() { + const string code = @" +from typing import List + +def f(a: List[str]): + return a + +x = f(1) +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType("List[str]"); + } + + [TestMethod, Priority(0)] + public async Task FunctionFetchingFromList() { + const string code = @" +from typing import List + +def f(a: List[str], index: int): + return a[index] + +x = f(1) +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task TypeVarSimple() { + const string code = @" +from typing import TypeVar + +T = TypeVar('T', str, bytes) +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("T") + .Which.Value.Should().HaveDocumentation("TypeVar('T', str, bytes)"); + analysis.Should().HaveVariable("T").OfType(typeof(IGenericTypeParameter)); + } + + [TestMethod, Priority(0)] + [Ignore] + public async Task TypeVarFunc() { + const string code = @" +from typing import Sequence, TypeVar + +T = TypeVar('T') # Declare type variable + +def first(l: Sequence[T]) -> T: # Generic function + return l[0] + +arr = [1, 2, 3] +x = first(arr) # should be int +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task TypeVarIncomplete() { + const string code = @" +from typing import TypeVar + +_ = TypeVar() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("_").WithNoTypes(); + } + + + [TestMethod, Priority(0)] + public async Task GenericArguments() { + const string code = @" +from typing import TypeVar + +T = TypeVar('T', str, bytes) + +def longest(x: T, y: T): + return x if len(x) >= len(y) else y + +x = longest('a', 'bc') +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("longest") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0) + .Which.Should().HaveName("x") + .And.HaveType("T"); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task TypeAlias() { + const string code = @" +Url = str + +def f(a: Url) -> Url: ... +def f(a: int) -> float: ... + +u: Url +x = f('s') +y = f(u) +z = f(1) +"; + + var analysis = await GetAnalysisAsync(code); + // TODO: should it be Url? Should we rename type copy on assignment? How to match types then? + analysis.Should().HaveVariable("u").OfType(BuiltinTypeId.Str) + .And.HaveVariable("x").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("z").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task TupleContent() { + const string code = @" +from typing import Tuple + +t: Tuple[int, str] +x = t[0] +y = t[1] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("t").OfType("Tuple[int, str]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task TupleOfTuple() { + const string code = @" +from typing import Tuple + +t: Tuple[Tuple[int, str], bool] +x = t[0] +y = t[1] +z0 = x[0] +z1 = x[1] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("t").OfType("Tuple[Tuple[int, str], bool]") + .And.HaveVariable("x").OfType("Tuple[int, str]") + .And.HaveVariable("y").OfType(BuiltinTypeId.Bool) + .And.HaveVariable("z0").OfType(BuiltinTypeId.Int) + .And.HaveVariable("z1").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task IteratorParamTypeMatch() { + const string code = @" +from typing import Iterator, List, TypeVar + +T = TypeVar('T') + +@overload +def f(a: Iterator[T]) -> str: ... +@overload +def f(a: int) -> float: ... +def f(a): ... + +a: List[str] = ['a', 'b', 'c'] +x = f(iter(a)) +"; + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveFunction("f").Which; + + f.Should().HaveOverloadAt(0) + .Which.Should().HaveReturnType(BuiltinTypeId.Str) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType("Iterator[T]"); + + f.Should().HaveOverloadAt(1) + .Which.Should().HaveReturnType(BuiltinTypeId.Float) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Int); + + analysis.Should().HaveVariable("a").OfType("List[str]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + + [TestMethod, Priority(0)] + public async Task IterableParamTypeMatch() { + const string code = @" +from typing import Iterable, List, Tuple, TypeVar + +T = TypeVar('T') + +@overload +def f(a: Iterable[T]) -> str: ... +@overload +def f(a: int) -> float: ... +def f(a): ... + +a: List[str] = ['a', 'b', 'c'] + +x = f(a) +y = f(1) +"; + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveFunction("f").Which; + + f.Should().HaveOverloadAt(0) + .Which.Should().HaveReturnType(BuiltinTypeId.Str) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType("Iterable[T]"); + + f.Should().HaveOverloadAt(1) + .Which.Should().HaveReturnType(BuiltinTypeId.Float) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Int); + + analysis.Should().HaveVariable("a").OfType("List[str]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Str) + .And.HaveVariable("y").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task SequenceParamTypeMatch() { + const string code = @" +from typing import List, Sequence, TypeVar + +T = TypeVar('T') + +@overload +def f(a: Sequence[T]) -> str: ... +@overload +def f(a: int) -> float: ... +def f(a): pass + +a: List[str] = ['a', 'b', 'c'] +x = f(a) +"; + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveFunction("f").Which; + + f.Should().HaveOverloadAt(0) + .Which.Should().HaveReturnType(BuiltinTypeId.Str) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType("Sequence[T]"); + + f.Should().HaveOverloadAt(1) + .Which.Should().HaveReturnType(BuiltinTypeId.Float) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Int); + + analysis.Should().HaveVariable("a").OfType("List[str]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task MappingParamTypeMatch() { + const string code = @" +from typing import Dict, Mapping, TypeVar + +KT = TypeVar('KT') +KV = TypeVar('KV') + +@overload +def f(a: Mapping[KT, KV]) -> str: ... +@overload +def f(a: int) -> float: ... +def f(a): ... + +a: Dict[str, int] +x = f(a) +"; + var analysis = await GetAnalysisAsync(code); + var f = analysis.Should().HaveFunction("f").Which; + + f.Should().HaveOverloadAt(0) + .Which.Should().HaveReturnType(BuiltinTypeId.Str) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType("Mapping[KT, KV]"); + + f.Should().HaveOverloadAt(1) + .Which.Should().HaveReturnType(BuiltinTypeId.Float) + .Which.Should().HaveSingleParameter() + .Which.Should().HaveName("a").And.HaveType(BuiltinTypeId.Int); + + analysis.Should().HaveVariable("a").OfType("Dict[str, int]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task TypingListOfTuples() { + const string code = @" +from typing import List + +def ls() -> List[tuple]: + pass + +x = ls()[0] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("ls") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveReturnDocumentation("List[tuple]"); + + analysis.Should().HaveVariable("x").Which + .Should().HaveType(BuiltinTypeId.Tuple); + } + + + [TestMethod, Priority(0)] + public async Task DictContent() { + const string code = @" +from typing import Dict + +d: Dict[str, int] +x = d['a'] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable(@"d").OfType("Dict[str, int]") + .And.HaveVariable("x").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task DictOfDicts() { + const string code = @" +from typing import Dict + +a: Dict[int, Dict[str, float]] +x = a[0] +y = x['a'] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable(@"a").OfType("Dict[int, Dict[str, float]]") + .And.HaveVariable("x").OfType("Dict[str, float]") + .And.HaveVariable("y").OfType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task GenericDictArg() { + const string code = @" +from typing import Dict + +def func(a: Dict[int, str]): + pass +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("func") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveParameterAt(0) + .Which.Should().HaveName("a").And.HaveType("Dict[int, str]"); + } + + [TestMethod, Priority(0)] + public async Task GenericIterator() { + const string code = @" +from typing import Iterator, List + +a: List[str] = ['a', 'b', 'c'] +ia = iter(a); +x = next(ia); +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType("List[str]") + .And.HaveVariable("ia").OfType(BuiltinTypeId.ListIterator) + .And.HaveVariable("x").OfType(BuiltinTypeId.Str); + } + + [TestMethod, Priority(0)] + public async Task NewType() { + const string code = @" +from typing import NewType + +Foo = NewType('Foo', dict) +foo: Foo = Foo({ }) +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("Foo").OfType("Foo") + .And.HaveVariable("foo").OfType("Foo"); + analysis.Should().HaveVariable("Foo").Which.Should().HaveMembers("keys", "values"); + } + + [TestMethod, Priority(0)] + public async Task Containers() { + const string code = @" +from typing import * + +i : SupportsInt = ... +lst_i : List[int] = ... +lst_i_0 = lst_i[0] + +u : Union[Mapping[int, str], MappingView[str, float], MutableMapping[int, List[str]]] = ... + +dct_s_i : Mapping[str, int] = ... +dct_s_i_a = dct_s_i['a'] +dct_s_i_keys = dct_s_i.keys() +dct_s_i_key = next(iter(dct_s_i_keys)) +dct_s_i_values = dct_s_i.values() +dct_s_i_value = next(iter(dct_s_i_values)) +dct_s_i_items = dct_s_i.items() +dct_s_i_item_1, dct_s_i_item_2 = next(iter(dct_s_i_items)) + +dctv_s_i_keys : KeysView[str] = ... +dctv_s_i_key = next(iter(dctv_s_i_keys)) +dctv_s_i_values : ValuesView[int] = ... +dctv_s_i_value = next(iter(dctv_s_i_values)) +dctv_s_i_items : ItemsView[str, int] = ... +dctv_s_i_item_1, dctv_s_i_item_2 = next(iter(dctv_s_i_items)) +"; + ; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("i").OfType(BuiltinTypeId.Int) + .And.HaveVariable("lst_i").OfType("List[int]") + .And.HaveVariable("lst_i_0").OfType(BuiltinTypeId.Int) + .And.HaveVariable("u").OfType("Union[Mapping[int, str], MappingView[str, float], MutableMapping[int, List[str]]]") + .And.HaveVariable("dct_s_i").OfType("Mapping[str, int]") + .And.HaveVariable("dct_s_i_a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("dct_s_i_keys").OfType("KeysView[str]") + .And.HaveVariable("dct_s_i_key").OfType(BuiltinTypeId.Str) + .And.HaveVariable("dct_s_i_values").OfType("ValuesView[int]") + .And.HaveVariable("dct_s_i_value").OfType(BuiltinTypeId.Int) + .And.HaveVariable("dct_s_i_items").OfType("ItemsView[str, int]") + .And.HaveVariable("dct_s_i_item_1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("dct_s_i_item_2").OfType(BuiltinTypeId.Int) + .And.HaveVariable("dctv_s_i_keys").OfType("KeysView[str]") + .And.HaveVariable("dctv_s_i_key").OfType(BuiltinTypeId.Str) + .And.HaveVariable("dctv_s_i_values").OfType("ValuesView[int]") + .And.HaveVariable("dctv_s_i_value").OfType(BuiltinTypeId.Int) + .And.HaveVariable("dctv_s_i_items").OfType("ItemsView[str, int]") + .And.HaveVariable("dctv_s_i_item_1").OfType(BuiltinTypeId.Str) + .And.HaveVariable("dctv_s_i_item_2").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task NamedTypeAlias() { + const string code = @" +from typing import * + +MyList = List[str] +MyTuple = Tuple[int, str] + +sl : MyList = ... +sl_0 = sl[0] + +t : MyTuple = ... +t_0 = t[0] + +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("sl").OfType("List[str]") + .And.HaveVariable("sl_0").OfType(BuiltinTypeId.Str) + .And.HaveVariable("t").OfType("Tuple[int, str]") + .And.HaveVariable("t_0").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task NamedTuple() { + const string code = @" +from typing import * + +n1 : NamedTuple('n1', [('x', int), ('y', float)]) = ... + +n1_x = n1.x +n1_y = n1.y + +n1_0 = n1[0] +n1_1 = n1[1] + +n1_m2 = n1[-2] +n1_m1 = n1[-1] + +i = 0 +i = 1 +n1_i = n1[i] +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("n1").OfType("n1(x: int, y: float)") + + .And.HaveVariable("n1_x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("n1_y").OfType(BuiltinTypeId.Float) + + .And.HaveVariable("n1_0").OfType(BuiltinTypeId.Int) + .And.HaveVariable("n1_1").OfType(BuiltinTypeId.Float) + + .And.HaveVariable("n1_m2").OfType(BuiltinTypeId.Int) + .And.HaveVariable("n1_m1").OfType(BuiltinTypeId.Float) + + .And.HaveVariable("n1_i").OfType(BuiltinTypeId.Float); + + var n1 = analysis.Should().HaveVariable("n1").Which; + n1.Should().HaveMember("x").Which.Should().HaveType(BuiltinTypeId.Int); + n1.Should().HaveMember("y").Which.Should().HaveType(BuiltinTypeId.Float); + } + + [TestMethod, Priority(0)] + public async Task AnyStr() { + const string code = @" +from typing import AnyStr + +n1 : AnyStr = 'abc' +x = n1[0] + +n2 : AnyStr = b'abc' +y = n2[0] +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("n1").OfType("AnyStr") + .And.HaveVariable("x").OfType("AnyStr") + .And.HaveVariable("y").OfType("AnyStr"); + } + + [TestMethod, Priority(0)] + public void AnnotationParsing() { + AssertTransform("List", "NameOp:List"); + AssertTransform("List[Int]", "NameOp:List", "NameOp:Int", "MakeGenericOp"); + AssertTransform("Dict[Int, Str]", "NameOp:Dict", "StartListOp", "NameOp:Int", "NameOp:Str", "MakeGenericOp"); + + AssertTransform("'List'", "NameOp:List"); + AssertTransform("List['Int']", "NameOp:List", "NameOp:Int", "MakeGenericOp"); + AssertTransform("Dict['Int, Str']", "NameOp:Dict", "StartListOp", "NameOp:Int", "NameOp:Str", "MakeGenericOp"); + } + + [TestMethod, Priority(0)] + public void AnnotationConversion() { + AssertConvert("List"); + AssertConvert("List[Int]"); + AssertConvert("Dict[Int, Str]"); + AssertConvert("typing.Container[typing.Iterable]"); + + AssertConvert("List"); + AssertConvert("'List[Int]'", "List[Int]"); + AssertConvert("Dict['Int, Str']", "Dict[Int, Str]"); + AssertConvert("typing.Container['typing.Iterable']", "typing.Container[typing.Iterable]"); + } + + private static void AssertTransform(string expr, params string[] steps) { + var ta = Parse(expr); + ta.GetTransformSteps().Should().Equal(steps); + } + + private static void AssertConvert(string expr, string expected = null) { + var ta = Parse(expr); + var actual = ta.GetValue(new StringConverter()); + Assert.AreEqual(expected ?? expr, actual); + } + + private static TypeAnnotation Parse(string expr, PythonLanguageVersion version = PythonLanguageVersion.V36) { + var errors = new CollectingErrorSink(); + var ops = new ParserOptions {ErrorSink = errors}; + var p = Parser.CreateParser(new StringReader(expr), version, ops); + var ast = p.ParseTopExpression(); + if (errors.Errors.Any()) { + foreach (var e in errors.Errors) { + Console.WriteLine(e); + } + + Assert.Fail(string.Join("\n", errors.Errors.Select(e => e.ToString()))); + return null; + } + + var node = Statement.GetExpression(ast.Body); + return new TypeAnnotation(version, node); + } + + private class StringConverter : TypeAnnotationConverter { + public override string LookupName(string name) => name; + public override string GetTypeMember(string baseType, string member) => $"{baseType}.{member}"; + public override string MakeUnion(IReadOnlyList types) => string.Join(", ", types); + public override string MakeGeneric(string baseType, IReadOnlyList args) => $"{baseType}[{string.Join(", ", args)}]"; + + public override IReadOnlyList GetUnionTypes(string unionType) => unionType.Split(',').Select(n => n.Trim()).ToArray(); + + public override string GetBaseType(string genericType) { + int i = genericType.IndexOf('['); + if (i < 0) { + return null; + } + + return genericType.Remove(i); + } + } + } +} diff --git a/src/Analysis/Ast/Test/ValuesTests.cs b/src/Analysis/Ast/Test/ValuesTests.cs new file mode 100644 index 000000000..e32096b29 --- /dev/null +++ b/src/Analysis/Ast/Test/ValuesTests.cs @@ -0,0 +1,229 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; +using System.Threading.Tasks; +using FluentAssertions; +using Microsoft.Python.Analysis.Tests.FluentAssertions; +using Microsoft.Python.Analysis.Types; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TestUtilities; + +namespace Microsoft.Python.Analysis.Tests { + [TestClass] + public class ValuesTests : AnalysisTestBase { + public TestContext TestContext { get; set; } + + [TestInitialize] + public void TestInitialize() + => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); + + [TestCleanup] + public void Cleanup() => TestEnvironmentImpl.TestCleanup(); + + [TestMethod, Priority(0)] + public async Task Values() { + var code = await File.ReadAllTextAsync(Path.Combine(GetAnalysisTestDataFilesPath(), "Values.py")); + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("z").OfType(BuiltinTypeId.Bytes) + .And.HaveVariable("pi").OfType(BuiltinTypeId.Float) + .And.HaveVariable("l").OfType(BuiltinTypeId.List) + .And.HaveVariable("t").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("d").OfType(BuiltinTypeId.Dict) + .And.HaveVariable("s").OfType(BuiltinTypeId.Set) + .And.HaveVariable("X").OfType(BuiltinTypeId.Int) + .And.HaveVariable("Y").OfType(BuiltinTypeId.Str) + .And.HaveVariable("Z").OfType(BuiltinTypeId.Bytes) + .And.HaveVariable("PI").OfType(BuiltinTypeId.Float) + .And.HaveVariable("L").OfType(BuiltinTypeId.List) + .And.HaveVariable("T").OfType(BuiltinTypeId.Tuple) + .And.HaveVariable("D").OfType(BuiltinTypeId.Dict) + .And.HaveVariable("S").OfType(BuiltinTypeId.Set); + } + + [TestMethod, Priority(0)] + public async Task DocStrings() { + var code = @" +def f(): + '''func doc''' + + +def funicode(): + u'''unicode func doc''' + +class C: + '''class doc''' + +class CUnicode: + u'''unicode class doc''' + +class CNewStyle(object): + '''new-style class doc''' + +class CInherited(CNewStyle): + pass + +class CInit: + def __init__(self): + '''init doc''' + pass + +class CUnicodeInit: + def __init__(self): + u'''unicode init doc''' + pass + +class CNewStyleInit(object): + '''new-style class doc''' + def __init__(self): + pass + +class CInheritedInit(CNewStyleInit): + pass +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("f") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveDocumentation("func doc"); + + analysis.Should().HaveClass("C") + .Which.Should().HaveDocumentation("class doc"); + + analysis.Should().HaveFunction(@"funicode") + .Which.Should().HaveSingleOverload() + .Which.Should().HaveDocumentation("unicode func doc"); + + analysis.Should().HaveClass("CUnicode") + .Which.Should().HaveDocumentation("unicode class doc"); + + analysis.Should().HaveClass("CNewStyle") + .Which.Should().HaveDocumentation("new-style class doc"); + + analysis.Should().HaveClass("CInherited") + .Which.Should().HaveDocumentation("new-style class doc"); + + analysis.Should().HaveClass("CInit") + .Which.Should().HaveDocumentation("init doc"); + + analysis.Should().HaveClass("CUnicodeInit") + .Which.Should().HaveDocumentation("unicode init doc"); + + analysis.Should().HaveClass("CNewStyleInit") + .Which.Should().HaveDocumentation("new-style class doc"); + + analysis.Should().HaveClass("CInheritedInit") + .Which.Should().HaveDocumentation("new-style class doc"); + } + + [TestMethod, Priority(0)] + public async Task WithStatement() { + const string code = @" +class X(object): + def x_method(self): pass + def __enter__(self): return self + def __exit__(self, exc_type, exc_value, traceback): return False + +class Y(object): + def y_method(self): pass + def __enter__(self): return 123 + def __exit__(self, exc_type, exc_value, traceback): return False + +with X() as x: + pass #x + +with Y() as y: + pass #y + +with X(): + pass +"; + var analysis = await GetAnalysisAsync(code); + + analysis.Should().HaveVariable("y").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x") + .Which.Should().HaveMember("x_method"); + } + + [TestMethod, Priority(0)] + public async Task Global() { + const string code = @" +x = None +y = None +def f(): + def g(): + global x, y + x = 123 + y = 123 + return x, y + +a, b = f() +"; + + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int) + .And.HaveVariable("x").OfType(BuiltinTypeId.Int) + .And.HaveVariable("y").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task Nonlocal() { + const string code = @" +def f(): + x = None + y = None + def g(): + nonlocal x, y + x = 123 + y = 234 + return x, y + +a, b = f() +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveVariable("a").OfType(BuiltinTypeId.Int) + .And.HaveVariable("b").OfType(BuiltinTypeId.Int); + } + + [TestMethod, Priority(0)] + public async Task TryExcept() { + const string code = @" +class MyException(Exception): pass + +def f(): + try: + pass + except TypeError, e1: + pass + +def g(): + try: + pass + except MyException, e2: + pass +"; + var analysis = await GetAnalysisAsync(code); + analysis.Should().HaveFunction("f") + .Which.Should().HaveVariable("e1").OfType("TypeError"); + + analysis.Should().HaveFunction("g") + .Which.Should().HaveVariable("e2").OfType("MyException"); + } + } +} diff --git a/src/Analysis/Engine/Impl/DependencyResolution/AstUtilities.cs b/src/Analysis/Core/Impl/DependencyResolution/AstUtilities.cs similarity index 84% rename from src/Analysis/Engine/Impl/DependencyResolution/AstUtilities.cs rename to src/Analysis/Core/Impl/DependencyResolution/AstUtilities.cs index c08fe25ad..132d06ff1 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/AstUtilities.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/AstUtilities.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -15,10 +14,10 @@ // permissions and limitations under the License. using System.Linq; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal static class AstUtilities { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public static class AstUtilities { public static IImportSearchResult FindImports(this PathResolverSnapshot pathResolver, string modulePath, FromImportStatement fromImportStatement) { var rootNames = fromImportStatement.Root.Names.Select(n => n.Name); return fromImportStatement.Root is RelativeModuleName relativeName diff --git a/src/Analysis/Engine/Impl/DependencyResolution/IImportSearchResult.cs b/src/Analysis/Core/Impl/DependencyResolution/IImportSearchResult.cs similarity index 77% rename from src/Analysis/Engine/Impl/DependencyResolution/IImportSearchResult.cs rename to src/Analysis/Core/Impl/DependencyResolution/IImportSearchResult.cs index 162385fdf..0467ef4e3 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/IImportSearchResult.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/IImportSearchResult.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -14,6 +13,6 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal interface IImportSearchResult {} +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public interface IImportSearchResult {} } diff --git a/src/Analysis/Engine/Impl/DependencyResolution/ImportNotFound.cs b/src/Analysis/Core/Impl/DependencyResolution/ImportNotFound.cs similarity index 80% rename from src/Analysis/Engine/Impl/DependencyResolution/ImportNotFound.cs rename to src/Analysis/Core/Impl/DependencyResolution/ImportNotFound.cs index fba0a25a8..7705d9195 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/ImportNotFound.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/ImportNotFound.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -14,8 +13,8 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal class ImportNotFound : IImportSearchResult { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public class ImportNotFound : IImportSearchResult { public string FullName { get; } public ImportNotFound(string fullName) { FullName = fullName; diff --git a/src/Analysis/Engine/Impl/DependencyResolution/ModuleImport.cs b/src/Analysis/Core/Impl/DependencyResolution/ModuleImport.cs similarity index 86% rename from src/Analysis/Engine/Impl/DependencyResolution/ModuleImport.cs rename to src/Analysis/Core/Impl/DependencyResolution/ModuleImport.cs index 193ecb2d7..a376f0f1e 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/ModuleImport.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/ModuleImport.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -14,8 +13,8 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal class ModuleImport : IImportSearchResult { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public class ModuleImport : IImportSearchResult { public string Name { get; } public string FullName { get; } public string RootPath { get; } diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PackageImport.cs b/src/Analysis/Core/Impl/DependencyResolution/PackageImport.cs similarity index 79% rename from src/Analysis/Engine/Impl/DependencyResolution/PackageImport.cs rename to src/Analysis/Core/Impl/DependencyResolution/PackageImport.cs index 36623a851..e02220e87 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PackageImport.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PackageImport.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -14,11 +13,8 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; -using System.Collections.Generic; - -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal class PackageImport : IImportSearchResult { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public class PackageImport : IImportSearchResult { public string Name { get; } public ModuleImport[] Modules { get; } public string[] Packages { get; } diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PathResolver.cs b/src/Analysis/Core/Impl/DependencyResolution/PathResolver.cs similarity index 90% rename from src/Analysis/Engine/Impl/DependencyResolution/PathResolver.cs rename to src/Analysis/Core/Impl/DependencyResolution/PathResolver.cs index d765a86ca..cf73189c8 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PathResolver.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PathResolver.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -15,11 +14,10 @@ // permissions and limitations under the License. using System.Collections.Generic; -using System.Linq; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal sealed class PathResolver { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public sealed class PathResolver { private PathResolverSnapshot _currentSnapshot; public PathResolver(PythonLanguageVersion pythonLanguageVersion) { diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Edge.cs b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.Edge.cs similarity index 95% rename from src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Edge.cs rename to src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.Edge.cs index 946889a35..37b1ce011 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Edge.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.Edge.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -14,11 +13,10 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.Collections.Generic; using System.Diagnostics; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal partial struct PathResolverSnapshot { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public partial struct PathResolverSnapshot { /// /// Represents the edge between two nodes in the tree /// diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.ImmutableArray.cs b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.ImmutableArray.cs similarity index 94% rename from src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.ImmutableArray.cs rename to src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.ImmutableArray.cs index 4056fdd0f..ed4d79181 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.ImmutableArray.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.ImmutableArray.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -19,10 +18,9 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; -using Microsoft.PythonTools.Analysis.Infrastructure; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal partial struct PathResolverSnapshot { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public partial struct PathResolverSnapshot { /// /// This type is a compromise between an array (fast access, slow and expensive copying for every immutable change) and binary tree based immutable types /// Access is almost as fast as in array, adding is as fast as in List (almost identical implementation), @@ -129,9 +127,8 @@ private int GetCapacity(int length) { return capacity; } - private bool Equals(ImmutableArray other) { - return Equals(_items, other._items) && _size == other._size && Count == other.Count; - } + private bool Equals(ImmutableArray other) + => Equals(_items, other._items) && _size == other._size && Count == other.Count; public override bool Equals(object obj) => obj is ImmutableArray other && Equals(other); diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Node.cs b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.Node.cs similarity index 94% rename from src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Node.cs rename to src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.Node.cs index be9c9ab62..da6147a3b 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.Node.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.Node.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,10 +15,12 @@ using System.Diagnostics; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal partial struct PathResolverSnapshot { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public partial struct PathResolverSnapshot { [DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")] private class Node { public readonly ImmutableArray Children; diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.cs similarity index 97% rename from src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs rename to src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.cs index c1f69c132..56c86decf 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PathResolverSnapshot.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PathResolverSnapshot.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -21,11 +20,13 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal partial struct PathResolverSnapshot { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public partial struct PathResolverSnapshot { private static readonly bool IgnoreCaseInPaths = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX); private static readonly StringComparison PathsStringComparison = IgnoreCaseInPaths ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; @@ -41,7 +42,7 @@ internal partial struct PathResolverSnapshot { // // When search paths changes, nodes may be added or removed from this subtree private readonly Node _nonRooted; - + // This node contains available builtin modules. private readonly Node _builtins; private readonly PythonLanguageVersion _pythonLanguageVersion; @@ -52,7 +53,7 @@ internal partial struct PathResolverSnapshot { private readonly int _userRootsCount; public int Version { get; } - public PathResolverSnapshot(PythonLanguageVersion pythonLanguageVersion) + public PathResolverSnapshot(PythonLanguageVersion pythonLanguageVersion) : this(pythonLanguageVersion, string.Empty, Array.Empty(), Array.Empty(), ImmutableArray.Empty, 0, Node.CreateDefaultRoot(), Node.CreateBuiltinRoot(), default) { } private PathResolverSnapshot(PythonLanguageVersion pythonLanguageVersion, string workDirectory, string[] userSearchPaths, string[] interpreterSearchPaths, ImmutableArray roots, int userRootsCount, Node nonRooted, Node builtins, int version) { @@ -146,7 +147,7 @@ public IImportSearchResult GetImportsFromAbsoluteName(in string modulePath, in I if (TryFindImport(rootEdges, fullNameList, out var matchedEdges, out var shortestPath)) { return TryGetSearchResults(matchedEdges, out var searchResult) ? searchResult : new ImportNotFound(string.Join(".", fullNameList)); } - + if (fullNameList.Count == 1 && _builtins.TryGetChild(fullNameList[0], out var builtin)) { return new ModuleImport(builtin.Name, builtin.FullModuleName, null, null, true); } @@ -335,12 +336,12 @@ public PathResolverSnapshot SetBuiltins(in IEnumerable builtinModuleName return new PathResolverSnapshot( _pythonLanguageVersion, - _workDirectory, + _workDirectory, _userSearchPaths, _interpreterSearchPaths, _roots, _userRootsCount, - _nonRooted, + _nonRooted, Node.CreateBuiltinRoot(builtins), Version + 1); } @@ -355,7 +356,7 @@ private void CreateRoots(string rootDirectory, string[] userSearchPaths, string[ private void CreateRootsWithDefault(string rootDirectory, string[] userSearchPaths, string[] interpreterSearchPaths, out ImmutableArray nodes, out int userRootsCount) { var filteredUserSearchPaths = userSearchPaths.Select(FixPath) - .Except(new [] { rootDirectory }) + .Except(new[] { rootDirectory }) .ToArray(); var filteredInterpreterSearchPaths = interpreterSearchPaths.Select(FixPath) @@ -397,7 +398,7 @@ private ImmutableArray AddRootsFromSearchPaths(string[] userSearchPaths, s .AddRange(interpreterSearchPaths.Select(GetOrCreateRoot).ToArray()); } - private Node GetOrCreateRoot(string path) + private Node GetOrCreateRoot(string path) => _roots.FirstOrDefault(r => r.Name.Equals(path, PathsStringComparison)) ?? Node.CreateRoot(path); public PathResolverSnapshot AddModulePath(in string modulePath, out string fullModuleName) { @@ -438,7 +439,7 @@ public PathResolverSnapshot RemoveModulePath(in string modulePath) { var moduleParent = lastEdge.Start; var moduleIndex = lastEdge.EndIndex; - var newParent = moduleNode.Children.Count > 0 + var newParent = moduleNode.Children.Count > 0 ? moduleParent.ReplaceChildAt(moduleNode.ToPackage(), moduleIndex) // preserve node as package : moduleParent.RemoveChildAt(moduleIndex); @@ -474,7 +475,7 @@ private bool MatchNodePathInNonRooted(string normalizedPath, out Edge lastEdge, } lastEdge = lastEdge.Append(nameNodeIndex); - unmatchedPathSpan = new StringSpan(normalizedPath, - 1, 0); + unmatchedPathSpan = new StringSpan(normalizedPath, -1, 0); return true; } @@ -492,7 +493,7 @@ private bool MatchNodePath(in string normalizedModulePath, in int rootIndex, out } lastEdge = lastEdge.Append(childIndex); } - + return unmatchedPathSpan.Length == 0 && lastEdge.End.IsModule; } @@ -663,9 +664,8 @@ private static void AppendNameIfNotInitPy(StringBuilder builder, string name) { } } - private static void AppendName(StringBuilder builder, string name) { - builder.AppendIf(builder.Length > 0, ".").Append(name); - } + private static void AppendName(StringBuilder builder, string name) + => builder.AppendIf(builder.Length > 0, ".").Append(name); private static Node UpdateNodesFromEnd(Edge lastEdge, Node newEnd) { while (lastEdge.Start != default) { @@ -700,8 +700,8 @@ private bool TryFindModule(string modulePath, out Edge lastEdge, out StringSpan } // Search for module in root, or in - return rootIndex < _roots.Count - ? MatchNodePath(normalizedPath, rootIndex, out lastEdge, out unmatchedPathSpan) + return rootIndex < _roots.Count + ? MatchNodePath(normalizedPath, rootIndex, out lastEdge, out unmatchedPathSpan) : MatchNodePathInNonRooted(normalizedPath, out lastEdge, out unmatchedPathSpan); } @@ -728,28 +728,28 @@ private static bool IsRootedPathEndsWithPythonFile(string rootedPath) { return IsValidIdentifier(rootedPath, moduleNameStart, moduleNameLength); } - private static bool IsValidIdentifier(string str, int start, int length) + private static bool IsValidIdentifier(string str, int start, int length) => str[start].IsLatin1LetterOrUnderscore() && str.CharsAreLatin1LetterOrDigitOrUnderscore(start + 1, length - 1); private static bool IsPythonFile(string rootedPath) - => rootedPath.EndsWithAnyOrdinal(new[] {".py", ".pyi", ".pyw"}, IgnoreCaseInPaths); + => rootedPath.EndsWithAnyOrdinal(new[] { ".py", ".pyi", ".pyw" }, IgnoreCaseInPaths); private static bool IsPythonCompiled(string rootedPath) - => rootedPath.EndsWithAnyOrdinal(new[] {".pyd", ".so", ".dylib"}, IgnoreCaseInPaths); + => rootedPath.EndsWithAnyOrdinal(new[] { ".pyd", ".so", ".dylib" }, IgnoreCaseInPaths); - private static int GetModuleNameStart(string rootedModulePath) + private static int GetModuleNameStart(string rootedModulePath) => rootedModulePath.LastIndexOf(Path.DirectorySeparatorChar) + 1; - private static int GetModuleNameEnd(string rootedModulePath) + private static int GetModuleNameEnd(string rootedModulePath) => IsPythonCompiled(rootedModulePath) ? rootedModulePath.IndexOf('.', GetModuleNameStart(rootedModulePath)) : rootedModulePath.LastIndexOf('.'); private static bool IsNotInitPy(string name) => !name.EqualsOrdinal("__init__"); - private PathResolverSnapshot ReplaceNonRooted(Node nonRooted) + private PathResolverSnapshot ReplaceNonRooted(Node nonRooted) => new PathResolverSnapshot(_pythonLanguageVersion, _workDirectory, _userSearchPaths, _interpreterSearchPaths, _roots, _userRootsCount, nonRooted, _builtins, Version + 1); - private PathResolverSnapshot ImmutableReplaceRoot(Node root, int index) + private PathResolverSnapshot ImmutableReplaceRoot(Node root, int index) => new PathResolverSnapshot(_pythonLanguageVersion, _workDirectory, _userSearchPaths, _interpreterSearchPaths, _roots.ReplaceAt(index, root), _userRootsCount, _nonRooted, _builtins, Version + 1); } } diff --git a/src/Analysis/Engine/Impl/DependencyResolution/PossibleModuleImport.cs b/src/Analysis/Core/Impl/DependencyResolution/PossibleModuleImport.cs similarity index 86% rename from src/Analysis/Engine/Impl/DependencyResolution/PossibleModuleImport.cs rename to src/Analysis/Core/Impl/DependencyResolution/PossibleModuleImport.cs index cf9532085..aca2d8b1d 100644 --- a/src/Analysis/Engine/Impl/DependencyResolution/PossibleModuleImport.cs +++ b/src/Analysis/Core/Impl/DependencyResolution/PossibleModuleImport.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,8 +15,8 @@ using System.Collections.Generic; -namespace Microsoft.PythonTools.Analysis.DependencyResolution { - internal class PossibleModuleImport : IImportSearchResult { +namespace Microsoft.Python.Analysis.Core.DependencyResolution { + public class PossibleModuleImport : IImportSearchResult { public string PossibleModuleFullName { get; } public string RootPath { get; } public string PrecedingModuleFullName { get; } diff --git a/src/Analysis/Engine/Impl/Interpreter/InterpreterArchitecture.cs b/src/Analysis/Core/Impl/Interpreter/InterpreterArchitecture.cs similarity index 86% rename from src/Analysis/Engine/Impl/Interpreter/InterpreterArchitecture.cs rename to src/Analysis/Core/Impl/Interpreter/InterpreterArchitecture.cs index 24bc421fb..e3d6779b8 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InterpreterArchitecture.cs +++ b/src/Analysis/Core/Impl/Interpreter/InterpreterArchitecture.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,24 +8,21 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Interpreter { - public abstract class InterpreterArchitecture : +namespace Microsoft.Python.Analysis.Core.Interpreter { + public abstract class InterpreterArchitecture : IFormattable, IComparable, - IEquatable - { + IEquatable { protected abstract bool Equals(string value); - public virtual string ToString(string format, IFormatProvider formatProvider, string defaultString) { - return defaultString; - } + public virtual string ToString(string format, IFormatProvider formatProvider, string defaultString) => defaultString; public static readonly InterpreterArchitecture Unknown = new UnknownArchitecture(); public static readonly InterpreterArchitecture x86 = new X86Architecture(); @@ -36,9 +32,7 @@ public virtual string ToString(string format, IFormatProvider formatProvider, st public string ToString(string format) => ToString(format, null, ""); public string ToString(string format, IFormatProvider formatProvider) => ToString(format, formatProvider, ""); - public string ToPEP514() { - return ToString("PEP514", null); - } + public string ToPEP514() => ToString("PEP514", null); public static bool TryParse(string value, out InterpreterArchitecture arch) { arch = Unknown; @@ -57,28 +51,18 @@ public static bool TryParse(string value, out InterpreterArchitecture arch) { return false; } - public static InterpreterArchitecture TryParse(string value) { - InterpreterArchitecture result; - if (!TryParse(value, out result)) { - return Unknown; - } - return result; - } + public static InterpreterArchitecture TryParse(string value) + => !TryParse(value, out var result) ? Unknown : result; - public static InterpreterArchitecture Parse(string value) { - InterpreterArchitecture result; - if (!TryParse(value, out result)) { - throw new FormatException(); - } - return result; - } + public static InterpreterArchitecture Parse(string value) + => !TryParse(value, out var result) ? throw new FormatException() : result; public int CompareTo(InterpreterArchitecture other) { // We implement the full comparison here rather than delegating to // subclasses so that we have some way to handle extra // architectures being injected while ensuring that the // standard ones take priority. - + // The ordering is: // x86 // x64 @@ -109,9 +93,9 @@ public int CompareTo(InterpreterArchitecture other) { } public static bool operator ==(InterpreterArchitecture x, InterpreterArchitecture y) - => x?.Equals(y) ?? object.ReferenceEquals(y, null); + => x?.Equals(y) ?? ReferenceEquals(y, null); public static bool operator !=(InterpreterArchitecture x, InterpreterArchitecture y) - => !(x?.Equals(y) ?? object.ReferenceEquals(y, null)); + => !(x?.Equals(y) ?? ReferenceEquals(y, null)); public override bool Equals(object obj) => Equals(obj as InterpreterArchitecture); public bool Equals(InterpreterArchitecture other) => other != null && GetType().IsEquivalentTo(other.GetType()); public override int GetHashCode() => GetType().GetHashCode(); diff --git a/src/Analysis/Engine/Impl/Interpreter/InterpreterConfiguration.cs b/src/Analysis/Core/Impl/Interpreter/InterpreterConfiguration.cs similarity index 76% rename from src/Analysis/Engine/Impl/Interpreter/InterpreterConfiguration.cs rename to src/Analysis/Core/Impl/Interpreter/InterpreterConfiguration.cs index e6012dfa1..5211ccaf4 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InterpreterConfiguration.cs +++ b/src/Analysis/Core/Impl/Interpreter/InterpreterConfiguration.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,9 +17,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Interpreter { +namespace Microsoft.Python.Analysis.Core.Interpreter { public sealed class InterpreterConfiguration : IEquatable { private readonly string _description; private string _fullDescription; @@ -35,7 +34,9 @@ public InterpreterConfiguration( string pathVar = "", string libPath = null, string sitePackagesPath = null, - InterpreterArchitecture architecture = default(InterpreterArchitecture), + string typeshedPath = null, + string moduleCachePath = null, + InterpreterArchitecture architecture = default, Version version = null ) { Id = id; @@ -46,40 +47,21 @@ public InterpreterConfiguration( Version = version ?? new Version(); LibraryPath = libPath ?? string.Empty; SitePackagesPath = sitePackagesPath ?? string.Empty; + TypeshedPath = typeshedPath ?? string.Empty; + ModuleCachePath = moduleCachePath ?? string.Empty; } - [Obsolete] - public InterpreterConfiguration( - string id, - string description, - string prefixPath = null, - string path = null, - string winPath = "", - string pathVar = "", - InterpreterArchitecture arch = default(InterpreterArchitecture), - Version version = null, - InterpreterUIMode uiMode = InterpreterUIMode.Normal - ) { - Id = id; - _description = description ?? ""; - PrefixPath = prefixPath; - InterpreterPath = path; - WindowsInterpreterPath = string.IsNullOrEmpty(winPath) ? path : winPath; - PathEnvironmentVariable = pathVar; - Architecture = arch ?? InterpreterArchitecture.Unknown; - Version = version ?? new Version(); - UIMode = uiMode; - } - - private static string Read(Dictionary d, string k) + private static string Read(IReadOnlyDictionary d, string k) => d.TryGetValue(k, out var o) ? o as string : null; - private InterpreterConfiguration(Dictionary properties) { + private InterpreterConfiguration(IReadOnlyDictionary properties) { Id = Read(properties, nameof(Id)); _description = Read(properties, nameof(Description)) ?? ""; InterpreterPath = Read(properties, nameof(InterpreterPath)); PathEnvironmentVariable = Read(properties, nameof(PathEnvironmentVariable)); LibraryPath = Read(properties, nameof(LibraryPath)); + TypeshedPath = Read(properties, nameof(TypeshedPath)); + ModuleCachePath = Read(properties, nameof(ModuleCachePath)); Architecture = InterpreterArchitecture.TryParse(Read(properties, nameof(Architecture))); try { Version = Version.Parse(Read(properties, nameof(Version))); @@ -87,21 +69,24 @@ private InterpreterConfiguration(Dictionary properties) { Version = new Version(); } if (properties.TryGetValue(nameof(SearchPaths), out object o)) { - SearchPaths.Clear(); + var sp = new List(); if (o is string s) { - SearchPaths.AddRange(s.Split(';')); + sp.AddRange(s.Split(';')); } else if (o is IEnumerable ss) { - SearchPaths.AddRange(ss); + sp.AddRange(ss); } + SearchPaths = sp.ToArray(); } } - internal void WriteToDictionary(Dictionary properties) { + public void WriteToDictionary(IDictionary properties) { properties[nameof(Id)] = Id; properties[nameof(Description)] = _description; properties[nameof(InterpreterPath)] = InterpreterPath; properties[nameof(PathEnvironmentVariable)] = PathEnvironmentVariable; properties[nameof(LibraryPath)] = LibraryPath; + properties[nameof(TypeshedPath)] = TypeshedPath; + properties[nameof(ModuleCachePath)] = ModuleCachePath; properties[nameof(Architecture)] = Architecture.ToString(); if (Version != null) { properties[nameof(Version)] = Version.ToString(); @@ -112,13 +97,13 @@ internal void WriteToDictionary(Dictionary properties) { /// /// Reconstructs an interpreter configuration from a dictionary. /// - public static InterpreterConfiguration FromDictionary(Dictionary properties) + public static InterpreterConfiguration FromDictionary(IReadOnlyDictionary properties) => new InterpreterConfiguration(properties); /// /// Serializes an interpreter configuration to a dictionary. /// - public Dictionary ToDictionary() { + public IReadOnlyDictionary ToDictionary() { var d = new Dictionary(); WriteToDictionary(d); return d; @@ -155,22 +140,12 @@ public void SwitchToFullDescription() { } } - [Obsolete("Prefix path only applies to Windows.")] - public string PrefixPath { get; } - /// /// Returns the path to the interpreter executable for launching Python /// applications. /// public string InterpreterPath { get; } - /// - /// Returns the path to the interpreter executable for launching Python - /// applications which are windows applications (pythonw.exe, ipyw.exe). - /// - [Obsolete("Python Language Server is platform-agnostic and does not use Windows-specific settings.")] - public string WindowsInterpreterPath { get; } - /// /// Gets the environment variable which should be used to set sys.path. /// @@ -181,8 +156,6 @@ public void SwitchToFullDescription() { /// public InterpreterArchitecture Architecture { get; } - public string ArchitectureString => Architecture.ToString(); - /// /// The language version of the interpreter (e.g. 2.7). /// @@ -191,7 +164,7 @@ public void SwitchToFullDescription() { /// /// Returns path to Python standard libraries. /// - public string LibraryPath {get; } + public string LibraryPath { get; } /// /// Returns path to Python site packages from 'import site; print(site.getsitepackages())' @@ -199,20 +172,24 @@ public void SwitchToFullDescription() { public string SitePackagesPath { get; } /// - /// The UI behavior of the interpreter. + /// The fixed search paths of the interpreter. /// - [Obsolete("Language Server does not support UI features related to the interpreter.")] - public InterpreterUIMode UIMode { get; } + public IReadOnlyList SearchPaths { get; set; } = Array.Empty(); /// - /// The fixed search paths of the interpreter. + /// Typeshed root folder. + /// + public string TypeshedPath { get; set; } + + /// + /// Module cache folder. /// - public List SearchPaths { get; } = new List(); + public string ModuleCachePath { get; set; } public static bool operator ==(InterpreterConfiguration x, InterpreterConfiguration y) - => x?.Equals(y) ?? object.ReferenceEquals(y, null); + => x?.Equals(y) ?? ReferenceEquals(y, null); public static bool operator !=(InterpreterConfiguration x, InterpreterConfiguration y) - => !(x?.Equals(y) ?? object.ReferenceEquals(y, null)); + => !(x?.Equals(y) ?? ReferenceEquals(y, null)); public override bool Equals(object obj) => Equals(obj as InterpreterConfiguration); diff --git a/src/Analysis/Core/Impl/Interpreter/InterpreterUIMode.cs b/src/Analysis/Core/Impl/Interpreter/InterpreterUIMode.cs new file mode 100644 index 000000000..bce3fc7f8 --- /dev/null +++ b/src/Analysis/Core/Impl/Interpreter/InterpreterUIMode.cs @@ -0,0 +1,55 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; + +namespace Microsoft.Python.Analysis.Core.Interpreter { + /// + /// Specifies the interpreter's behavior in the UI. + /// + [Flags] + [Obsolete("Language Server does not support UI features related to the interpreter.")] + public enum InterpreterUIMode : int { + /// + /// Interpreter can be set or selected as the default, and is visible to + /// the user. + /// + Normal = 0x00, + + /// + /// Interpreter is not displayed in the user interface, but can still be + /// added to a project if the ID is known. + /// + Hidden = 0x01, + + /// + /// Interpreter cannot be selected as the default. Implies + /// . + /// + CannotBeDefault = 0x02, + + /// + /// Interpreter cannot be automatically selected as the default. + /// + CannotBeAutoDefault = 0x04, + + /// + /// Interpreter has no user-modifiable settings. + /// + CannotBeConfigured = 0x08, + + SupportsDatabase = 0x10, + } +} diff --git a/src/Analysis/Engine/Impl/ModulePath.cs b/src/Analysis/Core/Impl/Interpreter/ModulePath.cs similarity index 95% rename from src/Analysis/Engine/Impl/ModulePath.cs rename to src/Analysis/Core/Impl/Interpreter/ModulePath.cs index 0c6192bc1..4d1fdd2aa 100644 --- a/src/Analysis/Engine/Impl/ModulePath.cs +++ b/src/Analysis/Core/Impl/Interpreter/ModulePath.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,10 +21,10 @@ using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Analysis.Core.Interpreter { public struct ModulePath { public static readonly ModulePath Empty = new ModulePath(null, null, null); @@ -54,11 +53,7 @@ public static bool PythonVersionRequiresInitPyFiles(Version languageVersion) /// /// The last portion of . /// - public string Name { - get { - return FullName.Substring(FullName.LastIndexOf('.') + 1); - } - } + public string Name => FullName.Substring(FullName.LastIndexOf('.') + 1); /// /// True if the module is named '__main__' or '__init__'. @@ -78,7 +73,7 @@ public bool IsSpecialName { public string ModuleName { get { if (Name.Equals("__init__", StringComparison.OrdinalIgnoreCase)) { - int lastDot = FullName.LastIndexOf('.'); + var lastDot = FullName.LastIndexOf('.'); if (lastDot < 0) { return string.Empty; } else { @@ -203,7 +198,7 @@ bool includePackages var dirname = PathUtils.GetFileName(dir); var match = PythonPackageRegex.Match(dirname); if (match.Success && !match.Groups["stubs"].Success) { - bool hasInitPy = true; + var hasInitPy = true; var modulePath = dir; if (requireInitPy) { modulePath = GetPackageInitPy(dir); @@ -324,9 +319,7 @@ public static IEnumerable ExpandPathFiles(IEnumerable paths) { /// /// The original directories are not included in the result. /// - public static IEnumerable ExpandPathFiles(params string[] paths) { - return ExpandPathFiles(paths.AsEnumerable()); - } + public static IEnumerable ExpandPathFiles(params string[] paths) => ExpandPathFiles(paths.AsEnumerable()); /// /// Returns a sequence of ModulePaths for all modules importable from @@ -400,13 +393,8 @@ public static IEnumerable GetModulesInLib( /// /// Returns a sequence of ModulePaths for all modules importable by the provided factory. /// - public static IEnumerable GetModulesInLib(InterpreterConfiguration config) { - return GetModulesInLib( - config.LibraryPath, - config.SitePackagesPath, - PythonVersionRequiresInitPyFiles(config.Version) - ); - } + public static IEnumerable GetModulesInLib(InterpreterConfiguration config) + => GetModulesInLib(config.LibraryPath, config.SitePackagesPath, PythonVersionRequiresInitPyFiles(config.Version)); /// /// Returns true if the provided path references an importable Python @@ -524,9 +512,7 @@ public static bool IsInitPyFile(string path) { /// /// path is not a valid Python module. /// - public static ModulePath FromFullPath(string path) { - return FromFullPath(path, null, null); - } + public static ModulePath FromFullPath(string path) => FromFullPath(path, null, null); /// /// Returns a new ModulePath value determined from the provided full @@ -544,9 +530,7 @@ public static ModulePath FromFullPath(string path) { /// path is not a valid Python module. /// /// This overload - public static ModulePath FromFullPath(string path, string topLevelPath) { - return FromFullPath(path, topLevelPath, null); - } + public static ModulePath FromFullPath(string path, string topLevelPath) => FromFullPath(path, topLevelPath, null); /// /// Returns a new ModulePath value determined from the provided full @@ -643,19 +627,16 @@ public static ModulePath FromBasePathAndName( Func isPackage = null, Func getModule = null ) { - ModulePath module; - string errorParameter; - bool isInvalid, isMissing; if (FromBasePathAndName_NoThrow( basePath, moduleName, isPackage, getModule, requireInitPy, - out module, - out isInvalid, - out isMissing, - out errorParameter + out var module, + out var isInvalid, + out var isMissing, + out var errorParameter )) { return module; } @@ -683,7 +664,7 @@ private static bool IsModuleNameMatch(Regex regex, string path, string mod) { return m.Groups["name"].Value == mod; } - internal static string GetPackageInitPy(string path) { + public static string GetPackageInitPy(string path) { if (!Directory.Exists(path)) { return null; } @@ -703,7 +684,7 @@ internal static string GetPackageInitPy(string path) { } - internal static bool FromBasePathAndName_NoThrow( + public static bool FromBasePathAndName_NoThrow( string basePath, string moduleName, Func isPackage, @@ -714,7 +695,7 @@ internal static bool FromBasePathAndName_NoThrow( out bool isMissing, out string errorParameter ) { - modulePath = default(ModulePath); + modulePath = default; isInvalid = false; isMissing = false; errorParameter = null; @@ -742,7 +723,7 @@ out string errorParameter } var path = basePath; - bool allowStub = true; + var allowStub = true; Match m; foreach (var bit in bits.Take(bits.Length - 1)) { @@ -783,7 +764,7 @@ out string errorParameter return true; } - internal static bool FromBasePathAndFile_NoThrow( + public static bool FromBasePathAndFile_NoThrow( string basePath, string sourceFile, bool isPackage, @@ -791,7 +772,7 @@ internal static bool FromBasePathAndFile_NoThrow( out bool isInvalid, out bool isMissing ) { - modulePath = default(ModulePath); + modulePath = default; isInvalid = false; isMissing = false; @@ -843,7 +824,7 @@ out bool isMissing } - internal static IEnumerable GetParents(string name, bool includeFullName = true) { + public static IEnumerable GetParents(string name, bool includeFullName = true) { if (string.IsNullOrEmpty(name)) { yield break; } diff --git a/src/Analysis/Engine/Impl/Interpreter/PythonLibraryPath.cs b/src/Analysis/Core/Impl/Interpreter/PythonLibraryPath.cs similarity index 90% rename from src/Analysis/Engine/Impl/Interpreter/PythonLibraryPath.cs rename to src/Analysis/Core/Impl/Interpreter/PythonLibraryPath.cs index 613c8c501..3026de091 100644 --- a/src/Analysis/Engine/Impl/Interpreter/PythonLibraryPath.cs +++ b/src/Analysis/Core/Impl/Interpreter/PythonLibraryPath.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,14 +21,13 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.OS; using IOPath = System.IO.Path; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Analysis.Core.Interpreter { public sealed class PythonLibraryPath { - private readonly string _path; - private readonly bool _isStandardLibrary; private readonly string _modulePrefix; private static readonly Regex ParseRegex = new Regex( @@ -37,26 +35,19 @@ public sealed class PythonLibraryPath { ); public PythonLibraryPath(string path, bool isStandardLibrary, string modulePrefix) { - _path = path; - _isStandardLibrary = isStandardLibrary; + Path = path; + IsStandardLibrary = isStandardLibrary; _modulePrefix = modulePrefix; } - public string Path { - get { return _path; } - } + public string Path { get; } - public bool IsStandardLibrary { - get { return _isStandardLibrary; } - } + public bool IsStandardLibrary { get; } - public string ModulePrefix { - get { return _modulePrefix ?? string.Empty; } - } + public string ModulePrefix => _modulePrefix ?? string.Empty; - public override string ToString() { - return "{0}|{1}|{2}".FormatInvariant(_path, _isStandardLibrary ? "stdlib" : "", _modulePrefix ?? ""); - } + public override string ToString() + => "{0}|{1}|{2}".FormatInvariant(Path, IsStandardLibrary ? "stdlib" : "", _modulePrefix ?? ""); public static PythonLibraryPath Parse(string s) { if (string.IsNullOrEmpty(s)) { @@ -113,7 +104,7 @@ public static async Task> GetDatabaseSearchPathsAsync(I List paths; if (!string.IsNullOrEmpty(cachePath)) { paths = GetCachedDatabaseSearchPaths(cachePath); - if (paths != null) { + if (paths != null && paths.Count > 2) { return paths; } } @@ -155,7 +146,7 @@ public static async Task> GetUncachedDatabaseSearchPaths // path that we can filter out later var tempWorkingDir = IOPath.Combine(IOPath.GetTempPath(), IOPath.GetRandomFileName()); Directory.CreateDirectory(tempWorkingDir); - if (!InstallPath.TryGetFile("get_search_paths.py", out string srcGetSearchPaths)) { + if (!InstallPath.TryGetFile("get_search_paths.py", out var srcGetSearchPaths)) { return new List(); } var getSearchPaths = IOPath.Combine(tempWorkingDir, PathUtils.GetFileName(srcGetSearchPaths)); @@ -165,7 +156,6 @@ public static async Task> GetUncachedDatabaseSearchPaths var errorLines = new List { "Cannot obtain list of paths" }; try { - using (var seenNullData = new ManualResetEventSlim()) using (var proc = new ProcessHelper(interpreter, new[] { "-S", "-E", getSearchPaths }, tempWorkingDir)) { proc.OnOutputLine = lines.Add; proc.OnErrorLine = errorLines.Add; diff --git a/src/Analysis/Core/Impl/Microsoft.Python.Analysis.Core.csproj b/src/Analysis/Core/Impl/Microsoft.Python.Analysis.Core.csproj new file mode 100644 index 000000000..4e97b8e58 --- /dev/null +++ b/src/Analysis/Core/Impl/Microsoft.Python.Analysis.Core.csproj @@ -0,0 +1,28 @@ + + + netstandard2.0 + Microsoft.Python.Analysis + Microsoft.Python.Analysis.Core + + + + 1701;1702;$(NoWarn) + 7.2 + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + diff --git a/src/Analysis/Core/Impl/Properties/AssemblyInfo.cs b/src/Analysis/Core/Impl/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..33b24b71a --- /dev/null +++ b/src/Analysis/Core/Impl/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.Python.Analysis.Engine, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("Microsoft.Python.Analysis, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("Microsoft.Python.Analysis.Engine.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/src/Analysis/Engine/Impl/AggregateProjectEntry.cs b/src/Analysis/Engine/Impl/AggregateProjectEntry.cs index 75ab769ef..fce242df6 100644 --- a/src/Analysis/Engine/Impl/AggregateProjectEntry.cs +++ b/src/Analysis/Engine/Impl/AggregateProjectEntry.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/AnalysisDictionary.cs b/src/Analysis/Engine/Impl/AnalysisDictionary.cs index cab4c8f22..321a3a989 100644 --- a/src/Analysis/Engine/Impl/AnalysisDictionary.cs +++ b/src/Analysis/Engine/Impl/AnalysisDictionary.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/AnalysisExtensions.cs b/src/Analysis/Engine/Impl/AnalysisExtensions.cs index 98a4929b8..8e4b348b1 100644 --- a/src/Analysis/Engine/Impl/AnalysisExtensions.cs +++ b/src/Analysis/Engine/Impl/AnalysisExtensions.cs @@ -9,13 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Interpreter { public static class AnalysisExtensions { diff --git a/src/Analysis/Engine/Impl/AnalysisHashSet.cs b/src/Analysis/Engine/Impl/AnalysisHashSet.cs index a612be922..40bc06000 100644 --- a/src/Analysis/Engine/Impl/AnalysisHashSet.cs +++ b/src/Analysis/Engine/Impl/AnalysisHashSet.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/AnalysisLimits.cs b/src/Analysis/Engine/Impl/AnalysisLimits.cs index ac34a7d62..fa685addf 100644 --- a/src/Analysis/Engine/Impl/AnalysisLimits.cs +++ b/src/Analysis/Engine/Impl/AnalysisLimits.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/AnalysisLog.cs b/src/Analysis/Engine/Impl/AnalysisLog.cs index 7e0a0a067..cb8b4b910 100644 --- a/src/Analysis/Engine/Impl/AnalysisLog.cs +++ b/src/Analysis/Engine/Impl/AnalysisLog.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/AnalysisLogWriter.cs b/src/Analysis/Engine/Impl/AnalysisLogWriter.cs index 7a9ff3357..4a9314931 100644 --- a/src/Analysis/Engine/Impl/AnalysisLogWriter.cs +++ b/src/Analysis/Engine/Impl/AnalysisLogWriter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,7 +22,8 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; namespace Microsoft.PythonTools.Analysis { public class AnalysisLogWriter : IDisposable { diff --git a/src/Analysis/Engine/Impl/AnalysisSet.cs b/src/Analysis/Engine/Impl/AnalysisSet.cs index efd8a5a38..f4a624f32 100644 --- a/src/Analysis/Engine/Impl/AnalysisSet.cs +++ b/src/Analysis/Engine/Impl/AnalysisSet.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/AnalysisUnit.cs b/src/Analysis/Engine/Impl/AnalysisUnit.cs index 27b7a0993..58b4891c6 100644 --- a/src/Analysis/Engine/Impl/AnalysisUnit.cs +++ b/src/Analysis/Engine/Impl/AnalysisUnit.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,12 +19,12 @@ using System.Diagnostics; using System.Linq; using System.Threading; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/AnalysisValue.cs b/src/Analysis/Engine/Impl/AnalysisValue.cs index 6e1b27af9..ca1093da1 100644 --- a/src/Analysis/Engine/Impl/AnalysisValue.cs +++ b/src/Analysis/Engine/Impl/AnalysisValue.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,8 +22,8 @@ using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/AnalysisValueSetExtensions.cs b/src/Analysis/Engine/Impl/AnalysisValueSetExtensions.cs index bd7d67316..4735801a1 100644 --- a/src/Analysis/Engine/Impl/AnalysisValueSetExtensions.cs +++ b/src/Analysis/Engine/Impl/AnalysisValueSetExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,10 +18,9 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/AnalysisVariable.cs b/src/Analysis/Engine/Impl/AnalysisVariable.cs index cb902bd2b..ca80536d2 100644 --- a/src/Analysis/Engine/Impl/AnalysisVariable.cs +++ b/src/Analysis/Engine/Impl/AnalysisVariable.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Analyzer/ClassScope.cs b/src/Analysis/Engine/Impl/Analyzer/ClassScope.cs index 939471f45..77010a158 100644 --- a/src/Analysis/Engine/Impl/Analyzer/ClassScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/ClassScope.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { sealed class ClassScope : InterpreterScope, IClassScope { diff --git a/src/Analysis/Engine/Impl/Analyzer/ComprehensionScope.cs b/src/Analysis/Engine/Impl/Analyzer/ComprehensionScope.cs index 7f6371600..c132c3194 100644 --- a/src/Analysis/Engine/Impl/Analyzer/ComprehensionScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/ComprehensionScope.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { sealed class ComprehensionScope : InterpreterScope { diff --git a/src/Analysis/Engine/Impl/Analyzer/DDG.cs b/src/Analysis/Engine/Impl/Analyzer/DDG.cs index a8a3bca6b..64805ac71 100644 --- a/src/Analysis/Engine/Impl/Analyzer/DDG.cs +++ b/src/Analysis/Engine/Impl/Analyzer/DDG.cs @@ -19,10 +19,10 @@ using System.Diagnostics; using System.Linq; using System.Threading; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { internal class DDG : PythonWalker { @@ -422,7 +422,7 @@ internal void WalkBody(Node node, AnalysisUnit unit) { } public override bool Walk(IfStatement node) { - foreach (var test in node.TestsInternal) { + foreach (var test in node.Tests) { _eval.Evaluate(test.Test); var prevScope = Scope; diff --git a/src/Analysis/Engine/Impl/Analyzer/DependencyInfo.cs b/src/Analysis/Engine/Impl/Analyzer/DependencyInfo.cs index 4d5d037c9..7d896b9d2 100644 --- a/src/Analysis/Engine/Impl/Analyzer/DependencyInfo.cs +++ b/src/Analysis/Engine/Impl/Analyzer/DependencyInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Analyzer/DependentKeyValue.cs b/src/Analysis/Engine/Impl/Analyzer/DependentKeyValue.cs index 9005fd376..fd896b199 100644 --- a/src/Analysis/Engine/Impl/Analyzer/DependentKeyValue.cs +++ b/src/Analysis/Engine/Impl/Analyzer/DependentKeyValue.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Analyzer/ErrorMessages.cs b/src/Analysis/Engine/Impl/Analyzer/ErrorMessages.cs index 11090b72a..dbeb146c6 100644 --- a/src/Analysis/Engine/Impl/Analyzer/ErrorMessages.cs +++ b/src/Analysis/Engine/Impl/Analyzer/ErrorMessages.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Analysis.Analyzer { static class ErrorMessages { diff --git a/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs b/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs index 78508cc01..a06d8ee41 100644 --- a/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs +++ b/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluator.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,8 +20,8 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { internal class ExpressionEvaluator { diff --git a/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluatorAnnotationConverter.cs b/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluatorAnnotationConverter.cs index 29e9d3a1c..290c1cc66 100644 --- a/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluatorAnnotationConverter.cs +++ b/src/Analysis/Engine/Impl/Analyzer/ExpressionEvaluatorAnnotationConverter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,7 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { class ExpressionEvaluatorAnnotationConverter : TypeAnnotationConverter { diff --git a/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs b/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs index fc8c375ca..99149ac45 100644 --- a/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs +++ b/src/Analysis/Engine/Impl/Analyzer/FunctionAnalysisUnit.cs @@ -17,10 +17,10 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { class FunctionAnalysisUnit : AnalysisUnit { diff --git a/src/Analysis/Engine/Impl/Analyzer/FunctionScope.cs b/src/Analysis/Engine/Impl/Analyzer/FunctionScope.cs index 05bb0249e..d124f30a5 100644 --- a/src/Analysis/Engine/Impl/Analyzer/FunctionScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/FunctionScope.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Diagnostics; using System.Linq; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { sealed class FunctionScope : InterpreterScope, IFunctionScope { diff --git a/src/Analysis/Engine/Impl/Analyzer/InterpreterScope.cs b/src/Analysis/Engine/Impl/Analyzer/InterpreterScope.cs index de2051be5..3b7295e36 100644 --- a/src/Analysis/Engine/Impl/Analyzer/InterpreterScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/InterpreterScope.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { abstract class InterpreterScope: IScope { diff --git a/src/Analysis/Engine/Impl/Analyzer/IsInstanceScope.cs b/src/Analysis/Engine/Impl/Analyzer/IsInstanceScope.cs index c3b80a576..d822c0f0c 100644 --- a/src/Analysis/Engine/Impl/Analyzer/IsInstanceScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/IsInstanceScope.cs @@ -9,15 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { sealed class IsInstanceScope : InterpreterScope { diff --git a/src/Analysis/Engine/Impl/Analyzer/ModuleScope.cs b/src/Analysis/Engine/Impl/Analyzer/ModuleScope.cs index 8b7687f1c..03e4e76c3 100644 --- a/src/Analysis/Engine/Impl/Analyzer/ModuleScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/ModuleScope.cs @@ -9,11 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Values; namespace Microsoft.PythonTools.Analysis.Analyzer { @@ -33,7 +34,7 @@ internal void SetModuleVariable(string name, IAnalysisSet value) public override string Name => Module.Name; - public override bool AssignVariable(string name, Parsing.Ast.Node location, AnalysisUnit unit, IAnalysisSet values) { + public override bool AssignVariable(string name, Node location, AnalysisUnit unit, IAnalysisSet values) { if (base.AssignVariable(name, location, unit, values)) { Module.ModuleDefinition.EnqueueDependents(); return true; diff --git a/src/Analysis/Engine/Impl/Analyzer/OverviewWalker.cs b/src/Analysis/Engine/Impl/Analyzer/OverviewWalker.cs index e8574267e..17ec2e603 100644 --- a/src/Analysis/Engine/Impl/Analyzer/OverviewWalker.cs +++ b/src/Analysis/Engine/Impl/Analyzer/OverviewWalker.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,8 +19,8 @@ using System.Diagnostics; using System.Linq; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { /// @@ -453,8 +453,8 @@ public override bool Walk(FromImportStatement node) { public override bool Walk(IfStatement node) { UpdateChildRanges(node); - if (node.TestsInternal != null) { - foreach (var test in node.TestsInternal) { + if (node.Tests != null) { + foreach (var test in node.Tests) { var isInstanceNames = GetIsInstanceNamesAndExpressions(test.Test); if (isInstanceNames != null) { if (test.Test != null) { @@ -558,11 +558,13 @@ public override bool Walk(SuiteStatement node) { var lineNo = _tree.IndexToLocation(node.EndIndex).Line; int offset; - if (_tree._lineLocations.Length == 0) { + if (_tree.NewLineLocations.Length == 0) { // single line input offset = 0; } else { - offset = lineNo < _tree._lineLocations.Length ? _tree._lineLocations[lineNo].EndIndex : _tree._lineLocations[_tree._lineLocations.Length - 1].EndIndex; + offset = lineNo < _tree.NewLineLocations.Length + ? _tree.NewLineLocations[lineNo].EndIndex + : _tree.NewLineLocations[_tree.NewLineLocations.Length - 1].EndIndex; } var closingScope = new StatementScope(offset, _scope); _scope.Children.Add(closingScope); diff --git a/src/Analysis/Engine/Impl/Analyzer/StatementScope.cs b/src/Analysis/Engine/Impl/Analyzer/StatementScope.cs index af431bb8a..290217110 100644 --- a/src/Analysis/Engine/Impl/Analyzer/StatementScope.cs +++ b/src/Analysis/Engine/Impl/Analyzer/StatementScope.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Analyzer { class StatementScope : InterpreterScope { diff --git a/src/Analysis/Engine/Impl/Definitions/Diagnostic.cs b/src/Analysis/Engine/Impl/Definitions/Diagnostic.cs index fc3657320..8919aeecf 100644 --- a/src/Analysis/Engine/Impl/Definitions/Diagnostic.cs +++ b/src/Analysis/Engine/Impl/Definitions/Diagnostic.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; +using Microsoft.Python.Core.Text; namespace Microsoft.PythonTools.Analysis { public class Diagnostic { diff --git a/src/Analysis/Engine/Impl/Definitions/GetMemberOptions.cs b/src/Analysis/Engine/Impl/Definitions/GetMemberOptions.cs index 2c97e6042..4f118dd2d 100644 --- a/src/Analysis/Engine/Impl/Definitions/GetMemberOptions.cs +++ b/src/Analysis/Engine/Impl/Definitions/GetMemberOptions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IAggregateableProjectEntry.cs b/src/Analysis/Engine/Impl/Definitions/IAggregateableProjectEntry.cs index b6343525e..9bfaa0a68 100644 --- a/src/Analysis/Engine/Impl/Definitions/IAggregateableProjectEntry.cs +++ b/src/Analysis/Engine/Impl/Definitions/IAggregateableProjectEntry.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IAnalysisCookie.cs b/src/Analysis/Engine/Impl/Definitions/IAnalysisCookie.cs index 8af943909..9c0ccff10 100644 --- a/src/Analysis/Engine/Impl/Definitions/IAnalysisCookie.cs +++ b/src/Analysis/Engine/Impl/Definitions/IAnalysisCookie.cs @@ -9,13 +9,11 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; - namespace Microsoft.PythonTools.Analysis { /// /// Marker interface for analysis cookies. Analysis cookies are opaque objects diff --git a/src/Analysis/Engine/Impl/Definitions/IAnalysisSet.cs b/src/Analysis/Engine/Impl/Definitions/IAnalysisSet.cs index 1e5b9d893..c1b2f015d 100644 --- a/src/Analysis/Engine/Impl/Definitions/IAnalysisSet.cs +++ b/src/Analysis/Engine/Impl/Definitions/IAnalysisSet.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IAnalysisUnit.cs b/src/Analysis/Engine/Impl/Definitions/IAnalysisUnit.cs index 282e75678..9d26c7ec9 100644 --- a/src/Analysis/Engine/Impl/Definitions/IAnalysisUnit.cs +++ b/src/Analysis/Engine/Impl/Definitions/IAnalysisUnit.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IAnalysisUnit : ILocationResolver, ICanExpire { diff --git a/src/Analysis/Engine/Impl/Definitions/IAnalysisVariable.cs b/src/Analysis/Engine/Impl/Definitions/IAnalysisVariable.cs index 3f46300a4..eabf144ab 100644 --- a/src/Analysis/Engine/Impl/Definitions/IAnalysisVariable.cs +++ b/src/Analysis/Engine/Impl/Definitions/IAnalysisVariable.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IAnalyzable.cs b/src/Analysis/Engine/Impl/Definitions/IAnalyzable.cs index d508f6fce..1634782fc 100644 --- a/src/Analysis/Engine/Impl/Definitions/IAnalyzable.cs +++ b/src/Analysis/Engine/Impl/Definitions/IAnalyzable.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/ICanExpire.cs b/src/Analysis/Engine/Impl/Definitions/ICanExpire.cs index 11daeadb8..b8ad96d08 100644 --- a/src/Analysis/Engine/Impl/Definitions/ICanExpire.cs +++ b/src/Analysis/Engine/Impl/Definitions/ICanExpire.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IDocument.cs b/src/Analysis/Engine/Impl/Definitions/IDocument.cs index 621c06070..a726eface 100644 --- a/src/Analysis/Engine/Impl/Definitions/IDocument.cs +++ b/src/Analysis/Engine/Impl/Definitions/IDocument.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IEncodedLocation.cs b/src/Analysis/Engine/Impl/Definitions/IEncodedLocation.cs index 863f51350..696ff7643 100644 --- a/src/Analysis/Engine/Impl/Definitions/IEncodedLocation.cs +++ b/src/Analysis/Engine/Impl/Definitions/IEncodedLocation.cs @@ -9,14 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Generic; -using System.Text; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/Definitions/IEphemeralVariableDefinition.cs b/src/Analysis/Engine/Impl/Definitions/IEphemeralVariableDefinition.cs index 705b85c52..a73cae0b8 100644 --- a/src/Analysis/Engine/Impl/Definitions/IEphemeralVariableDefinition.cs +++ b/src/Analysis/Engine/Impl/Definitions/IEphemeralVariableDefinition.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IExternalProjectEntry.cs b/src/Analysis/Engine/Impl/Definitions/IExternalProjectEntry.cs index 90975d065..903c8a7a8 100644 --- a/src/Analysis/Engine/Impl/Definitions/IExternalProjectEntry.cs +++ b/src/Analysis/Engine/Impl/Definitions/IExternalProjectEntry.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IFunctionScope.cs b/src/Analysis/Engine/Impl/Definitions/IFunctionScope.cs index 10e53fea8..7fcc464ed 100644 --- a/src/Analysis/Engine/Impl/Definitions/IFunctionScope.cs +++ b/src/Analysis/Engine/Impl/Definitions/IFunctionScope.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProject.cs b/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProject.cs index db04a6c53..dec67802e 100644 --- a/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProject.cs +++ b/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProject.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProjectEntry.cs b/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProjectEntry.cs index f0012554c..ab31246c7 100644 --- a/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProjectEntry.cs +++ b/src/Analysis/Engine/Impl/Definitions/IGroupableAnalysisProjectEntry.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IHasQualifiedName.cs b/src/Analysis/Engine/Impl/Definitions/IHasQualifiedName.cs index aa85704df..4de5595b9 100644 --- a/src/Analysis/Engine/Impl/Definitions/IHasQualifiedName.cs +++ b/src/Analysis/Engine/Impl/Definitions/IHasQualifiedName.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IHasRichDescription.cs b/src/Analysis/Engine/Impl/Definitions/IHasRichDescription.cs index 87cf16fef..4b873ae3b 100644 --- a/src/Analysis/Engine/Impl/Definitions/IHasRichDescription.cs +++ b/src/Analysis/Engine/Impl/Definitions/IHasRichDescription.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/ILocatedMember.cs b/src/Analysis/Engine/Impl/Definitions/ILocatedMember.cs index fb214d505..df351da2e 100644 --- a/src/Analysis/Engine/Impl/Definitions/ILocatedMember.cs +++ b/src/Analysis/Engine/Impl/Definitions/ILocatedMember.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/ILocatedVariableDefinition.cs b/src/Analysis/Engine/Impl/Definitions/ILocatedVariableDefinition.cs index 75feeb395..1ed5463e0 100644 --- a/src/Analysis/Engine/Impl/Definitions/ILocatedVariableDefinition.cs +++ b/src/Analysis/Engine/Impl/Definitions/ILocatedVariableDefinition.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/ILocationInfo.cs b/src/Analysis/Engine/Impl/Definitions/ILocationInfo.cs index 64956f44c..50ed23c6b 100644 --- a/src/Analysis/Engine/Impl/Definitions/ILocationInfo.cs +++ b/src/Analysis/Engine/Impl/Definitions/ILocationInfo.cs @@ -9,12 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; +using Microsoft.Python.Core.Text; namespace Microsoft.PythonTools.Analysis { public interface ILocationInfo: IEquatable, ILocationResolver { diff --git a/src/Analysis/Engine/Impl/Definitions/ILocationResolver.cs b/src/Analysis/Engine/Impl/Definitions/ILocationResolver.cs index 29f72c524..258671df4 100644 --- a/src/Analysis/Engine/Impl/Definitions/ILocationResolver.cs +++ b/src/Analysis/Engine/Impl/Definitions/ILocationResolver.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IMemberResult.cs b/src/Analysis/Engine/Impl/Definitions/IMemberResult.cs index 788da12b3..389b5405b 100644 --- a/src/Analysis/Engine/Impl/Definitions/IMemberResult.cs +++ b/src/Analysis/Engine/Impl/Definitions/IMemberResult.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IModule.cs b/src/Analysis/Engine/Impl/Definitions/IModule.cs index 20c4282fa..484a1e7b5 100644 --- a/src/Analysis/Engine/Impl/Definitions/IModule.cs +++ b/src/Analysis/Engine/Impl/Definitions/IModule.cs @@ -17,7 +17,7 @@ using System.Collections.Generic; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IModule : IAnalysisValue { diff --git a/src/Analysis/Engine/Impl/Definitions/IModuleAnalysis.cs b/src/Analysis/Engine/Impl/Definitions/IModuleAnalysis.cs index df1e0f554..3ccfe2380 100644 --- a/src/Analysis/Engine/Impl/Definitions/IModuleAnalysis.cs +++ b/src/Analysis/Engine/Impl/Definitions/IModuleAnalysis.cs @@ -9,15 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IModuleAnalysis { diff --git a/src/Analysis/Engine/Impl/Definitions/IModuleContext.cs b/src/Analysis/Engine/Impl/Definitions/IModuleContext.cs index 1ed9a4507..3e3bb8b08 100644 --- a/src/Analysis/Engine/Impl/Definitions/IModuleContext.cs +++ b/src/Analysis/Engine/Impl/Definitions/IModuleContext.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IModuleScope.cs b/src/Analysis/Engine/Impl/Definitions/IModuleScope.cs index f797c57e7..06d57cf3d 100644 --- a/src/Analysis/Engine/Impl/Definitions/IModuleScope.cs +++ b/src/Analysis/Engine/Impl/Definitions/IModuleScope.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IProjectEntry.cs b/src/Analysis/Engine/Impl/Definitions/IProjectEntry.cs index 8217bad42..f96aa6f9e 100644 --- a/src/Analysis/Engine/Impl/Definitions/IProjectEntry.cs +++ b/src/Analysis/Engine/Impl/Definitions/IProjectEntry.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IPythonAnalyzer.cs b/src/Analysis/Engine/Impl/Definitions/IPythonAnalyzer.cs index 460ae7b30..9b99b68d9 100644 --- a/src/Analysis/Engine/Impl/Definitions/IPythonAnalyzer.cs +++ b/src/Analysis/Engine/Impl/Definitions/IPythonAnalyzer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,8 +19,8 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IPythonAnalyzer: IGroupableAnalysisProject { diff --git a/src/Analysis/Engine/Impl/Definitions/IPythonParse.cs b/src/Analysis/Engine/Impl/Definitions/IPythonParse.cs index c39888ebb..d0ae16871 100644 --- a/src/Analysis/Engine/Impl/Definitions/IPythonParse.cs +++ b/src/Analysis/Engine/Impl/Definitions/IPythonParse.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IPythonParse : IDisposable { diff --git a/src/Analysis/Engine/Impl/Definitions/IPythonProjectEntry.cs b/src/Analysis/Engine/Impl/Definitions/IPythonProjectEntry.cs index 4d3bd6a80..a8cdc9974 100644 --- a/src/Analysis/Engine/Impl/Definitions/IPythonProjectEntry.cs +++ b/src/Analysis/Engine/Impl/Definitions/IPythonProjectEntry.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Threading; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IPythonProjectEntry : IGroupableAnalysisProjectEntry, IProjectEntry { diff --git a/src/Analysis/Engine/Impl/Definitions/IReferenceable.cs b/src/Analysis/Engine/Impl/Definitions/IReferenceable.cs index 6a55a2756..4b5a1652a 100644 --- a/src/Analysis/Engine/Impl/Definitions/IReferenceable.cs +++ b/src/Analysis/Engine/Impl/Definitions/IReferenceable.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/IScope.cs b/src/Analysis/Engine/Impl/Definitions/IScope.cs index e01b266e0..d890dc0df 100644 --- a/src/Analysis/Engine/Impl/Definitions/IScope.cs +++ b/src/Analysis/Engine/Impl/Definitions/IScope.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IScope { diff --git a/src/Analysis/Engine/Impl/Definitions/IVariableDefinition.cs b/src/Analysis/Engine/Impl/Definitions/IVariableDefinition.cs index e15766cb8..fe09e35f7 100644 --- a/src/Analysis/Engine/Impl/Definitions/IVariableDefinition.cs +++ b/src/Analysis/Engine/Impl/Definitions/IVariableDefinition.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public interface IVariableDefinition: IReferenceable { diff --git a/src/Analysis/Engine/Impl/Definitions/IVersioned.cs b/src/Analysis/Engine/Impl/Definitions/IVersioned.cs index 7ddaa2b1a..a2588e902 100644 --- a/src/Analysis/Engine/Impl/Definitions/IVersioned.cs +++ b/src/Analysis/Engine/Impl/Definitions/IVersioned.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/VariableType.cs b/src/Analysis/Engine/Impl/Definitions/VariableType.cs index c57aab401..6470a5488 100644 --- a/src/Analysis/Engine/Impl/Definitions/VariableType.cs +++ b/src/Analysis/Engine/Impl/Definitions/VariableType.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Definitions/WellKnownRichDescriptionKinds.cs b/src/Analysis/Engine/Impl/Definitions/WellKnownRichDescriptionKinds.cs index ad60e4e46..6173b8c06 100644 --- a/src/Analysis/Engine/Impl/Definitions/WellKnownRichDescriptionKinds.cs +++ b/src/Analysis/Engine/Impl/Definitions/WellKnownRichDescriptionKinds.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Deque.cs b/src/Analysis/Engine/Impl/Deque.cs index a9ac7e037..7b7850801 100644 --- a/src/Analysis/Engine/Impl/Deque.cs +++ b/src/Analysis/Engine/Impl/Deque.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/DocumentBuffer.cs b/src/Analysis/Engine/Impl/DocumentBuffer.cs index 82812fee0..b324685e2 100644 --- a/src/Analysis/Engine/Impl/DocumentBuffer.cs +++ b/src/Analysis/Engine/Impl/DocumentBuffer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Analysis { class DocumentBuffer { diff --git a/src/Analysis/Engine/Impl/DocumentChange.cs b/src/Analysis/Engine/Impl/DocumentChange.cs index a2ca55c22..823cf54df 100644 --- a/src/Analysis/Engine/Impl/DocumentChange.cs +++ b/src/Analysis/Engine/Impl/DocumentChange.cs @@ -9,14 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public sealed class DocumentChangeSet { diff --git a/src/Analysis/Engine/Impl/Documentation/DocumentationBuilder.cs b/src/Analysis/Engine/Impl/Documentation/DocumentationBuilder.cs index 88a6ccaa8..e3d52b7b5 100644 --- a/src/Analysis/Engine/Impl/Documentation/DocumentationBuilder.cs +++ b/src/Analysis/Engine/Impl/Documentation/DocumentationBuilder.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,7 @@ using System.IO; using System.Linq; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; namespace Microsoft.PythonTools.Analysis.Documentation { diff --git a/src/Analysis/Engine/Impl/Documentation/InformationDisplayOptions.cs b/src/Analysis/Engine/Impl/Documentation/InformationDisplayOptions.cs index 4e217614c..c3fc6dae2 100644 --- a/src/Analysis/Engine/Impl/Documentation/InformationDisplayOptions.cs +++ b/src/Analysis/Engine/Impl/Documentation/InformationDisplayOptions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Documentation/MarkdownDocumentationBuilder.cs b/src/Analysis/Engine/Impl/Documentation/MarkdownDocumentationBuilder.cs index 8eada2206..aff991f13 100644 --- a/src/Analysis/Engine/Impl/Documentation/MarkdownDocumentationBuilder.cs +++ b/src/Analysis/Engine/Impl/Documentation/MarkdownDocumentationBuilder.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System; using System.IO; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Analysis.Documentation { internal sealed class MarkdownDocumentationBuilder : DocumentationBuilder { diff --git a/src/Analysis/Engine/Impl/Documentation/MarkupContent.cs b/src/Analysis/Engine/Impl/Documentation/MarkupContent.cs index a633f6ec7..6822212a6 100644 --- a/src/Analysis/Engine/Impl/Documentation/MarkupContent.cs +++ b/src/Analysis/Engine/Impl/Documentation/MarkupContent.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Documentation/MarkupKind.cs b/src/Analysis/Engine/Impl/Documentation/MarkupKind.cs index 712a2e995..5a43e50d4 100644 --- a/src/Analysis/Engine/Impl/Documentation/MarkupKind.cs +++ b/src/Analysis/Engine/Impl/Documentation/MarkupKind.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Documentation/PlainTextDocumentationBuilder.cs b/src/Analysis/Engine/Impl/Documentation/PlainTextDocumentationBuilder.cs index 590ad3e7a..03ab0be05 100644 --- a/src/Analysis/Engine/Impl/Documentation/PlainTextDocumentationBuilder.cs +++ b/src/Analysis/Engine/Impl/Documentation/PlainTextDocumentationBuilder.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Documentation/RestTextConverter.cs b/src/Analysis/Engine/Impl/Documentation/RestTextConverter.cs index 47c8e06aa..8d9b83b2a 100644 --- a/src/Analysis/Engine/Impl/Documentation/RestTextConverter.cs +++ b/src/Analysis/Engine/Impl/Documentation/RestTextConverter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; // Based on https://github.com/Microsoft/vscode-python/blob/master/src/client/common/markdown/restTextConverter.ts diff --git a/src/Analysis/Engine/Impl/EmptyBuiltinModule.cs b/src/Analysis/Engine/Impl/EmptyBuiltinModule.cs index dab810cb8..fccc4f9d6 100644 --- a/src/Analysis/Engine/Impl/EmptyBuiltinModule.cs +++ b/src/Analysis/Engine/Impl/EmptyBuiltinModule.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/EncodedLocation.cs b/src/Analysis/Engine/Impl/EncodedLocation.cs index f8ba0bc13..53f26eda5 100644 --- a/src/Analysis/Engine/Impl/EncodedLocation.cs +++ b/src/Analysis/Engine/Impl/EncodedLocation.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/ExportedMemberInfo.cs b/src/Analysis/Engine/Impl/ExportedMemberInfo.cs index 6e2c1ea34..13859279e 100644 --- a/src/Analysis/Engine/Impl/ExportedMemberInfo.cs +++ b/src/Analysis/Engine/Impl/ExportedMemberInfo.cs @@ -9,13 +9,11 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; - namespace Microsoft.PythonTools.Analysis { /// /// Provides information about a value exported from a module. diff --git a/src/Analysis/Engine/Impl/ExpressionFinder.cs b/src/Analysis/Engine/Impl/ExpressionFinder.cs index 5cdd9cde1..cfcaaefaa 100644 --- a/src/Analysis/Engine/Impl/ExpressionFinder.cs +++ b/src/Analysis/Engine/Impl/ExpressionFinder.cs @@ -9,16 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.IO; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { sealed class ExpressionFinder { @@ -92,13 +93,9 @@ public Node GetExpression(SourceSpan range) { return GetExpression(startIndex, endIndex); } - public SourceSpan? GetExpressionSpan(int startIndex, int endIndex) { - return GetExpression(startIndex, endIndex)?.GetSpan(Ast); - } + public SourceSpan? GetExpressionSpan(int startIndex, int endIndex) => GetExpression(startIndex, endIndex)?.GetSpan(Ast); - public SourceSpan? GetExpressionSpan(SourceSpan range) { - return GetExpression(range)?.GetSpan(Ast); - } + public SourceSpan? GetExpressionSpan(SourceSpan range) => GetExpression(range)?.GetSpan(Ast); private abstract class ExpressionWalker : PythonWalkerWithLocation { public ExpressionWalker(int location) : base(location) { } diff --git a/src/Analysis/Engine/Impl/HashSetExtensions.cs b/src/Analysis/Engine/Impl/HashSetExtensions.cs index 95c76d423..50bfbcb7e 100644 --- a/src/Analysis/Engine/Impl/HashSetExtensions.cs +++ b/src/Analysis/Engine/Impl/HashSetExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/IdDispenser.cs b/src/Analysis/Engine/Impl/IdDispenser.cs index 63aa52e45..d35116e31 100644 --- a/src/Analysis/Engine/Impl/IdDispenser.cs +++ b/src/Analysis/Engine/Impl/IdDispenser.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Infrastructure/LinearSpan.cs b/src/Analysis/Engine/Impl/Infrastructure/LinearSpan.cs deleted file mode 100644 index ecc201f62..000000000 --- a/src/Analysis/Engine/Impl/Infrastructure/LinearSpan.cs +++ /dev/null @@ -1,258 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; -using System.Diagnostics; - -namespace Microsoft.PythonTools.Analysis.Infrastructure { - public class LinearSpan { - /// - /// Returns an empty, invalid span. - /// - public static LinearSpan EmptySpan { get; } = new LinearSpan(0, 0); - - /// - /// Creates span starting at position 0 and length of 0 - /// - [DebuggerStepThrough] - public LinearSpan() : this(0) { } - - /// - /// Creates span starting at given position and length of zero. - /// - /// Start position - [DebuggerStepThrough] - public LinearSpan(int position) { - Start = position; - End = position < int.MaxValue ? position + 1 : position; - } - - /// - /// Creates span based on start and end positions. - /// End is exclusive, Length = End - Start - /// Span start - /// Span length - /// - [DebuggerStepThrough] - public LinearSpan(int start, int length) { - Check.Argument(nameof(length), () => length >= 0); - Start = start; - End = start + length; - } - - /// - /// Creates span based on another span - /// - /// Span to use as position source - public LinearSpan(LinearSpan span) : this(span.Start, span.Length) { } - - /// - /// Resets span to (0, 0) - /// - [DebuggerStepThrough] - public void Empty() { - Start = 0; - End = 0; - } - - /// - /// Creates span based on start and end positions. - /// End is exclusive, Length = End - Start - /// - /// - /// - [DebuggerStepThrough] - public static LinearSpan FromBounds(int start, int end) => new LinearSpan(start, end - start); - - /// - /// Finds out of span intersects another span - /// - /// Start of another span - /// Length of another span - /// True if spans intersect - [DebuggerStepThrough] - public virtual bool Intersect(int start, int length) => Intersect(this, start, length); - - /// - /// Finds out of span intersects another span - /// - /// span - /// True if spans intersect - [DebuggerStepThrough] - public virtual bool Intersect(LinearSpan span) => Intersect(this, span.Start, span.Length); - - /// - /// Finds out if span represents valid span (it's length is greater than zero) - /// - /// True if span is valid - [DebuggerStepThrough] - public virtual bool IsValid() => IsValid(this); - - #region LinearSpan - /// - /// span start position - /// - public int Start { get; private set; } - - /// - /// span end position (excluded) - /// - public int End { get; private set; } - - /// - /// span length - /// - public int Length => End - Start; - - /// - /// Determines if span contains given position - /// - [DebuggerStepThrough] - public virtual bool Contains(int position) => Contains(this, position); - #endregion - - /// - /// Determines if span fully contains another span - /// - [DebuggerStepThrough] - public virtual bool Contains(LinearSpan span) => Contains(span.Start) && Contains(span.End); - - /// - /// Finds out if span represents valid span (when span is not null and it's length is greater than zero) - /// - /// True if span is valid - [DebuggerStepThrough] - public static bool IsValid(LinearSpan span) => span != null && span.Length > 0; - - /// - /// Determines if span contains given position - /// - /// True if position is inside the span - [DebuggerStepThrough] - public static bool Contains(LinearSpan span, int position) => Contains(span.Start, span.Length, position); - - /// - /// Determines if span contains another span - /// - [DebuggerStepThrough] - public static bool Contains(LinearSpan span, LinearSpan other) => span.Contains(other.Start) && span.Contains(other.End); - - /// - /// Determines if span contains given position - /// - /// Start of the span - /// Length of the span - /// Position - /// True if position is inside the span - public static bool Contains(int spanStart, int spanLength, int position) { - if (spanLength == 0 && position == spanStart) { - return true; - } - return position >= spanStart && position < spanStart + spanLength; - } - - /// - /// Calculates span that includes both supplied spans. - /// - public static LinearSpan Union(LinearSpan span1, LinearSpan span2) { - var start = Math.Min(span1.Start, span2.Start); - var end = Math.Max(span1.End, span2.End); - - return start <= end ? FromBounds(start, end) : EmptySpan; - } - - /// - /// Calculates span that includes both supplied spans. - /// - public static LinearSpan Union(LinearSpan span1, int spanStart, int spanLength) { - var start = Math.Min(span1.Start, spanStart); - var end = Math.Max(span1.End, spanStart + spanLength); - - return start <= end ? FromBounds(start, end) : EmptySpan; - } - - /// - /// Finds out if span intersects another span - /// - /// First text span - /// Second text span - /// True if spans intersect - [DebuggerStepThrough] - public static bool Intersect(LinearSpan span1, LinearSpan span2) - => Intersect(span1, span2.Start, span2.Length); - - /// - /// Finds out if span intersects another span - /// - /// First text span - /// Start of the second span - /// Length of the second span - /// True if spans intersect - [DebuggerStepThrough] - public static bool Intersect(LinearSpan span1, int spanStart2, int spanLength2) - => Intersect(span1.Start, span1.Length, spanStart2, spanLength2); - - /// - /// Finds out if span intersects another span - /// - /// Start of the first span - /// Length of the first span - /// Start of the second span - /// Length of the second span - /// True if spans intersect - public static bool Intersect(int spanStart1, int spanLength1, int spanStart2, int spanLength2) { - // !(spanEnd2 <= spanStart1 || spanStart2 >= spanEnd1) - - // Support intersection with empty spans - - if (spanLength1 == 0 && spanLength2 == 0) { - return spanStart1 == spanStart2; - } - - if (spanLength1 == 0) { - return Contains(spanStart2, spanLength2, spanStart1); - } - - if (spanLength2 == 0) { - return Contains(spanStart1, spanLength1, spanStart2); - } - - return spanStart2 + spanLength2 > spanStart1 && spanStart2 < spanStart1 + spanLength1; - } - - /// - /// Calculates span that is an intersection of the supplied spans. - /// - /// Intersection or empty span if spans don't intersect - public static LinearSpan Intersection(LinearSpan span1, LinearSpan span2) { - var start = Math.Max(span1.Start, span2.Start); - var end = Math.Min(span1.End, span2.End); - - return start <= end ? FromBounds(start, end) : EmptySpan; - } - - /// - /// Calculates span that is an intersection of the supplied spans. - /// - /// Intersection or empty span if spans don't intersect - public static LinearSpan Intersection(LinearSpan span1, int spanStart, int spanLength) { - var start = Math.Max(span1.Start, spanStart); - var end = Math.Min(span1.End, spanStart + spanLength); - - return start <= end ? FromBounds(start, end) : EmptySpan; - } - } -} diff --git a/src/Analysis/Engine/Impl/Intellisense/AnalysisPriority.cs b/src/Analysis/Engine/Impl/Intellisense/AnalysisPriority.cs index 64dc989e8..f8bffc0be 100644 --- a/src/Analysis/Engine/Impl/Intellisense/AnalysisPriority.cs +++ b/src/Analysis/Engine/Impl/Intellisense/AnalysisPriority.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs b/src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs index 143e66ed8..98704d772 100644 --- a/src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs +++ b/src/Analysis/Engine/Impl/Intellisense/AnalysisQueue.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,8 +19,10 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Disposables; +using Microsoft.Python.Core.Threading; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; namespace Microsoft.PythonTools.Intellisense { /// diff --git a/src/Analysis/Engine/Impl/Intellisense/DetectSideEffectsWalker.cs b/src/Analysis/Engine/Impl/Intellisense/DetectSideEffectsWalker.cs index 31619fc1c..fa4bbd4e3 100644 --- a/src/Analysis/Engine/Impl/Intellisense/DetectSideEffectsWalker.cs +++ b/src/Analysis/Engine/Impl/Intellisense/DetectSideEffectsWalker.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Intellisense { /// diff --git a/src/Analysis/Engine/Impl/Intellisense/EnclosingNodeWalker.cs b/src/Analysis/Engine/Impl/Intellisense/EnclosingNodeWalker.cs index 2a7d4efcd..644ad2a42 100644 --- a/src/Analysis/Engine/Impl/Intellisense/EnclosingNodeWalker.cs +++ b/src/Analysis/Engine/Impl/Intellisense/EnclosingNodeWalker.cs @@ -9,15 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Intellisense { diff --git a/src/Analysis/Engine/Impl/Intellisense/ExtractMethodResult.cs b/src/Analysis/Engine/Impl/Intellisense/ExtractMethodResult.cs index 842940de4..e222e36af 100644 --- a/src/Analysis/Engine/Impl/Intellisense/ExtractMethodResult.cs +++ b/src/Analysis/Engine/Impl/Intellisense/ExtractMethodResult.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Intellisense/ExtractedMethodCreator.cs b/src/Analysis/Engine/Impl/Intellisense/ExtractedMethodCreator.cs index b7ff83880..423ff2020 100644 --- a/src/Analysis/Engine/Impl/Intellisense/ExtractedMethodCreator.cs +++ b/src/Analysis/Engine/Impl/Intellisense/ExtractedMethodCreator.cs @@ -9,19 +9,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Intellisense { class OutOfProcExtractedMethodCreator { diff --git a/src/Analysis/Engine/Impl/Intellisense/FlowChecker.cs b/src/Analysis/Engine/Impl/Intellisense/FlowChecker.cs index 6fb129370..7034aa2ce 100644 --- a/src/Analysis/Engine/Impl/Intellisense/FlowChecker.cs +++ b/src/Analysis/Engine/Impl/Intellisense/FlowChecker.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; /* * The data flow. @@ -388,7 +388,7 @@ public override bool Walk(IfStatement node) { _bits = new BitArray(_bits.Length); - foreach (IfStatementTest ist in node.TestsInternal) { + foreach (IfStatementTest ist in node.Tests) { // Set the initial branch value to bits _bits.SetAll(false); _bits.Or(save); diff --git a/src/Analysis/Engine/Impl/Intellisense/IAnalysisFileHandler.cs b/src/Analysis/Engine/Impl/Intellisense/IAnalysisFileHandler.cs index f61b89f32..7f004c8b3 100644 --- a/src/Analysis/Engine/Impl/Intellisense/IAnalysisFileHandler.cs +++ b/src/Analysis/Engine/Impl/Intellisense/IAnalysisFileHandler.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Intellisense/ImportRemover.cs b/src/Analysis/Engine/Impl/Intellisense/ImportRemover.cs index 8ba086615..450d23548 100644 --- a/src/Analysis/Engine/Impl/Intellisense/ImportRemover.cs +++ b/src/Analysis/Engine/Impl/Intellisense/ImportRemover.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +17,8 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; +using Microsoft.Python.Core.Text; namespace Microsoft.PythonTools.Intellisense { class ImportRemover { @@ -51,9 +51,9 @@ internal IReadOnlyList RemoveImports() { //var node = removeInfo.Node; var removing = removeInfo.ToRemove; var removed = removeInfo.Statement; - UpdatedStatement updatedStatement = removed.InitialStatement; + var updatedStatement = removed.InitialStatement; - int removeCount = 0; + var removeCount = 0; for (int i = 0, curRemoveIndex = 0; i < removed.NameCount; i++) { if (removed.IsRemoved(i, removing)) { removeCount++; @@ -71,7 +71,7 @@ internal IReadOnlyList RemoveImports() { } else { var newCode = updatedStatement.ToCodeString(_ast); - int proceedingLength = (removed.LeadingWhitespace ?? "").Length; + var proceedingLength = (removed.LeadingWhitespace ?? "").Length; changes.Add(DocumentChange.Replace(new SourceSpan( _ast.IndexToLocation(removed.Node.StartIndex - proceedingLength), @@ -86,9 +86,9 @@ private void DeleteStatement(List changes, SourceSpan span, bool // remove the entire node, leave any trailing whitespace/comments, but include the // newline and any indentation. - int start = _ast.LocationToIndex(span.Start); - int length = _ast.GetSpanLength(span); - int cur = start - 1; + var start = _ast.LocationToIndex(span.Start); + var length = _ast.GetSpanLength(span); + var cur = start - 1; if (!insertPass) { // backup to remove any indentation while (start - 1 > 0) { @@ -349,7 +349,7 @@ public bool InTargetScope { } public ICollection GetToRemove() { - Dictionary removeInfo = new Dictionary(); + var removeInfo = new Dictionary(); foreach (var nameAndList in _importedNames) { if (!_readNames.Contains(nameAndList.Key)) { @@ -369,7 +369,7 @@ public ICollection GetToRemove() { public override bool Walk(ImportStatement node) { if (InTargetScope && !(_scopes[_scopes.Count - 1] is ClassDefinition)) { - for (int i = 0; i < node.Names.Count; i++) { + for (var i = 0; i < node.Names.Count; i++) { if (node.AsNames != null && node.AsNames[i] != null) { var name = node.AsNames[i].Name; TrackImport(node, name); @@ -387,12 +387,12 @@ private void TrackImport(Statement node, string name) { StrongBox statementCount; if (!_statementCount.TryGetValue(parent, out statementCount)) { - PythonAst outerParent = parent as PythonAst; + var outerParent = parent as PythonAst; if (outerParent != null) { // we don't care about the number of children at the top level statementCount = new StrongBox(-1); } else { - FunctionDefinition funcDef = parent as FunctionDefinition; + var funcDef = parent as FunctionDefinition; if (funcDef != null) { statementCount = GetNumberOfChildStatements(funcDef.Body); } else { @@ -420,7 +420,7 @@ private static StrongBox GetNumberOfChildStatements(Statement body) { public override bool Walk(FromImportStatement node) { if (InTargetScope && !node.IsFromFuture && !(_scopes[_scopes.Count - 1] is ClassDefinition)) { - for (int i = 0; i < node.Names.Count; i++) { + for (var i = 0; i < node.Names.Count; i++) { if (node.Names[i].Name == "*") { // ignore from .. import * continue; diff --git a/src/Analysis/Engine/Impl/Intellisense/ImportedModuleNameWalker.cs b/src/Analysis/Engine/Impl/Intellisense/ImportedModuleNameWalker.cs index 73ae4c1d5..5e77adf1f 100644 --- a/src/Analysis/Engine/Impl/Intellisense/ImportedModuleNameWalker.cs +++ b/src/Analysis/Engine/Impl/Intellisense/ImportedModuleNameWalker.cs @@ -9,16 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; +using Microsoft.Python.Core.Text; namespace Microsoft.PythonTools.Intellisense { sealed class NamedLocation { diff --git a/src/Analysis/Engine/Impl/Intellisense/LineInfo.cs b/src/Analysis/Engine/Impl/Intellisense/LineInfo.cs index ed59e5b6a..29bb716a4 100644 --- a/src/Analysis/Engine/Impl/Intellisense/LineInfo.cs +++ b/src/Analysis/Engine/Impl/Intellisense/LineInfo.cs @@ -9,13 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Intellisense { struct LineInfo { @@ -47,9 +48,9 @@ public LineInfo(int start, int length, int lineNo, NewLineKind lineBreak) { public static IEnumerable SplitLines(string text, int firstLineNumber = 0) { NewLineLocation nextLine; - int lineNo = firstLineNumber; + var lineNo = firstLineNumber; - int lastLineEnd = 0; + var lastLineEnd = 0; while ((nextLine = NewLineLocation.FindNewLine(text, lastLineEnd)).EndIndex != lastLineEnd) { yield return new LineInfo( lastLineEnd, diff --git a/src/Analysis/Engine/Impl/Intellisense/LinePreservingCodeReplacer.cs b/src/Analysis/Engine/Impl/Intellisense/LinePreservingCodeReplacer.cs index b56347782..e7a563b79 100644 --- a/src/Analysis/Engine/Impl/Intellisense/LinePreservingCodeReplacer.cs +++ b/src/Analysis/Engine/Impl/Intellisense/LinePreservingCodeReplacer.cs @@ -9,17 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using Microsoft.PythonTools.Analysis; using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Core.Text; +using Microsoft.PythonTools.Analysis; namespace Microsoft.PythonTools.Intellisense { /// diff --git a/src/Analysis/Engine/Impl/Intellisense/LongestCommonSequence.cs b/src/Analysis/Engine/Impl/Intellisense/LongestCommonSequence.cs index 1470766c9..ca9a8b03c 100644 --- a/src/Analysis/Engine/Impl/Intellisense/LongestCommonSequence.cs +++ b/src/Analysis/Engine/Impl/Intellisense/LongestCommonSequence.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -258,4 +258,4 @@ public override int GetHashCode() { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Intellisense/ProjectEntryExtensions.cs b/src/Analysis/Engine/Impl/Intellisense/ProjectEntryExtensions.cs index e4346a666..db0d34156 100644 --- a/src/Analysis/Engine/Impl/Intellisense/ProjectEntryExtensions.cs +++ b/src/Analysis/Engine/Impl/Intellisense/ProjectEntryExtensions.cs @@ -9,20 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; -using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Intellisense { static class ProjectEntryExtensions { diff --git a/src/Analysis/Engine/Impl/Intellisense/SelectionTarget.cs b/src/Analysis/Engine/Impl/Intellisense/SelectionTarget.cs index 981f73337..a279db561 100644 --- a/src/Analysis/Engine/Impl/Intellisense/SelectionTarget.cs +++ b/src/Analysis/Engine/Impl/Intellisense/SelectionTarget.cs @@ -9,14 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Intellisense { abstract class SelectionTarget { diff --git a/src/Analysis/Engine/Impl/Intellisense/VersionCookie.cs b/src/Analysis/Engine/Impl/Intellisense/VersionCookie.cs index b2b2432bb..78e94d664 100644 --- a/src/Analysis/Engine/Impl/Intellisense/VersionCookie.cs +++ b/src/Analysis/Engine/Impl/Intellisense/VersionCookie.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,9 +18,9 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Intellisense { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalker.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalker.cs index 7316bce0c..6e2de7867 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalker.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalker.cs @@ -18,8 +18,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { [DebuggerDisplay("{Target.Name}")] diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalkerSet.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalkerSet.cs index cb6300d20..d87948101 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalkerSet.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisFunctionWalkerSet.cs @@ -16,8 +16,8 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisWalker.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisWalker.cs index b8d9582df..7f003d216 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisWalker.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstAnalysisWalker.cs @@ -18,11 +18,11 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstAnalysisWalker : PythonWalker { @@ -373,7 +373,7 @@ private void ImportMembersFromPackage(FromImportStatement node, PackageImport pa public override bool Walk(IfStatement node) { var allValidComparisons = true; - foreach (var test in node.TestsInternal) { + foreach (var test in node.Tests) { if (test.Test is BinaryExpression cmp && cmp.Left is MemberExpression me && (me.Target as NameExpression)?.Name == "sys" && me.Name == "version_info" && cmp.Right is TupleExpression te && te.Items.All(i => (i as ConstantExpression)?.Value is int)) { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinPythonModule.cs index 6415511f0..34ef4b417 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinPythonModule.cs @@ -9,14 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.IO; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; namespace Microsoft.PythonTools.Interpreter.Ast { class AstBuiltinPythonModule : AstScrapedPythonModule { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinsPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinsPythonModule.cs index 9ef20664a..cf135c3fd 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinsPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstBuiltinsPythonModule.cs @@ -18,9 +18,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstBuiltinsPythonModule : AstScrapedPythonModule, IBuiltinPythonModule { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstCachedPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstCachedPythonModule.cs index 4a3caf060..82a578281 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstCachedPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstCachedPythonModule.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.IO; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.IO; namespace Microsoft.PythonTools.Interpreter.Ast { class AstCachedPythonModule : AstScrapedPythonModule { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleCache.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleCache.cs index 1266cbe0f..85ad3214d 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleCache.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleCache.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,9 +20,11 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; namespace Microsoft.PythonTools.Interpreter.Ast { internal sealed class AstModuleCache { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleResolution.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleResolution.cs index 4ccf04d6b..d61525a85 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleResolution.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstModuleResolution.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,14 +22,16 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; namespace Microsoft.PythonTools.Interpreter.Ast { internal sealed class AstModuleResolution { - private static IReadOnlyDictionary _emptyModuleSet = new Dictionary(); + private static readonly IReadOnlyDictionary _emptyModuleSet = new Dictionary(); private readonly IPythonInterpreter _interpreter; private readonly ConcurrentDictionary _modules; private readonly AstModuleCache _astModuleCache; diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModule.cs index ce9297a04..56bfc5eb6 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModule.cs @@ -18,8 +18,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Threading; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; namespace Microsoft.PythonTools.Interpreter.Ast { internal sealed class AstNestedPythonModule : PythonModuleType, IPythonModule, ILocatedMember { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModuleMember.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModuleMember.cs index dcbad360e..af8a9617b 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModuleMember.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstNestedPythonModuleMember.cs @@ -9,13 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Linq; using System.Threading; using Microsoft.PythonTools.Analysis; diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonClass.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonClass.cs index 111028c6b..f89ad8a0b 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonClass.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonClass.cs @@ -18,9 +18,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstPythonClass : AstPythonType, IPythonClass { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonFunction.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonFunction.cs index cf79624e2..655ac496f 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonFunction.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonFunction.cs @@ -16,9 +16,9 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstPythonFunction : AstPythonType, IPythonFunction { @@ -41,7 +41,7 @@ ILocationInfo loc _doc = declaringType?.Documentation; } - foreach (var dec in (FunctionDefinition.Decorators?.Decorators).MaybeEnumerate().ExcludeDefault().OfType()) { + foreach (var dec in (FunctionDefinition.Decorators?.Decorators).MaybeEnumerate().OfType()) { if (dec.Name == "classmethod") { IsClassMethod = true; } else if (dec.Name == "staticmethod") { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreter.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreter.cs index ef4ec8ce6..c35fd5fd2 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreter.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,14 +18,13 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; namespace Microsoft.PythonTools.Interpreter.Ast { internal class AstPythonInterpreter : IPythonInterpreter2, IModuleContext { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreterFactory.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreterFactory.cs index a71e342dd..5f4adc08a 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreterFactory.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonInterpreterFactory.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,9 +18,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; namespace Microsoft.PythonTools.Interpreter.Ast { public class AstPythonInterpreterFactory : IPythonInterpreterFactory, IPythonInterpreterFactoryWithLog, ICustomInterpreterSerialization, IDisposable { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonModule.cs index 0c4d509d1..0721603f5 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonModule.cs @@ -20,10 +20,11 @@ using System.Linq; using System.Text; using System.Threading; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { sealed class AstPythonModule : PythonModuleType, IPythonModule, IProjectEntry, ILocatedMember { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonMultipleMembers.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonMultipleMembers.cs index d130703e0..2dd76cb83 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonMultipleMembers.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonMultipleMembers.cs @@ -17,9 +17,9 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstPythonMultipleMembers : IPythonMultipleMembers, ILocatedMember { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonParameterInfo.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonParameterInfo.cs index 11065ca52..662489977 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonParameterInfo.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonParameterInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +17,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstPythonParameterInfo : IParameterInfo { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonProperty.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonProperty.cs index 0c46ee251..f59225713 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonProperty.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonProperty.cs @@ -1,8 +1,22 @@ -using System.Collections.Generic; +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstPythonProperty : AstPythonType, IPythonProperty { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonStringLiteral.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonStringLiteral.cs index 8e522628f..2d5c622c3 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonStringLiteral.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonStringLiteral.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonTypeWrapper.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonTypeWrapper.cs index 097a2a6f5..ffcae7d68 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonTypeWrapper.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstPythonTypeWrapper.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Interpreter.Ast { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstScrapedPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstScrapedPythonModule.cs index d874eb88d..4121a65f7 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstScrapedPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstScrapedPythonModule.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -21,10 +20,13 @@ using System.Linq; using System.Text; using System.Threading; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.OS; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstScrapedPythonModule : PythonModuleType, IPythonModule diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypeAnnotationConverter.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypeAnnotationConverter.cs index 979a8163a..9c8a76e34 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypeAnnotationConverter.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypeAnnotationConverter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,8 +18,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { class AstTypeAnnotationConverter : TypeAnnotationConverter { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypingModule.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypingModule.cs index ecb1c385e..a5e3c455d 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypingModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/AstTypingModule.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.IO; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.IO; namespace Microsoft.PythonTools.Interpreter.Ast { class AstTypingModule : AstCachedPythonModule { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/NameLookupContext.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/NameLookupContext.cs index b7d04a427..1581e9696 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/NameLookupContext.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/NameLookupContext.cs @@ -19,10 +19,10 @@ using System.Diagnostics; using System.Linq; using System.Numerics; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter.Ast { sealed class NameLookupContext { @@ -374,7 +374,7 @@ private IMember GetValueFromCallable(CallExpression expr, LookupOptions options) } if (value == null) { - _log?.Log(TraceLevel.Verbose, "UnknownCallable", expr.Target.ToCodeString(Ast).Trim()); + _log?.Log(TraceLevel.Verbose, $"Unknown callable: {expr.Target.ToCodeString(Ast).Trim()}"); } return value; } diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/PythonModuleLoader.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/PythonModuleLoader.cs index 04f35e1e4..98aaeae44 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/PythonModuleLoader.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/PythonModuleLoader.cs @@ -16,11 +16,11 @@ using System.IO; using System.Linq; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Interpreter.Ast { public static class PythonModuleLoader { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleContext.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleContext.cs index cd2eeae64..fc2f397a2 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleContext.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleContext.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis; +using Microsoft.Python.Analysis.Core.Interpreter; namespace Microsoft.PythonTools.Interpreter.Ast { public sealed class TryImportModuleContext { diff --git a/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleResult.cs b/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleResult.cs index 9cb170efd..d6c065761 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleResult.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Ast/TryImportModuleResult.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/CannotAnalyzeExtensionException.cs b/src/Analysis/Engine/Impl/Interpreter/CannotAnalyzeExtensionException.cs index 1fe053703..48e45a833 100644 --- a/src/Analysis/Engine/Impl/Interpreter/CannotAnalyzeExtensionException.cs +++ b/src/Analysis/Engine/Impl/Interpreter/CannotAnalyzeExtensionException.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/BuiltinTypeId.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/BuiltinTypeId.cs index 4abd2e27b..8cec8be28 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/BuiltinTypeId.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/BuiltinTypeId.cs @@ -16,7 +16,7 @@ using System; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IAdvancedPythonType.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IAdvancedPythonType.cs index cb00b537a..ba28da738 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IAdvancedPythonType.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IAdvancedPythonType.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IBuiltinPythonModule.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IBuiltinPythonModule.cs index a6120732b..5a4b7cfc2 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IBuiltinPythonModule.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IBuiltinPythonModule.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/ICustomInterpreterSerialization.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/ICustomInterpreterSerialization.cs index 901c2a2d1..43dda4f70 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/ICustomInterpreterSerialization.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/ICustomInterpreterSerialization.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IDotNetPythonInterpreter.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IDotNetPythonInterpreter.cs index 6ccd37072..70d591a20 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IDotNetPythonInterpreter.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IDotNetPythonInterpreter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterLog.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterLog.cs index 2b7f3ce41..097c6257d 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterLog.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterLog.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Microsoft.PythonTools.Interpreter { +namespace Microsoft.PythonTools.Interpreter { public interface IInterpreterLog { void Log(string msg); } diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterRegistryService.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterRegistryService.cs index 0a561a589..c7501228d 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterRegistryService.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IInterpreterRegistryService.cs @@ -9,13 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; +using Microsoft.Python.Analysis.Core.Interpreter; namespace Microsoft.PythonTools.Interpreter { public interface IInterpreterRegistryService { diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/ILazyMember.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/ILazyMember.cs index c67bb8661..391a77f67 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/ILazyMember.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/ILazyMember.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IMember.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IMember.cs index 8d05d2a9a..b7c9bf23b 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IMember.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IMember.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IMemberContainer.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IMemberContainer.cs index 946c0818a..a7020daf9 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IMemberContainer.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IMemberContainer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IParameterInfo.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IParameterInfo.cs index 4186fe6c9..56bfc84d1 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IParameterInfo.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IParameterInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonClass.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonClass.cs index 2a454c334..f411a6671 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonClass.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonClass.cs @@ -15,7 +15,7 @@ // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonCollectionTypes.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonCollectionTypes.cs index 8fef4615d..477e5f1f3 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonCollectionTypes.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonCollectionTypes.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonConstant.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonConstant.cs index f3ba2fb91..b5e533155 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonConstant.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonConstant.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonEvent.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonEvent.cs index 6abf538c5..83b30e0a8 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonEvent.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonEvent.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunction.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunction.cs index d310ce766..ef8647168 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunction.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunction.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunctionOverload.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunctionOverload.cs index 76bde7dac..4acad62b2 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunctionOverload.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonFunctionOverload.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreter.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreter.cs index e54006741..5c1e8965b 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreter.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterFactory.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterFactory.cs index 232887613..052efd1cf 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterFactory.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterFactory.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; +using Microsoft.Python.Analysis.Core.Interpreter; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithLog.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithLog.cs index a4ff9e8a2..7b9f9688d 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithLog.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithLog.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithProjectReferences.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithProjectReferences.cs index c43eecafd..0c40161bf 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithProjectReferences.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonInterpreterWithProjectReferences.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonMultipleMembers.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonMultipleMembers.cs index bb4bc6d70..fe4e3e0e1 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonMultipleMembers.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonMultipleMembers.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonProperty.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonProperty.cs index 7cca5d0b7..2fca499ff 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonProperty.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonProperty.cs @@ -14,7 +14,7 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonType.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonType.cs index d3d9f6a76..a193d9ea0 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonType.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/IPythonType.cs @@ -14,9 +14,6 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; - namespace Microsoft.PythonTools.Interpreter { public interface IPythonType : IMemberContainer, IMember { // Python __name__. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/ProjectReferenceKind.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/ProjectReferenceKind.cs index 486d9571c..d847f6b5a 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/ProjectReferenceKind.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/ProjectReferenceKind.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/Definitions/PythonMemberType.cs b/src/Analysis/Engine/Impl/Interpreter/Definitions/PythonMemberType.cs index db1e4bbeb..6732be27b 100644 --- a/src/Analysis/Engine/Impl/Interpreter/Definitions/PythonMemberType.cs +++ b/src/Analysis/Engine/Impl/Interpreter/Definitions/PythonMemberType.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/InMemoryProject.cs b/src/Analysis/Engine/Impl/Interpreter/InMemoryProject.cs index 970aa2461..6616d3387 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InMemoryProject.cs +++ b/src/Analysis/Engine/Impl/Interpreter/InMemoryProject.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreationOptions.cs b/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreationOptions.cs index fd3e4f04d..97fdc3c72 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreationOptions.cs +++ b/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreationOptions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Interpreter { /// diff --git a/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreator.cs b/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreator.cs index dbb9190d2..23b33e8dd 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreator.cs +++ b/src/Analysis/Engine/Impl/Interpreter/InterpreterFactoryCreator.cs @@ -9,16 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using System.IO; -using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Interpreter { /// @@ -57,7 +56,9 @@ public static IPythonInterpreterFactory CreateAnalysisInterpreterFactory( sitePackagesPath: null, version: languageVersion ); - config.SearchPaths.AddRange(searchPaths.MaybeEnumerate()); + var list = new List(config.SearchPaths); + list.AddRange(searchPaths.MaybeEnumerate()); + config.SearchPaths = list; var opts = new InterpreterFactoryCreationOptions { WatchFileSystem = false diff --git a/src/Analysis/Engine/Impl/Interpreter/InterpreterRegistryConstants.cs b/src/Analysis/Engine/Impl/Interpreter/InterpreterRegistryConstants.cs index 70d2a2269..d696ea951 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InterpreterRegistryConstants.cs +++ b/src/Analysis/Engine/Impl/Interpreter/InterpreterRegistryConstants.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/InterpreterUIMode.cs b/src/Analysis/Engine/Impl/Interpreter/InterpreterUIMode.cs index ab7aba8dd..26d5b8c90 100644 --- a/src/Analysis/Engine/Impl/Interpreter/InterpreterUIMode.cs +++ b/src/Analysis/Engine/Impl/Interpreter/InterpreterUIMode.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/NoInterpretersException.cs b/src/Analysis/Engine/Impl/Interpreter/NoInterpretersException.cs index e738f178e..48eef918f 100644 --- a/src/Analysis/Engine/Impl/Interpreter/NoInterpretersException.cs +++ b/src/Analysis/Engine/Impl/Interpreter/NoInterpretersException.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/PackageSpec.cs b/src/Analysis/Engine/Impl/Interpreter/PackageSpec.cs index 1bc668964..5ab65e44e 100644 --- a/src/Analysis/Engine/Impl/Interpreter/PackageSpec.cs +++ b/src/Analysis/Engine/Impl/Interpreter/PackageSpec.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/PackageVersion.cs b/src/Analysis/Engine/Impl/Interpreter/PackageVersion.cs index b3e9292e0..c3c5489fd 100644 --- a/src/Analysis/Engine/Impl/Interpreter/PackageVersion.cs +++ b/src/Analysis/Engine/Impl/Interpreter/PackageVersion.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,7 +21,7 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Interpreter { public struct PackageVersion : IComparable, IEquatable { diff --git a/src/Analysis/Engine/Impl/Interpreter/ProjectReference.cs b/src/Analysis/Engine/Impl/Interpreter/ProjectReference.cs index 800c0c13d..f0c73f763 100644 --- a/src/Analysis/Engine/Impl/Interpreter/ProjectReference.cs +++ b/src/Analysis/Engine/Impl/Interpreter/ProjectReference.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Interpreter/PythonInterpreterFactoryExtensions.cs b/src/Analysis/Engine/Impl/Interpreter/PythonInterpreterFactoryExtensions.cs index b41fd914f..0741391fc 100644 --- a/src/Analysis/Engine/Impl/Interpreter/PythonInterpreterFactoryExtensions.cs +++ b/src/Analysis/Engine/Impl/Interpreter/PythonInterpreterFactoryExtensions.cs @@ -9,13 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.IO; +using Microsoft.Python.Analysis.Core.Interpreter; namespace Microsoft.PythonTools.Interpreter { public static class PythonInterpreterFactoryExtensions { diff --git a/src/Analysis/Engine/Impl/KnownTypes.cs b/src/Analysis/Engine/Impl/KnownTypes.cs index a2600e494..fa1b54ff2 100644 --- a/src/Analysis/Engine/Impl/KnownTypes.cs +++ b/src/Analysis/Engine/Impl/KnownTypes.cs @@ -21,7 +21,7 @@ using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Analysis { internal interface IKnownPythonTypes { diff --git a/src/Analysis/Engine/Impl/LanguageServer/Enums.cs b/src/Analysis/Engine/Impl/LanguageServer/Enums.cs deleted file mode 100644 index 1fc9ffed8..000000000 --- a/src/Analysis/Engine/Impl/LanguageServer/Enums.cs +++ /dev/null @@ -1,171 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; - -namespace Microsoft.PythonTools.Analysis.LanguageServer { - public sealed class SerializeAsAttribute : Attribute { - public object Value { get; } - - public SerializeAsAttribute(object value) { - Value = value; - } - } - - public enum TraceLevel { - [SerializeAs("off")] - Off, - [SerializeAs("messages")] - Messages, - [SerializeAs("verbose")] - Verbose - } - - public enum SymbolKind { - None = 0, - File = 1, - Module = 2, - Namespace = 3, - Package = 4, - Class = 5, - Method = 6, - Property = 7, - Field = 8, - Constructor = 9, - Enum = 10, - Interface = 11, - Function = 12, - Variable = 13, - Constant = 14, - String = 15, - Number = 16, - Boolean = 17, - Array = 18, - Object = 19, - Key = 20, - Null = 21, - EnumMember = 22, - Struct = 23, - Event = 24, - Operator = 25, - TypeParameter = 26 - } - - public enum TextDocumentSyncKind : int { - None = 0, - Full = 1, - Incremental = 2 - } - - public enum MessageType : int { - /// - /// General language server output relevant to the user - /// such as information on Python interpreter type. - /// Does not conform to LSP definitions, Python LS specific. - /// - _General = 0, - - /// - /// Language server errors. - /// - Error = 1, - - /// - /// Language server warnings. - /// - Warning = 2, - - /// - /// Language server internal information. - /// - Info = 3, - - /// - /// Language server log-level diagnostic messages. - /// - Log = 4 - } - - public enum FileChangeType : int { - Created = 1, - Changed = 2, - Deleted = 3 - } - - public enum WatchKind : int { - Create = 1, - Change = 2, - Delete = 4 - } - - public enum TextDocumentSaveReason : int { - Manual = 1, - AfterDelay = 2, - FocusOut = 3 - } - - public enum CompletionTriggerKind : int { - Invoked = 1, - TriggerCharacter = 2 - } - - public enum InsertTextFormat : int { - PlainText = 1, - Snippet = 2 - } - - public enum CompletionItemKind : int { - None = 0, - Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19, - EnumMember = 20, - Constant = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25 - } - - public enum DocumentHighlightKind : int { - Text = 1, - Read = 2, - Write = 3 - } - - // Not in the LSP spec. - public enum ReferenceKind : int { - Definition = 1, - Reference = 2, - Value = 3 - } -} diff --git a/src/Analysis/Engine/Impl/LanguageServer/Extensibility.cs b/src/Analysis/Engine/Impl/LanguageServer/Extensibility.cs deleted file mode 100644 index f15e99041..000000000 --- a/src/Analysis/Engine/Impl/LanguageServer/Extensibility.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; -using Microsoft.PythonTools.Parsing.Ast; - -namespace Microsoft.PythonTools.Analysis.LanguageServer.Extensibility { - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public sealed class CompletionEventArgs : EventArgs { - public CompletionEventArgs(ModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList initialCompletionList) { - Analysis = analysis; - Tree = tree; - Location = location; - CompletionList = initialCompletionList; - } - - public ModuleAnalysis Analysis { get; } - public PythonAst Tree { get; } - public SourceLocation Location { get; } - - public CompletionList CompletionList; - } -} diff --git a/src/Analysis/Engine/Impl/LanguageServer/ILanguageServerExtension.cs b/src/Analysis/Engine/Impl/LanguageServer/ILanguageServerExtension.cs deleted file mode 100644 index c270d7471..000000000 --- a/src/Analysis/Engine/Impl/LanguageServer/ILanguageServerExtension.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; -using System.Collections.Generic; - -namespace Microsoft.PythonTools.Analysis.LanguageServer { - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public interface ILanguageServerExtension { - /// - /// The name of the extension. Used to look up the current instance - /// when processing extension command messages. If null or empty, - /// the extension cannot be sent messages and may be garbage collected - /// if it does not manage its own lifetime against the - /// instance provided to its provider. - /// - string Name { get; } - - /// - /// Called when an extension command arrives for this extension. - /// - IReadOnlyDictionary ExecuteCommand(string command, IReadOnlyDictionary properties); - } -} diff --git a/src/Analysis/Engine/Impl/LanguageServer/Server.cs b/src/Analysis/Engine/Impl/LanguageServer/Server.cs deleted file mode 100644 index 802c76881..000000000 --- a/src/Analysis/Engine/Impl/LanguageServer/Server.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; - -namespace Microsoft.PythonTools.Analysis.LanguageServer { - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public class Server : IServer { - public event EventHandler PostProcessCompletion; - - public void LogMessage(MessageType type, string message) { } - - public void ProcessCompletionList(ModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions) { - var evt = PostProcessCompletion; - if (evt != null) { - var e = new Extensibility.CompletionEventArgs(analysis, tree, location, completions); - try { - evt(this, e); - completions = e.CompletionList; - completions.items = completions.items ?? Array.Empty(); - } catch (Exception ex) when (!ex.IsCriticalException()) { - // We do not replace res in this case. - } - } - } - } -} diff --git a/src/Analysis/Engine/Impl/LanguageServer/Structures.cs b/src/Analysis/Engine/Impl/LanguageServer/Structures.cs deleted file mode 100644 index d2ae853f7..000000000 --- a/src/Analysis/Engine/Impl/LanguageServer/Structures.cs +++ /dev/null @@ -1,891 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; -using System.Collections.Generic; - -namespace Microsoft.PythonTools.Analysis.LanguageServer { - [Serializable] - public struct ResponseError { - public int code; - public string message; - } - - public struct ResponseError { - public int code; - public string message; - public T data; - } - - [Serializable] - public struct Position { - /// - /// Line position in a document (zero-based). - /// - public int line; - - /// - /// Character offset on a line in a document (zero-based). Assuming that the line is - /// represented as a string, the `character` value represents the gap between the - /// `character` and `character + 1`. - /// - /// If the character value is greater than the line length it defaults back to the - /// line length. - /// - public int character; - - public static implicit operator SourceLocation(Position p) => new SourceLocation(p.line + 1, p.character + 1); - public static implicit operator Position(SourceLocation loc) => new Position { line = loc.Line - 1, character = loc.Column - 1 }; - - public static bool operator >(Position p1, Position p2) => p1.line > p2.line || p1.line == p2.line && p1.character > p2.character; - public static bool operator <(Position p1, Position p2) => p1.line < p2.line || p1.line == p2.line && p1.character < p2.character; - - public override string ToString() => ((SourceLocation)this).ToString(); - } - - [Serializable] - public struct Range { - public Position start, end; - - public static implicit operator SourceSpan(Range r) => new SourceSpan(r.start, r.end); - public static implicit operator Range(SourceSpan span) => new Range { start = span.Start, end = span.End }; - - public override string ToString() => ((SourceSpan)this).ToString(); - } - - [Serializable] - public struct Location { - public Uri uri; - public Range range; - } - - [Serializable] - public struct Command { - /// - /// Title of the command, like `save`. - /// - public string title; - - /// - /// The identifier of the actual command handler. - /// - public string command; - - /// - /// Arguments that the command handler should be invoked with. - /// - public object[] arguments; - } - - [Serializable] - public struct TextEdit { - /// - /// The range of the text document to be manipulated. To insert - /// text into a document create a range where start === end. - /// - public Range range; - - /// - /// The string to be inserted. For delete operations use an - /// empty string. - /// - public string newText; - - /// - /// Extended version information specifying the source version - /// that range applies to. Should be used by the client to - /// adjust range before applying the edit. - /// - public int? _version; - } - - [Serializable] - public struct TextDocumentEdit { - public VersionedTextDocumentIdentifier textDocument; - public TextEdit[] edits; - } - - [Serializable] - public struct WorkspaceEdit { - public Dictionary changes; - public TextDocumentEdit[] documentChanges; - } - - [Serializable] - public struct TextDocumentIdentifier { - public Uri uri; - - public static implicit operator TextDocumentIdentifier(Uri uri) => new TextDocumentIdentifier { uri = uri }; - } - - [Serializable] - public struct TextDocumentItem { - public Uri uri; - public string languageId; - public int version; - public string text; - } - - [Serializable] - public struct VersionedTextDocumentIdentifier { - public Uri uri; - public int? version; - public int? _fromVersion; - } - - [Serializable] - public struct DocumentFilter { - /// - /// A language id, like `typescript`. - /// - public string language; - - /// - /// A Uri [scheme](#Uri.scheme), like `file` or `untitled`. - /// - public string scheme; - - /// - /// A glob pattern, like `*.{ts,js}`. - /// - public string pattern; - } - - [Serializable] - public class MarkupContent { - public string kind; - public string value; - - public static implicit operator MarkupContent(string text) => new MarkupContent { kind = MarkupKind.PlainText, value = text }; - } - - public class InformationDisplayOptions { - public string preferredFormat; - public bool trimDocumentationLines; - public int maxDocumentationLineLength; - public bool trimDocumentationText; - public int maxDocumentationTextLength; - public int maxDocumentationLines; - } - - /// - /// Required layout for the initializationOptions member of initializeParams - /// - [Serializable] - public class PythonInitializationOptions { - [Serializable] - public struct Interpreter { - /// - /// The serialized info required to restore an interpreter factory - /// - public string assembly; - public string typeName; - public Dictionary properties; - - /// - /// The x.y language version of the interpreter in case the factory - /// cannot be restored. - /// - public string version; - } - public Interpreter interpreter; - - /// - /// Paths to search when attempting to resolve module imports. - /// - public string[] searchPaths = Array.Empty(); - - /// - /// Secondary paths to search when resolving modules. Not supported by all - /// factories. In generaly, only source files will be discovered, and their - /// contents will be merged with the initial module. - /// - public string[] typeStubSearchPaths = Array.Empty(); - - /// - /// Indicates that analysis engine is running in a test environment. - /// Causes initialization and analysis sequences to fully - /// complete before information requests such as hover or - /// completion can be processed. - /// - public bool testEnvironment; - - /// - /// Controls tooltip display appearance. Different between VS and VS Code. - /// - public InformationDisplayOptions displayOptions = new InformationDisplayOptions(); - - /// - /// Glob pattern of files and folders to exclude from loading - /// into the Python analysis engine. - /// - public string[] excludeFiles = Array.Empty(); - - /// - /// Glob pattern of files and folders under the root folder that - /// should be loaded into the Python analysis engine. - /// - public string[] includeFiles = Array.Empty(); - - /// - /// Client expects analysis progress updates, including notifications - /// when analysis is complete for a particular document version. - /// - public bool analysisUpdates; - - /// - /// Enables an even higher level of logging via the logMessage event. - /// This will likely have a performance impact. - /// - public bool traceLogging; - - /// - /// If true, analyzer will be created asynchronously. Used in VS Code. - /// - public bool asyncStartup; - } - - [Serializable] - public class WorkspaceClientCapabilities { - public bool applyEdit; - - public struct WorkspaceEditCapabilities { public bool documentChanges; } - public WorkspaceEditCapabilities? documentChanges; - - public struct DidConfigurationChangeCapabilities { public bool dynamicRegistration; } - public DidConfigurationChangeCapabilities? didConfigurationChange; - - public struct DidChangeWatchedFilesCapabilities { public bool dynamicRegistration; } - public DidChangeWatchedFilesCapabilities? didChangeWatchedFiles; - - [Serializable] - public struct SymbolCapabilities { - public bool dynamicRegistration; - - [Serializable] - public struct SymbolKindCapabilities { - /// - /// The symbol kind values the client supports. When this - /// property exists the client also guarantees that it will - /// handle values outside its set gracefully and falls back - /// to a default value when unknown. - /// - /// If this property is not present the client only supports - /// the symbol kinds from `File` to `Array` as defined in - /// the initial version of the protocol. - /// - public SymbolKind[] valueSet; - } - public SymbolKindCapabilities? symbolKind; - } - - public SymbolCapabilities? symbol; - - public struct ExecuteCommandCapabilities { public bool dynamicRegistration; } - public ExecuteCommandCapabilities? executeCommand; - } - - [Serializable] - public class TextDocumentClientCapabilities { - [Serializable] - public struct SynchronizationCapabilities { - public bool dynamicRegistration; - public bool willSave; - /// - /// The client supports sending a will save request and - /// waits for a response providing text edits which will - /// be applied to the document before it is saved. - /// - public bool willSaveWaitUntil; - public bool didSave; - } - public SynchronizationCapabilities? synchronization; - - [Serializable] - public struct CompletionCapabilities { - public bool dynamicRegistration; - - [Serializable] - public struct CompletionItemCapabilities { - /// - /// Client supports snippets as insert text. - /// - /// A snippet can define tab stops and placeholders with `$1`, `$2` - /// and `${3:foo}`. `$0` defines the final tab stop, it defaults to - /// the end of the snippet. Placeholders with equal identifiers are linked, - /// that is typing in one will update others too. - /// - public bool snippetSupport; - - public bool commitCharactersSupport; - - public string[] documentationFormat; - } - public CompletionItemCapabilities? completionItem; - - [Serializable] - public struct CompletionItemKindCapabilities { - /// - /// The completion item kind values the client supports. When this - /// property exists the client also guarantees that it will - /// handle values outside its set gracefully and falls back - /// to a default value when unknown. - /// - /// If this property is not present the client only supports - /// the completion items kinds from `Text` to `Reference` as defined in - /// the initial version of the protocol. - /// - public SymbolKind[] valueSet; - } - public CompletionItemKindCapabilities? completionItemKind; - - /// - /// The client supports to send additional context information for a - /// `textDocument/completion` request. - /// - public bool contextSupport; - } - public CompletionCapabilities? completion; - - [Serializable] - public struct HoverCapabilities { - public bool dynamicRegistration; - /// - /// Client supports the follow content formats for the content - /// property.The order describes the preferred format of the client. - /// - public string[] contentFormat; - } - public HoverCapabilities? hover; - - [Serializable] - public struct SignatureHelpCapabilities { - public bool dynamicRegistration; - - public struct SignatureInformationCapabilities { - /// - /// Client supports the follow content formats for the documentation - /// property.The order describes the preferred format of the client. - /// - public string[] documentationFormat; - - /// - /// When true, the label in the returned signature information will - /// only contain the function name. Otherwise, the label will contain - /// the full signature. - /// - public bool? _shortLabel; - } - public SignatureInformationCapabilities? signatureInformation; - } - public SignatureHelpCapabilities? signatureHelp; - - [Serializable] - public struct ReferencesCapabilities { public bool dynamicRegistration; } - public ReferencesCapabilities? references; - - [Serializable] - public struct DocumentHighlightCapabilities { public bool dynamicRegistration; } - public DocumentHighlightCapabilities? documentHighlight; - - [Serializable] - public struct DocumentSymbolCapabilities { - public bool dynamicRegistration; - public struct SymbolKindCapabilities { - /// - /// The symbol kind values the client supports. When this - /// property exists the client also guarantees that it will - /// handle values outside its set gracefully and falls back - /// to a default value when unknown. - /// - /// If this property is not present the client only supports - /// the symbol kinds from `File` to `Array` as defined in - /// the initial version of the protocol. - /// - public SymbolKind[] valueSet; - } - public SymbolKindCapabilities? symbolKind; - - /// - /// The client support hierarchical document symbols. - /// - public bool? hierarchicalDocumentSymbolSupport; - } - public DocumentSymbolCapabilities? documentSymbol; - - [Serializable] - public struct FormattingCapabilities { public bool dynamicRegistration; } - public FormattingCapabilities? formatting; - - [Serializable] - public struct RangeFormattingCapabilities { public bool dynamicRegistration; } - public RangeFormattingCapabilities? rangeFormatting; - - [Serializable] - public struct OnTypeFormattingCapabilities { public bool dynamicRegistration; } - public OnTypeFormattingCapabilities? onTypeFormatting; - - public struct DefinitionCapabilities { public bool dynamicRegistration; } - public DefinitionCapabilities? definition; - - [Serializable] - public struct CodeActionCapabilities { public bool dynamicRegistration; } - public CodeActionCapabilities? codeAction; - - [Serializable] - public struct CodeLensCapabilities { public bool dynamicRegistration; } - public CodeLensCapabilities? codeLens; - - [Serializable] - public struct DocumentLinkCapabilities { public bool dynamicRegistration; } - public DocumentLinkCapabilities? documentLink; - - [Serializable] - public struct RenameCapabilities { public bool dynamicRegistration; } - public RenameCapabilities? rename; - } - - /// - /// This struct is for Python-specific extensions. It is included with - /// client capabilities following the specification for extra settings. - /// - [Serializable] - public class PythonClientCapabilities { - /// - /// Disables automatic analysis of all files under the root URI. - /// - public bool? manualFileLoad; - - /// - /// Enables rich diagnostics from code analysis. - /// - public bool? liveLinting; - } - - [Serializable] - public class ClientCapabilities { - public WorkspaceClientCapabilities workspace; - public TextDocumentClientCapabilities textDocument; - public object experimental; - public PythonClientCapabilities python; - } - - [Serializable] - public struct CompletionOptions { - /// - /// The server provides support to resolve additional - /// information for a completion item. - /// - public bool resolveProvider; - /// - /// The characters that trigger completion automatically. - /// - public string[] triggerCharacters; - } - - [Serializable] - public struct SignatureHelpOptions { - /// - /// The characters that trigger signature help - /// automatically. - /// - public string[] triggerCharacters; - } - - [Serializable] - public struct CodeLensOptions { - public bool resolveProvider; - } - - [Serializable] - public struct DocumentOnTypeFormattingOptions { - public string firstTriggerCharacter; - public string[] moreTriggerCharacter; - } - - [Serializable] - public struct DocumentLinkOptions { - public bool resolveProvider; - } - - [Serializable] - public struct ExecuteCommandOptions { - public string[] commands; - } - - [Serializable] - public class SaveOptions { - public bool includeText; - } - - [Serializable] - public class TextDocumentSyncOptions { - /// - /// Open and close notifications are sent to the server. - /// - public bool openClose; - public TextDocumentSyncKind change; - public bool willSave; - public bool willSaveWaitUntil; - public SaveOptions save; - } - - [Serializable] - public struct ServerCapabilities { - public TextDocumentSyncOptions textDocumentSync; - public bool hoverProvider; - public CompletionOptions? completionProvider; - public SignatureHelpOptions? signatureHelpProvider; - public bool definitionProvider; - public bool referencesProvider; - public bool documentHighlightProvider; - public bool documentSymbolProvider; - public bool workspaceSymbolProvider; - public bool codeActionProvider; - public CodeLensOptions? codeLensProvider; - public bool documentFormattingProvider; - public bool documentRangeFormattingProvider; - public DocumentOnTypeFormattingOptions? documentOnTypeFormattingProvider; - public bool renameProvider; - public DocumentLinkOptions? documentLinkProvider; - public ExecuteCommandOptions? executeCommandProvider; - public object experimental; - } - - [Serializable] - public struct MessageActionItem { - public string title; - } - - [Serializable] - public struct Registration { - public string id; - public string method; - public IRegistrationOptions registerOptions; - } - - public interface IRegistrationOptions { } - - [Serializable] - public struct TextDocumentRegistrationOptions : IRegistrationOptions { - public DocumentFilter? documentSelector; - } - - [Serializable] - public struct Unregistration { - public string id; - public string method; - } - - [Serializable] - public struct FileEvent { - public Uri uri; - public FileChangeType type; - } - - [Serializable] - public struct DidChangeWatchedFilesRegistrationOptions : IRegistrationOptions { - public FileSystemWatcher[] watchers; - } - - [Serializable] - public struct FileSystemWatcher { - public string globPattern; - public WatchKind? type; - } - - [Serializable] - public struct ExecuteCommandRegistrationOptions : IRegistrationOptions { - public string[] commands; - } - - [Serializable] - public struct TextDocumentContentChangedEvent { - public Range? range; - public int? rangeLength; - public string text; - } - - public struct TextDocumentChangeRegistrationOptions : IRegistrationOptions { - public DocumentFilter? documentSelector; - public TextDocumentSyncKind syncKind; - } - - [Serializable] - public struct TextDocumentSaveRegistrationOptions : IRegistrationOptions { - public DocumentFilter? documentSelector; - public bool includeText; - } - - [Serializable] - public class CompletionList { - /// - /// This list is not complete. Further typing should result in recomputing - /// this list. - /// - public bool isIncomplete; - public CompletionItem[] items; - - /// - /// The range that should be replaced when committing a completion from this - /// list. Where textEdit is set on a completion, prefer that. - /// - public Range? _applicableSpan; - /// - /// When true, snippets are allowed in this context. - /// - public bool? _allowSnippet; - /// - /// The expression that members are being displayed for. - /// - public string _expr; - /// - /// When true, completions should commit by default. When false, completions - /// should not commit. If unspecified the client may decide. - /// - public bool? _commitByDefault; - } - - [Serializable] - public class CompletionItem { - public string label; - public CompletionItemKind kind; - public string detail; - public MarkupContent documentation; - public string sortText; - public string filterText; - public bool? preselect; // VS Code 1.25+ - public string insertText; - public InsertTextFormat insertTextFormat; - public TextEdit? textEdit; - public TextEdit[] additionalTextEdits; - public string[] commitCharacters; - public Command? command; - public object data; - - public string _kind; - public CompletionItemValue[] _values; - } - - // Not in LSP spec - [Serializable] - public struct CompletionItemValue { - public string description; - public string documentation; - public Reference[] references; - } - - [Serializable] - public struct CompletionRegistrationOptions : IRegistrationOptions { - public DocumentFilter? documentSelector; - public string[] triggerCharacters; - public bool resolveProvider; - } - - [Serializable] - public class Hover { - public MarkupContent contents; - public Range? range; - - /// - /// The document version that range applies to. - /// - public int? _version; - /// - /// List of fully qualified type names for the expression - /// - public string[] _typeNames; - } - - [Serializable] - public class SignatureHelp { - public SignatureInformation[] signatures; - public int activeSignature; - public int activeParameter; - } - - [Serializable] - public class SignatureInformation { - public string label; - public MarkupContent documentation; - public ParameterInformation[] parameters; - - public string[] _returnTypes; - } - - [Serializable] - public class ParameterInformation { - public string label; - public MarkupContent documentation; - - [NonSerialized] - public string _type; - [NonSerialized] - public string _defaultValue; - [NonSerialized] - public bool? _isOptional; - } - - /// - /// Used instead of Position when returning references so we can include - /// the kind. - /// - [Serializable] - public class Reference { - public Uri uri; - public Range range; - - /// - /// The kind of reference - /// - public ReferenceKind? _kind; - /// - /// The document version that range applies to - /// - public int? _version; - - /// - /// Indicates that reference is a module name - /// - public bool _isModule; - } - - [Serializable] - public struct DocumentHighlight { - public Range range; - public DocumentHighlightKind kind; - - /// - /// The document version that range applies to - /// - public int? _version; - } - - [Serializable] - public class DocumentSymbol { - /// - /// The name of this symbol. - /// - public string name; - - /// - /// More detail for this symbol, e.g the signature of a function. If not provided the - /// name is used. - /// - public string detail; - - /// - /// The kind of this symbol. - /// - public SymbolKind kind; - - /// - /// Indicates if this symbol is deprecated. - /// - public bool deprecated; - - /// - /// The range enclosing this symbol not including leading/trailing whitespace but everything else - /// like comments.This information is typically used to determine if the clients cursor is - /// inside the symbol to reveal in the symbol in the UI. - /// - public Range range; - - /// - /// The range that should be selected and revealed when this symbol is being picked, - /// e.g the name of a function. Must be contained by the `range`. - /// - public Range selectionRange; - - /// - /// Children of this symbol, e.g. properties of a class. - /// - public DocumentSymbol[] children; - - /// - /// Custom field provides more information on the function or method such as - /// 'classmethod' or 'property' that are not part of the . - /// - public string _functionKind; - } - - [Serializable] - public class SymbolInformation { - public string name; - public SymbolKind kind; - public Location location; - /// - /// The name of the symbol containing this symbol. This information is for - /// user interface purposes (e.g.to render a qualifier in the user interface - /// if necessary). It can't be used to re-infer a hierarchy for the document - /// symbols. - /// - public string containerName; - - /// - /// The document version that location applies to - /// - public int? _version; - public string _kind; - } - - [Serializable] - public class CodeLens { - public Range range; - public Command? command; - public object data; - - /// - /// The document version that range applies to - /// - public int? _version; - } - - [Serializable] - public class DocumentLink { - public Range range; - public Uri target; - - /// - /// The document version tha range applies to - /// - public int? _version; - } - - [Serializable] - public class DocumentLinkRegistrationOptions : IRegistrationOptions { - public DocumentFilter? documentSelector; - public bool resolveProvider; - } - - [Serializable] - public class FormattingOptions { - public int tabSize; - public bool insertSpaces; - - } - - [Serializable] - public class DocumentOnTypeFormattingRegistrationOptions : IRegistrationOptions { - public DocumentFilter? documentSelector; - public string firstTriggerCharacter; - public string[] moreTriggerCharacters; - } - internal static class MarkupKind { - public const string PlainText = "plaintext"; - public const string Markdown = "markdown"; - } -} diff --git a/src/Analysis/Engine/Impl/LocationInfo.cs b/src/Analysis/Engine/Impl/LocationInfo.cs index c34854ea6..e0efbfeb3 100644 --- a/src/Analysis/Engine/Impl/LocationInfo.cs +++ b/src/Analysis/Engine/Impl/LocationInfo.cs @@ -9,13 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; +using Microsoft.Python.Core.Text; namespace Microsoft.PythonTools.Analysis { internal class LocationInfo : ILocationInfo, IEquatable { diff --git a/src/Analysis/Engine/Impl/LockedEnumerable.cs b/src/Analysis/Engine/Impl/LockedEnumerable.cs index ae81be72f..9ed0ace51 100644 --- a/src/Analysis/Engine/Impl/LockedEnumerable.cs +++ b/src/Analysis/Engine/Impl/LockedEnumerable.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/MemberResult.cs b/src/Analysis/Engine/Impl/MemberResult.cs index e8cfe0f8f..6478b12c6 100644 --- a/src/Analysis/Engine/Impl/MemberResult.cs +++ b/src/Analysis/Engine/Impl/MemberResult.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,8 +18,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Documentation; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; diff --git a/src/Analysis/Engine/Impl/Microsoft.Python.Analysis.Engine.csproj b/src/Analysis/Engine/Impl/Microsoft.Python.Analysis.Engine.csproj index 23c2f03e5..347b68de9 100644 --- a/src/Analysis/Engine/Impl/Microsoft.Python.Analysis.Engine.csproj +++ b/src/Analysis/Engine/Impl/Microsoft.Python.Analysis.Engine.csproj @@ -35,16 +35,12 @@ - - True - True - Resources.resx - + + ResXFileCodeGenerator - Resources.Designer.cs diff --git a/src/Analysis/Engine/Impl/ModuleAnalysis.cs b/src/Analysis/Engine/Impl/ModuleAnalysis.cs index 3c328585c..b94cfb369 100644 --- a/src/Analysis/Engine/Impl/ModuleAnalysis.cs +++ b/src/Analysis/Engine/Impl/ModuleAnalysis.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,12 +21,13 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { /// @@ -358,7 +359,7 @@ private bool IsFunctionArgument(IScope scope, IAnalysisVariable v) { } if (scope is FunctionScope funcScope) { var funcDef = funcScope.Function.FunctionDefinition; - var varSpan = v.Location.Span.ToLinearSpan(_unit.Tree); + var varSpan = v.Location.Span.ToIndexSpan(_unit.Tree); return funcDef.NameExpression.EndIndex <= varSpan.Start && varSpan.End <= funcDef.HeaderIndex; } return false; @@ -1083,8 +1084,7 @@ private InterpreterScope FindScope(SourceLocation location) { } private static bool IsInFunctionParameter(InterpreterScope scope, PythonAst tree, SourceLocation location) { - var function = scope.Node as FunctionDefinition; - if (function == null) { + if (!(scope.Node is FunctionDefinition function)) { // Not a function return false; } @@ -1282,7 +1282,7 @@ private int LineToIndex(int line) { // line is 1 based, and index 0 in the array is the position of the 2nd line in the file. line -= 2; - return _unit.Tree._lineLocations[line].EndIndex; + return _unit.Tree.NewLineLocations[line].EndIndex; } /// diff --git a/src/Analysis/Engine/Impl/ModuleReference.cs b/src/Analysis/Engine/Impl/ModuleReference.cs index 04b39babe..c97897a58 100644 --- a/src/Analysis/Engine/Impl/ModuleReference.cs +++ b/src/Analysis/Engine/Impl/ModuleReference.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/ModuleResolver.cs b/src/Analysis/Engine/Impl/ModuleResolver.cs index 192de06f1..9fbc4333a 100644 --- a/src/Analysis/Engine/Impl/ModuleResolver.cs +++ b/src/Analysis/Engine/Impl/ModuleResolver.cs @@ -16,8 +16,8 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Analysis { internal class ModuleResolver { diff --git a/src/Analysis/Engine/Impl/ModuleTable.cs b/src/Analysis/Engine/Impl/ModuleTable.cs index dcc106928..73bd48482 100644 --- a/src/Analysis/Engine/Impl/ModuleTable.cs +++ b/src/Analysis/Engine/Impl/ModuleTable.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,11 +17,8 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; diff --git a/src/Analysis/Engine/Impl/OverloadResult.cs b/src/Analysis/Engine/Impl/OverloadResult.cs index b7f9f2a1e..c3f07ab5c 100644 --- a/src/Analysis/Engine/Impl/OverloadResult.cs +++ b/src/Analysis/Engine/Impl/OverloadResult.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; namespace Microsoft.PythonTools.Analysis { diff --git a/src/Analysis/Engine/Impl/ParameterResult.cs b/src/Analysis/Engine/Impl/ParameterResult.cs index 6dd03f3d8..76eb7a339 100644 --- a/src/Analysis/Engine/Impl/ParameterResult.cs +++ b/src/Analysis/Engine/Impl/ParameterResult.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/Comprehension.cs b/src/Analysis/Engine/Impl/Parsing/Ast/Comprehension.cs deleted file mode 100644 index fbbce5f5a..000000000 --- a/src/Analysis/Engine/Impl/Parsing/Ast/Comprehension.cs +++ /dev/null @@ -1,180 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.PythonTools.Parsing.Ast { - public abstract class ComprehensionIterator : Node { - } - - public abstract class Comprehension : Expression { - public abstract IList Iterators { get; } - public abstract override string NodeName { get; } - - public abstract override void Walk(PythonWalker walker); - - internal void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Expression item) { - if (!String.IsNullOrEmpty(start)) { - format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); - res.Append(start); - } - - item.AppendCodeString(res, ast, format); - - for (int i = 0; i < Iterators.Count; i++) { - Iterators[i].AppendCodeString(res, ast, format); - } - - if (!String.IsNullOrEmpty(end)) { - res.Append(this.GetSecondWhiteSpace(ast)); - res.Append(end); - } - } - } - - public sealed class ListComprehension : Comprehension { - private readonly ComprehensionIterator[] _iterators; - private readonly Expression _item; - - public ListComprehension(Expression item, ComprehensionIterator[] iterators) { - _item = item; - _iterators = iterators; - } - - public Expression Item { - get { return _item; } - } - - public override IList Iterators { - get { return _iterators; } - } - - public override string NodeName { - get { - return "list comprehension"; - } - } - - public override void Walk(PythonWalker walker) { - if (walker.Walk(this)) { - if (_item != null) { - _item.Walk(walker); - } - if (_iterators != null) { - foreach (ComprehensionIterator ci in _iterators) { - ci.Walk(walker); - } - } - } - walker.PostWalk(this); - } - - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - AppendCodeString(res, ast, format, "[", this.IsMissingCloseGrouping(ast) ? "" : "]", _item); - } - } - - public sealed class SetComprehension : Comprehension { - private readonly ComprehensionIterator[] _iterators; - private readonly Expression _item; - - public SetComprehension(Expression item, ComprehensionIterator[] iterators) { - _item = item; - _iterators = iterators; - } - - public Expression Item { - get { return _item; } - } - - public override IList Iterators { - get { return _iterators; } - } - - public override string NodeName { - get { - return "set comprehension"; - } - } - - public override void Walk(PythonWalker walker) { - if (walker.Walk(this)) { - if (_item != null) { - _item.Walk(walker); - } - if (_iterators != null) { - foreach (ComprehensionIterator ci in _iterators) { - ci.Walk(walker); - } - } - } - walker.PostWalk(this); - } - - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - AppendCodeString(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", _item); - } - } - - public sealed class DictionaryComprehension : Comprehension { - private readonly ComprehensionIterator[] _iterators; - private readonly SliceExpression _value; - - public DictionaryComprehension(SliceExpression value, ComprehensionIterator[] iterators) { - _value = value; - _iterators = iterators; - } - - public Expression Key { - get { return _value.SliceStart; } - } - - public Expression Value { - get { return _value.SliceStop; } - } - - public override IList Iterators { - get { return _iterators; } - } - - public override string NodeName { - get { - return "dict comprehension"; - } - } - - public override void Walk(PythonWalker walker) { - if (walker.Walk(this)) { - if (_value != null) { - _value.Walk(walker); - } - - if (_iterators != null) { - foreach (ComprehensionIterator ci in _iterators) { - ci.Walk(walker); - } - } - } - walker.PostWalk(this); - } - - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - AppendCodeString(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", _value); - } - } -} diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/GeneratorExpression.cs b/src/Analysis/Engine/Impl/Parsing/Ast/GeneratorExpression.cs deleted file mode 100644 index 60b6b0279..000000000 --- a/src/Analysis/Engine/Impl/Parsing/Ast/GeneratorExpression.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System.Collections.Generic; -using System.Text; - -namespace Microsoft.PythonTools.Parsing.Ast { - public sealed class GeneratorExpression : Comprehension { - private readonly ComprehensionIterator[] _iterators; - private readonly Expression _item; - - public GeneratorExpression(Expression item, ComprehensionIterator[] iterators) { - _item = item; - _iterators = iterators; - } - - public override IList Iterators { - get { return _iterators; } - } - - public override string NodeName { get { return "generator"; } } - - public Expression Item { - get { - return _item; - } - } - - internal override string CheckAssign() { - return "can't assign to generator expression"; - } - - internal override string CheckAugmentedAssign() { - return CheckAssign(); - } - - internal override string CheckDelete() { - return "can't delete generator expression"; - } - - public override void Walk(PythonWalker walker) { - if (walker.Walk(this)) { - if (_item != null) { - _item.Walk(walker); - } - - if (_iterators != null) { - foreach (ComprehensionIterator ci in _iterators) { - ci.Walk(walker); - } - } - } - walker.PostWalk(this); - } - - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - if (this.IsAltForm(ast)) { - this.AppendCodeString(res, ast, format, "", "", _item); - } else { - this.AppendCodeString(res, ast, format, "(", this.IsMissingCloseGrouping(ast) ? "" : ")", _item); - } - } - } -} diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PythonVariable.cs b/src/Analysis/Engine/Impl/Parsing/Ast/PythonVariable.cs deleted file mode 100644 index d6e36b91b..000000000 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PythonVariable.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -namespace Microsoft.PythonTools.Parsing.Ast { - public class PythonVariable { - private readonly string _name; - private readonly ScopeStatement/*!*/ _scope; - private VariableKind _kind; // the type of variable, - - // variables used during the named binding to report errors - private bool _deleted; // del x, the variable gets deleted at some point - private bool _accessedInNestedScope; // the variable is accessed in a nested scope and therefore needs to be a closure var - - internal PythonVariable(string name, VariableKind kind, ScopeStatement/*!*/ scope) { - _name = name; - _kind = kind; - _scope = scope; - } - - /// - /// The name of the variable. - /// - public string Name { - get { return _name; } - } - - /// - /// The scope the variable was declared in. - /// - public ScopeStatement Scope { - get { return _scope; } - } - - /// - /// True if the variable is a global variable (either referenced from an inner scope, or referenced from the global scope); - /// - internal bool IsGlobal { - get { - return Kind == VariableKind.Global || Scope.IsGlobal; - } - } - - internal VariableKind Kind { - get { return _kind; } - set { _kind = value; } - } - - internal bool Deleted { - get { return _deleted; } - set { _deleted = value; } - } - - /// - /// True iff the variable is referred to from the inner scope. - /// - internal bool AccessedInNestedScope { - get { return _accessedInNestedScope; } - set { _accessedInNestedScope = value; } - } - } -} diff --git a/src/Analysis/Engine/Impl/Parsing/Token.cs b/src/Analysis/Engine/Impl/Parsing/Token.cs deleted file mode 100644 index f741fd436..000000000 --- a/src/Analysis/Engine/Impl/Parsing/Token.cs +++ /dev/null @@ -1,313 +0,0 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the License); you may not use -// this file except in compliance with the License. You may obtain a copy of the -// License at http://www.apache.org/licenses/LICENSE-2.0 -// -// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS -// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY -// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. -// -// See the Apache Version 2.0 License for specific language governing -// permissions and limitations under the License. - -using System; - -namespace Microsoft.PythonTools.Parsing { - internal struct TokenWithSpan { - public static readonly TokenWithSpan Empty = new TokenWithSpan(); - - private readonly Token _token; - private readonly IndexSpan _span; - - public TokenWithSpan(Token token, IndexSpan span) { - _token = token; - _span = span; - } - - public IndexSpan Span { - get { return _span; } - } - - public Token Token { - get { return _token; } - } - - } - - /// - /// Summary description for Token. - /// - public abstract class Token { - private readonly TokenKind _kind; - - internal Token(TokenKind kind) { - _kind = kind; - } - - public TokenKind Kind { - get { return _kind; } - } - - public virtual object Value { - get { - throw new NotSupportedException("no value for this token"); - } - } - - public override string ToString() { - return base.ToString() + "(" + _kind + ")"; - } - - /// - /// Returns the exact text of the token if it's available. The text does not - /// include any leading white space. - /// - public virtual String VerbatimImage { - get { - return Image; - } - } - - /// - /// Returns a user friendly display of the token. - /// - public abstract String Image { - get; - } - } - - internal class ErrorToken : Token { - private readonly String _message; - private readonly string _verbatim; - - public ErrorToken(String message, string verbatim) - : base(TokenKind.Error) { - _message = message; - _verbatim = verbatim; - } - - public String Message { - get { return _message; } - } - - public override String Image { - get { return _message; } - } - - public override object Value { - get { return _message; } - } - - public override string VerbatimImage { - get { - return _verbatim; - } - } - } - - internal class IncompleteStringErrorToken : ErrorToken { - private readonly string _value; - - public IncompleteStringErrorToken(string message, string value) - : base(message, value) { - _value = value; - } - - public override string Image { - get { - return _value; - } - } - - public override object Value { - get { - return _value; - } - } - } - - internal class ConstantValueToken : Token { - private readonly object _value; - - public ConstantValueToken(object value) - : base(TokenKind.Constant) { - _value = value; - } - - public object Constant { - get { return this._value; } - } - - public override object Value { - get { return _value; } - } - - public override String Image { - get { - return _value == null ? "None" : _value.ToString(); - } - } - } - - internal sealed class VerbatimConstantValueToken : ConstantValueToken { - private readonly string _verbatim; - - public VerbatimConstantValueToken(object value, string verbatim) - : base(value) { - _verbatim = verbatim; - } - - public override string VerbatimImage { - get { - return _verbatim; - } - } - } - - class UnicodeStringToken : ConstantValueToken { - public UnicodeStringToken(object value) - : base(value) { - } - } - - sealed class VerbatimUnicodeStringToken : UnicodeStringToken { - private readonly string _verbatim; - - public VerbatimUnicodeStringToken(object value, string verbatim) - : base(value) { - _verbatim = verbatim; - } - - public override string VerbatimImage { - get { - return _verbatim; - } - } - } - - internal sealed class CommentToken : Token { - private readonly string _comment; - - public CommentToken(string comment) - : base(TokenKind.Comment) { - _comment = comment; - } - - public string Comment { - get { return _comment; } - } - - public override string Image { - get { return _comment; } - } - - public override object Value { - get { return _comment; } - } - } - - internal class NameToken : Token { - private readonly string _name; - - public NameToken(string name) - : base(TokenKind.Name) { - _name = name; - } - - public string Name { - get { return this._name; } - } - - public override object Value { - get { return _name; } - } - - public override String Image { - get { - return _name; - } - } - } - - internal sealed class OperatorToken : Token { - private readonly int _precedence; - private readonly string _image; - - public OperatorToken(TokenKind kind, string image, int precedence) - : base(kind) { - _image = image; - _precedence = precedence; - } - - public int Precedence { - get { return _precedence; } - } - - public override object Value { - get { return _image; } - } - - public override String Image { - get { return _image; } - } - } - - internal class SymbolToken : Token { - private readonly string _image; - - public SymbolToken(TokenKind kind, String image) - : base(kind) { - _image = image; - } - - public String Symbol { - get { return _image; } - } - - public override object Value { - get { return _image; } - } - - public override String Image { - get { return _image; } - } - } - - internal sealed class StatementSymbolToken : SymbolToken { - public StatementSymbolToken(TokenKind kind, String image) - : base(kind, image) { - } - } - - internal class VerbatimToken : SymbolToken { - private readonly string _verbatimImage; - - public VerbatimToken(TokenKind kind, string verbatimImage, string image) - : base(kind, image) { - _verbatimImage = verbatimImage; - } - - public override string VerbatimImage { - get { - return _verbatimImage; - } - } - } - - internal class DentToken : SymbolToken { - public DentToken(TokenKind kind, String image) - : base(kind, image) { - } - - public override string VerbatimImage { - get { - // indents are accounted for in whitespace - return ""; - } - } - } -} diff --git a/src/Analysis/Engine/Impl/ProjectEntry.cs b/src/Analysis/Engine/Impl/ProjectEntry.cs index 755726ed5..c2a756e13 100644 --- a/src/Analysis/Engine/Impl/ProjectEntry.cs +++ b/src/Analysis/Engine/Impl/ProjectEntry.cs @@ -24,12 +24,14 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/ProjectEntryExtensions.cs b/src/Analysis/Engine/Impl/ProjectEntryExtensions.cs index fd0d29bfe..18541155e 100644 --- a/src/Analysis/Engine/Impl/ProjectEntryExtensions.cs +++ b/src/Analysis/Engine/Impl/ProjectEntryExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Projects/AnalysisCompleteEventArgs.cs b/src/Analysis/Engine/Impl/Projects/AnalysisCompleteEventArgs.cs index a93c6343f..db8d51427 100644 --- a/src/Analysis/Engine/Impl/Projects/AnalysisCompleteEventArgs.cs +++ b/src/Analysis/Engine/Impl/Projects/AnalysisCompleteEventArgs.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Projects/AnalysisExtensionNameAttribute.cs b/src/Analysis/Engine/Impl/Projects/AnalysisExtensionNameAttribute.cs index 4a7cf6102..0d95cf72a 100644 --- a/src/Analysis/Engine/Impl/Projects/AnalysisExtensionNameAttribute.cs +++ b/src/Analysis/Engine/Impl/Projects/AnalysisExtensionNameAttribute.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Projects/IAnalysisExtension.cs b/src/Analysis/Engine/Impl/Projects/IAnalysisExtension.cs index 741092599..7ff0f1c6e 100644 --- a/src/Analysis/Engine/Impl/Projects/IAnalysisExtension.cs +++ b/src/Analysis/Engine/Impl/Projects/IAnalysisExtension.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Projects/IPythonProjectProvider.cs b/src/Analysis/Engine/Impl/Projects/IPythonProjectProvider.cs index 0a3145b17..dccb2ee55 100644 --- a/src/Analysis/Engine/Impl/Projects/IPythonProjectProvider.cs +++ b/src/Analysis/Engine/Impl/Projects/IPythonProjectProvider.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Projects/ProjectAnalyzer.cs b/src/Analysis/Engine/Impl/Projects/ProjectAnalyzer.cs index 126bfa37c..518d21627 100644 --- a/src/Analysis/Engine/Impl/Projects/ProjectAnalyzer.cs +++ b/src/Analysis/Engine/Impl/Projects/ProjectAnalyzer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Projects/PythonProject.cs b/src/Analysis/Engine/Impl/Projects/PythonProject.cs index 519ddf769..4830fb52b 100644 --- a/src/Analysis/Engine/Impl/Projects/PythonProject.cs +++ b/src/Analysis/Engine/Impl/Projects/PythonProject.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/PythonAnalyzer.Specializations.cs b/src/Analysis/Engine/Impl/PythonAnalyzer.Specializations.cs index 2f59b0b6d..51933c3a7 100644 --- a/src/Analysis/Engine/Impl/PythonAnalyzer.Specializations.cs +++ b/src/Analysis/Engine/Impl/PythonAnalyzer.Specializations.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,15 +17,13 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; -using System.Threading; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.Analysis { public delegate IAnalysisSet CallDelegate(Node node, AnalysisUnit unit, IAnalysisSet[] args, NameExpression[] keywordArgNames); diff --git a/src/Analysis/Engine/Impl/PythonAnalyzer.cs b/src/Analysis/Engine/Impl/PythonAnalyzer.cs index c8b90d753..73b77d835 100644 --- a/src/Analysis/Engine/Impl/PythonAnalyzer.cs +++ b/src/Analysis/Engine/Impl/PythonAnalyzer.cs @@ -24,13 +24,14 @@ using System.Numerics; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.DependencyResolution; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/PythonKeywords.cs b/src/Analysis/Engine/Impl/PythonKeywords.cs index 737200a12..1472074e4 100644 --- a/src/Analysis/Engine/Impl/PythonKeywords.cs +++ b/src/Analysis/Engine/Impl/PythonKeywords.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Analysis { /// diff --git a/src/Analysis/Engine/Impl/QualifiedNameExtensions.cs b/src/Analysis/Engine/Impl/QualifiedNameExtensions.cs index 1f2ea7c3a..1a50e4205 100644 --- a/src/Analysis/Engine/Impl/QualifiedNameExtensions.cs +++ b/src/Analysis/Engine/Impl/QualifiedNameExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/ResolutionContext.cs b/src/Analysis/Engine/Impl/ResolutionContext.cs index 323a090b8..e4000f4d8 100644 --- a/src/Analysis/Engine/Impl/ResolutionContext.cs +++ b/src/Analysis/Engine/Impl/ResolutionContext.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Diagnostics; using Microsoft.PythonTools.Analysis.Values; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { sealed class ResolutionContext { diff --git a/src/Analysis/Engine/Impl/RichDescriptionExtensions.cs b/src/Analysis/Engine/Impl/RichDescriptionExtensions.cs index fe54d3217..9ff025062 100644 --- a/src/Analysis/Engine/Impl/RichDescriptionExtensions.cs +++ b/src/Analysis/Engine/Impl/RichDescriptionExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/SetOfOne.cs b/src/Analysis/Engine/Impl/SetOfOne.cs index 3a58fd86e..416edff1c 100644 --- a/src/Analysis/Engine/Impl/SetOfOne.cs +++ b/src/Analysis/Engine/Impl/SetOfOne.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/SetOfOneEnumerator.cs b/src/Analysis/Engine/Impl/SetOfOneEnumerator.cs index c77d1bfb1..6205a6cb3 100644 --- a/src/Analysis/Engine/Impl/SetOfOneEnumerator.cs +++ b/src/Analysis/Engine/Impl/SetOfOneEnumerator.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/SetOfTwo.cs b/src/Analysis/Engine/Impl/SetOfTwo.cs index 205040a2d..5b21c43ea 100644 --- a/src/Analysis/Engine/Impl/SetOfTwo.cs +++ b/src/Analysis/Engine/Impl/SetOfTwo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/SingleDict.cs b/src/Analysis/Engine/Impl/SingleDict.cs index 7aa6cc91f..183c48fb6 100644 --- a/src/Analysis/Engine/Impl/SingleDict.cs +++ b/src/Analysis/Engine/Impl/SingleDict.cs @@ -9,12 +9,11 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/Analysis/Engine/Impl/SmallSetWithExpiry.cs b/src/Analysis/Engine/Impl/SmallSetWithExpiry.cs index 48d1092b8..743f9df83 100644 --- a/src/Analysis/Engine/Impl/SmallSetWithExpiry.cs +++ b/src/Analysis/Engine/Impl/SmallSetWithExpiry.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Validation.cs b/src/Analysis/Engine/Impl/Validation.cs index d91ce05c1..c6b82aa36 100644 --- a/src/Analysis/Engine/Impl/Validation.cs +++ b/src/Analysis/Engine/Impl/Validation.cs @@ -9,14 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Diagnostics; -using Microsoft.PythonTools.Analysis.Infrastructure; namespace Microsoft.PythonTools.Analysis { #if FULL_VALIDATION || DEBUG diff --git a/src/Analysis/Engine/Impl/Values/ArgumentSet.cs b/src/Analysis/Engine/Impl/Values/ArgumentSet.cs index 7f57cf083..bae5e7b71 100644 --- a/src/Analysis/Engine/Impl/Values/ArgumentSet.cs +++ b/src/Analysis/Engine/Impl/Values/ArgumentSet.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,9 +17,8 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { struct ArgumentSet { diff --git a/src/Analysis/Engine/Impl/Values/BoundBuiltinMethodInfo.cs b/src/Analysis/Engine/Impl/Values/BoundBuiltinMethodInfo.cs index 97b79969a..13d0d5f2e 100644 --- a/src/Analysis/Engine/Impl/Values/BoundBuiltinMethodInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BoundBuiltinMethodInfo.cs @@ -16,7 +16,7 @@ using System.Collections.Generic; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class BoundBuiltinMethodInfo : BuiltinNamespace { diff --git a/src/Analysis/Engine/Impl/Values/BoundMethodInfo.cs b/src/Analysis/Engine/Impl/Values/BoundMethodInfo.cs index 67e53eb56..1ee88e849 100644 --- a/src/Analysis/Engine/Impl/Values/BoundMethodInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BoundMethodInfo.cs @@ -16,9 +16,9 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BoundMethodInfo : AnalysisValue, IBoundMethodInfo, IHasRichDescription, IHasQualifiedName { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/BuiltinClassInfo.cs index 43e850013..5bbf7f81a 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinClassInfo.cs @@ -20,7 +20,7 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinClassInfo : BuiltinNamespace, IBuiltinClassInfo { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinEventInfo.cs b/src/Analysis/Engine/Impl/Values/BuiltinEventInfo.cs index f4ecca3c2..5eca89bb4 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinEventInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinEventInfo.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinEventInfo : BuiltinNamespace { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinFunctionInfo.cs b/src/Analysis/Engine/Impl/Values/BuiltinFunctionInfo.cs index cf9c1743f..fd143c3b4 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinFunctionInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinFunctionInfo.cs @@ -9,16 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinFunctionInfo : BuiltinNamespace, IHasRichDescription, IHasQualifiedName { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/BuiltinInstanceInfo.cs index d9c1b8df2..4da4a56d0 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinInstanceInfo.cs @@ -18,8 +18,8 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinInstanceInfo : BuiltinNamespace, IBuiltinInstanceInfo { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinMethodInfo.cs b/src/Analysis/Engine/Impl/Values/BuiltinMethodInfo.cs index 835c7bebf..370461f3a 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinMethodInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinMethodInfo.cs @@ -18,7 +18,7 @@ using System.Linq; using System.Text; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinMethodInfo : BuiltinNamespace, IHasRichDescription { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinModule.cs b/src/Analysis/Engine/Impl/Values/BuiltinModule.cs index 6560ffff6..c25eb489a 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinModule.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinModule.cs @@ -9,19 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinModule : BuiltinNamespace, IReferenceableContainer, IModule { diff --git a/src/Analysis/Engine/Impl/Values/BuiltinNamespace.cs b/src/Analysis/Engine/Impl/Values/BuiltinNamespace.cs index 6d3101ca9..d92628462 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinNamespace.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinNamespace.cs @@ -16,9 +16,9 @@ using System; using System.Collections.Generic; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/BuiltinPropertyInfo.cs b/src/Analysis/Engine/Impl/Values/BuiltinPropertyInfo.cs index fcfea0d8e..7b0f8bcad 100644 --- a/src/Analysis/Engine/Impl/Values/BuiltinPropertyInfo.cs +++ b/src/Analysis/Engine/Impl/Values/BuiltinPropertyInfo.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class BuiltinPropertyInfo : BuiltinNamespace { diff --git a/src/Analysis/Engine/Impl/Values/CallChain.cs b/src/Analysis/Engine/Impl/Values/CallChain.cs index 0605b173b..6482039f7 100644 --- a/src/Analysis/Engine/Impl/Values/CallChain.cs +++ b/src/Analysis/Engine/Impl/Values/CallChain.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,9 +17,9 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal struct CallChain : IEnumerable, IEquatable { diff --git a/src/Analysis/Engine/Impl/Values/ClassInfo.cs b/src/Analysis/Engine/Impl/Values/ClassInfo.cs index ef6e14ec1..07c53165d 100644 --- a/src/Analysis/Engine/Impl/Values/ClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ClassInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,10 +19,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class ClassInfo : AnalysisValue, IClassInfo, IHasRichDescription, IHasQualifiedName { diff --git a/src/Analysis/Engine/Impl/Values/ConstantInfo.cs b/src/Analysis/Engine/Impl/Values/ConstantInfo.cs index 73afb3214..e5ebb4459 100644 --- a/src/Analysis/Engine/Impl/Values/ConstantInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ConstantInfo.cs @@ -15,10 +15,10 @@ // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class ConstantInfo : BuiltinInstanceInfo { diff --git a/src/Analysis/Engine/Impl/Values/CoroutineInfo.cs b/src/Analysis/Engine/Impl/Values/CoroutineInfo.cs index dc9491765..cb33a0b36 100644 --- a/src/Analysis/Engine/Impl/Values/CoroutineInfo.cs +++ b/src/Analysis/Engine/Impl/Values/CoroutineInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisIterableValue.cs b/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisIterableValue.cs index 4fc2aa859..1b56d6a12 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisIterableValue.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisIterableValue.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValue.cs b/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValue.cs index 9a3c9d603..87af97696 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValue.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValue.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { public interface IAnalysisValue : IAnalysisSet, ICanExpire { diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValueOperations.cs b/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValueOperations.cs index 839865718..b2d3a5485 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValueOperations.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IAnalysisValueOperations.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { public interface IAnalysisValueOperations: IAnalysisValue { diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IBoundMethodInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IBoundMethodInfo.cs index 47800ae81..109636cef 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IBoundMethodInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IBoundMethodInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinClassInfo.cs index 33b9bb32d..0cde4e11e 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinClassInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinInstanceInfo.cs index 1fddb3074..263ec5ea6 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IBuiltinInstanceInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IClassInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IClassInfo.cs index a1f2f97c2..31a455d5b 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IClassInfo.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { public interface IClassInfo : IAnalysisValue, IReferenceableContainer { diff --git a/src/Analysis/Engine/Impl/Values/Definitions/ICoroutineInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/ICoroutineInfo.cs index 7b2828264..c01022f6e 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/ICoroutineInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/ICoroutineInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IFunctionInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IFunctionInfo.cs index 3afaa779e..316be8d69 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IFunctionInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IFunctionInfo.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { public interface IFunctionInfo: IAnalysisValue { diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IGeneratorInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IGeneratorInfo.cs index 64b124410..c4f893fb6 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IGeneratorInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IGeneratorInfo.cs @@ -9,15 +9,11 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; -using System.Collections.Generic; -using System.Text; - namespace Microsoft.PythonTools.Analysis.Values { public interface IGeneratorInfo: IBuiltinInstanceInfo { } diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IInstanceInfo.cs index 0157be07e..d353f9a92 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IInstanceInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IModuleInfo.cs b/src/Analysis/Engine/Impl/Values/Definitions/IModuleInfo.cs index dca3f1c1a..0fe6c802d 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IModuleInfo.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IModuleInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/Definitions/IMro.cs b/src/Analysis/Engine/Impl/Values/Definitions/IMro.cs index 0592c5ad3..8c7e16dce 100644 --- a/src/Analysis/Engine/Impl/Values/Definitions/IMro.cs +++ b/src/Analysis/Engine/Impl/Values/Definitions/IMro.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/DictBuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/DictBuiltinClassInfo.cs index 663f74317..a3c3bf2b0 100644 --- a/src/Analysis/Engine/Impl/Values/DictBuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/DictBuiltinClassInfo.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class DictBuiltinClassInfo : BuiltinClassInfo { diff --git a/src/Analysis/Engine/Impl/Values/DictBuiltinInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/DictBuiltinInstanceInfo.cs index 03be82bd9..749628c26 100644 --- a/src/Analysis/Engine/Impl/Values/DictBuiltinInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/DictBuiltinInstanceInfo.cs @@ -16,9 +16,8 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class DictBuiltinInstanceInfo : BuiltinInstanceInfo, IHasRichDescription { diff --git a/src/Analysis/Engine/Impl/Values/DictionaryInfo.cs b/src/Analysis/Engine/Impl/Values/DictionaryInfo.cs index 037d98dee..197daf22c 100644 --- a/src/Analysis/Engine/Impl/Values/DictionaryInfo.cs +++ b/src/Analysis/Engine/Impl/Values/DictionaryInfo.cs @@ -21,8 +21,8 @@ using System.Threading; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class DictionaryInfo : BuiltinInstanceInfo, IAnalysisIterableValue { diff --git a/src/Analysis/Engine/Impl/Values/EnumInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/EnumInstanceInfo.cs index 917abd0f5..8ba993fde 100644 --- a/src/Analysis/Engine/Impl/Values/EnumInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/EnumInstanceInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/FunctionInfo.cs b/src/Analysis/Engine/Impl/Values/FunctionInfo.cs index 814465467..ba55c3d3b 100644 --- a/src/Analysis/Engine/Impl/Values/FunctionInfo.cs +++ b/src/Analysis/Engine/Impl/Values/FunctionInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,11 +18,11 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class FunctionInfo : AnalysisValue, IFunctionInfo2, IHasRichDescription, IHasQualifiedName { diff --git a/src/Analysis/Engine/Impl/Values/GeneratorInfo.cs b/src/Analysis/Engine/Impl/Values/GeneratorInfo.cs index 56fe48a84..96cbeab39 100644 --- a/src/Analysis/Engine/Impl/Values/GeneratorInfo.cs +++ b/src/Analysis/Engine/Impl/Values/GeneratorInfo.cs @@ -18,8 +18,8 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/InstanceInfo.cs b/src/Analysis/Engine/Impl/Values/InstanceInfo.cs index 18af72075..c65407e8f 100644 --- a/src/Analysis/Engine/Impl/Values/InstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/InstanceInfo.cs @@ -9,18 +9,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/IterableInfo.cs b/src/Analysis/Engine/Impl/Values/IterableInfo.cs index ac8465d32..fc4870f82 100644 --- a/src/Analysis/Engine/Impl/Values/IterableInfo.cs +++ b/src/Analysis/Engine/Impl/Values/IterableInfo.cs @@ -19,7 +19,7 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/IteratorInfo.cs b/src/Analysis/Engine/Impl/Values/IteratorInfo.cs index 651b448d5..2aedfbda6 100644 --- a/src/Analysis/Engine/Impl/Values/IteratorInfo.cs +++ b/src/Analysis/Engine/Impl/Values/IteratorInfo.cs @@ -9,15 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Diagnostics; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/LazyValueInfo.cs b/src/Analysis/Engine/Impl/Values/LazyValueInfo.cs index 4644cbf8c..54f13ec9e 100644 --- a/src/Analysis/Engine/Impl/Values/LazyValueInfo.cs +++ b/src/Analysis/Engine/Impl/Values/LazyValueInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,10 +19,10 @@ using System.Diagnostics; using System.Linq; using System.Threading; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class LazyValueInfo : AnalysisValue { diff --git a/src/Analysis/Engine/Impl/Values/ListBuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/ListBuiltinClassInfo.cs index 1d427ac89..b5779ca87 100644 --- a/src/Analysis/Engine/Impl/Values/ListBuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ListBuiltinClassInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class ListBuiltinClassInfo : SequenceBuiltinClassInfo { diff --git a/src/Analysis/Engine/Impl/Values/ListInfo.cs b/src/Analysis/Engine/Impl/Values/ListInfo.cs index 638d33932..dc3d9eeff 100644 --- a/src/Analysis/Engine/Impl/Values/ListInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ListInfo.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/MemberReferences.cs b/src/Analysis/Engine/Impl/Values/MemberReferences.cs index 6690cd0cf..e8ae7f1be 100644 --- a/src/Analysis/Engine/Impl/Values/MemberReferences.cs +++ b/src/Analysis/Engine/Impl/Values/MemberReferences.cs @@ -9,17 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/MergeStrengths.cs b/src/Analysis/Engine/Impl/Values/MergeStrengths.cs index bae63bc1e..864190ba5 100644 --- a/src/Analysis/Engine/Impl/Values/MergeStrengths.cs +++ b/src/Analysis/Engine/Impl/Values/MergeStrengths.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/ModuleInfo.cs b/src/Analysis/Engine/Impl/Values/ModuleInfo.cs index 69ab10238..6d6ee907d 100644 --- a/src/Analysis/Engine/Impl/Values/ModuleInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ModuleInfo.cs @@ -16,14 +16,14 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Text; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class ModuleInfo : AnalysisValue, IReferenceableContainer, IModuleInfo { diff --git a/src/Analysis/Engine/Impl/Values/MultipleMemberInfo.cs b/src/Analysis/Engine/Impl/Values/MultipleMemberInfo.cs index 822674bf9..a6322305b 100644 --- a/src/Analysis/Engine/Impl/Values/MultipleMemberInfo.cs +++ b/src/Analysis/Engine/Impl/Values/MultipleMemberInfo.cs @@ -9,21 +9,19 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Text; -using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { sealed class MultipleMemberInfo : AnalysisValue, IModule { diff --git a/src/Analysis/Engine/Impl/Values/NumericInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/NumericInstanceInfo.cs index 7aae7707c..5c60c8cb4 100644 --- a/src/Analysis/Engine/Impl/Values/NumericInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/NumericInstanceInfo.cs @@ -15,8 +15,8 @@ // permissions and limitations under the License. using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class NumericInstanceInfo : BuiltinInstanceInfo { diff --git a/src/Analysis/Engine/Impl/Values/ObjectBuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/ObjectBuiltinClassInfo.cs index 0e62e2250..58860d561 100644 --- a/src/Analysis/Engine/Impl/Values/ObjectBuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ObjectBuiltinClassInfo.cs @@ -9,15 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.Collections.Generic; using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class ObjectBuiltinClassInfo : BuiltinClassInfo { diff --git a/src/Analysis/Engine/Impl/Values/ParameterInfo.cs b/src/Analysis/Engine/Impl/Values/ParameterInfo.cs index 24dcb02f5..f49dc1424 100644 --- a/src/Analysis/Engine/Impl/Values/ParameterInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ParameterInfo.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class ParameterInfo : LazyValueInfo { diff --git a/src/Analysis/Engine/Impl/Values/PartialFunctionInfo.cs b/src/Analysis/Engine/Impl/Values/PartialFunctionInfo.cs index 58d8be563..af247a387 100644 --- a/src/Analysis/Engine/Impl/Values/PartialFunctionInfo.cs +++ b/src/Analysis/Engine/Impl/Values/PartialFunctionInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Linq; using System.Text; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class PartialFunctionInfo : AnalysisValue { diff --git a/src/Analysis/Engine/Impl/Values/ProtocolInfo.cs b/src/Analysis/Engine/Impl/Values/ProtocolInfo.cs index 1d7c287ac..1496991d0 100644 --- a/src/Analysis/Engine/Impl/Values/ProtocolInfo.cs +++ b/src/Analysis/Engine/Impl/Values/ProtocolInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,10 +18,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/Protocols.cs b/src/Analysis/Engine/Impl/Values/Protocols.cs index b1406765a..c0deae8d3 100644 --- a/src/Analysis/Engine/Impl/Values/Protocols.cs +++ b/src/Analysis/Engine/Impl/Values/Protocols.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,11 +17,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { abstract class Protocol : AnalysisValue, IHasRichDescription { diff --git a/src/Analysis/Engine/Impl/Values/PythonPackage.cs b/src/Analysis/Engine/Impl/Values/PythonPackage.cs index af71d3f62..e28cb61e9 100644 --- a/src/Analysis/Engine/Impl/Values/PythonPackage.cs +++ b/src/Analysis/Engine/Impl/Values/PythonPackage.cs @@ -16,8 +16,8 @@ using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/RangeInfo.cs b/src/Analysis/Engine/Impl/Values/RangeInfo.cs index 7f3d9b679..655d6e083 100644 --- a/src/Analysis/Engine/Impl/Values/RangeInfo.cs +++ b/src/Analysis/Engine/Impl/Values/RangeInfo.cs @@ -9,13 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class RangeInfo : BuiltinInstanceInfo { diff --git a/src/Analysis/Engine/Impl/Values/SequenceBuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/SequenceBuiltinClassInfo.cs index d2dad8d7b..0d1c097c1 100644 --- a/src/Analysis/Engine/Impl/Values/SequenceBuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SequenceBuiltinClassInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,7 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/SequenceBuiltinInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/SequenceBuiltinInstanceInfo.cs index 777d8865b..ff1931b4e 100644 --- a/src/Analysis/Engine/Impl/Values/SequenceBuiltinInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SequenceBuiltinInstanceInfo.cs @@ -9,18 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class SequenceBuiltinInstanceInfo : BaseIterableValue { @@ -73,7 +70,7 @@ public override IAnalysisSet GetEnumeratorTypes(Node node, AnalysisUnit unit) { return UnionType; } - public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation, IAnalysisSet rhs) { + public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { var res = AnalysisSet.Empty; switch (operation) { case PythonOperator.Add: diff --git a/src/Analysis/Engine/Impl/Values/SequenceInfo.cs b/src/Analysis/Engine/Impl/Values/SequenceInfo.cs index e94694a4f..1574dbdfd 100644 --- a/src/Analysis/Engine/Impl/Values/SequenceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SequenceInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,8 +18,8 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/SetInfo.cs b/src/Analysis/Engine/Impl/Values/SetInfo.cs index 95c56148f..4a0c04f58 100644 --- a/src/Analysis/Engine/Impl/Values/SetInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SetInfo.cs @@ -9,17 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.Collections.Generic; using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { internal class SetInfo : SequenceInfo { diff --git a/src/Analysis/Engine/Impl/Values/SliceInfo.cs b/src/Analysis/Engine/Impl/Values/SliceInfo.cs index b91926e02..24a75f6ea 100644 --- a/src/Analysis/Engine/Impl/Values/SliceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SliceInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/SpecializedCallable.cs b/src/Analysis/Engine/Impl/Values/SpecializedCallable.cs index afd6f72d1..b42799dbe 100644 --- a/src/Analysis/Engine/Impl/Values/SpecializedCallable.cs +++ b/src/Analysis/Engine/Impl/Values/SpecializedCallable.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/SpecializedInstanceInfo.cs b/src/Analysis/Engine/Impl/Values/SpecializedInstanceInfo.cs index 5891559b4..79f1dafac 100644 --- a/src/Analysis/Engine/Impl/Values/SpecializedInstanceInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SpecializedInstanceInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,8 +19,8 @@ using System.Linq; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs b/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs index 2b12d7669..f8708c524 100644 --- a/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs +++ b/src/Analysis/Engine/Impl/Values/SpecializedNamespace.cs @@ -17,9 +17,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { abstract class SpecializedNamespace : AnalysisValue { @@ -67,7 +68,7 @@ public override void AugmentAssign(AugmentedAssignStatement node, AnalysisUnit u _original.AugmentAssign(node, unit, value); } - public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation, IAnalysisSet rhs) { + public override IAnalysisSet BinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { if (_original == null) { return base.BinaryOperation(node, unit, operation, rhs); } @@ -221,7 +222,7 @@ public override bool IsOfType(IAnalysisSet klass) { public override PythonMemberType MemberType => _original == null ? PythonMemberType.Unknown : _original.MemberType; - public override IAnalysisSet ReverseBinaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation, IAnalysisSet rhs) { + public override IAnalysisSet ReverseBinaryOperation(Node node, AnalysisUnit unit, PythonOperator operation, IAnalysisSet rhs) { if (_original == null) { return AnalysisSet.Empty; } @@ -258,7 +259,7 @@ public override BuiltinTypeId TypeId { } } - public override IAnalysisSet UnaryOperation(Node node, AnalysisUnit unit, Parsing.PythonOperator operation) { + public override IAnalysisSet UnaryOperation(Node node, AnalysisUnit unit, PythonOperator operation) { if (_original == null) { return AnalysisSet.Empty; } diff --git a/src/Analysis/Engine/Impl/Values/SuperInfo.cs b/src/Analysis/Engine/Impl/Values/SuperInfo.cs index e7db35819..0a9c3f79c 100644 --- a/src/Analysis/Engine/Impl/Values/SuperInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SuperInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Diagnostics; using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/SyntheticDefinitionInfo.cs b/src/Analysis/Engine/Impl/Values/SyntheticDefinitionInfo.cs index 62203a2b4..ec0dbbf5e 100644 --- a/src/Analysis/Engine/Impl/Values/SyntheticDefinitionInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SyntheticDefinitionInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Impl/Values/SysModuleInfo.cs b/src/Analysis/Engine/Impl/Values/SysModuleInfo.cs index 58c59629d..448fa4d5c 100644 --- a/src/Analysis/Engine/Impl/Values/SysModuleInfo.cs +++ b/src/Analysis/Engine/Impl/Values/SysModuleInfo.cs @@ -9,15 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class SysModuleInfo : BuiltinModule { diff --git a/src/Analysis/Engine/Impl/Values/TupleBuiltinClassInfo.cs b/src/Analysis/Engine/Impl/Values/TupleBuiltinClassInfo.cs index 7c72615f9..afcd77e74 100644 --- a/src/Analysis/Engine/Impl/Values/TupleBuiltinClassInfo.cs +++ b/src/Analysis/Engine/Impl/Values/TupleBuiltinClassInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { diff --git a/src/Analysis/Engine/Impl/Values/TypingModuleInfo.cs b/src/Analysis/Engine/Impl/Values/TypingModuleInfo.cs index ac5dd3d3e..64ee6cf04 100644 --- a/src/Analysis/Engine/Impl/Values/TypingModuleInfo.cs +++ b/src/Analysis/Engine/Impl/Values/TypingModuleInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { class TypingModuleInfo : BuiltinModule { diff --git a/src/Analysis/Engine/Impl/Values/TypingTypeInfo.cs b/src/Analysis/Engine/Impl/Values/TypingTypeInfo.cs index 0ace7ec05..052398763 100644 --- a/src/Analysis/Engine/Impl/Values/TypingTypeInfo.cs +++ b/src/Analysis/Engine/Impl/Values/TypingTypeInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,10 +17,10 @@ using System; using System.Collections.Generic; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis.Values { /// diff --git a/src/Analysis/Engine/Impl/Values/Utils.cs b/src/Analysis/Engine/Impl/Values/Utils.cs index 8e64156d6..9295398b7 100644 --- a/src/Analysis/Engine/Impl/Values/Utils.cs +++ b/src/Analysis/Engine/Impl/Values/Utils.cs @@ -9,17 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using System.Linq; using System.Runtime.CompilerServices; using System.Text; -using Microsoft.PythonTools.Interpreter; namespace Microsoft.PythonTools.Analysis.Values { internal static class Utils { diff --git a/src/Analysis/Engine/Impl/VariableDef.cs b/src/Analysis/Engine/Impl/VariableDef.cs index afef28a0b..e4bebb830 100644 --- a/src/Analysis/Engine/Impl/VariableDef.cs +++ b/src/Analysis/Engine/Impl/VariableDef.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,9 +18,9 @@ using System.Diagnostics; using System.Linq; using System.Runtime.CompilerServices; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { abstract class DependentData where TStorageType : DependencyInfo { diff --git a/src/Analysis/Engine/Impl/VariablesResult.cs b/src/Analysis/Engine/Impl/VariablesResult.cs index adb2548e4..eb2c75a83 100644 --- a/src/Analysis/Engine/Impl/VariablesResult.cs +++ b/src/Analysis/Engine/Impl/VariablesResult.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections; using System.Collections.Generic; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.PythonTools.Analysis { public sealed class VariablesResult : IEnumerable { diff --git a/src/Analysis/Engine/Test/AnalysisSetTest.cs b/src/Analysis/Engine/Test/AnalysisSetTest.cs index 8265ef58d..8125e4a0c 100644 --- a/src/Analysis/Engine/Test/AnalysisSetTest.cs +++ b/src/Analysis/Engine/Test/AnalysisSetTest.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/AnalysisTest.cs b/src/Analysis/Engine/Test/AnalysisTest.cs index 0d2eab2ab..acc776244 100644 --- a/src/Analysis/Engine/Test/AnalysisTest.cs +++ b/src/Analysis/Engine/Test/AnalysisTest.cs @@ -24,6 +24,8 @@ using FluentAssertions; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Tests; using Microsoft.Python.UnitTests.Core.MSTest; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.Analyzer; @@ -31,7 +33,6 @@ using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; -using Microsoft.PythonTools.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; @@ -5688,16 +5689,16 @@ def fob(a, b, c, d): "args_from_fob_1" }) { entry.AssertDescription(name, "tuple[int, float, str, list]"); - var result = entry.GetValue(name); + var result = entry.GetAnnotationType(name); Console.WriteLine("{0} = {1}", name, result); AssertTupleContains(result, BuiltinTypeId.Int, BuiltinTypeId.Float, entry.BuiltinTypeId_Str, BuiltinTypeId.List); } - var fob = entry.GetValue("fob"); - var fob2 = entry.GetValue("func_from_fob_1"); + var fob = entry.GetAnnotationType("fob"); + var fob2 = entry.GetAnnotationType("func_from_fob_1"); Assert.AreSame(fob, fob2); - entry.GetValue("keywords_from_fob_2"); + entry.GetAnnotationType("keywords_from_fob_2"); } [TestMethod, Priority(0)] @@ -5735,10 +5736,10 @@ def test2a(): state.AssertConstantEquals("test1.__name__", "test1"); state.AssertConstantEquals("test1.__doc__", "doc"); - var fi = state.GetValue("test1"); + var fi = state.GetAnnotationType("test1"); Assert.AreEqual("doc", fi.Documentation); - state.GetValue("test1.__wrapped__"); - Assert.AreEqual(2, state.GetValue("test1").Overloads.Count()); + state.GetAnnotationType("test1.__wrapped__"); + Assert.AreEqual(2, state.GetAnnotationType("test1").Overloads.Count()); state.AssertConstantEquals("test1_result", "decorated"); // __name__ should not have been changed by update_wrapper @@ -5857,9 +5858,9 @@ public async Task SysModulesSetSpecialization() { var entry = ProcessTextV2(code); - var sys = entry.GetValue("sys"); + var sys = entry.GetAnnotationType("sys"); - var modules = entry.GetValue("modules"); + var modules = entry.GetAnnotationType("modules"); Assert.IsInstanceOfType(modules, typeof(SysModuleInfo.SysModulesDictionaryInfo)); AssertUtil.ContainsExactly( @@ -5886,9 +5887,9 @@ public async Task SysModulesGetSpecialization() { entry.AssertIsInstance("value_in_modules", BuiltinTypeId.Int); - Assert.AreEqual("__builtin__", entry.GetValue("builtins").Name); - Assert.AreEqual("__builtin__", entry.GetValue("builtins2").Name); - Assert.AreEqual("__builtin__", entry.GetValue("builtins3").Name); + Assert.AreEqual("__builtin__", entry.GetAnnotationType("builtins").Name); + Assert.AreEqual("__builtin__", entry.GetAnnotationType("builtins2").Name); + Assert.AreEqual("__builtin__", entry.GetAnnotationType("builtins3").Name); } [TestMethod, Priority(0)] @@ -6070,7 +6071,7 @@ public void CrossModuleFunctionCallMemLeak() { entryA.Analyze(CancellationToken.None, true); analyzer.WaitForAnalysis(CancellationTokens.After5s); } - var g = analyzer.GetValue(entryB, "g"); + var g = analyzer.GetAnnotationType(entryB, "g"); Assert.AreEqual(1, g.References.Count()); } diff --git a/src/Analysis/Engine/Test/AssemblySetup.cs b/src/Analysis/Engine/Test/AssemblySetup.cs index fab31dbbd..0f6df5e35 100644 --- a/src/Analysis/Engine/Test/AssemblySetup.cs +++ b/src/Analysis/Engine/Test/AssemblySetup.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.Testing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; @@ -32,4 +32,4 @@ public static void Initialize() { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/AstAnalysisTests.cs b/src/Analysis/Engine/Test/AstAnalysisTests.cs index 400d0cc78..2f98f4c32 100644 --- a/src/Analysis/Engine/Test/AstAnalysisTests.cs +++ b/src/Analysis/Engine/Test/AstAnalysisTests.cs @@ -24,7 +24,11 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Tests; using Microsoft.Python.Tests.Utilities; using Microsoft.Python.Tests.Utilities.FluentAssertions; using Microsoft.PythonTools.Analysis; @@ -32,11 +36,9 @@ using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; -using Microsoft.PythonTools.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; -using static Microsoft.PythonTools.Analysis.Infrastructure.StringExtensions; -using Ast = Microsoft.PythonTools.Parsing.Ast; +using Ast = Microsoft.Python.Parsing.Ast; namespace AnalysisTests { [TestClass] @@ -622,7 +624,7 @@ private async Task AstNativeBuiltinScrape(InterpreterConfiguration configuration new[] { interpreter.BuiltinModuleName, "exceptions" } : new[] { interpreter.BuiltinModuleName }; - foreach (var pyd in Microsoft.PythonTools.Analysis.Infrastructure.PathUtils.EnumerateFiles(dllsDir, "*", recurse: false).Where(ModulePath.IsPythonFile)) { + foreach (var pyd in Microsoft.Python.Core.IO.PathUtils.EnumerateFiles(dllsDir, "*", recurse: false).Where(ModulePath.IsPythonFile)) { var mp = ModulePath.FromFullPath(pyd); if (mp.IsDebug) { continue; @@ -762,7 +764,7 @@ private async Task FullStdLibTest(InterpreterConfiguration configuration, params interp.AddUnimportableModule(m); } - foreach (var r in modules + var set = modules .Where(m => !skip.Contains(m.ModuleName)) .GroupBy(m => { var i = m.FullName.IndexOf('.'); @@ -770,7 +772,9 @@ private async Task FullStdLibTest(InterpreterConfiguration configuration, params }) .AsParallel() .SelectMany(g => g.Select(m => Tuple.Create(m, interp.ImportModule(m.ModuleName)))) - ) { + .ToArray(); + + foreach (var r in set) { var modName = r.Item1; var mod = r.Item2; diff --git a/src/Analysis/Engine/Test/BlockFormatterTests.cs b/src/Analysis/Engine/Test/BlockFormatterTests.cs index 280fea2b6..4b68333cb 100644 --- a/src/Analysis/Engine/Test/BlockFormatterTests.cs +++ b/src/Analysis/Engine/Test/BlockFormatterTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,9 +18,9 @@ using System.IO; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Implementation; -using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Test/CompletionTests.cs b/src/Analysis/Engine/Test/CompletionTests.cs index cc98b77e6..834d74d85 100644 --- a/src/Analysis/Engine/Test/CompletionTests.cs +++ b/src/Analysis/Engine/Test/CompletionTests.cs @@ -21,17 +21,18 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Shell; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Extensions; using Microsoft.Python.LanguageServer.Implementation; -using Microsoft.PythonTools; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.Documentation; using Microsoft.PythonTools.Analysis.FluentAssertions; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Test/DocumentBufferTests.cs b/src/Analysis/Engine/Test/DocumentBufferTests.cs index 89913879a..ecb5b40d9 100644 --- a/src/Analysis/Engine/Test/DocumentBufferTests.cs +++ b/src/Analysis/Engine/Test/DocumentBufferTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Linq; using System.Text; using FluentAssertions; -using Microsoft.PythonTools; +using Microsoft.Python.Core.Text; using Microsoft.PythonTools.Analysis; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Analysis/Engine/Test/EventTaskSources.cs b/src/Analysis/Engine/Test/EventTaskSources.cs index d24ca8145..fddab872f 100644 --- a/src/Analysis/Engine/Test/EventTaskSources.cs +++ b/src/Analysis/Engine/Test/EventTaskSources.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/ExpressionFinderTests.cs b/src/Analysis/Engine/Test/ExpressionFinderTests.cs index 2fc623fcb..b0aac99fa 100644 --- a/src/Analysis/Engine/Test/ExpressionFinderTests.cs +++ b/src/Analysis/Engine/Test/ExpressionFinderTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,11 +17,11 @@ using System; using System.IO; using System.Linq; -using Microsoft.PythonTools; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AnalysisTests { diff --git a/src/Analysis/Engine/Test/FindReferencesTests.cs b/src/Analysis/Engine/Test/FindReferencesTests.cs index 495bee9c8..3da0ae066 100644 --- a/src/Analysis/Engine/Test/FindReferencesTests.cs +++ b/src/Analysis/Engine/Test/FindReferencesTests.cs @@ -20,9 +20,9 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Implementation; -using Microsoft.PythonTools; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; using Microsoft.PythonTools.Analysis.Values; diff --git a/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertions.cs index 309a083e4..8ccabb128 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertionsExtensions.cs b/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertionsExtensions.cs index fc61caa96..6c3ec9ee4 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertionsExtensions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueAssertionsExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueTestInfo.cs b/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueTestInfo.cs index 144bb0e15..1e0c733f6 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueTestInfo.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/AnalysisValueTestInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/AssertionsFactory.cs b/src/Analysis/Engine/Test/FluentAssertions/AssertionsFactory.cs index 107188b9c..90f59b89b 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/AssertionsFactory.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/AssertionsFactory.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,6 +15,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; diff --git a/src/Analysis/Engine/Test/FluentAssertions/AssertionsUtilities.cs b/src/Analysis/Engine/Test/FluentAssertions/AssertionsUtilities.cs index 51987dd85..bb8ea8658 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/AssertionsUtilities.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/AssertionsUtilities.cs @@ -20,11 +20,12 @@ using System.Text; using FluentAssertions; using FluentAssertions.Execution; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; namespace Microsoft.PythonTools.Analysis.FluentAssertions { internal static class AssertionsUtilities { @@ -250,4 +251,4 @@ public static Continuation AssertHasMemberOfType(this AssertionScope as return continuation; } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/AstPythonFunctionAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/AstPythonFunctionAssertions.cs index 3104ccd9c..db4c75ee4 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/AstPythonFunctionAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/AstPythonFunctionAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,6 @@ using FluentAssertions; using FluentAssertions.Execution; using FluentAssertions.Primitives; -using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; namespace Microsoft.PythonTools.Analysis.FluentAssertions { @@ -61,4 +60,4 @@ public AndWhichConstraint(this, new PythonFunctionOverloadTestInfo(overloads[index], Subject.FullyQualifiedName)); } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/BoundBuiltinMethodInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/BoundBuiltinMethodInfoAssertions.cs index 9517621db..fedff5b47 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/BoundBuiltinMethodInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/BoundBuiltinMethodInfoAssertions.cs @@ -9,17 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Diagnostics.CodeAnalysis; -using System.Linq; using FluentAssertions; using FluentAssertions.Execution; -using FluentAssertions.Primitives; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; namespace Microsoft.PythonTools.Analysis.FluentAssertions { @@ -41,4 +38,4 @@ public AndWhichConstraint protected override string Identifier => nameof(BuiltinFunctionInfoAssertions); } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/BuiltinInstanceInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/BuiltinInstanceInfoAssertions.cs index 569ad38ca..ed3144456 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/BuiltinInstanceInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/BuiltinInstanceInfoAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/BuiltinModuleAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/BuiltinModuleAssertions.cs index 2a1702a75..fb32a05ef 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/BuiltinModuleAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/BuiltinModuleAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,6 @@ using System.Diagnostics.CodeAnalysis; using FluentAssertions; using FluentAssertions.Execution; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; diff --git a/src/Analysis/Engine/Test/FluentAssertions/ClassInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/ClassInfoAssertions.cs index 73328c8dd..9f5c8e1f8 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ClassInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ClassInfoAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,7 +19,6 @@ using System.Linq; using FluentAssertions; using FluentAssertions.Execution; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; @@ -69,4 +68,4 @@ public AndConstraint HaveInvalidMethodResolutionOrder(strin protected override string GetName() => $"class {GetQuotedName(Subject)}"; } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/DictionaryInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/DictionaryInfoAssertions.cs index 6dc361fe7..044d638db 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/DictionaryInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/DictionaryInfoAssertions.cs @@ -9,21 +9,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Linq; using FluentAssertions; -using FluentAssertions.Execution; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; namespace Microsoft.PythonTools.Analysis.FluentAssertions { [ExcludeFromCodeCoverage] @@ -44,4 +41,4 @@ public AndConstraint HaveValueTypes(IEnumerable(this); } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/FunctionInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/FunctionInfoAssertions.cs index c76631530..f3f36828d 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/FunctionInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/FunctionInfoAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,6 @@ using System.Diagnostics.CodeAnalysis; using FluentAssertions; using FluentAssertions.Execution; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; @@ -50,4 +49,4 @@ public AndWhichConstraint HaveFunctionSc protected override string GetName() => $"function {GetQuotedName(Subject)} in a scope {GetQuotedName(OwnerScope)}"; } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/FunctionScopeAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/FunctionScopeAssertions.cs index 29fc14464..2f7f3eff3 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/FunctionScopeAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/FunctionScopeAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,7 +20,7 @@ using FluentAssertions; using FluentAssertions.Execution; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; namespace Microsoft.PythonTools.Analysis.FluentAssertions { diff --git a/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertions.cs index 74775df5d..4742563cd 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,7 +20,6 @@ using FluentAssertions; using FluentAssertions.Execution; using FluentAssertions.Primitives; -using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; @@ -114,4 +113,4 @@ public AndConstraint NotHaveMembers(IEnumerable memberNames return new AndConstraint((TAssertions)this); } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs b/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs index 55e8f69de..e06ea72cf 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/MemberContainerAssertionsExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/ModuleAnalysisAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/ModuleAnalysisAssertions.cs index 9ca89b0de..311267086 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ModuleAnalysisAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ModuleAnalysisAssertions.cs @@ -9,18 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using FluentAssertions; using FluentAssertions.Execution; using FluentAssertions.Primitives; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; diff --git a/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertions.cs index 2e1938404..e245cd9d9 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertionsExtensions.cs b/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertionsExtensions.cs index b58b8d7a4..d0187db65 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertionsExtensions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/OverloadResultAssertionsExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/OverloadResultTestInfo.cs b/src/Analysis/Engine/Test/FluentAssertions/OverloadResultTestInfo.cs index 41c05711f..1b36bd46f 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/OverloadResultTestInfo.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/OverloadResultTestInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/ParameterInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/ParameterInfoAssertions.cs index f2c6b2048..9a92920b4 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ParameterInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ParameterInfoAssertions.cs @@ -9,13 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Diagnostics.CodeAnalysis; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; @@ -29,4 +28,4 @@ public ParameterInfoAssertions(AnalysisValueTestInfo subject) : b protected override string GetName() => $"parameter {GetQuotedName(Subject)} in a function {GetQuotedName(Subject.Function)}"; } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/ParameterResultAssertionsExtensions.cs b/src/Analysis/Engine/Test/FluentAssertions/ParameterResultAssertionsExtensions.cs index 3d34cc93e..1235cee7b 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ParameterResultAssertionsExtensions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ParameterResultAssertionsExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/ProtocolInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/ProtocolInfoAssertions.cs index fc2f9bf2a..b133a1b84 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ProtocolInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ProtocolInfoAssertions.cs @@ -9,13 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Diagnostics.CodeAnalysis; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; namespace Microsoft.PythonTools.Analysis.FluentAssertions { @@ -25,4 +24,4 @@ public ProtocolInfoAssertions(AnalysisValueTestInfo subject) : bas protected override string Identifier => nameof(ProtocolInfo); } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs index 5d59c5746..749178a3a 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadTestInfo.cs b/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadTestInfo.cs index 463afb90c..a5093d42a 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadTestInfo.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/PythonFunctionOverloadTestInfo.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/RangeAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/RangeAssertions.cs index 21a7b951c..b684273f0 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/RangeAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/RangeAssertions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,7 +15,7 @@ using FluentAssertions; using FluentAssertions.Execution; -using FluentAssertions.Primitives; +using Microsoft.Python.Core.Text; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; namespace Microsoft.PythonTools.Analysis.FluentAssertions { diff --git a/src/Analysis/Engine/Test/FluentAssertions/ReferenceCollectionAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/ReferenceCollectionAssertions.cs index 84a5f4038..6ab7acce9 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ReferenceCollectionAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ReferenceCollectionAssertions.cs @@ -21,6 +21,7 @@ using FluentAssertions; using FluentAssertions.Collections; using FluentAssertions.Execution; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using TestUtilities; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; diff --git a/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertions.cs index a40d9ab5b..52149470d 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertionsExtensions.cs b/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertionsExtensions.cs index 29aebca0d..0436852c4 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertionsExtensions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/ScopeAssertionsExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/SequenceInfoAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/SequenceInfoAssertions.cs index a4ffb83c4..0280b4cac 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/SequenceInfoAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/SequenceInfoAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/SignatureInformationAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/SignatureInformationAssertions.cs index 0309de92c..182eaa72e 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/SignatureInformationAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/SignatureInformationAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/SpecializedCallableAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/SpecializedCallableAssertions.cs index 3d7c19bf3..bb6a6f854 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/SpecializedCallableAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/SpecializedCallableAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FluentAssertions/TextEditCollectionAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/TextEditCollectionAssertions.cs index 069c8e604..f045f64ef 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/TextEditCollectionAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/TextEditCollectionAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,6 +21,7 @@ using FluentAssertions; using FluentAssertions.Collections; using FluentAssertions.Execution; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; @@ -110,4 +111,4 @@ private string GetHaveTextEditErrorMessage(string expectedText, Range expectedRa [CustomAssertion] private static string GetSubjectName() => CallerIdentifier.DetermineCallerIdentity() ?? "collection"; } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertions.cs b/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertions.cs index a7fbeb637..43bad4ef6 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,7 +20,6 @@ using FluentAssertions; using FluentAssertions.Execution; using FluentAssertions.Primitives; -using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; using static Microsoft.PythonTools.Analysis.FluentAssertions.AssertionsUtilities; @@ -253,4 +252,4 @@ private string GetScopeDescription() { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertionsExtensions.cs b/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertionsExtensions.cs index 881a0bf3a..22f47adee 100644 --- a/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertionsExtensions.cs +++ b/src/Analysis/Engine/Test/FluentAssertions/VariableDefAssertionsExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/FunctionBodyAnalysisTests.cs b/src/Analysis/Engine/Test/FunctionBodyAnalysisTests.cs index b6d1002dc..84743e160 100644 --- a/src/Analysis/Engine/Test/FunctionBodyAnalysisTests.cs +++ b/src/Analysis/Engine/Test/FunctionBodyAnalysisTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,9 +17,10 @@ using System.Linq; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing.Tests; using Microsoft.Python.Tests.Utilities.FluentAssertions; -using Microsoft.PythonTools; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; using Microsoft.PythonTools.Analysis.Values; diff --git a/src/Analysis/Engine/Test/HoverTests.cs b/src/Analysis/Engine/Test/HoverTests.cs index c38d180f9..386069974 100644 --- a/src/Analysis/Engine/Test/HoverTests.cs +++ b/src/Analysis/Engine/Test/HoverTests.cs @@ -20,10 +20,10 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Implementation; using Microsoft.Python.Tests.Utilities.FluentAssertions; -using Microsoft.PythonTools; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.Documentation; using Microsoft.PythonTools.Analysis.FluentAssertions; diff --git a/src/Analysis/Engine/Test/ImportTests.cs b/src/Analysis/Engine/Test/ImportTests.cs index 4f1ad0acd..60abd01e0 100644 --- a/src/Analysis/Engine/Test/ImportTests.cs +++ b/src/Analysis/Engine/Test/ImportTests.cs @@ -16,7 +16,6 @@ using System; using System.IO; -using System.Linq; using System.Threading; using System.Threading.Tasks; using Microsoft.Python.LanguageServer.Implementation; diff --git a/src/Analysis/Engine/Test/InheritanceTests.cs b/src/Analysis/Engine/Test/InheritanceTests.cs index f7dfb7232..4c1cb1186 100644 --- a/src/Analysis/Engine/Test/InheritanceTests.cs +++ b/src/Analysis/Engine/Test/InheritanceTests.cs @@ -1,12 +1,26 @@ -using System; -using System.Collections.Generic; -using System.Text; +// Python Tools for Visual Studio +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + using System.Threading.Tasks; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Tests; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Test/LanguageServerTests.cs b/src/Analysis/Engine/Test/LanguageServerTests.cs index 974499161..b40488158 100644 --- a/src/Analysis/Engine/Test/LanguageServerTests.cs +++ b/src/Analysis/Engine/Test/LanguageServerTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,18 +22,22 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Services; +using Microsoft.Python.Core.Tests; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Extensions; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing.Tests; using Microsoft.Python.Tests.Utilities.FluentAssertions; -using Microsoft.PythonTools; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.Analyzer; using Microsoft.PythonTools.Analysis.FluentAssertions; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; -using Microsoft.PythonTools.Parsing.Ast; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; @@ -79,8 +83,11 @@ public Task CreateServer(string rootPath, InterpreterConfiguration confi public async Task CreateServer(Uri rootUri, InterpreterConfiguration configuration = null, Dictionary diagnosticEvents = null) { configuration = configuration ?? Default; configuration.AssertInstalled(); - var s = new Server(); - s.OnLogMessage += Server_OnLogMessage; + + var sm = new ServiceManager(); + sm.AddService(new TestLogger()); + var s = new Server(sm); + var properties = new InterpreterFactoryCreationOptions { TraceLevel = System.Diagnostics.TraceLevel.Verbose, DatabasePath = TestData.GetAstAnalysisCachePath(configuration.Version) @@ -129,15 +136,6 @@ private async Task LoadFromDirectoryAsync(Server s, string rootDir) { } } - private void Server_OnLogMessage(object sender, LogMessageEventArgs e) { - switch (e.type) { - case MessageType.Error: Trace.TraceError(e.message); break; - case MessageType.Warning: Trace.TraceWarning(e.message); break; - case MessageType.Info: Trace.TraceInformation(e.message); break; - case MessageType.Log: Trace.TraceInformation("LOG: " + e.message); break; - } - } - private TextDocumentIdentifier GetDocument(string file) { if (!Path.IsPathRooted(file)) { file = TestData.GetPath(file); diff --git a/src/Analysis/Engine/Test/LineFormatterTests.cs b/src/Analysis/Engine/Test/LineFormatterTests.cs index 58ccdbaf0..da77308f8 100644 --- a/src/Analysis/Engine/Test/LineFormatterTests.cs +++ b/src/Analysis/Engine/Test/LineFormatterTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,14 +17,10 @@ using System; using System.IO; using FluentAssertions; -using Microsoft.Python.LanguageServer; +using Microsoft.Python.Core.Diagnostics; using Microsoft.Python.LanguageServer.Implementation; -using Microsoft.Python.Tests.Utilities.FluentAssertions; -using Microsoft.PythonTools; -using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Test/LongestCommonSequenceTests.cs b/src/Analysis/Engine/Test/LongestCommonSequenceTests.cs index d3d4b0707..bb487e48d 100644 --- a/src/Analysis/Engine/Test/LongestCommonSequenceTests.cs +++ b/src/Analysis/Engine/Test/LongestCommonSequenceTests.cs @@ -9,17 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; -using System.Linq; using FluentAssertions; using Microsoft.PythonTools.Intellisense; using Microsoft.VisualStudio.TestTools.UnitTesting; -using TestUtilities; namespace AnalysisTests { [TestClass] @@ -59,4 +56,4 @@ private void FindCharDiffs(string oldText, string newText, params LcsDiff[] expe diffs.Should().Equal(expected); } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj b/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj index 08ccbb292..06171e282 100644 --- a/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj +++ b/src/Analysis/Engine/Test/Microsoft.Python.Analysis.Engine.Tests.csproj @@ -38,8 +38,13 @@ + + + + + diff --git a/src/Analysis/Engine/Test/ModuleAnalysisExtensions.cs b/src/Analysis/Engine/Test/ModuleAnalysisExtensions.cs index 7fae3d0c3..1ed4c4b70 100644 --- a/src/Analysis/Engine/Test/ModuleAnalysisExtensions.cs +++ b/src/Analysis/Engine/Test/ModuleAnalysisExtensions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/Analysis/Engine/Test/Properties/AssemblyInfo.cs b/src/Analysis/Engine/Test/Properties/AssemblyInfo.cs index 88a89bc0a..cd607c745 100644 --- a/src/Analysis/Engine/Test/Properties/AssemblyInfo.cs +++ b/src/Analysis/Engine/Test/Properties/AssemblyInfo.cs @@ -14,7 +14,6 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.Reflection; using System.Runtime.InteropServices; [assembly: ComVisible(false)] diff --git a/src/Analysis/Engine/Test/ServerBasedTest.cs b/src/Analysis/Engine/Test/ServerBasedTest.cs index 1727caf49..1cddaa402 100644 --- a/src/Analysis/Engine/Test/ServerBasedTest.cs +++ b/src/Analysis/Engine/Test/ServerBasedTest.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,17 +15,15 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing.Tests; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Intellisense; -using Microsoft.PythonTools.Interpreter; -using TestUtilities; namespace AnalysisTests { public class ServerBasedTest { diff --git a/src/Analysis/Engine/Test/ServerExtensions.cs b/src/Analysis/Engine/Test/ServerExtensions.cs index 52813934b..ccfca16d5 100644 --- a/src/Analysis/Engine/Test/ServerExtensions.cs +++ b/src/Analysis/Engine/Test/ServerExtensions.cs @@ -20,8 +20,13 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core.Services; +using Microsoft.Python.Core.Tests; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing.Tests; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; using TestUtilities; @@ -31,7 +36,6 @@ internal static class ServerExtensions { public static async Task InitializeAsync(this Server server, InterpreterConfiguration configuration, Uri rootUri = null, IEnumerable searchPaths = null) { configuration.AssertInstalled(); - server.OnLogMessage += Server_OnLogMessage; var properties = new InterpreterFactoryCreationOptions { TraceLevel = System.Diagnostics.TraceLevel.Verbose, DatabasePath = TestData.GetAstAnalysisCachePath(configuration.Version) @@ -39,6 +43,10 @@ public static async Task InitializeAsync(this Server server, Interpreter configuration.WriteToDictionary(properties); + var sm = new ServiceManager(); + sm.AddService(new TestLogger()); + server.SetServices(sm); + await server.Initialize(new InitializeParams { rootUri = rootUri, initializationOptions = new PythonInitializationOptions { @@ -255,15 +263,6 @@ public static async Task ChangeDefaultDocumentAndGetAnalysisAsy public static string[] GetBuiltinTypeMemberNames(this Server server, BuiltinTypeId typeId) => server.Analyzer.Types[typeId].GetMemberNames((IModuleContext)server.Analyzer.Interpreter).ToArray(); - private static void Server_OnLogMessage(object sender, LogMessageEventArgs e) { - switch (e.type) { - case MessageType.Error: Trace.TraceError($"[{TestEnvironmentImpl.Elapsed()}]: {e.message}"); break; - case MessageType.Warning: Trace.TraceWarning($"[{TestEnvironmentImpl.Elapsed()}]: {e.message}"); break; - case MessageType.Info: Trace.TraceInformation($"[{TestEnvironmentImpl.Elapsed()}]: {e.message}"); break; - case MessageType.Log: Trace.TraceInformation($"[{TestEnvironmentImpl.Elapsed()}] LOG: {e.message}"); break; - } - } - private static CancellationToken GetCancellationToken(int failAfter = 30000) => Debugger.IsAttached ? CancellationToken.None : new CancellationTokenSource(failAfter).Token; } diff --git a/src/Analysis/Engine/Test/ServerTestMethodAttribute.cs b/src/Analysis/Engine/Test/ServerTestMethodAttribute.cs index d2dffff01..1f335f6e2 100644 --- a/src/Analysis/Engine/Test/ServerTestMethodAttribute.cs +++ b/src/Analysis/Engine/Test/ServerTestMethodAttribute.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -15,11 +14,11 @@ // permissions and limitations under the License. using System; -using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.Interpreter; using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Tests; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Test/ThreadingTest.cs b/src/Analysis/Engine/Test/ThreadingTest.cs index 5069dddea..3c439550c 100644 --- a/src/Analysis/Engine/Test/ThreadingTest.cs +++ b/src/Analysis/Engine/Test/ThreadingTest.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,11 +22,10 @@ using System.Threading; using System.Threading.Tasks; using FluentAssertions; -using Microsoft.Python.Tests.Utilities.FluentAssertions; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Test/TypeAnnotationTests.cs b/src/Analysis/Engine/Test/TypeAnnotationTests.cs index 41435c759..35c05292f 100644 --- a/src/Analysis/Engine/Test/TypeAnnotationTests.cs +++ b/src/Analysis/Engine/Test/TypeAnnotationTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,14 +20,15 @@ using System.Linq; using System.Threading.Tasks; using FluentAssertions; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer.Implementation; -using Microsoft.PythonTools; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; +using Microsoft.Python.Parsing.Tests; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.FluentAssertions; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; diff --git a/src/Analysis/Engine/Impl/Infrastructure/Check.cs b/src/Core/Impl/Diagnostics/Check.cs similarity index 74% rename from src/Analysis/Engine/Impl/Infrastructure/Check.cs rename to src/Core/Impl/Diagnostics/Check.cs index 694296234..9437ca48e 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Check.cs +++ b/src/Core/Impl/Diagnostics/Check.cs @@ -1,12 +1,24 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. using System; using System.Diagnostics; using System.Runtime.CompilerServices; using static System.FormattableString; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Diagnostics { public static class Check { [DebuggerStepThrough] public static void FieldType(string fieldName, object fieldValue) { @@ -61,4 +73,4 @@ public static void Argument(string argumentName, Func predicate) { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/CountdownDisposable.cs b/src/Core/Impl/Disposables/CountdownDisposable.cs similarity index 55% rename from src/Analysis/Engine/Impl/Infrastructure/CountdownDisposable.cs rename to src/Core/Impl/Disposables/CountdownDisposable.cs index 7e57596f4..73e23f0c2 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/CountdownDisposable.cs +++ b/src/Core/Impl/Disposables/CountdownDisposable.cs @@ -1,10 +1,22 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. using System; using System.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Disposables { public sealed class CountdownDisposable { private readonly Action _createAction; private readonly Action _disposeAction; diff --git a/src/Analysis/Engine/Impl/Infrastructure/DefaultDisposable.cs b/src/Core/Impl/Disposables/DefaultDisposable.cs similarity index 82% rename from src/Analysis/Engine/Impl/Infrastructure/DefaultDisposable.cs rename to src/Core/Impl/Disposables/DefaultDisposable.cs index 56e91de77..b450fec7e 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/DefaultDisposable.cs +++ b/src/Core/Impl/Disposables/DefaultDisposable.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,19 +8,19 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Disposables { /// /// Represents a disposable that does nothing on disposal. /// Implementation is copied from System.Reactive.Core.dll /// - internal sealed class DefaultDisposable : IDisposable { + public sealed class DefaultDisposable : IDisposable { /// /// Singleton default disposable. /// @@ -34,4 +33,4 @@ private DefaultDisposable() { } /// public void Dispose() { } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/Disposable.cs b/src/Core/Impl/Disposables/Disposable.cs similarity index 94% rename from src/Analysis/Engine/Impl/Infrastructure/Disposable.cs rename to src/Core/Impl/Disposables/Disposable.cs index 09070f159..854d05038 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Disposable.cs +++ b/src/Core/Impl/Disposables/Disposable.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +16,9 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core.Diagnostics; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Disposables { /// /// Provides a set of static methods for creating Disposables. /// @@ -71,7 +71,7 @@ public AnonymousDisposable(Action dispose) { /// Calls the disposal action if and only if the current instance hasn't been disposed yet. /// public void Dispose() { - Action action = Interlocked.Exchange(ref _dispose, null); + var action = Interlocked.Exchange(ref _dispose, null); action?.Invoke(); } } diff --git a/src/Analysis/Engine/Impl/Infrastructure/DisposableBag.cs b/src/Core/Impl/Disposables/DisposableBag.cs similarity index 93% rename from src/Analysis/Engine/Impl/Infrastructure/DisposableBag.cs rename to src/Core/Impl/Disposables/DisposableBag.cs index fc3d14797..d9607e31d 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/DisposableBag.cs +++ b/src/Core/Impl/Disposables/DisposableBag.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +17,7 @@ using System.Collections.Concurrent; using System.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Disposables { public sealed class DisposableBag { private readonly string _objectName; private readonly string _message; @@ -77,4 +76,4 @@ public bool TryDispose() { public bool IsDisposed => _disposables == null; } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/DisposeToken.cs b/src/Core/Impl/Disposables/DisposeToken.cs similarity index 87% rename from src/Analysis/Engine/Impl/Infrastructure/DisposeToken.cs rename to src/Core/Impl/Disposables/DisposeToken.cs index 3ec4c26d9..9c0c473b9 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/DisposeToken.cs +++ b/src/Core/Impl/Disposables/DisposeToken.cs @@ -1,5 +1,4 @@ -// Visual Studio Shared Project -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,12 +17,12 @@ using System.Threading; using static System.FormattableString; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Disposables { /// - /// Represents a disposable that does nothing on disposal. - /// Implementation is copied from System.Reactive.Core.dll - /// - internal sealed class EmptyDisposable : IDisposable { + /// Represents a disposable that does nothing on disposal. + /// Implementation is copied from System.Reactive.Core.dll + /// + public sealed class EmptyDisposable : IDisposable { /// /// Singleton default disposable. /// @@ -37,7 +36,7 @@ private EmptyDisposable() { } public void Dispose() { } } - internal sealed class DisposeToken { + public sealed class DisposeToken { private readonly Type _type; private readonly CancellationTokenSource _cts; private int _disposed; @@ -94,7 +93,7 @@ public bool TryMarkDisposed() { _cts.Dispose(); return true; } - + private ObjectDisposedException CreateException() => new ObjectDisposedException(_type.Name, Invariant($"{_type.Name} instance is disposed")); } } diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/ArrayExtensions.cs b/src/Core/Impl/Extensions/ArrayExtensions.cs similarity index 87% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/ArrayExtensions.cs rename to src/Core/Impl/Extensions/ArrayExtensions.cs index a532d1116..20c6478b2 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/ArrayExtensions.cs +++ b/src/Core/Impl/Extensions/ArrayExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,8 +15,8 @@ using System; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class ArrayExtensions { +namespace Microsoft.Python.Core { + public static class ArrayExtensions { public static int IndexOf(this T[] array, Func predicate) { for (var i = 0; i < array.Length; i++) { if (predicate(array[i])) { diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/CharExtensions.cs b/src/Core/Impl/Extensions/CharExtensions.cs similarity index 86% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/CharExtensions.cs rename to src/Core/Impl/Extensions/CharExtensions.cs index b0aa4eb62..88c760436 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/CharExtensions.cs +++ b/src/Core/Impl/Extensions/CharExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -14,12 +13,12 @@ // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class CharExtensions { +namespace Microsoft.Python.Core { + public static class CharExtensions { public static bool IsLatin1(this char ch) => ch <= 'ÿ'; public static bool IsLatin1Letter(this char ch) => ch.IsLatin1() && char.IsLetter(ch); public static bool IsLatin1LetterOrUnderscore(this char ch) => ch == '_' || ch.IsLatin1() && char.IsLetter(ch); public static bool IsLatin1LetterOrDigit(this char ch) => ch.IsLatin1() && char.IsLetterOrDigit(ch); public static bool IsLatin1LetterOrDigitOrUnderscore(this char ch) => ch == '_' || ch.IsLatin1() && char.IsLetterOrDigit(ch); } -} \ No newline at end of file +} diff --git a/src/Core/Impl/Extensions/DateTimeExtensions.cs b/src/Core/Impl/Extensions/DateTimeExtensions.cs new file mode 100644 index 000000000..83bb24a0f --- /dev/null +++ b/src/Core/Impl/Extensions/DateTimeExtensions.cs @@ -0,0 +1,25 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; + +namespace Microsoft.Python.Core.Shell { + public static class DateTimeExtensions { + public static int MillisecondsSinceUtc(this DateTime since) { + var diff = DateTime.UtcNow - since; + return (int)diff.TotalMilliseconds; + } + } +} diff --git a/src/Core/Impl/Extensions/DictionaryExtensions.cs b/src/Core/Impl/Extensions/DictionaryExtensions.cs new file mode 100644 index 000000000..6ecde8b6d --- /dev/null +++ b/src/Core/Impl/Extensions/DictionaryExtensions.cs @@ -0,0 +1,37 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.Python.Core { + public class EmptyDictionary: IReadOnlyDictionary { + public static readonly IReadOnlyDictionary Instance = new EmptyDictionary(); + + public TValue this[TKey key] => throw new KeyNotFoundException(); + public IEnumerable Keys => Enumerable.Empty(); + public IEnumerable Values => Enumerable.Empty(); + public int Count => 0; + public bool ContainsKey(TKey key) => false; + public IEnumerator> GetEnumerator() => Enumerable.Empty>().GetEnumerator(); + + public bool TryGetValue(TKey key, out TValue value) { + value = default; + return false; + } + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/EnumerableExtensions.cs b/src/Core/Impl/Extensions/EnumerableExtensions.cs similarity index 94% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/EnumerableExtensions.cs rename to src/Core/Impl/Extensions/EnumerableExtensions.cs index 28a0337d0..f64014627 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/EnumerableExtensions.cs +++ b/src/Core/Impl/Extensions/EnumerableExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,8 +17,8 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - static class EnumerableExtensions { +namespace Microsoft.Python.Core { + public static class EnumerableExtensions { public static bool IsNullOrEmpty(this IEnumerable source) => source == null || !source.Any(); diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/ExceptionExtensions.cs b/src/Core/Impl/Extensions/ExceptionExtensions.cs similarity index 62% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/ExceptionExtensions.cs rename to src/Core/Impl/Extensions/ExceptionExtensions.cs index 801f54ab5..b812e1025 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/ExceptionExtensions.cs +++ b/src/Core/Impl/Extensions/ExceptionExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,16 +16,14 @@ using System; using System.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - static class ExceptionExtensions { +namespace Microsoft.Python.Core { + public static class ExceptionExtensions { /// /// Returns true if an exception should not be handled by logging code. /// - public static bool IsCriticalException(this Exception ex) { - return ex is StackOverflowException || - ex is OutOfMemoryException || - ex is ThreadAbortException || - ex is AccessViolationException; - } + public static bool IsCriticalException(this Exception ex) => ex is StackOverflowException || + ex is OutOfMemoryException || + ex is ThreadAbortException || + ex is AccessViolationException; } } diff --git a/src/Core/Impl/Extensions/IOExtensions.cs b/src/Core/Impl/Extensions/IOExtensions.cs new file mode 100644 index 000000000..cfabc6cc4 --- /dev/null +++ b/src/Core/Impl/Extensions/IOExtensions.cs @@ -0,0 +1,128 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; + +namespace Microsoft.Python.Core.IO { + public static class IOExtensions { + /// + /// Deletes a file, making multiple attempts and suppressing any + /// IO-related errors. + /// + /// File system object. + /// The full path of the file to delete. + /// True if the file was successfully deleted. + public static bool DeleteFileWithRetries(this IFileSystem fs, string path, int maxRetries = 5) { + for (var retries = maxRetries; retries > 0; --retries) { + try { + if (fs.FileExists(path)) { + fs.SetFileAttributes(path, FileAttributes.Normal); + fs.DeleteFile(path); + return true; + } + } catch (UnauthorizedAccessException) { + } catch (IOException) { + } + Thread.Sleep(10); + } + return !fs.FileExists(path); + } + + /// + /// Recursively deletes a directory, making multiple attempts + /// and suppressing any IO-related errors. + /// + /// The full path of the directory to delete. + /// True if the directory was successfully deleted. + public static bool DeleteDirectoryWithRetries(this IFileSystem fs, string path, int maxRetries = 2) { + for (var retries = maxRetries; retries > 0; --retries) { + try { + fs.DeleteDirectory(path, true); + return true; + } catch (UnauthorizedAccessException) { + } catch (IOException) { + } + } + + // Regular delete failed, so let's start removing the contents ourselves + var directories = fs.GetDirectories(path).OrderByDescending(p => p.Length).ToArray(); + foreach (var dir in directories) { + foreach (var f in fs.GetFiles(dir, "*.*", SearchOption.TopDirectoryOnly)) { + fs.DeleteFile(f); + } + + try { + fs.DeleteDirectory(dir, true); + } catch (UnauthorizedAccessException) { + } catch (IOException) { + } + } + + // If we get to this point and the directory still exists, there's + // likely nothing we can do. + return !fs.DirectoryExists(path); + } + + public static FileStream OpenWithRetry(this IFileSystem fs, string file, FileMode mode, FileAccess access, FileShare share) { + // Retry for up to one second + var create = mode != FileMode.Open; + for (var retries = 100; retries > 0; --retries) { + try { + return new FileStream(file, mode, access, share); + } catch (FileNotFoundException) when (!create) { + return null; + } catch (DirectoryNotFoundException) when (!create) { + return null; + } catch (UnauthorizedAccessException) { + Thread.Sleep(10); + } catch (IOException) { + if (create) { + var dir = Path.GetDirectoryName(file); + try { + fs.CreateDirectory(dir); + } catch (IOException) { + // Cannot create directory for DB, so just bail out + return null; + } + } + Thread.Sleep(10); + } catch (NotSupportedException) { + return null; + } + } + return null; + } + + public static void WriteTextWithRetry(this IFileSystem fs, string filePath, string text) { + try { + using (var stream = fs.OpenWithRetry(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) { + if (stream != null) { + var bytes = Encoding.UTF8.GetBytes(text); + stream.Write(bytes, 0, bytes.Length); + return; + } + } + } catch (IOException) { } catch (UnauthorizedAccessException) { } + + try { + fs.DeleteFile(filePath); + } catch (IOException) { } catch (UnauthorizedAccessException) { } + } + } +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/KeyValuePairExtension.cs b/src/Core/Impl/Extensions/KeyValuePairExtension.cs similarity index 84% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/KeyValuePairExtension.cs rename to src/Core/Impl/Extensions/KeyValuePairExtension.cs index eae92239d..a343adfb5 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/KeyValuePairExtension.cs +++ b/src/Core/Impl/Extensions/KeyValuePairExtension.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -16,14 +15,14 @@ using System.Collections.Generic; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core { /// /// Tuple support for KeyValuePair. Remove when project is updated to .net standard 2.1 /// - internal static class KeyValuePairExtension { + public static class KeyValuePairExtension { public static void Deconstruct(this KeyValuePair source, out TKey Key, out TValue Value) { Key = source.Key; Value = source.Value; } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/StringBuilderExtensions.cs b/src/Core/Impl/Extensions/StringBuilderExtensions.cs similarity index 91% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/StringBuilderExtensions.cs rename to src/Core/Impl/Extensions/StringBuilderExtensions.cs index 4e03243af..639fba975 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/StringBuilderExtensions.cs +++ b/src/Core/Impl/Extensions/StringBuilderExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +16,8 @@ using System.Collections.Generic; using System.Text; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class StringBuilderExtensions { +namespace Microsoft.Python.Core { + public static class StringBuilderExtensions { public static StringBuilder TrimEnd(this StringBuilder sb) { while (sb.Length > 0 && char.IsWhiteSpace(sb[sb.Length - 1])) { sb.Length -= 1; diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/StringExtensions.cs b/src/Core/Impl/Extensions/StringExtensions.cs similarity index 89% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/StringExtensions.cs rename to src/Core/Impl/Extensions/StringExtensions.cs index 6c0eceb39..82c383e9d 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/StringExtensions.cs +++ b/src/Core/Impl/Extensions/StringExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,9 +19,10 @@ using System.Globalization; using System.Linq; using System.Text.RegularExpressions; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - static class StringExtensions { +namespace Microsoft.Python.Core { + public static class StringExtensions { #if DEBUG private static readonly Regex SubstitutionRegex = new Regex( @"\{(\d+)", @@ -32,7 +32,7 @@ static class StringExtensions { private static void ValidateFormatString(string str, int argCount) { foreach (Match m in SubstitutionRegex.Matches(str)) { - int index = int.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture); + var index = int.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture); if (index >= argCount) { Debug.Fail(string.Format(CultureInfo.InvariantCulture, "Format string expects more than {0} args.\n\n{1}", argCount, str)); } @@ -72,24 +72,22 @@ public static string FormatInvariant(this string str, params object[] args) { ValidateFormatString(str, args.Length); return string.Format(CultureInfo.InvariantCulture, str, args); } - + public static int IndexOfEnd(this string s, string substring, StringComparison comparisonType = StringComparison.Ordinal) { var i = s.IndexOf(substring, comparisonType); return i < 0 ? i : i + substring.Length; } public static bool IsTrue(this string str) { - bool asBool; return !string.IsNullOrWhiteSpace(str) && ( str.Equals("1", StringComparison.Ordinal) || str.Equals("yes", StringComparison.OrdinalIgnoreCase) || - (bool.TryParse(str, out asBool) && asBool) + (bool.TryParse(str, out var asBool) && asBool) ); } - public static string AsQuotedArguments(this IEnumerable args) { - return string.Join(" ", args.Select(QuoteArgument).Where(a => !string.IsNullOrEmpty(a))); - } + public static string AsQuotedArguments(this IEnumerable args) + => string.Join(" ", args.Select(QuoteArgument).Where(a => !string.IsNullOrEmpty(a))); private static IEnumerable FindUnescapedChar(string s, char c, int start = 0, int end = int.MaxValue) { start -= 1; @@ -134,7 +132,7 @@ public static string QuoteArgument(this string arg) { arg += '\\'; } - foreach (int i in FindUnescapedChar(arg, '"').Reverse().ToArray()) { + foreach (var i in FindUnescapedChar(arg, '"').Reverse().ToArray()) { // We are going to quote with double quotes, so escape any // inline double quotes first arg = arg.Insert(i, "\\"); @@ -143,17 +141,15 @@ public static string QuoteArgument(this string arg) { return "\"{0}\"".FormatInvariant(arg); } - public static bool StartsWithOrdinal(this string s, string prefix, bool ignoreCase = false) { - return s?.StartsWith(prefix, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) ?? false; - } + public static bool StartsWithOrdinal(this string s, string prefix, bool ignoreCase = false) + => s?.StartsWith(prefix, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) ?? false; - public static bool EndsWithOrdinal(this string s, string suffix, bool ignoreCase = false) { - return s?.EndsWith(suffix, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) ?? false; - } + public static bool EndsWithOrdinal(this string s, string suffix, bool ignoreCase = false) + => s?.EndsWith(suffix, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) ?? false; public static bool EndsWithAnyOrdinal(this string s, params string[] values) => s.EndsWithAnyOrdinal(values, false); - + public static bool EndsWithAnyOrdinalIgnoreCase(this string s, params string[] values) => s.EndsWithAnyOrdinal(values, true); @@ -185,9 +181,8 @@ public static bool CharsAreLatin1LetterOrDigitOrUnderscore(this string s, int st return true; } - public static int IndexOfOrdinal(this string s, string value, int startIndex = 0, bool ignoreCase = false) { - return s?.IndexOf(value, startIndex, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) ?? -1; - } + public static int IndexOfOrdinal(this string s, string value, int startIndex = 0, bool ignoreCase = false) + => s?.IndexOf(value, startIndex, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) ?? -1; public static bool EqualsIgnoreCase(this string s, string other) => string.Equals(s, other, StringComparison.OrdinalIgnoreCase); @@ -241,7 +236,7 @@ public static string[] Split(this string s, char separator, int startIndex, int } public static StringSpan Slice(this string s, int start, int length) - => new StringSpan(s, start, length); + => new StringSpan(s, start, length); public static StringSpanSplitSequence SplitIntoSpans(this string s, char separator) => s.SplitIntoSpans(separator, 0, s.Length); diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskCompletionSourceExtensions.cs b/src/Core/Impl/Extensions/TaskCompletionSourceExtensions.cs similarity index 92% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskCompletionSourceExtensions.cs rename to src/Core/Impl/Extensions/TaskCompletionSourceExtensions.cs index 84058abda..7054a2cd0 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskCompletionSourceExtensions.cs +++ b/src/Core/Impl/Extensions/TaskCompletionSourceExtensions.cs @@ -1,5 +1,4 @@ -// Visual Studio Shared Project -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +16,8 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class TaskCompletionSourceExtensions { +namespace Microsoft.Python.Core { + public static class TaskCompletionSourceExtensions { public static CancellationTokenRegistration RegisterForCancellation(this TaskCompletionSource taskCompletionSource, CancellationToken cancellationToken) => taskCompletionSource.RegisterForCancellation(-1, cancellationToken); diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskExtensions.cs b/src/Core/Impl/Extensions/TaskExtensions.cs similarity index 92% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskExtensions.cs rename to src/Core/Impl/Extensions/TaskExtensions.cs index 20f7b6650..ca83cb836 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/TaskExtensions.cs +++ b/src/Core/Impl/Extensions/TaskExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,9 +17,10 @@ using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class TaskExtensions { +namespace Microsoft.Python.Core { + public static class TaskExtensions { public static void SetCompletionResultTo(this Task task, TaskCompletionSourceEx tcs) => task.ContinueWith(SetCompletionResultToContinuation, tcs, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); @@ -90,17 +90,13 @@ private static void DoNotWaitSynchronizationContextContinuation(Task task, objec /// will be raised without being wrapped in a /// . /// - public static void WaitAndUnwrapExceptions(this Task task) { - task.GetAwaiter().GetResult(); - } + public static void WaitAndUnwrapExceptions(this Task task) => task.GetAwaiter().GetResult(); /// /// Waits for a task to complete. If an exception occurs, the exception /// will be raised without being wrapped in a /// . /// - public static T WaitAndUnwrapExceptions(this Task task) { - return task.GetAwaiter().GetResult(); - } + public static T WaitAndUnwrapExceptions(this Task task) => task.GetAwaiter().GetResult(); } } diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/UriExtensions.cs b/src/Core/Impl/Extensions/UriExtensions.cs similarity index 86% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/UriExtensions.cs rename to src/Core/Impl/Extensions/UriExtensions.cs index 2d569978b..60b89b785 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/UriExtensions.cs +++ b/src/Core/Impl/Extensions/UriExtensions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,17 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Net; using System.Runtime.InteropServices; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class UriExtensions { +namespace Microsoft.Python.Core { + public static class UriExtensions { public static string ToAbsolutePath(this Uri uri) { if(IsWindows()) { // VS Code always sends /-based paths with leading / such as diff --git a/src/Core/Impl/IO/DirectoryInfoProxy.cs b/src/Core/Impl/IO/DirectoryInfoProxy.cs new file mode 100644 index 000000000..1295804bf --- /dev/null +++ b/src/Core/Impl/IO/DirectoryInfoProxy.cs @@ -0,0 +1,48 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Microsoft.Python.Core.IO { + public sealed class DirectoryInfoProxy : IDirectoryInfo { + private readonly DirectoryInfo _directoryInfo; + + public DirectoryInfoProxy(string directoryPath) { + _directoryInfo = new DirectoryInfo(directoryPath); + } + + public DirectoryInfoProxy(DirectoryInfo directoryInfo) { + _directoryInfo = directoryInfo; + } + + public bool Exists => _directoryInfo.Exists; + public string FullName => _directoryInfo.FullName; + public FileAttributes Attributes => _directoryInfo.Attributes; + public IDirectoryInfo Parent => _directoryInfo.Parent != null ? new DirectoryInfoProxy(_directoryInfo.Parent) : null; + + public void Delete() => _directoryInfo.Delete(); + + public IEnumerable EnumerateFileSystemInfos() => _directoryInfo + .EnumerateFileSystemInfos() + .Select(CreateFileSystemInfoProxy); + + private static IFileSystemInfo CreateFileSystemInfoProxy(FileSystemInfo fileSystemInfo) + => fileSystemInfo is DirectoryInfo directoryInfo + ? (IFileSystemInfo)new DirectoryInfoProxy(directoryInfo) + : new FileInfoProxy((FileInfo)fileSystemInfo); + } +} diff --git a/src/Core/Impl/IO/FileInfoProxy.cs b/src/Core/Impl/IO/FileInfoProxy.cs new file mode 100644 index 000000000..c343e327c --- /dev/null +++ b/src/Core/Impl/IO/FileInfoProxy.cs @@ -0,0 +1,35 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; + +namespace Microsoft.Python.Core.IO { + public sealed class FileInfoProxy : IFileInfo { + private readonly FileInfo _fileInfo; + + public FileInfoProxy(FileInfo fileInfo) { + _fileInfo = fileInfo; + } + + public bool Exists => _fileInfo.Exists; + public string FullName => _fileInfo.FullName; + public FileAttributes Attributes => _fileInfo.Attributes; + public IDirectoryInfo Directory => _fileInfo.Directory != null ? new DirectoryInfoProxy(_fileInfo.Directory) : null; + + public StreamWriter CreateText() => _fileInfo.CreateText(); + + public void Delete() => _fileInfo.Delete(); + } +} diff --git a/src/Core/Impl/IO/FileSystem.cs b/src/Core/Impl/IO/FileSystem.cs new file mode 100644 index 000000000..ad865dfaf --- /dev/null +++ b/src/Core/Impl/IO/FileSystem.cs @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using Microsoft.Python.Core.OS; + +namespace Microsoft.Python.Core.IO { + public sealed class FileSystem : IFileSystem { + private readonly IOSPlatform _os; + + public FileSystem(IOSPlatform os) { + _os = os; + } + + public IFileSystemWatcher CreateFileSystemWatcher(string path, string filter) => new FileSystemWatcherProxy(path, filter); + public IDirectoryInfo GetDirectoryInfo(string directoryPath) => new DirectoryInfoProxy(directoryPath); + public bool FileExists(string path) => File.Exists(path); + + public long FileSize(string path) { + var fileInfo = new FileInfo(path); + return fileInfo.Length; + } + + public string ReadAllText(string path) => File.ReadAllText(path); + public void WriteAllText(string path, string content) => File.WriteAllText(path, content); + public IEnumerable FileReadAllLines(string path) => File.ReadLines(path); + public void FileWriteAllLines(string path, IEnumerable contents) => File.WriteAllLines(path, contents); + public byte[] FileReadAllBytes(string path) => File.ReadAllBytes(path); + public void FileWriteAllBytes(string path, byte[] bytes) => File.WriteAllBytes(path, bytes); + public Stream CreateFile(string path) => File.Create(path); + public Stream FileOpen(string path, FileMode mode) => File.Open(path, mode); + public bool DirectoryExists(string path) => Directory.Exists(path); + public FileAttributes GetFileAttributes(string path) => File.GetAttributes(path); + public void SetFileAttributes(string fullPath, FileAttributes attributes) => File.SetAttributes(fullPath, attributes); + public DateTime GetLastWriteTimeUtc(string path) => File.GetLastWriteTimeUtc(path); + + public Version GetFileVersion(string path) { + var fvi = FileVersionInfo.GetVersionInfo(path); + return new Version(fvi.FileMajorPart, fvi.FileMinorPart, fvi.FileBuildPart, fvi.FilePrivatePart); + } + + public void DeleteFile(string path) => File.Delete(path); + public void DeleteDirectory(string path, bool recursive) => Directory.Delete(path, recursive); + public string[] GetFileSystemEntries(string path, string searchPattern, SearchOption options) => Directory.GetFileSystemEntries(path, searchPattern, options); + public void CreateDirectory(string path) => Directory.CreateDirectory(path); + public string[] GetFiles(string path) => Directory.GetFiles(path); + public string[] GetFiles(string path, string pattern) => Directory.GetFiles(path, pattern); + public string[] GetFiles(string path, string pattern, SearchOption option) => Directory.GetFiles(path, pattern, option); + public string[] GetDirectories(string path) => Directory.GetDirectories(path); + + public bool IsPathUnderRoot(string root, string path) => Path.GetFullPath(path).StartsWith(root, StringComparison); + public StringComparison StringComparison => _os.IsLinux ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; + } +} diff --git a/src/Core/Impl/IO/FileSystemWatcherProxy.cs b/src/Core/Impl/IO/FileSystemWatcherProxy.cs new file mode 100644 index 000000000..886567270 --- /dev/null +++ b/src/Core/Impl/IO/FileSystemWatcherProxy.cs @@ -0,0 +1,73 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; + +namespace Microsoft.Python.Core.IO { + public sealed class FileSystemWatcherProxy : IFileSystemWatcher { + private readonly FileSystemWatcher _fileSystemWatcher; + + public FileSystemWatcherProxy(string path, string filter) { + _fileSystemWatcher = new FileSystemWatcher(path, filter); + } + + public void Dispose() => _fileSystemWatcher.Dispose(); + + public bool EnableRaisingEvents { + get => _fileSystemWatcher.EnableRaisingEvents; + set => _fileSystemWatcher.EnableRaisingEvents = value; + } + + public bool IncludeSubdirectories { + get => _fileSystemWatcher.IncludeSubdirectories; + set => _fileSystemWatcher.IncludeSubdirectories = value; + } + + public int InternalBufferSize { + get => _fileSystemWatcher.InternalBufferSize; + set => _fileSystemWatcher.InternalBufferSize = value; + } + + public NotifyFilters NotifyFilter { + get => _fileSystemWatcher.NotifyFilter; + set => _fileSystemWatcher.NotifyFilter = value; + } + + public event FileSystemEventHandler Changed { + add => _fileSystemWatcher.Changed += value; + remove => _fileSystemWatcher.Changed -= value; + } + + public event FileSystemEventHandler Created { + add => _fileSystemWatcher.Created += value; + remove => _fileSystemWatcher.Created -= value; + } + + public event FileSystemEventHandler Deleted { + add => _fileSystemWatcher.Deleted += value; + remove => _fileSystemWatcher.Deleted -= value; + } + + public event RenamedEventHandler Renamed { + add => _fileSystemWatcher.Renamed += value; + remove => _fileSystemWatcher.Renamed -= value; + } + + public event ErrorEventHandler Error { + add => _fileSystemWatcher.Error += value; + remove => _fileSystemWatcher.Error -= value; + } + } +} diff --git a/src/Core/Impl/IO/IDirectoryInfo.cs b/src/Core/Impl/IO/IDirectoryInfo.cs new file mode 100644 index 000000000..bb97fb3f2 --- /dev/null +++ b/src/Core/Impl/IO/IDirectoryInfo.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; + +namespace Microsoft.Python.Core.IO { + public interface IDirectoryInfo : IFileSystemInfo { + IDirectoryInfo Parent { get; } + IEnumerable EnumerateFileSystemInfos(); + } +} diff --git a/src/Core/Impl/IO/IFileInfo.cs b/src/Core/Impl/IO/IFileInfo.cs new file mode 100644 index 000000000..290aaf824 --- /dev/null +++ b/src/Core/Impl/IO/IFileInfo.cs @@ -0,0 +1,23 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; + +namespace Microsoft.Python.Core.IO { + public interface IFileInfo : IFileSystemInfo { + IDirectoryInfo Directory { get; } + StreamWriter CreateText(); + } +} diff --git a/src/Core/Impl/IO/IFileSystem.cs b/src/Core/Impl/IO/IFileSystem.cs new file mode 100644 index 000000000..ecdb55065 --- /dev/null +++ b/src/Core/Impl/IO/IFileSystem.cs @@ -0,0 +1,59 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.IO; + +namespace Microsoft.Python.Core.IO { + public interface IFileSystem { + IFileSystemWatcher CreateFileSystemWatcher(string directory, string filter); + IDirectoryInfo GetDirectoryInfo(string directoryPath); + bool FileExists(string fullPath); + bool DirectoryExists(string fullPath); + + long FileSize(string path); + + FileAttributes GetFileAttributes(string fullPath); + void SetFileAttributes(string fullPath, FileAttributes attributes); + DateTime GetLastWriteTimeUtc(string fullPath); + + string ReadAllText(string path); + void WriteAllText(string path, string content); + + IEnumerable FileReadAllLines(string path); + void FileWriteAllLines(string path, IEnumerable contents); + + byte[] FileReadAllBytes(string path); + void FileWriteAllBytes(string path, byte[] bytes); + + Stream CreateFile(string path); + Stream FileOpen(string path, FileMode mode); + + Version GetFileVersion(string path); + void DeleteFile(string path); + void DeleteDirectory(string path, bool recursive); + string[] GetFileSystemEntries(string path, string searchPattern, SearchOption options); + void CreateDirectory(string path); + + string[] GetFiles(string path); + string[] GetFiles(string path, string pattern); + string[] GetFiles(string path, string pattern, SearchOption option); + string[] GetDirectories(string path); + + bool IsPathUnderRoot(string root, string path); + StringComparison StringComparison { get; } + } +} diff --git a/src/Core/Impl/IO/IFileSystemInfo.cs b/src/Core/Impl/IO/IFileSystemInfo.cs new file mode 100644 index 000000000..bde128d26 --- /dev/null +++ b/src/Core/Impl/IO/IFileSystemInfo.cs @@ -0,0 +1,25 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.IO; + +namespace Microsoft.Python.Core.IO { + public interface IFileSystemInfo { + bool Exists { get; } + string FullName { get; } + FileAttributes Attributes { get; } + void Delete(); + } +} diff --git a/src/Core/Impl/IO/IFileSystemWatcher.cs b/src/Core/Impl/IO/IFileSystemWatcher.cs new file mode 100644 index 000000000..e20f647b4 --- /dev/null +++ b/src/Core/Impl/IO/IFileSystemWatcher.cs @@ -0,0 +1,32 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.IO; + +namespace Microsoft.Python.Core.IO { + public interface IFileSystemWatcher : IDisposable { + bool EnableRaisingEvents { get; set; } + bool IncludeSubdirectories { get; set; } + int InternalBufferSize { get; set; } + NotifyFilters NotifyFilter { get; set; } + + event FileSystemEventHandler Changed; + event FileSystemEventHandler Created; + event FileSystemEventHandler Deleted; + event RenamedEventHandler Renamed; + event ErrorEventHandler Error; + } +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/InstallPath.cs b/src/Core/Impl/IO/InstallPath.cs similarity index 81% rename from src/Analysis/Engine/Impl/Infrastructure/InstallPath.cs rename to src/Core/Impl/IO/InstallPath.cs index d10afcc1a..cf335313c 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/InstallPath.cs +++ b/src/Core/Impl/IO/InstallPath.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,15 +8,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.IO; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - static class InstallPath { +namespace Microsoft.Python.Core.IO { + public static class InstallPath { public static bool TryGetFile(string filename, out string fullpath) { fullpath = Path.Combine( Path.GetDirectoryName(typeof(InstallPath).Assembly.Location), diff --git a/src/Analysis/Engine/Impl/Infrastructure/PathEqualityComparer.cs b/src/Core/Impl/IO/PathEqualityComparer.cs similarity index 91% rename from src/Analysis/Engine/Impl/Infrastructure/PathEqualityComparer.cs rename to src/Core/Impl/IO/PathEqualityComparer.cs index 203073324..db173fe19 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/PathEqualityComparer.cs +++ b/src/Core/Impl/IO/PathEqualityComparer.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,21 +20,19 @@ using System.Runtime.InteropServices; using System.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - class PathEqualityComparer : IEqualityComparer { +namespace Microsoft.Python.Core.IO { + public sealed class PathEqualityComparer : IEqualityComparer { public static readonly PathEqualityComparer Instance = new PathEqualityComparer( RuntimeInformation.IsOSPlatform(OSPlatform.Linux), Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar ); private static readonly char[] InvalidPathChars = GetInvalidPathChars(); - private static char[] GetInvalidPathChars() { - return Path.GetInvalidPathChars().Concat(new[] { '*', '?' }).ToArray(); - } + private static char[] GetInvalidPathChars() => Path.GetInvalidPathChars().Concat(new[] { '*', '?' }).ToArray(); // This is just a small cache to deal with the same keys being used // frequently in a loop. - internal class CacheItem { + public class CacheItem { public string CompareKey; public long Accessed; } @@ -49,7 +46,7 @@ internal class CacheItem { private readonly char[] _directorySeparators; private readonly StringComparer _stringComparer; - internal PathEqualityComparer(bool isCaseSensitivePath, char directorySeparator, char altDirectorySeparator = '\0') { + public PathEqualityComparer(bool isCaseSensitivePath, char directorySeparator, char altDirectorySeparator = '\0') { _isCaseSensitivePath = isCaseSensitivePath; _directorySeparator = directorySeparator; _altDirectorySeparator = altDirectorySeparator; @@ -63,7 +60,7 @@ internal PathEqualityComparer(bool isCaseSensitivePath, char directorySeparator, _stringComparer = _isCaseSensitivePath ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase; } - internal string GetCompareKeyUncached(string path) { + public string GetCompareKeyUncached(string path) { if (string.IsNullOrEmpty(path)) { return path; } @@ -157,7 +154,7 @@ internal CacheItem GetOrCreateCacheItem(string key, out bool created) { } private string GetCompareKey(string path) { - var item = GetOrCreateCacheItem(path, out bool created); + var item = GetOrCreateCacheItem(path, out var created); string result; lock (item) { diff --git a/src/Analysis/Engine/Impl/Infrastructure/PathUtils.cs b/src/Core/Impl/IO/PathUtils.cs similarity index 92% rename from src/Analysis/Engine/Impl/Infrastructure/PathUtils.cs rename to src/Core/Impl/IO/PathUtils.cs index 1f4f747ba..a9513ee59 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/PathUtils.cs +++ b/src/Core/Impl/IO/PathUtils.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,8 +20,8 @@ using System.Runtime.InteropServices; using System.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - static class PathUtils { +namespace Microsoft.Python.Core.IO { + public static class PathUtils { private static readonly bool IsWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); private static readonly char[] InvalidFileNameChars; @@ -31,21 +30,22 @@ static PathUtils() { Array.Sort(InvalidFileNameChars); } - internal static readonly char[] DirectorySeparators = { + public static readonly char[] DirectorySeparators = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; - public static bool IsValidWindowsDriveChar(char value) => (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z'); + public static bool IsValidWindowsDriveChar(char value) + => (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z'); - public static bool IsValidFileNameCharacter(char character) => Array.BinarySearch(InvalidFileNameChars, character) < 0; + public static bool IsValidFileNameCharacter(char character) + => Array.BinarySearch(InvalidFileNameChars, character) < 0; /// /// Returns true if the path has a directory separator character at the end. /// - public static bool HasEndSeparator(string path) { - return !string.IsNullOrEmpty(path) && DirectorySeparators.Contains(path[path.Length - 1]); - } + public static bool HasEndSeparator(string path) + => !string.IsNullOrEmpty(path) && DirectorySeparators.Contains(path[path.Length - 1]); /// /// Removes up to one directory separator character from the end of path. @@ -56,15 +56,15 @@ public static string TrimEndSeparator(string path) { // The slash at the end of a drive specifier is not actually // a separator. return path; - } else if (path.Length > 3 && path[path.Length - 2] == path[path.Length - 1] && path[path.Length - 3] == ':') { + } + if (path.Length > 3 && path[path.Length - 2] == path[path.Length - 1] && path[path.Length - 3] == ':') { // The double slash at the end of a schema is not actually a // separator. return path; } return path.Remove(path.Length - 1); - } else { - return path; } + return path; } /// @@ -73,11 +73,11 @@ public static string TrimEndSeparator(string path) { public static string EnsureEndSeparator(string path) { if (string.IsNullOrEmpty(path)) { return string.Empty; - } else if (!HasEndSeparator(path)) { + } + if (!HasEndSeparator(path)) { return path + Path.DirectorySeparatorChar; - } else { - return path; } + return path; } /// @@ -130,12 +130,12 @@ public static string FindFile( dirQueue.Enqueue(new KeyValuePair(root, 0)); while (dirQueue.Any()) { var dirDepth = dirQueue.Dequeue(); - string dir = dirDepth.Key; + var dir = dirDepth.Key; var result = EnumerateFiles(dir, file, recurse: false).FirstOrDefault(); if (result != null) { return result; } - int depth = dirDepth.Value; + var depth = dirDepth.Value; if (depth < depthLimit) { foreach (var subDir in EnumerateDirectories(dir, recurse: false)) { dirQueue.Enqueue(new KeyValuePair(subDir, depth + 1)); @@ -212,7 +212,7 @@ public static string GetParent(string path) { return string.Empty; } - int last = path.Length - 1; + var last = path.Length - 1; if (DirectorySeparators.Contains(path[last])) { last -= 1; } @@ -239,7 +239,7 @@ public static string GetFileName(string filePath) { return string.Empty; } - int i = filePath.LastIndexOfAny(DirectorySeparators); + var i = filePath.LastIndexOfAny(DirectorySeparators); return filePath.Substring(i + 1); } @@ -315,7 +315,7 @@ public static IEnumerable EnumerateFiles( /// The full path of the file to delete. /// True if the file was successfully deleted. public static bool DeleteFile(string path) { - for (int retries = 5; retries > 0; --retries) { + for (var retries = 5; retries > 0; --retries) { try { if (File.Exists(path)) { File.SetAttributes(path, FileAttributes.Normal); @@ -337,7 +337,7 @@ public static bool DeleteFile(string path) { /// The full path of the directory to delete. /// True if the directory was successfully deleted. public static bool DeleteDirectory(string path) { - for (int retries = 2; retries > 0; --retries) { + for (var retries = 2; retries > 0; --retries) { try { Directory.Delete(path, true); return true; @@ -367,8 +367,8 @@ public static bool DeleteDirectory(string path) { public static FileStream OpenWithRetry(string file, FileMode mode, FileAccess access, FileShare share) { // Retry for up to one second - bool create = mode != FileMode.Open; - for (int retries = 100; retries > 0; --retries) { + var create = mode != FileMode.Open; + for (var retries = 100; retries > 0; --retries) { try { return new FileStream(file, mode, access, share); } catch (FileNotFoundException) when (!create) { @@ -469,8 +469,8 @@ public static string NormalizePath(string path) { } if (parts[i] == "..") { - bool found = false; - for (int j = i - 1; j >= 0; --j) { + var found = false; + for (var j = i - 1; j >= 0; --j) { if (!string.IsNullOrEmpty(parts[j])) { parts[i] = null; parts[j] = null; diff --git a/src/Analysis/Engine/Impl/LanguageServer/IServer.cs b/src/Core/Impl/Idle/IIdleTimeService.cs similarity index 54% rename from src/Analysis/Engine/Impl/LanguageServer/IServer.cs rename to src/Core/Impl/Idle/IIdleTimeService.cs index 607c67f38..447241658 100644 --- a/src/Analysis/Engine/Impl/LanguageServer/IServer.cs +++ b/src/Core/Impl/Idle/IIdleTimeService.cs @@ -9,22 +9,24 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Analysis.LanguageServer { - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public interface IServer { - void LogMessage(MessageType type, string message); - } - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public interface IServer2 : IServer { - } - [Obsolete("Implement Microsoft.Python.LanguageServer.Extensions.ILanguageServerExtension model")] - public interface IServer3 : IServer2 { +namespace Microsoft.Python.Core.Idle { + public interface IIdleTimeService { + /// + /// Fires when host application enters idle state. + /// + event EventHandler Idle; + + /// + /// Fires when application is closing + /// + event EventHandler Closing; } } + diff --git a/src/LanguageServer/Impl/Definitions/ILogger.cs b/src/Core/Impl/Idle/IIdleTimeTracker.cs similarity index 79% rename from src/LanguageServer/Impl/Definitions/ILogger.cs rename to src/Core/Impl/Idle/IIdleTimeTracker.cs index 6ef60820f..820ae93e8 100644 --- a/src/LanguageServer/Impl/Definitions/ILogger.cs +++ b/src/Core/Impl/Idle/IIdleTimeTracker.cs @@ -9,15 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; - -namespace Microsoft.Python.LanguageServer { - public interface ILogger { - void TraceMessage(IFormattable message); +namespace Microsoft.Python.Core.Idle { + public interface IIdleTimeTracker { + void NotifyUserActivity(); } } diff --git a/src/Core/Impl/Idle/IdleTimeAction.cs b/src/Core/Impl/Idle/IdleTimeAction.cs new file mode 100644 index 000000000..64a159d8e --- /dev/null +++ b/src/Core/Impl/Idle/IdleTimeAction.cs @@ -0,0 +1,92 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Concurrent; +using Microsoft.Python.Core.Shell; + +namespace Microsoft.Python.Core.Idle { + /// + /// Action that should be executed on next idle after certain number of milliseconds + /// + public class IdleTimeAction { + private static readonly ConcurrentDictionary _idleActions + = new ConcurrentDictionary(); + + private readonly Action _action; + private readonly int _delay; + private readonly IIdleTimeService _idleTime; + private readonly object _tag; + private volatile bool _connectedToIdle; + private DateTime _idleConnectTime; + + /// + /// Create delayed idle time action + /// + /// Action to execute on idle + /// Minimum number of milliseconds to wait before executing the action + /// Object that uniquely identifies the action. Typically creator object. + /// Idle time service + public static void Create(Action action, int delay, object tag, IIdleTimeService idleTime) { + if (!_idleActions.TryGetValue(tag, out var existingAction)) { + existingAction = new IdleTimeAction(action, delay, tag, idleTime); + _idleActions[tag] = existingAction; + } + } + + /// + /// Cancels idle time action. Has no effect if action has already been executed. + /// + /// Tag identifying the action to cancel + public static void Cancel(object tag) { + if (_idleActions.TryRemove(tag, out var idleTimeAction)) { + idleTimeAction.DisconnectFromIdle(); + } + } + + private IdleTimeAction(Action action, int delay, object tag, IIdleTimeService idleTime) { + _action = action; + _delay = delay; + _tag = tag; + _idleTime = idleTime; + + ConnectToIdle(); + } + + void OnIdle(object sender, EventArgs e) { + if (_idleConnectTime.MillisecondsSinceUtc() > _delay) { + DisconnectFromIdle(); + _action(); + _idleActions.TryRemove(_tag, out _); + } + } + + void ConnectToIdle() { + if (!_connectedToIdle) { + _idleTime.Idle += OnIdle; + + _idleConnectTime = DateTime.UtcNow; + _connectedToIdle = true; + } + } + + void DisconnectFromIdle() { + if (_connectedToIdle) { + _idleTime.Idle -= OnIdle; + _connectedToIdle = false; + } + } + } +} diff --git a/src/Core/Impl/Idle/IdleTimeTaskQueue.cs b/src/Core/Impl/Idle/IdleTimeTaskQueue.cs new file mode 100644 index 000000000..5caef1a85 --- /dev/null +++ b/src/Core/Impl/Idle/IdleTimeTaskQueue.cs @@ -0,0 +1,160 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.Python.Core.Shell; + +namespace Microsoft.Python.Core.Idle { + /// + /// A queue of asynchronous tasks that are processed in the order they were added. + /// As opposed to the thread pool tasks only start on idle and queued task may be + /// canceled if needed. There may be one or more tasks running in parallel depending + /// on number of CPUs available. + /// + public sealed class IdleTimeTaskQueue { + class ActionEntry { + public Func Action { get; } + public Action OnCompleted { get; } + public Action OnCanceled { get; } + public object Data { get; } + public object Tag { get; } + + public ActionEntry(Func action, Action onCompleted, Action onCanceled, object data, object tag) { + Action = action; + OnCompleted = onCompleted; + OnCanceled = onCanceled; + Data = data; + Tag = tag; + } + } + + private readonly IServiceContainer _services; + private readonly IIdleTimeService _idleTime; + private readonly List _actionQueue = new List(); + private readonly Task[] _runningTasks; + private readonly object _lock = new object(); + private bool _connectedToIdle; + + public IdleTimeTaskQueue(IServiceContainer services) { + _services = services; + _idleTime = services.GetService(); + + var taskCount = Math.Max(Environment.ProcessorCount / 2, 1); + _runningTasks = new Task[taskCount]; + } + + /// + /// Add task to the idle time queue. Tasks are executed asynchronously + /// in the order they were added. On next idle time if thread is available + /// it will take task from the head of the queue and execute it. + /// There may be one or more tasks running in parallel depending on + /// the number of CPUs available. + /// + public void Enqueue(Func taskAction, Action onCompleted, Action onCanceled, object p, object tag) { + lock (_lock) { + _actionQueue.Add(new ActionEntry(taskAction, onCompleted, onCanceled, p, tag)); + ConnectToIdle(); + } + } + + /// + /// Add task to the idle time queue. Tasks are executed asynchronously in the order they were added. + /// On next idle time if thread is available it will take task from the head of the queue and execute it. + /// There may be one or more tasks running in parallel depending on number of CPUs available. + /// + public void Enqueue(Func taskAction, Action callbackAction, object data, object tag) + => Enqueue(taskAction, callbackAction, null, data, tag); + + /// + /// Removes tasks associated with a give callback + /// + /// Object uniquely identifying the task + public void Cancel(object tag) { + ActionEntry e = null; + + lock (_lock) { + if (_actionQueue.Count > 0) { + for (var i = _actionQueue.Count - 1; i >= 0; i--) { + if (_actionQueue[i].Tag == tag) { + e = _actionQueue[i]; + _actionQueue.RemoveAt(i); + } + } + + if (_actionQueue.Count == 0) { + DisconnectFromIdle(); + } + } + } + + e?.OnCanceled?.Invoke(); + } + + public void IncreasePriority(object tag) { + lock (_lock) { + for (var i = 0; i < _actionQueue.Count; i++) { + var task = _actionQueue[i]; + + if (task.Tag == tag) { + _actionQueue.RemoveAt(i); + _actionQueue.Insert(0, task); + break; + } + } + } + } + + private void ConnectToIdle() { + if (!_connectedToIdle) { + _connectedToIdle = true; + _idleTime.Idle += OnIdle; + } + } + + private void DisconnectFromIdle() { + if (_connectedToIdle) { + _connectedToIdle = false; + _idleTime.Idle -= OnIdle; + } + } + + private void OnIdle(object sender, EventArgs _) { + lock (_lock) { + for (var i = 0; i < _actionQueue.Count; i++) { + var index = GetAvailableWorkerTask(); + if (index < 0) { + return; // all worker threads are busy + } + + var e = _actionQueue[0]; + _actionQueue.RemoveAt(0); + + _runningTasks[index] = Task.Run(() => e.Action(e.Data)) + .ContinueWith(t => { + if (t.IsCompleted) { + e.OnCompleted(t.Result); + } else if (t.IsCanceled) { + e.OnCanceled?.Invoke(); + } + }); + + if (_actionQueue.Count == 0) { + DisconnectFromIdle(); + } + } + } + } + + private int GetAvailableWorkerTask() { + for (var i = 0; i < _runningTasks.Length; i++) { + var t = _runningTasks[i]; + if (t == null || t.IsCompleted || t.IsCanceled || t.IsFaulted) { + return i; + } + } + return -1; + } + } +} diff --git a/src/Core/Impl/Logging/ILogger.cs b/src/Core/Impl/Logging/ILogger.cs new file mode 100644 index 000000000..b0fedf093 --- /dev/null +++ b/src/Core/Impl/Logging/ILogger.cs @@ -0,0 +1,31 @@ +// Python Tools for Visual Studio +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Diagnostics; + +namespace Microsoft.Python.Core.Logging { + public interface ILogger { + /// + /// Sets minimal log level for output to appear in the host application. + /// + TraceEventType LogLevel { get; set; } + + void Log(TraceEventType eventType, IFormattable message); + void Log(TraceEventType eventType, string message); + void Log(TraceEventType eventType, params object[] p); + } +} diff --git a/src/Core/Impl/Microsoft.Python.Core.csproj b/src/Core/Impl/Microsoft.Python.Core.csproj new file mode 100644 index 000000000..4b3da4419 --- /dev/null +++ b/src/Core/Impl/Microsoft.Python.Core.csproj @@ -0,0 +1,42 @@ + + + netstandard2.0 + Microsoft.Python.Core + Microsoft.Python.Core + + + + 1701;1702;$(NoWarn) + 7.2 + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + diff --git a/src/Core/Impl/OS/IOSPlatform.cs b/src/Core/Impl/OS/IOSPlatform.cs new file mode 100644 index 000000000..0d14273ff --- /dev/null +++ b/src/Core/Impl/OS/IOSPlatform.cs @@ -0,0 +1,22 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Core.OS { + public interface IOSPlatform { + bool IsWindows { get; } + bool IsMac { get; } + bool IsLinux { get; } + } +} diff --git a/src/Core/Impl/OS/OSPlatform.cs b/src/Core/Impl/OS/OSPlatform.cs new file mode 100644 index 000000000..c682ef5fb --- /dev/null +++ b/src/Core/Impl/OS/OSPlatform.cs @@ -0,0 +1,24 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Runtime.InteropServices; + +namespace Microsoft.Python.Core.OS { + public sealed class OSPlatform : IOSPlatform { + public bool IsWindows => RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); + public bool IsMac => RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX); + public bool IsLinux => RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); + } +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/ProcessHelper.cs b/src/Core/Impl/OS/ProcessHelper.cs similarity index 81% rename from src/Analysis/Engine/Impl/Infrastructure/ProcessHelper.cs rename to src/Core/Impl/OS/ProcessHelper.cs index 6f469649c..75c25dbfc 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/ProcessHelper.cs +++ b/src/Core/Impl/OS/ProcessHelper.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,9 +20,8 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - sealed class ProcessHelper : IDisposable { - private readonly ProcessStartInfo _psi; +namespace Microsoft.Python.Core.OS { + public sealed class ProcessHelper : IDisposable { private Process _process; private int? _exitCode; private readonly SemaphoreSlim _seenNullOutput, _seenNullError; @@ -33,25 +31,26 @@ public ProcessHelper(string filename, IEnumerable arguments, string work throw new FileNotFoundException("Could not launch process", filename); } - _psi = new ProcessStartInfo( + StartInfo = new ProcessStartInfo( filename, arguments.AsQuotedArguments() - ); - _psi.WorkingDirectory = workingDir ?? Path.GetDirectoryName(filename); - _psi.UseShellExecute = false; - _psi.ErrorDialog = false; - _psi.CreateNoWindow = true; - _psi.RedirectStandardInput = true; - _psi.RedirectStandardOutput = true; - _psi.RedirectStandardError = true; + ) { + WorkingDirectory = workingDir ?? Path.GetDirectoryName(filename), + UseShellExecute = false, + ErrorDialog = false, + CreateNoWindow = true, + RedirectStandardInput = true, + RedirectStandardOutput = true, + RedirectStandardError = true + }; _seenNullOutput = new SemaphoreSlim(1); _seenNullError = new SemaphoreSlim(1); } - public ProcessStartInfo StartInfo => _psi; - public string FileName => _psi.FileName; - public string Arguments => _psi.Arguments; + public ProcessStartInfo StartInfo { get; } + public string FileName => StartInfo.FileName; + public string Arguments => StartInfo.Arguments; public Action OnOutputLine { get; set; } public Action OnErrorLine { get; set; } @@ -67,7 +66,7 @@ public void Start() { _seenNullError.Wait(0); var p = new Process { - StartInfo = _psi + StartInfo = StartInfo }; p.OutputDataReceived += Process_OutputDataReceived; @@ -157,13 +156,11 @@ public async Task WaitAsync(CancellationToken cancellationToken) { throw new InvalidOperationException("Process was not started"); } - if (!_process.HasExited) { - await _seenNullOutput.WaitAsync(cancellationToken).ConfigureAwait(false); - await _seenNullError.WaitAsync(cancellationToken).ConfigureAwait(false); - } + await _seenNullOutput.WaitAsync(cancellationToken).ConfigureAwait(false); + await _seenNullError.WaitAsync(cancellationToken).ConfigureAwait(false); for (var i = 0; i < 5 && !_process.HasExited; i++) { - await Task.Delay(100); + await Task.Delay(100, cancellationToken); } Debug.Assert(_process.HasExited, "Process still has not exited."); diff --git a/src/Core/Impl/Properties/AssemblyInfo.cs b/src/Core/Impl/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..c4214cb62 --- /dev/null +++ b/src/Core/Impl/Properties/AssemblyInfo.cs @@ -0,0 +1,18 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.Python.Core.Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/src/Core/Impl/Resources.Designer.cs b/src/Core/Impl/Resources.Designer.cs new file mode 100644 index 000000000..3c5eeb9cb --- /dev/null +++ b/src/Core/Impl/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.PythonTools.Core { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.PythonTools.Core.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/Core/Impl/Resources.resx b/src/Core/Impl/Resources.resx new file mode 100644 index 000000000..4fdb1b6af --- /dev/null +++ b/src/Core/Impl/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/LanguageServer/Impl/Services/IdleTimeTracker.cs b/src/Core/Impl/Services/IdleTimeService.cs similarity index 68% rename from src/LanguageServer/Impl/Services/IdleTimeTracker.cs rename to src/Core/Impl/Services/IdleTimeService.cs index 6287b1b1b..fa7d1431f 100644 --- a/src/LanguageServer/Impl/Services/IdleTimeTracker.cs +++ b/src/Core/Impl/Services/IdleTimeService.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,24 +8,21 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Threading; +using Microsoft.Python.Core.Idle; -namespace Microsoft.Python.LanguageServer.Services { - sealed class IdleTimeTracker : IDisposable { - private readonly int _delay; - private readonly Action _action; +namespace Microsoft.Python.Core.Services { + public sealed class IdleTimeService : IIdleTimeService, IIdleTimeTracker, IDisposable { private Timer _timer; private DateTime _lastActivityTime; - public IdleTimeTracker(int msDelay, Action action) { - _delay = msDelay; - _action = action; + public IdleTimeService() { _timer = new Timer(OnTimer, this, 50, 50); NotifyUserActivity(); } @@ -36,12 +32,16 @@ public IdleTimeTracker(int msDelay, Action action) { public void Dispose() { _timer?.Dispose(); _timer = null; + Closing?.Invoke(this, EventArgs.Empty); } private void OnTimer(object state) { - if ((DateTime.Now - _lastActivityTime).TotalMilliseconds >= _delay && _timer != null) { - _action(); + if ((DateTime.Now - _lastActivityTime).TotalMilliseconds >= 100 && _timer != null) { + Idle?.Invoke(this, EventArgs.Empty); } } + + public event EventHandler Idle; + public event EventHandler Closing; } } diff --git a/src/LanguageServer/Impl/Services/ServiceManager.cs b/src/Core/Impl/Services/ServiceManager.cs similarity index 84% rename from src/LanguageServer/Impl/Services/ServiceManager.cs rename to src/Core/Impl/Services/ServiceManager.cs index 3a83f23d4..5ae5af006 100644 --- a/src/LanguageServer/Impl/Services/ServiceManager.cs +++ b/src/Core/Impl/Services/ServiceManager.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,12 +20,13 @@ using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; -using Microsoft.Python.LanguageServer; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Core.Disposables; +using Microsoft.Python.Core.Shell; using static System.FormattableString; -namespace Microsoft.PythonTools.LanguageServer.Services { - public class ServiceManager : IServiceManager { +namespace Microsoft.Python.Core.Services { + public sealed class ServiceManager : IServiceManager { private readonly DisposeToken _disposeToken = DisposeToken.Create(); private readonly ConcurrentDictionary _s = new ConcurrentDictionary(); @@ -38,7 +39,7 @@ public class ServiceManager : IServiceManager { /// some global services are registered as 'SVsService` while /// actual interface type is IVsService. /// - public virtual IServiceManager AddService(object service, Type type = null) { + public IServiceManager AddService(object service, Type type = null) { _disposeToken.ThrowIfDisposed(); type = type ?? service.GetType(); @@ -52,7 +53,7 @@ public virtual IServiceManager AddService(object service, Type type = null) { /// Adds on-demand created service /// /// Service factory - public virtual IServiceManager AddService(Func factory) where T : class { + public IServiceManager AddService(Func factory) where T : class { _disposeToken.ThrowIfDisposed(); var lazy = new Lazy(() => factory(this)); @@ -65,7 +66,7 @@ public virtual IServiceManager AddService(Func factory) /// /// Service type /// Service instance or null if it doesn't exist - public virtual T GetService(Type type = null) where T : class { + public T GetService(Type type = null) where T : class { if (_disposeToken.IsDisposed) { // Do not throw. When editor text buffer is closed, the associated service manager // is disposed. However, some actions may still hold on the text buffer reference @@ -75,16 +76,16 @@ public virtual T GetService(Type type = null) where T : class { } type = type ?? typeof(T); - if (!_s.TryGetValue(type, out object value)) { + if (!_s.TryGetValue(type, out var value)) { value = _s.FirstOrDefault(kvp => type.GetTypeInfo().IsAssignableFrom(kvp.Key)).Value; } return (T)CheckDisposed(value as T ?? (value as Lazy)?.Value); } - public virtual void RemoveService(object service) => _s.TryRemove(service.GetType(), out object dummy); + public void RemoveService(object service) => _s.TryRemove(service.GetType(), out var dummy); - public virtual IEnumerable AllServices => _s.Keys.ToList(); + public IEnumerable AllServices => _s.Keys.ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] private object CheckDisposed(object service) { @@ -109,4 +110,4 @@ public void Dispose() { } #endregion } -} \ No newline at end of file +} diff --git a/src/LanguageServer/Impl/Definitions/IProgressService.cs b/src/Core/Impl/Shell/IProgressService.cs similarity index 87% rename from src/LanguageServer/Impl/Definitions/IProgressService.cs rename to src/Core/Impl/Shell/IProgressService.cs index 2036ad1c6..0932519ca 100644 --- a/src/LanguageServer/Impl/Definitions/IProgressService.cs +++ b/src/Core/Impl/Shell/IProgressService.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +16,7 @@ using System; using System.Threading.Tasks; -namespace Microsoft.Python.LanguageServer { +namespace Microsoft.Python.Core.Shell { /// /// Progress reporting service /// diff --git a/src/LanguageServer/Impl/Definitions/IServiceContainer.cs b/src/Core/Impl/Shell/IServiceContainer.cs similarity index 71% rename from src/LanguageServer/Impl/Definitions/IServiceContainer.cs rename to src/Core/Impl/Shell/IServiceContainer.cs index 13f65ed7b..046d4cba1 100644 --- a/src/LanguageServer/Impl/Definitions/IServiceContainer.cs +++ b/src/Core/Impl/Shell/IServiceContainer.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,24 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Generic; -namespace Microsoft.Python.LanguageServer { +namespace Microsoft.Python.Core { public interface IServiceContainer { /// /// Provides access to global application services /// T GetService(Type type = null) where T : class; - - /// - /// Enumerates all available services - /// - IEnumerable AllServices { get; } } } diff --git a/src/LanguageServer/Impl/Services/IServiceManager.cs b/src/Core/Impl/Shell/IServiceManager.cs similarity index 92% rename from src/LanguageServer/Impl/Services/IServiceManager.cs rename to src/Core/Impl/Shell/IServiceManager.cs index dc84908f5..0ab68054e 100644 --- a/src/LanguageServer/Impl/Services/IServiceManager.cs +++ b/src/Core/Impl/Shell/IServiceManager.cs @@ -9,15 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using Microsoft.Python.LanguageServer; -namespace Microsoft.PythonTools.LanguageServer.Services { +namespace Microsoft.Python.Core.Shell { public interface IServiceManager : IServiceContainer, IDisposable { /// /// Adds service instance diff --git a/src/LanguageServer/Impl/Definitions/ITelemetryService.cs b/src/Core/Impl/Shell/ITelemetryService.cs similarity index 80% rename from src/LanguageServer/Impl/Definitions/ITelemetryService.cs rename to src/Core/Impl/Shell/ITelemetryService.cs index 215d2509a..9c3e084f5 100644 --- a/src/LanguageServer/Impl/Definitions/ITelemetryService.cs +++ b/src/Core/Impl/Shell/ITelemetryService.cs @@ -9,22 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; using System.Threading.Tasks; -namespace Microsoft.Python.LanguageServer { - [Obsolete] +namespace Microsoft.Python.Core.Shell { public interface ITelemetryService { - Task SendTelemetry(object o); - } - public interface ITelemetryService2 { - Task SendTelemetry(TelemetryEvent telemetryEvent); + Task SendTelemetryAsync(TelemetryEvent telemetryEvent); } public sealed class TelemetryEvent { diff --git a/src/LanguageServer/Impl/Definitions/IUIService.cs b/src/Core/Impl/Shell/IUIService.cs similarity index 57% rename from src/LanguageServer/Impl/Definitions/IUIService.cs rename to src/Core/Impl/Shell/IUIService.cs index 1193db291..c9af48a6c 100644 --- a/src/LanguageServer/Impl/Definitions/IUIService.cs +++ b/src/Core/Impl/Shell/IUIService.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,14 +8,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. +using System.Diagnostics; using System.Threading.Tasks; -namespace Microsoft.Python.LanguageServer { +namespace Microsoft.Python.Core.Shell { /// /// Service that represents the application user interface. /// @@ -24,30 +24,17 @@ public interface IUIService { /// /// Displays error message in a host-specific UI /// - Task ShowMessage(string message, MessageType messageType); + Task ShowMessageAsync(string message, TraceEventType eventType); /// /// Displays message with specified buttons in a host-specific UI /// - Task ShowMessage(string message, MessageActionItem[] actions, MessageType messageType); - - /// - /// Writes message to the host application output log - /// - /// - /// - Task LogMessage(string message, MessageType messageType); + Task ShowMessageAsync(string message, string[] actions, TraceEventType eventType); /// /// Writes message to the host application status bar /// /// - Task SetStatusBarMessage(string message); - - /// - /// Sets log level for output in the host application. - /// - /// - void SetLogLevel(MessageType logLevel); + Task SetStatusBarMessageAsync(string message); } } diff --git a/src/Analysis/Engine/Impl/Infrastructure/ITestEnvironment.cs b/src/Core/Impl/Testing/ITestEnvironment.cs similarity index 85% rename from src/Analysis/Engine/Impl/Infrastructure/ITestEnvironment.cs rename to src/Core/Impl/Testing/ITestEnvironment.cs index 14a64d23a..a8aaaf20b 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/ITestEnvironment.cs +++ b/src/Core/Impl/Testing/ITestEnvironment.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Threading.Tasks; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Testing { public interface ITestEnvironment { bool TryAddTaskToWait(Task task); } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/TestEnvironment.cs b/src/Core/Impl/Testing/TestEnvironment.cs similarity index 86% rename from src/Analysis/Engine/Impl/Infrastructure/TestEnvironment.cs rename to src/Core/Impl/Testing/TestEnvironment.cs index 7f5181873..fbb0ec7a0 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/TestEnvironment.cs +++ b/src/Core/Impl/Testing/TestEnvironment.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +16,7 @@ using System; using System.Threading; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Testing { public static class TestEnvironment { private static ITestEnvironment _current; @@ -31,4 +30,4 @@ public static ITestEnvironment Current { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Parsing/IndexSpan.cs b/src/Core/Impl/Text/IndexSpan.cs similarity index 61% rename from src/Analysis/Engine/Impl/Parsing/IndexSpan.cs rename to src/Core/Impl/Text/IndexSpan.cs index 464729cd9..25c9ca823 100644 --- a/src/Analysis/Engine/Impl/Parsing/IndexSpan.cs +++ b/src/Core/Impl/Text/IndexSpan.cs @@ -9,20 +9,20 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Core.Text { /// /// This structure represents an immutable integer interval that describes a range of values, from Start to End. /// /// It is closed on the left and open on the right: [Start .. End). /// - internal struct IndexSpan : IEquatable { + public struct IndexSpan : IEquatable { private readonly int _start, _length; public IndexSpan(int start, int length) { @@ -30,34 +30,15 @@ public IndexSpan(int start, int length) { _length = length; } - public int Start { - get { - return _start; - } - } + public int Start => _start; - public int End { - get { - return _start + _length; - } - } + public int End => _start + _length; - public int Length { - get { - return _length; - } - } + public int Length => _length; - public override int GetHashCode() { - return Length.GetHashCode() ^ Start.GetHashCode(); - } + public override int GetHashCode() => Length.GetHashCode() ^ Start.GetHashCode(); - public override bool Equals(object obj) { - if (obj is IndexSpan) { - return Equals((IndexSpan)obj); - } - return false; - } + public override bool Equals(object obj) => obj is IndexSpan ? Equals((IndexSpan)obj) : false; public static bool operator ==(IndexSpan self, IndexSpan other) { return self.Equals(other); @@ -68,11 +49,9 @@ public override bool Equals(object obj) { } #region IEquatable Members - - public bool Equals(IndexSpan other) { - return _length == other._length && _start == other._start; - } - + public bool Equals(IndexSpan other) => _length == other._length && _start == other._start; #endregion + + public static IndexSpan FromBounds(int start, int end) => new IndexSpan(start, end - start); } } diff --git a/src/Analysis/Engine/Impl/Definitions/Position.cs b/src/Core/Impl/Text/Position.cs similarity index 95% rename from src/Analysis/Engine/Impl/Definitions/Position.cs rename to src/Core/Impl/Text/Position.cs index 8c8ab39a4..d7ad18649 100644 --- a/src/Analysis/Engine/Impl/Definitions/Position.cs +++ b/src/Core/Impl/Text/Position.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Core.Text { [Serializable] public struct Position { /// diff --git a/src/Analysis/Engine/Impl/Definitions/Range.cs b/src/Core/Impl/Text/Range.cs similarity index 92% rename from src/Analysis/Engine/Impl/Definitions/Range.cs rename to src/Core/Impl/Text/Range.cs index c0af7dbbd..59ad02afd 100644 --- a/src/Analysis/Engine/Impl/Definitions/Range.cs +++ b/src/Core/Impl/Text/Range.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Core.Text { [Serializable] public struct Range { public Position start, end; diff --git a/src/Analysis/Engine/Impl/Infrastructure/SourceLocation.cs b/src/Core/Impl/Text/SourceLocation.cs similarity index 87% rename from src/Analysis/Engine/Impl/Infrastructure/SourceLocation.cs rename to src/Core/Impl/Text/SourceLocation.cs index c19990ef3..0cc62f278 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/SourceLocation.cs +++ b/src/Core/Impl/Text/SourceLocation.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,9 +17,8 @@ using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -namespace Microsoft.PythonTools { +namespace Microsoft.Python.Core.Text { /// /// Represents a location in source code. /// @@ -71,9 +70,8 @@ private static void ValidateLocation(int index, int line, int column) { } [DebuggerStepThrough] - private static Exception ErrorOutOfRange(object p0, object p1) { - return new ArgumentOutOfRangeException("{0} must be greater than or equal to {1}".FormatInvariant(p0, p1)); - } + private static Exception ErrorOutOfRange(object p0, object p1) + => new ArgumentOutOfRangeException("{0} must be greater than or equal to {1}".FormatInvariant(p0, p1)); [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters")] private SourceLocation(int index, int line, int column, bool noChecks) { @@ -85,7 +83,7 @@ private SourceLocation(int index, int line, int column, bool noChecks) { /// /// The index in the source stream the location represents (0-based). /// - public int Index => _index >= 0 ? _index: throw new InvalidOperationException("Index is not valid"); + public int Index => _index >= 0 ? _index : throw new InvalidOperationException("Index is not valid"); /// /// The line in the source stream the location represents (1-based). @@ -164,8 +162,13 @@ private SourceLocation(int index, int line, int column, bool noChecks) { /// The other location to compare. /// 0 if the locations are equal, -1 if the left one is less than the right one, 1 otherwise. public static int Compare(SourceLocation left, SourceLocation right) { - if (left < right) return -1; - if (left > right) return 1; + if (left < right) { + return -1; + } + + if (left > right) { + return 1; + } return 0; } @@ -201,23 +204,23 @@ public SourceLocation AddColumns(int columns) { return Invalid; } - int newIndex = this._index, newCol = this.Column; + int newIndex = _index, newCol = Column; // These comparisons have been arranged to allow columns to // be int.MaxValue without the arithmetic overflowing. // The naive version is shown as a comment. // if (this.Column + columns > int.MaxValue) - if (columns > int.MaxValue - this.Column) { + if (columns > int.MaxValue - Column) { newCol = int.MaxValue; if (newIndex >= 0) { newIndex = int.MaxValue; } - // if (this.Column + columns <= 0) - } else if (columns == int.MinValue || (columns < 0 && this.Column <= -columns)) { + // if (this.Column + columns <= 0) + } else if (columns == int.MinValue || (columns < 0 && Column <= -columns)) { newCol = 1; if (newIndex >= 0) { - newIndex += 1 - this.Column; + newIndex += 1 - Column; } } else { newCol += columns; @@ -225,34 +228,27 @@ public SourceLocation AddColumns(int columns) { newIndex += columns; } } - return newIndex >= 0 ? new SourceLocation(newIndex, this.Line, newCol) : new SourceLocation(this.Line, newCol); + return newIndex >= 0 ? new SourceLocation(newIndex, Line, newCol) : new SourceLocation(Line, newCol); } public override bool Equals(object obj) { - if (!(obj is SourceLocation)) return false; + if (!(obj is SourceLocation)) { + return false; + } - SourceLocation other = (SourceLocation)obj; + var other = (SourceLocation)obj; return other.Line == Line && other.Column == Column; } - public override int GetHashCode() { - return (Line << 16) ^ Column; - } + public override int GetHashCode() => (Line << 16) ^ Column; - public override string ToString() { - return "(" + Line + ", " + Column + ")"; - } + public override string ToString() => $"({Line}, {Column})"; - public bool Equals(SourceLocation other) { - return other.Line == Line && other.Column == Column; - } + public bool Equals(SourceLocation other) => other.Line == Line && other.Column == Column; public int CompareTo(SourceLocation other) { - int c = Line.CompareTo(other.Line); - if (c == 0) { - return Column.CompareTo(other.Column); - } - return c; + var c = Line.CompareTo(other.Line); + return c == 0 ? Column.CompareTo(other.Column) : c; } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/SourceSpan.cs b/src/Core/Impl/Text/SourceSpan.cs similarity index 96% rename from src/Analysis/Engine/Impl/Infrastructure/SourceSpan.cs rename to src/Core/Impl/Text/SourceSpan.cs index 1343325e4..8fa9b2294 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/SourceSpan.cs +++ b/src/Core/Impl/Text/SourceSpan.cs @@ -9,16 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Diagnostics; -using Microsoft.PythonTools.Analysis.Infrastructure; -namespace Microsoft.PythonTools { +namespace Microsoft.Python.Core.Text { /// /// Stores the location of a span of text in a source file. @@ -109,7 +108,9 @@ public SourceSpan Union(SourceSpan other) { => left.Start != right.Start || left.End != right.End; public override bool Equals(object obj) { - if (!(obj is SourceSpan)) return false; + if (!(obj is SourceSpan)) { + return false; + } var other = (SourceSpan)obj; return Start == other.Start && End == other.End; diff --git a/src/Analysis/Engine/Impl/Infrastructure/StringSpan.cs b/src/Core/Impl/Text/StringSpan.cs similarity index 94% rename from src/Analysis/Engine/Impl/Infrastructure/StringSpan.cs rename to src/Core/Impl/Text/StringSpan.cs index 5f9dd8c3c..b01a9b6cb 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/StringSpan.cs +++ b/src/Core/Impl/Text/StringSpan.cs @@ -18,7 +18,7 @@ using System.Collections; using System.Collections.Generic; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Core.Text { /// /// This type represents the span over the string /// It is a temporary solution until .net standard 2.1 with ReadOnlySpan is published @@ -46,9 +46,7 @@ public override bool Equals(object obj) public bool Equals(StringSpan other) => Length == other.Length && string.CompareOrdinal(Source, Start, other.Source, other.Start, Length) == 0; - public override int GetHashCode() { - throw new NotSupportedException(); - } + public override int GetHashCode() => throw new NotSupportedException(); public void Deconstruct(out string source, out int start, out int length) { source = Source; @@ -117,8 +115,6 @@ public bool MoveNext() { public void Dispose() { } object IEnumerator.Current => Current; - public void Reset() { - Current = new StringSpan(_source, 0, _start); - } + public void Reset() => Current = new StringSpan(_source, 0, _start); } } diff --git a/src/Analysis/Engine/Impl/Infrastructure/CancellationTokenUtilities.cs b/src/Core/Impl/Threading/CancellationTokenUtilities.cs similarity index 80% rename from src/Analysis/Engine/Impl/Infrastructure/CancellationTokenUtilities.cs rename to src/Core/Impl/Threading/CancellationTokenUtilities.cs index 9b097f258..3e0480fe1 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/CancellationTokenUtilities.cs +++ b/src/Core/Impl/Threading/CancellationTokenUtilities.cs @@ -1,4 +1,3 @@ -// Visual Studio Shared Project // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -17,11 +16,11 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal static class CancellationTokenUtilities { +namespace Microsoft.Python.Core.Threading { + public static class CancellationTokenUtilities { public static void UnregisterOnCompletion(this CancellationTokenRegistration registration, Task task) - => task.ContinueWith(UnregisterCancellationToken, registration, default(CancellationToken), TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); + => task.ContinueWith(UnregisterCancellationToken, registration, default, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); private static void UnregisterCancellationToken(Task task, object state) => ((CancellationTokenRegistration)state).Dispose(); } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/PriorityProducerConsumer.cs b/src/Core/Impl/Threading/PriorityProducerConsumer.cs similarity index 94% rename from src/Analysis/Engine/Impl/Infrastructure/PriorityProducerConsumer.cs rename to src/Core/Impl/Threading/PriorityProducerConsumer.cs index 2722b782c..21cfa8afa 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/PriorityProducerConsumer.cs +++ b/src/Core/Impl/Threading/PriorityProducerConsumer.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,9 +19,10 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core.Disposables; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal sealed class PriorityProducerConsumer : IDisposable { +namespace Microsoft.Python.Core.Threading { + public sealed class PriorityProducerConsumer : IDisposable { private readonly int _maxPriority; private readonly object _syncObj; private readonly List[] _queues; @@ -71,7 +71,10 @@ public void Dispose() { } public void Produce(T value, int priority = 0) { - if (priority < 0 || priority >= _maxPriority) throw new ArgumentOutOfRangeException(nameof(priority)); + if (priority < 0 || priority >= _maxPriority) { + throw new ArgumentOutOfRangeException(nameof(priority)); + } + _disposeToken.ThrowIfDisposed(); TaskCompletionSource pendingTcs = null; @@ -109,7 +112,7 @@ private void RemoveExistingValue(T value, ref int priority) { } } - public Task ConsumeAsync(CancellationToken cancellationToken = default(CancellationToken)) { + public Task ConsumeAsync(CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { return Task.FromCanceled(cancellationToken); } @@ -186,4 +189,4 @@ public TaskCompletionSource Release() { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Impl/Infrastructure/SingleThreadSynchronizationContext.cs b/src/Core/Impl/Threading/SingleThreadSynchronizationContext.cs similarity index 83% rename from src/Analysis/Engine/Impl/Infrastructure/SingleThreadSynchronizationContext.cs rename to src/Core/Impl/Threading/SingleThreadSynchronizationContext.cs index 0c857bb00..9f0afe0bb 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/SingleThreadSynchronizationContext.cs +++ b/src/Core/Impl/Threading/SingleThreadSynchronizationContext.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,8 +18,8 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal class SingleThreadSynchronizationContext : SynchronizationContext, IDisposable { +namespace Microsoft.Python.Core.Threading { + public class SingleThreadSynchronizationContext : SynchronizationContext, IDisposable { private readonly ConcurrentQueue> _queue = new ConcurrentQueue>(); private readonly ManualResetEventSlim _workAvailable = new ManualResetEventSlim(false); private readonly CancellationTokenSource _cts = new CancellationTokenSource(); @@ -34,9 +33,7 @@ public override void Post(SendOrPostCallback d, object state) { _workAvailable.Set(); } - public void Dispose() { - _cts.Cancel(); - } + public void Dispose() => _cts.Cancel(); private void QueueWorker() { while (true) { diff --git a/src/Analysis/Engine/Impl/Infrastructure/TaskCompletionSourceEx.cs b/src/Core/Impl/Threading/TaskCompletionSourceEx.cs similarity index 89% rename from src/Analysis/Engine/Impl/Infrastructure/TaskCompletionSourceEx.cs rename to src/Core/Impl/Threading/TaskCompletionSourceEx.cs index 705d561f0..373e4c135 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/TaskCompletionSourceEx.cs +++ b/src/Core/Impl/Threading/TaskCompletionSourceEx.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,8 +19,8 @@ using System.Threading.Tasks; using static System.FormattableString; -namespace Microsoft.PythonTools.Analysis.Infrastructure { - internal sealed class TaskCompletionSourceEx { +namespace Microsoft.Python.Core.Threading { + public sealed class TaskCompletionSourceEx { private readonly AsyncTaskMethodBuilder _atmb; private int _completed; @@ -46,7 +45,7 @@ public bool TrySetResult(TResult result) { return false; } - public bool TrySetCanceled(OperationCanceledException exception = null, CancellationToken cancellationToken = default(CancellationToken)) { + public bool TrySetCanceled(OperationCanceledException exception = null, CancellationToken cancellationToken = default) { if (Task.IsCompleted) { return false; } @@ -100,7 +99,7 @@ public void SetResult(TResult result) { } } - public void SetCanceled(OperationCanceledException exception = null, CancellationToken cancellationToken = default(CancellationToken)) { + public void SetCanceled(OperationCanceledException exception = null, CancellationToken cancellationToken = default) { if (!TrySetCanceled(exception, cancellationToken)) { throw new InvalidOperationException("Task already completed"); } @@ -112,4 +111,4 @@ public void SetException(Exception exception) { } } } -} \ No newline at end of file +} diff --git a/src/Core/Test/Microsoft.Python.Core.Tests.csproj b/src/Core/Test/Microsoft.Python.Core.Tests.csproj new file mode 100644 index 000000000..8bcb75b13 --- /dev/null +++ b/src/Core/Test/Microsoft.Python.Core.Tests.csproj @@ -0,0 +1,46 @@ + + + netcoreapp2.1 + Microsoft.Python.Core.Tests + Microsoft.Python.Core.Tests + + + + 1701;1702;$(NoWarn) + + + ..\..\PLS.ruleset + + + ..\..\PLS.ruleset + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + diff --git a/src/Analysis/Engine/Test/ModulePathTests.cs b/src/Core/Test/ModulePathTests.cs similarity index 98% rename from src/Analysis/Engine/Test/ModulePathTests.cs rename to src/Core/Test/ModulePathTests.cs index 0135f0408..0b39f1753 100644 --- a/src/Analysis/Engine/Test/ModulePathTests.cs +++ b/src/Core/Test/ModulePathTests.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,11 +16,11 @@ using System; using System.Collections.Generic; using System.IO; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AnalysisTests { +namespace Microsoft.Python.Core.Tests { [TestClass] public class ModulePathTests { [TestMethod, Priority(0)] diff --git a/src/Analysis/Engine/Test/PathEqualityComparerTests.cs b/src/Core/Test/PathEqualityComparerTests.cs similarity index 98% rename from src/Analysis/Engine/Test/PathEqualityComparerTests.cs rename to src/Core/Test/PathEqualityComparerTests.cs index dd7025152..395745694 100644 --- a/src/Analysis/Engine/Test/PathEqualityComparerTests.cs +++ b/src/Core/Test/PathEqualityComparerTests.cs @@ -9,18 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.IO; using System.Linq; using FluentAssertions; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AnalysisTests { +namespace Microsoft.Python.Core.Tests { [TestClass] public class PathEqualityComparerTests { [TestMethod] diff --git a/src/Analysis/Engine/Test/PriorityProducerConsumerTest.cs b/src/Core/Test/PriorityProducerConsumerTest.cs similarity index 98% rename from src/Analysis/Engine/Test/PriorityProducerConsumerTest.cs rename to src/Core/Test/PriorityProducerConsumerTest.cs index 0166590ce..62c755ca6 100644 --- a/src/Analysis/Engine/Test/PriorityProducerConsumerTest.cs +++ b/src/Core/Test/PriorityProducerConsumerTest.cs @@ -9,17 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Threading.Tasks; using FluentAssertions; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.Threading; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AnalysisTests { +namespace Microsoft.Python.Core.Tests { [TestClass] public class PriorityProducerConsumerTest { [TestMethod, Priority(0)] diff --git a/src/Core/Test/TestLogger.cs b/src/Core/Test/TestLogger.cs new file mode 100644 index 000000000..28cd09563 --- /dev/null +++ b/src/Core/Test/TestLogger.cs @@ -0,0 +1,112 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Concurrent; +using System.Diagnostics; +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Logging; +using TestUtilities; + +namespace Microsoft.Python.Core.Tests { + public sealed class TestLogger : ILogger, IDisposable { + private readonly ConcurrentQueue> _messages = new ConcurrentQueue>(); + private readonly ManualResetEventSlim _itemsAvailable = new ManualResetEventSlim(false); + private readonly CancellationTokenSource _cts = new CancellationTokenSource(); + private readonly object _lock = new object(); + private readonly FileStream _file = null; + + public TestLogger() { + //var path = Path.Combine(Path.GetTempPath(), "python_analysis.log"); + //_file = File.OpenWrite(path); + Task.Run(() => Worker()).DoNotWait(); + } + + public void Dispose() { + _cts.Cancel(); + _file?.Close(); + _file?.Dispose(); + } + + public TraceEventType LogLevel { get; set; } = TraceEventType.Verbose; + public void Log(TraceEventType eventType, IFormattable message) => Log(eventType, message.ToString()); + public void Log(TraceEventType eventType, string message) { + + var m = $"[{TestEnvironmentImpl.Elapsed()}]: {message}"; + lock (_lock) { + _messages.Enqueue(new Tuple(eventType, m)); + _itemsAvailable.Set(); + } + } + + private void WriteToFile(string s) { + if (_file != null) { + var b = Encoding.UTF8.GetBytes(s + Environment.NewLine); + _file.Write(b, 0, b.Length); + } + } + + public void Log(TraceEventType eventType, params object[] parameters) { + var sb = new StringBuilder(); + for (var i = 0; i < parameters.Length; i++) { + sb.Append('{'); + sb.Append(i.ToString()); + sb.Append("} "); + } + Log(eventType, sb.ToString().FormatUI(parameters)); + } + + private void Worker() { + while (!_cts.IsCancellationRequested) { + Tuple t; + lock (_lock) { + if (!_messages.TryDequeue(out t)) { + _itemsAvailable.Reset(); + } + } + + if (t == null) { + try { + _itemsAvailable.Wait(_cts.Token); + } catch (OperationCanceledException) { + break; + } + continue; + } + + var m = t.Item2; + switch (t.Item1) { + case TraceEventType.Error: + case TraceEventType.Critical: + Trace.TraceError(m); + break; + case TraceEventType.Warning: + Trace.TraceWarning(m); + break; + case TraceEventType.Information: + Trace.TraceInformation(m); + break; + case TraceEventType.Verbose: + Trace.TraceInformation($"LOG: {m}"); + break; + } + WriteToFile(m); + } + } + } +} diff --git a/src/LanguageServer/Impl/Definitions/CallbackEventArgs.cs b/src/LanguageServer/Impl/Definitions/CallbackEventArgs.cs index a82932d97..5ff38902d 100644 --- a/src/LanguageServer/Impl/Definitions/CallbackEventArgs.cs +++ b/src/LanguageServer/Impl/Definitions/CallbackEventArgs.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Definitions/Enums.cs b/src/LanguageServer/Impl/Definitions/Enums.cs index aa7383af5..ca7cf1917 100644 --- a/src/LanguageServer/Impl/Definitions/Enums.cs +++ b/src/LanguageServer/Impl/Definitions/Enums.cs @@ -9,12 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; +using System.Diagnostics; namespace Microsoft.Python.LanguageServer { public sealed class SerializeAsAttribute : Attribute { @@ -99,6 +100,24 @@ public enum MessageType : int { Log = 4 } + public static class MessageTypeExtensions { + public static TraceEventType ToTraceEventType(this MessageType mt) { + switch (mt) { + case MessageType.Error: + return TraceEventType.Error; + case MessageType.Warning: + return TraceEventType.Warning; + case MessageType.Info: + case MessageType._General: + return TraceEventType.Information; + case MessageType.Log: + return TraceEventType.Verbose; + } + + return TraceEventType.Error; + } + } + public enum FileChangeType : int { Created = 1, Changed = 2, diff --git a/src/LanguageServer/Impl/Definitions/IDocumentReader.cs b/src/LanguageServer/Impl/Definitions/IDocumentReader.cs index 5d266c302..1073946e1 100644 --- a/src/LanguageServer/Impl/Definitions/IDocumentReader.cs +++ b/src/LanguageServer/Impl/Definitions/IDocumentReader.cs @@ -9,15 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.Python.LanguageServer { public interface IDocumentReader { @@ -26,11 +24,11 @@ public interface IDocumentReader { } public static class DocumentReaderExtensions { - public static string ReadLinearSpan(this IDocumentReader reader, LinearSpan span) + public static string ReadLinearSpan(this IDocumentReader reader, IndexSpan span) => reader.Read(span.Start, span.Length); public static string ReadRange(this IDocumentReader reader, Range range, PythonAst ast) - => reader.ReadLinearSpan(range.ToLinearSpan(ast)); + => reader.ReadLinearSpan(range.ToIndexSpan(ast)); public static string ReadSourceSpan(this IDocumentReader reader, SourceSpan span, PythonAst ast) - => reader.ReadLinearSpan(span.ToLinearSpan(ast)); + => reader.ReadLinearSpan(span.ToIndexSpan(ast)); } } diff --git a/src/LanguageServer/Impl/Definitions/ILanguageServerExtensionProvider.cs b/src/LanguageServer/Impl/Definitions/ILanguageServerExtensionProvider.cs index c30ba55d5..aff42f70f 100644 --- a/src/LanguageServer/Impl/Definitions/ILanguageServerExtensionProvider.cs +++ b/src/LanguageServer/Impl/Definitions/ILanguageServerExtensionProvider.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Definitions/IPythonLanguageServer.cs b/src/LanguageServer/Impl/Definitions/IPythonLanguageServer.cs index c380c5100..ae102c698 100644 --- a/src/LanguageServer/Impl/Definitions/IPythonLanguageServer.cs +++ b/src/LanguageServer/Impl/Definitions/IPythonLanguageServer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,8 +18,9 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core.Logging; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.Python.LanguageServer { public interface IPythonLanguageServer : IPythonLanguageServerProtocol { diff --git a/src/LanguageServer/Impl/Definitions/IPythonLanguageServerProtocol.cs b/src/LanguageServer/Impl/Definitions/IPythonLanguageServerProtocol.cs index 7b5dd28e3..4d0efdab0 100644 --- a/src/LanguageServer/Impl/Definitions/IPythonLanguageServerProtocol.cs +++ b/src/LanguageServer/Impl/Definitions/IPythonLanguageServerProtocol.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Definitions/ITextChangeNotifications.cs b/src/LanguageServer/Impl/Definitions/ITextChangeNotifications.cs index 19f45e79d..23d2e525e 100644 --- a/src/LanguageServer/Impl/Definitions/ITextChangeNotifications.cs +++ b/src/LanguageServer/Impl/Definitions/ITextChangeNotifications.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Definitions/Messages.cs b/src/LanguageServer/Impl/Definitions/Messages.cs index afb627f4b..f8aec2d94 100644 --- a/src/LanguageServer/Impl/Definitions/Messages.cs +++ b/src/LanguageServer/Impl/Definitions/Messages.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,7 +18,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading.Tasks; -using Microsoft.Python.LanguageServer.Implementation; +using Microsoft.Python.Core.Text; using Microsoft.PythonTools.Analysis; namespace Microsoft.Python.LanguageServer { @@ -72,15 +72,6 @@ public class ShowMessageRequestParams { public MessageActionItem[] actions; } - public sealed class LogMessageEventArgs : EventArgs { - public MessageType type { get; set; } - public string message { get; set; } - } - - public sealed class TelemetryEventArgs : EventArgs { - public object value { get; set; } - } - public sealed class CommandEventArgs: EventArgs { public string command; public object[] arguments; diff --git a/src/LanguageServer/Impl/Definitions/ServerSettings.cs b/src/LanguageServer/Impl/Definitions/ServerSettings.cs index 982446351..a86f2d987 100644 --- a/src/LanguageServer/Impl/Definitions/ServerSettings.cs +++ b/src/LanguageServer/Impl/Definitions/ServerSettings.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Definitions/Structures.cs b/src/LanguageServer/Impl/Definitions/Structures.cs index feb077091..635b28082 100644 --- a/src/LanguageServer/Impl/Definitions/Structures.cs +++ b/src/LanguageServer/Impl/Definitions/Structures.cs @@ -9,15 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using Microsoft.PythonTools; -using Microsoft.PythonTools.Analysis; +using Microsoft.Python.Core.Text; using Microsoft.PythonTools.Analysis.Documentation; namespace Microsoft.Python.LanguageServer { diff --git a/src/LanguageServer/Impl/Diagnostics/DiagnosticsPublisher.cs b/src/LanguageServer/Impl/Diagnostics/DiagnosticsPublisher.cs new file mode 100644 index 000000000..cd5b58ab6 --- /dev/null +++ b/src/LanguageServer/Impl/Diagnostics/DiagnosticsPublisher.cs @@ -0,0 +1,102 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Disposables; +using Microsoft.Python.Core.Idle; +using Microsoft.Python.Core.Shell; +using Microsoft.PythonTools.Analysis; +using Newtonsoft.Json; +using StreamJsonRpc; + +namespace Microsoft.Python.LanguageServer.Diagnostics { + internal sealed class DiagnosticsPublisher : IDisposable { + private readonly Dictionary _pendingDiagnostic = new Dictionary(); + private readonly DisposableBag _disposables = DisposableBag.Create(); + private readonly JsonRpc _rpc; + private readonly object _lock = new object(); + private DateTime _lastChangeTime; + + public DiagnosticsPublisher(Implementation.Server server, IServiceContainer services) { + var s = server; + s.OnPublishDiagnostics += OnPublishDiagnostics; + + var idleTimeService = services.GetService(); + idleTimeService.Idle += OnIdle; + idleTimeService.Closing += OnClosing; + + _rpc = services.GetService(); + + _disposables + .Add(() => s.OnPublishDiagnostics -= OnPublishDiagnostics) + .Add(() => idleTimeService.Idle -= OnIdle) + .Add(() => idleTimeService.Idle -= OnClosing); + } + + public int PublishingDelay { get; set; } + + public void Dispose() => _disposables.TryDispose(); + + private void OnClosing(object sender, EventArgs e) => Dispose(); + + private void OnIdle(object sender, EventArgs e) { + if (_pendingDiagnostic.Count > 0 && (DateTime.Now - _lastChangeTime).TotalMilliseconds > PublishingDelay) { + PublishPendingDiagnostics(); + } + } + + private void OnPublishDiagnostics(object sender, PublishDiagnosticsEventArgs e) { + lock (_lock) { + // If list is empty (errors got fixed), publish immediately, + // otherwise throttle so user does not get spurious squiggles + // while typing normally. + var diags = e.diagnostics.ToArray(); + _pendingDiagnostic[e.uri] = diags; + if (diags.Length == 0) { + PublishPendingDiagnostics(); + } + _lastChangeTime = DateTime.Now; + } + } + + private void PublishPendingDiagnostics() { + List> list; + + lock (_lock) { + list = _pendingDiagnostic.ToList(); + _pendingDiagnostic.Clear(); + } + + foreach (var kvp in list) { + var parameters = new PublishDiagnosticsParams { + uri = kvp.Key, + diagnostics = kvp.Value.Where(d => d.severity != DiagnosticSeverity.Unspecified).ToArray() + }; + _rpc.NotifyWithParameterObjectAsync("textDocument/publishDiagnostics", parameters).DoNotWait(); + } + } + + [JsonObject] + private class PublishDiagnosticsParams { + [JsonProperty] + public Uri uri; + [JsonProperty] + public Diagnostic[] diagnostics; + } + } +} diff --git a/src/LanguageServer/Impl/Extensions/ICompletionExtension.cs b/src/LanguageServer/Impl/Extensions/ICompletionExtension.cs index 02b7ca856..369b3f5d0 100644 --- a/src/LanguageServer/Impl/Extensions/ICompletionExtension.cs +++ b/src/LanguageServer/Impl/Extensions/ICompletionExtension.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,9 +17,9 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Extensions { public interface ICompletionExtension { diff --git a/src/LanguageServer/Impl/Extensions/ILanguageServerExtension.cs b/src/LanguageServer/Impl/Extensions/ILanguageServerExtension.cs index 2b80f1cfb..581454c5f 100644 --- a/src/LanguageServer/Impl/Extensions/ILanguageServerExtension.cs +++ b/src/LanguageServer/Impl/Extensions/ILanguageServerExtension.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,6 +18,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; namespace Microsoft.Python.LanguageServer.Extensions { public interface ILanguageServerExtension: IDisposable { diff --git a/src/LanguageServer/Impl/Implementation/BlockFormatter.cs b/src/LanguageServer/Impl/Implementation/BlockFormatter.cs index c27e24652..b13356946 100644 --- a/src/LanguageServer/Impl/Implementation/BlockFormatter.cs +++ b/src/LanguageServer/Impl/Implementation/BlockFormatter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,8 +20,9 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Core.Text; namespace Microsoft.Python.LanguageServer.Implementation { /// diff --git a/src/LanguageServer/Impl/Implementation/CodeActionProvider.cs b/src/LanguageServer/Impl/Implementation/CodeActionProvider.cs index 749903213..93ced1191 100644 --- a/src/LanguageServer/Impl/Implementation/CodeActionProvider.cs +++ b/src/LanguageServer/Impl/Implementation/CodeActionProvider.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Implementation/CompletionAnalysis.cs b/src/LanguageServer/Impl/Implementation/CompletionAnalysis.cs index 065576264..9bda0b3b0 100644 --- a/src/LanguageServer/Impl/Implementation/CompletionAnalysis.cs +++ b/src/LanguageServer/Impl/Implementation/CompletionAnalysis.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,15 +19,17 @@ using System.IO; using System.Linq; using System.Text; -using Microsoft.PythonTools; +using Microsoft.Python.Analysis.Core.DependencyResolution; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Core.Logging; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.DependencyResolution; using Microsoft.PythonTools.Analysis.Documentation; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { class CompletionAnalysis { @@ -151,7 +152,7 @@ private void EnsureTokens() { var reader = _openDocument?.Invoke(); if (reader == null) { - _log.TraceMessage($"Cannot get completions at error node without sources"); + _log.Log(TraceEventType.Verbose, "Cannot get completions at error node without sources"); _tokens = Array.Empty>(); _tokenNewlines = Array.Empty(); return; @@ -176,7 +177,7 @@ private void EnsureTokens() { public IEnumerable GetCompletionsFromString(string expr) { Check.ArgumentNotNullOrEmpty(nameof(expr), expr); - _log.TraceMessage($"Completing expression '{expr}'"); + _log.Log(TraceEventType.Verbose, $"Completing expression '{expr}'"); return Analysis.GetMembers(expr, Position, Options).Select(ToCompletionItem); } @@ -247,7 +248,7 @@ private static IEnumerable Once(CompletionItem item) { } private IEnumerable GetCompletionsFromMembers(MemberExpression me) { - _log.TraceMessage( + _log.Log(TraceEventType.Verbose, $"Completing expression {me.Target.ToCodeString(Tree, CodeFormattingOptions.Traditional)}"); ParentExpression = me.Target; if (!string.IsNullOrEmpty(me.Name)) { @@ -618,7 +619,7 @@ private bool TryGetCompletionsInExceptStatement(TryStatementHandler tryStatement } private bool IsInsideComment() { - var match = Array.BinarySearch(Tree._commentLocations, Position); + var match = Array.BinarySearch(Tree.CommentLocations, Position); // If our index = -1, it means we're before the first comment if (match == -1) { return false; @@ -630,16 +631,16 @@ private bool IsInsideComment() { match = ~match - 1; } - if (match >= Tree._commentLocations.Length) { + if (match >= Tree.CommentLocations.Length) { Debug.Fail("Failed to find nearest preceding comment in AST"); return false; } - if (Tree._commentLocations[match].Line != Position.Line) { + if (Tree.CommentLocations[match].Line != Position.Line) { return false; } - if (Tree._commentLocations[match].Column >= Position.Column) { + if (Tree.CommentLocations[match].Column >= Position.Column) { return false; } @@ -712,7 +713,7 @@ private IEnumerable GetCompletionsFromTopLevel() { ShouldAllowSnippets = options.HasFlag(GetMemberOptions.IncludeExpressionKeywords); - _log.TraceMessage($"Completing all names"); + _log.Log(TraceEventType.Verbose, "Completing all names"); var members = Analysis.GetAllMembers(Position, options); var finder = new ExpressionFinder(Tree, new GetExpressionOptions { Calls = true }); @@ -725,7 +726,7 @@ private IEnumerable GetCompletionsFromTopLevel() { .Select(n => new MemberResult($"{n}=", PythonMemberType.NamedArgument) as IMemberResult) .ToArray(); - _log.TraceMessage($"Including {argNames.Length} named arguments"); + _log.Log(TraceEventType.Verbose, $"Including {argNames.Length} named arguments"); members = members.Concat(argNames); } diff --git a/src/LanguageServer/Impl/Implementation/DiagnosticsErrorSink.cs b/src/LanguageServer/Impl/Implementation/DiagnosticsErrorSink.cs index ec40f3c22..2bbad8d11 100644 --- a/src/LanguageServer/Impl/Implementation/DiagnosticsErrorSink.cs +++ b/src/LanguageServer/Impl/Implementation/DiagnosticsErrorSink.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,10 +17,10 @@ using System; using System.Collections.Generic; using System.Linq; -using Microsoft.PythonTools; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; namespace Microsoft.Python.LanguageServer.Implementation { class DiagnosticsErrorSink : ErrorSink { diff --git a/src/LanguageServer/Impl/Implementation/DocumentReader.cs b/src/LanguageServer/Impl/Implementation/DocumentReader.cs index e6148b48f..3027d9e12 100644 --- a/src/LanguageServer/Impl/Implementation/DocumentReader.cs +++ b/src/LanguageServer/Impl/Implementation/DocumentReader.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Implementation/EditorFiles.cs b/src/LanguageServer/Impl/Implementation/EditorFiles.cs index 0861e953e..89c397477 100644 --- a/src/LanguageServer/Impl/Implementation/EditorFiles.cs +++ b/src/LanguageServer/Impl/Implementation/EditorFiles.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,9 +20,8 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core.Threading; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Analyzer; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Intellisense; namespace Microsoft.Python.LanguageServer.Implementation { diff --git a/src/LanguageServer/Impl/Implementation/LineFormatter.cs b/src/LanguageServer/Impl/Implementation/LineFormatter.cs index 19467272e..4fed7a0f8 100644 --- a/src/LanguageServer/Impl/Implementation/LineFormatter.cs +++ b/src/LanguageServer/Impl/Implementation/LineFormatter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,9 +19,10 @@ using System.IO; using System.Linq; using System.Text; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; namespace Microsoft.Python.LanguageServer.Implementation { /// diff --git a/src/LanguageServer/Impl/Implementation/ParseQueue.cs b/src/LanguageServer/Impl/Implementation/ParseQueue.cs index bf0a5a8ac..d177c7dea 100644 --- a/src/LanguageServer/Impl/Implementation/ParseQueue.cs +++ b/src/LanguageServer/Impl/Implementation/ParseQueue.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,11 +22,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Intellisense; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { class ParseQueue: IDisposable { diff --git a/src/LanguageServer/Impl/Implementation/ProjectFiles.cs b/src/LanguageServer/Impl/Implementation/ProjectFiles.cs index e5a8e8cc9..efc9de332 100644 --- a/src/LanguageServer/Impl/Implementation/ProjectFiles.cs +++ b/src/LanguageServer/Impl/Implementation/ProjectFiles.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,10 +20,10 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Intellisense; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { internal sealed class ProjectFiles : IDisposable, IEnumerable { diff --git a/src/LanguageServer/Impl/Implementation/RestTextConverter.cs b/src/LanguageServer/Impl/Implementation/RestTextConverter.cs index 6ddd82b64..ee4e31f4d 100644 --- a/src/LanguageServer/Impl/Implementation/RestTextConverter.cs +++ b/src/LanguageServer/Impl/Implementation/RestTextConverter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,7 +17,7 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; // Based on https://github.com/Microsoft/vscode-python/blob/master/src/client/common/markdown/restTextConverter.ts diff --git a/src/LanguageServer/Impl/Implementation/Server.Completion.cs b/src/LanguageServer/Impl/Implementation/Server.Completion.cs index 3eed44844..7ab08626a 100644 --- a/src/LanguageServer/Impl/Implementation/Server.Completion.cs +++ b/src/LanguageServer/Impl/Implementation/Server.Completion.cs @@ -9,21 +9,20 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core.Text; using Microsoft.Python.LanguageServer.Extensions; -using Microsoft.PythonTools; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { public sealed partial class Server { @@ -41,7 +40,7 @@ public override async Task Completion(CompletionParams @params, } var opts = GetOptions(@params.context); - var ctxt = new CompletionAnalysis(analysis, tree, @params.position, opts, Settings.completion, _displayTextBuilder, this, () => entry.ReadDocument(ProjectFiles.GetPart(uri), out _)); + var ctxt = new CompletionAnalysis(analysis, tree, @params.position, opts, Settings.completion, _displayTextBuilder, Logger, () => entry.ReadDocument(ProjectFiles.GetPart(uri), out _)); var members = string.IsNullOrEmpty(@params._expr) ? ctxt.GetCompletions() @@ -72,10 +71,6 @@ public override async Task Completion(CompletionParams @params, res._applicableSpan = GetApplicableSpan(ctxt, @params, tree); LogMessage(MessageType.Info, $"Found {res.items.Length} completions for {uri} at {@params.position} after filtering"); - if (HandleOldStyleCompletionExtension(analysis as ModuleAnalysis, tree, @params.position, res)) { - return res; - } - await InvokeExtensionsAsync((ext, token) => (ext as ICompletionExtension)?.HandleCompletionAsync(uri, analysis, tree, @params.position, res, cancellationToken), cancellationToken); @@ -130,72 +125,5 @@ private GetMemberOptions GetOptions(CompletionContext? context) { } return opts; } - - private bool HandleOldStyleCompletionExtension(ModuleAnalysis analysis, PythonAst tree, SourceLocation location, CompletionList completions) { - if (_oldServer == null) { - return false; - } - // Backward compatibility case - var cl = new PythonTools.Analysis.LanguageServer.CompletionList { - items = completions.items.Select(x => new PythonTools.Analysis.LanguageServer.CompletionItem { - // Partial copy - label = x.label, - kind = (PythonTools.Analysis.LanguageServer.CompletionItemKind)x.kind, - detail = x.detail, - sortText = x.sortText, - filterText = x.filterText, - preselect = x.preselect, - insertText = x.insertText, - insertTextFormat = (PythonTools.Analysis.LanguageServer.InsertTextFormat)x.insertTextFormat, - }).ToArray() - }; - - var oldItems = new HashSet(); - foreach (var x in completions.items) { - oldItems.Add(x.label); - } - - _oldServer.ProcessCompletionList(analysis as ModuleAnalysis, tree, location, cl); - - var newItems = cl.items.Where(x => !oldItems.Contains(x.label)).ToArray(); - if (newItems.Length == 0) { - return false; - } - - var converted = newItems.Select(x => new CompletionItem { - label = x.label, - kind = (CompletionItemKind)x.kind, - detail = x.detail, - sortText = x.sortText, - filterText = x.filterText, - preselect = x.preselect, - insertText = x.insertText, - insertTextFormat = (InsertTextFormat)x.insertTextFormat, - textEdit = x.textEdit.HasValue - ? new TextEdit { - range = new Range { - start = new Position { - line = x.textEdit.Value.range.start.line, - character = x.textEdit.Value.range.start.character, - }, - end = new Position { - line = x.textEdit.Value.range.end.line, - character = x.textEdit.Value.range.end.character, - } - }, - newText = x.textEdit.Value.newText - } : (TextEdit?)null, - command = x.command.HasValue - ? new Command { - title = x.command.Value.title, - command = x.command.Value.command, - arguments = x.command.Value.arguments - } : (Command?)null, - data = x.data - }); - - completions.items = completions.items.Concat(converted).ToArray(); - return true; - } } } diff --git a/src/LanguageServer/Impl/Implementation/Server.Extensions.cs b/src/LanguageServer/Impl/Implementation/Server.Extensions.cs index e25f06574..086434ad7 100644 --- a/src/LanguageServer/Impl/Implementation/Server.Extensions.cs +++ b/src/LanguageServer/Impl/Implementation/Server.Extensions.cs @@ -9,67 +9,22 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -#pragma warning disable CS0618 // Type or member is obsolete - using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Shell; using Microsoft.Python.LanguageServer.Extensions; -using Microsoft.PythonTools.Analysis.Infrastructure; namespace Microsoft.Python.LanguageServer.Implementation { partial class Server { - private readonly ConcurrentDictionary _oldExtensions = - new ConcurrentDictionary(); - private PythonTools.Analysis.LanguageServer.Server _oldServer; - public async Task LoadExtensionAsync(PythonAnalysisExtensionParams extension, IServiceContainer services, CancellationToken cancellationToken) { - if (!await LoadExtensionAsyncOld(extension, cancellationToken)) { - await LoadExtensionAsyncNew(extension, services, cancellationToken); - } - } - private async Task LoadExtensionAsyncOld(PythonAnalysisExtensionParams extension, CancellationToken cancellationToken) { - try { - var provider = ActivateObject(extension.assembly, extension.typeName, null); - if (provider == null) { - return false; - } - - _oldServer = new PythonTools.Analysis.LanguageServer.Server(); - var ext = await provider.CreateAsync(_oldServer, extension.properties ?? new Dictionary(), cancellationToken); - if (ext == null) { - LogMessage(MessageType.Error, $"Extension provider {extension.assembly} {extension.typeName} returned null"); - return false; - } - - string n = null; - try { - n = ext.Name; - } catch (NotImplementedException) { - } catch (NotSupportedException) { - } - - if (!string.IsNullOrEmpty(n)) { - _oldExtensions.AddOrUpdate(n, ext, (_, previous) => { - (previous as IDisposable)?.Dispose(); - return ext; - }); - } - return true; - } catch (Exception) { - } - return false; - } - - private async Task LoadExtensionAsyncNew(PythonAnalysisExtensionParams extension, IServiceContainer services, CancellationToken cancellationToken) { try { var provider = ActivateObject(extension.assembly, extension.typeName, null); if (provider == null) { diff --git a/src/LanguageServer/Impl/Implementation/Server.FindReferences.cs b/src/LanguageServer/Impl/Implementation/Server.FindReferences.cs index e89685761..e1f5fb2b4 100644 --- a/src/LanguageServer/Impl/Implementation/Server.FindReferences.cs +++ b/src/LanguageServer/Impl/Implementation/Server.FindReferences.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,11 +19,11 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Intellisense; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { public sealed partial class Server { diff --git a/src/LanguageServer/Impl/Implementation/Server.GoToDefinition.cs b/src/LanguageServer/Impl/Implementation/Server.GoToDefinition.cs index 86f5f5921..2e98b7183 100644 --- a/src/LanguageServer/Impl/Implementation/Server.GoToDefinition.cs +++ b/src/LanguageServer/Impl/Implementation/Server.GoToDefinition.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Implementation/Server.Hover.cs b/src/LanguageServer/Impl/Implementation/Server.Hover.cs index cb0596816..1e1617b25 100644 --- a/src/LanguageServer/Impl/Implementation/Server.Hover.cs +++ b/src/LanguageServer/Impl/Implementation/Server.Hover.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,13 +19,13 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.Documentation; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Intellisense; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; +using Microsoft.Python.Core.Text; namespace Microsoft.Python.LanguageServer.Implementation { public sealed partial class Server { diff --git a/src/LanguageServer/Impl/Implementation/Server.OnTypeFormatting.cs b/src/LanguageServer/Impl/Implementation/Server.OnTypeFormatting.cs index 1b3210e5d..8846d3dec 100644 --- a/src/LanguageServer/Impl/Implementation/Server.OnTypeFormatting.cs +++ b/src/LanguageServer/Impl/Implementation/Server.OnTypeFormatting.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +17,8 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; namespace Microsoft.Python.LanguageServer.Implementation { public sealed partial class Server { diff --git a/src/LanguageServer/Impl/Implementation/Server.PrivateHelpers.cs b/src/LanguageServer/Impl/Implementation/Server.PrivateHelpers.cs index 49672ee96..40764a13a 100644 --- a/src/LanguageServer/Impl/Implementation/Server.PrivateHelpers.cs +++ b/src/LanguageServer/Impl/Implementation/Server.PrivateHelpers.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Implementation/Server.Rename.cs b/src/LanguageServer/Impl/Implementation/Server.Rename.cs index eda7da7ae..f5e674165 100644 --- a/src/LanguageServer/Impl/Implementation/Server.Rename.cs +++ b/src/LanguageServer/Impl/Implementation/Server.Rename.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,8 +20,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; namespace Microsoft.Python.LanguageServer.Implementation { public sealed partial class Server { @@ -46,7 +47,7 @@ public override async Task Rename(RenameParams @params, Cancellat throw new EditorOperationException(Resources.RenameVariable_CannotRename); } - var definitionSpan = definition.range.ToLinearSpan(tree); + var definitionSpan = definition.range.ToIndexSpan(tree); var reader = new DocumentReader(entry as IDocument, ProjectFiles.GetPart(definition.uri)); var originalName = reader.Read(definitionSpan.Start, definitionSpan.Length); if (originalName == null) { diff --git a/src/LanguageServer/Impl/Implementation/Server.SignatureHelp.cs b/src/LanguageServer/Impl/Implementation/Server.SignatureHelp.cs index 7e2e36be6..8dd945927 100644 --- a/src/LanguageServer/Impl/Implementation/Server.SignatureHelp.cs +++ b/src/LanguageServer/Impl/Implementation/Server.SignatureHelp.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,10 +20,10 @@ using System.Text; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Parsing; +using Microsoft.Python.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { public sealed partial class Server { diff --git a/src/LanguageServer/Impl/Implementation/Server.WorkspaceSymbols.cs b/src/LanguageServer/Impl/Implementation/Server.WorkspaceSymbols.cs index 98bb72841..5858ee8b5 100644 --- a/src/LanguageServer/Impl/Implementation/Server.WorkspaceSymbols.cs +++ b/src/LanguageServer/Impl/Implementation/Server.WorkspaceSymbols.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,9 +19,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.PythonTools; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Analysis.Values; using Microsoft.PythonTools.Interpreter; diff --git a/src/LanguageServer/Impl/Implementation/Server.cs b/src/LanguageServer/Impl/Implementation/Server.cs index 8a6a1e6c0..a8f653536 100644 --- a/src/LanguageServer/Impl/Implementation/Server.cs +++ b/src/LanguageServer/Impl/Implementation/Server.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -24,18 +23,21 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Disposables; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.Shell; using Microsoft.Python.LanguageServer.Extensions; +using Microsoft.Python.Parsing.Ast; using Microsoft.PythonTools.Analysis; using Microsoft.PythonTools.Analysis.Documentation; -using Microsoft.PythonTools.Analysis.Infrastructure; using Microsoft.PythonTools.Intellisense; using Microsoft.PythonTools.Interpreter; using Microsoft.PythonTools.Interpreter.Ast; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; namespace Microsoft.Python.LanguageServer.Implementation { - public sealed partial class Server : ServerBase, ILogger, IPythonLanguageServer, IDisposable { + public sealed partial class Server : ServerBase, IPythonLanguageServer, IDisposable { /// /// Implements ability to execute module reload on the analyzer thread /// @@ -90,7 +92,8 @@ public void Analyze(CancellationToken cancel) { maxDocumentationLines = 100 }; - public Server() { + public Server(IServiceContainer services = null): base(services) { + AnalysisQueue = new AnalysisQueue(); AnalysisQueue.UnhandledException += Analysis_UnhandledException; @@ -100,10 +103,7 @@ public Server() { _disposableBag .Add(() => { foreach (var ext in _extensions.Values) { - ext?.Dispose(); - } - foreach (var ext in _oldExtensions.Values) { - (ext as IDisposable)?.Dispose(); + ext.Dispose(); } }) .Add(ProjectFiles) @@ -336,8 +336,6 @@ private void AnalysisQueued(Uri uri) { #endregion #region IPythonLanguageServer - public ILogger Logger => this; - public PythonAst GetCurrentAst(Uri documentUri) { ProjectFiles.GetEntry(documentUri, null, out var entry, out var tree); return entry.GetCurrentParse()?.Tree; diff --git a/src/LanguageServer/Impl/Implementation/ServerBase.cs b/src/LanguageServer/Impl/Implementation/ServerBase.cs index 4ecbee12f..5d9bfddd9 100644 --- a/src/LanguageServer/Impl/Implementation/ServerBase.cs +++ b/src/LanguageServer/Impl/Implementation/ServerBase.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,13 +16,25 @@ using System; using System.Threading; using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Logging; namespace Microsoft.Python.LanguageServer.Implementation { public abstract class ServerBase { + protected IServiceContainer Services { get; private set; } + public ILogger Logger { get; private set; } + + protected ServerBase(IServiceContainer services) { + SetServices(services); + } + /// - /// Doesn't do anything. Left here for legacy purpores + /// For tests /// - public IDisposable AllowRequestCancellation(int millisecondsTimeout = -1) => EmptyDisposable.Instance; + internal void SetServices(IServiceContainer services) { + Services = services; + Logger = services?.GetService(); + } #region Client Requests @@ -118,20 +129,7 @@ public virtual Task Rename(RenameParams @params, CancellationToke #endregion #region Server Requests - public event EventHandler OnShowMessage; - - public void ShowMessage(MessageType type, string message) - => OnShowMessage?.Invoke(this, new ShowMessageEventArgs { type = type, message = message }); - - public event EventHandler OnLogMessage; - - public void LogMessage(MessageType type, string message) - => OnLogMessage?.Invoke(this, new LogMessageEventArgs { type = type, message = message }); - - [Obsolete] - public event EventHandler OnTelemetry; - [Obsolete] - public void Telemetry(TelemetryEventArgs e) => OnTelemetry?.Invoke(this, e); + public void LogMessage(MessageType mt, string message) => Logger.Log(mt.ToTraceEventType(), message); public event EventHandler OnCommand; public void Command(CommandEventArgs e) => OnCommand?.Invoke(this, e); diff --git a/src/LanguageServer/Impl/Implementation/VolatileCounter.cs b/src/LanguageServer/Impl/Implementation/VolatileCounter.cs index b53703aa7..a5c2cf581 100644 --- a/src/LanguageServer/Impl/Implementation/VolatileCounter.cs +++ b/src/LanguageServer/Impl/Implementation/VolatileCounter.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/LanguageServer.Lifetime.cs b/src/LanguageServer/Impl/LanguageServer.Lifetime.cs index 4b8f7aef4..dd47fca46 100644 --- a/src/LanguageServer/Impl/LanguageServer.Lifetime.cs +++ b/src/LanguageServer/Impl/LanguageServer.Lifetime.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,8 +22,9 @@ using System.Threading.Tasks; using Microsoft.Extensions.FileSystemGlobbing; using Microsoft.Extensions.FileSystemGlobbing.Abstractions; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; using Newtonsoft.Json.Linq; using StreamJsonRpc; @@ -64,14 +65,12 @@ public async Task Shutdown() { // https://microsoft.github.io/language-server-protocol/specification#shutdown await _server.Shutdown(); _shutdown = true; - _idleTimeTracker.Dispose(); } [JsonRpcMethod("exit")] public async Task Exit() { await _server.Exit(); _sessionTokenSource.Cancel(); - _idleTimeTracker.Dispose(); // Per https://microsoft.github.io/language-server-protocol/specification#exit Environment.Exit(_shutdown ? 0 : 1); } diff --git a/src/LanguageServer/Impl/LanguageServer.cs b/src/LanguageServer/Impl/LanguageServer.cs index 001a9595a..716ea25d8 100644 --- a/src/LanguageServer/Impl/LanguageServer.cs +++ b/src/LanguageServer/Impl/LanguageServer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,12 +17,16 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.Python.LanguageServer.Services; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Disposables; +using Microsoft.Python.Core.Idle; +using Microsoft.Python.Core.Logging; +using Microsoft.Python.Core.Shell; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Core.Threading; +using Microsoft.Python.LanguageServer.Diagnostics; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using StreamJsonRpc; @@ -35,51 +39,46 @@ namespace Microsoft.Python.LanguageServer.Implementation { /// public sealed partial class LanguageServer : IDisposable { private readonly DisposableBag _disposables = new DisposableBag(nameof(LanguageServer)); - private readonly Server _server = new Server(); private readonly CancellationTokenSource _sessionTokenSource = new CancellationTokenSource(); - private readonly RestTextConverter _textConverter = new RestTextConverter(); - private readonly Dictionary _pendingDiagnostic = new Dictionary(); private readonly object _lock = new object(); private readonly Prioritizer _prioritizer = new Prioritizer(); private readonly CancellationTokenSource _shutdownCts = new CancellationTokenSource(); private IServiceContainer _services; - private IUIService _ui; - private ITelemetryService2 _telemetry; + private Server _server; + private ILogger _logger; + private ITelemetryService _telemetry; private JsonRpc _rpc; private JsonSerializer _jsonSerializer; private bool _filesLoaded; private PathsWatcher _pathsWatcher; - private IdleTimeTracker _idleTimeTracker; + private IIdleTimeTracker _idleTimeTracker; + private DiagnosticsPublisher _diagnosticsPublisher; private bool _watchSearchPaths; private string[] _searchPaths = Array.Empty(); public CancellationToken Start(IServiceContainer services, JsonRpc rpc) { + _server = new Server(services); _services = services; - _ui = services.GetService(); _rpc = rpc; - _jsonSerializer = services.GetService(); - _telemetry = services.GetService(); - var progress = services.GetService(); + _jsonSerializer = services.GetService(); + _idleTimeTracker = services.GetService(); + _logger = services.GetService(); + _telemetry = services.GetService(); var rpcTraceListener = new TelemetryRpcTraceListener(_telemetry); _rpc.TraceSource.Listeners.Add(rpcTraceListener); - _server.OnLogMessage += OnLogMessage; - _server.OnShowMessage += OnShowMessage; - _server.OnPublishDiagnostics += OnPublishDiagnostics; + _diagnosticsPublisher = new DiagnosticsPublisher(_server, services); _server.OnApplyWorkspaceEdit += OnApplyWorkspaceEdit; _server.OnRegisterCapability += OnRegisterCapability; _server.OnUnregisterCapability += OnUnregisterCapability; _server.AnalysisQueue.UnhandledException += OnAnalysisQueueUnhandledException; _disposables - .Add(() => _server.OnLogMessage -= OnLogMessage) - .Add(() => _server.OnShowMessage -= OnShowMessage) - .Add(() => _server.OnPublishDiagnostics -= OnPublishDiagnostics) .Add(() => _server.OnApplyWorkspaceEdit -= OnApplyWorkspaceEdit) .Add(() => _server.OnRegisterCapability -= OnRegisterCapability) .Add(() => _server.OnUnregisterCapability -= OnUnregisterCapability) @@ -87,7 +86,8 @@ public CancellationToken Start(IServiceContainer services, JsonRpc rpc) { .Add(() => _shutdownCts.Cancel()) .Add(_prioritizer) .Add(() => _pathsWatcher?.Dispose()) - .Add(() => _rpc.TraceSource.Listeners.Remove(rpcTraceListener)); + .Add(() => _rpc.TraceSource.Listeners.Remove(rpcTraceListener)) + .Add(_diagnosticsPublisher); return _sessionTokenSource.Token; } @@ -97,31 +97,7 @@ public void Dispose() { _server.Dispose(); } - [JsonObject] - private class PublishDiagnosticsParams { - [JsonProperty] - public Uri uri; - [JsonProperty] - public Diagnostic[] diagnostics; - } - #region Events - private void OnShowMessage(object sender, ShowMessageEventArgs e) => _ui.ShowMessage(e.message, e.type); - private void OnLogMessage(object sender, LogMessageEventArgs e) => _ui.LogMessage(e.message, e.type); - - private void OnPublishDiagnostics(object sender, PublishDiagnosticsEventArgs e) { - lock (_lock) { - // If list is empty (errors got fixed), publish immediately, - // otherwise throttle so user does not get spurious squiggles - // while typing normally. - var diags = e.diagnostics.ToArray(); - _pendingDiagnostic[e.uri] = diags; - if (diags.Length == 0) { - PublishPendingDiagnostics(); - } - } - } - private void OnApplyWorkspaceEdit(object sender, ApplyWorkspaceEditEventArgs e) => _rpc.NotifyWithParameterObjectAsync("workspace/applyEdit", e.@params).DoNotWait(); private void OnRegisterCapability(object sender, RegisterCapabilityEventArgs e) @@ -152,10 +128,8 @@ public async Task DidChangeConfiguration(JToken token, CancellationToken cancell settings.symbolsHierarchyDepthLimit = GetSetting(analysis, "symbolsHierarchyDepthLimit", 10); settings.symbolsHierarchyMaxSymbols = GetSetting(analysis, "symbolsHierarchyMaxSymbols", 1000); - _ui.SetLogLevel(GetLogLevel(analysis)); - - _idleTimeTracker?.Dispose(); - _idleTimeTracker = new IdleTimeTracker(settings.diagnosticPublishDelay, PublishPendingDiagnostics); + _logger.LogLevel = GetLogLevel(analysis).ToTraceEventType(); + _diagnosticsPublisher.PublishingDelay = settings.diagnosticPublishDelay; HandlePathWatchChange(token); @@ -176,7 +150,7 @@ public async Task DidChangeConfiguration(JToken token, CancellationToken cancell [JsonRpcMethod("workspace/didChangeWatchedFiles")] public async Task DidChangeWatchedFiles(JToken token, CancellationToken cancellationToken) { - using (await _prioritizer.DocumentChangePriorityAsync()) { + using (await _prioritizer.DocumentChangePriorityAsync(cancellationToken)) { await _server.DidChangeWatchedFiles(ToObject(token), cancellationToken); } } @@ -416,23 +390,6 @@ private MessageType GetLogLevel(JToken analysisKey) { return MessageType.Error; } - private void PublishPendingDiagnostics() { - List> list; - - lock (_lock) { - list = _pendingDiagnostic.ToList(); - _pendingDiagnostic.Clear(); - } - - foreach (var kvp in list) { - var parameters = new PublishDiagnosticsParams { - uri = kvp.Key, - diagnostics = kvp.Value.Where(d => d.severity != DiagnosticSeverity.Unspecified).ToArray() - }; - _rpc.NotifyWithParameterObjectAsync("textDocument/publishDiagnostics", parameters).DoNotWait(); - } - } - private void HandlePathWatchChange(JToken section) { var watchSearchPaths = GetSetting(section, "watchSearchPaths", true); if (!watchSearchPaths) { @@ -450,7 +407,7 @@ private void HandlePathWatchChange(JToken section) { _pathsWatcher = new PathsWatcher( _initParams.initializationOptions.searchPaths, () => _server.ReloadModulesAsync(CancellationToken.None).DoNotWait(), - _server + _services.GetService() ); } @@ -465,7 +422,7 @@ private void OnAnalysisQueueUnhandledException(object sender, UnhandledException } var te = Telemetry.CreateEventWithException("analysis_queue.unhandled_exception", ex); - _telemetry.SendTelemetry(te).DoNotWait(); + _telemetry.SendTelemetryAsync(te).DoNotWait(); } private class Prioritizer : IDisposable { diff --git a/src/LanguageServer/Impl/LanguageServerSettings.cs b/src/LanguageServer/Impl/LanguageServerSettings.cs index 0cc6917ed..c796205f0 100644 --- a/src/LanguageServer/Impl/LanguageServerSettings.cs +++ b/src/LanguageServer/Impl/LanguageServerSettings.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj b/src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj index 77702d03c..de6dba4a4 100644 --- a/src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj +++ b/src/LanguageServer/Impl/Microsoft.Python.LanguageServer.csproj @@ -42,6 +42,10 @@ PreserveNewest + + + + True diff --git a/src/LanguageServer/Impl/PathsWatcher.cs b/src/LanguageServer/Impl/PathsWatcher.cs index 0e12f4dc7..fe331385d 100644 --- a/src/LanguageServer/Impl/PathsWatcher.cs +++ b/src/LanguageServer/Impl/PathsWatcher.cs @@ -9,17 +9,19 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Threading; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core.Disposables; +using Microsoft.Python.Core.Logging; namespace Microsoft.Python.LanguageServer { internal sealed class PathsWatcher : IDisposable { @@ -33,7 +35,7 @@ internal sealed class PathsWatcher : IDisposable { public PathsWatcher(string[] paths, Action onChanged, ILogger log) { _log = log; - paths = paths != null ? paths.Where(p => Path.IsPathRooted(p)).ToArray() : Array.Empty(); + paths = paths != null ? paths.Where(Path.IsPathRooted).ToArray() : Array.Empty(); if (paths.Length == 0) { return; } @@ -47,7 +49,7 @@ public PathsWatcher(string[] paths, Action onChanged, ILogger log) { continue; } } catch (IOException ex) { - _log.TraceMessage($"Unable to access directory {p}, exception {ex.Message}"); + _log.Log(TraceEventType.Warning, $"Unable to access directory {p}, exception {ex.Message}"); continue; } @@ -68,7 +70,7 @@ public PathsWatcher(string[] paths, Action onChanged, ILogger log) { .Add(() => fsw.EnableRaisingEvents = false) .Add(fsw); } catch (ArgumentException ex) { - _log.TraceMessage($"Unable to create file watcher for {p}, exception {ex.Message}"); + _log.Log(TraceEventType.Warning, $"Unable to create file watcher for {p}, exception {ex.Message}"); } } } diff --git a/src/LanguageServer/Impl/Program.cs b/src/LanguageServer/Impl/Program.cs index 7485d60bf..2c91268fa 100644 --- a/src/LanguageServer/Impl/Program.cs +++ b/src/LanguageServer/Impl/Program.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -19,8 +18,11 @@ using System; using System.Diagnostics; using System.IO; +using Microsoft.Python.Core.IO; +using Microsoft.Python.Core.OS; +using Microsoft.Python.Core.Services; +using Microsoft.Python.Core.Threading; using Microsoft.Python.LanguageServer.Services; -using Microsoft.PythonTools.Analysis.Infrastructure; using Newtonsoft.Json; using StreamJsonRpc; using StreamJsonRpc.Protocol; @@ -45,9 +47,17 @@ public static void Main(string[] args) { rpc.TraceSource.Switch.Level = SourceLevels.Error; rpc.SynchronizationContext = new SingleThreadSynchronizationContext(); - services.AddService(new UIService(rpc)); - services.AddService(new ProgressService(rpc)); - services.AddService(new TelemetryService(rpc)); + var osp = new OSPlatform(); + services + .AddService(rpc) + .AddService(new Logger(rpc)) + .AddService(new UIService(rpc)) + .AddService(new ProgressService(rpc)) + .AddService(new TelemetryService(rpc)) + .AddService(new IdleTimeService()) + .AddService(osp) + .AddService(new FileSystem(osp)); + services.AddService(messageFormatter.JsonSerializer); var token = server.Start(services, rpc); diff --git a/src/LanguageServer/Impl/Properties/AssemblyInfo.cs b/src/LanguageServer/Impl/Properties/AssemblyInfo.cs index 3d3091ecb..d876237fb 100644 --- a/src/LanguageServer/Impl/Properties/AssemblyInfo.cs +++ b/src/LanguageServer/Impl/Properties/AssemblyInfo.cs @@ -9,12 +9,11 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System.Reflection; using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.PythonTools.TestAdapter, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] diff --git a/src/LanguageServer/Impl/Services/CoreShell.cs b/src/LanguageServer/Impl/Services/CoreShell.cs index 5ff8d23b1..352f7be0d 100644 --- a/src/LanguageServer/Impl/Services/CoreShell.cs +++ b/src/LanguageServer/Impl/Services/CoreShell.cs @@ -9,13 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Diagnostics; +using Microsoft.Python.Core.Services; +using Microsoft.Python.Core.Shell; using Microsoft.PythonTools.LanguageServer.Services; namespace Microsoft.Python.LanguageServer.Services { diff --git a/src/LanguageServer/Impl/Services/ICoreShell.cs b/src/LanguageServer/Impl/Services/ICoreShell.cs index 3da5bb822..143e9c98d 100644 --- a/src/LanguageServer/Impl/Services/ICoreShell.cs +++ b/src/LanguageServer/Impl/Services/ICoreShell.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.Python.LanguageServer; +using Microsoft.Python.Core; namespace Microsoft.PythonTools.LanguageServer.Services { /// diff --git a/src/LanguageServer/Impl/Services/Logger.cs b/src/LanguageServer/Impl/Services/Logger.cs new file mode 100644 index 000000000..e9cff7c3d --- /dev/null +++ b/src/LanguageServer/Impl/Services/Logger.cs @@ -0,0 +1,65 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License + +using System; +using System.Diagnostics; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Logging; +using StreamJsonRpc; + +namespace Microsoft.Python.LanguageServer.Services { + internal sealed class Logger: ILogger { + private readonly JsonRpc _rpc; + + public Logger(JsonRpc rpc) { + _rpc = rpc; + } + + public TraceEventType LogLevel { get; set; } = TraceEventType.Error; + public void Log(TraceEventType eventType, string message) + => LogMessageAsync(message, eventType).DoNotWait(); + public void Log(TraceEventType eventType, IFormattable message) + => Log(eventType, message.ToString()); + + public void Log(TraceEventType eventType, params object[] parameters) { + var sb = new StringBuilder(); + for(var i = 0; i < parameters.Length; i++) { + sb.Append('{'); + sb.Append(i.ToString()); + sb.Append("} "); + } + Log(eventType, sb.ToString().FormatUI(parameters)); + } + + public Task LogMessageAsync(string message, TraceEventType eventType) { + if (eventType > LogLevel && eventType != TraceEventType.Information) { + return Task.CompletedTask; + } + var parameters = new LogMessageParams { + type = eventType.ToMessageType(), + message = message + }; + return _rpc.NotifyWithParameterObjectAsync("window/logMessage", parameters); + } + + [Serializable] + private class LogMessageParams { + public MessageType type; + public string message; + } + } +} diff --git a/src/LanguageServer/Impl/Services/ProgressService.cs b/src/LanguageServer/Impl/Services/ProgressService.cs index 93bb6a016..1443913dc 100644 --- a/src/LanguageServer/Impl/Services/ProgressService.cs +++ b/src/LanguageServer/Impl/Services/ProgressService.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Threading.Tasks; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.LanguageServer; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Shell; using StreamJsonRpc; namespace Microsoft.Python.LanguageServer.Services { diff --git a/src/LanguageServer/Impl/Services/TelemetryService.cs b/src/LanguageServer/Impl/Services/TelemetryService.cs index ca91b3072..353887179 100644 --- a/src/LanguageServer/Impl/Services/TelemetryService.cs +++ b/src/LanguageServer/Impl/Services/TelemetryService.cs @@ -9,19 +9,19 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Reflection; using System.Threading.Tasks; +using Microsoft.Python.Core.Shell; using StreamJsonRpc; namespace Microsoft.Python.LanguageServer.Services { #pragma warning disable CS0612 // Type or member is obsolete - public sealed class TelemetryService : ITelemetryService, ITelemetryService2 { + public sealed class TelemetryService : ITelemetryService { #pragma warning restore CS0612 // Type or member is obsolete private readonly JsonRpc _rpc; private readonly string _plsVersion; @@ -35,10 +35,7 @@ public TelemetryService(JsonRpc rpc) { #endif } - [Obsolete] - public Task SendTelemetry(object o) => Task.CompletedTask; - - public Task SendTelemetry(TelemetryEvent telemetryEvent) { + public Task SendTelemetryAsync(TelemetryEvent telemetryEvent) { telemetryEvent.Properties["plsVersion"] = _plsVersion; return _rpc.NotifyWithParameterObjectAsync("telemetry/event", telemetryEvent); } diff --git a/src/LanguageServer/Impl/Services/TraceEventTypeExtensions.cs b/src/LanguageServer/Impl/Services/TraceEventTypeExtensions.cs new file mode 100644 index 000000000..da9abd9a2 --- /dev/null +++ b/src/LanguageServer/Impl/Services/TraceEventTypeExtensions.cs @@ -0,0 +1,40 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Diagnostics; + +namespace Microsoft.Python.LanguageServer.Services { + internal static class TraceEventTypeExtensions { + public static MessageType ToMessageType(this TraceEventType eventType) { + var mt = MessageType.Error; + switch (eventType) { + case TraceEventType.Critical: + case TraceEventType.Error: + mt = MessageType.Error; + break; + case TraceEventType.Warning: + mt = MessageType.Warning; + break; + case TraceEventType.Information: + mt = MessageType.Info; + break; + case TraceEventType.Verbose: + mt = MessageType.Log; + break; + } + return mt; + } + } +} diff --git a/src/LanguageServer/Impl/Services/UIService.cs b/src/LanguageServer/Impl/Services/UIService.cs index 3c0c7e088..4b45dda49 100644 --- a/src/LanguageServer/Impl/Services/UIService.cs +++ b/src/LanguageServer/Impl/Services/UIService.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,63 +8,44 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; +using System.Diagnostics; +using System.Linq; using System.Threading.Tasks; +using Microsoft.Python.Core.Shell; using StreamJsonRpc; namespace Microsoft.Python.LanguageServer.Services { - public sealed class UIService : IUIService, ILogger { + public sealed class UIService : IUIService { private readonly JsonRpc _rpc; - private MessageType _logLevel = MessageType.Error; public UIService(JsonRpc rpc) { _rpc = rpc; } - public Task ShowMessage(string message, MessageType messageType) { + + public Task ShowMessageAsync(string message, TraceEventType eventType) { var parameters = new ShowMessageRequestParams { - type = messageType, + type = eventType.ToMessageType(), message = message }; return _rpc.NotifyWithParameterObjectAsync("window/showMessage", parameters); } - public Task ShowMessage(string message, MessageActionItem[] actions, MessageType messageType) { + public async Task ShowMessageAsync(string message, string[] actions, TraceEventType eventType) { var parameters = new ShowMessageRequestParams { - type = messageType, + type = eventType.ToMessageType(), message = message, - actions = actions + actions = actions.Select(a => new MessageActionItem { title = a }).ToArray() }; - return _rpc.InvokeWithParameterObjectAsync("window/showMessageRequest", parameters); - } - - [Serializable] - class LogMessageParams { - public MessageType type; - public string message; + var result = await _rpc.InvokeWithParameterObjectAsync("window/showMessageRequest", parameters); + return result?.title; } - public Task LogMessage(string message, MessageType messageType) { - if(messageType > _logLevel) { - return Task.CompletedTask; - } - var parameters = new LogMessageParams { - type = messageType, - message = message - }; - return _rpc.NotifyWithParameterObjectAsync("window/logMessage", parameters); - } - - public Task SetStatusBarMessage(string message) + public Task SetStatusBarMessageAsync(string message) => _rpc.NotifyWithParameterObjectAsync("window/setStatusBarMessage", message); - - public void TraceMessage(string message) => LogMessage(message.ToString(), MessageType.Info); - public void TraceMessage(IFormattable message) => TraceMessage(message.ToString()); - - public void SetLogLevel(MessageType logLevel) => _logLevel = logLevel; } } diff --git a/src/LanguageServer/Impl/Telemetry.cs b/src/LanguageServer/Impl/Telemetry.cs index ee0592c70..95c5ac89e 100644 --- a/src/LanguageServer/Impl/Telemetry.cs +++ b/src/LanguageServer/Impl/Telemetry.cs @@ -17,7 +17,8 @@ using System; using System.Diagnostics; using System.Reflection; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Shell; using StreamJsonRpc; namespace Microsoft.Python.LanguageServer.Implementation { @@ -50,9 +51,9 @@ public static TelemetryEvent CreateEventWithException(string eventName, Exceptio } internal class TelemetryRpcTraceListener : TraceListener { - private readonly ITelemetryService2 _telemetryService; + private readonly ITelemetryService _telemetryService; - public TelemetryRpcTraceListener(ITelemetryService2 telemetryService) { + public TelemetryRpcTraceListener(ITelemetryService telemetryService) { _telemetryService = telemetryService; } @@ -95,7 +96,7 @@ public override void TraceData(TraceEventCache eventCache, string source, TraceE var e = Telemetry.CreateEventWithException("rpc.exception", exception); e.Properties["method"] = method; - _telemetryService.SendTelemetry(e).DoNotWait(); + _telemetryService.SendTelemetryAsync(e).DoNotWait(); } public override void Write(string message) { } diff --git a/src/PLS.sln b/src/PLS.sln index a5f064534..630b965cb 100644 --- a/src/PLS.sln +++ b/src/PLS.sln @@ -15,6 +15,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Analysis.E EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Analysis.Engine.Tests", "Analysis\Engine\Test\Microsoft.Python.Analysis.Engine.Tests.csproj", "{1CFA416B-6932-432F-8C75-34B5615D7664}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Core", "Core\Impl\Microsoft.Python.Core.csproj", "{84EB780C-55D0-4DEF-B5F7-D63696E11764}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Core.Tests", "Core\Test\Microsoft.Python.Core.Tests.csproj", "{AFEA5563-CED6-4932-8BB7-2A83D797FB36}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Parsing", "Parsing\Impl\Microsoft.Python.Parsing.csproj", "{C59C4212-95B8-43FA-B909-60652FA5E8E0}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Parsing.Tests", "Parsing\Test\Microsoft.Python.Parsing.Tests.csproj", "{FF6696BA-5071-439C-A811-A46A2650C689}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Analysis", "Analysis\Ast\Impl\Microsoft.Python.Analysis.csproj", "{615CC909-CDDD-49B1-87B8-CE8A637613E9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Analysis.Core", "Analysis\Core\Impl\Microsoft.Python.Analysis.Core.csproj", "{2C8DE250-41F4-4FC5-A661-76E2A4172891}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Python.Analysis.Tests", "Analysis\Ast\Test\Microsoft.Python.Analysis.Tests.csproj", "{D8D85896-5DB0-4FA6-B744-910A272C39F9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +51,34 @@ Global {1CFA416B-6932-432F-8C75-34B5615D7664}.Debug|Any CPU.Build.0 = Debug|Any CPU {1CFA416B-6932-432F-8C75-34B5615D7664}.Release|Any CPU.ActiveCfg = Release|Any CPU {1CFA416B-6932-432F-8C75-34B5615D7664}.Release|Any CPU.Build.0 = Release|Any CPU + {84EB780C-55D0-4DEF-B5F7-D63696E11764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {84EB780C-55D0-4DEF-B5F7-D63696E11764}.Debug|Any CPU.Build.0 = Debug|Any CPU + {84EB780C-55D0-4DEF-B5F7-D63696E11764}.Release|Any CPU.ActiveCfg = Release|Any CPU + {84EB780C-55D0-4DEF-B5F7-D63696E11764}.Release|Any CPU.Build.0 = Release|Any CPU + {AFEA5563-CED6-4932-8BB7-2A83D797FB36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AFEA5563-CED6-4932-8BB7-2A83D797FB36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AFEA5563-CED6-4932-8BB7-2A83D797FB36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AFEA5563-CED6-4932-8BB7-2A83D797FB36}.Release|Any CPU.Build.0 = Release|Any CPU + {C59C4212-95B8-43FA-B909-60652FA5E8E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C59C4212-95B8-43FA-B909-60652FA5E8E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C59C4212-95B8-43FA-B909-60652FA5E8E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C59C4212-95B8-43FA-B909-60652FA5E8E0}.Release|Any CPU.Build.0 = Release|Any CPU + {FF6696BA-5071-439C-A811-A46A2650C689}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF6696BA-5071-439C-A811-A46A2650C689}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF6696BA-5071-439C-A811-A46A2650C689}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FF6696BA-5071-439C-A811-A46A2650C689}.Release|Any CPU.Build.0 = Release|Any CPU + {615CC909-CDDD-49B1-87B8-CE8A637613E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {615CC909-CDDD-49B1-87B8-CE8A637613E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {615CC909-CDDD-49B1-87B8-CE8A637613E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {615CC909-CDDD-49B1-87B8-CE8A637613E9}.Release|Any CPU.Build.0 = Release|Any CPU + {2C8DE250-41F4-4FC5-A661-76E2A4172891}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C8DE250-41F4-4FC5-A661-76E2A4172891}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C8DE250-41F4-4FC5-A661-76E2A4172891}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C8DE250-41F4-4FC5-A661-76E2A4172891}.Release|Any CPU.Build.0 = Release|Any CPU + {D8D85896-5DB0-4FA6-B744-910A272C39F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D8D85896-5DB0-4FA6-B744-910A272C39F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D8D85896-5DB0-4FA6-B744-910A272C39F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D8D85896-5DB0-4FA6-B744-910A272C39F9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -46,6 +88,13 @@ Global {B1F6F2EA-6465-4D63-9457-D856F17EDF38} = {80AA38A1-3E82-4B87-BB21-FDEDD2CC87E6} {55679AE9-8C3D-4F26-A0B5-10A5B2F1789F} = {C465393D-145E-4695-A7DB-AF55951BD533} {1CFA416B-6932-432F-8C75-34B5615D7664} = {80AA38A1-3E82-4B87-BB21-FDEDD2CC87E6} + {84EB780C-55D0-4DEF-B5F7-D63696E11764} = {C465393D-145E-4695-A7DB-AF55951BD533} + {AFEA5563-CED6-4932-8BB7-2A83D797FB36} = {80AA38A1-3E82-4B87-BB21-FDEDD2CC87E6} + {C59C4212-95B8-43FA-B909-60652FA5E8E0} = {C465393D-145E-4695-A7DB-AF55951BD533} + {FF6696BA-5071-439C-A811-A46A2650C689} = {80AA38A1-3E82-4B87-BB21-FDEDD2CC87E6} + {615CC909-CDDD-49B1-87B8-CE8A637613E9} = {C465393D-145E-4695-A7DB-AF55951BD533} + {2C8DE250-41F4-4FC5-A661-76E2A4172891} = {C465393D-145E-4695-A7DB-AF55951BD533} + {D8D85896-5DB0-4FA6-B744-910A272C39F9} = {80AA38A1-3E82-4B87-BB21-FDEDD2CC87E6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {ABC12ED7-0EC8-4219-8A14-A058F7942D92} diff --git a/src/Analysis/Engine/Impl/Parsing/AsciiString.cs b/src/Parsing/Impl/AsciiString.cs similarity index 55% rename from src/Analysis/Engine/Impl/Parsing/AsciiString.cs rename to src/Parsing/Impl/AsciiString.cs index 7de586afe..96bf66ae0 100644 --- a/src/Analysis/Engine/Impl/Parsing/AsciiString.cs +++ b/src/Parsing/Impl/AsciiString.cs @@ -9,15 +9,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. +using System; using System.Collections.Generic; +using System.Linq; -namespace Microsoft.PythonTools.Parsing { - public sealed class AsciiString { +namespace Microsoft.Python.Parsing { + public sealed class AsciiString: IEquatable { public AsciiString(byte[] bytes, string str) { Bytes = bytes; String = str; @@ -27,20 +29,28 @@ public AsciiString(byte[] bytes, string str) { public string String { get; } - public override string ToString() { - return String; - } + public override string ToString() => String; public override bool Equals(object obj) { - AsciiString other = obj as AsciiString; - if (other != null) { - return String == other.String; + if (ReferenceEquals(null, obj)) { + return false; + } + if (ReferenceEquals(this, obj)) { + return true; } - return false; + return obj is AsciiString other && Equals(other); } public override int GetHashCode() { - return String.GetHashCode(); + unchecked { + return ((Bytes != null ? Bytes.GetHashCode() : 0) * 397) ^ (String != null ? String.GetHashCode() : 0); + } + } + + public bool Equals(AsciiString other) { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Bytes.SequenceEqual(other.Bytes) && string.Equals(String, other.String); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/AndExpression.cs b/src/Parsing/Impl/Ast/AndExpression.cs similarity index 64% rename from src/Analysis/Engine/Impl/Parsing/Ast/AndExpression.cs rename to src/Parsing/Impl/Ast/AndExpression.cs index 4636dcded..c0ba6f464 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/AndExpression.cs +++ b/src/Parsing/Impl/Ast/AndExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class AndExpression : Expression { public AndExpression(Expression left, Expression right, int andIndex) { Left = left ?? throw new ArgumentNullException(nameof(left)); @@ -31,11 +32,7 @@ public AndExpression(Expression left, Expression right, int andIndex) { public Expression Right { get; } public int AndIndex { get; } - public override string NodeName { - get { - return "and expression"; - } - } + public override string NodeName => "and expression"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { @@ -45,16 +42,21 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - BinaryExpression.BinaryToCodeString(res, ast, format, this, Left, Right, "and"); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + await Left.WalkAsync(walker, cancellationToken); + if (Right != null) { + await Right.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return Left.GetLeadingWhiteSpace(ast); - } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) + => BinaryExpression.BinaryToCodeString(res, ast, format, this, Left, Right, "and"); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - Left.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Left.GetLeadingWhiteSpace(ast); + + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Left.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/Arg.cs b/src/Parsing/Impl/Ast/Arg.cs similarity index 78% rename from src/Analysis/Engine/Impl/Parsing/Ast/Arg.cs rename to src/Parsing/Impl/Ast/Arg.cs index d357cb616..cdd15157a 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/Arg.cs +++ b/src/Parsing/Impl/Ast/Arg.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public sealed class Arg : Node { private int? _endIndexIncludingWhitespace; @@ -37,28 +38,32 @@ public int EndIndexIncludingWhitespace { set => _endIndexIncludingWhitespace = value; } - public override string ToString() { - return base.ToString() + ":" + NameExpression; - } + public override string ToString() => base.ToString() + ":" + NameExpression; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { + Expression?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { if (Expression != null) { - Expression.Walk(walker); + await Expression.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } - internal string GetPreceedingWhiteSpaceDefaultNull(PythonAst ast) { + string GetPreceedingWhiteSpaceDefaultNull(PythonAst ast) { if (NameExpression != null) { return NameExpression.GetPreceedingWhiteSpaceDefaultNull(ast); } return Expression?.GetPreceedingWhiteSpaceDefaultNull(ast); } - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) - { + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (NameExpression != null) { if (Name == "*" || Name == "**") { NameExpression.AppendCodeString(res, ast, format); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/AssertStatement.cs b/src/Parsing/Impl/Ast/AssertStatement.cs similarity index 58% rename from src/Analysis/Engine/Impl/Parsing/Ast/AssertStatement.cs rename to src/Parsing/Impl/Ast/AssertStatement.cs index ad707c49e..de407caef 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/AssertStatement.cs +++ b/src/Parsing/Impl/Ast/AssertStatement.cs @@ -9,50 +9,54 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class AssertStatement : Statement { - private readonly Expression _test, _message; - public AssertStatement(Expression test, Expression message) { - _test = test; - _message = message; + Test = test; + Message = message; } - public Expression Test { - get { return _test; } - } + public Expression Test { get; } - public Expression Message { - get { return _message; } - } + public Expression Message { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_test != null) { - _test.Walk(walker); + Test?.Walk(walker); + Message?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Test != null) { + await Test.WalkAsync(walker, cancellationToken); } - if (_message != null) { - _message.Walk(walker); + if (Message != null) { + await Message.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("assert"); - _test.AppendCodeString(res, ast, format); - if (_message != null) { + Test.AppendCodeString(res, ast, format); + if (Message != null) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append(','); - _message.AppendCodeString(res, ast, format); + Message.AppendCodeString(res, ast, format); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/AssignmentStatement.cs b/src/Parsing/Impl/Ast/AssignmentStatement.cs similarity index 69% rename from src/Analysis/Engine/Impl/Parsing/Ast/AssignmentStatement.cs rename to src/Parsing/Impl/Ast/AssignmentStatement.cs index 7f6393fba..35b56e68c 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/AssignmentStatement.cs +++ b/src/Parsing/Impl/Ast/AssignmentStatement.cs @@ -9,47 +9,56 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class AssignmentStatement : Statement { // _left.Length is 1 for simple assignments like "x = 1" // _left.Length will be 3 for "x = y = z = 1" private readonly Expression[] _left; - private readonly Expression _right; public AssignmentStatement(Expression[] left, Expression right) { _left = left; - _right = right; + Right = right; } - public IList Left { - get { return _left; } - } + public IList Left => _left; - public Expression Right { - get { return _right; } - } + public Expression Right { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - foreach (Expression e in _left) { + foreach (var e in _left) { e.Walk(walker); } - _right.Walk(walker); + Right?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var e in _left) { + await e.WalkAsync(walker, cancellationToken); + } + if (Right != null) { + await Right.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var lhs = this.GetListWhiteSpace(ast); - for (int i = 0; i < Left.Count; i++) { + for (var i = 0; i < Left.Count; i++) { if (lhs != null && i != 0) { format.Append( res, @@ -61,31 +70,31 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co res.Append("="); } Left[i].AppendCodeString( - res, - ast, + res, + ast, format, i != 0 && format.SpacesAroundAssignmentOperator != null ? - format.SpacesAroundAssignmentOperator.Value ? " " : "" : + format.SpacesAroundAssignmentOperator.Value ? " " : string.Empty : null ); } if (lhs != null) { format.Append( res, - format.SpacesAroundAssignmentOperator, - " ", - "", + format.SpacesAroundAssignmentOperator, + " ", + string.Empty, lhs[lhs.Length - 1] ); } res.Append("="); Right.AppendCodeString( - res, - ast, - format, - format.SpacesAroundAssignmentOperator != null ? - format.SpacesAroundAssignmentOperator.Value ? " " : "" : + res, + ast, + format, + format.SpacesAroundAssignmentOperator != null ? + format.SpacesAroundAssignmentOperator.Value ? " " : string.Empty : null ); } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/AugmentedAssignStatement.cs b/src/Parsing/Impl/Ast/AugmentedAssignStatement.cs similarity index 54% rename from src/Analysis/Engine/Impl/Parsing/Ast/AugmentedAssignStatement.cs rename to src/Parsing/Impl/Ast/AugmentedAssignStatement.cs index 8fb82ec0a..ecb660e4e 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/AugmentedAssignStatement.cs +++ b/src/Parsing/Impl/Ast/AugmentedAssignStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,63 +8,59 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class AugmentedAssignStatement : Statement { - private readonly PythonOperator _op; - private readonly Expression _left; - private readonly Expression _right; - public AugmentedAssignStatement(PythonOperator op, Expression left, Expression right) { - _op = op; - _left = left; - _right = right; + Operator = op; + Left = left; + Right = right; } - public PythonOperator Operator { - get { return _op; } - } + public PythonOperator Operator { get; } - public Expression Left { - get { return _left; } - } + public Expression Left { get; } - public Expression Right { - get { return _right; } - } + public Expression Right { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_left != null) { - _left.Walk(walker); + Left?.Walk(walker); + Right?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Left != null) { + await Left.WalkAsync(walker, cancellationToken); } - if (_right != null) { - _right.Walk(walker); + if (Right != null) { + await Right.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - _left.AppendCodeString(res, ast, format); + Left.AppendCodeString(res, ast, format); res.Append(this.GetPreceedingWhiteSpace(ast)); - res.Append(_op.ToCodeString()); + res.Append(Operator.ToCodeString()); res.Append('='); - _right.AppendCodeString(res, ast, format); + Right.AppendCodeString(res, ast, format); } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return _left.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Left.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - _left.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Left.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/AwaitExpression.cs b/src/Parsing/Impl/Ast/AwaitExpression.cs similarity index 66% rename from src/Analysis/Engine/Impl/Parsing/Ast/AwaitExpression.cs rename to src/Parsing/Impl/Ast/AwaitExpression.cs index 8dbb8e68a..6b8df18f6 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/AwaitExpression.cs +++ b/src/Parsing/Impl/Ast/AwaitExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,53 +8,52 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { // New in Pep429 for Python 3.5. Await is an expression with a return value. // x = await z // TODO: The return value (x) is provided by calling ... public class AwaitExpression : Expression { - private readonly Expression _expression; - public AwaitExpression(Expression expression) { - _expression = expression; + Expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } - internal override string CheckAugmentedAssign() { - return CheckAssign(); - } - - public override string NodeName { - get { - return "await expression"; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } } + await walker.PostWalkAsync(this, cancellationToken); } + internal override string CheckAugmentedAssign() => CheckAssign(); + + public override string NodeName => "await expression"; + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("await"); if (!this.IsAltForm(ast)) { - _expression.AppendCodeString(res, ast, format); + Expression.AppendCodeString(res, ast, format); var itemWhiteSpace = this.GetListWhiteSpace(ast); if (itemWhiteSpace != null) { res.Append(","); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/BackQuoteExpression.cs b/src/Parsing/Impl/Ast/BackQuoteExpression.cs similarity index 66% rename from src/Analysis/Engine/Impl/Parsing/Ast/BackQuoteExpression.cs rename to src/Parsing/Impl/Ast/BackQuoteExpression.cs index 363e6627f..7e1c247d3 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/BackQuoteExpression.cs +++ b/src/Parsing/Impl/Ast/BackQuoteExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,38 +8,43 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class BackQuoteExpression : Expression { - private readonly Expression _expression; - public BackQuoteExpression(Expression expression) { - _expression = expression; + Expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append('`'); - _expression.AppendCodeString(res, ast, format); + Expression.AppendCodeString(res, ast, format); if (!this.IsMissingCloseGrouping(ast)) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append('`'); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/BinaryExpression.cs b/src/Parsing/Impl/Ast/BinaryExpression.cs similarity index 78% rename from src/Analysis/Engine/Impl/Parsing/Ast/BinaryExpression.cs rename to src/Parsing/Impl/Ast/BinaryExpression.cs index 39ef3d894..28650a2c0 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/BinaryExpression.cs +++ b/src/Parsing/Impl/Ast/BinaryExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,11 +16,15 @@ using System; using System.Diagnostics; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public partial class BinaryExpression : Expression { public BinaryExpression(PythonOperator op, Expression left, Expression right, int operatorIndex) { - if (op == PythonOperator.None) throw new ArgumentException("bad operator"); + if (op == PythonOperator.None) { + throw new ArgumentException("bad operator"); + } Operator = op; Left = left ?? throw new ArgumentNullException(nameof(left)); @@ -56,23 +59,31 @@ private bool IsComparison() { return false; } - public override string NodeName { - get { - return "binary operator"; - } - } + public override string NodeName => "binary operator"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - Left.Walk(walker); - Right.Walk(walker); + Left?.Walk(walker); + Right?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Left != null) { + await Left.WalkAsync(walker, cancellationToken); + } + if (Right != null) { + await Right.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - Expression left = Left; - Expression right = Right; + var left = Left; + var right = Right; string op1, op2; if (Operator == PythonOperator.NotIn) { @@ -103,7 +114,7 @@ internal static void BinaryToCodeString(StringBuilder res, PythonAst ast, CodeFo res, format.SpacesAroundBinaryOperators, " ", - Char.IsLetter(op1[0]) ? " " : "", // spaces required for is not, not in, etc... + char.IsLetter(op1[0]) ? " " : "", // spaces required for is not, not in, etc... node.GetPreceedingWhiteSpace(ast) ); @@ -116,11 +127,11 @@ internal static void BinaryToCodeString(StringBuilder res, PythonAst ast, CodeFo format.SpacesAroundBinaryOperators != null ? format.SpacesAroundBinaryOperators.Value ? " " : - (Char.IsLetter(op1[0]) ? " " : "") : + (char.IsLetter(op1[0]) ? " " : string.Empty) : null ); } else { - Debug.Assert(Char.IsLetter(op1[0])); + Debug.Assert(char.IsLetter(op1[0])); res.Append(op1); res.Append(node.GetSecondWhiteSpace(ast)); @@ -132,19 +143,15 @@ internal static void BinaryToCodeString(StringBuilder res, PythonAst ast, CodeFo public int GetIndexOfSecondOp(PythonAst ast) { if (Operator == PythonOperator.NotIn) { return OperatorIndex + 3 + this.GetSecondWhiteSpace(ast).Length; - } else if (Operator == PythonOperator.IsNot) { + } + if (Operator == PythonOperator.IsNot) { return OperatorIndex + 2 + this.GetSecondWhiteSpace(ast).Length; - } else { - return -1; } + return -1; } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return Left.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Left.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - Left.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Left.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/BreakStatement.cs b/src/Parsing/Impl/Ast/BreakStatement.cs similarity index 71% rename from src/Analysis/Engine/Impl/Parsing/Ast/BreakStatement.cs rename to src/Parsing/Impl/Ast/BreakStatement.cs index de3864463..c0543889e 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/BreakStatement.cs +++ b/src/Parsing/Impl/Ast/BreakStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class BreakStatement : Statement { public BreakStatement() { } @@ -27,9 +28,15 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); - res.Append("break"); + res.Append("break"); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/CallExpression.cs b/src/Parsing/Impl/Ast/CallExpression.cs similarity index 69% rename from src/Analysis/Engine/Impl/Parsing/Ast/CallExpression.cs rename to src/Parsing/Impl/Ast/CallExpression.cs index 70944aaaa..dcee3b745 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/CallExpression.cs +++ b/src/Parsing/Impl/Ast/CallExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,18 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; -using System.Linq; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { - +namespace Microsoft.Python.Parsing.Ast { public class CallExpression : Expression { private readonly Arg[] _args; @@ -33,15 +32,22 @@ public CallExpression(Expression target, Arg[] args) { public IList Args => _args; public bool NeedsLocalsDictionary() { - NameExpression nameExpr = Target as NameExpression; - if (nameExpr == null) return false; + if (!(Target is NameExpression nameExpr)) { + return false; + } if (_args.Length == 0) { - if (nameExpr.Name == "locals") return true; - if (nameExpr.Name == "vars") return true; - if (nameExpr.Name == "dir") return true; - return false; - } else if (_args.Length == 1 && (nameExpr.Name == "dir" || nameExpr.Name == "vars")) { + switch (nameExpr.Name) { + case "locals": + case "vars": + case "dir": + return true; + default: + return false; + } + } + + if (_args.Length == 1 && (nameExpr.Name == "dir" || nameExpr.Name == "vars")) { if (_args[0].Name == "*" || _args[0].Name == "**") { // could be splatting empty list or dict resulting in 0-param call which needs context return true; @@ -52,32 +58,40 @@ public bool NeedsLocalsDictionary() { return true; } } else { - if (nameExpr.Name == "eval") return true; - if (nameExpr.Name == "execfile") return true; + switch (nameExpr.Name) { + case "eval": + case "execfile": + return true; + } } return false; } - internal override string CheckAssign() { - return "can't assign to function call"; - } + internal override string CheckAssign() => "can't assign to function call"; - internal override string CheckDelete() { - return "can't delete function call"; - } + internal override string CheckDelete() => "can't delete function call"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { + Target?.Walk(walker); + foreach (var arg in _args.MaybeEnumerate()) { + arg.Walk(walker); + } + } + walker.PostWalk(this); + } + + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { if (Target != null) { - Target.Walk(walker); + await Target.WalkAsync(walker, cancellationToken); } - if (_args != null) { - foreach (Arg arg in _args) { - arg.Walk(walker); - } + foreach (var arg in _args.MaybeEnumerate()) { + await arg.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { @@ -86,9 +100,9 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo res, format.SpaceBeforeCallParen, " ", - "", + string.Empty, this.GetPreceedingWhiteSpaceDefaultNull(ast) - ); + ); res.Append('('); @@ -98,8 +112,8 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } } else { var listWhiteSpace = format.SpaceBeforeComma == null ? this.GetListWhiteSpace(ast) : null; - var spaceAfterComma = format.SpaceAfterComma.HasValue ? (format.SpaceAfterComma.Value ? " " : "") : (string)null; - for (int i = 0; i < _args.Length; i++) { + var spaceAfterComma = format.SpaceAfterComma.HasValue ? (format.SpaceAfterComma.Value ? " " : string.Empty) : (string)null; + for (var i = 0; i < _args.Length; i++) { if (i > 0) { if (format.SpaceBeforeComma == true) { res.Append(' '); @@ -108,7 +122,7 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } res.Append(','); } else if (format.SpaceWithinCallParens != null) { - _args[i].AppendCodeString(res, ast, format, format.SpaceWithinCallParens.Value ? " " : ""); + _args[i].AppendCodeString(res, ast, format, format.SpaceWithinCallParens.Value ? " " : string.Empty); continue; } @@ -121,16 +135,16 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo res.Append(","); } } - + if (!this.IsMissingCloseGrouping(ast)) { - if (Args.Count != 0 || + if (Args.Count != 0 || format.SpaceWithinEmptyCallArgumentList == null || - !String.IsNullOrWhiteSpace(this.GetSecondWhiteSpaceDefaultNull(ast))) { + !string.IsNullOrWhiteSpace(this.GetSecondWhiteSpaceDefaultNull(ast))) { format.Append( res, format.SpaceWithinCallParens, " ", - "", + string.Empty, this.GetSecondWhiteSpaceDefaultNull(ast) ); } @@ -143,7 +157,7 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo /// /// False if not within the call. -1 if it is in /// an argument not in Args. - internal bool GetArgumentAtIndex(PythonAst ast, int index, out int argIndex) { + public bool GetArgumentAtIndex(PythonAst ast, int index, out int argIndex) { argIndex = -1; if (index <= Target.EndIndex || index > EndIndex) { return false; @@ -152,7 +166,7 @@ internal bool GetArgumentAtIndex(PythonAst ast, int index, out int argIndex) { return true; } - for (int i = 0; i < Args.Count; ++i) { + for (var i = 0; i < Args.Count; ++i) { var a = Args[i]; if (index <= a.EndIndexIncludingWhitespace) { argIndex = i; @@ -168,12 +182,8 @@ internal bool GetArgumentAtIndex(PythonAst ast, int index, out int argIndex) { return false; } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return Target.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Target.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - Target.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Target.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ClassDefinition.cs b/src/Parsing/Impl/Ast/ClassDefinition.cs similarity index 67% rename from src/Analysis/Engine/Impl/Parsing/Ast/ClassDefinition.cs rename to src/Parsing/Impl/Ast/ClassDefinition.cs index faed394e1..fed23c9ea 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ClassDefinition.cs +++ b/src/Parsing/Impl/Ast/ClassDefinition.cs @@ -9,30 +9,26 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ClassDefinition : ScopeStatement { - private int _headerIndex; private readonly NameExpression/*!*/ _name; private readonly Statement _body; private readonly Arg[] _bases; private DecoratorStatement _decorators; - private PythonVariable _variable; // Variable corresponding to the class name - private PythonVariable _modVariable; // Variable for the the __module__ (module name) - private PythonVariable _docVariable; // Variable for the __doc__ attribute - private PythonVariable _modNameVariable; // Variable for the module's __name__ - private PythonVariable _classVariable; // Variable for the classes __class__ cell var on 3.x - - public ClassDefinition(NameExpression/*!*/ name, Arg[] bases, Statement body) { + public ClassDefinition(NameExpression/*!*/ name, Arg[] bases, Statement body) { _name = name; _bases = bases; _body = body; @@ -40,18 +36,11 @@ public ClassDefinition(NameExpression/*!*/ name, Arg[] bases, Statement body) { public override int KeywordLength => 5; - public int HeaderIndex { - get { return _headerIndex; } - set { _headerIndex = value; } - } + public int HeaderIndex { get; set; } - public override string/*!*/ Name { - get { return _name.Name ?? ""; } - } + public override string/*!*/ Name => _name.Name ?? ""; - public NameExpression/*!*/ NameExpression { - get { return _name; } - } + public NameExpression/*!*/ NameExpression => _name; public Arg[] Bases => _bases ?? Array.Empty(); @@ -65,61 +54,46 @@ public DecoratorStatement Decorators { /// /// Gets the variable that this class definition was assigned to. /// - public PythonVariable Variable { - get { return _variable; } - set { _variable = value; } - } + public PythonVariable Variable { get; set; } /// /// Gets the variable reference for the specific assignment to the variable for this class definition. /// - public PythonReference GetVariableReference(PythonAst ast) { - return GetVariableReference(this, ast); - } + public PythonReference GetVariableReference(PythonAst ast) => GetVariableReference(this, ast); - internal PythonVariable ClassVariable { - get { return _classVariable; } - set { _classVariable = value; } - } + /// + /// Variable for the classes __class__ cell var on 3.x + /// + internal PythonVariable ClassVariable { get; set; } - internal PythonVariable ModVariable { - get { return _modVariable; } - set { _modVariable = value; } - } + /// + /// Variable for the the __module__ (module name) + /// + internal PythonVariable ModVariable { get; set; } - internal PythonVariable DocVariable { - get { return _docVariable; } - set { _docVariable = value; } - } + /// + /// Variable for the __doc__ attribute + /// + internal PythonVariable DocVariable { get; set; } - internal PythonVariable ModuleNameVariable { - get { return _modNameVariable; } - set { _modNameVariable = value; } - } + /// + /// Variable for the module's __name__ + /// + internal PythonVariable ModuleNameVariable { get; set; } internal override bool HasLateBoundVariableSets { - get { - return base.HasLateBoundVariableSets || NeedsLocalsDictionary; - } - set { - base.HasLateBoundVariableSets = value; - } - } - - internal override bool NeedsLocalContext { - get { - return true; - } + get => base.HasLateBoundVariableSets || NeedsLocalsDictionary; + set => base.HasLateBoundVariableSets = value; } - internal override bool ExposesLocalVariable(PythonVariable variable) { - return true; - } + public override bool NeedsLocalContext => true; + + internal override bool ExposesLocalVariable(PythonVariable variable) => true; internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable) { - if (name == "__class__" && _classVariable != null) { + if (name == "__class__" && ClassVariable != null) { // 3.x has a cell var called __class__ which can be bound by inner scopes - variable = _classVariable; + variable = ClassVariable; return true; } @@ -127,11 +101,10 @@ internal override bool TryBindOuter(ScopeStatement from, string name, bool allow } internal override PythonVariable BindReference(PythonNameBinder binder, string name) { - PythonVariable variable; // Python semantics: The variables bound local in the class // scope are accessed by name - the dictionary behavior of classes - if (TryGetVariable(name, out variable)) { + if (TryGetVariable(name, out var variable)) { // TODO: This results in doing a dictionary lookup to get/set the local, // when it should probably be an uninitialized check / global lookup for gets // and a direct set @@ -146,7 +119,7 @@ internal override PythonVariable BindReference(PythonNameBinder binder, string n // Try to bind in outer scopes, if we have an unqualified exec we need to leave the // variables as free for the same reason that locals are accessed by name. - for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent) { + for (var parent = Parent; parent != null; parent = parent.Parent) { if (parent.TryBindOuter(this, name, true, out variable)) { return variable; } @@ -158,24 +131,35 @@ internal override PythonVariable BindReference(PythonNameBinder binder, string n public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { _name?.Walk(walker); + _decorators?.Walk(walker); + foreach (var b in _bases.MaybeEnumerate()) { + b.Walk(walker); + } + _body?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (_name != null) { + await _name.WalkAsync(walker, cancellationToken); + } + if (_decorators != null) { - _decorators.Walk(walker); + await _decorators.WalkAsync(walker, cancellationToken); } - if (_bases != null) { - foreach (var b in _bases) { - b.Walk(walker); - } + foreach (var b in _bases.MaybeEnumerate()) { + await b.WalkAsync(walker, cancellationToken); } if (_body != null) { - _body.Walk(walker); + await _body.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } - public SourceLocation Header { - get { return GlobalParent.IndexToLocation(_headerIndex); } - } + public SourceLocation Header => GlobalParent.IndexToLocation(HeaderIndex); internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (Decorators != null) { @@ -209,7 +193,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co this, Bases.Length, (i, sb) => { - if(format.SpaceWithinClassDeclarationParens != null && i == 0) { + if (format.SpaceWithinClassDeclarationParens != null && i == 0) { // need to remove any leading whitespace which was preserved for // the 1st param, and then force the correct whitespace. Bases[i].AppendCodeString(sb, ast, format, format.SpaceWithinClassDeclarationParens.Value ? " " : ""); @@ -223,11 +207,11 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co res.Append(' '); } } - + if (!this.IsAltForm(ast) && !this.IsMissingCloseGrouping(ast)) { - if (Bases.Length != 0 || + if (Bases.Length != 0 || format.SpaceWithinEmptyBaseClassList == null || - !String.IsNullOrWhiteSpace(this.GetFourthWhiteSpace(ast))) { + !string.IsNullOrWhiteSpace(this.GetFourthWhiteSpace(ast))) { format.Append( res, format.SpaceWithinClassDeclarationParens, diff --git a/src/Parsing/Impl/Ast/Comprehension.cs b/src/Parsing/Impl/Ast/Comprehension.cs new file mode 100644 index 000000000..7fa73c3ad --- /dev/null +++ b/src/Parsing/Impl/Ast/Comprehension.cs @@ -0,0 +1,171 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Parsing.Ast { + public abstract class ComprehensionIterator : Node { + } + + public abstract class Comprehension : Expression { + public abstract IList Iterators { get; } + public abstract override string NodeName { get; } + + public abstract override void Walk(PythonWalker walker); + + internal void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Expression item) { + if (!string.IsNullOrEmpty(start)) { + format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); + res.Append(start); + } + + item.AppendCodeString(res, ast, format); + + for (var i = 0; i < Iterators.Count; i++) { + Iterators[i].AppendCodeString(res, ast, format); + } + + if (!string.IsNullOrEmpty(end)) { + res.Append(this.GetSecondWhiteSpace(ast)); + res.Append(end); + } + } + } + + public sealed class ListComprehension : Comprehension { + private readonly ComprehensionIterator[] _iterators; + + public ListComprehension(Expression item, ComprehensionIterator[] iterators) { + Item = item; + _iterators = iterators; + } + + public Expression Item { get; } + + public override IList Iterators => _iterators; + + public override string NodeName => "list comprehension"; + + public override void Walk(PythonWalker walker) { + if (walker.Walk(this)) { + Item?.Walk(walker); + foreach (var ci in _iterators.MaybeEnumerate()) { + ci.Walk(walker); + } + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Item != null) { + await Item.WalkAsync(walker, cancellationToken); + } + foreach (var ci in _iterators.MaybeEnumerate()) { + await ci.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => AppendCodeString(res, ast, format, "[", this.IsMissingCloseGrouping(ast) ? "" : "]", Item); + } + + public sealed class SetComprehension : Comprehension { + private readonly ComprehensionIterator[] _iterators; + + public SetComprehension(Expression item, ComprehensionIterator[] iterators) { + Item = item; + _iterators = iterators; + } + + public Expression Item { get; } + + public override IList Iterators => _iterators; + + public override string NodeName => "set comprehension"; + + public override void Walk(PythonWalker walker) { + if (walker.Walk(this)) { + Item?.Walk(walker); + foreach (var ci in _iterators.MaybeEnumerate()) { + ci.Walk(walker); + } + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Item != null) { + await Item.WalkAsync(walker, cancellationToken); + } + foreach (var ci in _iterators.MaybeEnumerate()) { + await ci.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => AppendCodeString(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", Item); + } + + public sealed class DictionaryComprehension : Comprehension { + private readonly ComprehensionIterator[] _iterators; + private readonly SliceExpression _value; + + public DictionaryComprehension(SliceExpression value, ComprehensionIterator[] iterators) { + _value = value; + _iterators = iterators; + } + + public Expression Key => _value.SliceStart; + + public Expression Value => _value.SliceStop; + + public override IList Iterators => _iterators; + + public override string NodeName => "dict comprehension"; + + public override void Walk(PythonWalker walker) { + if (walker.Walk(this)) { + _value?.Walk(walker); + foreach (var ci in _iterators.MaybeEnumerate()) { + ci.Walk(walker); + } + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (_value != null) { + await _value.WalkAsync(walker, cancellationToken); + } + foreach (var ci in _iterators.MaybeEnumerate()) { + await ci.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) + => AppendCodeString(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", _value); + } +} diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ComprehensionFor.cs b/src/Parsing/Impl/Ast/ComprehensionFor.cs similarity index 55% rename from src/Analysis/Engine/Impl/Parsing/Ast/ComprehensionFor.cs rename to src/Parsing/Impl/Ast/ComprehensionFor.cs index 681e91fa1..8efb417ef 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ComprehensionFor.cs +++ b/src/Parsing/Impl/Ast/ComprehensionFor.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,76 +8,71 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ComprehensionFor : ComprehensionIterator { - private readonly Expression _lhs, _list; - private readonly bool _isAsync; - public ComprehensionFor(Expression lhs, Expression list) { - _lhs = lhs; - _list = list; + Left = lhs; + List = list; } public ComprehensionFor(Expression lhs, Expression list, bool isAsync) : this(lhs, list) { - _isAsync = isAsync; + IsAsync = isAsync; } - public Expression Left { - get { return _lhs; } - } + public Expression Left { get; } - public Expression List { - get { return _list; } - } + public Expression List { get; } - public bool IsAsync => _isAsync; + public bool IsAsync { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_lhs != null) { - _lhs.Walk(walker); - } - if (_list != null) { - _list.Walk(walker); - } + Left?.Walk(walker); + List?.Walk(walker); } walker.PostWalk(this); } - public int GetIndexOfFor(PythonAst ast) { - if (!IsAsync) { - return StartIndex; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Left != null) { + await Left.WalkAsync(walker, cancellationToken); + } + if (List != null) { + await List.WalkAsync(walker, cancellationToken); + } } - return StartIndex + 5 + this.GetPreceedingWhiteSpace(ast).Length; + await walker.PostWalkAsync(this, cancellationToken); } - public int GetIndexOfIn(PythonAst ast) { - if (this.IsIncompleteNode(ast)) { - return -1; - } - return Left.EndIndex + this.GetSecondWhiteSpace(ast).Length; - } + public int GetIndexOfFor(PythonAst ast) + => !IsAsync ? StartIndex : StartIndex + 5 + this.GetPreceedingWhiteSpace(ast).Length; + + public int GetIndexOfIn(PythonAst ast) + => this.IsIncompleteNode(ast) ? -1 : Left.EndIndex + this.GetSecondWhiteSpace(ast).Length; internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - if (_isAsync) { + if (IsAsync) { res.Append(this.GetThirdWhiteSpace(ast)); res.Append("async"); } res.Append(this.GetPreceedingWhiteSpace(ast)); res.Append("for"); - _lhs.AppendCodeString(res, ast, format); + Left.AppendCodeString(res, ast, format); if (!this.IsIncompleteNode(ast)) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append("in"); - _list.AppendCodeString(res, ast, format); + List.AppendCodeString(res, ast, format); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ComprehensionIf.cs b/src/Parsing/Impl/Ast/ComprehensionIf.cs similarity index 62% rename from src/Analysis/Engine/Impl/Parsing/Ast/ComprehensionIf.cs rename to src/Parsing/Impl/Ast/ComprehensionIf.cs index 7f5880001..9ae87ebb7 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ComprehensionIf.cs +++ b/src/Parsing/Impl/Ast/ComprehensionIf.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,41 +8,45 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ComprehensionIf : ComprehensionIterator { - private readonly Expression _test; - private int _headerIndex; - public ComprehensionIf(Expression test) { - _test = test; + Test = test; } - public Expression Test { - get { return _test; } - } + public Expression Test { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_test != null) { - _test.Walk(walker); - } + Test?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Test != null) { + await Test.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { res.Append(this.GetPreceedingWhiteSpace(ast)); res.Append("if"); - _test.AppendCodeString(res, ast, format); + Test.AppendCodeString(res, ast, format); } - public int HeaderIndex { get { return _headerIndex; } set { _headerIndex = value; } } + public int HeaderIndex { get; set; } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ConditionalExpression.cs b/src/Parsing/Impl/Ast/ConditionalExpression.cs similarity index 72% rename from src/Analysis/Engine/Impl/Parsing/Ast/ConditionalExpression.cs rename to src/Parsing/Impl/Ast/ConditionalExpression.cs index 224d84df3..017a5245f 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ConditionalExpression.cs +++ b/src/Parsing/Impl/Ast/ConditionalExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ConditionalExpression : Expression { public ConditionalExpression(Expression testExpression, Expression trueExpression, Expression falseExpression, int ifIndex, int elseIndex) { Test = testExpression; @@ -43,6 +44,21 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Test != null) { + await Test.WalkAsync(walker, cancellationToken); + } + if (TrueExpression != null) { + await TrueExpression.WalkAsync(walker, cancellationToken); + } + if (FalseExpression != null) { + await FalseExpression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { TrueExpression.AppendCodeString(res, ast, format); res.Append(this.GetPreceedingWhiteSpace(ast)); @@ -61,12 +77,8 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return TrueExpression.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => TrueExpression.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - TrueExpression.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => TrueExpression.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ConstantExpression.cs b/src/Parsing/Impl/Ast/ConstantExpression.cs similarity index 69% rename from src/Analysis/Engine/Impl/Parsing/Ast/ConstantExpression.cs rename to src/Parsing/Impl/Ast/ConstantExpression.cs index ff2dc79ac..59960280f 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ConstantExpression.cs +++ b/src/Parsing/Impl/Ast/ConstantExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,39 +8,28 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Generic; using System.Globalization; using System.Numerics; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ConstantExpression : Expression { - private readonly object _value; - public ConstantExpression(object value) { - _value = value; + Value = value; } - public object Value { - get { - return _value; - } - } + public object Value { get; } - internal override string CheckAssign() { - if (_value == null) { - return "assignment to None"; - } - - return "can't assign to literal"; - } + internal override string CheckAssign() => Value == null ? "assignment to None" : "can't assign to literal"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { @@ -49,19 +37,21 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } - public override string NodeName { - get { - return "literal"; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { } + await walker.PostWalkAsync(this, cancellationToken); } + public override string NodeName => "literal"; + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var verbatimPieces = this.GetVerbatimNames(ast); var verbatimComments = this.GetListWhiteSpace(ast); if (verbatimPieces != null) { // string+ / bytes+, such as "abc" "abc", which can spawn multiple lines, and // have comments in between the peices. - for (int i = 0; i < verbatimPieces.Length; i++) { + for (var i = 0; i < verbatimPieces.Length; i++) { if (verbatimComments != null && i < verbatimComments.Length) { format.ReflowComment(res, verbatimComments[i]); } @@ -73,14 +63,10 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } } - private static bool IsNegativeZero(double value) { - return (value == 0.0) && double.IsNegativeInfinity(1.0 / value); - } + private static bool IsNegativeZero(double value) => (value == 0.0) && double.IsNegativeInfinity(1.0 / value); // ToString does not distinguish between negative zero and positive zero, but repr() does, and so should we. - private static string NegativeZeroAwareToString(double n) { - return IsNegativeZero(n) ? "-0" : n.ToString("g", nfi); - } + private static string NegativeZeroAwareToString(double n) => IsNegativeZero(n) ? "-0" : n.ToString("g", nfi); private void AppendEscapedString(StringBuilder res, string s, bool escape8bitStrings) { res.Append("'"); @@ -92,7 +78,7 @@ private void AppendEscapedString(StringBuilder res, string s, bool escape8bitStr case '\'': res.Append("\\'"); break; case '\\': res.Append("\\\\"); break; default: - ushort cp = (ushort)c; + var cp = (ushort)c; if (cp > 0xFF) { res.AppendFormat(CultureInfo.InvariantCulture, "\\u{0:x04}", cp); } else if (cp < 0x20 || (escape8bitStrings && cp >= 0x7F)) { @@ -107,26 +93,26 @@ private void AppendEscapedString(StringBuilder res, string s, bool escape8bitStr } public string GetConstantRepr(PythonLanguageVersion version, bool escape8bitStrings = false) { - if (_value == null) { + if (Value == null) { return "None"; - } else if (_value is AsciiString) { - StringBuilder res = new StringBuilder(); + } else if (Value is AsciiString) { + var res = new StringBuilder(); if (!version.Is2x()) { res.Append("b"); } - AppendEscapedString(res, ((AsciiString)_value).String, escape8bitStrings); + AppendEscapedString(res, ((AsciiString)Value).String, escape8bitStrings); return res.ToString(); - } else if (_value is string) { - StringBuilder res = new StringBuilder(); + } else if (Value is string) { + var res = new StringBuilder(); if (!version.Is3x()) { res.Append("u"); } - AppendEscapedString(res, (string)_value, escape8bitStrings); + AppendEscapedString(res, (string)Value, escape8bitStrings); return res.ToString(); - } else if (_value is Complex) { - Complex n = (Complex)_value; - string real = NegativeZeroAwareToString(n.Real); - string imag = NegativeZeroAwareToString(n.Imaginary); + } else if (Value is Complex) { + var n = (Complex)Value; + var real = NegativeZeroAwareToString(n.Real); + var imag = NegativeZeroAwareToString(n.Imaginary); if (n.Real != 0) { if (!imag.StartsWithOrdinal("-")) { imag = "+" + imag; @@ -135,13 +121,12 @@ public string GetConstantRepr(PythonLanguageVersion version, bool escape8bitStri } else { return imag + "j"; } - } else if (_value is BigInteger) { + } else if (Value is BigInteger) { if (!version.Is3x()) { - return "{0}L".FormatInvariant(_value); + return "{0}L".FormatInvariant(Value); } - } else if (_value is double) { - double n = (double)_value; - string s = NegativeZeroAwareToString(n); + } else if (Value is double n) { + var s = NegativeZeroAwareToString(n); // If there's no fractional part, and this is not NaN or +-Inf, G format will not include the decimal // point. This is okay if we're using scientific notation as this implies float, but if not, add the // decimal point to indicate the type, just like Python repr() does. @@ -149,12 +134,12 @@ public string GetConstantRepr(PythonLanguageVersion version, bool escape8bitStri s += ".0"; } return s; - } else if (_value is IFormattable) { - return ((IFormattable)_value).ToString(null, CultureInfo.InvariantCulture); + } else if (Value is IFormattable) { + return ((IFormattable)Value).ToString(null, CultureInfo.InvariantCulture); } // TODO: We probably need to handle more primitives here - return _value.ToString(); + return Value.ToString(); } private static NumberFormatInfo _nfi; @@ -162,7 +147,7 @@ public string GetConstantRepr(PythonLanguageVersion version, bool escape8bitStri private static NumberFormatInfo nfi { get { if (_nfi == null) { - NumberFormatInfo numberFormatInfo = ((CultureInfo)CultureInfo.InvariantCulture.Clone()).NumberFormat; + var numberFormatInfo = ((CultureInfo)CultureInfo.InvariantCulture.Clone()).NumberFormat; // The CLI formats as "Infinity", but CPython formats differently numberFormatInfo.PositiveInfinitySymbol = "inf"; numberFormatInfo.NegativeInfinitySymbol = "-inf"; diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ContinueStatement.cs b/src/Parsing/Impl/Ast/ContinueStatement.cs similarity index 73% rename from src/Analysis/Engine/Impl/Parsing/Ast/ContinueStatement.cs rename to src/Parsing/Impl/Ast/ContinueStatement.cs index e4cf71a0a..8ee939161 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ContinueStatement.cs +++ b/src/Parsing/Impl/Ast/ContinueStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ContinueStatement : Statement { public ContinueStatement() { @@ -28,6 +29,13 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); + } + + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("continue"); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/DecoratorStatement.cs b/src/Parsing/Impl/Ast/DecoratorStatement.cs similarity index 79% rename from src/Analysis/Engine/Impl/Parsing/Ast/DecoratorStatement.cs rename to src/Parsing/Impl/Ast/DecoratorStatement.cs index 90b685f8d..f0443a7eb 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/DecoratorStatement.cs +++ b/src/Parsing/Impl/Ast/DecoratorStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class DecoratorStatement : Statement { public DecoratorStatement(Expression[] decorators) { Decorators = decorators ?? Array.Empty(); @@ -28,13 +29,22 @@ public DecoratorStatement(Expression[] decorators) { public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - foreach (var decorator in Decorators) { + foreach (var decorator in Decorators.MaybeEnumerate()) { decorator?.Walk(walker); } } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var decorator in Decorators.MaybeEnumerate()) { + await decorator?.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var decorateWhiteSpace = this.GetNamesWhiteSpace(ast); for (int i = 0, curWhiteSpace = 0; i < Decorators.Length; i++) { diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/DelStatement.cs b/src/Parsing/Impl/Ast/DelStatement.cs similarity index 55% rename from src/Analysis/Engine/Impl/Parsing/Ast/DelStatement.cs rename to src/Parsing/Impl/Ast/DelStatement.cs index 12a1188a0..5da27a348 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/DelStatement.cs +++ b/src/Parsing/Impl/Ast/DelStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class DelStatement : Statement { private readonly Expression[] _expressions; @@ -26,23 +28,27 @@ public DelStatement(Expression[] expressions) { _expressions = expressions; } - public IList Expressions { - get { return _expressions; } - } + public IList Expressions => _expressions; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expressions != null) { - foreach (Expression expression in _expressions) { - expression.Walk(walker); - } + foreach (var expression in _expressions.MaybeEnumerate()) { + expression.Walk(walker); } } walker.PostWalk(this); } - internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - ListExpression.AppendItems(res, ast, format, "del", "", this, Expressions); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var expression in _expressions.MaybeEnumerate()) { + await expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } + + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) + => ListExpression.AppendItems(res, ast, format, "del", string.Empty, this, Expressions); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/DictionaryExpression.cs b/src/Parsing/Impl/Ast/DictionaryExpression.cs similarity index 64% rename from src/Analysis/Engine/Impl/Parsing/Ast/DictionaryExpression.cs rename to src/Parsing/Impl/Ast/DictionaryExpression.cs index e32ad7c81..6bf6e3470 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/DictionaryExpression.cs +++ b/src/Parsing/Impl/Ast/DictionaryExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { - +namespace Microsoft.Python.Parsing.Ast { public class DictionaryExpression : Expression { private readonly SliceExpression[] _items; @@ -26,30 +27,29 @@ public DictionaryExpression(params SliceExpression[] items) { _items = items; } - public IList Items { - get { return _items; } - } + public IList Items => _items; - public override string NodeName { - get { - return "dictionary display"; - } - } + public override string NodeName => "dictionary display"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_items != null) { - foreach (SliceExpression s in _items) { - s.Walk(walker); - } + foreach (var s in _items.MaybeEnumerate()) { + s.Walk(walker); } } walker.PostWalk(this); } - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - ListExpression.AppendItems(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", this, Items); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var s in _items.MaybeEnumerate()) { + await s.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => ListExpression.AppendItems(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", this, Items); } /// @@ -61,9 +61,7 @@ public DictKeyOnlyExpression(Expression expr) : base(expr, null, null, false) { public Expression Key => SliceStart; - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - Key?.AppendCodeString(res, ast, format); - } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => Key?.AppendCodeString(res, ast, format); } /// @@ -75,8 +73,6 @@ public DictValueOnlyExpression(Expression expr) : base(null, expr, null, false) public Expression Value => SliceStop; - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - Value?.AppendCodeString(res, ast, format); - } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => Value?.AppendCodeString(res, ast, format); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/DottedName.cs b/src/Parsing/Impl/Ast/DottedName.cs similarity index 80% rename from src/Analysis/Engine/Impl/Parsing/Ast/DottedName.cs rename to src/Parsing/Impl/Ast/DottedName.cs index afd0af2a4..a63590f01 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/DottedName.cs +++ b/src/Parsing/Impl/Ast/DottedName.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class DottedName : Node { private readonly NameExpression[] _names; @@ -29,10 +29,12 @@ public DottedName(NameExpression[]/*!*/ names) { public IList Names => _names; public virtual string MakeString() { - if (_names.Length == 0) return string.Empty; + if (_names.Length == 0) { + return string.Empty; + } - StringBuilder ret = new StringBuilder(_names[0].Name); - for (int i = 1; i < _names.Length; i++) { + var ret = new StringBuilder(_names[0].Name); + for (var i = 1; i < _names.Length; i++) { ret.Append('.'); ret.Append(_names[i].Name); } @@ -41,11 +43,16 @@ public virtual string MakeString() { public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - ; } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var whitespace = this.GetNamesWhiteSpace(ast); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/EmptyStatement.cs b/src/Parsing/Impl/Ast/EmptyStatement.cs similarity index 74% rename from src/Analysis/Engine/Impl/Parsing/Ast/EmptyStatement.cs rename to src/Parsing/Impl/Ast/EmptyStatement.cs index c8f7912dd..ac72c941f 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/EmptyStatement.cs +++ b/src/Parsing/Impl/Ast/EmptyStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { - +namespace Microsoft.Python.Parsing.Ast { public class EmptyStatement : Statement { public EmptyStatement() { } @@ -30,6 +30,12 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("pass"); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ErrorExpression.cs b/src/Parsing/Impl/Ast/ErrorExpression.cs similarity index 71% rename from src/Analysis/Engine/Impl/Parsing/Ast/ErrorExpression.cs rename to src/Parsing/Impl/Ast/ErrorExpression.cs index 691b1d420..e9297a651 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ErrorExpression.cs +++ b/src/Parsing/Impl/Ast/ErrorExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ErrorExpression : Expression { private readonly Expression _preceding; private readonly string _verbatimImage; @@ -30,13 +31,10 @@ private ErrorExpression(string verbatimImage, Expression preceding, ErrorExpress public ErrorExpression(string verbatimImage, Expression preceding) : this(verbatimImage, preceding, null) { } - public ErrorExpression AddPrefix(string verbatimImage, Expression preceding) { - return new ErrorExpression(verbatimImage, preceding, this); - } + public ErrorExpression AddPrefix(string verbatimImage, Expression preceding) => new ErrorExpression(verbatimImage, preceding, this); public string VerbatimImage => _verbatimImage; - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { _preceding?.AppendCodeString(res, ast, format); res.Append(_verbatimImage ?? ""); @@ -50,5 +48,17 @@ public override void Walk(PythonWalker walker) { } walker.PostWalk(this); } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (_preceding != null) { + await _preceding.WalkAsync(walker, cancellationToken); + } + if (_nested != null) { + await _nested.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ErrorParameter.cs b/src/Parsing/Impl/Ast/ErrorParameter.cs similarity index 73% rename from src/Analysis/Engine/Impl/Parsing/Ast/ErrorParameter.cs rename to src/Parsing/Impl/Ast/ErrorParameter.cs index 6a1687ab6..a68758c6a 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ErrorParameter.cs +++ b/src/Parsing/Impl/Ast/ErrorParameter.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,26 +8,22 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { class ErrorParameter : Parameter { - private readonly Expression _error; - public ErrorParameter(Expression errorValue, ParameterKind kind) : base(null, kind) { - _error = errorValue; + Error = errorValue; } - public Expression Error => _error; + public Expression Error { get; } - internal override void AppendParameterName(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) { - _error?.AppendCodeString(res, ast, format, leadingWhiteSpace); - } + internal override void AppendParameterName(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) => Error?.AppendCodeString(res, ast, format, leadingWhiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ErrorStatement.cs b/src/Parsing/Impl/Ast/ErrorStatement.cs similarity index 67% rename from src/Analysis/Engine/Impl/Parsing/Ast/ErrorStatement.cs rename to src/Parsing/Impl/Ast/ErrorStatement.cs index af55be118..a7eb61655 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ErrorStatement.cs +++ b/src/Parsing/Impl/Ast/ErrorStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ErrorStatement : Statement { private readonly Statement[] _preceeding; @@ -33,11 +35,20 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - foreach (var preceeding in _preceeding) { + foreach (var preceeding in _preceeding.MaybeEnumerate()) { preceeding.Walk(walker); } } walker.PostWalk(this); } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var preceeding in _preceeding.MaybeEnumerate()) { + await preceeding.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ExecStatement.cs b/src/Parsing/Impl/Ast/ExecStatement.cs similarity index 66% rename from src/Analysis/Engine/Impl/Parsing/Ast/ExecStatement.cs rename to src/Parsing/Impl/Ast/ExecStatement.cs index a934cb911..90adbd54a 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ExecStatement.cs +++ b/src/Parsing/Impl/Ast/ExecStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Linq; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { - +namespace Microsoft.Python.Parsing.Ast { public class ExecStatement : Statement { private readonly Expression _code, _locals, _globals; private readonly TupleExpression _codeTuple; @@ -30,38 +30,40 @@ public ExecStatement(Expression code, Expression locals, Expression globals, Tup _codeTuple = codeTuple; } - public Expression Code { - get { return _code ?? _codeTuple?.Items.ElementAtOrDefault(0); } - } + public Expression Code => _code ?? _codeTuple?.Items.ElementAtOrDefault(0); - public Expression Locals { - get { return _locals ?? _codeTuple?.Items.ElementAtOrDefault(2); } - } + public Expression Locals => _locals ?? _codeTuple?.Items.ElementAtOrDefault(2); - public Expression Globals { - get { return _globals ?? _codeTuple?.Items.ElementAtOrDefault(1); } - } + public Expression Globals => _globals ?? _codeTuple?.Items.ElementAtOrDefault(1); - public bool NeedsLocalsDictionary() { - return Globals == null && Locals == null; - } + public bool NeedsLocalsDictionary() => Globals == null && Locals == null; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { + _code?.Walk(walker); + _codeTuple?.Walk(walker); + _locals?.Walk(walker); + _globals?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { if (_code != null) { - _code.Walk(walker); + await _code.WalkAsync(walker, cancellationToken); } if (_codeTuple != null) { - _codeTuple.Walk(walker); + await _codeTuple.WalkAsync(walker, cancellationToken); } if (_locals != null) { - _locals.Walk(walker); + await _locals.WalkAsync(walker, cancellationToken); } if (_globals != null) { - _globals.Walk(walker); + await _globals.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/Expression.cs b/src/Parsing/Impl/Ast/Expression.cs similarity index 74% rename from src/Analysis/Engine/Impl/Parsing/Ast/Expression.cs rename to src/Parsing/Impl/Ast/Expression.cs index 2e5c5a936..f1db8a3db 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/Expression.cs +++ b/src/Parsing/Impl/Ast/Expression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,20 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public abstract class Expression : Node { internal Expression() { } - internal virtual string CheckAssign() { - return "can't assign to " + NodeName; - } + internal virtual string CheckAssign() => "can't assign to " + NodeName; internal virtual string CheckAugmentedAssign() { if (CheckAssign() != null) { @@ -32,8 +29,6 @@ internal virtual string CheckAugmentedAssign() { return null; } - internal virtual string CheckDelete() { - return "can't delete " + NodeName; - } + internal virtual string CheckDelete() => "can't delete " + NodeName; } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ExpressionStatement.cs b/src/Parsing/Impl/Ast/ExpressionStatement.cs similarity index 54% rename from src/Analysis/Engine/Impl/Parsing/Ast/ExpressionStatement.cs rename to src/Parsing/Impl/Ast/ExpressionStatement.cs index a90535d6d..02790875c 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ExpressionStatement.cs +++ b/src/Parsing/Impl/Ast/ExpressionStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,59 +8,56 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { - - public class ExpressionStatement : Statement { - private readonly Expression _expression; +namespace Microsoft.Python.Parsing.Ast { + public class ExpressionStatement : Statement { public ExpressionStatement(Expression expression) { - _expression = expression; + Expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + public override string Documentation { get { - ConstantExpression ce = _expression as ConstantExpression; - if (ce != null) { - if (ce.Value is string) { - return ce.Value as string; - } else if (ce.Value is AsciiString) { - return ((AsciiString)ce.Value).String; + if (Expression is ConstantExpression ce) { + if (ce.Value is string s) { + return s; } + return ce.Value is AsciiString ? ((AsciiString)ce.Value).String : null; } return null; } } - internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - _expression.AppendCodeString(res, ast, format); - } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => Expression.AppendCodeString(res, ast, format); - public override string GetLeadingWhiteSpace(PythonAst ast) { - return _expression.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Expression.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - _expression.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Expression.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ExpressionWithAnnotation.cs b/src/Parsing/Impl/Ast/ExpressionWithAnnotation.cs similarity index 58% rename from src/Analysis/Engine/Impl/Parsing/Ast/ExpressionWithAnnotation.cs rename to src/Parsing/Impl/Ast/ExpressionWithAnnotation.cs index 8943c4618..4574f101f 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ExpressionWithAnnotation.cs +++ b/src/Parsing/Impl/Ast/ExpressionWithAnnotation.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,32 +8,31 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ExpressionWithAnnotation : Expression { - private readonly Expression _expression; - private readonly Expression _annotation; - public ExpressionWithAnnotation(Expression expression, Expression annotation) { - _expression = expression; - _annotation = annotation; + Expression = expression; + Annotation = annotation; } public override string ToString() { - if (_annotation != null) { - return _expression.ToString() + ":" + _annotation.ToString(); + if (Annotation != null) { + return Expression.ToString() + ":" + Annotation.ToString(); } - return _expression.ToString(); + return Expression.ToString(); } - public Expression Expression => _expression; - public Expression Annotation => _annotation; + public Expression Expression { get; } + public Expression Annotation { get; } public override string NodeName => "annotated expression"; @@ -44,23 +42,35 @@ public override string ToString() { public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - _expression.Walk(walker); - _annotation?.Walk(walker); + Expression.Walk(walker); + Annotation?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } + if (Annotation != null) { + await Annotation.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - _expression.AppendCodeString(res, ast, format); - if (_annotation != null) { + Expression.AppendCodeString(res, ast, format); + if (Annotation != null) { // For now, use same formatting as around an assignment if (format.SpacesAroundAssignmentOperator == null) { - res.Append(this.GetSecondWhiteSpaceDefaultNull(ast) ?? ""); + res.Append(this.GetSecondWhiteSpaceDefaultNull(ast) ?? string.Empty); } else if (format.SpacesAroundAssignmentOperator == true) { res.Append(' '); } res.Append(':'); - _annotation.AppendCodeString(res, ast, format); + Annotation.AppendCodeString(res, ast, format); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ForStatement.cs b/src/Parsing/Impl/Ast/ForStatement.cs similarity index 77% rename from src/Analysis/Engine/Impl/Parsing/Ast/ForStatement.cs rename to src/Parsing/Impl/Ast/ForStatement.cs index 3b43408e2..874249ce6 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ForStatement.cs +++ b/src/Parsing/Impl/Ast/ForStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ForStatement : Statement, IMaybeAsyncStatement { private int? _keywordEndIndex; @@ -56,6 +57,24 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Left != null) { + await Left.WalkAsync(walker, cancellationToken); + } + if (List != null) { + await List.WalkAsync(walker, cancellationToken); + } + if (Body != null) { + await Body.WalkAsync(walker, cancellationToken); + } + if (Else != null) { + await Else.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); if (IsAsync) { diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/FromImportStatement.cs b/src/Parsing/Impl/Ast/FromImportStatement.cs similarity index 89% rename from src/Analysis/Engine/Impl/Parsing/Ast/FromImportStatement.cs rename to src/Parsing/Impl/Ast/FromImportStatement.cs index e282e6420..d8c3859d0 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/FromImportStatement.cs +++ b/src/Parsing/Impl/Ast/FromImportStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -18,13 +17,12 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class FromImportStatement : Statement { - private static readonly string[] _star = new[] { "*" }; - private PythonVariable[] _variables; - public FromImportStatement(ModuleName/*!*/ root, NameExpression/*!*/[] names, NameExpression/*!*/[] asNames, bool fromFuture, bool forceAbsolute, int importIndex) { Root = root; Names = names; @@ -48,14 +46,9 @@ public FromImportStatement(ModuleName/*!*/ root, NameExpression/*!*/[] names, Na /// [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "breaking change")] - public PythonVariable[] Variables { - get { return _variables; } - set { _variables = value; } - } + public PythonVariable[] Variables { get; set; } - public PythonReference[] GetReferences(PythonAst ast) { - return GetVariableReferences(this, ast); - } + public PythonReference[] GetReferences(PythonAst ast) => GetVariableReferences(this, ast); public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { @@ -63,6 +56,13 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); + } + /// /// Returns a new FromImport statement that is identical to this one but has /// removed the specified import statement. Otherwise preserves any attributes @@ -80,14 +80,14 @@ public FromImportStatement RemoveImport(PythonAst ast, int index) { throw new ArgumentNullException("ast"); } - NameExpression[] names = new NameExpression[Names.Count - 1]; - NameExpression[] asNames = AsNames == null ? null : new NameExpression[AsNames.Count - 1]; + var names = new NameExpression[Names.Count - 1]; + var asNames = AsNames == null ? null : new NameExpression[AsNames.Count - 1]; var asNameWhiteSpace = this.GetNamesWhiteSpace(ast); - List newAsNameWhiteSpace = new List(); - int importIndex = ImportIndex; - int asIndex = 0; + var newAsNameWhiteSpace = new List(); + var importIndex = ImportIndex; + var asIndex = 0; for (int i = 0, write = 0; i < Names.Count; i++) { - bool includingCurrentName = i != index; + var includingCurrentName = i != index; // track the white space, this needs to be kept in sync w/ ToCodeString and how the // parser creates the white space. @@ -177,8 +177,8 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co } var asNameWhiteSpace = this.GetNamesWhiteSpace(ast); - int asIndex = 0; - for (int i = 0; i < Names.Count; i++) { + var asIndex = 0; + for (var i = 0; i < Names.Count; i++) { if (i > 0) { if (asNameWhiteSpace != null && asIndex < asNameWhiteSpace.Length) { res.Append(asNameWhiteSpace[asIndex++]); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/FunctionDefinition.cs b/src/Parsing/Impl/Ast/FunctionDefinition.cs similarity index 85% rename from src/Analysis/Engine/Impl/Parsing/Ast/FunctionDefinition.cs rename to src/Parsing/Impl/Ast/FunctionDefinition.cs index c1aa96710..7e7f81b08 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/FunctionDefinition.cs +++ b/src/Parsing/Impl/Ast/FunctionDefinition.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,9 +16,12 @@ using System; using System.Diagnostics; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { [DebuggerDisplay("{Name}")] public class FunctionDefinition : ScopeStatement, IMaybeAsyncStatement { internal static readonly object WhitespaceAfterAsync = new object(); @@ -50,7 +52,7 @@ public FunctionDefinition(NameExpression name, Parameter[] parameters, Statement public Parameter[] Parameters => _parameters ?? Array.Empty(); - internal override int ArgCount => Parameters.Length; + public override int ArgCount => Parameters.Length; internal void SetKeywordEndIndex(int index) => _keywordEndIndex = index; public override int KeywordEndIndex => _keywordEndIndex ?? (DefIndex + (IsCoroutine ? 9 : 3)); @@ -66,13 +68,13 @@ public FunctionDefinition(NameExpression name, Parameter[] parameters, Statement public int DefIndex { get; set; } - public override string/*!*/ Name => NameExpression.Name ?? ""; + public override string/*!*/ Name => NameExpression.Name ?? string.Empty; public NameExpression NameExpression { get; } public DecoratorStatement Decorators { get; internal set; } - internal LambdaExpression LambdaExpression { get; set; } + public LambdaExpression LambdaExpression { get; set; } /// /// True if the function is a generator. Generators contain at least one yield @@ -97,13 +99,9 @@ public FunctionDefinition(NameExpression name, Parameter[] parameters, Statement /// /// Gets the variable reference for the specific assignment to the variable for this function definition. /// - public PythonReference GetVariableReference(PythonAst ast) { - return GetVariableReference(this, ast); - } + public PythonReference GetVariableReference(PythonAst ast) => GetVariableReference(this, ast); - internal override bool ExposesLocalVariable(PythonVariable variable) { - return NeedsLocalsDictionary; - } + internal override bool ExposesLocalVariable(PythonVariable variable) => NeedsLocalsDictionary; internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable) { // Functions expose their locals to direct access @@ -114,7 +112,7 @@ internal override bool TryBindOuter(ScopeStatement from, string name, bool allow if (variable.Kind == VariableKind.Local || variable.Kind == VariableKind.Parameter) { from.AddFreeVariable(variable, true); - for (ScopeStatement scope = from.Parent; scope != this; scope = scope.Parent) { + for (var scope = from.Parent; scope != this; scope = scope.Parent) { scope.AddFreeVariable(variable, false); } @@ -128,10 +126,8 @@ internal override bool TryBindOuter(ScopeStatement from, string name, bool allow } internal override PythonVariable BindReference(PythonNameBinder binder, string name) { - PythonVariable variable; - // First try variables local to this scope - if (TryGetVariable(name, out variable) && variable.Kind != VariableKind.Nonlocal) { + if (TryGetVariable(name, out var variable) && variable.Kind != VariableKind.Nonlocal) { if (variable.Kind == VariableKind.Global) { AddReferencedGlobal(name); } @@ -139,7 +135,7 @@ internal override PythonVariable BindReference(PythonNameBinder binder, string n } // Try to bind in outer scopes - for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent) { + for (var parent = Parent; parent != null; parent = parent.Parent) { if (parent.TryBindOuter(this, name, true, out variable)) { return variable; } @@ -202,10 +198,31 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } - public SourceLocation Header { - get { return GlobalParent.IndexToLocation(HeaderIndex); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (NameExpression != null) { + await NameExpression?.WalkAsync(walker, cancellationToken); + } + + foreach (var p in _parameters.MaybeEnumerate()) { + await p.WalkAsync(walker, cancellationToken); + } + + if (Decorators != null) { + await Decorators.WalkAsync(walker, cancellationToken); + } + if (_body != null) { + await _body.WalkAsync(walker, cancellationToken); + } + if (ReturnAnnotation != null) { + await ReturnAnnotation.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } + public SourceLocation Header => GlobalParent.IndexToLocation(HeaderIndex); + public override string GetLeadingWhiteSpace(PythonAst ast) { if (Decorators != null) { return Decorators.GetLeadingWhiteSpace(ast); @@ -258,7 +275,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co ); } - string namedOnly = this.GetExtraVerbatimText(ast); + var namedOnly = this.GetExtraVerbatimText(ast); if (namedOnly != null) { res.Append(namedOnly); } @@ -282,7 +299,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co res, format.SpaceAroundAnnotationArrow, " ", - "", + string.Empty, this.GetFifthWhiteSpace(ast) ); res.Append("->"); @@ -291,7 +308,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co ast, format, format.SpaceAroundAnnotationArrow != null ? - format.SpaceAroundAnnotationArrow.Value ? " " : "" : + format.SpaceAroundAnnotationArrow.Value ? " " : string.Empty : null ); } @@ -302,7 +319,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co } internal void ParamsToString(StringBuilder res, PythonAst ast, string[] commaWhiteSpace, CodeFormattingOptions format, string initialLeadingWhiteSpace = null) { - for (int i = 0; i < Parameters.Length; i++) { + for (var i = 0; i < Parameters.Length; i++) { if (i > 0) { if (commaWhiteSpace != null) { res.Append(commaWhiteSpace[i - 1]); diff --git a/src/Parsing/Impl/Ast/GeneratorExpression.cs b/src/Parsing/Impl/Ast/GeneratorExpression.cs new file mode 100644 index 000000000..464a47e39 --- /dev/null +++ b/src/Parsing/Impl/Ast/GeneratorExpression.cs @@ -0,0 +1,73 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; + +namespace Microsoft.Python.Parsing.Ast { + public sealed class GeneratorExpression : Comprehension { + private readonly ComprehensionIterator[] _iterators; + + public GeneratorExpression(Expression item, ComprehensionIterator[] iterators) { + Item = item; + _iterators = iterators; + } + + public override IList Iterators => _iterators; + + public override string NodeName => "generator"; + + public Expression Item { get; } + + internal override string CheckAssign() => "can't assign to generator expression"; + + internal override string CheckAugmentedAssign() => CheckAssign(); + + internal override string CheckDelete() => "can't delete generator expression"; + + public override void Walk(PythonWalker walker) { + if (walker.Walk(this)) { + Item?.Walk(walker); + foreach (var ci in _iterators.MaybeEnumerate()) { + ci.Walk(walker); + } + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Item != null) { + await Item.WalkAsync(walker, cancellationToken); + } + foreach (var ci in _iterators.MaybeEnumerate()) { + await ci.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { + if (this.IsAltForm(ast)) { + AppendCodeString(res, ast, format, string.Empty, string.Empty, Item); + } else { + AppendCodeString(res, ast, format, "(", this.IsMissingCloseGrouping(ast) ? string.Empty : ")", Item); + } + } + } +} diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/GlobalStatement.cs b/src/Parsing/Impl/Ast/GlobalStatement.cs similarity index 74% rename from src/Analysis/Engine/Impl/Parsing/Ast/GlobalStatement.cs rename to src/Parsing/Impl/Ast/GlobalStatement.cs index 07d6445a6..a6abf8098 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/GlobalStatement.cs +++ b/src/Parsing/Impl/Ast/GlobalStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class GlobalStatement : Statement { private readonly NameExpression[] _names; @@ -26,9 +27,7 @@ public GlobalStatement(NameExpression[] names) { _names = names; } - public IList Names { - get { return _names; } - } + public IList Names => _names; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { @@ -39,6 +38,15 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var n in _names.MaybeEnumerate().ExcludeDefault()) { + await n.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var namesWhiteSpace = this.GetNamesWhiteSpace(ast); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/IMaybeAsyncStatement.cs b/src/Parsing/Impl/Ast/IMaybeAsyncStatement.cs similarity index 81% rename from src/Analysis/Engine/Impl/Parsing/Ast/IMaybeAsyncStatement.cs rename to src/Parsing/Impl/Ast/IMaybeAsyncStatement.cs index d2366e1b0..37ef1d3b6 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/IMaybeAsyncStatement.cs +++ b/src/Parsing/Impl/Ast/IMaybeAsyncStatement.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,12 +8,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public interface IMaybeAsyncStatement { bool IsAsync { get; } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/IfStatement.cs b/src/Parsing/Impl/Ast/IfStatement.cs similarity index 68% rename from src/Analysis/Engine/Impl/Parsing/Ast/IfStatement.cs rename to src/Parsing/Impl/Ast/IfStatement.cs index 32f2f6304..04764de37 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/IfStatement.cs +++ b/src/Parsing/Impl/Ast/IfStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,54 +8,57 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class IfStatement : Statement { private readonly IfStatementTest[] _tests; - private readonly Statement _else; - private int _elseIndex; public IfStatement(IfStatementTest[] tests, Statement else_) { _tests = tests; - _else = else_; + ElseStatement = else_; } public IList Tests => _tests; - public Statement ElseStatement => _else; - internal IfStatementTest[] TestsInternal => _tests; + public Statement ElseStatement { get; } - public int ElseIndex { - get { - return _elseIndex; - } - set { - _elseIndex = value; - } - } + public int ElseIndex { get; set; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_tests != null) { - foreach (IfStatementTest test in _tests) { - test.Walk(walker); - } + foreach (var test in _tests.MaybeEnumerate()) { + test.Walk(walker); } - _else?.Walk(walker); + ElseStatement?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var test in _tests.MaybeEnumerate()) { + await test.WalkAsync(walker, cancellationToken); + } + if (ElseStatement != null) { + await ElseStatement.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var itemWhiteSpace = this.GetListWhiteSpace(ast); - for (int i = 0; i < _tests.Length; i++) { + for (var i = 0; i < _tests.Length; i++) { if (itemWhiteSpace != null) { format.ReflowComment(res, itemWhiteSpace[i]); } @@ -69,10 +71,10 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co _tests[i].AppendCodeString(res, ast, format); } - if (_else != null) { + if (ElseStatement != null) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("else"); - _else.AppendCodeString(res, ast, format); + ElseStatement.AppendCodeString(res, ast, format); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/IfStatementTest.cs b/src/Parsing/Impl/Ast/IfStatementTest.cs similarity index 50% rename from src/Analysis/Engine/Impl/Parsing/Ast/IfStatementTest.cs rename to src/Parsing/Impl/Ast/IfStatementTest.cs index 3761ca34e..4dfb3cabe 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/IfStatementTest.cs +++ b/src/Parsing/Impl/Ast/IfStatementTest.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,57 +8,54 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class IfStatementTest : Node { - private int _headerIndex; - private readonly Expression _test; - private Statement _body; - public IfStatementTest(Expression test, Statement body) { - _test = test; - _body = body; + Test = test; + Body = body; } - public int HeaderIndex { - set { _headerIndex = value; } - get { return _headerIndex; } - } + public int HeaderIndex { get; set; } - public Expression Test { - get { return _test; } - } + public Expression Test { get; } - public Statement Body { - get { return _body; } - set { _body = value; } - } + public Statement Body { get; set; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_test != null) { - _test.Walk(walker); - } - if (_body != null) { - _body.Walk(walker); - } + Test?.Walk(walker); + Body?.Walk(walker); } walker.PostWalk(this); } - public SourceLocation GetHeader(PythonAst ast) { - return ast.IndexToLocation(_headerIndex); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Test != null) { + await Test.WalkAsync(walker, cancellationToken); + } + if (Body != null) { + await Body.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } + public SourceLocation GetHeader(PythonAst ast) => ast.IndexToLocation(HeaderIndex); + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - _test.AppendCodeString(res, ast, format); - _body.AppendCodeString(res, ast, format); + Test.AppendCodeString(res, ast, format); + Body.AppendCodeString(res, ast, format); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ImportStatement.cs b/src/Parsing/Impl/Ast/ImportStatement.cs similarity index 86% rename from src/Analysis/Engine/Impl/Parsing/Ast/ImportStatement.cs rename to src/Parsing/Impl/Ast/ImportStatement.cs index ffa44bb67..1962289bf 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ImportStatement.cs +++ b/src/Parsing/Impl/Ast/ImportStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,12 +17,13 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ImportStatement : Statement { private readonly ModuleName[] _names; private readonly NameExpression[] _asNames; - private PythonVariable[] _variables; public ImportStatement(ModuleName[] names, NameExpression[] asNames, bool forceAbsolute) { _names = names; @@ -36,14 +36,9 @@ public ImportStatement(ModuleName[] names, NameExpression[] asNames, bool forceA public override int KeywordLength => 6; [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "breaking change")] - public PythonVariable[] Variables { - get { return _variables; } - set { _variables = value; } - } + public PythonVariable[] Variables { get; set; } - public PythonReference[] GetReferences(PythonAst ast) { - return GetVariableReferences(this, ast); - } + public PythonReference[] GetReferences(PythonAst ast) => GetVariableReferences(this, ast); public IList Names => _names; public IList AsNames => _asNames; @@ -54,6 +49,13 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); + } + /// /// Removes the import at the specified index (which must be in the range of /// the Names property) and returns a new ImportStatement which is the same @@ -70,15 +72,15 @@ public ImportStatement RemoveImport(PythonAst ast, int index) { throw new ArgumentNullException("ast"); } - ModuleName[] names = new ModuleName[_names.Length - 1]; - NameExpression[] asNames = _asNames == null ? null : new NameExpression[_asNames.Length - 1]; + var names = new ModuleName[_names.Length - 1]; + var asNames = _asNames == null ? null : new NameExpression[_asNames.Length - 1]; var asNameWhiteSpace = this.GetNamesWhiteSpace(ast); var itemWhiteSpace = this.GetListWhiteSpace(ast); - List newAsNameWhiteSpace = new List(); - List newListWhiteSpace = new List(); - int asIndex = 0; + var newAsNameWhiteSpace = new List(); + var newListWhiteSpace = new List(); + var asIndex = 0; for (int i = 0, write = 0; i < _names.Length; i++) { - bool includingCurrentName = i != index; + var includingCurrentName = i != index; // track the white space, this needs to be kept in sync w/ ToCodeString and how the // parser creates the white space. diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/IndexExpression.cs b/src/Parsing/Impl/Ast/IndexExpression.cs similarity index 58% rename from src/Analysis/Engine/Impl/Parsing/Ast/IndexExpression.cs rename to src/Parsing/Impl/Ast/IndexExpression.cs index a0a700493..d3cce0cf5 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/IndexExpression.cs +++ b/src/Parsing/Impl/Ast/IndexExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,57 +8,52 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class IndexExpression : Expression { - private readonly Expression _target; - private readonly Expression _index; - public IndexExpression(Expression target, Expression index) { - _target = target; - _index = index; + Target = target; + Index = index; } - public Expression Target { - get { return _target; } - } + public Expression Target { get; } - public Expression Index { - get { return _index; } - } + public Expression Index { get; } - internal override string CheckAssign() { - return null; - } + internal override string CheckAssign() => null; - internal override string CheckDelete() { - return null; - } + internal override string CheckDelete() => null; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_target != null) { - _target.Walk(walker); - } - if (_index != null) { - _index.Walk(walker); - } + Target?.Walk(walker); + Index?.Walk(walker); } walker.PostWalk(this); } - private bool IsSlice { - get { - return _index is SliceExpression; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Target != null) { + await Target.WalkAsync(walker, cancellationToken); + } + if (Index != null) { + await Index.WalkAsync(walker, cancellationToken); + } } + await walker.PostWalkAsync(this, cancellationToken); } + private bool IsSlice => Index is SliceExpression; + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { Target.AppendCodeString(res, ast, format); format.Append( @@ -67,14 +61,14 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo format.SpaceBeforeIndexBracket, " ", "", - this.GetPreceedingWhiteSpace(ast) + this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? string.Empty ); res.Append('['); - _index.AppendCodeString( - res, - ast, - format, + Index.AppendCodeString( + res, + ast, + format, format.SpaceWithinIndexBrackets != null ? format.SpaceWithinIndexBrackets.Value ? " " : "" : null ); @@ -84,18 +78,14 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo format.SpaceWithinIndexBrackets, " ", "", - this.GetSecondWhiteSpace(ast) + this.GetSecondWhiteSpaceDefaultNull(ast) ?? string.Empty ); res.Append(']'); } } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return Target.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Target.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - Target.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Target.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/LambdaExpression.cs b/src/Parsing/Impl/Ast/LambdaExpression.cs similarity index 63% rename from src/Analysis/Engine/Impl/Parsing/Ast/LambdaExpression.cs rename to src/Parsing/Impl/Ast/LambdaExpression.cs index 55ba45660..3cdfc176b 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/LambdaExpression.cs +++ b/src/Parsing/Impl/Ast/LambdaExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,49 +8,54 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Diagnostics; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class LambdaExpression : Expression { - private readonly FunctionDefinition _function; - public LambdaExpression(FunctionDefinition function) { - _function = function; + Function = function; } - public FunctionDefinition Function { - get { return _function; } - } + public FunctionDefinition Function { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_function != null) { - _function.Walk(walker); - } + Function?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Function != null) { + await Function.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("lambda"); var commaWhiteSpace = this.GetListWhiteSpace(ast); - if (_function.Parameters.Length > 0) { + if (Function.Parameters.Length > 0) { var paramStr = new StringBuilder(); - _function.ParamsToString(paramStr, ast, commaWhiteSpace, format); - if (paramStr.Length > 0 && !char.IsWhiteSpace(paramStr[0]) && !(_function.Parameters[0] is ErrorParameter)) { + Function.ParamsToString(paramStr, ast, commaWhiteSpace, format); + if (paramStr.Length > 0 && !char.IsWhiteSpace(paramStr[0]) && !(Function.Parameters[0] is ErrorParameter)) { res.Append(' '); } res.Append(paramStr.ToString()); } - string namedOnlyText = this.GetExtraVerbatimText(ast); + var namedOnlyText = this.GetExtraVerbatimText(ast); if (namedOnlyText != null) { res.Append(namedOnlyText); } @@ -64,11 +68,11 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } else if (format.SpaceAfterLambdaColon == false) { afterColon = ""; } - if (_function.Body is ReturnStatement) { - ((ReturnStatement)_function.Body).Expression.AppendCodeString(res, ast, format, afterColon); + if (Function.Body is ReturnStatement) { + ((ReturnStatement)Function.Body).Expression.AppendCodeString(res, ast, format, afterColon); } else { - Debug.Assert(_function.Body is ExpressionStatement); - ((ExpressionStatement)_function.Body).Expression.AppendCodeString(res, ast, format, afterColon); + Debug.Assert(Function.Body is ExpressionStatement); + ((ExpressionStatement)Function.Body).Expression.AppendCodeString(res, ast, format, afterColon); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ListExpression.cs b/src/Parsing/Impl/Ast/ListExpression.cs similarity index 70% rename from src/Analysis/Engine/Impl/Parsing/Ast/ListExpression.cs rename to src/Parsing/Impl/Ast/ListExpression.cs index 5329b19af..a6523822c 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ListExpression.cs +++ b/src/Parsing/Impl/Ast/ListExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,52 +16,58 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ListExpression : SequenceExpression { public ListExpression(params Expression[] items) : base(items) { } - public override string NodeName { - get { - return "list display"; - } - } + public override string NodeName => "list display"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (Items != null) { - foreach (Expression e in Items) { - e.Walk(walker); - } + foreach (var e in Items.MaybeEnumerate()) { + e.Walk(walker); } } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var e in Items.MaybeEnumerate()) { + await e.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { if (Items.Count == 0 && format.SpacesWithinEmptyListExpression != null) { res.Append(this.GetPreceedingWhiteSpace(ast)); res.Append('['); - if (String.IsNullOrWhiteSpace(this.GetSecondWhiteSpace(ast))) { - res.Append(format.SpacesWithinEmptyListExpression.Value ? " " : ""); + if (string.IsNullOrWhiteSpace(this.GetSecondWhiteSpace(ast))) { + res.Append(format.SpacesWithinEmptyListExpression.Value ? " " : string.Empty); } else { format.ReflowComment(res, this.GetSecondWhiteSpace(ast)); } res.Append(']'); } else { - AppendItems(res, ast, format, "[", this.IsMissingCloseGrouping(ast) ? "" : "]", this, Items, format.SpacesWithinListExpression); + AppendItems(res, ast, format, "[", this.IsMissingCloseGrouping(ast) ? string.Empty : "]", this, Items, format.SpacesWithinListExpression); } } internal static void AppendItems(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Node node, IList items, bool? delimiterWhiteSpace = null) where T : Expression { string initialWs = null, ws = null; if (delimiterWhiteSpace.HasValue) { - initialWs = delimiterWhiteSpace.Value ? " " : ""; + initialWs = delimiterWhiteSpace.Value ? " " : string.Empty; } if (format.SpaceAfterComma.HasValue) { - ws = format.SpaceAfterComma.Value ? " " : ""; + ws = format.SpaceAfterComma.Value ? " " : string.Empty; } AppendItems(res, ast, format, start, end, node, items.Count, (i, sb) => { if (i == 0) { @@ -74,14 +79,14 @@ internal static void AppendItems(StringBuilder res, PythonAst ast, CodeFormat } internal static void AppendItems(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string start, string end, Node node, int itemCount, Action appendItem, bool? trailingWhiteSpace = null) { - if (!String.IsNullOrEmpty(start)) { + if (!string.IsNullOrEmpty(start)) { format.ReflowComment(res, node.GetPreceedingWhiteSpace(ast)); res.Append(start); } var listWhiteSpace = node.GetListWhiteSpace(ast); - for (int i = 0; i < itemCount; i++) { + for (var i = 0; i < itemCount; i++) { if (i > 0) { - format.Append(res, format.SpaceBeforeComma, " ", "", listWhiteSpace?[i - 1]); + format.Append(res, format.SpaceBeforeComma, " ", string.Empty, listWhiteSpace?[i - 1]); res.Append(","); } @@ -90,12 +95,12 @@ internal static void AppendItems(StringBuilder res, PythonAst ast, CodeFormattin if (listWhiteSpace != null && listWhiteSpace.Length == itemCount && itemCount != 0) { // trailing comma - format.Append(res, format.SpaceBeforeComma, " ", "", listWhiteSpace[listWhiteSpace.Length - 1]); + format.Append(res, format.SpaceBeforeComma, " ", string.Empty, listWhiteSpace[listWhiteSpace.Length - 1]); res.Append(","); } - if (!String.IsNullOrEmpty(end)) { - format.Append(res, trailingWhiteSpace, " ", "", node.GetSecondWhiteSpaceDefaultNull(ast)); + if (!string.IsNullOrEmpty(end)) { + format.Append(res, trailingWhiteSpace, " ", string.Empty, node.GetSecondWhiteSpaceDefaultNull(ast)); res.Append(end); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/MemberExpression.cs b/src/Parsing/Impl/Ast/MemberExpression.cs similarity index 57% rename from src/Analysis/Engine/Impl/Parsing/Ast/MemberExpression.cs rename to src/Parsing/Impl/Ast/MemberExpression.cs index c19fa7107..a4f394231 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/MemberExpression.cs +++ b/src/Parsing/Impl/Ast/MemberExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,21 +8,21 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public sealed class MemberExpression : Expression { - private readonly Expression _target; - private readonly string _name; - public MemberExpression(Expression target, string name) { - _target = target; - _name = name; + Target = target; + Name = name; } public void SetLoc(int start, int name, int end) { @@ -41,62 +40,54 @@ public void SetLoc(int start, int name, int end) { /// public int DotIndex { get; set; } - public Expression Target { - get { return _target; } - } + public Expression Target { get; } - public string Name { - get { return _name; } - } + public string Name { get; } - public override string ToString() { - return base.ToString() + ":" + _name; - } + public override string ToString() => base.ToString() + ":" + Name; - internal override string CheckAssign() { - return null; - } + internal override string CheckAssign() => null; - internal override string CheckDelete() { - return null; - } + internal override string CheckDelete() => null; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_target != null) { - _target.Walk(walker); - } + Target?.Walk(walker); } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Target != null) { + await Target.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - _target.AppendCodeString(res, ast, format); - format.Append(res, format.SpaceBeforeDot, " ", "", this.GetPreceedingWhiteSpaceDefaultNull(ast)); + Target.AppendCodeString(res, ast, format); + format.Append(res, format.SpaceBeforeDot, " ", string.Empty, this.GetPreceedingWhiteSpaceDefaultNull(ast)); res.Append('.'); if (!this.IsIncompleteNode(ast)) { - format.Append(res, format.SpaceAfterDot, " ", "", this.GetSecondWhiteSpaceDefaultNull(ast)); + format.Append(res, format.SpaceAfterDot, " ", string.Empty, this.GetSecondWhiteSpaceDefaultNull(ast)); if (format.UseVerbatimImage) { - res.Append(this.GetVerbatimImage(ast) ?? _name); + res.Append(this.GetVerbatimImage(ast) ?? Name); } else { - res.Append(_name); + res.Append(Name); } } } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return _target.GetLeadingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Target.GetLeadingWhiteSpace(ast); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - _target.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) + => Target.SetLeadingWhiteSpace(ast, whiteSpace); /// /// Returns the span of the name component of the expression /// - public SourceSpan GetNameSpan(PythonAst parent) { - return new SourceSpan(parent.IndexToLocation(NameHeader), GetEnd(parent)); - } + public SourceSpan GetNameSpan(PythonAst parent) => new SourceSpan(parent.IndexToLocation(NameHeader), GetEnd(parent)); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ModuleName.cs b/src/Parsing/Impl/Ast/ModuleName.cs similarity index 86% rename from src/Analysis/Engine/Impl/Parsing/Ast/ModuleName.cs rename to src/Parsing/Impl/Ast/ModuleName.cs index 01bb749f2..e52ed6eaf 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ModuleName.cs +++ b/src/Parsing/Impl/Ast/ModuleName.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,12 +8,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ModuleName : DottedName { public ModuleName(NameExpression[]/*!*/ names) : base(names) { diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/NameExpression.cs b/src/Parsing/Impl/Ast/NameExpression.cs similarity index 62% rename from src/Analysis/Engine/Impl/Parsing/Ast/NameExpression.cs rename to src/Parsing/Impl/Ast/NameExpression.cs index 91866d138..827b4e1c1 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/NameExpression.cs +++ b/src/Parsing/Impl/Ast/NameExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,39 +8,29 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class NameExpression : Expression { public static readonly NameExpression[] EmptyArray = new NameExpression[0]; - public static readonly NameExpression Empty = new NameExpression(""); - - private readonly string _name; + public static readonly NameExpression Empty = new NameExpression(string.Empty); public NameExpression(string name) { - _name = name ?? ""; - } - - public string/*!*/ Name { - get { return _name; } - } - - public override string ToString() { - return base.ToString() + ":" + _name; + Name = name ?? ""; } - internal override string CheckAssign() { - return null; - } + public string/*!*/ Name { get; } - internal override string CheckDelete() { - return null; - } + public override string ToString() => base.ToString() + ":" + Name; + internal override string CheckAssign() => null; + internal override string CheckDelete() => null; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { @@ -49,20 +38,23 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } - public PythonReference GetVariableReference(PythonAst ast) { - return GetVariableReference(this, ast); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + } + await walker.PostWalkAsync(this, cancellationToken); } - public void AddPreceedingWhiteSpace(PythonAst ast, string whiteSpace) { - ast.SetAttribute(this, NodeAttributes.PreceedingWhiteSpace, whiteSpace); - } + public PythonReference GetVariableReference(PythonAst ast) => GetVariableReference(this, ast); + + public void AddPreceedingWhiteSpace(PythonAst ast, string whiteSpace) + => ast.SetAttribute(this, NodeAttributes.PreceedingWhiteSpace, whiteSpace); internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpaceDefaultNull(ast)); if (format.UseVerbatimImage) { - res.Append(this.GetVerbatimImage(ast) ?? _name); + res.Append(this.GetVerbatimImage(ast) ?? Name); } else { - res.Append(_name); + res.Append(Name); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/Node.cs b/src/Parsing/Impl/Ast/Node.cs similarity index 62% rename from src/Analysis/Engine/Impl/Parsing/Ast/Node.cs rename to src/Parsing/Impl/Ast/Node.cs index b902832fc..58aa67997 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/Node.cs +++ b/src/Parsing/Impl/Ast/Node.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,83 +8,62 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public abstract class Node { - private IndexSpan _span; - internal Node() { } #region Public API public int EndIndex { - get { - return _span.End; - } - set { - _span = new IndexSpan(_span.Start, value - _span.Start); - } + get => IndexSpan.End; + set => IndexSpan = new IndexSpan(IndexSpan.Start, value - IndexSpan.Start); } public int StartIndex { - get { - return _span.Start; - } - set { - _span = new IndexSpan(value, 0); - } + get => IndexSpan.Start; + set => IndexSpan = new IndexSpan(value, 0); } public abstract void Walk(PythonWalker walker); + public abstract Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default); - public virtual string NodeName { - get { - return GetType().Name; - } - } + public virtual string NodeName => GetType().Name; - public string ToCodeString(PythonAst ast) { - return ToCodeString(ast, CodeFormattingOptions.Default); - } + public string ToCodeString(PythonAst ast) => ToCodeString(ast, CodeFormattingOptions.Default); public string ToCodeString(PythonAst ast, CodeFormattingOptions format) { - StringBuilder res = new StringBuilder(); + var res = new StringBuilder(); AppendCodeString(res, ast, format); return res.ToString(); } - public SourceLocation GetStart(PythonAst parent) { - return parent.IndexToLocation(StartIndex); - } + public SourceLocation GetStart(PythonAst parent) => parent.IndexToLocation(StartIndex); - public SourceLocation GetEnd(PythonAst parent) { - return parent.IndexToLocation(EndIndex); - } + public SourceLocation GetEnd(PythonAst parent) => parent.IndexToLocation(EndIndex); - public SourceSpan GetSpan(PythonAst parent) { - return new SourceSpan(GetStart(parent), GetEnd(parent)); - } + public SourceSpan GetSpan(PythonAst parent) => new SourceSpan(GetStart(parent), GetEnd(parent)); - public static void CopyLeadingWhiteSpace(PythonAst parentNode, Node fromNode, Node toNode) { - parentNode.SetAttribute(toNode, NodeAttributes.PreceedingWhiteSpace, fromNode.GetLeadingWhiteSpace(parentNode)); - } + public static void CopyLeadingWhiteSpace(PythonAst parentNode, Node fromNode, Node toNode) + => parentNode.SetAttribute(toNode, NodeAttributes.PreceedingWhiteSpace, fromNode.GetLeadingWhiteSpace(parentNode)); /// - /// Returns the proceeeding whitespace (newlines and comments) that + /// Returns the proceeding whitespace (newlines and comments) that /// shows up before this node. /// /// New in 1.1. /// - public virtual string GetLeadingWhiteSpace(PythonAst ast) { - return this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""; - } + public virtual string GetLeadingWhiteSpace(PythonAst ast) => this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""; /// /// Sets the proceeding whitespace (newlines and comments) that shows up @@ -93,9 +71,7 @@ public virtual string GetLeadingWhiteSpace(PythonAst ast) { /// /// /// - public virtual void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - ast.SetAttribute(this, NodeAttributes.PreceedingWhiteSpace, whiteSpace); - } + public virtual void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => ast.SetAttribute(this, NodeAttributes.PreceedingWhiteSpace, whiteSpace); /// /// Gets the indentation level for the current statement. Requires verbose @@ -104,7 +80,7 @@ public virtual void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { public string GetIndentationLevel(PythonAst parentNode) { var leading = GetLeadingWhiteSpace(parentNode); // we only want the trailing leading space for the current line... - for (int i = leading.Length - 1; i >= 0; i--) { + for (var i = leading.Length - 1; i >= 0; i--) { if (leading[i] == '\r' || leading[i] == '\n') { leading = leading.Substring(i + 1); break; @@ -114,7 +90,7 @@ public string GetIndentationLevel(PythonAst parentNode) { } #endregion - + #region Internal APIs /// @@ -133,9 +109,9 @@ internal virtual void AppendCodeString(StringBuilder res, PythonAst ast, CodeFor return; } res.Append(leadingWhiteSpace); - StringBuilder tmp = new StringBuilder(); + var tmp = new StringBuilder(); AppendCodeString(tmp, ast, format); - for (int curChar = 0; curChar < tmp.Length; curChar++) { + for (var curChar = 0; curChar < tmp.Length; curChar++) { if (!char.IsWhiteSpace(tmp[curChar])) { res.Append(tmp.ToString(curChar, tmp.Length - curChar)); break; @@ -143,38 +119,22 @@ internal virtual void AppendCodeString(StringBuilder res, PythonAst ast, CodeFor } } - internal void SetLoc(int start, int end) { - _span = new IndexSpan(start, end >= start ? end - start : start); - } + public void SetLoc(int start, int end) => IndexSpan = new IndexSpan(start, end >= start ? end - start : start); + public void SetLoc(IndexSpan span) => IndexSpan = span; - internal void SetLoc(IndexSpan span) { - _span = span; - } + public IndexSpan IndexSpan { get; set; } - internal IndexSpan IndexSpan { - get { - return _span; - } - set { - _span = value; - } - } - - internal virtual string GetDocumentation(Statement/*!*/ stmt) { - return stmt.Documentation; - } + internal virtual string GetDocumentation(Statement/*!*/ stmt) => stmt.Documentation; internal static PythonReference GetVariableReference(Node node, PythonAst ast) { - object reference; - if (ast.TryGetAttribute(node, NodeAttributes.VariableReference, out reference)) { + if (ast.TryGetAttribute(node, NodeAttributes.VariableReference, out var reference)) { return (PythonReference)reference; } return null; } internal static PythonReference[] GetVariableReferences(Node node, PythonAst ast) { - object reference; - if (ast.TryGetAttribute(node, NodeAttributes.VariableReference, out reference)) { + if (ast.TryGetAttribute(node, NodeAttributes.VariableReference, out var reference)) { return (PythonReference[])reference; } return null; diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/NodeAttributes.cs b/src/Parsing/Impl/Ast/NodeAttributes.cs similarity index 62% rename from src/Analysis/Engine/Impl/Parsing/Ast/NodeAttributes.cs rename to src/Parsing/Impl/Ast/NodeAttributes.cs index 22387d208..f9636afdb 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/NodeAttributes.cs +++ b/src/Parsing/Impl/Ast/NodeAttributes.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. - -using System; - -namespace Microsoft.PythonTools.Parsing.Ast { - internal static class NodeAttributes { +namespace Microsoft.Python.Parsing.Ast { + public static class NodeAttributes { /// /// Value is a string which proceeds a token in the node. /// @@ -89,7 +85,7 @@ internal static class NodeAttributes { public static readonly object VariableReference = new object(); public static readonly object Variable = new object(); - + public static void AddVariableReference(this Node node, PythonAst ast, bool bindNames, object reference) { if (bindNames) { ast.SetAttribute(node, VariableReference, reference); @@ -102,116 +98,63 @@ public static void AddVariable(this Parameter node, PythonAst ast, bool bindName } } - public static string GetPreceedingWhiteSpace(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.PreceedingWhiteSpace); - } + public static string GetPreceedingWhiteSpace(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.PreceedingWhiteSpace); - public static string GetPreceedingWhiteSpaceDefaultNull(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.PreceedingWhiteSpace, null); - } + public static string GetPreceedingWhiteSpaceDefaultNull(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.PreceedingWhiteSpace, null); internal static string GetWhiteSpace(Node node, PythonAst ast, object kind, string defaultValue = " ") { - object whitespace; - if (ast.TryGetAttribute(node, kind, out whitespace)) { + if (ast.TryGetAttribute(node, kind, out var whitespace)) { return (string)whitespace; } else { return defaultValue; } } - public static string GetSecondWhiteSpace(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.SecondPreceedingWhiteSpace); - } + public static string GetSecondWhiteSpace(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.SecondPreceedingWhiteSpace); - public static string GetSecondWhiteSpaceDefaultNull(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.SecondPreceedingWhiteSpace, null); - } + public static string GetSecondWhiteSpaceDefaultNull(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.SecondPreceedingWhiteSpace, null); - public static string GetThirdWhiteSpace(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.ThirdPreceedingWhiteSpace); - } + public static string GetThirdWhiteSpace(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.ThirdPreceedingWhiteSpace); - public static string GetThirdWhiteSpaceDefaultNull(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.ThirdPreceedingWhiteSpace, null); - } + public static string GetThirdWhiteSpaceDefaultNull(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.ThirdPreceedingWhiteSpace, null); - public static string GetFourthWhiteSpace(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.FourthPreceedingWhiteSpace); - } + public static string GetFourthWhiteSpace(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.FourthPreceedingWhiteSpace); - public static string GetFourthWhiteSpaceDefaultNull(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.FourthPreceedingWhiteSpace, null); - } + public static string GetFourthWhiteSpaceDefaultNull(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.FourthPreceedingWhiteSpace, null); - public static string GetFifthWhiteSpace(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.FifthPreceedingWhiteSpace); - } + public static string GetFifthWhiteSpace(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.FifthPreceedingWhiteSpace); - public static string GetExtraVerbatimText(this Node node, PythonAst ast) { - return GetWhiteSpace(node, ast, NodeAttributes.ExtraVerbatimText, null); - } + public static string GetExtraVerbatimText(this Node node, PythonAst ast) + => GetWhiteSpace(node, ast, NodeAttributes.ExtraVerbatimText, null); - public static bool IsAltForm(this Node node, PythonAst ast) { - object dummy; - if (ast.TryGetAttribute(node, NodeAttributes.IsAltFormValue, out dummy)) { - return true; - } else { - return false; - } - } + public static bool IsAltForm(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.IsAltFormValue, out var dummy); - public static bool IsMissingCloseGrouping(this Node node, PythonAst ast) { - object dummy; - if (ast.TryGetAttribute(node, NodeAttributes.ErrorMissingCloseGrouping, out dummy)) { - return true; - } else { - return false; - } - } + public static bool IsMissingCloseGrouping(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.ErrorMissingCloseGrouping, out var dummy); - public static bool IsIncompleteNode(this Node node, PythonAst ast) { - object dummy; - if (ast.TryGetAttribute(node, NodeAttributes.ErrorIncompleteNode, out dummy)) { - return true; - } else { - return false; - } - } + public static bool IsIncompleteNode(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.ErrorIncompleteNode, out var dummy); - public static string[] GetListWhiteSpace(this Node node, PythonAst ast) { - object whitespace; - if (ast.TryGetAttribute(node, NodeAttributes.ListWhiteSpace, out whitespace)) { - return (string[])whitespace; - } else { - return null; - } - } + public static string[] GetListWhiteSpace(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.ListWhiteSpace, out var whitespace) ? (string[])whitespace : null; - public static string[] GetNamesWhiteSpace(this Node node, PythonAst ast) { - object whitespace; - if (ast.TryGetAttribute(node, NodeAttributes.NamesWhiteSpace, out whitespace)) { - return (string[])whitespace; - } else { - return null; - } - } + public static string[] GetNamesWhiteSpace(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.NamesWhiteSpace, out var whitespace) ? (string[])whitespace : null; - public static string[] GetVerbatimNames(this Node node, PythonAst ast) { - object names; - if (ast.TryGetAttribute(node, NodeAttributes.VerbatimNames, out names)) { - return (string[])names; - } else { - return null; - } - } + public static string[] GetVerbatimNames(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.VerbatimNames, out var names) ? (string[])names : null; - public static string GetVerbatimImage(this Node node, PythonAst ast) { - object image; - if (ast.TryGetAttribute(node, NodeAttributes.VerbatimImage, out image)) { - return (string)image; - } else { - return null; - } - } + public static string GetVerbatimImage(this Node node, PythonAst ast) + => ast.TryGetAttribute(node, NodeAttributes.VerbatimImage, out var image) ? (string)image : null; } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/NonlocalStatement.cs b/src/Parsing/Impl/Ast/NonlocalStatement.cs similarity index 69% rename from src/Analysis/Engine/Impl/Parsing/Ast/NonlocalStatement.cs rename to src/Parsing/Impl/Ast/NonlocalStatement.cs index 930eaaffd..80f84ad3c 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/NonlocalStatement.cs +++ b/src/Parsing/Impl/Ast/NonlocalStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,16 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class NonlocalStatement : Statement { private readonly NameExpression[] _names; @@ -26,19 +27,26 @@ public NonlocalStatement(NameExpression[] names) { _names = names; } - public IList Names { - get { return _names; } - } + public IList Names => _names; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - foreach (var n in _names.MaybeEnumerate()) { - n?.Walk(walker); + foreach (var n in _names.MaybeEnumerate().ExcludeDefault()) { + n.Walk(walker); } } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var n in _names.MaybeEnumerate().ExcludeDefault()) { + await n.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var namesWhiteSpace = this.GetNamesWhiteSpace(ast); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/OrExpression.cs b/src/Parsing/Impl/Ast/OrExpression.cs similarity index 64% rename from src/Analysis/Engine/Impl/Parsing/Ast/OrExpression.cs rename to src/Parsing/Impl/Ast/OrExpression.cs index a48ebe362..210f682dc 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/OrExpression.cs +++ b/src/Parsing/Impl/Ast/OrExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class OrExpression : Expression { public OrExpression(Expression left, Expression right, int orIndex) { Left = left ?? throw new ArgumentNullException(nameof(left)); @@ -33,11 +34,7 @@ public OrExpression(Expression left, Expression right, int orIndex) { public int OrIndex { get; } - public override string NodeName { - get { - return "or expression"; - } - } + public override string NodeName => "or expression"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { @@ -47,16 +44,20 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - BinaryExpression.BinaryToCodeString(res, ast, format, this, Left, Right, "or"); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + await Left.WalkAsync(walker, cancellationToken); + if (Right != null) { + await Right.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } - public override string GetLeadingWhiteSpace(PythonAst ast) { - return Left.GetLeadingWhiteSpace(ast); - } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => BinaryExpression.BinaryToCodeString(res, ast, format, this, Left, Right, "or"); - public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - Left.SetLeadingWhiteSpace(ast, whiteSpace); - } + public override string GetLeadingWhiteSpace(PythonAst ast) => Left.GetLeadingWhiteSpace(ast); + + public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) => Left.SetLeadingWhiteSpace(ast, whiteSpace); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/Parameter.cs b/src/Parsing/Impl/Ast/Parameter.cs similarity index 57% rename from src/Analysis/Engine/Impl/Parsing/Ast/Parameter.cs rename to src/Parsing/Impl/Ast/Parameter.cs index dfcea9cd6..108c7a455 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/Parameter.cs +++ b/src/Parsing/Impl/Ast/Parameter.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,119 +8,85 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { /// /// Parameter base class /// public class Parameter : Node { - /// - /// Position of the parameter: 0-based index - /// - private readonly NameExpression _name; - internal readonly ParameterKind _kind; - internal Expression _defaultValue, _annotation; - internal static readonly object WhitespacePrecedingAssign = new object(); public Parameter(NameExpression name, ParameterKind kind) { - _name = name; - _kind = kind; + NameExpression = name; + Kind = kind; } - public override string NodeName { - get { - return "parameter name"; - } - } + public override string NodeName => "parameter name"; /// /// Parameter name /// - public virtual string/*!*/ Name => _name?.Name ?? ""; + public virtual string/*!*/ Name => NameExpression?.Name ?? string.Empty; - public NameExpression NameExpression => _name; - internal IndexSpan NameSpan => _name?.IndexSpan ?? IndexSpan; + public NameExpression NameExpression { get; } + internal IndexSpan NameSpan => NameExpression?.IndexSpan ?? IndexSpan; - public Expression DefaultValue { - get { return _defaultValue; } - set { _defaultValue = value; } - } + public Expression DefaultValue { get; set; } - public Expression Annotation { - get { - return _annotation; - } - set { - _annotation = value; - } - } + public Expression Annotation { get; set; } - public bool IsList { - get { - return _kind == ParameterKind.List; - } - } + public bool IsList => Kind == ParameterKind.List; - public bool IsDictionary { - get { - return _kind == ParameterKind.Dictionary; - } - } + public bool IsDictionary => Kind == ParameterKind.Dictionary; - public bool IsKeywordOnly { - get { - return _kind == ParameterKind.KeywordOnly; - } - } + public bool IsKeywordOnly => Kind == ParameterKind.KeywordOnly; - internal ParameterKind Kind { - get { - return _kind; - } - } + public ParameterKind Kind { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_annotation != null) { - _annotation.Walk(walker); - } - if (_defaultValue != null) { - _defaultValue.Walk(walker); - } + Annotation?.Walk(walker); + DefaultValue?.Walk(walker); } walker.PostWalk(this); } - public PythonVariable GetVariable(PythonAst ast) { - object reference; - if (ast.TryGetAttribute(this, NodeAttributes.Variable, out reference)) { - return (PythonVariable)reference; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Annotation != null) { + await Annotation.WalkAsync(walker, cancellationToken); + } + if (DefaultValue != null) { + await DefaultValue.WalkAsync(walker, cancellationToken); + } } - return null; + await walker.PostWalkAsync(this, cancellationToken); } - public void AddPreceedingWhiteSpace(PythonAst ast, string whiteSpace) { - ast.SetAttribute(this, NodeAttributes.PreceedingWhiteSpace, whiteSpace); - } + public PythonVariable GetVariable(PythonAst ast) + => ast.TryGetAttribute(this, NodeAttributes.Variable, out var reference) ? (PythonVariable)reference : null; - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - AppendCodeString(res, ast, format, null); - } + public void AddPreceedingWhiteSpace(PythonAst ast, string whiteSpace) + => ast.SetAttribute(this, NodeAttributes.PreceedingWhiteSpace, whiteSpace); - internal virtual void AppendParameterName(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) { - _name?.AppendCodeString(res, ast, format, leadingWhiteSpace); - } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) + => AppendCodeString(res, ast, format, null); + + internal virtual void AppendParameterName(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) + => NameExpression?.AppendCodeString(res, ast, format, leadingWhiteSpace); internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) { - string kwOnlyText = this.GetExtraVerbatimText(ast); + var kwOnlyText = this.GetExtraVerbatimText(ast); if (kwOnlyText != null) { if (leadingWhiteSpace != null) { res.Append(leadingWhiteSpace); @@ -132,21 +97,21 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } } - bool writeName = true; + var writeName = true; switch (Kind) { case ParameterKind.Dictionary: - res.Append(leadingWhiteSpace ?? this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); + res.Append(leadingWhiteSpace ?? this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? string.Empty); leadingWhiteSpace = null; res.Append("**"); break; case ParameterKind.List: - res.Append(leadingWhiteSpace ?? this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); + res.Append(leadingWhiteSpace ?? this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? string.Empty); leadingWhiteSpace = null; res.Append('*'); break; case ParameterKind.Normal: if (this.IsAltForm(ast)) { - res.Append(leadingWhiteSpace ?? this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); + res.Append(leadingWhiteSpace ?? this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? string.Empty); leadingWhiteSpace = null; res.Append('('); AppendParameterName(res, ast, format, leadingWhiteSpace); @@ -166,26 +131,26 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo AppendParameterName(res, ast, format, leadingWhiteSpace); } - if (_annotation != null) { + if (Annotation != null) { res.Append(this.GetThirdWhiteSpaceDefaultNull(ast) ?? ""); res.Append(':'); - _annotation.AppendCodeString(res, ast, format); + Annotation.AppendCodeString(res, ast, format); } - if (_defaultValue != null) { + if (DefaultValue != null) { format.Append( res, format.SpaceAroundDefaultValueEquals, " ", - "", + string.Empty, NodeAttributes.GetWhiteSpace(this, ast, WhitespacePrecedingAssign) ); res.Append('='); if (format.SpaceAroundDefaultValueEquals != null) { - _defaultValue.AppendCodeString(res, ast, format, format.SpaceAroundDefaultValueEquals.Value ? " " : ""); + DefaultValue.AppendCodeString(res, ast, format, format.SpaceAroundDefaultValueEquals.Value ? " " : string.Empty); } else { - _defaultValue.AppendCodeString(res, ast, format); + DefaultValue.AppendCodeString(res, ast, format); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ParameterKind.cs b/src/Parsing/Impl/Ast/ParameterKind.cs similarity index 86% rename from src/Analysis/Engine/Impl/Parsing/Ast/ParameterKind.cs rename to src/Parsing/Impl/Ast/ParameterKind.cs index 1f694465d..57d2c3298 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ParameterKind.cs +++ b/src/Parsing/Impl/Ast/ParameterKind.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,13 +8,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. - -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public enum ParameterKind { Normal, List, diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ParenthesisExpression.cs b/src/Parsing/Impl/Ast/ParenthesisExpression.cs similarity index 67% rename from src/Analysis/Engine/Impl/Parsing/Ast/ParenthesisExpression.cs rename to src/Parsing/Impl/Ast/ParenthesisExpression.cs index db80bac01..16e44dca0 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ParenthesisExpression.cs +++ b/src/Parsing/Impl/Ast/ParenthesisExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ParenthesisExpression : Expression { private readonly Expression _expression; @@ -25,43 +26,45 @@ public ParenthesisExpression(Expression expression) { _expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression => _expression; - internal override string CheckAssign() { - return _expression.CheckAssign(); - } + internal override string CheckAssign() => _expression.CheckAssign(); - internal override string CheckDelete() { - return _expression.CheckDelete(); - } + internal override string CheckDelete() => _expression.CheckDelete(); public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { + _expression?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { if (_expression != null) { - _expression.Walk(walker); + await _expression.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append('('); - + _expression.AppendCodeString( - res, - ast, + res, + ast, format, - format.SpacesWithinParenthesisExpression != null ? format.SpacesWithinParenthesisExpression.Value ? " " : "" : null + format.SpacesWithinParenthesisExpression != null ? format.SpacesWithinParenthesisExpression.Value ? " " : string.Empty : null ); if (!this.IsMissingCloseGrouping(ast)) { format.Append( res, format.SpacesWithinParenthesisExpression, " ", - "", + string.Empty, this.GetSecondWhiteSpace(ast) ); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PrintStatement.cs b/src/Parsing/Impl/Ast/PrintStatement.cs similarity index 55% rename from src/Analysis/Engine/Impl/Parsing/Ast/PrintStatement.cs rename to src/Parsing/Impl/Ast/PrintStatement.cs index 8488eea02..a912bec00 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PrintStatement.cs +++ b/src/Parsing/Impl/Ast/PrintStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,65 +8,68 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class PrintStatement : Statement { - private readonly Expression _dest; private readonly Expression[] _expressions; - private readonly bool _trailingComma; public PrintStatement(Expression destination, Expression[] expressions, bool trailingComma) { - _dest = destination; + Destination = destination; _expressions = expressions; - _trailingComma = trailingComma; + TrailingComma = trailingComma; } - public Expression Destination { - get { return _dest; } - } + public Expression Destination { get; } - public IList Expressions { - get { return _expressions; } - } + public IList Expressions => _expressions; - public bool TrailingComma { - get { return _trailingComma; } - } + public bool TrailingComma { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_dest != null) { - _dest.Walk(walker); - } - if (_expressions != null) { - foreach (Expression expression in _expressions) { - expression.Walk(walker); - } + Destination?.Walk(walker); + foreach (var expression in _expressions.MaybeEnumerate()) { + expression.Walk(walker); } } walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Destination != null) { + await Destination.WalkAsync(walker, cancellationToken); + } + foreach (var expression in _expressions.MaybeEnumerate()) { + await expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("print"); - if (_dest != null) { + if (Destination != null) { res.Append(this.GetSecondWhiteSpace(ast)); res.Append(">>"); - _dest.AppendCodeString(res, ast, format); + Destination.AppendCodeString(res, ast, format); if (_expressions.Length > 0) { res.Append(this.GetThirdWhiteSpace(ast)); res.Append(','); } } - ListExpression.AppendItems(res, ast, format, "", "", this, Expressions); + ListExpression.AppendItems(res, ast, format, string.Empty, string.Empty, this, Expressions); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PythonAst.cs b/src/Parsing/Impl/Ast/PythonAst.cs similarity index 70% rename from src/Analysis/Engine/Impl/Parsing/Ast/PythonAst.cs rename to src/Parsing/Impl/Ast/PythonAst.cs index 7a6be1f65..39aba7fa9 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PythonAst.cs +++ b/src/Parsing/Impl/Ast/PythonAst.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,69 +17,56 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.PythonTools.Analysis; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { /// /// Top-level ast for all Python code. Holds onto the body and the line mapping information. /// public sealed class PythonAst : ScopeStatement { - private readonly PythonLanguageVersion _langVersion; private readonly Statement _body; - internal readonly NewLineLocation[] _lineLocations; - internal readonly SourceLocation[] _commentLocations; private readonly Dictionary> _attributes = new Dictionary>(); - private string _privatePrefix; - internal PythonAst(Statement body, NewLineLocation[] lineLocations, PythonLanguageVersion langVersion, SourceLocation[] commentLocations) { - if (body == null) { - throw new ArgumentNullException(nameof(body)); - } - _langVersion = langVersion; - _body = body; - _lineLocations = lineLocations; - _commentLocations = commentLocations; + public PythonAst(Statement body, NewLineLocation[] lineLocations, PythonLanguageVersion langVersion, SourceLocation[] commentLocations) { + _body = body ?? throw new ArgumentNullException(nameof(body)); + LanguageVersion = langVersion; + NewLineLocations = lineLocations; + CommentLocations = commentLocations; } - internal PythonAst(IEnumerable existingAst) { + public PythonAst(IEnumerable existingAst) { var asts = existingAst.ToArray(); _body = new SuiteStatement(asts.Select(a => a.Body).ToArray()); - _langVersion = asts.Select(a => a._langVersion).Distinct().Single(); + LanguageVersion = asts.Select(a => a.LanguageVersion).Distinct().Single(); var locs = new List(); var comments = new List(); - int offset = 0; + var offset = 0; foreach (var a in asts) { - locs.AddRange(a._lineLocations.Select(ll => new NewLineLocation(ll.EndIndex + offset, ll.Kind))); + locs.AddRange(a.NewLineLocations.Select(ll => new NewLineLocation(ll.EndIndex + offset, ll.Kind))); offset = locs.LastOrDefault().EndIndex; } - _lineLocations = locs.ToArray(); + NewLineLocations = locs.ToArray(); offset = 0; foreach (var a in asts) { - comments.AddRange(a._commentLocations.Select(cl => new SourceLocation(cl.Line + offset, cl.Column))); - offset += a._lineLocations.Length + 1; + comments.AddRange(a.CommentLocations.Select(cl => new SourceLocation(cl.Line + offset, cl.Column))); + offset += a.NewLineLocations.Length + 1; } - _commentLocations = comments.ToArray(); + CommentLocations = comments.ToArray(); } - public override string Name { - get { - return ""; - } - } + public NewLineLocation[] NewLineLocations { get; } + public SourceLocation[] CommentLocations { get; } + + public override string Name => ""; /// /// Gets the class name which this AST was parsed under. The class name is appended to any member /// accesses that occur. /// - public string PrivatePrefix { - get { - return _privatePrefix; - } - internal set { - _privatePrefix = value; - } - } + public string PrivatePrefix { get; internal set; } /// /// True if the AST was created with verbatim strings. @@ -94,13 +80,16 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } - public override Statement Body { - get { return _body; } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + await _body.WalkAsync(walker, cancellationToken); + } + await walker.PostWalkAsync(this, cancellationToken); } - public PythonLanguageVersion LanguageVersion { - get { return _langVersion; } - } + public override Statement Body => _body; + + public PythonLanguageVersion LanguageVersion { get; } internal bool TryGetAttribute(Node node, object key, out object value) { if (_attributes.TryGetValue(node, out var nodeAttrs)) { @@ -145,28 +134,22 @@ internal void SetAttributes(Dictionary> attribu } } - public SourceLocation IndexToLocation(int index) { - return NewLineLocation.IndexToLocation(_lineLocations, index); - } + public SourceLocation IndexToLocation(int index) => NewLineLocation.IndexToLocation(NewLineLocations, index); - public int LocationToIndex(SourceLocation location) { - return NewLineLocation.LocationToIndex(_lineLocations, location, EndIndex); - } + public int LocationToIndex(SourceLocation location) => NewLineLocation.LocationToIndex(NewLineLocations, location, EndIndex); /// /// Length of the span (number of characters inside the span). /// - public int GetSpanLength(SourceSpan span) { - return LocationToIndex(span.End) - LocationToIndex(span.Start); - } + public int GetSpanLength(SourceSpan span) => LocationToIndex(span.End) - LocationToIndex(span.Start); internal int GetLineEndFromPosition(int index) { var loc = IndexToLocation(index); - if (loc.Line >= _lineLocations.Length) { + if (loc.Line >= NewLineLocations.Length) { return index; } - var res = _lineLocations[loc.Line - 1]; + var res = NewLineLocations[loc.Line - 1]; switch (res.Kind) { case NewLineKind.LineFeed: case NewLineKind.CarriageReturn: return res.EndIndex - 1; @@ -178,16 +161,12 @@ internal int GetLineEndFromPosition(int index) { #region Name Binding Support - internal override bool ExposesLocalVariable(PythonVariable variable) { - return true; - } + internal override bool ExposesLocalVariable(PythonVariable variable) => true; internal override void FinishBind(PythonNameBinder binder) { } - internal override PythonVariable BindReference(PythonNameBinder binder, string name) { - return EnsureVariable(name); - } + internal override PythonVariable BindReference(PythonNameBinder binder, string name) => EnsureVariable(name); internal override bool TryBindOuter(ScopeStatement from, string name, bool allowGlobals, out PythonVariable variable) { if (allowGlobals) { @@ -210,9 +189,7 @@ internal override bool TryBindOuter(ScopeStatement from, string name, bool allow return false; } - internal override bool IsGlobal { - get { return true; } - } + public override bool IsGlobal => true; /// /// Creates a variable at the global level. Called for known globals (e.g. __name__), @@ -220,8 +197,7 @@ internal override bool IsGlobal { /// but not defined in the lexical scope. /// internal PythonVariable/*!*/ EnsureGlobalVariable(string name) { - PythonVariable variable; - if (!TryGetVariable(name, out variable)) { + if (!TryGetVariable(name, out var variable)) { variable = CreateVariable(name, VariableKind.Global); } @@ -230,8 +206,7 @@ internal override bool IsGlobal { internal PythonVariable/*!*/ EnsureNonlocalVariable(string name) { - PythonVariable variable; - if (!TryGetVariable(name, out variable)) { + if (!TryGetVariable(name, out var variable)) { variable = CreateVariable(name, VariableKind.Nonlocal); } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PythonNameBinder.cs b/src/Parsing/Impl/Ast/PythonNameBinder.cs similarity index 86% rename from src/Analysis/Engine/Impl/Parsing/Ast/PythonNameBinder.cs rename to src/Parsing/Impl/Ast/PythonNameBinder.cs index 0c5b0ac79..0b3ec0178 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PythonNameBinder.cs +++ b/src/Parsing/Impl/Ast/PythonNameBinder.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; /* @@ -43,9 +41,9 @@ * print x */ -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { internal class DefineBinder : PythonWalkerNonRecursive { - private PythonNameBinder _binder; + private readonly PythonNameBinder _binder; public DefineBinder(PythonNameBinder binder) { _binder = binder; } @@ -55,15 +53,9 @@ public override bool Walk(NameExpression node) { } return false; } - public override bool Walk(ParenthesisExpression node) { - return true; - } - public override bool Walk(TupleExpression node) { - return true; - } - public override bool Walk(ListExpression node) { - return true; - } + public override bool Walk(ParenthesisExpression node) => true; + public override bool Walk(TupleExpression node) => true; + public override bool Walk(ListExpression node) => true; } internal class ParameterBinder : PythonWalkerNonRecursive { @@ -84,23 +76,20 @@ public override bool Walk(SublistParameter node) { } private void WalkTuple(TupleExpression tuple) { - foreach (Expression innerNode in tuple.Items) { - NameExpression name = innerNode as NameExpression; - if (name != null) { + foreach (var innerNode in tuple.Items) { + if (innerNode is NameExpression name) { _binder.DefineName(name.Name); name.AddVariableReference(_binder.GlobalScope, _binder.BindReferences, _binder.Reference(name.Name)); - } else if (innerNode is TupleExpression) { - WalkTuple((TupleExpression)innerNode); + } else if (innerNode is TupleExpression expression) { + WalkTuple(expression); } } } - public override bool Walk(TupleExpression node) { - return true; - } + public override bool Walk(TupleExpression node) => true; } class DeleteBinder : PythonWalkerNonRecursive { - private PythonNameBinder _binder; + private readonly PythonNameBinder _binder; public DeleteBinder(PythonNameBinder binder) { _binder = binder; } @@ -120,9 +109,9 @@ class PythonNameBinder : PythonWalker { #region Recursive binders - private DefineBinder _define; - private DeleteBinder _delete; - private ParameterBinder _parameter; + private readonly DefineBinder _define; + private readonly DeleteBinder _delete; + private readonly ParameterBinder _parameter; #endregion @@ -141,7 +130,7 @@ private PythonNameBinder(PythonLanguageVersion langVersion, PythonAst ast, Error #region Public surface internal static void BindAst(PythonLanguageVersion langVersion, PythonAst ast, ErrorSink context, bool bindReferences) { - PythonNameBinder binder = new PythonNameBinder(langVersion, ast, context, bindReferences); + var binder = new PythonNameBinder(langVersion, ast, context, bindReferences); binder.Bind(ast); } @@ -157,7 +146,7 @@ private void Bind(PythonAst unboundAst) { unboundAst.Walk(this); // Bind - foreach (ScopeStatement scope in _scopes) { + foreach (var scope in _scopes) { scope.Bind(this); } @@ -165,7 +154,7 @@ private void Bind(PythonAst unboundAst) { unboundAst.Bind(this); // Finish Binding w/ outer most scopes first. - for (int i = _scopes.Count - 1; i >= 0; i--) { + for (var i = _scopes.Count - 1; i >= 0; i--) { _scopes[i].FinishBind(this); } @@ -197,19 +186,15 @@ internal PythonVariable DefineDeleted(string/*!*/ name) { return variable; } - internal void ReportSyntaxWarning(string message, Node node) { - _errorSink.Add(message, _ast._lineLocations, node.StartIndex, node.EndIndex, ErrorCodes.SyntaxError, Severity.Warning); - } + internal void ReportSyntaxWarning(string message, Node node) => _errorSink.Add(message, _ast.NewLineLocations, node.StartIndex, node.EndIndex, ErrorCodes.SyntaxError, Severity.Warning); - internal void ReportSyntaxError(string message, Node node) { - _errorSink.Add(message, _ast._lineLocations, node.StartIndex, node.EndIndex, ErrorCodes.SyntaxError, Severity.FatalError); - } + internal void ReportSyntaxError(string message, Node node) => _errorSink.Add(message, _ast.NewLineLocations, node.StartIndex, node.EndIndex, ErrorCodes.SyntaxError, Severity.FatalError); #region AstBinder Overrides // AssignmentStatement public override bool Walk(AssignmentStatement node) { - foreach (Expression e in node.Left) { + foreach (var e in node.Left) { e.Walk(_define); } return true; @@ -268,7 +253,7 @@ public override void PostWalk(ClassDefinition node) { // DelStatement public override bool Walk(DelStatement node) { - foreach (Expression e in node.Expressions) { + foreach (var e in node.Expressions) { e.Walk(_delete); } return true; @@ -331,7 +316,7 @@ public override bool Walk(WhileStatement node) { public override bool Walk(WithStatement node) { _currentScope.ContainsExceptionHandling = true; - for (int i = 0; i < node.Items.Count; i++) { + for (var i = 0; i < node.Items.Count; i++) { if (node.Items[i].Variable != null) { node.Items[i].Variable.Walk(_define); } @@ -342,12 +327,12 @@ public override bool Walk(WithStatement node) { // FromImportStatement public override bool Walk(FromImportStatement node) { if (node.Names.Count != 1 || node.Names[0].Name != "*") { - PythonVariable[] variables = new PythonVariable[node.Names.Count]; + var variables = new PythonVariable[node.Names.Count]; PythonReference[] references = null; if (BindReferences) { references = new PythonReference[node.Names.Count]; } - for (int i = 0; i < node.Names.Count; i++) { + for (var i = 0; i < node.Names.Count; i++) { variables[i] = DefineName(node.AsNames[i] != null ? node.AsNames[i].Name : node.Names[i].Name); if (references != null) { references[i] = Reference(variables[i].Name); @@ -405,19 +390,24 @@ public override void PostWalk(FunctionDefinition node) { // GlobalStatement public override bool Walk(GlobalStatement node) { - foreach (NameExpression nameNode in node.Names) { - string n = nameNode.Name; + foreach (var nameNode in node.Names) { + var n = nameNode.Name; if (n == null) { continue; } - PythonVariable conflict; // Check current scope for conflicting variable - bool assignedGlobal = false; - if (_currentScope.TryGetVariable(n, out conflict)) { + var assignedGlobal = false; + if (_currentScope.TryGetVariable(n, out var conflict)) { // conflict? switch (conflict.Kind) { case VariableKind.Global: + // OK to reassign, as long as kind is the same. + // Consider (from Python test grammar) + // global a + // global a, b + assignedGlobal = true; + break; case VariableKind.Local: assignedGlobal = true; ReportSyntaxWarning( @@ -443,7 +433,7 @@ public override bool Walk(GlobalStatement node) { // Create the variable in the global context and mark it as global - PythonVariable variable = GlobalScope.EnsureGlobalVariable(n); + var variable = GlobalScope.EnsureGlobalVariable(n); variable.Kind = VariableKind.Global; if (conflict == null) { @@ -457,16 +447,15 @@ public override bool Walk(GlobalStatement node) { } public override bool Walk(NonlocalStatement node) { - foreach (NameExpression nameNode in node.Names) { - string n = nameNode.Name; + foreach (var nameNode in node.Names) { + var n = nameNode.Name; if (n == null) { continue; } - PythonVariable conflict; // Check current scope for conflicting variable - bool assignedLocal = false; - if (_currentScope.TryGetVariable(n, out conflict)) { + var assignedLocal = false; + if (_currentScope.TryGetVariable(n, out var conflict)) { // conflict? switch (conflict.Kind) { case VariableKind.Global: @@ -484,6 +473,13 @@ public override bool Walk(NonlocalStatement node) { "name '{0}' is a parameter and nonlocal".FormatUI(n), node); break; + case VariableKind.Nonlocal: + // OK to reassign as long as kind is the same. + // Consider example from Python test grammar: + // nonlocal x + // nonlocal x, y + assignedLocal = true; + break; } } @@ -510,22 +506,8 @@ public override bool Walk(NameExpression node) { return true; } - public override bool Walk(PrintStatement node) { - return base.Walk(node); - } - - public override bool Walk(IfStatement node) { - return base.Walk(node); - } - - public override bool Walk(AssertStatement node) { - return base.Walk(node); - } - // PythonAst - public override bool Walk(PythonAst node) { - return true; - } + public override bool Walk(PythonAst node) => true; // PythonAst public override void PostWalk(PythonAst node) { @@ -574,7 +556,7 @@ public override bool Walk(TryStatement node) { node.Body.Walk(this); if (node.Handlers != null) { - foreach (TryStatementHandler tsh in node.Handlers) { + foreach (var tsh in node.Handlers) { if (tsh.Target != null) { tsh.Target.Walk(_define); } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PythonOperator.cs b/src/Parsing/Impl/Ast/PythonOperator.cs similarity index 90% rename from src/Analysis/Engine/Impl/Parsing/Ast/PythonOperator.cs rename to src/Parsing/Impl/Ast/PythonOperator.cs index b8f69de56..f8a895236 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PythonOperator.cs +++ b/src/Parsing/Impl/Ast/PythonOperator.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,12 +8,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public enum PythonOperator { None, @@ -62,8 +61,8 @@ public enum PythonOperator { NotEquals = NotEqual, } - internal static class PythonOperatorExtensions { - internal static string ToCodeString(this PythonOperator self) { + public static class PythonOperatorExtensions { + public static string ToCodeString(this PythonOperator self) { switch (self) { case PythonOperator.Not: return "not"; case PythonOperator.Pos: return "+"; @@ -97,8 +96,7 @@ internal static string ToCodeString(this PythonOperator self) { return string.Empty; } - internal static bool IsComparison(this PythonOperator self) { - return self == PythonOperator.LessThan || + public static bool IsComparison(this PythonOperator self) => self == PythonOperator.LessThan || self == PythonOperator.LessThanOrEqual || self == PythonOperator.GreaterThan || self == PythonOperator.GreaterThanOrEqual || @@ -108,6 +106,5 @@ internal static bool IsComparison(this PythonOperator self) { self == PythonOperator.NotIn || self == PythonOperator.IsNot || self == PythonOperator.Is; - } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PythonReference.cs b/src/Parsing/Impl/Ast/PythonReference.cs similarity index 68% rename from src/Analysis/Engine/Impl/Parsing/Ast/PythonReference.cs rename to src/Parsing/Impl/Ast/PythonReference.cs index 2aa90add2..72f998f62 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PythonReference.cs +++ b/src/Parsing/Impl/Ast/PythonReference.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,31 +8,23 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { /// /// Represents a reference to a name. A PythonReference is created for each location /// where a name is referred to in a scope (global, class, or function). /// public class PythonReference { - private readonly string/*!*/ _name; - private PythonVariable _variable; - public PythonReference(string/*!*/ name) { - _name = name; + Name = name; } - public string/*!*/ Name { - get { return _name; } - } + public string/*!*/ Name { get; } - public PythonVariable Variable { - get { return _variable; } - set { _variable = value; } - } + public PythonVariable Variable { get; set; } } } diff --git a/src/Parsing/Impl/Ast/PythonVariable.cs b/src/Parsing/Impl/Ast/PythonVariable.cs new file mode 100644 index 000000000..a28a59b30 --- /dev/null +++ b/src/Parsing/Impl/Ast/PythonVariable.cs @@ -0,0 +1,48 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +namespace Microsoft.Python.Parsing.Ast { + public class PythonVariable { + internal PythonVariable(string name, VariableKind kind, ScopeStatement/*!*/ scope) { + Name = name; + Kind = kind; + Scope = scope; + } + + /// + /// The name of the variable. + /// + public string Name { get; } + + /// + /// The scope the variable was declared in. + /// + public ScopeStatement Scope { get; } + + /// + /// True if the variable is a global variable (either referenced from an inner scope, or referenced from the global scope); + /// + internal bool IsGlobal => Kind == VariableKind.Global || Scope.IsGlobal; + + internal VariableKind Kind { get; set; } + + internal bool Deleted { get; set; } + + /// + /// True iff the variable is referred to from the inner scope. + /// + internal bool AccessedInNestedScope { get; set; } + } +} diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/PythonWalker.Generated.cs b/src/Parsing/Impl/Ast/PythonWalker.Generated.cs similarity index 99% rename from src/Analysis/Engine/Impl/Parsing/Ast/PythonWalker.Generated.cs rename to src/Parsing/Impl/Ast/PythonWalker.Generated.cs index e66f7f466..73df22971 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/PythonWalker.Generated.cs +++ b/src/Parsing/Impl/Ast/PythonWalker.Generated.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,17 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing.Ast { +using Microsoft.Python.Core.Text; + +namespace Microsoft.Python.Parsing.Ast { /// /// PythonWalker class - The Python AST Walker (default result is true) /// public class PythonWalker { - // AndExpression public virtual bool Walk(AndExpression node) { return true; } public virtual void PostWalk(AndExpression node) { } diff --git a/src/Parsing/Impl/Ast/PythonWalkerAsync.Generated.cs b/src/Parsing/Impl/Ast/PythonWalkerAsync.Generated.cs new file mode 100644 index 000000000..8aade0e15 --- /dev/null +++ b/src/Parsing/Impl/Ast/PythonWalkerAsync.Generated.cs @@ -0,0 +1,866 @@ +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core.Text; + +namespace Microsoft.Python.Parsing.Ast { + /// + /// PythonWalker class - The Python AST Walker (default result is true) + /// + public class PythonWalkerAsync { + // AndExpression + public virtual Task WalkAsync(AndExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(AndExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AwaitExpression + public virtual Task WalkAsync(AwaitExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(AwaitExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // BackQuoteExpression + public virtual Task WalkAsync(BackQuoteExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(BackQuoteExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // BinaryExpression + public virtual Task WalkAsync(BinaryExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(BinaryExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // CallExpression + public virtual Task WalkAsync(CallExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(CallExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ConditionalExpression + public virtual Task WalkAsync(ConditionalExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ConditionalExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ConstantExpression + public virtual Task WalkAsync(ConstantExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ConstantExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DictionaryComprehension + public virtual Task WalkAsync(DictionaryComprehension node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(DictionaryComprehension node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DictionaryExpression + public virtual Task WalkAsync(DictionaryExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(DictionaryExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ErrorExpression + public virtual Task WalkAsync(ErrorExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ErrorExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ExpressionWithAnnotation + public virtual Task WalkAsync(ExpressionWithAnnotation node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ExpressionWithAnnotation node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // GeneratorExpression + public virtual Task WalkAsync(GeneratorExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(GeneratorExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // IndexExpression + public virtual Task WalkAsync(IndexExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(IndexExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // LambdaExpression + public virtual Task WalkAsync(LambdaExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(LambdaExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ListComprehension + public virtual Task WalkAsync(ListComprehension node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ListComprehension node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ListExpression + public virtual Task WalkAsync(ListExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ListExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // MemberExpression + public virtual Task WalkAsync(MemberExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(MemberExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // NameExpression + public virtual Task WalkAsync(NameExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(NameExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // OrExpression + public virtual Task WalkAsync(OrExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(OrExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ParenthesisExpression + public virtual Task WalkAsync(ParenthesisExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ParenthesisExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SetComprehension + public virtual Task WalkAsync(SetComprehension node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(SetComprehension node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SetExpression + public virtual Task WalkAsync(SetExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(SetExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SliceExpression + public virtual Task WalkAsync(SliceExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(SliceExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // TupleExpression + public virtual Task WalkAsync(TupleExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(TupleExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // UnaryExpression + public virtual Task WalkAsync(UnaryExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(UnaryExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // YieldExpression + public virtual Task WalkAsync(YieldExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(YieldExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // YieldFromExpression + public virtual Task WalkAsync(YieldFromExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(YieldFromExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // StarredExpression + public virtual Task WalkAsync(StarredExpression node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(StarredExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AssertStatement + public virtual Task WalkAsync(AssertStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(AssertStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AssignmentStatement + public virtual Task WalkAsync(AssignmentStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(AssignmentStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AugmentedAssignStatement + public virtual Task WalkAsync(AugmentedAssignStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(AugmentedAssignStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // BreakStatement + public virtual Task WalkAsync(BreakStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(BreakStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ClassDefinition + public virtual Task WalkAsync(ClassDefinition node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ClassDefinition node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ContinueStatement + public virtual Task WalkAsync(ContinueStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ContinueStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DelStatement + public virtual Task WalkAsync(DelStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(DelStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // EmptyStatement + public virtual Task WalkAsync(EmptyStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(EmptyStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ExecStatement + public virtual Task WalkAsync(ExecStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ExecStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ExpressionStatement + public virtual Task WalkAsync(ExpressionStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ExpressionStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ForStatement + public virtual Task WalkAsync(ForStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ForStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // FromImportStatement + public virtual Task WalkAsync(FromImportStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(FromImportStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // FunctionDefinition + public virtual Task WalkAsync(FunctionDefinition node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(FunctionDefinition node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // GlobalStatement + public virtual Task WalkAsync(GlobalStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(GlobalStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // NonlocalStatement + public virtual Task WalkAsync(NonlocalStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(NonlocalStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // IfStatement + public virtual Task WalkAsync(IfStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(IfStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ImportStatement + public virtual Task WalkAsync(ImportStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ImportStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // PrintStatement + public virtual Task WalkAsync(PrintStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(PrintStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // PythonAst + public virtual Task WalkAsync(PythonAst node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(PythonAst node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // RaiseStatement + public virtual Task WalkAsync(RaiseStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(RaiseStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ReturnStatement + public virtual Task WalkAsync(ReturnStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ReturnStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SuiteStatement + public virtual Task WalkAsync(SuiteStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(SuiteStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // TryStatement + public virtual Task WalkAsync(TryStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(TryStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // WhileStatement + public virtual Task WalkAsync(WhileStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(WhileStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // WithStatement + public virtual Task WalkAsync(WithStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(WithStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // WithItem + public virtual Task WalkAsync(WithItem node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(WithItem node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // Arg + public virtual Task WalkAsync(Arg node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(Arg node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ComprehensionFor + public virtual Task WalkAsync(ComprehensionFor node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ComprehensionFor node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ComprehensionIf + public virtual Task WalkAsync(ComprehensionIf node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ComprehensionIf node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DottedName + public virtual Task WalkAsync(DottedName node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(DottedName node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // IfStatementTest + public virtual Task WalkAsync(IfStatementTest node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(IfStatementTest node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ModuleName + public virtual Task WalkAsync(ModuleName node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ModuleName node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // Parameter + public virtual Task WalkAsync(Parameter node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(Parameter node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // RelativeModuleName + public virtual Task WalkAsync(RelativeModuleName node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(RelativeModuleName node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SublistParameter + public virtual Task WalkAsync(SublistParameter node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(SublistParameter node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // TryStatementHandler + public virtual Task WalkAsync(TryStatementHandler node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(TryStatementHandler node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ErrorStatement + public virtual Task WalkAsync(ErrorStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(ErrorStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DecoratorStatement + public virtual Task WalkAsync(DecoratorStatement node, CancellationToken cancellationToken = default) => Task.FromResult(true); + public virtual Task PostWalkAsync(DecoratorStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + } + + + /// + /// PythonWalkerNonRecursive class - The Python AST Walker (default result is false) + /// + public class PythonWalkerNonRecursiveAsync : PythonWalkerAsync { + // AndExpression + public override Task WalkAsync(AndExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(AndExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AndExpression + public override Task WalkAsync(AwaitExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(AwaitExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // BackQuoteExpression + public override Task WalkAsync(BackQuoteExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(BackQuoteExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // BinaryExpression + public override Task WalkAsync(BinaryExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(BinaryExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // CallExpression + public override Task WalkAsync(CallExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(CallExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ConditionalExpression + public override Task WalkAsync(ConditionalExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ConditionalExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ConstantExpression + public override Task WalkAsync(ConstantExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ConstantExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DictionaryComprehension + public override Task WalkAsync(DictionaryComprehension node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(DictionaryComprehension node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DictionaryExpression + public override Task WalkAsync(DictionaryExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(DictionaryExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ErrorExpression + public override Task WalkAsync(ErrorExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ErrorExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ExpressionWithAnnotation + public override Task WalkAsync(ExpressionWithAnnotation node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ExpressionWithAnnotation node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // GeneratorExpression + public override Task WalkAsync(GeneratorExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(GeneratorExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // IndexExpression + public override Task WalkAsync(IndexExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(IndexExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // LambdaExpression + public override Task WalkAsync(LambdaExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(LambdaExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ListComprehension + public override Task WalkAsync(ListComprehension node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ListComprehension node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ListExpression + public override Task WalkAsync(ListExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ListExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // MemberExpression + public override Task WalkAsync(MemberExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(MemberExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // NameExpression + public override Task WalkAsync(NameExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(NameExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // OrExpression + public override Task WalkAsync(OrExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(OrExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ParenthesisExpression + public override Task WalkAsync(ParenthesisExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ParenthesisExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SetComprehension + public override Task WalkAsync(SetComprehension node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(SetComprehension node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SetExpression + public override Task WalkAsync(SetExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(SetExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SliceExpression + public override Task WalkAsync(SliceExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(SliceExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // TupleExpression + public override Task WalkAsync(TupleExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(TupleExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // UnaryExpression + public override Task WalkAsync(UnaryExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(UnaryExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // YieldExpression + public override Task WalkAsync(YieldExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(YieldExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // YieldFromExpression + public override Task WalkAsync(YieldFromExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(YieldFromExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // StarredExpression + public override Task WalkAsync(StarredExpression node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(StarredExpression node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AssertStatement + public override Task WalkAsync(AssertStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(AssertStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AssignmentStatement + public override Task WalkAsync(AssignmentStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(AssignmentStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // AugmentedAssignStatement + public override Task WalkAsync(AugmentedAssignStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(AugmentedAssignStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // BreakStatement + public override Task WalkAsync(BreakStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(BreakStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ClassDefinition + public override Task WalkAsync(ClassDefinition node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ClassDefinition node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ContinueStatement + public override Task WalkAsync(ContinueStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ContinueStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DelStatement + public override Task WalkAsync(DelStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(DelStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // EmptyStatement + public override Task WalkAsync(EmptyStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(EmptyStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ExecStatement + public override Task WalkAsync(ExecStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ExecStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ExpressionStatement + public override Task WalkAsync(ExpressionStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ExpressionStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ForStatement + public override Task WalkAsync(ForStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ForStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // FromImportStatement + public override Task WalkAsync(FromImportStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(FromImportStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // FunctionDefinition + public override Task WalkAsync(FunctionDefinition node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(FunctionDefinition node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // GlobalStatement + public override Task WalkAsync(GlobalStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(GlobalStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // NonlocalStatement + public override Task WalkAsync(NonlocalStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(NonlocalStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // IfStatement + public override Task WalkAsync(IfStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(IfStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ImportStatement + public override Task WalkAsync(ImportStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ImportStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // PrintStatement + public override Task WalkAsync(PrintStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(PrintStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // PythonAst + public override Task WalkAsync(PythonAst node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(PythonAst node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // RaiseStatement + public override Task WalkAsync(RaiseStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(RaiseStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ReturnStatement + public override Task WalkAsync(ReturnStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ReturnStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SuiteStatement + public override Task WalkAsync(SuiteStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(SuiteStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // TryStatement + public override Task WalkAsync(TryStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(TryStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // WhileStatement + public override Task WalkAsync(WhileStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(WhileStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // WithStatement + public override Task WalkAsync(WithStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(WithStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // WithItem + public override Task WalkAsync(WithItem node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(WithItem node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // Arg + public override Task WalkAsync(Arg node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(Arg node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ComprehensionFor + public override Task WalkAsync(ComprehensionFor node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ComprehensionFor node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ComprehensionIf + public override Task WalkAsync(ComprehensionIf node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ComprehensionIf node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DottedName + public override Task WalkAsync(DottedName node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(DottedName node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // IfStatementTest + public override Task WalkAsync(IfStatementTest node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(IfStatementTest node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ModuleName + public override Task WalkAsync(ModuleName node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ModuleName node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // Parameter + public override Task WalkAsync(Parameter node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(Parameter node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // RelativeModuleName + public override Task WalkAsync(RelativeModuleName node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(RelativeModuleName node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // SublistParameter + public override Task WalkAsync(SublistParameter node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(SublistParameter node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // TryStatementHandler + public override Task WalkAsync(TryStatementHandler node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(TryStatementHandler node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // ErrorStatement + public override Task WalkAsync(ErrorStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(ErrorStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + + // DecoratorStatement + public override Task WalkAsync(DecoratorStatement node, CancellationToken cancellationToken = default) => Task.FromResult(false); + public override Task PostWalkAsync(DecoratorStatement node, CancellationToken cancellationToken = default) => Task.CompletedTask; + } + + /// + /// PythonWalkerWithLocation class - The Python AST Walker (default result + /// is true if the node contains Location, otherwise false) + /// + public class PythonWalkerWithLocationAsync : PythonWalkerAsync { + public readonly int Location; + + private SourceLocation _loc = SourceLocation.Invalid; + + public PythonWalkerWithLocationAsync(int location) { + Location = location; + } + + /// + /// Required when ExtendedStatements is set. + /// + public PythonAst Tree { get; set; } + + /// + /// When enabled, statements will be walked if Location is on the same line. + /// Note that this may walk multiple statements if they are on the same line. Ensure + /// your walker state can handle this! + /// + public bool ExtendedStatements { get; set; } + + private bool Contains(Statement stmt) { + if (Location < stmt.StartIndex) { + return false; + } + if (Location <= stmt.EndIndex) { + return true; + } + if (!ExtendedStatements || Tree == null) { + return false; + } + if (!_loc.IsValid) { + _loc = Tree.IndexToLocation(Location); + } + var start = Tree.IndexToLocation(stmt.StartIndex); + return _loc.Line == start.Line && _loc.Column > start.Column; + } + + // AndExpression + public override Task WalkAsync(AndExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // AndExpression + public override Task WalkAsync(AwaitExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // BackQuoteExpression + public override Task WalkAsync(BackQuoteExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // BinaryExpression + public override Task WalkAsync(BinaryExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // CallExpression + public override Task WalkAsync(CallExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ConditionalExpression + public override Task WalkAsync(ConditionalExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ConstantExpression + public override Task WalkAsync(ConstantExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // DictionaryComprehension + public override Task WalkAsync(DictionaryComprehension node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // DictionaryExpression + public override Task WalkAsync(DictionaryExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ErrorExpression + public override Task WalkAsync(ErrorExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ExpressionWithAnnotation + public override Task WalkAsync(ExpressionWithAnnotation node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // GeneratorExpression + public override Task WalkAsync(GeneratorExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // IndexExpression + public override Task WalkAsync(IndexExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // LambdaExpression + public override Task WalkAsync(LambdaExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ListComprehension + public override Task WalkAsync(ListComprehension node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ListExpression + public override Task WalkAsync(ListExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // MemberExpression + public override Task WalkAsync(MemberExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // NameExpression + public override Task WalkAsync(NameExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // OrExpression + public override Task WalkAsync(OrExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ParenthesisExpression + public override Task WalkAsync(ParenthesisExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // SetComprehension + public override Task WalkAsync(SetComprehension node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // SetExpression + public override Task WalkAsync(SetExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // SliceExpression + public override Task WalkAsync(SliceExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // TupleExpression + public override Task WalkAsync(TupleExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // UnaryExpression + public override Task WalkAsync(UnaryExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // YieldExpression + public override Task WalkAsync(YieldExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // YieldFromExpression + public override Task WalkAsync(YieldFromExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // StarredExpression + public override Task WalkAsync(StarredExpression node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // AssertStatement + public override Task WalkAsync(AssertStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // AssignmentStatement + public override Task WalkAsync(AssignmentStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // AugmentedAssignStatement + public override Task WalkAsync(AugmentedAssignStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // BreakStatement + public override Task WalkAsync(BreakStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ClassDefinition + public override Task WalkAsync(ClassDefinition node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ContinueStatement + public override Task WalkAsync(ContinueStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // DelStatement + public override Task WalkAsync(DelStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // EmptyStatement + public override Task WalkAsync(EmptyStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ExecStatement + public override Task WalkAsync(ExecStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ExpressionStatement + public override Task WalkAsync(ExpressionStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ForStatement + public override Task WalkAsync(ForStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // FromImportStatement + public override Task WalkAsync(FromImportStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // FunctionDefinition + public override Task WalkAsync(FunctionDefinition node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // GlobalStatement + public override Task WalkAsync(GlobalStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // NonlocalStatement + public override Task WalkAsync(NonlocalStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // IfStatement + public override Task WalkAsync(IfStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ImportStatement + public override Task WalkAsync(ImportStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // PrintStatement + public override Task WalkAsync(PrintStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // PythonAst + public override Task WalkAsync(PythonAst node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // RaiseStatement + public override Task WalkAsync(RaiseStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // ReturnStatement + public override Task WalkAsync(ReturnStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // SuiteStatement + public override Task WalkAsync(SuiteStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // TryStatement + public override Task WalkAsync(TryStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // WhileStatement + public override Task WalkAsync(WhileStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // WithStatement + public override Task WalkAsync(WithStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // WithItem + public override Task WalkAsync(WithItem node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // Arg + public override Task WalkAsync(Arg node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ComprehensionFor + public override Task WalkAsync(ComprehensionFor node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ComprehensionIf + public override Task WalkAsync(ComprehensionIf node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // DottedName + public override Task WalkAsync(DottedName node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // IfStatementTest + public override Task WalkAsync(IfStatementTest node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ModuleName + public override Task WalkAsync(ModuleName node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // Parameter + public override Task WalkAsync(Parameter node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // RelativeModuleName + public override Task WalkAsync(RelativeModuleName node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // SublistParameter + public override Task WalkAsync(SublistParameter node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // TryStatementHandler + public override Task WalkAsync(TryStatementHandler node, CancellationToken cancellationToken = default) + => Task.FromResult(Location >= node.StartIndex && Location <= node.EndIndex); + + // ErrorStatement + public override Task WalkAsync(ErrorStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + + // DecoratorStatement + public override Task WalkAsync(DecoratorStatement node, CancellationToken cancellationToken = default) + => Task.FromResult(Contains(node)); + } +} diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/RaiseStatement.cs b/src/Parsing/Impl/Ast/RaiseStatement.cs similarity index 74% rename from src/Analysis/Engine/Impl/Parsing/Ast/RaiseStatement.cs rename to src/Parsing/Impl/Ast/RaiseStatement.cs index b49f890ff..d18cf595b 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/RaiseStatement.cs +++ b/src/Parsing/Impl/Ast/RaiseStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class RaiseStatement : Statement { public RaiseStatement(Expression exceptionType, Expression exceptionValue, Expression traceBack, Expression cause) { ExceptType = exceptionType; @@ -45,6 +46,24 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (ExceptType != null) { + await ExceptType.WalkAsync(walker, cancellationToken); + } + if (Value != null) { + await Value.WalkAsync(walker, cancellationToken); + } + if (Traceback != null) { + await Traceback.WalkAsync(walker, cancellationToken); + } + if (Cause != null) { + await Cause.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("raise"); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/RelativeModuleName.cs b/src/Parsing/Impl/Ast/RelativeModuleName.cs similarity index 93% rename from src/Analysis/Engine/Impl/Parsing/Ast/RelativeModuleName.cs rename to src/Parsing/Impl/Ast/RelativeModuleName.cs index ef0501463..26a69e83e 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/RelativeModuleName.cs +++ b/src/Parsing/Impl/Ast/RelativeModuleName.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class RelativeModuleName : ModuleName { public RelativeModuleName(NameExpression[]/*!*/ names, int dotCount) : base(names) { @@ -29,7 +29,7 @@ public RelativeModuleName(NameExpression[]/*!*/ names, int dotCount) internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { var whitespace = this.GetListWhiteSpace(ast); - for (int i = 0; i < DotCount; i++) { + for (var i = 0; i < DotCount; i++) { if (whitespace != null) { res.Append(whitespace[i]); } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ReturnStatement.cs b/src/Parsing/Impl/Ast/ReturnStatement.cs similarity index 60% rename from src/Analysis/Engine/Impl/Parsing/Ast/ReturnStatement.cs rename to src/Parsing/Impl/Ast/ReturnStatement.cs index 13fdc73dc..b58d47c3d 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ReturnStatement.cs +++ b/src/Parsing/Impl/Ast/ReturnStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,48 +8,52 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class ReturnStatement : Statement { - private readonly Expression _expression; - public ReturnStatement(Expression expression) { - _expression = expression; + Expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } - public void RoundTripRemoveValueWhiteSpace(PythonAst ast) { - ast.SetAttribute(this, NodeAttributes.IsAltFormValue, NodeAttributes.IsAltFormValue); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } + public void RoundTripRemoveValueWhiteSpace(PythonAst ast) + => ast.SetAttribute(this, NodeAttributes.IsAltFormValue, NodeAttributes.IsAltFormValue); + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("return"); - if (_expression != null) { - int len = res.Length; + if (Expression != null) { + var len = res.Length; - _expression.AppendCodeString(res, ast, format); + Expression.AppendCodeString(res, ast, format); if (this.IsAltForm(ast)) { // remove the leading white space and insert a single space - res.Remove(len, _expression.GetLeadingWhiteSpace(ast).Length); + res.Remove(len, Expression.GetLeadingWhiteSpace(ast).Length); res.Insert(len, ' '); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/ScopeStatement.cs b/src/Parsing/Impl/Ast/ScopeStatement.cs similarity index 68% rename from src/Analysis/Engine/Impl/Parsing/Ast/ScopeStatement.cs rename to src/Parsing/Impl/Ast/ScopeStatement.cs index 4c1f5c653..45900967d 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/ScopeStatement.cs +++ b/src/Parsing/Impl/Ast/ScopeStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,72 +16,41 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Microsoft.PythonTools.Analysis.Infrastructure; - -namespace Microsoft.PythonTools.Parsing.Ast { +using Microsoft.Python.Core; +namespace Microsoft.Python.Parsing.Ast { public abstract class ScopeStatement : Statement { - private bool _importStar; // from module import * - private bool _unqualifiedExec; // exec "code" - private bool _nestedFreeVariables; // nested function with free variable - private bool _locals; // The scope needs locals dictionary // due to "exec" or call to dir, locals, eval, vars... - private bool _hasLateboundVarSets; // calls code which can assign to variables - private bool _containsExceptionHandling; // true if this block contains a try/with statement - private Dictionary _variables; // mapping of string to variables private ClosureInfo[] _closureVariables; // closed over variables, bool indicates if we accessed it in this scope. private List _freeVars; // list of variables accessed from outer scopes private List _globalVars; // global variables accessed from this scope private List _cellVars; // variables accessed from nested scopes private List _nonLocalVars; // variables declared as nonlocal within this scope private Dictionary> _references; // names of all variables referenced, null after binding completes - private ScopeStatement _parent; internal const string NameForExec = "module: "; - public ScopeStatement Parent { - get { return _parent; } - set { _parent = value; } - } + public ScopeStatement Parent { get; set; } public abstract Statement Body { get; } - internal bool ContainsImportStar { - get { return _importStar; } - set { _importStar = value; } - } - - internal bool ContainsExceptionHandling { - get { - return _containsExceptionHandling; - } - set { - _containsExceptionHandling = value; - } - } + internal bool ContainsImportStar { get; set; } + internal bool ContainsExceptionHandling { get; set; } - internal bool ContainsUnqualifiedExec { - get { return _unqualifiedExec; } - set { _unqualifiedExec = value; } - } + internal bool ContainsUnqualifiedExec { get; set; } /// /// True if this scope accesses a variable from an outer scope. /// - internal bool IsClosure { - get { return FreeVariables != null && FreeVariables.Count > 0; } - } + public bool IsClosure => FreeVariables != null && FreeVariables.Count > 0; /// /// True if an inner scope is accessing a variable defined in this scope. /// - internal bool ContainsNestedFreeVariables { - get { return _nestedFreeVariables; } - set { _nestedFreeVariables = value; } - } + public bool ContainsNestedFreeVariables { get; set; } /// /// True if we are forcing the creation of a dictionary for storing locals. @@ -90,16 +58,9 @@ internal bool ContainsNestedFreeVariables { /// This occurs for calls to locals(), dir(), vars(), unqualified exec, and /// from ... import *. /// - internal bool NeedsLocalsDictionary { - get { return _locals; } - set { _locals = value; } - } + public bool NeedsLocalsDictionary { get; set; } - public virtual string/*!*/ Name { - get { - return ""; - } - } + public virtual string/*!*/ Name => ""; /// /// True if variables can be set in a late bound fashion that we don't @@ -107,50 +68,23 @@ public virtual string/*!*/ Name { /// /// This is tracked independently of the ContainsUnqualifiedExec/NeedsLocalsDictionary /// - internal virtual bool HasLateBoundVariableSets { - get { - return _hasLateboundVarSets; - } - set { - _hasLateboundVarSets = value; - } - } + internal virtual bool HasLateBoundVariableSets { get; set; } - internal Dictionary Variables { - get { return _variables; } - } + internal Dictionary Variables { get; private set; } /// /// Gets the variables for this scope. /// - public ICollection ScopeVariables { - get { - if (_variables != null) { - return _variables.Values; - } - return null; - } - } + public ICollection ScopeVariables + => Variables?.Values ?? Array.Empty() as ICollection; - internal virtual bool IsGlobal { - get { return false; } - } - - internal virtual bool NeedsLocalContext { - get { - return NeedsLocalsDictionary || ContainsNestedFreeVariables; - } - } - - internal virtual int ArgCount { - get { - return 0; - } - } + public virtual bool IsGlobal => false; + public virtual bool NeedsLocalContext => NeedsLocalsDictionary || ContainsNestedFreeVariables; + public virtual int ArgCount => 0; public PythonAst GlobalParent { get { - ScopeStatement cur = this; + var cur = this; while (!(cur is PythonAst)) { Debug.Assert(cur != null); cur = cur.Parent; @@ -199,36 +133,24 @@ internal void AddCellVariable(PythonVariable variable) { /// /// Variables that are bound in an outer scope - but not a global scope /// - public IList FreeVariables { - get { - return _freeVars; - } - } + public IReadOnlyList FreeVariables => _freeVars; /// /// Variables that are bound to the global scope /// - public IList GlobalVariables { - get { - return _globalVars; - } - } + public IReadOnlyList GlobalVariables => _globalVars; /// /// Variables that are referred to from a nested scope and need to be /// promoted to cells. /// - internal IList CellVariables { - get { - return _cellVars; - } - } + public IReadOnlyList CellVariables => _cellVars; internal abstract bool ExposesLocalVariable(PythonVariable variable); public bool TryGetVariable(string name, out PythonVariable variable) { - if (_variables != null && name != null) { - return _variables.TryGetValue(name, out variable); + if (Variables != null && name != null) { + return Variables.TryGetValue(name, out variable); } else { variable = null; return false; @@ -270,11 +192,9 @@ internal virtual void FinishBind(PythonNameBinder binder) { if (_nonLocalVars != null) { foreach (var variableName in _nonLocalVars) { - bool bound = false; - for (ScopeStatement parent = Parent; parent != null; parent = parent.Parent) { - PythonVariable variable; - - if (parent.TryBindOuter(this, variableName.Name, false, out variable)) { + var bound = false; + for (var parent = Parent; parent != null; parent = parent.Parent) { + if (parent.TryBindOuter(this, variableName.Name, false, out var variable)) { bound = !variable.IsGlobal; break; } @@ -299,7 +219,7 @@ internal virtual void FinishBind(PythonNameBinder binder) { closureVariables = new List(); } - foreach (PythonVariable variable in Variables.Values) { + foreach (var variable in Variables.Values) { if (!HasClosureVariable(closureVariables, variable) && !variable.IsGlobal && (variable.AccessedInNestedScope || ExposesLocalVariable(variable))) { closureVariables.Add(new ClosureInfo(variable, true)); @@ -324,7 +244,7 @@ private static bool HasClosureVariable(List closureVariables, Pytho return false; } - for (int i = 0; i < closureVariables.Count; i++) { + for (var i = 0; i < closureVariables.Count; i++) { if (closureVariables[i].Variable == variable) { return true; } @@ -334,14 +254,14 @@ private static bool HasClosureVariable(List closureVariables, Pytho } private void EnsureVariables() { - if (_variables == null) { - _variables = new Dictionary(StringComparer.Ordinal); + if (Variables == null) { + Variables = new Dictionary(StringComparer.Ordinal); } } internal void AddVariable(PythonVariable variable) { EnsureVariables(); - _variables[variable.Name] = variable; + Variables[variable.Name] = variable; } internal PythonReference Reference(string/*!*/ name) { @@ -357,28 +277,23 @@ internal PythonReference Reference(string/*!*/ name) { return reference; } - internal bool IsReferenced(string name) { - return _references != null && _references.ContainsKey(name); - } + internal bool IsReferenced(string name) => _references != null && _references.ContainsKey(name); internal PythonVariable/*!*/ CreateVariable(string name, VariableKind kind) { EnsureVariables(); PythonVariable variable; - _variables[name] = variable = new PythonVariable(name, kind, this); + Variables[name] = variable = new PythonVariable(name, kind, this); return variable; } internal PythonVariable/*!*/ EnsureVariable(string/*!*/ name) { - PythonVariable variable; - if (!TryGetVariable(name, out variable)) { + if (!TryGetVariable(name, out var variable)) { return CreateVariable(name, VariableKind.Local); } return variable; } - internal PythonVariable DefineParameter(string name) { - return CreateVariable(name, VariableKind.Parameter); - } + internal PythonVariable DefineParameter(string name) => CreateVariable(name, VariableKind.Parameter); struct ClosureInfo { public PythonVariable Variable; diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/SequenceExpression.cs b/src/Parsing/Impl/Ast/SequenceExpression.cs similarity index 78% rename from src/Analysis/Engine/Impl/Parsing/Ast/SequenceExpression.cs rename to src/Parsing/Impl/Ast/SequenceExpression.cs index cafa9103a..0e76b9cf3 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/SequenceExpression.cs +++ b/src/Parsing/Impl/Ast/SequenceExpression.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public abstract class SequenceExpression : Expression { private readonly Expression[] _items; @@ -24,13 +24,11 @@ protected SequenceExpression(Expression[] items) { _items = items; } - public IList Items { - get { return _items; } - } + public IList Items => _items; internal override string CheckAssign() { - for (int i = 0; i < Items.Count; i++) { - Expression e = Items[i]; + for (var i = 0; i < Items.Count; i++) { + var e = Items[i]; if (e is StarredExpression se && se.StarCount == 1) { continue; } @@ -47,8 +45,8 @@ internal override string CheckAssign() { } internal override string CheckDelete() { - for (int i = 0; i < Items.Count; i++) { - Expression e = Items[i]; + for (var i = 0; i < Items.Count; i++) { + var e = Items[i]; if (e.CheckDelete() != null) { // we don't return the same message here as CPython doesn't seem to either, // for example ((yield a), 2,3) = (2,3,4) gives a different error than @@ -59,12 +57,8 @@ internal override string CheckDelete() { return null; } - internal override string CheckAugmentedAssign() { - return "illegal expression for augmented assignment"; - } + internal override string CheckAugmentedAssign() => "illegal expression for augmented assignment"; - private static bool IsComplexAssignment(Expression expr) { - return !(expr is NameExpression); - } + private static bool IsComplexAssignment(Expression expr) => !(expr is NameExpression); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/SetExpression.cs b/src/Parsing/Impl/Ast/SetExpression.cs similarity index 59% rename from src/Analysis/Engine/Impl/Parsing/Ast/SetExpression.cs rename to src/Parsing/Impl/Ast/SetExpression.cs index 65415d4ea..cd5d7e58a 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/SetExpression.cs +++ b/src/Parsing/Impl/Ast/SetExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,15 +8,17 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class SetExpression : Expression { private readonly Expression[] _items; @@ -26,27 +27,28 @@ public SetExpression(params Expression[] items) { _items = items; } - public IList Items { - get { return _items; } - } + public IList Items => _items; - public override string NodeName { - get { - return "set display"; - } - } + public override string NodeName => "set display"; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - foreach (Expression s in _items) { + foreach (var s in _items) { s.Walk(walker); } } walker.PostWalk(this); } - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - ListExpression.AppendItems(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", this, Items); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var s in _items) { + await s.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => ListExpression.AppendItems(res, ast, format, "{", this.IsMissingCloseGrouping(ast) ? "" : "}", this, Items); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/SliceExpression.cs b/src/Parsing/Impl/Ast/SliceExpression.cs similarity index 54% rename from src/Analysis/Engine/Impl/Parsing/Ast/SliceExpression.cs rename to src/Parsing/Impl/Ast/SliceExpression.cs index 71713bb10..022a14c92 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/SliceExpression.cs +++ b/src/Parsing/Impl/Ast/SliceExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,109 +8,98 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class SliceExpression : Expression { - private readonly Expression _sliceStart; - private readonly Expression _sliceStop; - private readonly Expression _sliceStep; - private readonly bool _stepProvided; - public SliceExpression(Expression start, Expression stop, Expression step, bool stepProvided) { - _sliceStart = start; - _sliceStop = stop; - _sliceStep = step; - _stepProvided = stepProvided; + SliceStart = start; + SliceStop = stop; + SliceStep = step; + StepProvided = stepProvided; } - public Expression SliceStart { - get { return _sliceStart; } - } + public Expression SliceStart { get; } - public Expression SliceStop { - get { return _sliceStop; } - } + public Expression SliceStop { get; } - public Expression SliceStep { - get { return _sliceStep; } - } + public Expression SliceStep { get; } /// /// True if the user provided a step parameter (either providing an explicit parameter /// or providing an empty step parameter) false if only start and stop were provided. /// - public bool StepProvided { - get { - return _stepProvided; - } - } + public bool StepProvided { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_sliceStart != null) { - _sliceStart.Walk(walker); + SliceStart?.Walk(walker); + SliceStop?.Walk(walker); + SliceStep?.Walk(walker); + } + walker.PostWalk(this); + } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (SliceStart != null) { + await SliceStart.WalkAsync(walker, cancellationToken); } - if (_sliceStop != null) { - _sliceStop.Walk(walker); + if (SliceStop != null) { + await SliceStop.WalkAsync(walker, cancellationToken); } - if (_sliceStep != null) { - _sliceStep.Walk(walker); + if (SliceStep != null) { + await SliceStep.WalkAsync(walker, cancellationToken); } } - walker.PostWalk(this); + await walker.PostWalkAsync(this, cancellationToken); } internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - if (_sliceStart != null) { - _sliceStart.AppendCodeString(res, ast, format); - } + SliceStart?.AppendCodeString(res, ast, format); if (!this.IsIncompleteNode(ast)) { - format.Append(res, format.SpaceBeforeSliceColon, " ", "", this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); + format.Append(res, format.SpaceBeforeSliceColon, " ", string.Empty, this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); res.Append(':'); - if (_sliceStop != null) { + if (SliceStop != null) { string ws = null; if (format.SpaceAfterSliceColon.HasValue) { - ws = ""; - format.Append(res, format.SpaceAfterSliceColon, " ", "", ""); + ws = string.Empty; + format.Append(res, format.SpaceAfterSliceColon, " ", string.Empty, string.Empty); } - _sliceStop.AppendCodeString(res, ast, format, ws); + SliceStop.AppendCodeString(res, ast, format, ws); } - if (_stepProvided) { - format.Append(res, format.SpaceBeforeSliceColon, " ", "", this.GetSecondWhiteSpaceDefaultNull(ast) ?? ""); + if (StepProvided) { + format.Append(res, format.SpaceBeforeSliceColon, " ", string.Empty, this.GetSecondWhiteSpaceDefaultNull(ast) ?? ""); res.Append(':'); - if (_sliceStep != null) { + if (SliceStep != null) { string ws = null; if (format.SpaceAfterSliceColon.HasValue) { - ws = ""; - format.Append(res, format.SpaceAfterSliceColon, " ", "", ""); + ws = string.Empty; + format.Append(res, format.SpaceAfterSliceColon, " ", string.Empty, string.Empty); } - _sliceStep.AppendCodeString(res, ast, format, ws); + SliceStep.AppendCodeString(res, ast, format, ws); } } } } - public override string GetLeadingWhiteSpace(PythonAst ast) { - if (_sliceStart != null) { - return _sliceStart.GetLeadingWhiteSpace(ast); - } - return this.GetPreceedingWhiteSpace(ast); - } + public override string GetLeadingWhiteSpace(PythonAst ast) + => SliceStart != null ? SliceStart.GetLeadingWhiteSpace(ast) : this.GetPreceedingWhiteSpace(ast); public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace) { - if (_sliceStart != null) { - _sliceStart.SetLeadingWhiteSpace(ast, whiteSpace); + if (SliceStart != null) { + SliceStart.SetLeadingWhiteSpace(ast, whiteSpace); } else { base.SetLeadingWhiteSpace(ast, whiteSpace); } } - } } diff --git a/src/Analysis/Engine/Impl/Infrastructure/Extensions/SourceLocationExtensions.cs b/src/Parsing/Impl/Ast/SourceLocationExtensions.cs similarity index 64% rename from src/Analysis/Engine/Impl/Infrastructure/Extensions/SourceLocationExtensions.cs rename to src/Parsing/Impl/Ast/SourceLocationExtensions.cs index 17e2fd9a4..89cebe6fc 100644 --- a/src/Analysis/Engine/Impl/Infrastructure/Extensions/SourceLocationExtensions.cs +++ b/src/Parsing/Impl/Ast/SourceLocationExtensions.cs @@ -9,22 +9,22 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Analysis.Infrastructure { +namespace Microsoft.Python.Parsing.Ast { public static class SourceLocationExtensions { public static int ToIndex(this SourceLocation location, PythonAst ast) => ast.LocationToIndex(location); } public static class SourceSpanExtensions { - public static LinearSpan ToLinearSpan(this SourceSpan span, PythonAst ast) - => LinearSpan.FromBounds(ast.LocationToIndex(span.Start), ast.LocationToIndex(span.End)); - public static LinearSpan ToLinearSpan(this Range range, PythonAst ast) - => LinearSpan.FromBounds(ast.LocationToIndex(range.start), ast.LocationToIndex(range.end)); + public static IndexSpan ToIndexSpan(this SourceSpan span, PythonAst ast) + => IndexSpan.FromBounds(ast.LocationToIndex(span.Start), ast.LocationToIndex(span.End)); + public static IndexSpan ToIndexSpan(this Range range, PythonAst ast) + => IndexSpan.FromBounds(ast.LocationToIndex(range.start), ast.LocationToIndex(range.end)); } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/StarredExpression.cs b/src/Parsing/Impl/Ast/StarredExpression.cs similarity index 68% rename from src/Analysis/Engine/Impl/Parsing/Ast/StarredExpression.cs rename to src/Parsing/Impl/Ast/StarredExpression.cs index 04d638450..b3100f568 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/StarredExpression.cs +++ b/src/Parsing/Impl/Ast/StarredExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class StarredExpression : Expression { public StarredExpression(Expression expr) : this(expr, 1) { } @@ -35,16 +36,17 @@ public override void Walk(PythonWalker walker) { } } - internal override string CheckAssign() { - if (StarCount == 1) { - return "starred assignment target must be in a list or tuple"; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + await Expression.WalkAsync(walker, cancellationToken); } - return "invalid syntax"; + await walker.PostWalkAsync(this, cancellationToken); } - internal override string CheckAugmentedAssign() { - return "invalid syntax"; - } + internal override string CheckAssign() + => StarCount == 1 ? "starred assignment target must be in a list or tuple" : "invalid syntax"; + + internal override string CheckAugmentedAssign() => "invalid syntax"; internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { res.Append(this.GetPreceedingWhiteSpaceDefaultNull(ast) ?? ""); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/Statement.cs b/src/Parsing/Impl/Ast/Statement.cs similarity index 77% rename from src/Analysis/Engine/Impl/Parsing/Ast/Statement.cs rename to src/Parsing/Impl/Ast/Statement.cs index 59c4143de..337dfaff3 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/Statement.cs +++ b/src/Parsing/Impl/Ast/Statement.cs @@ -9,23 +9,19 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public abstract class Statement : Node { internal Statement() { } - public virtual string Documentation { - get { - return null; - } - } + public virtual string Documentation => null; /// /// Returns the length of the keywords (including internal whitespace), such @@ -37,27 +33,23 @@ public virtual string Documentation { /// public virtual int KeywordEndIndex => StartIndex + KeywordLength; - internal override sealed void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { - AppendCodeStringStmt(res, ast, format); - } + internal sealed override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) + => AppendCodeStringStmt(res, ast, format); internal abstract void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format); /// /// Returns the expression contained by the statement. - /// /// Returns null if it's not an expression statement or return statement. - /// - /// New in 1.1. /// public static Expression GetExpression(Statement statement) { if (statement is ExpressionStatement exprStmt) { return exprStmt.Expression; - } else if (statement is ReturnStatement retStmt) { + } + if (statement is ReturnStatement retStmt) { return retStmt.Expression; - } else { - return null; } + return null; } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/SublistParameter.cs b/src/Parsing/Impl/Ast/SublistParameter.cs similarity index 73% rename from src/Analysis/Engine/Impl/Parsing/Ast/SublistParameter.cs rename to src/Parsing/Impl/Ast/SublistParameter.cs index 9e8624480..bd387ce77 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/SublistParameter.cs +++ b/src/Parsing/Impl/Ast/SublistParameter.cs @@ -9,43 +9,38 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class SublistParameter : Parameter { - private readonly TupleExpression _tuple; private readonly int _position; public SublistParameter(int position, TupleExpression tuple) : base(null, ParameterKind.Normal) { _position = position; - _tuple = tuple; + Tuple = tuple; } public override string Name => ".{0}".FormatUI(_position); - public TupleExpression Tuple => _tuple; + public TupleExpression Tuple { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_tuple != null) { - _tuple.Walk(walker); - } - if (_defaultValue != null) { - _defaultValue.Walk(walker); - } + Tuple?.Walk(walker); + DefaultValue?.Walk(walker); } walker.PostWalk(this); } internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format, string leadingWhiteSpace) { - string kwOnlyText = this.GetExtraVerbatimText(ast); + var kwOnlyText = this.GetExtraVerbatimText(ast); if (kwOnlyText != null) { if (leadingWhiteSpace != null) { res.Append(leadingWhiteSpace); @@ -56,7 +51,7 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo } } Tuple.AppendCodeString(res, ast, format, leadingWhiteSpace); - if (_defaultValue != null) { + if (DefaultValue != null) { format.Append( res, format.SpaceAroundDefaultValueEquals, @@ -66,9 +61,9 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo ); res.Append('='); if (format.SpaceAroundDefaultValueEquals != null) { - _defaultValue.AppendCodeString(res, ast, format, format.SpaceAroundDefaultValueEquals.Value ? " " : ""); + DefaultValue.AppendCodeString(res, ast, format, format.SpaceAroundDefaultValueEquals.Value ? " " : ""); } else { - _defaultValue.AppendCodeString(res, ast, format); + DefaultValue.AppendCodeString(res, ast, format); } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/SuiteStatement.cs b/src/Parsing/Impl/Ast/SuiteStatement.cs similarity index 81% rename from src/Analysis/Engine/Impl/Parsing/Ast/SuiteStatement.cs rename to src/Parsing/Impl/Ast/SuiteStatement.cs index 71c7d9350..1556e621f 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/SuiteStatement.cs +++ b/src/Parsing/Impl/Ast/SuiteStatement.cs @@ -9,16 +9,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { - +namespace Microsoft.Python.Parsing.Ast { public sealed class SuiteStatement : Statement { private readonly Statement[] _statements; @@ -26,30 +28,29 @@ public SuiteStatement(Statement[] statements) { _statements = statements; } - public IList Statements { - get { return _statements; } - } + public IList Statements => _statements; public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_statements != null) { - foreach (Statement s in _statements) { - s.Walk(walker); - } + foreach (var s in _statements.MaybeEnumerate()) { + s.Walk(walker); } } walker.PostWalk(this); } - public override string Documentation { - get { - if (_statements.Length > 0) { - return _statements[0].Documentation; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var s in _statements.MaybeEnumerate()) { + cancellationToken.ThrowIfCancellationRequested(); + await s.WalkAsync(walker, cancellationToken); } - return null; } + await walker.PostWalkAsync(this, cancellationToken); } + public override string Documentation => _statements.Length > 0 ? _statements[0].Documentation : null; + /// /// Returns a new SuiteStatement which is composed of a subset of the statements in this suite statement. /// @@ -57,8 +58,8 @@ public override string Documentation { /// /// public SuiteStatement CloneSubset(PythonAst ast, int start, int end) { - Statement[] statements = new Statement[end - start + 1]; - for (int i = start; i <= end; i++) { + var statements = new Statement[end - start + 1]; + for (var i = start; i <= end; i++) { statements[i - start] = Statements[i]; } @@ -93,16 +94,16 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co } } else if (itemWhiteSpace != null) { if (format.BreakMultipleStatementsPerLine) { - string leadingWhiteSpace = ""; - for (int i = 0; i < _statements.Length; i++) { + var leadingWhiteSpace = ""; + for (var i = 0; i < _statements.Length; i++) { if (i == 0) { - StringBuilder tmp = new StringBuilder(); - _statements[i].AppendCodeString(tmp, ast, format); + var tmp = new StringBuilder(); + _statements[i].AppendCodeString(tmp, ast, format); var stmt = tmp.ToString(); res.Append(stmt); // figure out the whitespace needed for the next statement based upon the current statement - for (int curChar = 0; curChar < stmt.Length; curChar++) { + for (var curChar = 0; curChar < stmt.Length; curChar++) { if (!char.IsWhiteSpace(stmt[curChar])) { leadingWhiteSpace = format.GetNextLineProceedingText(stmt.Substring(0, curChar)); break; @@ -114,7 +115,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co } } else { // form 2, semi-colon seperated list. - for (int i = 0; i < _statements.Length; i++) { + for (var i = 0; i < _statements.Length; i++) { if (i > 0) { if (i - 1 < itemWhiteSpace.Length) { res.Append(itemWhiteSpace[i - 1]); @@ -138,7 +139,7 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co res.Append(colonWhiteSpace); } res.Append(':'); - + foreach (var statement in _statements) { statement.AppendCodeString(res, ast, format); } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/TryStatement.cs b/src/Parsing/Impl/Ast/TryStatement.cs similarity index 73% rename from src/Analysis/Engine/Impl/Parsing/Ast/TryStatement.cs rename to src/Parsing/Impl/Ast/TryStatement.cs index 9efeb62b2..bd7c9c445 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/TryStatement.cs +++ b/src/Parsing/Impl/Ast/TryStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,17 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; - -namespace Microsoft.PythonTools.Parsing.Ast { +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; +namespace Microsoft.Python.Parsing.Ast { public class TryStatement : Statement { private readonly TryStatementHandler[] _handlers; @@ -58,7 +58,7 @@ public TryStatement(Statement body, TryStatementHandler[] handlers, Statement el public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { Body?.Walk(walker); - foreach (TryStatementHandler handler in _handlers.MaybeEnumerate()) { + foreach (var handler in _handlers.MaybeEnumerate()) { handler.Walk(walker); } Else?.Walk(walker); @@ -67,6 +67,24 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Body != null) { + await Body.WalkAsync(walker, cancellationToken); + } + foreach (var handler in _handlers.MaybeEnumerate()) { + await handler.WalkAsync(walker, cancellationToken); + } + if (Else != null) { + await Else.WalkAsync(walker, cancellationToken); + } + if (Finally != null) { + await Finally.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("try"); @@ -115,6 +133,21 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Test != null) { + await Test.WalkAsync(walker, cancellationToken); + } + if (Target != null) { + await Target.WalkAsync(walker, cancellationToken); + } + if (Body != null) { + await Body.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("except"); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/TupleExpression.cs b/src/Parsing/Impl/Ast/TupleExpression.cs similarity index 74% rename from src/Analysis/Engine/Impl/Parsing/Ast/TupleExpression.cs rename to src/Parsing/Impl/Ast/TupleExpression.cs index 8450574a1..114fed653 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/TupleExpression.cs +++ b/src/Parsing/Impl/Ast/TupleExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,21 +8,21 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class TupleExpression : SequenceExpression { - private bool _expandable; - public TupleExpression(bool expandable, params Expression[] items) : base(items) { - _expandable = expandable; + IsExpandable = expandable; } internal override string CheckAssign() { @@ -35,27 +34,28 @@ internal override string CheckAssign() { public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (Items != null) { - foreach (Expression e in Items) { - e.Walk(walker); - } + foreach (var e in Items.MaybeEnumerate()) { + e.Walk(walker); } } walker.PostWalk(this); } - public bool IsExpandable { - get { - return _expandable; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var e in Items.MaybeEnumerate()) { + await e.WalkAsync(walker, cancellationToken); + } } + await walker.PostWalkAsync(this, cancellationToken); } + public bool IsExpandable { get; } + /// /// Marks this tuple expression as having no parenthesis for the purposes of round tripping. /// - public void RoundTripHasNoParenthesis(PythonAst ast) { - ast.SetAttribute(this, NodeAttributes.IsAltFormValue, NodeAttributes.IsAltFormValue); - } + public void RoundTripHasNoParenthesis(PythonAst ast) => ast.SetAttribute(this, NodeAttributes.IsAltFormValue, NodeAttributes.IsAltFormValue); public override string GetLeadingWhiteSpace(PythonAst ast) { if (this.IsAltForm(ast)) { @@ -76,7 +76,7 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo if (this.IsAltForm(ast)) { ListExpression.AppendItems(res, ast, format, "", "", this, Items); } else { - if (Items.Count == 0 && + if (Items.Count == 0 && format.SpaceWithinEmptyTupleExpression != null) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append('('); @@ -84,7 +84,7 @@ internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFo res.Append(')'); } else { ListExpression.AppendItems(res, ast, format, "(", this.IsMissingCloseGrouping(ast) ? "" : ")", this, Items, format.SpacesWithinParenthesisedTupleExpression); - } + } } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/TypeAnnotation.cs b/src/Parsing/Impl/Ast/TypeAnnotation.cs similarity index 94% rename from src/Analysis/Engine/Impl/Parsing/Ast/TypeAnnotation.cs rename to src/Parsing/Impl/Ast/TypeAnnotation.cs index eff7c868d..2f6aa7e35 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/TypeAnnotation.cs +++ b/src/Parsing/Impl/Ast/TypeAnnotation.cs @@ -9,28 +9,26 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing.Ast { - class TypeAnnotation { +namespace Microsoft.Python.Parsing.Ast { + public sealed class TypeAnnotation { public TypeAnnotation(PythonLanguageVersion version, Expression expr) { LanguageVersion = version; Expression = expr ?? throw new ArgumentNullException(nameof(expr)); } - public static TypeAnnotation FromType(TypeAnnotationConverter converter, T type) where T : class { - throw new NotImplementedException(); - } + public static TypeAnnotation FromType(TypeAnnotationConverter converter, T type) where T : class + => throw new NotImplementedException(); public PythonLanguageVersion LanguageVersion { get; } public Expression Expression { get; } @@ -49,7 +47,7 @@ public T GetValue(TypeAnnotationConverter converter) where T : class { return walker.GetResult(converter); } - internal IEnumerable GetTransformSteps() { + public IEnumerable GetTransformSteps() { var walker = new Walker(ParseSubExpression); Expression.Walk(walker); return walker._ops.Select(o => o.ToString()); @@ -69,17 +67,17 @@ public T GetResult(TypeAnnotationConverter converter) where T : class { try { foreach (var op in _ops) { if (!op.Apply(converter, stack)) { - return default(T); + return default; } } } catch (InvalidOperationException) { - return default(T); + return default; } if (stack.Count == 1) { return converter.Finalize(stack.Pop().Value); } - return default(T); + return default; } public override bool Walk(ConstantExpression node) { @@ -275,42 +273,42 @@ public override bool Apply(TypeAnnotationConverter converter, Stack where T : class { - #region Convert Type Hint to Type + #region Convert Type Hint to Type /// /// Returns the type or module object for the specified name. /// - public virtual T LookupName(string name) => default(T); + public virtual T LookupName(string name) => default; /// /// Returns a member of the preceding module object. /// - public virtual T GetTypeMember(T baseType, string member) => default(T); + public virtual T GetTypeMember(T baseType, string member) => default; /// /// Returns the specialized type object for the base /// type and generic types provided. /// - public virtual T MakeGeneric(T baseType, IReadOnlyList args) => default(T); + public virtual T MakeGeneric(T baseType, IReadOnlyList args) => default; /// /// Returns the type as an optional type. /// - public virtual T MakeOptional(T type) => default(T); + public virtual T MakeOptional(T type) => default; /// /// Returns the types as a single union type. /// - public virtual T MakeUnion(IReadOnlyList types) => default(T); + public virtual T MakeUnion(IReadOnlyList types) => default; /// /// Returns the types as a single list type. /// - public virtual T MakeList(IReadOnlyList types) => default(T); + public virtual T MakeList(IReadOnlyList types) => default; /// /// Returns a value containing an unresolved name. /// - public virtual T MakeNameType(string name) => default(T); + public virtual T MakeNameType(string name) => default; /// /// Ensure the final result is a suitable type. Return null @@ -320,9 +318,7 @@ public abstract class TypeAnnotationConverter where T : class { #endregion - #region Convert Type to Type Hint - /// /// Returns the name of the provided type. This should always /// be the name of the base type, omitting any generic arguments. @@ -334,7 +330,7 @@ public abstract class TypeAnnotationConverter where T : class { /// Gets the base type from a generic type. If it is already a /// base type, return null. /// - public virtual T GetBaseType(T genericType) => default(T); + public virtual T GetBaseType(T genericType) => default; /// /// Gets the generic types from a generic type. Return null if /// there are no generic types. @@ -345,7 +341,7 @@ public abstract class TypeAnnotationConverter where T : class { /// Gets the non-optional type from an optional type. If it is /// already a non-optional type, return null. /// - public virtual T GetNonOptionalType(T optionalType) => default(T); + public virtual T GetNonOptionalType(T optionalType) => default; /// /// Gets the original types from a type union. If it is not a diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/UnaryExpression.cs b/src/Parsing/Impl/Ast/UnaryExpression.cs similarity index 59% rename from src/Analysis/Engine/Impl/Parsing/Ast/UnaryExpression.cs rename to src/Parsing/Impl/Ast/UnaryExpression.cs index 8cef87342..d9181fb8e 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/UnaryExpression.cs +++ b/src/Parsing/Impl/Ast/UnaryExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,52 +8,49 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { - +namespace Microsoft.Python.Parsing.Ast { public class UnaryExpression : Expression { - private readonly Expression _expression; - private readonly PythonOperator _op; - public UnaryExpression(PythonOperator op, Expression expression) { - _op = op; - _expression = expression; + Op = op; + Expression = expression; EndIndex = expression.EndIndex; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } - public PythonOperator Op { - get { return _op; } - } + public PythonOperator Op { get; } - public override string NodeName { - get { - return "unary operator"; - } - } + public override string NodeName => "unary operator"; internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); - res.Append(_op.ToCodeString()); - _expression.AppendCodeString(res, ast, format); + res.Append(Op.ToCodeString()); + Expression.AppendCodeString(res, ast, format); } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } + + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/VariableKind.cs b/src/Parsing/Impl/Ast/VariableKind.cs similarity index 94% rename from src/Analysis/Engine/Impl/Parsing/Ast/VariableKind.cs rename to src/Parsing/Impl/Ast/VariableKind.cs index 9e4981ce9..1af024a7e 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/VariableKind.cs +++ b/src/Parsing/Impl/Ast/VariableKind.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { internal enum VariableKind { /// diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/WhileStatement.cs b/src/Parsing/Impl/Ast/WhileStatement.cs similarity index 73% rename from src/Analysis/Engine/Impl/Parsing/Ast/WhileStatement.cs rename to src/Parsing/Impl/Ast/WhileStatement.cs index 239e0fd4a..cbd0c792e 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/WhileStatement.cs +++ b/src/Parsing/Impl/Ast/WhileStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,14 +8,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class WhileStatement : Statement { public WhileStatement(Expression test, Statement body, Statement else_) { Test = test; @@ -47,6 +48,21 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Test != null) { + await Test.WalkAsync(walker, cancellationToken); + } + if (Body != null) { + await Body.WalkAsync(walker, cancellationToken); + } + if (ElseStatement != null) { + await ElseStatement.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("while"); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/WithStatement.cs b/src/Parsing/Impl/Ast/WithStatement.cs similarity index 74% rename from src/Analysis/Engine/Impl/Parsing/Ast/WithStatement.cs rename to src/Parsing/Impl/Ast/WithStatement.cs index 1ed7070d2..d55fc9dcd 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/WithStatement.cs +++ b/src/Parsing/Impl/Ast/WithStatement.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,8 +16,10 @@ using System; using System.Collections.Generic; using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { public class WithStatement : Statement, IMaybeAsyncStatement { private readonly WithItem[] _items; private int? _keywordEndIndex; @@ -33,11 +34,7 @@ public WithStatement(WithItem[] items, Statement body, bool isAsync) : this(item } - public IList Items { - get { - return _items; - } - } + public IList Items => _items; public int HeaderIndex { get; set; } internal void SetKeywordEndIndex(int index) => _keywordEndIndex = index; @@ -60,6 +57,18 @@ public override void Walk(PythonWalker walker) { walker.PostWalk(this); } + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + foreach (var item in _items) { + await item.WalkAsync(walker, cancellationToken); + } + if (Body != null) { + await Body.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + public int GetIndexOfWith(PythonAst ast) { if (!IsAsync) { return StartIndex; @@ -75,8 +84,8 @@ internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, Co } res.Append("with"); var itemWhiteSpace = this.GetListWhiteSpace(ast); - int whiteSpaceIndex = 0; - for (int i = 0; i < _items.Length; i++) { + var whiteSpaceIndex = 0; + for (var i = 0; i < _items.Length; i++) { var item = _items[i]; if (i != 0) { if (itemWhiteSpace != null) { @@ -117,9 +126,20 @@ public override void Walk(PythonWalker walker) { Variable?.Walk(walker); } - internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (ContextManager != null) { + await ContextManager.WalkAsync(walker, cancellationToken); + } + if (Variable != null) { + await Variable.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); + } + + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) => // WithStatement expands us throw new InvalidOperationException(); - } } } diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/YieldExpression.cs b/src/Parsing/Impl/Ast/YieldExpression.cs similarity index 66% rename from src/Analysis/Engine/Impl/Parsing/Ast/YieldExpression.cs rename to src/Parsing/Impl/Ast/YieldExpression.cs index bff4a9b48..dd5a4db16 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/YieldExpression.cs +++ b/src/Parsing/Impl/Ast/YieldExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,53 +8,52 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { // New in Pep342 for Python 2.5. Yield is an expression with a return value. // x = yield z // The return value (x) is provided by calling Generator.Send() public class YieldExpression : Expression { - private readonly Expression _expression; - public YieldExpression(Expression expression) { - _expression = expression; + Expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } - internal override string CheckAugmentedAssign() { - return CheckAssign(); - } - - public override string NodeName { - get { - return "yield expression"; + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } } + await walker.PostWalkAsync(this, cancellationToken); } + internal override string CheckAugmentedAssign() => CheckAssign(); + + public override string NodeName => "yield expression"; + internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { format.ReflowComment(res, this.GetPreceedingWhiteSpace(ast)); res.Append("yield"); if (!this.IsAltForm(ast)) { - _expression.AppendCodeString(res, ast, format); + Expression.AppendCodeString(res, ast, format); var itemWhiteSpace = this.GetListWhiteSpace(ast); if (itemWhiteSpace != null) { res.Append(","); diff --git a/src/Analysis/Engine/Impl/Parsing/Ast/YieldFromExpression.cs b/src/Parsing/Impl/Ast/YieldFromExpression.cs similarity index 69% rename from src/Analysis/Engine/Impl/Parsing/Ast/YieldFromExpression.cs rename to src/Parsing/Impl/Ast/YieldFromExpression.cs index 7250f6ac7..6a7a55fd1 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ast/YieldFromExpression.cs +++ b/src/Parsing/Impl/Ast/YieldFromExpression.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,46 +8,47 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Text; +using System.Threading; +using System.Threading.Tasks; -namespace Microsoft.PythonTools.Parsing.Ast { +namespace Microsoft.Python.Parsing.Ast { // New in Pep380 for Python 3.3. Yield From is an expression with a return value. // x = yield from z // The return value (x) is taken from the value attribute of a StopIteration // error raised by next(z) or z.send(). public class YieldFromExpression : Expression { - private readonly Expression _expression; - public YieldFromExpression(Expression expression) { - _expression = expression; + Expression = expression; } - public Expression Expression { - get { return _expression; } - } + public Expression Expression { get; } public override void Walk(PythonWalker walker) { if (walker.Walk(this)) { - if (_expression != null) { - _expression.Walk(walker); - } + Expression?.Walk(walker); } walker.PostWalk(this); } - internal override string CheckAugmentedAssign() { - return CheckAssign(); + public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default) { + if (await walker.WalkAsync(this, cancellationToken)) { + if (Expression != null) { + await Expression.WalkAsync(walker, cancellationToken); + } + } + await walker.PostWalkAsync(this, cancellationToken); } - public int GetIndexOfFrom(PythonAst ast) { - return StartIndex + 5 + this.GetSecondWhiteSpace(ast).Length; - } + internal override string CheckAugmentedAssign() => CheckAssign(); + + public int GetIndexOfFrom(PythonAst ast) => StartIndex + 5 + this.GetSecondWhiteSpace(ast).Length; internal override void AppendCodeString(StringBuilder res, PythonAst ast, CodeFormattingOptions format) { res.Append(this.GetPreceedingWhiteSpace(ast)); diff --git a/src/Analysis/Engine/Impl/Parsing/CodeFormattingOptions.cs b/src/Parsing/Impl/CodeFormattingOptions.cs similarity index 94% rename from src/Analysis/Engine/Impl/Parsing/CodeFormattingOptions.cs rename to src/Parsing/Impl/CodeFormattingOptions.cs index 7b0a4fb83..ba7ee9e99 100644 --- a/src/Analysis/Engine/Impl/Parsing/CodeFormattingOptions.cs +++ b/src/Parsing/Impl/CodeFormattingOptions.cs @@ -15,13 +15,12 @@ // permissions and limitations under the License. using System; -using System.Diagnostics; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// Provides options for formatting code when calling Node.ToCodeString. /// @@ -39,7 +38,7 @@ namespace Microsoft.PythonTools.Parsing { /// public sealed class CodeFormattingOptions { internal static CodeFormattingOptions Default = new CodeFormattingOptions(); // singleton with no options set, internal so no one mutates it - private static Regex _commentRegex = new Regex("^[\t ]*#+[\t ]*"); + private static readonly Regex _commentRegex = new Regex("^[\t ]*#+[\t ]*"); private const string _sentenceTerminators = ".!?"; public string NewLineFormat { get; set; } @@ -263,17 +262,17 @@ internal void ReflowComment(StringBuilder res, string text) { // # which will be wrapped // 2, // - int charsOnCurrentLine = GetCharsOnLastLine(res); + var charsOnCurrentLine = GetCharsOnLastLine(res); var lines = text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); - int lineCount = lines.Length; + var lineCount = lines.Length; if (text.EndsWithOrdinal("\r") || text.EndsWithOrdinal("\n")) { // split will give us an extra entry, but there's not really an extra line lineCount = lines.Length - 1; } int reflowStartingLine = 0, curLine = 0; do { - string commentPrefix = GetCommentPrefix(lines[curLine]); + var commentPrefix = GetCommentPrefix(lines[curLine]); if (commentPrefix == null) { // non-commented line (empty?), just append it and continue // to the next comment prefix if we have one @@ -297,7 +296,7 @@ internal void ReflowComment(StringBuilder res, string text) { } private static int GetCharsOnLastLine(StringBuilder res) { - for (int i = res.Length - 1; i >= 0; i--) { + for (var i = res.Length - 1; i >= 0; i--) { if (res[i] == '\n' || res[i] == '\r') { return res.Length - i - 1; } @@ -315,12 +314,12 @@ internal static string GetCommentPrefix(string text) { internal static string ReflowText(string prefix, string additionalLinePrefix, string newLine, int maxLength, string[] lines) { int curLine = 0, curOffset = prefix.Length, linesWritten = 0; - int columnCutoff = maxLength - prefix.Length; - int defaultColumnCutoff = columnCutoff; - StringBuilder newText = new StringBuilder(); + var columnCutoff = maxLength - prefix.Length; + var defaultColumnCutoff = columnCutoff; + var newText = new StringBuilder(); while (curLine < lines.Length) { - string curLineText = lines[curLine]; - int lastSpace = curLineText.Length; + var curLineText = lines[curLine]; + var lastSpace = curLineText.Length; // skip leading white space while (curOffset < curLineText.Length && Char.IsWhiteSpace(curLineText[curOffset])) { @@ -328,14 +327,14 @@ internal static string ReflowText(string prefix, string additionalLinePrefix, st } // find next word - for (int i = curOffset; i < curLineText.Length; i++) { + for (var i = curOffset; i < curLineText.Length; i++) { if (Char.IsWhiteSpace(curLineText[i])) { lastSpace = i; break; } } - bool startNewLine = lastSpace - curOffset >= columnCutoff && // word won't fit in remaining space + var startNewLine = lastSpace - curOffset >= columnCutoff && // word won't fit in remaining space columnCutoff != defaultColumnCutoff; // we're not already at the start of a new line if (!startNewLine) { diff --git a/src/Analysis/Engine/Impl/Parsing/CollectingErrorSink.cs b/src/Parsing/Impl/CollectingErrorSink.cs similarity index 92% rename from src/Analysis/Engine/Impl/Parsing/CollectingErrorSink.cs rename to src/Parsing/Impl/CollectingErrorSink.cs index dfbad8ccb..44098fb19 100644 --- a/src/Analysis/Engine/Impl/Parsing/CollectingErrorSink.cs +++ b/src/Parsing/Impl/CollectingErrorSink.cs @@ -9,14 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.Collections.Generic; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public class CollectingErrorSink : ErrorSink { public override void Add(string message, SourceSpan span, int errorCode, Severity severity) { if (severity == Severity.Error || severity == Severity.FatalError) { diff --git a/src/Analysis/Engine/Impl/Parsing/Ellipsis.cs b/src/Parsing/Impl/Ellipsis.cs similarity index 79% rename from src/Analysis/Engine/Impl/Parsing/Ellipsis.cs rename to src/Parsing/Impl/Ellipsis.cs index 70316012b..b6aeb8e5d 100644 --- a/src/Analysis/Engine/Impl/Parsing/Ellipsis.cs +++ b/src/Parsing/Impl/Ellipsis.cs @@ -9,17 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { - sealed class Ellipsis { +namespace Microsoft.Python.Parsing { + public sealed class Ellipsis { public static readonly Ellipsis Value = new Ellipsis(); - - public override string ToString() { - return "..."; - } + public override string ToString() => "..."; } } diff --git a/src/Analysis/Engine/Impl/Parsing/ErrorCodes.cs b/src/Parsing/Impl/ErrorCodes.cs similarity index 89% rename from src/Analysis/Engine/Impl/Parsing/ErrorCodes.cs rename to src/Parsing/Impl/ErrorCodes.cs index 2d01e0f86..a15e24c09 100644 --- a/src/Analysis/Engine/Impl/Parsing/ErrorCodes.cs +++ b/src/Parsing/Impl/ErrorCodes.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public static class ErrorCodes { // The error flags public const int IncompleteMask = 0x000F; @@ -37,12 +37,12 @@ public static class ErrorCodes { /// /// The error was a general syntax error /// - public const int SyntaxError = 0x0010; + public const int SyntaxError = 0x0010; /// /// The error was an indentation error. /// - public const int IndentationError = 0x0020; + public const int IndentationError = 0x0020; /// /// The error was a tab error. diff --git a/src/Analysis/Engine/Impl/Parsing/ErrorResult.cs b/src/Parsing/Impl/ErrorResult.cs similarity index 64% rename from src/Analysis/Engine/Impl/Parsing/ErrorResult.cs rename to src/Parsing/Impl/ErrorResult.cs index 65bacbaa2..42126aef1 100644 --- a/src/Analysis/Engine/Impl/Parsing/ErrorResult.cs +++ b/src/Parsing/Impl/ErrorResult.cs @@ -9,31 +9,22 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { - public class ErrorResult { - private readonly string _message; - private readonly SourceSpan _span; +using Microsoft.Python.Core.Text; +namespace Microsoft.Python.Parsing { + public class ErrorResult { public ErrorResult(string message, SourceSpan span) { - _message = message; - _span = span; + Message = message; + Span = span; } - public string Message { - get { - return _message; - } - } + public string Message { get; } - public SourceSpan Span { - get { - return _span; - } - } + public SourceSpan Span { get; } } } diff --git a/src/Analysis/Engine/Impl/Parsing/ErrorSink.cs b/src/Parsing/Impl/ErrorSink.cs similarity index 90% rename from src/Analysis/Engine/Impl/Parsing/ErrorSink.cs rename to src/Parsing/Impl/ErrorSink.cs index 46bc9a227..9f63f2a79 100644 --- a/src/Analysis/Engine/Impl/Parsing/ErrorSink.cs +++ b/src/Parsing/Impl/ErrorSink.cs @@ -9,23 +9,23 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +using Microsoft.Python.Core.Text; + +namespace Microsoft.Python.Parsing { public class ErrorSink { public static readonly ErrorSink Null = new ErrorSink(); - internal void Add(string message, NewLineLocation[] lineLocations, int startIndex, int endIndex, int errorCode, Severity severity) { - Add( + internal void Add(string message, NewLineLocation[] lineLocations, int startIndex, int endIndex, int errorCode, Severity severity) => Add( message, new SourceSpan(NewLineLocation.IndexToLocation(lineLocations, startIndex), NewLineLocation.IndexToLocation(lineLocations, endIndex)), errorCode, severity ); - } public virtual void Add(string message, SourceSpan span, int errorCode, Severity severity) { } diff --git a/src/Analysis/Engine/Impl/Parsing/FutureOptions.cs b/src/Parsing/Impl/FutureOptions.cs similarity index 95% rename from src/Analysis/Engine/Impl/Parsing/FutureOptions.cs rename to src/Parsing/Impl/FutureOptions.cs index ca2676e31..52edefee3 100644 --- a/src/Analysis/Engine/Impl/Parsing/FutureOptions.cs +++ b/src/Parsing/Impl/FutureOptions.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// Options which have been enabled using from __future__ import /// diff --git a/src/Analysis/Engine/Impl/Parsing/LiteralParser.cs b/src/Parsing/Impl/LiteralParser.cs similarity index 86% rename from src/Analysis/Engine/Impl/Parsing/LiteralParser.cs rename to src/Parsing/Impl/LiteralParser.cs index 0260d99f4..467761e61 100644 --- a/src/Analysis/Engine/Impl/Parsing/LiteralParser.cs +++ b/src/Parsing/Impl/LiteralParser.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,30 +19,29 @@ using System.Globalization; using System.Numerics; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// Summary description for ConstantValue. /// internal static class LiteralParser { - public static string ParseString(string text, bool isRaw, bool isUni) { - return ParseString(text.ToCharArray(), 0, text.Length, isRaw, isUni, false); - } + public static string ParseString(string text, bool isRaw, bool isUni) => ParseString(text.ToCharArray(), 0, text.Length, isRaw, isUni, false); public static string ParseString(char[] text, int start, int length, bool isRaw, bool isUni, bool normalizeLineEndings) { if (text == null) { throw new ArgumentNullException("text"); } - if (isRaw && !isUni && !normalizeLineEndings) return new String(text, start, length); + if (isRaw && !isUni && !normalizeLineEndings) { + return new String(text, start, length); + } StringBuilder buf = null; - int i = start; - int l = start + length; - int val; + var i = start; + var l = start + length; while (i < l) { - char ch = text[i++]; + var ch = text[i++]; if ((!isRaw || isUni) && ch == '\\') { if (buf == null) { buf = new StringBuilder(length); @@ -54,15 +52,15 @@ public static string ParseString(char[] text, int start, int length, bool isRaw, if (isRaw) { buf.Append('\\'); break; - } else { - throw new ArgumentException("Trailing \\ in string"); } + throw new ArgumentException("Trailing \\ in string"); } ch = text[i++]; + int val; if (ch == 'u' || ch == 'U') { - int len = (ch == 'u') ? 4 : 8; - int max = 16; + var len = (ch == 'u') ? 4 : 8; + var max = 16; if (isUni && !isRaw) { if (TryParseInt(text, i, len, max, out val)) { buf.Append((char)val); @@ -91,7 +89,7 @@ public static string ParseString(char[] text, int start, int length, bool isRaw, case '\\': buf.Append('\\'); continue; case '\'': buf.Append('\''); continue; case '\"': buf.Append('\"'); continue; - case '\r': if (i < l && text[i] == '\n') i++; continue; + case '\r': if (i < l && text[i] == '\n') { i++; } continue; case '\n': continue; case 'x': //hex if (!TryParseInt(text, i, 2, 16, out val)) { @@ -108,9 +106,8 @@ public static string ParseString(char[] text, int start, int length, bool isRaw, case '5': case '6': case '7': { - int onechar; val = ch - '0'; - if (i < l && HexValue(text[i], out onechar) && onechar < 8) { + if (i < l && HexValue(text[i], out var onechar) && onechar < 8) { val = val * 8 + onechar; i++; if (i < l && HexValue(text[i], out onechar) && onechar < 8) { @@ -153,13 +150,13 @@ public static string ParseString(char[] text, int start, int length, bool isRaw, internal static List ParseBytes(char[] text, int start, int length, bool isRaw, bool normalizeLineEndings) { Debug.Assert(text != null); - List buf = new List(length); + var buf = new List(length); - int i = start; - int l = start + length; + var i = start; + var l = start + length; int val; while (i < l) { - char ch = text[i++]; + var ch = text[i++]; if (!isRaw && ch == '\\') { if (i >= l) { throw new ArgumentException("Trailing \\ in string"); @@ -176,7 +173,7 @@ internal static List ParseBytes(char[] text, int start, int length, bool i case '\\': buf.Add('\\'); continue; case '\'': buf.Add('\''); continue; case '\"': buf.Add('\"'); continue; - case '\r': if (i < l && text[i] == '\n') i++; continue; + case '\r': if (i < l && text[i] == '\n') { i++; } continue; case '\n': continue; case 'x': //hex if (!TryParseInt(text, i, 2, 16, out val)) { @@ -193,9 +190,8 @@ internal static List ParseBytes(char[] text, int start, int length, bool i case '5': case '6': case '7': { - int onechar; val = ch - '0'; - if (i < l && HexValue(text[i], out onechar) && onechar < 8) { + if (i < l && HexValue(text[i], out var onechar) && onechar < 8) { val = val * 8 + onechar; i++; if (i < l && HexValue(text[i], out onechar) && onechar < 8) { @@ -263,15 +259,14 @@ private static bool HexValue(char ch, out int value) { } private static int HexValue(char ch) { - int value; - if (!HexValue(ch, out value)) { + if (!HexValue(ch, out var value)) { throw new ArgumentException("bad char for integer value: " + ch); } return value; } private static int CharValue(char ch, int b) { - int val = HexValue(ch); + var val = HexValue(ch); if (val >= b) { throw new ArgumentException("bad char for the integer value: '{0}' (base {1})".FormatUI(ch, b)); } @@ -281,15 +276,15 @@ private static int CharValue(char ch, int b) { private static bool ParseInt(string text, int b, out int ret) { ret = 0; long m = 1; - for (int i = text.Length - 1; i >= 0; i--) { + for (var i = text.Length - 1; i >= 0; i--) { // avoid the exception here. Not only is throwing it expensive, // but loading the resources for it is also expensive - char c = text[i]; + var c = text[i]; if (c == '_') { continue; } - long lret = (long)ret + m * CharValue(c, b); + var lret = (long)ret + m * CharValue(c, b); if (Int32.MinValue <= lret && lret <= Int32.MaxValue) { ret = (int)lret; } else { @@ -310,11 +305,10 @@ private static bool TryParseInt(char[] text, int start, int length, int b, out i return false; } for (int i = start, end = start + length; i < end; i++) { - int onechar; - char c = text[i]; + var c = text[i]; if (c == '_') { continue; - } else if (HexValue(c, out onechar) && onechar < b) { + } else if (HexValue(c, out var onechar) && onechar < b) { value = value * b + onechar; } else { return false; @@ -325,10 +319,9 @@ private static bool TryParseInt(char[] text, int start, int length, int b, out i public static object ParseInteger(string text, int b) { Debug.Assert(b != 0); - int iret; - if (!ParseInt(text, b, out iret)) { - BigInteger ret = ParseBigInteger(text, b); - if (ret >= Int32.MinValue && ret <= Int32.MaxValue) { + if (!ParseInt(text, b, out var iret)) { + var ret = ParseBigInteger(text, b); + if (ret >= int.MinValue && ret <= int.MaxValue) { return (int)ret; } return ret; @@ -346,20 +339,22 @@ public static object ParseIntegerSign(string text, int b) { ParseIntegerStart(text, ref b, ref start, end, ref sign); - int ret = 0; + var ret = 0; try { - int saveStart = start; + var saveStart = start; for (; ; ) { - int digit; if (start >= end) { if (saveStart == start) { throw new ArgumentException("Invalid integer literal"); } break; } - char c = text[start]; + var c = text[start]; if (c != '_') { - if (!HexValue(c, out digit)) break; + if (!HexValue(c, out var digit)) { + break; + } + if (!(digit < b)) { if (c == 'l' || c == 'L') { break; @@ -385,7 +380,9 @@ public static object ParseIntegerSign(string text, int b) { private static void ParseIntegerStart(string text, ref int b, ref int start, int end, ref short sign) { // Skip whitespace - while (start < end && Char.IsWhiteSpace(text, start)) start++; + while (start < end && Char.IsWhiteSpace(text, start)) { + start++; + } // Sign? if (start < end) { switch (text[start]) { @@ -398,7 +395,9 @@ private static void ParseIntegerStart(string text, ref int b, ref int start, int } } // Skip whitespace - while (start < end && Char.IsWhiteSpace(text, start)) start++; + while (start < end && Char.IsWhiteSpace(text, start)) { + start++; + } // Determine base if (b == 0) { @@ -437,7 +436,9 @@ private static void ParseIntegerStart(string text, ref int b, ref int start, int private static void ParseIntegerEnd(string text, int start, int end) { // Skip whitespace - while (start < end && Char.IsWhiteSpace(text, start)) start++; + while (start < end && Char.IsWhiteSpace(text, start)) { + start++; + } if (start < end) { throw new ArgumentException("invalid integer number literal"); @@ -446,24 +447,28 @@ private static void ParseIntegerEnd(string text, int start, int end) { public static BigInteger ParseBigInteger(string text, int b) { Debug.Assert(b != 0); - BigInteger ret = BigInteger.Zero; - BigInteger m = BigInteger.One; + var ret = BigInteger.Zero; + var m = BigInteger.One; if (text.Length != 0) { - int i = text.Length - 1; - if (text[i] == 'l' || text[i] == 'L') i -= 1; + var i = text.Length - 1; + if (text[i] == 'l' || text[i] == 'L') { + i -= 1; + } - int groupMax = 7; - if (b <= 10) groupMax = 9;// 2 147 483 647 + var groupMax = 7; + if (b <= 10) { + groupMax = 9;// 2 147 483 647 + } while (i >= 0) { // extract digits in a batch - int smallMultiplier = 1; + var smallMultiplier = 1; uint uval = 0; - for (int j = 0; j < groupMax && i >= 0; j++) { - char c = text[i--]; + for (var j = 0; j < groupMax && i >= 0; j++) { + var c = text[i--]; if (c != '_') { uval = (uint)(CharValue(c, b) * smallMultiplier + uval); smallMultiplier *= b; @@ -472,7 +477,9 @@ public static BigInteger ParseBigInteger(string text, int b) { // this is more generous than needed ret += m * (BigInteger)uval; - if (i >= 0) m = m * (smallMultiplier); + if (i >= 0) { + m = m * (smallMultiplier); + } } } @@ -489,19 +496,21 @@ public static BigInteger ParseBigIntegerSign(string text, int b) { ParseIntegerStart(text, ref b, ref start, end, ref sign); - BigInteger ret = BigInteger.Zero; - int saveStart = start; + var ret = BigInteger.Zero; + var saveStart = start; for (; ; ) { - int digit; if (start >= end) { if (start == saveStart) { throw new ArgumentException("Invalid integer literal"); } break; } - char c = text[start]; + var c = text[start]; if (c != '_') { - if (!HexValue(c, out digit)) break; + if (!HexValue(c, out var digit)) { + break; + } + if (!(digit < b)) { if (c == 'l' || c == 'L') { break; @@ -540,7 +549,7 @@ public static double ParseFloat(string text) { } private static double ParseFloatNoCatch(string text) { - string s = ReplaceUnicodeDigits(text); + var s = ReplaceUnicodeDigits(text); switch (s.ToLowerInvariant().TrimStart()) { case "nan": case "+nan": @@ -553,7 +562,7 @@ private static double ParseFloatNoCatch(string text) { return double.NegativeInfinity; default: // pass NumberStyles to disallow ,'s in float strings. - double res = double.Parse(s.Replace("_", ""), NumberStyles.Float, CultureInfo.InvariantCulture); + var res = double.Parse(s.Replace("_", ""), NumberStyles.Float, CultureInfo.InvariantCulture); return (res == 0.0 && text.TrimStart().StartsWithOrdinal("-")) ? NegativeZero : res; } } @@ -562,9 +571,12 @@ private static double ParseFloatNoCatch(string text) { private static string ReplaceUnicodeDigits(string text) { StringBuilder replacement = null; - for (int i = 0; i < text.Length; i++) { + for (var i = 0; i < text.Length; i++) { if (text[i] >= '\x660' && text[i] <= '\x669') { - if (replacement == null) replacement = new StringBuilder(text); + if (replacement == null) { + replacement = new StringBuilder(text); + } + replacement[i] = (char)(text[i] - '\x660' + '0'); } } @@ -575,15 +587,11 @@ private static string ReplaceUnicodeDigits(string text) { } // ParseComplex helpers - private static char[] signs = new char[] { '+', '-' }; - private static Exception ExnMalformed() { - return new ArgumentException("complex() arg is a malformed string"); - } public static Complex ParseImaginary(string text) { try { return new Complex(0.0, double.Parse( - text.Substring(0, text.Length - 1).Replace("_", ""), + text.Substring(0, text.Length - 1).Replace("_", string.Empty), CultureInfo.InvariantCulture.NumberFormat )); } catch (OverflowException) { diff --git a/src/Parsing/Impl/Microsoft.Python.Parsing.csproj b/src/Parsing/Impl/Microsoft.Python.Parsing.csproj new file mode 100644 index 000000000..0b21cd07b --- /dev/null +++ b/src/Parsing/Impl/Microsoft.Python.Parsing.csproj @@ -0,0 +1,40 @@ + + + netstandard2.0 + Microsoft.Python.Parsing + Microsoft.Python.Parsing + + + + 1701;1702;$(NoWarn) + 7.2 + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + diff --git a/src/Analysis/Engine/Impl/Parsing/ParseResult.cs b/src/Parsing/Impl/ParseResult.cs similarity index 94% rename from src/Analysis/Engine/Impl/Parsing/ParseResult.cs rename to src/Parsing/Impl/ParseResult.cs index 029163baa..2188b50d3 100644 --- a/src/Analysis/Engine/Impl/Parsing/ParseResult.cs +++ b/src/Parsing/Impl/ParseResult.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public enum ParseResult { /// /// Source code is a syntactically correct. diff --git a/src/Analysis/Engine/Impl/Parsing/Parser.cs b/src/Parsing/Impl/Parser.cs similarity index 87% rename from src/Analysis/Engine/Impl/Parsing/Parser.cs rename to src/Parsing/Impl/Parser.cs index ce48d262e..e30e9da07 100644 --- a/src/Analysis/Engine/Impl/Parsing/Parser.cs +++ b/src/Parsing/Impl/Parser.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -23,10 +23,11 @@ using System.Numerics; using System.Text; using System.Text.RegularExpressions; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public class Parser { // immutable properties: private readonly Tokenizer _tokenizer; @@ -86,9 +87,7 @@ private Parser(Tokenizer tokenizer, ErrorSink errorSink, PythonLanguageVersion l _privatePrefix = privatePrefix; } - public static Parser CreateParser(TextReader reader, PythonLanguageVersion version) { - return CreateParser(reader, version, null); - } + public static Parser CreateParser(TextReader reader, PythonLanguageVersion version) => CreateParser(reader, version, null); public static Parser CreateParser(TextReader reader, PythonLanguageVersion version, ParserOptions parserOptions) { if (reader == null) { @@ -145,9 +144,7 @@ public static Parser CreateParser(Stream stream, PythonLanguageVersion version, //single_input: Newline | simple_stmt | compound_stmt Newline //eval_input: testlist Newline* ENDMARKER //file_input: (Newline | stmt)* ENDMARKER - public PythonAst ParseFile() { - return ParseFileWorker(); - } + public PythonAst ParseFile() => ParseFileWorker(); //[stmt_list] Newline | compound_stmt Newline //stmt_list ::= simple_stmt (";" simple_stmt)* [";"] @@ -158,13 +155,11 @@ public PythonAst ParseFile() { /// /// null if input is not yet valid but could be with more lines public PythonAst ParseInteractiveCode(out ParseResult properties) { - bool parsingMultiLineCmpdStmt; - bool isEmptyStmt = false; properties = ParseResult.Complete; StartParsing(); - Statement ret = InternalParseInteractiveInput(out parsingMultiLineCmpdStmt, out isEmptyStmt); + var ret = InternalParseInteractiveInput(out var parsingMultiLineCmpdStmt, out var isEmptyStmt); if (_errorCode == 0) { if (isEmptyStmt) { @@ -221,7 +216,7 @@ public PythonAst ParseSingleStatement() { StartParsing(); MaybeEatNewLine(); - Statement statement = ParseStmt(); + var statement = ParseStmt(); EatEndOfInput(); return CreateAst(statement); } @@ -229,25 +224,21 @@ public PythonAst ParseSingleStatement() { public PythonAst ParseTopExpression() { // TODO: move from source unit .TrimStart(' ', '\t') _alwaysAllowContextDependentSyntax = true; - ReturnStatement ret = new ReturnStatement(ParseTestListAsExpression()); + var ret = new ReturnStatement(ParseTestListAsExpression()); _alwaysAllowContextDependentSyntax = false; ret.SetLoc(0, 0); return CreateAst(ret); } internal ErrorSink ErrorSink { - get { - return _errors; - } + get => _errors; set { Contract.Assert(value != null); _errors = value; } } - public int ErrorCode { - get { return _errorCode; } - } + public int ErrorCode => _errorCode; public void Reset(FutureOptions languageFeatures) { _languageFeatures = languageFeatures; @@ -262,21 +253,15 @@ public void Reset(FutureOptions languageFeatures) { _errorCode = 0; } - public void Reset() { - Reset(_languageFeatures); - } + public void Reset() => Reset(_languageFeatures); #endregion #region Error Reporting - private void ReportSyntaxError(TokenWithSpan t) { - ReportSyntaxError(t, ErrorCodes.SyntaxError); - } + private void ReportSyntaxError(TokenWithSpan t) => ReportSyntaxError(t, ErrorCodes.SyntaxError); - private void ReportSyntaxError(TokenWithSpan t, int errorCode) { - ReportSyntaxError(t.Token, t.Span, errorCode, true); - } + private void ReportSyntaxError(TokenWithSpan t, int errorCode) => ReportSyntaxError(t.Token, t.Span, errorCode, true); private void ReportSyntaxError(Token t, IndexSpan span, int errorCode, bool allowIncomplete) { var start = span.Start; @@ -286,7 +271,7 @@ private void ReportSyntaxError(Token t, IndexSpan span, int errorCode, bool allo errorCode |= ErrorCodes.IncompleteStatement; } - string msg = GetErrorMessage(t, errorCode); + var msg = GetErrorMessage(t, errorCode); ReportSyntaxError(start, end, msg, errorCode); } @@ -304,13 +289,9 @@ private static string GetErrorMessage(Token t, int errorCode) { return msg; } - private void ReportSyntaxError(string message) { - ReportSyntaxError(_lookahead.Span.Start, _lookahead.Span.End, message); - } + private void ReportSyntaxError(string message) => ReportSyntaxError(_lookahead.Span.Start, _lookahead.Span.End, message); - internal void ReportSyntaxError(int start, int end, string message) { - ReportSyntaxError(start, end, message, ErrorCodes.SyntaxError); - } + internal void ReportSyntaxError(int start, int end, string message) => ReportSyntaxError(start, end, message, ErrorCodes.SyntaxError); internal void ReportSyntaxError(int start, int end, string message, int errorCode) { // save the first one, the next error codes may be induced errors: @@ -329,9 +310,7 @@ internal void ReportSyntaxError(int start, int end, string message, int errorCod #region LL(1) Parsing - private static bool IsPrivateName(string name) { - return name.StartsWithOrdinal("__") && !name.EndsWithOrdinal("__"); - } + private static bool IsPrivateName(string name) => name.StartsWithOrdinal("__") && !name.EndsWithOrdinal("__"); private string FixName(string name) { if (_privatePrefix != null && IsPrivateName(name)) { @@ -343,7 +322,7 @@ private string FixName(string name) { private Name ReadNameMaybeNone() { // peek for better error recovery - Token t = PeekToken(); + var t = PeekToken(); if (t == Tokens.NoneToken) { NextToken(); return Name.None; @@ -373,11 +352,7 @@ public Name(string name, string verbatimName) { VerbatimName = verbatimName; } - public bool HasName { - get { - return RealName != null; - } - } + public bool HasName => RealName != null; } private Name ReadName() { @@ -398,19 +373,14 @@ private Name TokenToName(Token t) { return Name.Async; } } - var n = t as NameToken; - if (n != null) { + if (t is NameToken n) { return new Name(FixName(n.Name), n.Name); } return Name.Empty; } - private bool AllowReturnSyntax { - get { - return _alwaysAllowContextDependentSyntax || + private bool AllowReturnSyntax => _alwaysAllowContextDependentSyntax || CurrentFunction != null; - } - } private bool AllowYieldSyntax { get { @@ -494,7 +464,7 @@ private Statement ParseAsyncStmt() { //simple_stmt: small_stmt (';' small_stmt)* [';'] Newline private Statement ParseSimpleStmt() { - Statement s = ParseSmallStmt(); + var s = ParseSmallStmt(); string newline = null; if (MaybeEat(TokenKind.Semicolon)) { @@ -504,8 +474,7 @@ private Statement ParseSimpleStmt() { } var start = s.StartIndex; - List l = new List(); - l.Add(s); + var l = new List { s }; while (true) { if (MaybeEatNewLine(out newline) || MaybeEatEof()) { break; @@ -524,9 +493,9 @@ private Statement ParseSimpleStmt() { itemWhiteSpace.Add(_tokenWhiteSpace); } } - Statement[] stmts = l.ToArray(); + var stmts = l.ToArray(); - SuiteStatement ret = new SuiteStatement(stmts); + var ret = new SuiteStatement(stmts); ret.SetLoc(start, stmts[stmts.Length - 1].EndIndex); if (itemWhiteSpace != null) { AddListWhiteSpace(ret, itemWhiteSpace.ToArray()); @@ -617,21 +586,20 @@ private Statement ParseSmallStmt() { private Statement ParseDelStmt() { var curLookahead = _lookahead; NextToken(); - string delWhiteSpace = _tokenWhiteSpace; + var delWhiteSpace = _tokenWhiteSpace; var start = GetStart(); - List itemWhiteSpace; DelStatement ret; if (PeekToken(TokenKind.NewLine) || PeekToken(TokenKind.EndOfFile)) { ReportSyntaxError(curLookahead.Span.Start, curLookahead.Span.End, "expected expression after del"); ret = new DelStatement(new Expression[0]); } else { - List l = ParseExprList(out itemWhiteSpace); - foreach (Expression e in l) { + var l = ParseExprList(out var itemWhiteSpace); + foreach (var e in l) { if (e is ErrorExpression) { continue; } - string delError = e.CheckDelete(); + var delError = e.CheckDelete(); if (delError != null) { ReportSyntaxError(e.StartIndex, e.EndIndex, delError, ErrorCodes.SyntaxError); } @@ -656,7 +624,7 @@ private Statement ParseReturnStmt() { } var returnToken = _lookahead; NextToken(); - string returnWhitespace = _tokenWhiteSpace; + var returnWhitespace = _tokenWhiteSpace; Expression expr = null; var start = GetStart(); if (!NeverTestToken(PeekToken())) { @@ -674,7 +642,7 @@ private Statement ParseReturnStmt() { } } - ReturnStatement ret = new ReturnStatement(expr); + var ret = new ReturnStatement(expr); if (_verbatim) { AddPreceedingWhiteSpace(ret, returnWhitespace); } @@ -713,7 +681,7 @@ private Statement ParseYieldStmt() { Eat(TokenKind.KeywordYield); // See Pep 342: a yield statement is now just an expression statement around a yield expression. - Expression e = ParseYieldExpression(); + var e = ParseYieldExpression(); Debug.Assert(e != null); // caller already verified we have a yield. Statement s = new ExpressionStatement(e); @@ -733,11 +701,11 @@ private Expression ParseYieldExpression() { // If we're in a generator expression, then we don't have a function yet. // g=((yield i) for i in range(5)) // In that case, the genexp will mark IsGenerator. - FunctionDefinition current = CurrentFunction; + var current = CurrentFunction; if (current != null && !current.IsCoroutine) { current.IsGenerator = true; } - string whitespace = _tokenWhiteSpace; + var whitespace = _tokenWhiteSpace; var start = GetStart(); @@ -748,9 +716,9 @@ private Expression ParseYieldExpression() { // 4) 'from', in which case we expect a single expression and return YieldFromExpression Expression yieldResult; - bool isYieldFrom = PeekToken(TokenKind.KeywordFrom); - bool suppressSyntaxError = false; - string fromWhitespace = string.Empty; + var isYieldFrom = PeekToken(TokenKind.KeywordFrom); + var suppressSyntaxError = false; + var fromWhitespace = string.Empty; if (isYieldFrom) { if (_langVersion < PythonLanguageVersion.V33) { @@ -761,10 +729,7 @@ private Expression ParseYieldExpression() { NextToken(); fromWhitespace = _tokenWhiteSpace; } - - bool trailingComma; - List itemWhiteSpace; - List l = ParseTestListAsExpr(null, out itemWhiteSpace, out trailingComma); + var l = ParseTestListAsExpr(null, out var itemWhiteSpace, out var trailingComma); if (l.Count == 0) { if (_langVersion < PythonLanguageVersion.V25 && !suppressSyntaxError) { // 2.4 doesn't allow plain yield @@ -812,14 +777,14 @@ private Expression ParseYieldExpression() { private Statement FinishAssignments(Expression right, bool thereCanBeOnlyOne = false) { List left = null; - List assignWhiteSpace = MakeWhiteSpaceList(); + var assignWhiteSpace = MakeWhiteSpaceList(); Expression singleLeft = null; while (MaybeEat(TokenKind.Assign)) { if (assignWhiteSpace != null) { assignWhiteSpace.Add(_tokenWhiteSpace); } - string assignError = right.CheckAssign(); + var assignError = right.CheckAssign(); if (assignError != null) { ReportSyntaxError(right.StartIndex, right.EndIndex, assignError, ErrorCodes.SyntaxError | ErrorCodes.NoCaret); } @@ -831,8 +796,7 @@ private Statement FinishAssignments(Expression right, bool thereCanBeOnlyOne = f ReportSyntaxError(GetStart(), GetEnd(), "invalid syntax"); } if (left == null) { - left = new List(); - left.Add(singleLeft); + left = new List { singleLeft }; } left.Add(right); } @@ -923,8 +887,7 @@ private Expression ParseNameAnnotation(Expression expr) { var image = ws2 + ":"; Dictionary attr = null; if (_verbatim && _attributes.TryGetValue(err, out attr)) { - object o; - if (attr.TryGetValue(NodeAttributes.PreceedingWhiteSpace, out o)) { + if (attr.TryGetValue(NodeAttributes.PreceedingWhiteSpace, out var o)) { image += o.ToString(); } } @@ -951,8 +914,8 @@ private Expression ParseNameAnnotation(Expression expr) { // augmented_assignment_stmt ::= target augop (expression_list | yield_expression) // augop: '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '>>=' | '<<=' | '&=' | '^=' | '|=' | '//=' private Statement ParseExprStmt() { - Expression ret = ParseTestListAsExpr(); - bool hasAnnotation = false; + var ret = ParseTestListAsExpr(); + var hasAnnotation = false; if (PeekToken(TokenKind.Colon) && (_stubFile || _langVersion >= PythonLanguageVersion.V36)) { ret = ParseNameAnnotation(ret); @@ -966,10 +929,9 @@ private Statement ParseExprStmt() { if (PeekToken(TokenKind.Assign)) { if (_stubFile || _langVersion.Is3x()) { - SequenceExpression seq = ret as SequenceExpression; - bool hasStar = false; - if (seq != null) { - for (int i = 0; i < seq.Items.Count; i++) { + var hasStar = false; + if (ret is SequenceExpression seq) { + for (var i = 0; i < seq.Items.Count; i++) { if (seq.Items[i] is StarredExpression) { if (hasStar) { ReportSyntaxError(seq.Items[i].StartIndex, seq.Items[i].EndIndex, "two starred expressions in assignment"); @@ -982,10 +944,10 @@ private Statement ParseExprStmt() { return FinishAssignments(ret, hasAnnotation); } else { - PythonOperator op = GetAssignOperator(PeekToken()); + var op = GetAssignOperator(PeekToken()); if (op != PythonOperator.None) { NextToken(); - string whiteSpace = _tokenWhiteSpace; + var whiteSpace = _tokenWhiteSpace; Expression rhs; if (_langVersion >= PythonLanguageVersion.V25 && PeekToken(TokenKind.KeywordYield)) { @@ -998,12 +960,12 @@ private Statement ParseExprStmt() { rhs = ParseTestListAsExpr(); } - string assignError = ret.CheckAugmentedAssign(); + var assignError = ret.CheckAugmentedAssign(); if (assignError != null) { ReportSyntaxError(ret.StartIndex, ret.EndIndex, assignError); } - AugmentedAssignStatement aug = new AugmentedAssignStatement(op, ret, rhs); + var aug = new AugmentedAssignStatement(op, ret, rhs); if (_verbatim) { AddPreceedingWhiteSpace(aug, whiteSpace); } @@ -1063,12 +1025,12 @@ private PythonOperator GetBinaryOperator(OperatorToken token) { // name: identifier private ImportStatement ParseImportStmt() { Eat(TokenKind.KeywordImport); - string whitespace = _tokenWhiteSpace; + var whitespace = _tokenWhiteSpace; var start = GetStart(); - List asNameWhiteSpace = MakeWhiteSpaceList(); - List l = new List(); - List las = new List(); + var asNameWhiteSpace = MakeWhiteSpaceList(); + var l = new List(); + var las = new List(); var modName = ParseModuleName(); var commaWhiteSpace = MakeWhiteSpaceList(); if (modName.Names.Count > 0) { @@ -1082,10 +1044,10 @@ private ImportStatement ParseImportStmt() { las.Add(MaybeParseAsName(asNameWhiteSpace)); } } - ModuleName[] names = l.ToArray(); + var names = l.ToArray(); var asNames = las.ToArray(); - ImportStatement ret = new ImportStatement(names, asNames, AbsoluteImports); + var ret = new ImportStatement(names, asNames, AbsoluteImports); if (_verbatim) { AddListWhiteSpace(ret, commaWhiteSpace.ToArray()); AddNamesWhiteSpace(ret, asNameWhiteSpace.ToArray()); @@ -1097,37 +1059,34 @@ private ImportStatement ParseImportStmt() { // module: (identifier '.')* identifier private ModuleName ParseModuleName() { - List dotWhiteSpace; - ModuleName ret = new ModuleName(ReadDottedName(out dotWhiteSpace)); + var ret = new ModuleName(ReadDottedName(out var dotWhiteSpace)); if (_verbatim) { AddNamesWhiteSpace(ret, dotWhiteSpace.ToArray()); } - int start = ret.Names.FirstOrDefault()?.StartIndex ?? GetEnd(); + var start = ret.Names.FirstOrDefault()?.StartIndex ?? GetEnd(); ret.SetLoc(start, GetEnd()); return ret; } - private static NameExpression[] EmptyNames = new NameExpression[0]; + private static readonly NameExpression[] EmptyNames = new NameExpression[0]; // relative_module: "."* module | "."+ private ModuleName ParseRelativeModuleName() { - int start = -1; - bool isStartSetCorrectly = false; + var start = -1; + var isStartSetCorrectly = false; - int dotCount = 0; - List dotWhiteSpace = MakeWhiteSpaceList(); + var dotCount = 0; + var dotWhiteSpace = MakeWhiteSpaceList(); for (; ; ) { if (MaybeEat(TokenKind.Dot)) { - if (dotWhiteSpace != null) { - dotWhiteSpace.Add(_tokenWhiteSpace); - } + dotWhiteSpace?.Add(_tokenWhiteSpace); dotCount++; } else if (MaybeEat(TokenKind.Ellipsis)) { if (dotWhiteSpace != null) { dotWhiteSpace.Add(_tokenWhiteSpace); - dotWhiteSpace.Add(""); - dotWhiteSpace.Add(""); + dotWhiteSpace.Add(string.Empty); + dotWhiteSpace.Add(string.Empty); } dotCount += 3; } else { @@ -1140,7 +1099,7 @@ private ModuleName ParseRelativeModuleName() { } List nameWhiteSpace = null; - NameExpression[] names = EmptyNames; + var names = EmptyNames; if (PeekToken() is NameToken) { names = ReadDottedName(out nameWhiteSpace); if (!isStartSetCorrectly && names.Length > 0) { @@ -1179,7 +1138,7 @@ private ModuleName ParseRelativeModuleName() { } private NameExpression[] ReadDottedName(out List dotWhiteSpace) { - List l = new List(); + var l = new List(); dotWhiteSpace = MakeWhiteSpaceList(); var name = ReadName(); @@ -1211,25 +1170,25 @@ private NameExpression[] ReadDottedName(out List dotWhiteSpace) { // 'from' module 'import' "*" private FromImportStatement ParseFromImportStmt() { Eat(TokenKind.KeywordFrom); - string fromWhiteSpace = _tokenWhiteSpace; + var fromWhiteSpace = _tokenWhiteSpace; var start = GetStart(); - ModuleName dname = ParseRelativeModuleName(); + var dname = ParseRelativeModuleName(); - bool ateImport = Eat(TokenKind.KeywordImport); - int importIndex = ateImport ? GetStart() : 0; - string importWhiteSpace = _tokenWhiteSpace; + var ateImport = Eat(TokenKind.KeywordImport); + var importIndex = ateImport ? GetStart() : 0; + var importWhiteSpace = _tokenWhiteSpace; - bool ateParen = ateImport && MaybeEat(TokenKind.LeftParenthesis); - string parenWhiteSpace = ateParen ? _tokenWhiteSpace : null; + var ateParen = ateImport && MaybeEat(TokenKind.LeftParenthesis); + var parenWhiteSpace = ateParen ? _tokenWhiteSpace : null; NameExpression/*!*/[] names; NameExpression[] asNames; - bool fromFuture = false; + var fromFuture = false; List namesWhiteSpace = null; if (ateImport) { - List l = new List(); - List las = new List(); + var l = new List(); + var las = new List(); ParseAsNameList(l, las, out namesWhiteSpace); names = l.ToArray(); @@ -1250,9 +1209,9 @@ private FromImportStatement ParseFromImportStmt() { fromFuture = ProcessFutureStatements(start, names, fromFuture); } - bool ateRightParen = ateParen && Eat(TokenKind.RightParenthesis); + var ateRightParen = ateParen && Eat(TokenKind.RightParenthesis); - FromImportStatement ret = new FromImportStatement(dname, names, asNames, fromFuture, AbsoluteImports, importIndex); + var ret = new FromImportStatement(dname, names, asNames, fromFuture, AbsoluteImports, importIndex); if (_verbatim) { AddPreceedingWhiteSpace(ret, fromWhiteSpace); AddSecondPreceedingWhiteSpace(ret, importWhiteSpace); @@ -1316,7 +1275,7 @@ private bool ProcessFutureStatements(int start, NameExpression/*!*/[] names, boo } else if (_langVersion >= PythonLanguageVersion.V37 && name.Name == "annotations") { _languageFeatures |= FutureOptions.Annotations; } else { - string strName = name.Name; + var strName = name.Name; if (strName != "braces") { ReportSyntaxError(start, GetEnd(), "future feature is not defined: " + strName); @@ -1360,7 +1319,9 @@ private void ParseAsNameList(List l, List l asNamesWhiteSpace.Add(_tokenWhiteSpace); } - if (PeekToken(TokenKind.RightParenthesis)) return; // the list is allowed to end with a , + if (PeekToken(TokenKind.RightParenthesis)) { + return; // the list is allowed to end with a , + } if (MaybeEat(TokenKind.Multiply)) { nameExpr = new NameExpression("*"); @@ -1398,7 +1359,7 @@ private NameExpression MaybeParseAsName(List asNameWhiteSpace) { //exec_stmt: 'exec' expr ['in' expression [',' expression]] private ExecStatement ParseExecStmt() { Eat(TokenKind.KeywordExec); - string execWhiteSpace = _tokenWhiteSpace; + var execWhiteSpace = _tokenWhiteSpace; var start = GetStart(); Expression code, locals = null, globals = null; code = ParseExpr(); @@ -1412,7 +1373,7 @@ private ExecStatement ParseExecStmt() { } } - ExecStatement ret = new ExecStatement(code, locals, globals, code as TupleExpression); + var ret = new ExecStatement(code, locals, globals, code as TupleExpression); if (_verbatim) { AddPreceedingWhiteSpace(ret, execWhiteSpace); AddSecondPreceedingWhiteSpace(ret, inWhiteSpace); @@ -1426,13 +1387,11 @@ private ExecStatement ParseExecStmt() { private GlobalStatement ParseGlobalStmt() { Eat(TokenKind.KeywordGlobal); var start = GetStart(); - string globalWhiteSpace = _tokenWhiteSpace; - List commaWhiteSpace; - List namesWhiteSpace; + var globalWhiteSpace = _tokenWhiteSpace; - var l = ReadNameList(out commaWhiteSpace, out namesWhiteSpace); + var l = ReadNameList(out var commaWhiteSpace, out var namesWhiteSpace); var names = l.ToArray(); - GlobalStatement ret = new GlobalStatement(names); + var ret = new GlobalStatement(names); ret.SetLoc(start, GetEndForStatement()); if (_verbatim) { AddPreceedingWhiteSpace(ret, globalWhiteSpace); @@ -1448,14 +1407,12 @@ private NonlocalStatement ParseNonlocalStmt() { } Eat(TokenKind.KeywordNonlocal); - string localWhiteSpace = _tokenWhiteSpace; + var localWhiteSpace = _tokenWhiteSpace; var start = GetStart(); - List commaWhiteSpace; - List namesWhiteSpace; - var l = ReadNameList(out commaWhiteSpace, out namesWhiteSpace); + var l = ReadNameList(out var commaWhiteSpace, out var namesWhiteSpace); var names = l.ToArray(); - NonlocalStatement ret = new NonlocalStatement(names); + var ret = new NonlocalStatement(names); ret.SetLoc(start, GetEndForStatement()); if (_verbatim) { AddPreceedingWhiteSpace(ret, localWhiteSpace); @@ -1466,7 +1423,7 @@ private NonlocalStatement ParseNonlocalStmt() { } private List ReadNameList(out List commaWhiteSpace, out List namesWhiteSpace) { - List l = new List(); + var l = new List(); commaWhiteSpace = MakeWhiteSpaceList(); namesWhiteSpace = MakeWhiteSpaceList(); @@ -1495,11 +1452,11 @@ private List ReadNameList(out List commaWhiteSpace, out //raise_stmt: 'raise' [expression [',' expression [',' expression]]] private RaiseStatement ParseRaiseStmt() { Eat(TokenKind.KeywordRaise); - string raiseWhiteSpace = _tokenWhiteSpace; + var raiseWhiteSpace = _tokenWhiteSpace; string commaWhiteSpace = null, secondCommaWhiteSpace = null; var start = GetStart(); Expression type = null, value = null, traceback = null, cause = null; - bool isFromForm = false; + var isFromForm = false; int? valueFieldStart = null, tracebackFieldStart = null, causeFieldStart = null; @@ -1533,7 +1490,7 @@ private RaiseStatement ParseRaiseStmt() { } - RaiseStatement ret = new RaiseStatement(type, value, traceback, cause); + var ret = new RaiseStatement(type, value, traceback, cause); if (valueFieldStart.HasValue) { ret.ValueFieldStartIndex = valueFieldStart.Value; } @@ -1559,16 +1516,16 @@ private RaiseStatement ParseRaiseStmt() { //assert_stmt: 'assert' expression [',' expression] private AssertStatement ParseAssertStmt() { Eat(TokenKind.KeywordAssert); - string whiteSpace = _tokenWhiteSpace; + var whiteSpace = _tokenWhiteSpace; var start = GetStart(); - Expression expr = ParseExpression(); + var expr = ParseExpression(); Expression message = null; string commaWhiteSpace = null; if (MaybeEat(TokenKind.Comma)) { commaWhiteSpace = _tokenWhiteSpace; message = ParseExpression(); } - AssertStatement ret = new AssertStatement(expr, message); + var ret = new AssertStatement(expr, message); if (_verbatim) { AddPreceedingWhiteSpace(ret, whiteSpace); AddSecondPreceedingWhiteSpace(ret, commaWhiteSpace); @@ -1580,15 +1537,15 @@ private AssertStatement ParseAssertStmt() { //print_stmt: 'print' ( [ expression (',' expression)* [','] ] | '>>' expression [ (',' expression)+ [','] ] ) private PrintStatement ParsePrintStmt() { Eat(TokenKind.KeywordPrint); - string printWhiteSpace = _tokenWhiteSpace; + var printWhiteSpace = _tokenWhiteSpace; var start = GetStart(); Expression dest = null; PrintStatement ret; string rightShiftWhiteSpace = null; string theCommaWhiteSpace = null; - bool needNonEmptyTestList = false; - int end = 0; + var needNonEmptyTestList = false; + var end = 0; if (MaybeEat(TokenKind.RightShift)) { rightShiftWhiteSpace = _tokenWhiteSpace; dest = ParseExpression(); @@ -1607,7 +1564,7 @@ private PrintStatement ParsePrintStmt() { } } - bool trailingComma = false; + var trailingComma = false; List commaWhiteSpace = null; Expression[] exprs; @@ -1616,7 +1573,7 @@ private PrintStatement ParsePrintStmt() { if (!MaybeEat(TokenKind.Comma)) { exprs = new[] { expr }; } else { - List exprList = ParseTestListAsExpr(expr, out commaWhiteSpace, out trailingComma); + var exprList = ParseTestListAsExpr(expr, out commaWhiteSpace, out trailingComma); exprs = exprList.ToArray(); } } else { @@ -1642,7 +1599,7 @@ private PrintStatement ParsePrintStmt() { } private string SetPrivatePrefix(string name) { - string oldPrefix = _privatePrefix; + var oldPrefix = _privatePrefix; // Remove any leading underscores before saving the prefix _privatePrefix = name?.TrimStart('_'); @@ -1669,18 +1626,18 @@ private ErrorStatement ErrorStmt(string verbatimImage = null, params Statement[] //classdef: 'class' NAME ['(' testlist ')'] ':' suite private Statement ParseClassDef() { Eat(TokenKind.KeywordClass); - string classWhiteSpace = _tokenWhiteSpace; + var classWhiteSpace = _tokenWhiteSpace; var start = GetStart(); var name = ReadName(); var nameExpr = MakeName(name); - string nameWhiteSpace = name.HasName ? _tokenWhiteSpace : null; + var nameWhiteSpace = name.HasName ? _tokenWhiteSpace : null; - bool isParenFree = false; + var isParenFree = false; string leftParenWhiteSpace = null, rightParenWhiteSpace = null; List commaWhiteSpace = null; Arg[] args; - bool ateTerminator = true; + var ateTerminator = true; if (MaybeEat(TokenKind.LeftParenthesis)) { leftParenWhiteSpace = _tokenWhiteSpace; commaWhiteSpace = MakeWhiteSpaceList(); @@ -1700,17 +1657,17 @@ private Statement ParseClassDef() { var mid = _lookahead.Span.Start; // Save private prefix - string savedPrefix = SetPrivatePrefix(name.VerbatimName); + var savedPrefix = SetPrivatePrefix(name.VerbatimName); _classDepth++; // Parse the class body - Statement body = ParseClassOrFuncBody(); + var body = ParseClassOrFuncBody(); _classDepth--; // Restore the private prefix _privatePrefix = savedPrefix; - ClassDefinition ret = new ClassDefinition(nameExpr, args, body); + var ret = new ClassDefinition(nameExpr, args, body); AddVerbatimName(name, ret); if (_verbatim) { if (isParenFree) { @@ -1758,7 +1715,7 @@ private MemberExpression MakeMember(Expression target, Name name) { // decorator ::= // "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE private DecoratorStatement ParseDecorators(out List newlineWhiteSpace) { - List decorators = new List(); + var decorators = new List(); newlineWhiteSpace = MakeWhiteSpaceList(); Eat(TokenKind.At); var decStart = GetStart(); @@ -1779,14 +1736,14 @@ private DecoratorStatement ParseDecorators(out List newlineWhiteSpace) { } decorator.SetLoc(GetStart(), GetEnd()); while (MaybeEat(TokenKind.Dot)) { - int dotStart = GetStart(); - string whitespace = _tokenWhiteSpace; + var dotStart = GetStart(); + var whitespace = _tokenWhiteSpace; name = ReadNameMaybeNone(); if (!name.HasName) { decorator = Error(_verbatim ? (_tokenWhiteSpace + _token.Token.VerbatimImage + _lookaheadWhiteSpace + _lookahead.Token.VerbatimImage) : null, decorator); NextToken(); } else { - string nameWhitespace = _tokenWhiteSpace; + var nameWhitespace = _tokenWhiteSpace; var memberDecorator = MakeMember(decorator, name); memberDecorator.SetLoc(start, GetStart(), GetEnd()); memberDecorator.DotIndex = dotStart; @@ -1800,10 +1757,9 @@ private DecoratorStatement ParseDecorators(out List newlineWhiteSpace) { } if (MaybeEat(TokenKind.LeftParenthesis)) { - string parenWhiteSpace = _tokenWhiteSpace; + var parenWhiteSpace = _tokenWhiteSpace; var commaWhiteSpace = MakeWhiteSpaceList(); - bool ateTerminator; - Arg[] args = FinishArgumentList(null, commaWhiteSpace, out ateTerminator); + var args = FinishArgumentList(null, commaWhiteSpace, out var ateTerminator); decorator = FinishCallExpr(decorator, args); if (_verbatim) { @@ -1819,8 +1775,7 @@ private DecoratorStatement ParseDecorators(out List newlineWhiteSpace) { decorator.SetLoc(start, GetEnd()); } - string newline; - EatNewLine(out newline); + EatNewLine(out var newline); if (newlineWhiteSpace != null) { newlineWhiteSpace.Add(newline); } @@ -1838,18 +1793,17 @@ private DecoratorStatement ParseDecorators(out List newlineWhiteSpace) { // decorated: decorators (classdef | funcdef) // this gets called with "@" look-ahead private Statement ParseDecorated() { - List newlineWhiteSpace; - var decorators = ParseDecorators(out newlineWhiteSpace); + var decorators = ParseDecorators(out var newlineWhiteSpace); Statement res; var next = PeekToken(); if (next == Tokens.KeywordDefToken || next == Tokens.KeywordAsyncToken) { - bool isCoroutine = (next == Tokens.KeywordAsyncToken); + var isCoroutine = (next == Tokens.KeywordAsyncToken); if (isCoroutine) { Eat(TokenKind.KeywordAsync); } - FunctionDefinition fnc = ParseFuncDef(isCoroutine: isCoroutine); + var fnc = ParseFuncDef(isCoroutine: isCoroutine); fnc.Decorators = decorators; fnc.SetLoc(decorators.StartIndex, fnc.EndIndex); res = fnc; @@ -1888,7 +1842,7 @@ private FunctionDefinition ParseFuncDef(bool isCoroutine) { } Eat(TokenKind.KeywordDef); - int keywordEnd = GetEnd(); + var keywordEnd = GetEnd(); if (isCoroutine) { afterAsyncWhitespace = _tokenWhiteSpace; @@ -1899,24 +1853,23 @@ private FunctionDefinition ParseFuncDef(bool isCoroutine) { var name = ReadName(); var nameExpr = MakeName(name); - string nameWhiteSpace = _tokenWhiteSpace; + var nameWhiteSpace = _tokenWhiteSpace; - bool ateLeftParen = name.HasName && Eat(TokenKind.LeftParenthesis); - string parenWhiteSpace = _tokenWhiteSpace; + var ateLeftParen = name.HasName && Eat(TokenKind.LeftParenthesis); + var parenWhiteSpace = _tokenWhiteSpace; var lStart = GetStart(); var lEnd = GetEndForStatement(); - int grouping = _tokenizer.GroupingLevel; + var grouping = _tokenizer.GroupingLevel; List commaWhiteSpace = null; - bool ateTerminator = false; + var ateTerminator = false; var parameters = ateLeftParen ? ParseVarArgsList(TokenKind.RightParenthesis, true, out commaWhiteSpace, out ateTerminator) : null; - string closeParenWhiteSpace = ateTerminator || PeekToken(TokenKind.EndOfFile) ? _tokenWhiteSpace : null; + var closeParenWhiteSpace = ateTerminator || PeekToken(TokenKind.EndOfFile) ? _tokenWhiteSpace : null; FunctionDefinition ret; if (parameters == null) { // error in parameters - ret = new FunctionDefinition(nameExpr, new Parameter[0]); - ret.IsCoroutine = isCoroutine; + ret = new FunctionDefinition(nameExpr, new Parameter[0]) { IsCoroutine = isCoroutine }; if (_verbatim) { AddVerbatimName(name, ret); AddPreceedingWhiteSpace(ret, preWhitespace); @@ -1961,8 +1914,8 @@ private FunctionDefinition ParseFuncDef(bool isCoroutine) { // set IsCoroutine before parsing the body to enable use of 'await' ret.IsCoroutine = isCoroutine; - Statement body = ParseClassOrFuncBody(); - FunctionDefinition ret2 = PopFunction(); + var body = ParseClassOrFuncBody(); + var ret2 = PopFunction(); System.Diagnostics.Debug.Assert(ret == ret2); ret.SetBody(body); @@ -2000,13 +1953,13 @@ private Parameter[] ParseVarArgsList(TokenKind terminator, bool allowAnnotations var parameters = new List(); commaWhiteSpace = MakeWhiteSpaceList(); - bool namedOnly = false; - bool lastComma = true; + var namedOnly = false; + var lastComma = true; - int lastStart = -1; + var lastStart = -1; // First we parse all parameter names, as leniently as possible. - for (int pos = 0; !(ateTerminator = MaybeEat(terminator)) && !MaybeEat(TokenKind.EndOfFile); ++pos) { + for (var pos = 0; !(ateTerminator = MaybeEat(terminator)) && !MaybeEat(TokenKind.EndOfFile); ++pos) { Parameter p; if (!lastComma || lastStart == GetStart()) { @@ -2021,7 +1974,7 @@ private Parameter[] ParseVarArgsList(TokenKind terminator, bool allowAnnotations var kind = namedOnly ? ParameterKind.KeywordOnly : ParameterKind.Normal; string preStarWhitespace = null; - int start = -1; + var start = -1; if (MaybeEat(TokenKind.Multiply)) { start = GetStart(); @@ -2201,25 +2154,21 @@ private void ValidateSublistParameter(IEnumerable parameters, HashSe //Python2.5 -> old_lambdef: 'lambda' [varargslist] ':' old_expression private Expression FinishOldLambdef() { - string whitespace = _tokenWhiteSpace; - List commaWhiteSpace; - bool ateTerminator; - FunctionDefinition func = ParseLambdaHelperStart(out commaWhiteSpace, out ateTerminator); - string colonWhiteSpace = ateTerminator || PeekToken(TokenKind.EndOfFile) ? _tokenWhiteSpace : null; + var whitespace = _tokenWhiteSpace; + var func = ParseLambdaHelperStart(out var commaWhiteSpace, out var ateTerminator); + var colonWhiteSpace = ateTerminator || PeekToken(TokenKind.EndOfFile) ? _tokenWhiteSpace : null; - Expression expr = ateTerminator ? ParseOldExpression() : Error(""); + var expr = ateTerminator ? ParseOldExpression() : Error(string.Empty); return ParseLambdaHelperEnd(func, expr, whitespace, colonWhiteSpace, commaWhiteSpace, ateTerminator); } //lambdef: 'lambda' [varargslist] ':' expression private Expression FinishLambdef() { - string whitespace = _tokenWhiteSpace; - List commaWhiteSpace; - bool ateTerminator; - FunctionDefinition func = ParseLambdaHelperStart(out commaWhiteSpace, out ateTerminator); - string colonWhiteSpace = ateTerminator || PeekToken(TokenKind.EndOfFile) ? _tokenWhiteSpace : null; + var whitespace = _tokenWhiteSpace; + var func = ParseLambdaHelperStart(out var commaWhiteSpace, out var ateTerminator); + var colonWhiteSpace = ateTerminator || PeekToken(TokenKind.EndOfFile) ? _tokenWhiteSpace : null; - Expression expr = ateTerminator ? ParseExpression() : Error(""); + var expr = ateTerminator ? ParseExpression() : Error(string.Empty); return ParseLambdaHelperEnd(func, expr, whitespace, colonWhiteSpace, commaWhiteSpace, ateTerminator); } @@ -2235,8 +2184,7 @@ private FunctionDefinition ParseLambdaHelperStart(out List commaWhiteSpa var parameters = ParseVarArgsList(TokenKind.Colon, false, out commaWhiteSpace, out ateTerminator); var mid = GetEnd(); - FunctionDefinition func = new FunctionDefinition(null, parameters.MaybeEnumerate().ToArray()); - func.HeaderIndex = mid; + var func = new FunctionDefinition(null, parameters.MaybeEnumerate().ToArray()) { HeaderIndex = mid }; func.DefIndex = func.StartIndex = start; // Push the lambda function on the stack so that it's available for any yield expressions to mark it as a generator. @@ -2256,13 +2204,13 @@ private Expression ParseLambdaHelperEnd(FunctionDefinition func, Expression expr } body.SetLoc(expr.StartIndex, GetEndForStatement()); - FunctionDefinition func2 = PopFunction(); + var func2 = PopFunction(); System.Diagnostics.Debug.Assert(func == func2); func.SetBody(body); func.EndIndex = GetEndForStatement(); - LambdaExpression ret = new LambdaExpression(func); + var ret = new LambdaExpression(func); func.LambdaExpression = ret; func.SetLoc(func.IndexSpan); ret.SetLoc(func.IndexSpan); @@ -2280,22 +2228,22 @@ private Expression ParseLambdaHelperEnd(FunctionDefinition func, Expression expr //while_stmt: 'while' expression ':' suite ['else' ':' suite] private WhileStatement ParseWhileStmt() { Eat(TokenKind.KeywordWhile); - string whileWhiteSpace = _tokenWhiteSpace; + var whileWhiteSpace = _tokenWhiteSpace; var start = GetStart(); - Expression expr = ParseExpression(); + var expr = ParseExpression(); var mid = GetEnd(); - Statement body = ParseLoopSuite(); + var body = ParseLoopSuite(); Statement else_ = null; string elseWhiteSpace = null; - int end = body.EndIndex; - int elseIndex = -1; + var end = body.EndIndex; + var elseIndex = -1; if (MaybeEat(TokenKind.KeywordElse)) { elseIndex = _lookahead.Span.End; elseWhiteSpace = _tokenWhiteSpace; else_ = ParseSuite(); end = else_.EndIndex; } - WhileStatement ret = new WhileStatement(expr, body, else_); + var ret = new WhileStatement(expr, body, else_); ret.SetLoc(start, mid, end, elseIndex); if (_verbatim) { AddPreceedingWhiteSpace(ret, whileWhiteSpace); @@ -2315,26 +2263,22 @@ private WithStatement ParseWithStmt(bool isAsync) { if (!isAsync) { start = GetStart(); } - int keywordEnd = GetEnd(); + var keywordEnd = GetEnd(); - string withWhiteSpace = _tokenWhiteSpace; + var withWhiteSpace = _tokenWhiteSpace; var itemWhiteSpace = MakeWhiteSpaceList(); - List items = new List(); - items.Add(ParseWithItem(itemWhiteSpace)); + var items = new List { ParseWithItem(itemWhiteSpace) }; while (MaybeEat(TokenKind.Comma)) { - if (itemWhiteSpace != null) { - itemWhiteSpace.Add(_tokenWhiteSpace); - } + itemWhiteSpace?.Add(_tokenWhiteSpace); items.Add(ParseWithItem(itemWhiteSpace)); } var header = PeekToken(TokenKind.Colon) ? GetEnd() : -1; - Statement body = ParseSuite(); + var body = ParseSuite(); - WithStatement ret = new WithStatement(items.ToArray(), body, isAsync); - ret.HeaderIndex = header; + var ret = new WithStatement(items.ToArray(), body, isAsync) { HeaderIndex = header }; if (_verbatim) { AddPreceedingWhiteSpace(ret, isAsync ? asyncWhiteSpace : withWhiteSpace); AddSecondPreceedingWhiteSpace(ret, isAsync ? withWhiteSpace : null); @@ -2347,9 +2291,9 @@ private WithStatement ParseWithStmt(bool isAsync) { private WithItem ParseWithItem(List itemWhiteSpace) { var start = GetStart(); - Expression contextManager = ParseExpression(); + var contextManager = ParseExpression(); Expression var = null; - int asIndex = -1; + var asIndex = -1; if (MaybeEat(TokenKind.KeywordAs)) { asIndex = GetStart(); if (itemWhiteSpace != null) { @@ -2368,17 +2312,14 @@ private Statement ParseForStmt(bool isAsync) { var start = isAsync ? GetStart() : 0; var asyncWhiteSpace = isAsync ? _tokenWhiteSpace : null; Eat(TokenKind.KeywordFor); - int forIndex = GetStart(); + var forIndex = GetStart(); if (!isAsync) { start = GetStart(); } - int keywordEnd = GetEnd(); - string forWhiteSpace = _tokenWhiteSpace; - - bool trailingComma; - List listWhiteSpace; + var keywordEnd = GetEnd(); + var forWhiteSpace = _tokenWhiteSpace; - List l = ParseExpressionList(out trailingComma, out listWhiteSpace); + var l = ParseExpressionList(out var trailingComma, out var listWhiteSpace); // expr list is something like: // () @@ -2389,12 +2330,12 @@ private Statement ParseForStmt(bool isAsync) { // so we can do tupleExpr.EmitSet() or loneExpr.EmitSet() string inWhiteSpace = null, elseWhiteSpace = null; - Expression lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); + var lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); Expression list; Statement body, else_; - bool incomplete = false; + var incomplete = false; int header, inIndex = -1, elseIndex = -1; - string newlineWhiteSpace = ""; + var newlineWhiteSpace = ""; int end; if ((lhs is ErrorExpression && MaybeEatNewLine(out newlineWhiteSpace)) || !Eat(TokenKind.KeywordIn)) { // error handling @@ -2420,7 +2361,7 @@ private Statement ParseForStmt(bool isAsync) { } } - ForStatement ret = new ForStatement(lhs, list, body, else_, isAsync); + var ret = new ForStatement(lhs, list, body, else_, isAsync); if (_verbatim) { AddPreceedingWhiteSpace(ret, isAsync ? asyncWhiteSpace : forWhiteSpace); AddFourthPreceedingWhiteSpace(ret, isAsync ? forWhiteSpace : null); @@ -2445,8 +2386,8 @@ private Statement ParseForStmt(bool isAsync) { private Statement ParseLoopSuite() { Statement body; - bool inLoop = _inLoop; - bool inFinally = _inFinally; + var inLoop = _inLoop; + var inFinally = _inFinally; try { _inLoop = true; _inFinally = false; @@ -2486,7 +2427,7 @@ private IfStatement ParseIfStmt() { } var start = GetStart(); - List l = new List(); + var l = new List(); l.Add(ParseIfStmtTest()); while (MaybeEat(TokenKind.KeywordElseIf)) { @@ -2498,15 +2439,15 @@ private IfStatement ParseIfStmt() { Statement else_ = null; string elseWhiteSpace = null; - int elseIndex = -1; + var elseIndex = -1; if (MaybeEat(TokenKind.KeywordElse)) { elseWhiteSpace = _tokenWhiteSpace; elseIndex = _lookahead.Span.End; else_ = ParseSuite(); } - IfStatementTest[] tests = l.ToArray(); - IfStatement ret = new IfStatement(tests, else_); + var tests = l.ToArray(); + var ret = new IfStatement(tests, else_); if (_verbatim) { if (elseWhiteSpace != null) { AddPreceedingWhiteSpace(ret, elseWhiteSpace); @@ -2522,10 +2463,10 @@ private IfStatement ParseIfStmt() { private IfStatementTest ParseIfStmtTest() { var start = GetStart(); - Expression expr = ParseExpression(); + var expr = ParseExpression(); var header = GetEnd(); - Statement suite = ParseSuite(); - IfStatementTest ret = new IfStatementTest(expr, suite); + var suite = ParseSuite(); + var ret = new IfStatementTest(expr, suite); ret.SetLoc(start, GetEndForStatement()); ret.HeaderIndex = header; return ret; @@ -2548,11 +2489,11 @@ private IfStatementTest ParseIfStmtTest() { private Statement ParseTryStatement() { Eat(TokenKind.KeywordTry); - string tryWhiteSpace = _tokenWhiteSpace; + var tryWhiteSpace = _tokenWhiteSpace; var start = GetStart(); var mid = _lookahead.Span.End; int elseIndex = -1, finallyIndex = -1; - Statement body = ParseSuite(); + var body = ParseSuite(); Statement finallySuite = null; Statement elseSuite = null; TryStatement ret; @@ -2565,13 +2506,13 @@ private Statement ParseTryStatement() { ret = new TryStatement(body, null, elseSuite, finallySuite); ret.HeaderIndex = mid; } else { - List handlers = new List(); + var handlers = new List(); TryStatementHandler dh = null; while (true) { if (!MaybeEat(TokenKind.KeywordExcept)) { break; } - TryStatementHandler handler = ParseTryStmtHandler(); + var handler = ParseTryStmtHandler(); handlers.Add(handler); @@ -2616,7 +2557,7 @@ private Statement ParseTryStatement() { } private Statement ParseFinallySuite(Statement finallySuite) { - bool inFinally = _inFinally; + var inFinally = _inFinally; try { _inFinally = true; finallySuite = ParseSuite(); @@ -2629,12 +2570,12 @@ private Statement ParseFinallySuite(Statement finallySuite) { //except_clause: 'except' [expression [',' expression]] //2.6: except_clause: 'except' [expression [(',' or 'as') expression]] private TryStatementHandler ParseTryStmtHandler() { - string exceptWhiteSpace = _tokenWhiteSpace; + var exceptWhiteSpace = _tokenWhiteSpace; string commaWhiteSpace = null; var start = GetStart(); var keywordEnd = GetEnd(); Expression test1 = null, test2 = null; - bool altForm = false; + var altForm = false; if (PeekToken().Kind != TokenKind.Colon) { test1 = ParseExpression(); @@ -2657,10 +2598,8 @@ private TryStatementHandler ParseTryStmtHandler() { } } var mid = _lookahead.Span.End; - Statement body = ParseSuite(); - TryStatementHandler ret = new TryStatementHandler(test1, test2, body); - ret.HeaderIndex = mid; - ret.KeywordEndIndex = keywordEnd; + var body = ParseSuite(); + var ret = new TryStatementHandler(test1, test2, body) { HeaderIndex = mid, KeywordEndIndex = keywordEnd }; ret.SetLoc(start, body.EndIndex); if (_verbatim) { @@ -2686,10 +2625,10 @@ private Statement ParseSuite() { return error; } - string colonWhiteSpace = _tokenWhiteSpace; + var colonWhiteSpace = _tokenWhiteSpace; - TokenWithSpan cur = _lookahead; - List l = new List(); + var cur = _lookahead; + var l = new List(); // we only read a real NewLine here because we need to adjust error reporting // for the interpreter. @@ -2728,7 +2667,7 @@ private Statement ParseSuite() { } while (true) { - Statement s = ParseStmt(); + var s = ParseStmt(); l.Add(s); if (MaybeEat(TokenKind.Dedent)) { @@ -2783,7 +2722,7 @@ private Expression ParseExpression() { return FinishLambdef(); } - Expression ret = ParseOrTest(); + var ret = ParseOrTest(); if (ret is ErrorExpression) { return ret; } else if (MaybeEat(TokenKind.KeywordIf)) { @@ -2797,9 +2736,9 @@ private Expression ParseExpression() { // or_test: and_test ('or' and_test)* private Expression ParseOrTest() { - Expression ret = ParseAndTest(); + var ret = ParseAndTest(); while (MaybeEat(TokenKind.KeywordOr)) { - string proceeding = _tokenWhiteSpace; + var proceeding = _tokenWhiteSpace; var start = ret.StartIndex; var orIndex = GetStart(); ret = new OrExpression(ret, ParseAndTest(), orIndex); @@ -2812,11 +2751,11 @@ private Expression ParseOrTest() { } private Expression ParseConditionalTest(Expression trueExpr) { - int ifIndex = GetStart(); - string ifWhiteSpace = _tokenWhiteSpace; - Expression expr = ParseOrTest(); - bool ateElse = Eat(TokenKind.KeywordElse); - int elseIndex = GetStart(); + var ifIndex = GetStart(); + var ifWhiteSpace = _tokenWhiteSpace; + var expr = ParseOrTest(); + var ateElse = Eat(TokenKind.KeywordElse); + var elseIndex = GetStart(); string elseWhiteSpace; Expression falseExpr; if (ateElse) { @@ -2839,9 +2778,9 @@ private Expression ParseConditionalTest(Expression trueExpr) { // and_test: not_test ('and' not_test)* private Expression ParseAndTest() { - Expression ret = ParseNotTest(); + var ret = ParseNotTest(); while (MaybeEat(TokenKind.KeywordAnd)) { - string proceeding = _tokenWhiteSpace; + var proceeding = _tokenWhiteSpace; var start = ret.StartIndex; var andIndex = GetStart(); @@ -2857,7 +2796,7 @@ private Expression ParseAndTest() { //not_test: 'not' not_test | comparison private Expression ParseNotTest() { if (MaybeEat(TokenKind.KeywordNot)) { - string proceeding = _tokenWhiteSpace; + var proceeding = _tokenWhiteSpace; var start = GetStart(); Expression ret = new UnaryExpression(PythonOperator.Not, ParseNotTest()); if (_verbatim) { @@ -2872,13 +2811,13 @@ private Expression ParseNotTest() { //comparison: expr (comp_op expr)* //comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' private Expression ParseComparison() { - Expression ret = ParseStarExpression(); + var ret = ParseStarExpression(); while (true) { PythonOperator op; - string whitespaceBeforeOperator = _lookaheadWhiteSpace; + var whitespaceBeforeOperator = _lookaheadWhiteSpace; string secondWhiteSpace = null; bool isLessThanGreaterThan = false, isIncomplete = false; - int opIndex = -1; + var opIndex = -1; switch (PeekToken().Kind) { case TokenKind.LessThan: NextToken(); op = PythonOperator.LessThan; break; case TokenKind.LessThanOrEqual: NextToken(); op = PythonOperator.LessThanOrEqual; break; @@ -2914,8 +2853,8 @@ private Expression ParseComparison() { opIndex = GetStart(); } - Expression rhs = ParseComparison(); - BinaryExpression be = new BinaryExpression(op, ret, rhs, opIndex); + var rhs = ParseComparison(); + var be = new BinaryExpression(op, ret, rhs, opIndex); if (_verbatim) { AddPreceedingWhiteSpace(be, whitespaceBeforeOperator); GetNodeAttributes(be)[NodeAttributes.SecondPreceedingWhiteSpace] = secondWhiteSpace; @@ -2939,26 +2878,25 @@ private Expression ParseComparison() { arith_expr: term (('+'|'-') term)* term: factor (('*'|'@'|'/'|'%'|'//') factor)* */ - private Expression ParseExpr() { - return ParseExpr(0); - } + private Expression ParseExpr() => ParseExpr(0); private Expression ParseExpr(int precedence) { - Expression ret = ParseFactor(); + var ret = ParseFactor(); while (true) { - Token t = PeekToken(); + var t = PeekToken(); if (_langVersion >= PythonLanguageVersion.V35 && t.Kind == TokenKind.At) { t = Tokens.MatMultiplyToken; } - OperatorToken ot = t as OperatorToken; - if (ot == null) return ret; + if (!(t is OperatorToken ot)) { + return ret; + } - int prec = ot.Precedence; + var prec = ot.Precedence; if (prec >= precedence) { NextToken(); - int opIndex = GetStart(); - string whiteSpace = _tokenWhiteSpace; - Expression right = ParseExpr(prec + 1); + var opIndex = GetStart(); + var whiteSpace = _tokenWhiteSpace; + var right = ParseExpr(prec + 1); var start = ret.StartIndex; ret = new BinaryExpression(GetBinaryOperator(ot), ret, right, opIndex); if (_verbatim) { @@ -2978,7 +2916,7 @@ private Expression ParseFactor() { switch (PeekToken().Kind) { case TokenKind.Add: NextToken(); - string posWhiteSpace = _tokenWhiteSpace; + var posWhiteSpace = _tokenWhiteSpace; ret = new UnaryExpression(PythonOperator.Pos, ParseFactor()); if (_verbatim) { AddPreceedingWhiteSpace(ret, posWhiteSpace); @@ -2990,7 +2928,7 @@ private Expression ParseFactor() { break; case TokenKind.Twiddle: NextToken(); - string twiddleWhiteSpace = _tokenWhiteSpace; + var twiddleWhiteSpace = _tokenWhiteSpace; ret = new UnaryExpression(PythonOperator.Invert, ParseFactor()); if (_verbatim) { AddPreceedingWhiteSpace(ret, twiddleWhiteSpace); @@ -3006,17 +2944,17 @@ private Expression ParseFactor() { private Expression FinishUnaryNegate() { // Special case to ensure that System.Int32.MinValue is an int and not a BigInteger if (PeekToken().Kind == TokenKind.Constant) { - Token t = PeekToken(); + var t = PeekToken(); if (t.Value is BigInteger) { - BigInteger bi = (BigInteger)t.Value; + var bi = (BigInteger)t.Value; if (bi == 0x80000000) { - string tokenString = _tokenizer.GetTokenString(); ; + var tokenString = _tokenizer.GetTokenString(); ; Debug.Assert(tokenString.Length > 0); if (tokenString[tokenString.Length - 1] != 'L' && tokenString[tokenString.Length - 1] != 'l') { - string minusWhiteSpace = _tokenWhiteSpace; + var minusWhiteSpace = _tokenWhiteSpace; NextToken(); // TODO Fix the white space here @@ -3031,7 +2969,7 @@ private Expression FinishUnaryNegate() { } } - string whitespace = _tokenWhiteSpace; + var whitespace = _tokenWhiteSpace; var res = new UnaryExpression(PythonOperator.Negate, ParseFactor()); if (_verbatim) { AddPreceedingWhiteSpace(res, whitespace); @@ -3046,7 +2984,7 @@ private Expression ParseAwaitExpr() { if (allowed && MaybeEat(TokenKind.KeywordAwait)) { var start = GetStart(); - string whitespace = _tokenWhiteSpace; + var whitespace = _tokenWhiteSpace; var res = new AwaitExpression(ParseAwaitExpr()); if (_verbatim) { AddPreceedingWhiteSpace(res, whitespace); @@ -3060,12 +2998,12 @@ private Expression ParseAwaitExpr() { // power: atom trailer* ['**' factor] private Expression ParsePower() { - Expression ret = ParsePrimary(); + var ret = ParsePrimary(); ret = AddTrailers(ret); if (MaybeEat(TokenKind.Power)) { var start = ret.StartIndex; - int opIndex = GetStart(); - string whitespace = _tokenWhiteSpace; + var opIndex = GetStart(); + var whitespace = _tokenWhiteSpace; ret = new BinaryExpression(PythonOperator.Power, ret, ParseFactor(), opIndex); if (_verbatim) { AddPreceedingWhiteSpace(ret, whitespace); @@ -3086,7 +3024,7 @@ private Expression ParsePower() { // string_conversion | // yield_atom private Expression ParsePrimary() { - Token t = PeekToken(); + var t = PeekToken(); Expression ret; switch (t.Kind) { case TokenKind.LeftParenthesis: // parenth_form, generator_expression, yield_atom @@ -3140,8 +3078,8 @@ private Expression ParsePrimary() { case TokenKind.Constant: // literal NextToken(); var start = GetStart(); - object cv = t.Value; - string cvs = cv as string; + var cv = t.Value; + var cvs = cv as string; AsciiString bytes; if (PeekToken() is ConstantValueToken && (cv is string || cv is AsciiString)) { // string plus @@ -3206,12 +3144,11 @@ private string FinishStringPlus(string s, Token initialToken, out string[] verba } private string FinishStringPlus(string s, List verbatimImages, List verbatimWhiteSpace) { - Token t = PeekToken(); + var t = PeekToken(); while (true) { if (t is ConstantValueToken) { - string cvs; AsciiString bytes; - if ((cvs = t.Value as String) != null) { + if (t.Value is String cvs) { s += cvs; NextToken(); if (_verbatim) { @@ -3243,8 +3180,8 @@ private string FinishStringPlus(string s, List verbatimImages, List bytes) { - StringBuilder res = new StringBuilder(bytes.Count); - for (int i = 0; i < bytes.Count; i++) { + var res = new StringBuilder(bytes.Count); + for (var i = 0; i < bytes.Count; i++) { res.Append((char)bytes[i]); } return res.ToString(); @@ -3272,13 +3209,12 @@ private object FinishBytesPlus(AsciiString s, Token initialToken, out string[] v } private object FinishBytesPlus(AsciiString s, List verbatimImages, List verbatimWhiteSpace) { - Token t = PeekToken(); + var t = PeekToken(); while (true) { if (t is ConstantValueToken) { - AsciiString cvs; string str; - if ((cvs = t.Value as AsciiString) != null) { - List res = new List(s.Bytes); + if (t.Value is AsciiString cvs) { + var res = new List(s.Bytes); res.AddRange(cvs.Bytes); s = new AsciiString(res.ToArray(), s.String + cvs.String); NextToken(); @@ -3293,7 +3229,7 @@ private object FinishBytesPlus(AsciiString s, List verbatimImages, List< ReportSyntaxError("cannot mix bytes and nonbytes literals"); } - string final = s.String + str; + var final = s.String + str; NextToken(); if (_verbatim) { verbatimWhiteSpace.Add(_tokenWhiteSpace); @@ -3310,26 +3246,26 @@ private object FinishBytesPlus(AsciiString s, List verbatimImages, List< return s; } - private Expression AddTrailers(Expression ret) { - return AddTrailers(ret, true); - } + private Expression AddTrailers(Expression ret) => AddTrailers(ret, true); // trailer: '(' [ arglist_genexpr ] ')' | '[' subscriptlist ']' | '.' NAME private Expression AddTrailers(Expression ret, bool allowGeneratorExpression) { - bool prevAllow = _allowIncomplete; + var prevAllow = _allowIncomplete; try { _allowIncomplete = true; while (true) { switch (PeekToken().Kind) { case TokenKind.LeftParenthesis: - if (!allowGeneratorExpression) return ret; + if (!allowGeneratorExpression) { + return ret; + } NextToken(); - string whitespace = _tokenWhiteSpace; + var whitespace = _tokenWhiteSpace; List commaWhiteSpace; bool ateTerminator; - Arg[] args = FinishArgListOrGenExpr(out commaWhiteSpace, out ateTerminator); - string closeParenWhiteSpace = _tokenWhiteSpace; + var args = FinishArgListOrGenExpr(out commaWhiteSpace, out ateTerminator); + var closeParenWhiteSpace = _tokenWhiteSpace; CallExpression call; if (args != null) { call = FinishCallExpr(ret, args); @@ -3355,9 +3291,9 @@ private Expression AddTrailers(Expression ret, bool allowGeneratorExpression) { NextToken(); whitespace = _tokenWhiteSpace; - Expression index = ParseSubscriptList(out ateTerminator); - IndexExpression ie = new IndexExpression(ret, index); - string finishWhiteSpace = _tokenWhiteSpace; + var index = ParseSubscriptList(out ateTerminator); + var ie = new IndexExpression(ret, index); + var finishWhiteSpace = _tokenWhiteSpace; ie.SetLoc(ret.StartIndex, GetEnd()); if (_verbatim) { AddPreceedingWhiteSpace(ie, whitespace); @@ -3370,11 +3306,11 @@ private Expression AddTrailers(Expression ret, bool allowGeneratorExpression) { break; case TokenKind.Dot: NextToken(); - int dotStart = GetStart(); + var dotStart = GetStart(); whitespace = _tokenWhiteSpace; var name = ReadNameMaybeNone(); - string nameWhitespace = _tokenWhiteSpace; - MemberExpression fe = MakeMember(ret, name); + var nameWhitespace = _tokenWhiteSpace; + var fe = MakeMember(ret, name); fe.SetLoc(ret.StartIndex, name.HasName ? GetStart() : GetEnd(), GetEnd()); fe.DotIndex = dotStart; if (_verbatim) { @@ -3407,14 +3343,14 @@ private Expression AddTrailers(Expression ret, bool allowGeneratorExpression) { private Expression ParseSubscriptList(out bool ateTerminator) { const TokenKind terminator = TokenKind.RightBracket; var start0 = GetStart(); - bool trailingComma = false; + var trailingComma = false; - List l = new List(); - List listWhiteSpace = MakeWhiteSpaceList(); + var l = new List(); + var listWhiteSpace = MakeWhiteSpaceList(); while (true) { Expression e; if (MaybeEat(TokenKind.Dot)) { - string whitespace = _tokenWhiteSpace; + var whitespace = _tokenWhiteSpace; var start = GetStart(); if (Eat(TokenKind.Dot)) { if (Eat(TokenKind.Dot)) { @@ -3454,7 +3390,7 @@ private Expression ParseSubscriptList(out bool ateTerminator) { break; } } - Expression ret = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); + var ret = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); if (l.Count != 1 || ret != l[0]) { ret.SetLoc(start0, GetEnd()); } @@ -3477,9 +3413,9 @@ private Expression ParseSliceEnd() { private Expression FinishSlice(Expression e0, int start) { Expression e1 = null; Expression e2 = null; - bool stepProvided = false; + var stepProvided = false; Debug.Assert(_token.Token.Kind == TokenKind.Colon); - string colonWhiteSpace = _tokenWhiteSpace; + var colonWhiteSpace = _tokenWhiteSpace; string secondColonWhiteSpace = null; switch (PeekToken().Kind) { @@ -3503,7 +3439,7 @@ private Expression FinishSlice(Expression e0, int start) { } break; } - SliceExpression ret = new SliceExpression(e0, e1, e2, stepProvided); + var ret = new SliceExpression(e0, e1, e2, stepProvided); if (_verbatim) { AddPreceedingWhiteSpace(ret, colonWhiteSpace); if (secondColonWhiteSpace != null) { @@ -3517,10 +3453,10 @@ private Expression FinishSlice(Expression e0, int start) { //exprlist: expr (',' expr)* [','] private List ParseExprList(out List commaWhiteSpace) { - List l = new List(); + var l = new List(); commaWhiteSpace = MakeWhiteSpaceList(); while (true) { - Expression e = ParseExpr(); + var e = ParseExpr(); l.Add(e); if (!MaybeEat(TokenKind.Comma)) { break; @@ -3544,9 +3480,9 @@ private Arg[] FinishArgListOrGenExpr(out List commaWhiteSpace, out bool Arg a = null; commaWhiteSpace = MakeWhiteSpaceList(); - Token t = PeekToken(); + var t = PeekToken(); if (t.Kind != TokenKind.RightParenthesis && t.Kind != TokenKind.Multiply && t.Kind != TokenKind.Power) { - Expression e = ParseExpression(); + var e = ParseExpression(); if (e is ErrorExpression) { ateTerminator = false; a = new Arg(e); @@ -3589,19 +3525,18 @@ private Arg[] FinishArgListOrGenExpr(out List commaWhiteSpace, out bool private Arg FinishKeywordArgument(Expression t) { Debug.Assert(_token.Token.Kind == TokenKind.Assign); - string equalWhiteSpace = _tokenWhiteSpace; - NameExpression n = t as NameExpression; + var equalWhiteSpace = _tokenWhiteSpace; string name; - if (n == null) { + if (!(t is NameExpression n)) { ReportSyntaxError(t.StartIndex, t.EndIndex, "expected name"); name = null; } else { name = n.Name; } - Expression val = ParseExpression(); - Arg arg = new Arg(t, val); + var val = ParseExpression(); + var arg = new Arg(t, val); arg.SetLoc(t.StartIndex, val.EndIndex); if (_verbatim) { AddPreceedingWhiteSpace(arg, equalWhiteSpace); @@ -3613,8 +3548,8 @@ private Arg FinishKeywordArgument(Expression t) { private void CheckUniqueArgument(List names, Arg arg) { if (arg != null && arg.Name != null) { - string name = arg.Name; - for (int i = 0; i < names.Count; i++) { + var name = arg.Name; + for (var i = 0; i < names.Count; i++) { if (names[i].Name == arg.Name) { ReportSyntaxError("duplicate keyword argument"); } @@ -3626,7 +3561,7 @@ private void CheckUniqueArgument(List names, Arg arg) { //argument: [expression '='] expression # Really [keyword '='] expression private Arg[] FinishArgumentList(Arg first, List commaWhiteSpace, out bool ateTerminator) { const TokenKind terminator = TokenKind.RightParenthesis; - List l = new List(); + var l = new List(); if (first != null) { l.Add(first); @@ -3641,25 +3576,25 @@ private Arg[] FinishArgumentList(Arg first, List commaWhiteSpace, out bo int start; Arg a; if (MaybeEat(TokenKind.Multiply)) { - string starWhiteSpace = _tokenWhiteSpace; + var starWhiteSpace = _tokenWhiteSpace; start = GetStart(); - Expression t = ParseExpression(); + var t = ParseExpression(); var name = new NameExpression("*"); a = new Arg(name, t); if (_verbatim) { AddPreceedingWhiteSpace(name, starWhiteSpace); } } else if (MaybeEat(TokenKind.Power)) { - string starStarWhiteSpace = _tokenWhiteSpace; + var starStarWhiteSpace = _tokenWhiteSpace; start = GetStart(); - Expression t = ParseExpression(); + var t = ParseExpression(); var name = new NameExpression("**"); a = new Arg(name, t); if (_verbatim) { AddPreceedingWhiteSpace(name, starStarWhiteSpace); } } else { - Expression e = ParseExpression(); + var e = ParseExpression(); start = e.StartIndex; if (MaybeEat(TokenKind.Assign)) { a = FinishKeywordArgument(e); @@ -3686,9 +3621,7 @@ private Arg[] FinishArgumentList(Arg first, List commaWhiteSpace, out bo } private Expression ParseOldExpressionListAsExpr() { - bool trailingComma; - List itemWhiteSpace; - List l = ParseOldExpressionList(out trailingComma, out itemWhiteSpace); + var l = ParseOldExpressionList(out var trailingComma, out var itemWhiteSpace); // the case when no expression was parsed e.g. when we have an empty expression list if (l.Count == 0 && !trailingComma) { ReportSyntaxError("invalid syntax"); @@ -3698,11 +3631,14 @@ private Expression ParseOldExpressionListAsExpr() { // old_expression_list: old_expression [(',' old_expression)+ [',']] private List ParseOldExpressionList(out bool trailingComma, out List itemWhiteSpace) { - List l = new List(); + var l = new List(); itemWhiteSpace = MakeWhiteSpaceList(); trailingComma = false; while (true) { - if (NeverTestToken(PeekToken())) break; + if (NeverTestToken(PeekToken())) { + break; + } + l.Add(ParseOldExpression()); if (!MaybeEat(TokenKind.Comma)) { trailingComma = false; @@ -3718,12 +3654,15 @@ private List ParseOldExpressionList(out bool trailingComma, out List // expression_list: expression (',' expression)* [','] private List ParseExpressionList(out bool trailingComma, out List whitespace) { - List l = new List(); + var l = new List(); trailingComma = false; whitespace = MakeWhiteSpaceList(); while (true) { - if (NeverTestToken(PeekToken())) break; + if (NeverTestToken(PeekToken())) { + break; + } + l.Add(ParseStarExpression()); if (!MaybeEat(TokenKind.Comma)) { trailingComma = false; @@ -3742,7 +3681,7 @@ private List ParseExpressionList(out bool trailingComma, out List itemWhiteSpace; - bool trailingComma; - List l = ParseTestListAsExpr(expr, out itemWhiteSpace, out trailingComma); + var l = ParseTestListAsExpr(expr, out var itemWhiteSpace, out var trailingComma); return MakeTupleOrExpr(l, itemWhiteSpace, trailingComma, parenFreeTuple: true); } @@ -3792,7 +3729,10 @@ private List ParseTestListAsExpr(Expression expr, out List i trailingComma = true; while (true) { - if (NeverTestToken(PeekToken())) break; + if (NeverTestToken(PeekToken())) { + break; + } + var e = ParseExpression(); l.Add(e); @@ -3814,7 +3754,7 @@ private Expression ParseTestListAsExprError() { if (MaybeEat(TokenKind.Indent)) { // the error is on the next token which has a useful location, unlike the indent - note we don't have an // indent if we're at an EOF. It'a also an indentation error instead of a syntax error. - string indentVerbatim = _verbatim ? _tokenWhiteSpace + _token.Token.VerbatimImage : null; + var indentVerbatim = _verbatim ? _tokenWhiteSpace + _token.Token.VerbatimImage : null; NextToken(); ReportSyntaxError(GetStart(), GetEnd(), "unexpected indent", ErrorCodes.IndentationError); return Error(_verbatim ? (indentVerbatim + _tokenWhiteSpace + _token.Token.VerbatimImage) : null); @@ -3827,16 +3767,18 @@ private Expression ParseTestListAsExprError() { private Expression FinishExpressionListAsExpr(Expression expr) { var start = GetStart(); - bool trailingComma = true; - List l = new List(); - List itemWhiteSpace = MakeWhiteSpaceList(); + var trailingComma = true; + var l = new List(); + var itemWhiteSpace = MakeWhiteSpaceList(); if (itemWhiteSpace != null) { itemWhiteSpace.Add(_tokenWhiteSpace); } l.Add(expr); while (true) { - if (NeverTestToken(PeekToken())) break; + if (NeverTestToken(PeekToken())) { + break; + } expr = ParseExpression(); l.Add(expr); @@ -3850,7 +3792,7 @@ private Expression FinishExpressionListAsExpr(Expression expr) { trailingComma = true; } - Expression ret = MakeTupleOrExpr(l, itemWhiteSpace, trailingComma); + var ret = MakeTupleOrExpr(l, itemWhiteSpace, trailingComma); ret.SetLoc(start, GetEnd()); return ret; } @@ -3859,9 +3801,9 @@ private Expression FinishExpressionListAsExpr(Expression expr) { // testlist_gexp: expression ( genexpr_for | (',' expression)* [','] ) // private Expression FinishTupleOrGenExp() { - string startingWhiteSpace = _tokenWhiteSpace; + var startingWhiteSpace = _tokenWhiteSpace; var lStart = GetStart(); - int grouping = _tokenizer.GroupingLevel; + var grouping = _tokenizer.GroupingLevel; bool hasRightParenthesis; Expression ret; @@ -3877,11 +3819,11 @@ private Expression FinishTupleOrGenExp() { ret = new ParenthesisExpression(ParseYieldExpression()); hasRightParenthesis = Eat(TokenKind.RightParenthesis); } else { - bool prevAllow = _allowIncomplete; + var prevAllow = _allowIncomplete; try { _allowIncomplete = true; - Expression expr = ParseExpression(); + var expr = ParseExpression(); if (MaybeEat(TokenKind.Comma)) { // "(" expression "," ... ret = FinishExpressionListAsExpr(expr); @@ -3923,7 +3865,7 @@ private Expression ParseGeneratorExpression(Expression expr, string rightParenWh var prevIn = _inGeneratorExpression; _inGeneratorExpression = true; try { - ComprehensionIterator[] iters = ParseCompIter(); + var iters = ParseCompIter(); ret = new GeneratorExpression(expr, iters); } finally { @@ -3935,12 +3877,11 @@ private Expression ParseGeneratorExpression(Expression expr, string rightParenWh } private static Statement NestGenExpr(Statement current, Statement nested) { - ForStatement fes = current as ForStatement; IfStatement ifs; - if (fes != null) { + if (current is ForStatement fes) { fes.Body = nested; } else if ((ifs = current as IfStatement) != null) { - ifs.TestsInternal[0].Body = nested; + ifs.Tests[0].Body = nested; } return nested; } @@ -3993,10 +3934,10 @@ private Expression FinishDictOrSetValue() { List dictMembers = null; List setMembers = null; - List itemWhiteSpace = MakeWhiteSpaceList(); - bool prevAllow = _allowIncomplete; - bool reportedError = false; - bool ateTerminator = false; + var itemWhiteSpace = MakeWhiteSpaceList(); + var prevAllow = _allowIncomplete; + var reportedError = false; + var ateTerminator = false; bool hasSequenceUnpack = false, hasDictUnpack = false; try { _allowIncomplete = true; @@ -4008,8 +3949,8 @@ private Expression FinishDictOrSetValue() { } bool isSequenceUnpack = false, isDictUnpack = false; - bool first = false; - Expression e1 = ParseExpression(); + var first = false; + var e1 = ParseExpression(); if (e1 is StarredExpression s) { if (s.StarCount == 1) { isSequenceUnpack = true; @@ -4021,12 +3962,12 @@ private Expression FinishDictOrSetValue() { } if (MaybeEat(TokenKind.Colon)) { // dict literal - string colonWhiteSpace = _tokenWhiteSpace; + var colonWhiteSpace = _tokenWhiteSpace; if (setMembers == null && dictMembers == null) { dictMembers = new List(); first = true; } - Expression e2 = ParseExpression(); + var e2 = ParseExpression(); if (!reportedError) { if (setMembers != null || hasSequenceUnpack || isSequenceUnpack || isDictUnpack) { @@ -4036,7 +3977,7 @@ private Expression FinishDictOrSetValue() { } - SliceExpression se = new SliceExpression(e1, e2, null, false); + var se = new SliceExpression(e1, e2, null, false); if (_verbatim) { AddPreceedingWhiteSpace(se, colonWhiteSpace); } @@ -4162,22 +4103,22 @@ private Expression FinishDictOrSetValue() { // comp_iter '}' private SetComprehension FinishSetComp(Expression item, out bool ateTerminator) { - ComprehensionIterator[] iters = ParseCompIter(); + var iters = ParseCompIter(); ateTerminator = Eat(TokenKind.RightBrace); return new SetComprehension(item, iters); } // comp_iter '}' private DictionaryComprehension FinishDictComp(SliceExpression value, out bool ateTerminator) { - ComprehensionIterator[] iters = ParseCompIter(); + var iters = ParseCompIter(); ateTerminator = Eat(TokenKind.RightBrace); return new DictionaryComprehension(value, iters); } // comp_iter: comp_for | comp_if private ComprehensionIterator[] ParseCompIter() { - List iters = new List(); - ComprehensionFor firstFor = ParseCompFor(); + var iters = new List(); + var firstFor = ParseCompFor(); iters.Add(firstFor); while (true) { @@ -4219,9 +4160,9 @@ private bool PeekTokenForOrAsyncForToStartGenerator { // comp_for: '[async] for target_list 'in' or_test [comp_iter] private ComprehensionFor ParseCompFor() { - bool isAsync = false; + var isAsync = false; string firstWhitespace = null, asyncWhitespace = null; - int start = -1; + var start = -1; if (MaybeEat(TokenKind.KeywordAsync)) { isAsync = true; @@ -4233,10 +4174,7 @@ private ComprehensionFor ParseCompFor() { if (start < 0) { start = GetStart(); } - - bool trailingComma; - List listWhiteSpace; - List l = ParseExpressionList(out trailingComma, out listWhiteSpace); + var l = ParseExpressionList(out var trailingComma, out var listWhiteSpace); // expr list is something like: // () @@ -4246,8 +4184,8 @@ private ComprehensionFor ParseCompFor() { // we either want just () or a or we want (a,b) and (a,b,c) // so we can do tupleExpr.EmitSet() or loneExpr.EmitSet() - Expression lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); - bool ateIn = Eat(TokenKind.KeywordIn); + var lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); + var ateIn = Eat(TokenKind.KeywordIn); string inWhiteSpace; Expression list; @@ -4259,7 +4197,7 @@ private ComprehensionFor ParseCompFor() { list = Error(""); } - ComprehensionFor ret = new ComprehensionFor(lhs, list, isAsync); + var ret = new ComprehensionFor(lhs, list, isAsync); if (_verbatim) { AddPreceedingWhiteSpace(ret, firstWhitespace); AddSecondPreceedingWhiteSpace(ret, inWhiteSpace); @@ -4277,10 +4215,10 @@ private ComprehensionFor ParseCompFor() { // listmaker: expression ( list_for | (',' expression)* [','] ) private Expression FinishListValue() { - string proceedingWhiteSpace = _tokenWhiteSpace; + var proceedingWhiteSpace = _tokenWhiteSpace; var oStart = GetStart(); - int grouping = _tokenizer.GroupingLevel; + var grouping = _tokenizer.GroupingLevel; Expression ret; bool ateRightBracket; @@ -4288,19 +4226,17 @@ private Expression FinishListValue() { ret = new ListExpression(); ateRightBracket = true; } else { - bool prevAllow = _allowIncomplete; + var prevAllow = _allowIncomplete; try { _allowIncomplete = true; /*if (MaybeEat(TokenKind.Multiply)) { // Need to produce an AST with the splatting here... }*/ - Expression t0 = ParseExpression(); + var t0 = ParseExpression(); if (MaybeEat(TokenKind.Comma)) { - string commaWhiteSpace = _tokenWhiteSpace; - bool trailingComma; - List listWhiteSpace; - var l = ParseTestListAsExpr(t0, out listWhiteSpace, out trailingComma); + var commaWhiteSpace = _tokenWhiteSpace; + var l = ParseTestListAsExpr(t0, out var listWhiteSpace, out var trailingComma); ateRightBracket = Eat(TokenKind.RightBracket); ret = new ListExpression(l.ToArray()); @@ -4333,15 +4269,15 @@ private Expression FinishListValue() { // list_iter ']' private ListComprehension FinishListComp(Expression item, out bool ateRightBracket) { - ComprehensionIterator[] iters = ParseListCompIter(); + var iters = ParseListCompIter(); ateRightBracket = Eat(TokenKind.RightBracket); return new ListComprehension(item, iters); } // list_iter: list_for | list_if private ComprehensionIterator[] ParseListCompIter() { - List iters = new List(); - ComprehensionFor firstFor = ParseListCompFor(); + var iters = new List(); + var firstFor = ParseListCompFor(); iters.Add(firstFor); @@ -4364,9 +4300,9 @@ private ComprehensionIterator[] ParseListCompIter() { // list_for: 'for' target_list 'in' old_expression_list [list_iter] private ComprehensionFor ParseListCompFor() { - bool isAsync = false; + var isAsync = false; string firstWhitespace = null, asyncWhitespace = null; - int start = -1; + var start = -1; if (MaybeEat(TokenKind.KeywordAsync)) { isAsync = true; @@ -4378,10 +4314,7 @@ private ComprehensionFor ParseListCompFor() { if (start < 0) { start = GetStart(); } - - bool trailingComma; - List listWhiteSpace; - List l = ParseExpressionList(out trailingComma, out listWhiteSpace); + var l = ParseExpressionList(out var trailingComma, out var listWhiteSpace); // expr list is something like: // () @@ -4391,8 +4324,8 @@ private ComprehensionFor ParseListCompFor() { // we either want just () or a or we want (a,b) and (a,b,c) // so we can do tupleExpr.EmitSet() or loneExpr.EmitSet() - Expression lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); - bool ateIn = Eat(TokenKind.KeywordIn); + var lhs = MakeTupleOrExpr(l, listWhiteSpace, trailingComma, true); + var ateIn = Eat(TokenKind.KeywordIn); string inWhiteSpace; Expression list; @@ -4408,7 +4341,7 @@ private ComprehensionFor ParseListCompFor() { list = Error(""); } - ComprehensionFor ret = new ComprehensionFor(lhs, list, isAsync); + var ret = new ComprehensionFor(lhs, list, isAsync); if (_verbatim) { AddPreceedingWhiteSpace(ret, firstWhitespace); if (inWhiteSpace != null) { @@ -4431,12 +4364,11 @@ private ComprehensionFor ParseListCompFor() { private ComprehensionIf ParseCompIf() { var start = GetStart(); Eat(TokenKind.KeywordIf); - string ifWhiteSpace = _tokenWhiteSpace; - Expression expr = ParseOldExpression(); + var ifWhiteSpace = _tokenWhiteSpace; + var expr = ParseOldExpression(); var end = GetEnd(); - ComprehensionIf ret = new ComprehensionIf(expr); - ret.HeaderIndex = end; + var ret = new ComprehensionIf(expr) { HeaderIndex = end }; if (_verbatim) { AddPreceedingWhiteSpace(ret, ifWhiteSpace); } @@ -4446,11 +4378,11 @@ private ComprehensionIf ParseCompIf() { private Expression FinishStringConversion() { Debug.Assert(_token.Token.Kind == TokenKind.BackQuote); - string firstWhiteSpace = _tokenWhiteSpace; + var firstWhiteSpace = _tokenWhiteSpace; Expression ret; var start = GetStart(); - Expression expr = ParseTestListAsExpr(); - bool ateBackQuote = Eat(TokenKind.BackQuote); + var expr = ParseTestListAsExpr(); + var ateBackQuote = Eat(TokenKind.BackQuote); ret = new BackQuoteExpression(expr); if (_verbatim) { AddPreceedingWhiteSpace(ret, firstWhiteSpace); @@ -4463,15 +4395,15 @@ private Expression FinishStringConversion() { return ret; } - private Expression MakeTupleOrExpr(List l, List itemWhiteSpace, bool trailingComma, bool parenFreeTuple = false) { - return MakeTupleOrExpr(l, itemWhiteSpace, trailingComma, false, parenFreeTuple); - } + private Expression MakeTupleOrExpr(List l, List itemWhiteSpace, bool trailingComma, bool parenFreeTuple = false) => MakeTupleOrExpr(l, itemWhiteSpace, trailingComma, false, parenFreeTuple); private Expression MakeTupleOrExpr(List l, List itemWhiteSpace, bool trailingComma, bool expandable, bool parenFreeTuple = false) { - if (l.Count == 1 && !trailingComma) return l[0]; + if (l.Count == 1 && !trailingComma) { + return l[0]; + } - Expression[] exprs = l.ToArray(); - TupleExpression te = new TupleExpression(expandable && !trailingComma, exprs); + var exprs = l.ToArray(); + var te = new TupleExpression(expandable && !trailingComma, exprs); if (_verbatim) { if (itemWhiteSpace != null) { AddListWhiteSpace(te, itemWhiteSpace.ToArray()); @@ -4549,12 +4481,12 @@ private void PushFunction(FunctionDefinition function) { } private CallExpression FinishCallExpr(Expression target, params Arg[] args) { - bool hasArgsTuple = false; - bool hasKeywordDict = false; - int keywordCount = 0; - int extraArgs = 0; + var hasArgsTuple = false; + var hasKeywordDict = false; + var keywordCount = 0; + var extraArgs = 0; - foreach (Arg arg in args) { + foreach (var arg in args) { if (arg.Name == null) { if (_stubFile || _langVersion >= PythonLanguageVersion.V35) { if (hasKeywordDict) { @@ -4599,7 +4531,7 @@ private CallExpression FinishCallExpr(Expression target, params Arg[] args) { private PythonAst ParseFileWorker() { StartParsing(); - List l = new List(); + var l = new List(); // // A future statement must appear near the top of the module. @@ -4613,13 +4545,11 @@ private PythonAst ParseFileWorker() { MaybeEatNewLine(); if (PeekToken(TokenKind.Constant)) { - Statement s = ParseStmt(); + var s = ParseStmt(); l.Add(s); _fromFutureAllowed = false; - ExpressionStatement es = s as ExpressionStatement; - if (es != null) { - ConstantExpression ce = es.Expression as ConstantExpression; - if (ce != null && IsString(ce)) { + if (s is ExpressionStatement es) { + if (es.Expression is ConstantExpression ce && IsString(ce)) { // doc string _fromFutureAllowed = true; } @@ -4631,10 +4561,9 @@ private PythonAst ParseFileWorker() { // from __future__ if (_fromFutureAllowed) { while (PeekToken(Tokens.KeywordFromToken)) { - Statement s = ParseStmt(); + var s = ParseStmt(); l.Add(s); - FromImportStatement fis = s as FromImportStatement; - if (fis != null && !fis.IsFromFuture) { + if (s is FromImportStatement fis && !fis.IsFromFuture) { // end of from __future__ break; } @@ -4645,16 +4574,21 @@ private PythonAst ParseFileWorker() { _fromFutureAllowed = false; while (true) { - if (MaybeEatEof()) break; - if (MaybeEatNewLine()) continue; + if (MaybeEatEof()) { + break; + } - Statement s = ParseStmt(); + if (MaybeEatNewLine()) { + continue; + } + + var s = ParseStmt(); l.Add(s); } - Statement[] stmts = l.ToArray(); + var stmts = l.ToArray(); - SuiteStatement ret = new SuiteStatement(stmts); + var ret = new SuiteStatement(stmts); AddIsAltForm(ret); if (_token.Token != null) { ret.SetLoc(0, GetEndForStatement()); @@ -4717,7 +4651,7 @@ private Statement InternalParseInteractiveInput(out bool parsingMultiLineCmpdStm private Expression ParseTestListAsExpression() { StartParsing(); - Expression expression = ParseTestListAsExpr(); + var expression = ParseTestListAsExpr(); EatEndOfInput(); return expression; } @@ -4737,9 +4671,8 @@ private Expression ParseTestListAsExpression() { /// when we're parsing in verbatim mode. /// private bool MaybeEatNewLine() { - string curWhiteSpace = ""; - string newWhiteSpace; - if (MaybeEatNewLine(out newWhiteSpace)) { + var curWhiteSpace = string.Empty; + if (MaybeEatNewLine(out var newWhiteSpace)) { if (_verbatim) { _lookaheadWhiteSpace = curWhiteSpace + newWhiteSpace + _lookaheadWhiteSpace; } @@ -4749,7 +4682,7 @@ private bool MaybeEatNewLine() { } private bool MaybeEatNewLine(out string whitespace) { - whitespace = _verbatim ? "" : null; + whitespace = _verbatim ? string.Empty : null; if (MaybeEat(TokenKind.NewLine)) { if (whitespace != null) { whitespace += _tokenWhiteSpace + _token.Token.VerbatimImage; @@ -4768,14 +4701,14 @@ private bool MaybeEatNewLine(out string whitespace) { /// Eats a new line token throwing if the next token isn't a new line. /// /// Python always tokenizes to have only 1 new line character in a - /// row. But we also craete NLToken's and ignore them except for + /// row. But we also create NLToken's and ignore them except for /// error reporting purposes. This gives us the same errors as /// CPython and also matches the behavior of the standard library /// tokenize module. This function eats any present NL tokens and throws /// them away. /// private bool EatNewLine(out string whitespace) { - whitespace = _verbatim ? "" : null; + whitespace = _verbatim ? string.Empty : null; if (Eat(TokenKind.NewLine)) { if (whitespace != null) { whitespace += _tokenWhiteSpace + _token.Token.VerbatimImage; @@ -4796,30 +4729,27 @@ private Token EatEndOfInput() { ; } - Token t = NextToken(); + var t = NextToken(); if (t.Kind != TokenKind.EndOfFile) { ReportSyntaxError(_token); } return t; } - private bool TrueDivision { - get { return (_languageFeatures & FutureOptions.TrueDivision) == FutureOptions.TrueDivision; } - } + private bool TrueDivision => (_languageFeatures & FutureOptions.TrueDivision) == FutureOptions.TrueDivision; - private bool AbsoluteImports { - get { return (_languageFeatures & FutureOptions.AbsoluteImports) == FutureOptions.AbsoluteImports; } - } + private bool AbsoluteImports => (_languageFeatures & FutureOptions.AbsoluteImports) == FutureOptions.AbsoluteImports; private void StartParsing() { - if (_parsingStarted) + if (_parsingStarted) { throw new InvalidOperationException("Parsing already started. Use Restart to start again."); + } _parsingStarted = true; FetchLookahead(); - string whitespace = _verbatim ? "" : null; + var whitespace = _verbatim ? "" : null; while (PeekToken().Kind == TokenKind.NLToken) { NextToken(); @@ -4855,9 +4785,7 @@ private Token NextToken() { return _token.Token; } - private Token PeekToken() { - return _lookahead.Token; - } + private Token PeekToken() => _lookahead.Token; private Token PeekToken2() { if (_lookahead2.Token == null) { @@ -4879,16 +4807,12 @@ private void FetchLookahead() { } } - private bool PeekToken(TokenKind kind) { - return PeekToken().Kind == kind; - } + private bool PeekToken(TokenKind kind) => PeekToken().Kind == kind; - private bool PeekToken(Token check) { - return PeekToken() == check; - } + private bool PeekToken(Token check) => PeekToken() == check; private bool Eat(TokenKind kind) { - Token next = PeekToken(); + var next = PeekToken(); if (next.Kind != kind) { ReportSyntaxError(_lookahead); return false; @@ -4899,7 +4823,7 @@ private bool Eat(TokenKind kind) { } private bool EatNoEof(TokenKind kind) { - Token next = PeekToken(); + var next = PeekToken(); if (next.Kind != kind) { ReportSyntaxError(_lookahead.Token, _lookahead.Span, ErrorCodes.SyntaxError, false); return false; @@ -4960,9 +4884,7 @@ public static TextReader ReadStreamWithEncoding(Stream stream, PythonLanguageVer /// /// New in 1.1. /// - public static Encoding GetEncodingFromStream(Stream stream) { - return GetStreamReaderWithEncoding(stream, new UTF8Encoding(false), ErrorSink.Null).CurrentEncoding; - } + public static Encoding GetEncodingFromStream(Stream stream) => GetStreamReaderWithEncoding(stream, new UTF8Encoding(false), ErrorSink.Null).CurrentEncoding; /// /// Fetches encoding specified in the magic comment as per @@ -5011,33 +4933,30 @@ public static void GetEncodingFromMagicDesignator(string text, out Encoding enco // Python 2.x should pass ASCII as the default // Python 3.x should pass UTF-8 // A BOM or encoding comment can override the default - Encoding encoding = defaultEncoding; + var encoding = defaultEncoding; - List readBytes = new List(); + var readBytes = new List(); try { - byte[] bomBuffer = new byte[3]; - int bomRead = stream.Read(bomBuffer, 0, 3); - int bytesRead = 0; - bool isUtf8 = false; + var bomBuffer = new byte[3]; + var bomRead = stream.Read(bomBuffer, 0, 3); + var bytesRead = 0; + var isUtf8 = false; if (bomRead == 3 && (bomBuffer[0] == 0xef && bomBuffer[1] == 0xbb && bomBuffer[2] == 0xbf)) { isUtf8 = true; bytesRead = 3; readBytes.AddRange(bomBuffer); } else { - for (int i = 0; i < bomRead; i++) { + for (var i = 0; i < bomRead; i++) { readBytes.Add(bomBuffer[i]); } } - int lineLength; - string line = ReadOneLine(readBytes, ref bytesRead, stream, out lineLength); + var line = ReadOneLine(readBytes, ref bytesRead, stream, out var lineLength); bool? gotEncoding = false; - string encodingName = null; // magic encoding must be on line 1 or 2 - int lineNo = 1; - int encodingIndex = 0; - if ((gotEncoding = TryGetEncoding(line, ref encoding, out encodingName, out encodingIndex)) == false) { + var lineNo = 1; + if ((gotEncoding = TryGetEncoding(line, ref encoding, out var encodingName, out var encodingIndex)) == false) { var prevLineLength = lineLength; line = ReadOneLine(readBytes, ref bytesRead, stream, out lineLength); lineNo = 2; @@ -5089,7 +5008,7 @@ public static void GetEncodingFromMagicDesignator(string text, out Encoding enco } private static NewLineLocation[] GetEncodingLineNumbers(IList readBytes) { - NewLineLocation[] lineNos = new NewLineLocation[2]; + var lineNos = new NewLineLocation[2]; for (int i = 0, lineCount = 0; i < readBytes.Count && lineCount < 2; i++) { if (readBytes[i] == '\r') { if (i + 1 < readBytes.Count && readBytes[i + 1] == '\n') { @@ -5116,8 +5035,13 @@ private static NewLineLocation[] GetEncodingLineNumbers(IList readBytes) { // minimum length is 18 encName = null; index = 0; - if (line.Length < 10) return false; - if (line[0] != '#') return false; + if (line.Length < 10) { + return false; + } + + if (line[0] != '#') { + return false; + } // we have magic comment line if (_codingRegex == null) { @@ -5145,8 +5069,7 @@ private static NewLineLocation[] GetEncodingLineNumbers(IList readBytes) { internal static bool TryGetEncoding(string name, out Encoding encoding) { name = NormalizeEncodingName(name); - EncodingInfoWrapper encInfo; - if (CodecsInfo.Codecs.TryGetValue(name, out encInfo)) { + if (CodecsInfo.Codecs.TryGetValue(name, out var encInfo)) { encoding = (Encoding)encInfo.GetEncoding().Clone(); return true; } @@ -5159,10 +5082,10 @@ static class CodecsInfo { public static readonly Dictionary Codecs = MakeCodecsDict(); private static Dictionary MakeCodecsDict() { - Dictionary d = new Dictionary(); - EncodingInfo[] encs = Encoding.GetEncodings(); - for (int i = 0; i < encs.Length; i++) { - string normalizedName = NormalizeEncodingName(encs[i].Name); + var d = new Dictionary(); + var encs = Encoding.GetEncodings(); + for (var i = 0; i < encs.Length; i++) { + var normalizedName = NormalizeEncodingName(encs[i].Name); // setup well-known mappings, for everything // else we'll store as lower case w/ _ @@ -5263,7 +5186,7 @@ private static Dictionary MakeCodecsDict() { #if DEBUG // all codecs should be stored in lowercase because we only look up from lowercase strings - foreach (KeyValuePair kvp in d) { + foreach (var kvp in d) { Debug.Assert(kvp.Key.ToLowerInvariant() == kvp.Key); } #endif @@ -5271,16 +5194,12 @@ private static Dictionary MakeCodecsDict() { } } - class EncodingInfoWrapper { + private class EncodingInfoWrapper { private EncodingInfo _info; private Encoding _encoding; - private byte[] _preamble; - - public EncodingInfoWrapper(Encoding enc) { - _encoding = enc; - } + private readonly byte[] _preamble; - public EncodingInfoWrapper(EncodingInfo info) { + protected EncodingInfoWrapper(EncodingInfo info) { _info = info; } @@ -5289,15 +5208,10 @@ public EncodingInfoWrapper(EncodingInfo info, byte[] preamble) { _preamble = preamble; } - public virtual Encoding GetEncoding() { - if (_encoding != null) return _encoding; - - if (_preamble == null) { - return _info.GetEncoding(); - } - - return new EncodingWrapper(_info.GetEncoding(), _preamble); - } + public virtual Encoding GetEncoding() + => _encoding ?? (_encoding = _preamble == null + ? _info.GetEncoding() + : new EncodingWrapper(_info.GetEncoding(), _preamble)); public static implicit operator EncodingInfoWrapper(EncodingInfo info) { return new EncodingInfoWrapper(info); @@ -5305,47 +5219,26 @@ public static implicit operator EncodingInfoWrapper(EncodingInfo info) { } class AsciiEncodingInfoWrapper : EncodingInfoWrapper { - public AsciiEncodingInfoWrapper() - : base((EncodingInfo)null) { + public AsciiEncodingInfoWrapper() : base(null) { } public override Encoding GetEncoding() => Encoding.ASCII; } class EncodingWrapper : Encoding { - private byte[] _preamble; + private readonly byte[] _preamble; private Encoding _encoding; - public EncodingWrapper(Encoding encoding, byte[] preamable) { - _preamble = preamable; + public EncodingWrapper(Encoding encoding, byte[] preamble) { + _preamble = preamble; _encoding = encoding; } - private void SetEncoderFallback() { - _encoding.EncoderFallback = EncoderFallback; - } - - private void SetDecoderFallback() { - _encoding.DecoderFallback = DecoderFallback; - } - - public override int CodePage { - get { - return _encoding.CodePage; - } - } - - public override string EncodingName { - get { - return _encoding.EncodingName; - } - } - - public override string WebName { - get { - return _encoding.WebName; - } - } + private void SetEncoderFallback() => _encoding.EncoderFallback = EncoderFallback; + private void SetDecoderFallback() => _encoding.DecoderFallback = DecoderFallback; + public override int CodePage => _encoding.CodePage; + public override string EncodingName => _encoding.EncodingName; + public override string WebName => _encoding.WebName; public override int GetByteCount(char[] chars, int index, int count) { SetEncoderFallback(); @@ -5377,9 +5270,7 @@ public override int GetMaxCharCount(int byteCount) { return _encoding.GetMaxCharCount(byteCount); } - public override byte[] GetPreamble() { - return _preamble; - } + public override byte[] GetPreamble() => _preamble; public override Encoder GetEncoder() { SetEncoderFallback(); @@ -5393,34 +5284,30 @@ public override Decoder GetDecoder() { public override object Clone() { // need to call base.Clone to be marked as read/write - EncodingWrapper res = (EncodingWrapper)base.Clone(); + var res = (EncodingWrapper)base.Clone(); res._encoding = (Encoding)_encoding.Clone(); return res; } } - internal static string NormalizeEncodingName(string name) { - if (name == null) { - return null; - } - return name.ToLowerInvariant().Replace('-', '_').Replace(' ', '_'); - } + internal static string NormalizeEncodingName(string name) + => name?.ToLowerInvariant().Replace('-', '_').Replace(' ', '_'); /// /// Reads one line keeping track of the # of bytes read and saving the bytes that were read /// private static string ReadOneLine(List previewedBytes, ref int curIndex, Stream reader, out int lineLength) { lineLength = 0; - byte[] buffer = new byte[256]; - int bufferReadCount = reader.Read(buffer, 0, buffer.Length); - for (int i = 0; i < bufferReadCount; i++) { + var buffer = new byte[256]; + var bufferReadCount = reader.Read(buffer, 0, buffer.Length); + for (var i = 0; i < bufferReadCount; i++) { previewedBytes.Add(buffer[i]); } - int startIndex = curIndex; + var startIndex = curIndex; do { - for (int i = curIndex; i < previewedBytes.Count; i++) { - bool foundEnd = false; + for (var i = curIndex; i < previewedBytes.Count; i++) { + var foundEnd = false; if (previewedBytes[i] == '\r') { if (i + 1 < previewedBytes.Count) { @@ -5448,7 +5335,7 @@ private static string ReadOneLine(List previewedBytes, ref int curIndex, S } bufferReadCount = reader.Read(buffer, 0, buffer.Length); - for (int i = 0; i < bufferReadCount; i++) { + for (var i = 0; i < bufferReadCount; i++) { previewedBytes.Add(buffer[i]); } } while (bufferReadCount != 0); @@ -5466,13 +5353,10 @@ private static string ReadOneLine(List previewedBytes, ref int curIndex, S #region Verbatim AST support - private void AddPreceedingWhiteSpace(Node ret) { - AddPreceedingWhiteSpace(ret, _tokenWhiteSpace); - } + private void AddPreceedingWhiteSpace(Node ret) => AddPreceedingWhiteSpace(ret, _tokenWhiteSpace); private Dictionary GetNodeAttributes(Node node) { - Dictionary attrs; - if (!_attributes.TryGetValue(node, out attrs)) { + if (!_attributes.TryGetValue(node, out var attrs)) { _attributes[node] = attrs = new Dictionary(); } return attrs; @@ -5490,9 +5374,7 @@ private void AddVerbatimImage(Node ret, string image) { } } - private List MakeWhiteSpaceList() { - return _verbatim ? new List() : null; - } + private List MakeWhiteSpaceList() => _verbatim ? new List() : null; private void AddPreceedingWhiteSpace(Node ret, string whiteSpace) { Debug.Assert(_verbatim); @@ -5541,21 +5423,15 @@ private void AddVerbatimNames(Node ret, string[] names) { GetNodeAttributes(ret)[NodeAttributes.VerbatimNames] = names; } - private void AddIsAltForm(Node expr) { - GetNodeAttributes(expr)[NodeAttributes.IsAltFormValue] = NodeAttributes.IsAltFormValue; - } + private void AddIsAltForm(Node expr) => GetNodeAttributes(expr)[NodeAttributes.IsAltFormValue] = NodeAttributes.IsAltFormValue; - private void AddErrorMissingCloseGrouping(Node expr) { - GetNodeAttributes(expr)[NodeAttributes.ErrorMissingCloseGrouping] = NodeAttributes.ErrorMissingCloseGrouping; - } + private void AddErrorMissingCloseGrouping(Node expr) => GetNodeAttributes(expr)[NodeAttributes.ErrorMissingCloseGrouping] = NodeAttributes.ErrorMissingCloseGrouping; - private void AddErrorIsIncompleteNode(Node expr) { - GetNodeAttributes(expr)[NodeAttributes.ErrorIncompleteNode] = NodeAttributes.ErrorIncompleteNode; - } + private void AddErrorIsIncompleteNode(Node expr) => GetNodeAttributes(expr)[NodeAttributes.ErrorIncompleteNode] = NodeAttributes.ErrorIncompleteNode; private void MoveNodeAttributes(Node target, Node source, object key) { var s = GetNodeAttributes(source); - if (s.TryGetValue(key, out object o)) { + if (s.TryGetValue(key, out var o)) { GetNodeAttributes(target)[key] = o; s.Remove(key); } diff --git a/src/Analysis/Engine/Impl/Parsing/ParserOptions.cs b/src/Parsing/Impl/ParserOptions.cs similarity index 85% rename from src/Analysis/Engine/Impl/Parsing/ParserOptions.cs rename to src/Parsing/Impl/ParserOptions.cs index e3ce39331..4c798e97b 100644 --- a/src/Analysis/Engine/Impl/Parsing/ParserOptions.cs +++ b/src/Parsing/Impl/ParserOptions.cs @@ -9,23 +9,22 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public sealed class ParserOptions { - internal static ParserOptions Default = new ParserOptions(); + public static ParserOptions Default = new ParserOptions(); public ParserOptions() { ErrorSink = ErrorSink.Null; } - public ParserOptions Clone() { - return (ParserOptions)MemberwiseClone(); - } + public ParserOptions Clone() => (ParserOptions)MemberwiseClone(); public ErrorSink ErrorSink { get; set; } @@ -57,12 +56,7 @@ public ParserOptions Clone() { /// public event EventHandler ProcessComment; - internal void RaiseProcessComment(object sender, CommentEventArgs e) { - var handler = ProcessComment; - if (handler != null) { - handler(sender, e); - } - } + internal void RaiseProcessComment(object sender, CommentEventArgs e) => ProcessComment?.Invoke(sender, e); } public class CommentEventArgs : EventArgs { diff --git a/src/Analysis/Engine/Impl/Parsing/PartiallyReadStream.cs b/src/Parsing/Impl/PartiallyReadStream.cs similarity index 73% rename from src/Analysis/Engine/Impl/Parsing/PartiallyReadStream.cs rename to src/Parsing/Impl/PartiallyReadStream.cs index fd9108c91..81e118df9 100644 --- a/src/Analysis/Engine/Impl/Parsing/PartiallyReadStream.cs +++ b/src/Parsing/Impl/PartiallyReadStream.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,12 +19,12 @@ using System.IO; using System.Linq; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// Creates a stream out of a some bytes we've read and the stream we read them from. This allows us to /// not require a seekable stream for our parser. /// - class PartiallyReadStream : Stream { + internal class PartiallyReadStream : Stream { private readonly byte[] _readBytes; private readonly Stream _stream; private long _position; @@ -41,25 +41,11 @@ protected override void Dispose(bool disposing) { } } - public override bool CanRead { - get { return true; } - } - - public override bool CanSeek { - get { return false; } - } - - public override bool CanWrite { - get { return false; } - } - - public override void Flush() { - throw new InvalidOperationException(); - } - - public override long Length { - get { return _stream.Length; } - } + public override bool CanRead => true; + public override bool CanSeek => false; + public override bool CanWrite => false; + public override void Flush() => throw new InvalidOperationException(); + public override long Length => _stream.Length; public override long Position { get { @@ -68,17 +54,15 @@ public override long Position { } return _position; } - set { - throw new InvalidOperationException(); - } + set => throw new InvalidOperationException(); } public override int Read(byte[] buffer, int offset, int count) { if (_position == -1) { return _stream.Read(buffer, offset, count); } else { - int bytesRead = 0; - for (int i = 0; i < count && _position < _readBytes.Length; i++) { + var bytesRead = 0; + for (var i = 0; i < count && _position < _readBytes.Length; i++) { buffer[i + offset] = _readBytes[(int)_position]; _position++; bytesRead++; @@ -98,16 +82,8 @@ public override int Read(byte[] buffer, int offset, int count) { } } - public override long Seek(long offset, SeekOrigin origin) { - throw new InvalidOperationException(); - } - - public override void SetLength(long value) { - throw new InvalidOperationException(); - } - - public override void Write(byte[] buffer, int offset, int count) { - throw new InvalidOperationException(); - } + public override long Seek(long offset, SeekOrigin origin) => throw new InvalidOperationException(); + public override void SetLength(long value) => throw new InvalidOperationException(); + public override void Write(byte[] buffer, int offset, int count) => throw new InvalidOperationException(); } } diff --git a/src/Analysis/Engine/Impl/Parsing/PythonLanguageVersion.cs b/src/Parsing/Impl/PythonLanguageVersion.cs similarity index 80% rename from src/Analysis/Engine/Impl/Parsing/PythonLanguageVersion.cs rename to src/Parsing/Impl/PythonLanguageVersion.cs index 2ec7b5c63..5c3142c0f 100644 --- a/src/Analysis/Engine/Impl/Parsing/PythonLanguageVersion.cs +++ b/src/Parsing/Impl/PythonLanguageVersion.cs @@ -9,15 +9,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// Specifies the version of the Python language to be used for parsing. /// @@ -41,27 +41,17 @@ public enum PythonLanguageVersion { } public static class PythonLanguageVersionExtensions { - public static bool Is2x(this PythonLanguageVersion version) { - return (((int)version >> 8) & 0xff) == 2; - } - - public static bool Is3x(this PythonLanguageVersion version) { - return (((int)version >> 8) & 0xff) == 3; - } - - public static bool IsNone(this PythonLanguageVersion version) { - return version == PythonLanguageVersion.None; - } + public static bool Is2x(this PythonLanguageVersion version) => (((int)version >> 8) & 0xff) == 2; + public static bool Is3x(this PythonLanguageVersion version) => (((int)version >> 8) & 0xff) == 3; + public static bool IsNone(this PythonLanguageVersion version) => version == PythonLanguageVersion.None; public static bool IsImplicitNamespacePackagesSupported(this PythonLanguageVersion version) => version >= PythonLanguageVersion.V33; - public static Version ToVersion(this PythonLanguageVersion version) { - return new Version(((int)version) >> 8, ((int)version) & 0xff); - } + public static Version ToVersion(this PythonLanguageVersion version) => new Version(((int)version) >> 8, ((int)version) & 0xff); public static PythonLanguageVersion ToLanguageVersion(this Version version) { - int value = (version.Major << 8) + version.Minor; + var value = (version.Major << 8) + version.Minor; if (Enum.IsDefined(typeof(PythonLanguageVersion), value)) { return (PythonLanguageVersion)value; } diff --git a/src/Parsing/Impl/Resources.Designer.cs b/src/Parsing/Impl/Resources.Designer.cs new file mode 100644 index 000000000..3c5eeb9cb --- /dev/null +++ b/src/Parsing/Impl/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Microsoft.PythonTools.Core { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.PythonTools.Core.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/src/Parsing/Impl/Resources.resx b/src/Parsing/Impl/Resources.resx new file mode 100644 index 000000000..4fdb1b6af --- /dev/null +++ b/src/Parsing/Impl/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/Analysis/Engine/Impl/Parsing/Severity.cs b/src/Parsing/Impl/Severity.cs similarity index 90% rename from src/Analysis/Engine/Impl/Parsing/Severity.cs rename to src/Parsing/Impl/Severity.cs index 6a3b3f711..cbd401399 100644 --- a/src/Analysis/Engine/Impl/Parsing/Severity.cs +++ b/src/Parsing/Impl/Severity.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public enum Severity { Ignore, Warning, diff --git a/src/Analysis/Engine/Impl/Parsing/SourceCodeKind.cs b/src/Parsing/Impl/SourceCodeKind.cs similarity index 95% rename from src/Analysis/Engine/Impl/Parsing/SourceCodeKind.cs rename to src/Parsing/Impl/SourceCodeKind.cs index 1ae4adbcd..71473c8d2 100644 --- a/src/Analysis/Engine/Impl/Parsing/SourceCodeKind.cs +++ b/src/Parsing/Impl/SourceCodeKind.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.ComponentModel; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// Defines a kind of the source code. The parser sets its initial state accordingly. diff --git a/src/Parsing/Impl/Token.cs b/src/Parsing/Impl/Token.cs new file mode 100644 index 000000000..494f7e3b5 --- /dev/null +++ b/src/Parsing/Impl/Token.cs @@ -0,0 +1,202 @@ +// Python Tools for Visual Studio +// Copyright(c) Microsoft Corporation +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the License); you may not use +// this file except in compliance with the License. You may obtain a copy of the +// License at http://www.apache.org/licenses/LICENSE-2.0 +// +// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS +// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY +// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, +// MERCHANTABILITY OR NON-INFRINGEMENT. +// +// See the Apache Version 2.0 License for specific language governing +// permissions and limitations under the License. + +using System; +using Microsoft.Python.Core.Text; + +namespace Microsoft.Python.Parsing { + public struct TokenWithSpan { + public static readonly TokenWithSpan Empty = new TokenWithSpan(); + + public TokenWithSpan(Token token, IndexSpan span) { + Token = token; + Span = span; + } + + public IndexSpan Span { get; } + public Token Token { get; } + } + + /// + /// Summary description for Token. + /// + public abstract class Token { + public Token(TokenKind kind) { + Kind = kind; + } + + public TokenKind Kind { get; } + + public virtual object Value => throw new NotSupportedException("no value for this token"); + + public override string ToString() => base.ToString() + "(" + Kind + ")"; + + /// + /// Returns the exact text of the token if it's available. The text does not + /// include any leading white space. + /// + public virtual string VerbatimImage => Image; + + /// + /// Returns a user friendly display of the token. + /// + public abstract string Image { + get; + } + } + + public class ErrorToken : Token { + public ErrorToken(string message, string verbatim) + : base(TokenKind.Error) { + Message = message; + VerbatimImage = verbatim; + } + + public string Message { get; } + + public override string Image => Message; + + public override object Value => Message; + + public override string VerbatimImage { get; } + } + + public class IncompleteStringErrorToken : ErrorToken { + private readonly string _value; + + public IncompleteStringErrorToken(string message, string value) + : base(message, value) { + _value = value; + } + + public override string Image => _value; + + public override object Value => _value; + } + + public class ConstantValueToken : Token { + public ConstantValueToken(object value) + : base(TokenKind.Constant) { + Value = value; + } + + public object Constant => Value; + + public override object Value { get; } + + public override string Image => Value == null ? "None" : Value.ToString(); + } + + public sealed class VerbatimConstantValueToken : ConstantValueToken { + public VerbatimConstantValueToken(object value, string verbatim) + : base(value) { + VerbatimImage = verbatim; + } + + public override string VerbatimImage { get; } + } + + public class UnicodeStringToken : ConstantValueToken { + public UnicodeStringToken(object value) + : base(value) { + } + } + + public sealed class VerbatimUnicodeStringToken : UnicodeStringToken { + public VerbatimUnicodeStringToken(object value, string verbatim) + : base(value) { + VerbatimImage = verbatim; + } + + public override string VerbatimImage { get; } + } + + public sealed class CommentToken : Token { + public CommentToken(string comment) + : base(TokenKind.Comment) { + Comment = comment; + } + + public string Comment { get; } + public override string Image => Comment; + public override object Value => Comment; + } + + public class NameToken : Token { + public NameToken(string name) + : base(TokenKind.Name) { + Name = name; + } + + public string Name { get; } + + public override object Value => Name; + + public override string Image => Name; + } + + public sealed class OperatorToken : Token { + public OperatorToken(TokenKind kind, string image, int precedence) + : base(kind) { + Image = image; + Precedence = precedence; + } + + public int Precedence { get; } + + public override object Value => Image; + + public override string Image { get; } + } + + public class SymbolToken : Token { + public SymbolToken(TokenKind kind, string image) + : base(kind) { + Image = image; + } + + public string Symbol => Image; + + public override object Value => Image; + + public override string Image { get; } + } + + public sealed class StatementSymbolToken : SymbolToken { + public StatementSymbolToken(TokenKind kind, string image) + : base(kind, image) { + } + } + + public class VerbatimToken : SymbolToken { + public VerbatimToken(TokenKind kind, string verbatimImage, string image) + : base(kind, image) { + VerbatimImage = verbatimImage; + } + + public override string VerbatimImage { get; } + } + + public class DentToken : SymbolToken { + public DentToken(TokenKind kind, string image) + : base(kind, image) { + } + + public override string VerbatimImage => + // indents are accounted for in whitespace + ""; + } +} diff --git a/src/Analysis/Engine/Impl/Parsing/TokenCategory.cs b/src/Parsing/Impl/TokenCategory.cs similarity index 97% rename from src/Analysis/Engine/Impl/Parsing/TokenCategory.cs rename to src/Parsing/Impl/TokenCategory.cs index c71b82961..74161b04a 100644 --- a/src/Analysis/Engine/Impl/Parsing/TokenCategory.cs +++ b/src/Parsing/Impl/TokenCategory.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { public enum TokenCategory { None, diff --git a/src/Analysis/Engine/Impl/Parsing/TokenInfo.cs b/src/Parsing/Impl/TokenInfo.cs similarity index 51% rename from src/Analysis/Engine/Impl/Parsing/TokenInfo.cs rename to src/Parsing/Impl/TokenInfo.cs index 4b73de571..def66b8dd 100644 --- a/src/Analysis/Engine/Impl/Parsing/TokenInfo.cs +++ b/src/Parsing/Impl/TokenInfo.cs @@ -9,54 +9,35 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes")] // TODO: fix [Serializable] public struct TokenInfo : IEquatable { - private TokenCategory _category; - private TokenTriggers _trigger; - private SourceSpan _span; - - public TokenCategory Category { - get { return _category; } - set { _category = value; } - } - - public TokenTriggers Trigger { - get { return _trigger; } - set { _trigger = value; } - } - - public SourceSpan SourceSpan { - get { return _span; } - set { _span = value; } - } + public TokenCategory Category { get; set; } + public TokenTriggers Trigger { get; set; } + public SourceSpan SourceSpan { get; set; } internal TokenInfo(SourceSpan span, TokenCategory category, TokenTriggers trigger) { - _category = category; - _trigger = trigger; - _span = span; + Category = category; + Trigger = trigger; + SourceSpan = span; } #region IEquatable Members - - public bool Equals(TokenInfo other) { - return _category == other._category && _trigger == other._trigger && _span == other._span; - } - + public bool Equals(TokenInfo other) + => Category == other.Category && Trigger == other.Trigger && SourceSpan == other.SourceSpan; #endregion - public override string ToString() { - return "TokenInfo: {0}, {1}, {2}".FormatInvariant(_span, _category, _trigger); - } + public override string ToString() => "TokenInfo: {0}, {1}, {2}".FormatInvariant(SourceSpan, Category, Trigger); } } diff --git a/src/Analysis/Engine/Impl/Parsing/TokenKind.Generated.cs b/src/Parsing/Impl/TokenKind.Generated.cs similarity index 99% rename from src/Analysis/Engine/Impl/Parsing/TokenKind.Generated.cs rename to src/Parsing/Impl/TokenKind.Generated.cs index bb181fdf6..0d18572eb 100644 --- a/src/Analysis/Engine/Impl/Parsing/TokenKind.Generated.cs +++ b/src/Parsing/Impl/TokenKind.Generated.cs @@ -9,12 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Dedent")] public enum TokenKind { @@ -129,10 +129,10 @@ public enum TokenKind { KeywordAwait = 115 } - internal static class Tokens { - public static readonly Token EndOfFileToken = new VerbatimToken(TokenKind.EndOfFile, "", ""); + public static class Tokens { + public static readonly Token EndOfFileToken = new VerbatimToken(TokenKind.EndOfFile, string.Empty, ""); - public static readonly Token ImpliedNewLineToken = new VerbatimToken(TokenKind.NewLine, "", ""); + public static readonly Token ImpliedNewLineToken = new VerbatimToken(TokenKind.NewLine, string.Empty, ""); public static readonly Token NewLineToken = new VerbatimToken(TokenKind.NewLine, "\n", ""); public static readonly Token NewLineTokenCRLF = new VerbatimToken(TokenKind.NewLine, "\r\n", ""); diff --git a/src/Analysis/Engine/Impl/Parsing/TokenTriggers.cs b/src/Parsing/Impl/TokenTriggers.cs similarity index 92% rename from src/Analysis/Engine/Impl/Parsing/TokenTriggers.cs rename to src/Parsing/Impl/TokenTriggers.cs index 19e6aa494..70a45ddb2 100644 --- a/src/Analysis/Engine/Impl/Parsing/TokenTriggers.cs +++ b/src/Parsing/Impl/TokenTriggers.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// See also Microsoft.VisualStudio.Package.TokenTriggers. diff --git a/src/Analysis/Engine/Impl/Parsing/Tokenizer.cs b/src/Parsing/Impl/Tokenizer.cs similarity index 90% rename from src/Analysis/Engine/Impl/Parsing/Tokenizer.cs rename to src/Parsing/Impl/Tokenizer.cs index e7b104800..2582b6fc3 100644 --- a/src/Analysis/Engine/Impl/Parsing/Tokenizer.cs +++ b/src/Parsing/Impl/Tokenizer.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -22,13 +22,12 @@ using System.Diagnostics.Contracts; using System.Globalization; using System.IO; -using System.Linq; using System.Numerics; -using System.Runtime.CompilerServices; using System.Text; -using Microsoft.PythonTools.Analysis.Infrastructure; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { /// /// IronPython tokenizer @@ -41,7 +40,6 @@ public sealed partial class Tokenizer { private SourceCodeKind _kind = SourceCodeKind.AutoDetect; private ErrorSink _errors; private Severity _indentationInconsistencySeverity; - private bool _endContinues, _printFunction, _unicodeLiterals, _withStatement; private List _newLineLocations; private List _commentLocations; private SourceLocation _initialLocation; @@ -55,12 +53,12 @@ public sealed partial class Tokenizer { private const int EOF = -1; private const int MaxIndent = 80; - internal const int DefaultBufferCapacity = 1024; + public const int DefaultBufferCapacity = 1024; private readonly Dictionary _names; private static object _nameFromBuffer = new object(); - // precalcuated strings for space indentation strings so we usually don't allocate. + // pre-calculated strings for space indentation strings so we usually don't allocate. private static readonly string[] SpaceIndentation, TabIndentation; public Tokenizer(PythonLanguageVersion version, ErrorSink errorSink = null, TokenizerOptions options = TokenizerOptions.None) @@ -71,8 +69,8 @@ public Tokenizer(PythonLanguageVersion version, ErrorSink errorSink, TokenizerOp _errors = errorSink ?? ErrorSink.Null; _commentProcessor = commentProcessor; _state = new State(options); - _printFunction = false; - _unicodeLiterals = false; + PrintFunction = false; + UnicodeLiterals = false; _names = new Dictionary(new TokenEqualityComparer(this)); _langVersion = version; _options = options; @@ -80,26 +78,18 @@ public Tokenizer(PythonLanguageVersion version, ErrorSink errorSink, TokenizerOp static Tokenizer() { SpaceIndentation = new String[80]; - for (int i = 0; i < 80; i++) { + for (var i = 0; i < 80; i++) { SpaceIndentation[i] = new string(' ', i + 1); } TabIndentation = new String[10]; - for (int i = 0; i < 10; i++) { + for (var i = 0; i < 10; i++) { TabIndentation[i] = new string('\t', i + 1); } } - public bool Verbatim { - get { - return (_options & TokenizerOptions.Verbatim) != 0; - } - } + public bool Verbatim => (_options & TokenizerOptions.Verbatim) != 0; - public PythonLanguageVersion LanguageVersion { - get { - return _langVersion; - } - } + public PythonLanguageVersion LanguageVersion => _langVersion; private bool StubFile => _options.HasFlag(TokenizerOptions.StubFile); @@ -115,12 +105,12 @@ public PythonLanguageVersion LanguageVersion { /// Tokens are read until at least given amount of characters is read or the stream ends. /// A enumeration of tokens. public List ReadTokens(int characterCount) { - List tokens = new List(); + var tokens = new List(); - int start = CurrentPosition.Index; + var start = CurrentPosition.Index; while (CurrentPosition.Index - start < characterCount) { - TokenInfo token = ReadToken(); + var token = ReadToken(); if (token.Category == TokenCategory.EndOfStream) { break; } @@ -135,7 +125,7 @@ public List ReadTokens(int characterCount) { public SourceLocation CurrentPosition => IndexToLocation(CurrentIndex); public SourceLocation IndexToLocation(int index) { - int match = _newLineLocations.BinarySearch(new NewLineLocation(index, NewLineKind.None)); + var match = _newLineLocations.BinarySearch(new NewLineLocation(index, NewLineKind.None)); if (match < 0) { // If our index = -1, it means we're on the first line. if (match == -1) { @@ -150,7 +140,7 @@ public SourceLocation IndexToLocation(int index) { } internal ErrorSink ErrorSink { - get { return _errors; } + get => _errors; set { Contract.Assert(value != null); _errors = value; @@ -158,43 +148,35 @@ internal ErrorSink ErrorSink { } internal Severity IndentationInconsistencySeverity { - get { return _indentationInconsistencySeverity; } + get => _indentationInconsistencySeverity; set { _indentationInconsistencySeverity = value; - if (value != Severity.Ignore && _state.IndentFormat == null) { _state.IndentFormat = new string[MaxIndent]; } } } - public bool IsEndOfFile { - get { - return Peek() == EOF; - } - } + public bool IsEndOfFile => Peek() == EOF; - internal IndexSpan TokenSpan { - get { - return new IndexSpan(_tokenStartIndex, _tokenEndIndex - _tokenStartIndex); - } - } + public IndexSpan TokenSpan => new IndexSpan(_tokenStartIndex, _tokenEndIndex - _tokenStartIndex); public void Initialize(TextReader sourceUnit) { Contract.Assert(sourceUnit != null); - Initialize(null, sourceUnit, SourceLocation.MinValue, DefaultBufferCapacity); } - public void Initialize(object state, TextReader reader, SourceLocation initialLocation) { - Initialize(state, reader, initialLocation, DefaultBufferCapacity); - } + public void Initialize(object state, TextReader reader, SourceLocation initialLocation) + => Initialize(state, reader, initialLocation, DefaultBufferCapacity); public void Initialize(object state, TextReader reader, SourceLocation initialLocation, int bufferCapacity) { Contract.Assert(reader != null); if (state != null) { - if (!(state is State)) throw new ArgumentException("bad state provided"); + if (!(state is State)) { + throw new ArgumentException("bad state provided"); + } + _state = new State((State)state, Verbatim); } else { _state = new State(_options); @@ -232,8 +214,8 @@ public TokenInfo ReadToken() { throw new InvalidOperationException("Uninitialized"); } - TokenInfo result = new TokenInfo(); - Token token = GetNextToken(); + var result = new TokenInfo(); + var token = GetNextToken(); result.SourceSpan = new SourceSpan(IndexToLocation(TokenSpan.Start), IndexToLocation(TokenSpan.End)); switch (token.Kind) { @@ -348,7 +330,7 @@ private Token TransformStatementToken(Token token) { _state.ParenLevel = _state.BraceLevel = _state.BracketLevel = 0; // we can't possibly be in a grouping for real if we saw this token, bail... - int prevStart = _tokenStartIndex; + var prevStart = _tokenStartIndex; _position = _start; SetIndent(_state.GroupingRecovery.Spaces, _state.GroupingRecovery.Whitespace, _state.GroupingRecovery.NoAllocWhiteSpace); _tokenStartIndex = _state.GroupingRecovery.NewlineStart; @@ -359,7 +341,7 @@ private Token TransformStatementToken(Token token) { if (Verbatim) { // fixup our white space, remove the newline + any indentation from the current whitespace, add the whitespace minus the // newline to the next whitespace - int nextWhiteSpaceStart = _state.GroupingRecovery.VerbatimWhiteSpaceLength + _state.GroupingRecovery.NewLineKind.GetSize(); + var nextWhiteSpaceStart = _state.GroupingRecovery.VerbatimWhiteSpaceLength + _state.GroupingRecovery.NewLineKind.GetSize(); _state.NextWhiteSpace.Insert(0, _state.CurWhiteSpace.ToString(nextWhiteSpaceStart, _state.CurWhiteSpace.Length - nextWhiteSpaceStart)); _state.CurWhiteSpace.Remove(_state.GroupingRecovery.VerbatimWhiteSpaceLength, _state.CurWhiteSpace.Length - nextWhiteSpaceStart + _state.GroupingRecovery.NewLineKind.GetSize()); } @@ -382,32 +364,11 @@ internal bool TryGetTokenString(int len, out string tokenString) { return true; } - internal bool PrintFunction { - get { - return _printFunction; - } - set { - _printFunction = value; - } - } + internal bool PrintFunction { get; set; } - internal bool WithStatement { - get { - return _withStatement; - } - set { - _withStatement = value; - } - } + internal bool WithStatement { get; set; } - internal bool UnicodeLiterals { - get { - return _unicodeLiterals; - } - set { - _unicodeLiterals = value; - } - } + internal bool UnicodeLiterals { get; set; } /// /// Return the white space proceeding the last fetched token. Returns an empty string if @@ -452,17 +413,17 @@ public Token GetNextToken() { } private Token Next() { - bool at_beginning = AtBeginning; + var at_beginning = AtBeginning; if (_state.IncompleteString != null && Peek() != EOF) { - IncompleteString prev = _state.IncompleteString; + var prev = _state.IncompleteString; _state.IncompleteString = null; return ContinueString(prev.IsSingleTickQuote ? '\'' : '"', prev.IsRaw, prev.IsUnicode, false, prev.IsTripleQuoted, prev.IsFormatted, 0); } DiscardToken(); - int ch = NextChar(); + var ch = NextChar(); while (true) { switch (ch) { @@ -519,13 +480,13 @@ private Token Next() { ch = NextChar(); if (ch == -1) { - _endContinues = true; + EndContinues = true; } break; } else { if (nextChar == -1) { - _endContinues = true; + EndContinues = true; MarkTokenEnd(); return new VerbatimToken(TokenKind.EndOfFile, "\\", ""); } @@ -616,7 +577,7 @@ private Token Next() { } _state.LastNewLine = false; - Token res = NextOperator(ch); + var res = NextOperator(ch); if (res != null) { if (res is StatementSymbolToken) { return TransformStatementToken(res); @@ -625,7 +586,9 @@ private Token Next() { return res; } - if (IsNameStart(ch)) return ReadName(); + if (IsNameStart(ch)) { + return ReadName(); + } MarkTokenEnd(); return BadChar(ch); @@ -684,7 +647,7 @@ private void ProcessComment() { private int SkipSingleLineComment() { // do single-line comment: - int ch = ReadLine(); + var ch = ReadLine(); MarkTokenEnd(); ProcessComment(); @@ -705,9 +668,15 @@ private Token ReadSingleLineComment(out int ch) { } private Token ReadNameOrUnicodeString() { - bool isRaw = NextChar('r') || NextChar('R'); - if (NextChar('\"')) return ReadString('\"', isRaw, true, false, false); - if (NextChar('\'')) return ReadString('\'', isRaw, true, false, false); + var isRaw = NextChar('r') || NextChar('R'); + if (NextChar('\"')) { + return ReadString('\"', isRaw, true, false, false); + } + + if (NextChar('\'')) { + return ReadString('\'', isRaw, true, false, false); + } + if (isRaw) { BufferBack(); } @@ -715,9 +684,15 @@ private Token ReadNameOrUnicodeString() { } private Token ReadNameOrBytes() { - bool isRaw = NextChar('r') || NextChar('R'); - if (NextChar('\"')) return ReadString('\"', isRaw, false, true, false); - if (NextChar('\'')) return ReadString('\'', isRaw, false, true, false); + var isRaw = NextChar('r') || NextChar('R'); + if (NextChar('\"')) { + return ReadString('\"', isRaw, false, true, false); + } + + if (NextChar('\'')) { + return ReadString('\'', isRaw, false, true, false); + } + if (isRaw) { BufferBack(); } @@ -726,14 +701,20 @@ private Token ReadNameOrBytes() { private Token ReadNameOrRawString() { bool isBytes = false, isFormatted = false; - if (this._langVersion >= PythonLanguageVersion.V33) { + if (_langVersion >= PythonLanguageVersion.V33) { isBytes = NextChar('b') || NextChar('B'); } - if (this._langVersion >= PythonLanguageVersion.V36 && !isBytes) { + if (_langVersion >= PythonLanguageVersion.V36 && !isBytes) { isFormatted = NextChar('f') || NextChar('F'); } - if (NextChar('\"')) return ReadString('\"', true, false, isBytes, isFormatted); - if (NextChar('\'')) return ReadString('\'', true, false, isBytes, isFormatted); + if (NextChar('\"')) { + return ReadString('\"', true, false, isBytes, isFormatted); + } + + if (NextChar('\'')) { + return ReadString('\'', true, false, isBytes, isFormatted); + } + if (isBytes || isFormatted) { BufferBack(); } @@ -741,9 +722,15 @@ private Token ReadNameOrRawString() { } private Token ReadNameOrFormattedString() { - bool isRaw = NextChar('r') || NextChar('R'); - if (NextChar('\"')) return ReadString('\"', isRaw, false, false, true); - if (NextChar('\'')) return ReadString('\'', isRaw, false, false, true); + var isRaw = NextChar('r') || NextChar('R'); + if (NextChar('\"')) { + return ReadString('\"', isRaw, false, false, true); + } + + if (NextChar('\'')) { + return ReadString('\'', isRaw, false, false, true); + } + if (isRaw) { BufferBack(); } @@ -771,8 +758,8 @@ private Token ReadEof() { } private static string AddSlashes(string str) { - StringBuilder result = new StringBuilder(str.Length); - for (int i = 0; i < str.Length; i++) { + var result = new StringBuilder(str.Length); + for (var i = 0; i < str.Length; i++) { switch (str[i]) { case '\a': result.Append("\\a"); break; case '\b': result.Append("\\b"); break; @@ -897,8 +884,8 @@ public static bool IsIdentifierChar(char ch) { } private Token ReadString(char quote, bool isRaw, bool isUni, bool isBytes, bool isFormatted) { - int sadd = 0; - bool isTriple = false; + var sadd = 0; + var isTriple = false; if (NextChar(quote)) { if (NextChar(quote)) { @@ -911,10 +898,21 @@ private Token ReadString(char quote, bool isRaw, bool isUni, bool isBytes, bool sadd++; } - if (isRaw) sadd++; - if (isUni) sadd++; - if (isBytes) sadd++; - if (isFormatted) sadd++; + if (isRaw) { + sadd++; + } + + if (isUni) { + sadd++; + } + + if (isBytes) { + sadd++; + } + + if (isFormatted) { + sadd++; + } return ContinueString(quote, isRaw, isUni, isBytes, isTriple, isFormatted, sadd); } @@ -924,11 +922,11 @@ private Token ContinueString(char quote, bool isRaw, bool isUnicode, bool isByte // length of the string) and instead build up the string via pieces. Currently on files w/ large doc strings we // are forced to grow our buffer. - int end_add = 0; + var end_add = 0; NewLineKind nlKind; - for (;;) { - int ch = NextChar(); + for (; ; ) { + var ch = NextChar(); if (ch == EOF) { BufferBack(); @@ -936,16 +934,14 @@ private Token ContinueString(char quote, bool isRaw, bool isUnicode, bool isByte if (isTriple) { // CPython reports the multi-line string error as if it is a single line // ending at the last char in the file. - MarkTokenEnd(); - ReportSyntaxError(new IndexSpan(_tokenEndIndex, 0), "EOF while scanning triple-quoted string", ErrorCodes.SyntaxError | ErrorCodes.IncompleteToken); } else { MarkTokenEnd(); } UnexpectedEndOfString(isTriple, isTriple); - string incompleteContents = GetTokenString(); + var incompleteContents = GetTokenString(); _state.IncompleteString = new IncompleteString(quote == '\'', isRaw, isUnicode, isTriple, isFormatted); return new IncompleteStringErrorToken(" while reading string", incompleteContents); @@ -970,7 +966,7 @@ private Token ContinueString(char quote, bool isRaw, bool isUnicode, bool isByte MarkTokenEnd(); UnexpectedEndOfString(isTriple, isTriple); - string incompleteContents = GetTokenString(); + var incompleteContents = GetTokenString(); _state.IncompleteString = new IncompleteString(quote == '\'', isRaw, isUnicode, isTriple, isFormatted); @@ -984,7 +980,7 @@ private Token ContinueString(char quote, bool isRaw, bool isUnicode, bool isByte // incomplete string in the form "abc\ - string incompleteContents = GetTokenString(); + var incompleteContents = GetTokenString(); _state.IncompleteString = new IncompleteString(quote == '\'', isRaw, isUnicode, isTriple, isFormatted); UnexpectedEndOfString(isTriple, true); @@ -1003,7 +999,7 @@ private Token ContinueString(char quote, bool isRaw, bool isUnicode, bool isByte MarkTokenEnd(); UnexpectedEndOfString(isTriple, false); - string incompleteContents = GetTokenString(); + var incompleteContents = GetTokenString(); return new IncompleteStringErrorToken((quote == '"') ? "NEWLINE in double-quoted string" : "NEWLINE in single-quoted string", incompleteContents); } @@ -1047,8 +1043,8 @@ private Token MakeStringToken(char quote, bool isRaw, bool isUnicode, bool isByt return new ConstantValueToken(new AsciiString(new byte[0], "")); } - byte[] bytes = new byte[data.Count]; - for (int i = 0; i < bytes.Length; i++) { + var bytes = new byte[data.Count]; + for (var i = 0; i < bytes.Length; i++) { bytes[i] = (byte)data[i]; } @@ -1060,14 +1056,14 @@ private Token MakeStringToken(char quote, bool isRaw, bool isUnicode, bool isByt } private void UnexpectedEndOfString(bool isTriple, bool isIncomplete) { - string message = isTriple ? "EOF while scanning triple-quoted string" : "EOL while scanning single-quoted string"; - int error = isIncomplete ? ErrorCodes.SyntaxError | ErrorCodes.IncompleteToken : ErrorCodes.SyntaxError; + var message = isTriple ? "EOF while scanning triple-quoted string" : "EOL while scanning single-quoted string"; + var error = isIncomplete ? ErrorCodes.SyntaxError | ErrorCodes.IncompleteToken : ErrorCodes.SyntaxError; ReportSyntaxError(BufferTokenSpan, message, error); } private Token ReadNumber(int start) { - int b = 10; + var b = 10; if (start == '0') { if (NextChar('x') || NextChar('X')) { return ReadHexNumber(); @@ -1083,7 +1079,7 @@ private Token ReadNumber(int start) { } while (true) { - int ch = NextChar(); + var ch = NextChar(); switch (ch) { case '.': @@ -1099,7 +1095,7 @@ private Token ReadNumber(int start) { // TODO: parse in place if (Verbatim) { - string tokenStr = GetTokenString(); + var tokenStr = GetTokenString(); return new VerbatimConstantValueToken(LiteralParser.ParseImaginary(tokenStr), tokenStr); } return new ConstantValueToken(LiteralParser.ParseImaginary(GetTokenString())); @@ -1108,7 +1104,7 @@ private Token ReadNumber(int start) { case 'L': { MarkTokenEnd(); - string tokenStr = GetTokenString(); + var tokenStr = GetTokenString(); try { if (Verbatim) { return new VerbatimConstantValueToken(ParseBigInteger(tokenStr, b), tokenStr); @@ -1141,8 +1137,8 @@ private Token ReadNumber(int start) { BufferBack(); MarkTokenEnd(); - string image = GetTokenString(); - object val = ParseInteger(GetTokenString(), b); + var image = GetTokenString(); + var val = ParseInteger(GetTokenString(), b); if (b == 8 && _langVersion.Is3x() && (!(val is int) || !((int)val == 0))) { ReportSyntaxError(BufferTokenSpan, "invalid token", ErrorCodes.SyntaxError); } @@ -1157,12 +1153,12 @@ private Token ReadNumber(int start) { } private Token ReadBinaryNumber() { - int bits = 0; - int iVal = 0; - bool useBigInt = false; - BigInteger bigInt = BigInteger.Zero; + var bits = 0; + var iVal = 0; + var useBigInt = false; + var bigInt = BigInteger.Zero; while (true) { - int ch = NextChar(); + var ch = NextChar(); switch (ch) { case '0': if (iVal != 0) { @@ -1216,7 +1212,7 @@ private Token ReadBinaryNumber() { private Token ReadOctalNumber() { while (true) { - int ch = NextChar(); + var ch = NextChar(); switch (ch) { case '0': @@ -1259,7 +1255,7 @@ private Token ReadOctalNumber() { private Token ReadHexNumber() { string tokenStr; while (true) { - int ch = NextChar(); + var ch = NextChar(); switch (ch) { case '0': @@ -1318,7 +1314,7 @@ private Token ReadHexNumber() { private Token ReadFraction() { string tokenStr; while (true) { - int ch = NextChar(); + var ch = NextChar(); switch (ch) { case '0': @@ -1368,7 +1364,7 @@ private Token ReadFraction() { private Token ReadExponent(bool leftIsFloat = false) { string tokenStr; - int ch = NextChar(); + var ch = NextChar(); if (ch == '-' || ch == '+') { ch = NextChar(); @@ -1417,7 +1413,7 @@ private Token ReadExponent(bool leftIsFloat = false) { // depending on the lhs of the e tokenStr = GetTokenString(); - object parsed = leftIsFloat ? ParseFloat(tokenStr) : ParseInteger(tokenStr, 10); + var parsed = leftIsFloat ? ParseFloat(tokenStr) : ParseInteger(tokenStr, 10); if (Verbatim) { return new VerbatimConstantValueToken(parsed, tokenStr); } @@ -1493,7 +1489,7 @@ private Token ReadName() { } else if (ch == 'w') { ch = NextChar(); if (ch == 'i') { - if ((_langVersion >= PythonLanguageVersion.V26 || _withStatement) && NextChar() == 't' && NextChar() == 'h' && !IsNamePart(Peek())) { + if ((_langVersion >= PythonLanguageVersion.V26 || WithStatement) && NextChar() == 't' && NextChar() == 'h' && !IsNamePart(Peek())) { // with is a keyword in 2.6 and up return TransformStatementToken(Tokens.KeywordWithToken); } @@ -1525,7 +1521,7 @@ private Token ReadName() { } } else if (ch == 'r') { if (NextChar() == 'i' && NextChar() == 'n' && NextChar() == 't' && !IsNamePart(Peek())) { - if (!_printFunction && !_langVersion.Is3x() && !StubFile) { + if (!PrintFunction && !_langVersion.Is3x() && !StubFile) { return TransformStatementToken(Tokens.KeywordPrintToken); } } @@ -1616,7 +1612,7 @@ private Token ReadName() { return Tokens.KeywordAndToken; } } else if (ch == 's') { - if ((_langVersion >= PythonLanguageVersion.V26 || _withStatement) && !IsNamePart(Peek())) { + if ((_langVersion >= PythonLanguageVersion.V26 || WithStatement) && !IsNamePart(Peek())) { // as is a keyword in 2.6 and up or when from __future__ import with_statement is used MarkTokenEnd(); return Tokens.KeywordAsToken; @@ -1699,7 +1695,7 @@ private Token ReadName() { // When string is compared to _nameFromBuffer, this equality comparer uses _buffer for GetHashCode and Equals // to avoid allocation of a new string instance if (!_names.TryGetValue(_nameFromBuffer, out var token)) { - string name = GetTokenString(); + var name = GetTokenString(); token = _names[name] = new NameToken(name); } @@ -1871,17 +1867,17 @@ bool IEqualityComparer.Equals(object x, object y) { } public int GetHashCode(object obj) { - int result = 5381; + var result = 5381; if (obj == _nameFromBuffer) { - char[] buffer = _tokenizer._buffer; + var buffer = _tokenizer._buffer; int start = _tokenizer._start, end = _tokenizer._tokenEnd; - for (int i = start; i < end; i++) { + for (var i = start; i < end; i++) { int c = buffer[i]; result = unchecked(((result << 5) + result) ^ c); } } else { - string str = (string)obj; - for (int i = 0; i < str.Length; i++) { + var str = (string)obj; + for (var i = 0; i < str.Length; i++) { int c = str[i]; result = unchecked(((result << 5) + result) ^ c); } @@ -1890,7 +1886,7 @@ public int GetHashCode(object obj) { } private bool Equals(string value) { - int len = _tokenizer._tokenEnd - _tokenizer._start; + var len = _tokenizer._tokenEnd - _tokenizer._start; if (len != value.Length) { return false; } @@ -1908,21 +1904,13 @@ private bool Equals(string value) { #endregion } - public int GroupingLevel { - get { - return _state.ParenLevel + _state.BraceLevel + _state.BracketLevel; - } - } + public int GroupingLevel => _state.ParenLevel + _state.BraceLevel + _state.BracketLevel; /// /// True if the last characters in the buffer are a backslash followed by a new line indicating - /// that their is an incompletement statement which needs further input to complete. + /// that their is an incomplete statement which needs further input to complete. /// - public bool EndContinues { - get { - return _endContinues; - } - } + public bool EndContinues { get; private set; } private static void AppendSpace(ref string curWhiteSpace, ref StringBuilder constructedWhiteSpace, ref bool? isSpace) { if (constructedWhiteSpace == null) { @@ -1975,13 +1963,13 @@ private static void AppendTab(ref string curWhiteSpace, ref StringBuilder constr private bool ReadIndentationAfterNewLine(NewLineKind startingKind) { // Keep track of the indentation format for the current line StringBuilder sb = null; // the white space we've encounted after the new line if it's mixed tabs/spaces or is an unreasonable size. - string noAllocWhiteSpace = String.Empty; // the white space we've encountered after the newline assuming it's a reasonable sized run of all spaces or tabs + var noAllocWhiteSpace = String.Empty; // the white space we've encountered after the newline assuming it's a reasonable sized run of all spaces or tabs bool? isSpace = null; // the current mix of whitespace, null = nothing yet, true = space, false = tab - int spaces = 0; - int indentStart = CurrentIndex; + var spaces = 0; + var indentStart = CurrentIndex; while (true) { - int ch = NextChar(); + var ch = NextChar(); switch (ch) { case ' ': @@ -2029,7 +2017,7 @@ private bool ReadIndentationAfterNewLine(NewLineKind startingKind) { BufferBack(); if (GroupingLevel > 0) { - int startingWhiteSpace = 0; + var startingWhiteSpace = 0; if (Verbatim) { // we're not producing a new line after all... All of the white space // we collected goes to the current token, including the new line token @@ -2040,8 +2028,8 @@ private bool ReadIndentationAfterNewLine(NewLineKind startingKind) { _state.NextWhiteSpace.Clear(); } if ((_options & TokenizerOptions.GroupingRecovery) != 0) { - int tokenEnd = System.Math.Min(_position, _end); - int tokenLength = tokenEnd - _start; + var tokenEnd = Math.Min(_position, _end); + var tokenLength = tokenEnd - _start; _state.GroupingRecovery = new GroupingRecovery( startingKind, @@ -2093,11 +2081,9 @@ private bool ReadIndentationAfterNewLine(NewLineKind startingKind) { } private static int PreviousIndentLength(object previousIndent) { - string prevStr = previousIndent as string; - if (prevStr != null) { + if (previousIndent is string prevStr) { return prevStr.Length; } - return ((StringBuilder)previousIndent).Length; } @@ -2110,7 +2096,7 @@ private void CheckIndent(StringBuilder sb, string noAllocWhiteSpace, int indentS } else { checkLength = previousIndent.Length < sb.Length ? previousIndent.Length : sb.Length; } - for (int i = 0; i < checkLength; i++) { + for (var i = 0; i < checkLength; i++) { bool neq; if (sb == null) { neq = noAllocWhiteSpace[i] != previousIndent[i]; @@ -2132,7 +2118,7 @@ private void CheckIndent(StringBuilder sb, string noAllocWhiteSpace, int indentS } private void SetIndent(int spaces, StringBuilder chars, string noAllocWhiteSpace, int indentStart = -1) { - int current = _state.Indent[_state.IndentLevel]; + var current = _state.Indent[_state.IndentLevel]; if (spaces == current) { return; } else if (spaces > current) { @@ -2167,7 +2153,7 @@ private int DoDedent(int spaces, int current) { } private object ParseInteger(string s, int radix) { - bool reported = false; + var reported = false; try { reported = ReportInvalidNumericLiteral(s, allowLeadingUnderscore: radix != 10); return LiteralParser.ParseInteger(s, radix); @@ -2180,7 +2166,7 @@ private object ParseInteger(string s, int radix) { } private object ParseBigInteger(string s, int radix) { - bool reported = false; + var reported = false; try { reported = ReportInvalidNumericLiteral(s, allowLeadingUnderscore: radix != 10); return LiteralParser.ParseBigInteger(s, radix); @@ -2193,7 +2179,7 @@ private object ParseBigInteger(string s, int radix) { } private object ParseFloat(string s) { - bool reported = false; + var reported = false; try { reported = ReportInvalidNumericLiteral(s, eIsForExponent: true); return LiteralParser.ParseFloat(s); @@ -2206,7 +2192,7 @@ private object ParseFloat(string s) { } private object ParseComplex(string s) { - bool reported = false; + var reported = false; try { reported = ReportInvalidNumericLiteral(s, eIsForExponent: true); return LiteralParser.ParseImaginary(s); @@ -2218,18 +2204,16 @@ private object ParseComplex(string s) { } } - private void ReportSyntaxError(IndexSpan span, string message, int errorCode) { - _errors.Add(message, _newLineLocations.ToArray(), span.Start, span.End, errorCode, Severity.FatalError); - } + private void ReportSyntaxError(IndexSpan span, string message, int errorCode) + => _errors.Add(message, _newLineLocations.ToArray(), span.Start, span.End, errorCode, Severity.FatalError); [Conditional("DUMP_TOKENS")] - private static void DumpToken(Token token) { - Console.WriteLine("{0} `{1}`", token.Kind, token.Image.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t")); - } + private static void DumpToken(Token token) + => Console.WriteLine("{0} `{1}`", token.Kind, token.Image.Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t")); - internal NewLineLocation GetNewLineLocation(int line) => _newLineLocations.Count == line ? new NewLineLocation(CurrentIndex, NewLineKind.None) : _newLineLocations[line]; - internal NewLineLocation[] GetLineLocations() => _newLineLocations.ToArray(); - internal SourceLocation[] GetCommentLocations() => _commentLocations.ToArray(); + public NewLineLocation GetNewLineLocation(int line) => _newLineLocations.Count == line ? new NewLineLocation(CurrentIndex, NewLineKind.None) : _newLineLocations[line]; + public NewLineLocation[] GetLineLocations() => _newLineLocations.ToArray(); + public SourceLocation[] GetCommentLocations() => _commentLocations.ToArray(); [Serializable] class IncompleteString : IEquatable { @@ -2244,24 +2228,20 @@ public IncompleteString(bool isSingleTickQuote, bool isRaw, bool isUnicode, bool } public override bool Equals(object obj) { - IncompleteString oth = obj as IncompleteString; - if (oth != null) { - return Equals(oth); - } - return false; + var oth = obj as IncompleteString; + return oth != null && Equals(oth); } - public override int GetHashCode() { - return (IsRaw ? 0x01 : 0) | + public override int GetHashCode() => (IsRaw ? 0x01 : 0) | (IsUnicode ? 0x02 : 0) | (IsTripleQuoted ? 0x04 : 0) | (IsSingleTickQuote ? 0x08 : 0) | (IsFormatted ? 0x10 : 0); - } public static bool operator ==(IncompleteString left, IncompleteString right) { - if ((object)left == null) return (object)right == null; - + if ((object)left == null) { + return (object)right == null; + } return left.Equals(right); } @@ -2295,7 +2275,7 @@ struct State : IEquatable { public bool LastNewLine; // true if the last token we emitted was a new line. public IncompleteString IncompleteString; - // Indentation state used only when we're reporting on inconsistent identation format. + // Indentation state used only when we're reporting on inconsistent indentation format. public string[] IndentFormat; // grouping state @@ -2343,17 +2323,13 @@ public State(TokenizerOptions options) { } public override bool Equals(object obj) { - if (obj is State) { - State other = (State)obj; + if (obj is State other) { return other == this; - } else { - return false; } + return false; } - public override int GetHashCode() { - return base.GetHashCode(); - } + public override int GetHashCode() => base.GetHashCode(); public static bool operator ==(State left, State right) { return left.BraceLevel == right.BraceLevel && @@ -2371,9 +2347,7 @@ public override int GetHashCode() { #region IEquatable Members - public bool Equals(State other) { - return this.Equals(other); - } + public bool Equals(State other) => Equals(other); #endregion } @@ -2431,9 +2405,7 @@ public GroupingRecovery(NewLineKind newlineKind, string noAllocWhiteSpace, int s #region Buffer Access - private string GetTokenSubstring(int offset) { - return GetTokenSubstring(offset, _tokenEnd - _start - offset); - } + private string GetTokenSubstring(int offset) => GetTokenSubstring(offset, _tokenEnd - _start - offset); private string GetTokenSubstring(int offset, int length) { Debug.Assert(_tokenEnd != -1, "Token end not marked"); @@ -2483,8 +2455,8 @@ private int ReadLine() { private void MarkTokenEnd() { CheckInvariants(); - _tokenEnd = System.Math.Min(_position, _end); - int token_length = _tokenEnd - _start; + _tokenEnd = Math.Min(_position, _end); + var token_length = _tokenEnd - _start; _tokenEndIndex = _tokenStartIndex + token_length; @@ -2494,45 +2466,21 @@ private void MarkTokenEnd() { } [Conditional("DUMP_TOKENS")] - private void DumpToken() { - Console.WriteLine("--> `{0}` {1}", GetTokenString().Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"), TokenSpan); - } - - private void BufferBack(int count = -1) { - SeekRelative(count); - } - - internal string GetTokenString() { - return new String(_buffer, _start, _tokenEnd - _start); - } + private void DumpToken() => Console.WriteLine("--> `{0}` {1}", GetTokenString().Replace("\r", "\\r").Replace("\n", "\\n").Replace("\t", "\\t"), TokenSpan); - private int TokenLength { - get { - return _tokenEnd - _start; - } - } + private void BufferBack(int count = -1) => SeekRelative(count); + internal string GetTokenString() => new string(_buffer, _start, _tokenEnd - _start); + private int TokenLength => _tokenEnd - _start; private void SeekRelative(int disp) { CheckInvariants(); Debug.Assert(disp >= _start - _position); // no upper limit, we can seek beyond end in which case we are reading EOFs - _position += disp; - CheckInvariants(); } - private SourceLocation BufferTokenEnd { - get { - return IndexToLocation(_tokenEndIndex); - } - } - - private IndexSpan BufferTokenSpan { - get { - return new IndexSpan(_tokenStartIndex, _tokenEndIndex - _tokenStartIndex); - } - } + private IndexSpan BufferTokenSpan => new IndexSpan(_tokenStartIndex, _tokenEndIndex - _tokenStartIndex); private bool NextChar(int ch) { CheckInvariants(); @@ -2540,22 +2488,17 @@ private bool NextChar(int ch) { _position++; CheckInvariants(); return true; - } else { - return false; } + return false; } private int NextChar() { - int result = Peek(); + var result = Peek(); _position++; return result; } - private bool AtBeginning { - get { - return _position == 0 && !_bufferResized; - } - } + private bool AtBeginning => _position == 0 && !_bufferResized; private int CurrentIndex => _tokenStartIndex + Math.Min(_position, _end) - _start; @@ -2563,7 +2506,9 @@ private void DiscardToken() { CheckInvariants(); // no token marked => mark it now: - if (_tokenEnd == -1) MarkTokenEnd(); + if (_tokenEnd == -1) { + MarkTokenEnd(); + } // the current token's end is the next token's start: _start = _tokenEnd; @@ -2593,7 +2538,9 @@ private NewLineKind ReadEolnOpt(int current) { } private bool IsEoln(int current) { - if (current == '\n') return true; + if (current == '\n') { + return true; + } if (current == '\r' && _multiEolns) { if (Peek() == '\n') { @@ -2608,9 +2555,9 @@ private bool IsEoln(int current) { private void RefillBuffer() { if (_end == _buffer.Length) { - int ws_start = _tokenStartIndex - _state.GroupingRecovery?.NewlineStart ?? 0; - int new_start = _start - ws_start; // move the buffer to the start of the current whitespace - int new_size = Math.Max(Math.Max((_end - new_start) * 2, _buffer.Length), _position); + var ws_start = _tokenStartIndex - _state.GroupingRecovery?.NewlineStart ?? 0; + var new_start = _start - ws_start; // move the buffer to the start of the current whitespace + var new_size = Math.Max(Math.Max((_end - new_start) * 2, _buffer.Length), _position); ResizeInternal(ref _buffer, new_size, new_start, _end - new_start); _end -= new_start; _position -= new_start; @@ -2620,29 +2567,32 @@ private void RefillBuffer() { } // make the buffer full: - int count = _reader.Read(_buffer, _end, _buffer.Length - _end); + var count = _reader.Read(_buffer, _end, _buffer.Length - _end); _end += count; ClearInvalidChars(); } /// - /// Resizes an array to a speficied new size and copies a portion of the original array into its beginning. + /// Resizes an array to a specified new size and copies a portion of the original array into its beginning. /// private static void ResizeInternal(ref char[] array, int newSize, int start, int count) { Debug.Assert(array != null && newSize > 0 && count >= 0 && newSize >= count && start >= 0); - char[] result = (newSize != array.Length) ? new char[newSize] : array; - + var result = (newSize != array.Length) ? new char[newSize] : array; Buffer.BlockCopy(array, start * sizeof(char), result, 0, count * sizeof(char)); - array = result; } [Conditional("DEBUG")] private void ClearInvalidChars() { - for (int i = 0; i < _start; i++) _buffer[i] = '\0'; - for (int i = _end; i < _buffer.Length; i++) _buffer[i] = '\0'; + for (var i = 0; i < _start; i++) { + _buffer[i] = '\0'; + } + + for (var i = _end; i < _buffer.Length; i++) { + _buffer[i] = '\0'; + } } #endregion @@ -2675,16 +2625,14 @@ public NewLineLocation(int lineEnd, NewLineKind kind) { /// public NewLineKind Kind => _kind; - public int CompareTo(NewLineLocation other) { - return EndIndex - other.EndIndex; - } + public int CompareTo(NewLineLocation other) => EndIndex - other.EndIndex; public static SourceLocation IndexToLocation(NewLineLocation[] lineLocations, int index) { if (lineLocations == null || index == 0) { return new SourceLocation(index, 1, 1); } - int match = Array.BinarySearch(lineLocations, new NewLineLocation(index, NewLineKind.None)); + var match = Array.BinarySearch(lineLocations, new NewLineLocation(index, NewLineKind.None)); if (match < 0) { // If our index = -1, it means we're on the first line. if (match == -1) { @@ -2702,8 +2650,8 @@ public static SourceLocation IndexToLocation(NewLineLocation[] lineLocations, in return new SourceLocation(index, 1, checked(index + 1)); } - int line = match + 2; - int col = index - lineLocations[match].EndIndex + 1; + var line = match + 2; + var col = index - lineLocations[match].EndIndex + 1; return new SourceLocation(index, line, col); } @@ -2711,13 +2659,13 @@ public static int LocationToIndex(NewLineLocation[] lineLocations, SourceLocatio if (lineLocations == null) { return 0; } - int index = 0; + var index = 0; if (lineLocations.Length == 0) { // We have a single line, so the column is the index index = location.Column - 1; return endIndex >= 0 ? Math.Min(index, endIndex) : index; } - int line = location.Line - 1; + var line = location.Line - 1; if (line > lineLocations.Length) { index = lineLocations[lineLocations.Length - 1].EndIndex; @@ -2740,10 +2688,10 @@ public static int LocationToIndex(NewLineLocation[] lineLocations, SourceLocatio return (int)Math.Min((long)index + location.Column - 1, endIndex); } - private static char[] _lineSeparators = new[] { '\r', '\n' }; + private static readonly char[] _lineSeparators = new[] { '\r', '\n' }; public static NewLineLocation FindNewLine(string text, int start) { - int i = text.IndexOfAny(_lineSeparators, start); + var i = text.IndexOfAny(_lineSeparators, start); if (i < start) { return new NewLineLocation(text.Length, NewLineKind.None); } diff --git a/src/Analysis/Engine/Impl/Parsing/TokenizerOptions.cs b/src/Parsing/Impl/TokenizerOptions.cs similarity index 96% rename from src/Analysis/Engine/Impl/Parsing/TokenizerOptions.cs rename to src/Parsing/Impl/TokenizerOptions.cs index 17b0051fe..534d8f3f6 100644 --- a/src/Analysis/Engine/Impl/Parsing/TokenizerOptions.cs +++ b/src/Parsing/Impl/TokenizerOptions.cs @@ -9,14 +9,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -namespace Microsoft.PythonTools.Parsing { +namespace Microsoft.Python.Parsing { [Flags] public enum TokenizerOptions { None, diff --git a/src/Parsing/Test/Microsoft.Python.Parsing.Tests.csproj b/src/Parsing/Test/Microsoft.Python.Parsing.Tests.csproj new file mode 100644 index 000000000..f262305fd --- /dev/null +++ b/src/Parsing/Test/Microsoft.Python.Parsing.Tests.csproj @@ -0,0 +1,47 @@ + + + netcoreapp2.1 + Microsoft.Python.Parsing.Tests + Microsoft.Python.Parsing.Tests + + + + 1701;1702;$(NoWarn) + + + ..\..\PLS.ruleset + + + ..\..\PLS.ruleset + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + + diff --git a/src/Analysis/Engine/Test/MutateStdLibTest.cs b/src/Parsing/Test/MutateStdLibTest.cs similarity index 95% rename from src/Analysis/Engine/Test/MutateStdLibTest.cs rename to src/Parsing/Test/MutateStdLibTest.cs index 464b13e89..cdc62e938 100644 --- a/src/Analysis/Engine/Test/MutateStdLibTest.cs +++ b/src/Parsing/Test/MutateStdLibTest.cs @@ -1,4 +1,3 @@ -// Python Tools for Visual Studio // Copyright(c) Microsoft Corporation // All rights reserved. // @@ -9,20 +8,18 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.IO; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Analysis.Core.Interpreter; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; -namespace AnalysisTests { +namespace Microsoft.Python.Parsing.Tests { [TestClass] public class MutateStdLibTest { public TestContext TestContext { get; set; } diff --git a/src/Analysis/Engine/Test/ParserEncodingTests.cs b/src/Parsing/Test/ParserEncodingTests.cs similarity index 94% rename from src/Analysis/Engine/Test/ParserEncodingTests.cs rename to src/Parsing/Test/ParserEncodingTests.cs index 049f56284..fafaccaa5 100644 --- a/src/Analysis/Engine/Test/ParserEncodingTests.cs +++ b/src/Parsing/Test/ParserEncodingTests.cs @@ -9,17 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.IO; using System.Text; -using Microsoft.PythonTools.Parsing; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AnalysisTests { +namespace Microsoft.Python.Parsing.Tests { /// /// Test cases for parser written in a continuation passing style. /// diff --git a/src/Analysis/Engine/Test/ParserRoundTripTest.cs b/src/Parsing/Test/ParserRoundTripTest.cs similarity index 99% rename from src/Analysis/Engine/Test/ParserRoundTripTest.cs rename to src/Parsing/Test/ParserRoundTripTest.cs index 791a1e626..e96341c69 100644 --- a/src/Analysis/Engine/Test/ParserRoundTripTest.cs +++ b/src/Parsing/Test/ParserRoundTripTest.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,14 +18,12 @@ using System.IO; using System.Linq; using System.Text; -using Microsoft.PythonTools.Analysis; -using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Parsing.Ast; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; -namespace AnalysisTests { +namespace Microsoft.Python.Parsing.Tests { /// /// Test cases to verify that the parser successfully preserves all information for round tripping source code. /// @@ -549,12 +547,12 @@ public void TestStartWhiteSpace() { foreach (var testCase in allSnippets) { var exprText = testCase.Text; - string code = preceedingText + exprText; + var code = preceedingText + exprText; Console.WriteLine(code); var parser = Parser.CreateParser(new StringReader(code), testCase.Version, new ParserOptions() { Verbatim = true }); var ast = parser.ParseFile(); - Statement stmt = ((SuiteStatement)ast.Body).Statements[0]; + var stmt = ((SuiteStatement)ast.Body).Statements[0]; if (stmt is ExpressionStatement) { var expr = ((ExpressionStatement)stmt).Expression; @@ -1686,7 +1684,7 @@ private static void TestOneFile(string filename, PythonLanguageVersion version) TestOneString(version, originalText, filename: filename); } - internal static void TestOneString( + public static void TestOneString( PythonLanguageVersion version, string originalText, CodeFormattingOptions format = null, diff --git a/src/Analysis/Engine/Test/ParserTests.cs b/src/Parsing/Test/ParserTests.cs similarity index 97% rename from src/Analysis/Engine/Test/ParserTests.cs rename to src/Parsing/Test/ParserTests.cs index 43db611b8..e6116044f 100644 --- a/src/Analysis/Engine/Test/ParserTests.cs +++ b/src/Parsing/Test/ParserTests.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -21,17 +21,15 @@ using System.Linq; using System.Numerics; using System.Text; -using System.Threading.Tasks; using FluentAssertions; -using Microsoft.PythonTools; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; -using Microsoft.PythonTools.Parsing.Ast; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.Text; +using Microsoft.Python.Parsing.Ast; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; -namespace AnalysisTests { +namespace Microsoft.Python.Parsing.Tests { /// /// Test cases for parser written in a continuation passing style. /// @@ -106,7 +104,7 @@ public void GeneralizedUnpacking() { CheckAst( ParseFile("GenUnpack.py", ErrorSink.Null, version), CheckSuite( - CheckCallStmt(Fob, + CheckCallStmt(Fob, CheckNamedArg("*", CheckListExpr(One)), CheckNamedArg("*", CheckListExpr(Two)), PositionalArg(Three) @@ -631,7 +629,7 @@ public void InvalidUnicodeLiteral() { foreach (var version in V26AndUp) { ParseErrors("InvalidUnicodeLiteral26Up.py", version, - new ErrorInfo($"'unicodeescape' codec can't decode bytes in position {position}: truncated \\uXXXX escape", + new ErrorInfo($"'unicodeescape' codec can't decode bytes in position {position}: truncated \\uXXXX escape", 39 + Environment.NewLine.Length, 2, 1, 47 + Environment.NewLine.Length, 2, 9) ); } @@ -1051,7 +1049,7 @@ public void BinaryOperatorsV2() { } foreach (var version in V3Versions) { - ParseErrors("BinaryOperatorsV2.py", version, new[] { + ParseErrors("BinaryOperatorsV2.py", version, new[] { new ErrorInfo("unexpected token '>'", 3, 1, 4, 4, 1, 5), new ErrorInfo("invalid syntax", 5, 1, 6, 6, 1, 7) }); @@ -1070,7 +1068,7 @@ public void MatMulOperator() { } foreach (var version in V3Versions.Except(V35AndUp)) { - ParseErrors("MatMulOperator.py", version, new[] { + ParseErrors("MatMulOperator.py", version, new[] { new ErrorInfo("unexpected token '@'", 2, 1, 3, 3, 1, 4) }); } @@ -1267,7 +1265,7 @@ public void DelimitersV2() { ParseErrors( "DelimitersV2.py", version, - new[] { + new[] { new ErrorInfo("unexpected token '`'", 0, 1, 1, 1, 1, 2), new ErrorInfo("unexpected token 'fob'", 1, 1, 2, 4, 1, 5), new ErrorInfo("unexpected token '`'", 4, 1, 5, 5, 1, 6) @@ -1434,9 +1432,9 @@ public void YieldExpr() { ParseErrors("YieldExpr.py", PythonLanguageVersion.V24, new ErrorInfo("invalid syntax", 19, 2, 10, 21, 3, 1), new ErrorInfo("unexpected token 'yield'", 43, 5, 11, 48, 5, 16) - // [(yield oar) for ...] should be an error, but it is not raised. - // V24 is not supported by PTVS, so don't fail the test because of this. - //new ErrorInfo("unexpected token 'yield'", 74, 8, 13, 79, 8, 18) + // [(yield oar) for ...] should be an error, but it is not raised. + // V24 is not supported by PTVS, so don't fail the test because of this. + //new ErrorInfo("unexpected token 'yield'", 74, 8, 13, 79, 8, 18) ); } @@ -2793,7 +2791,7 @@ public void VariableAnnotation() { CheckAst( ParseFile("VarAnnotation.py", ErrorSink.Null, version), CheckSuite( - CheckExprStmt(FobWithOar), + CheckExprStmt(FobWithOar), CheckAssignment(FobWithOar, One), CheckExprStmt(Fob1WithOar), CheckExprStmt(FobOarWithBaz), @@ -2875,7 +2873,7 @@ private static string StdLibWorker(InterpreterConfiguration configuration) { var errorSink = new CollectingErrorSink(); var errors = new Dictionary>(); foreach (var file in files) { - string filename = Path.GetFileName(file); + var filename = Path.GetFileName(file); if (skippedFiles.Contains(filename) || filename.StartsWith("badsyntax_") || filename.StartsWith("bad_coding") || file.IndexOf("\\lib2to3\\tests\\") != -1) { continue; } @@ -2910,7 +2908,7 @@ private static string StdLibWorker(InterpreterConfiguration configuration) { } if (errors.Count != 0) { - StringBuilder errorList = new StringBuilder(); + var errorList = new StringBuilder(); foreach (var keyValue in errors) { errorList.Append(keyValue.Key + " :" + Environment.NewLine); foreach (var error in keyValue.Value) { @@ -2928,7 +2926,7 @@ public void SourceLocationTests() { Assert.AreEqual(0, new SourceLocation().Index); Assert.AreEqual(100, new SourceLocation(100, 1, 1).Index); try { - int i = new SourceLocation(1, 1).Index; + var i = new SourceLocation(1, 1).Index; Assert.Fail("Expected InvalidOperationException"); } catch (InvalidOperationException) { } @@ -2988,7 +2986,7 @@ public void FindArgument() { var tree = parser.ParseTopExpression(); if (Statement.GetExpression(tree.Body) is CallExpression ce) { return (index, expected) => { - int? actual = ce.GetArgumentAtIndex(tree, index, out int i) ? i : (int?)null; + var actual = ce.GetArgumentAtIndex(tree, index, out var i) ? i : (int?)null; Assert.AreEqual(expected, actual); }; } @@ -3005,7 +3003,7 @@ public void CommentLocations() { # line 4"), PythonLanguageVersion.V36); var tree = parser.ParseFile(); - tree._commentLocations.Should().Equal( + tree.CommentLocations.Should().Equal( new SourceLocation(1, 1), new SourceLocation(3, 1), new SourceLocation(5, 3) @@ -3018,7 +3016,7 @@ public void CommentLocations() { pass # line 4"), PythonLanguageVersion.V36); tree = new PythonAst(new[] { tree1, parser.ParseFile() }); - tree._commentLocations.Should().Equal( + tree.CommentLocations.Should().Equal( new SourceLocation(1, 1), new SourceLocation(3, 1), new SourceLocation(5, 3) @@ -3059,8 +3057,8 @@ private void ParseErrors(string filename, PythonLanguageVersion version, Severit var sink = new CollectingErrorSink(); ParseFile(filename, sink, version, indentationInconsistencySeverity); - StringBuilder foundErrors = new StringBuilder(); - for (int i = 0; i < sink.Errors.Count; i++) { + var foundErrors = new StringBuilder(); + for (var i = 0; i < sink.Errors.Count; i++) { foundErrors.AppendFormat("{0}{1}{2}", FormatError(sink.Errors[i]), i == sink.Errors.Count - 1 ? "" : ",", @@ -3068,10 +3066,10 @@ private void ParseErrors(string filename, PythonLanguageVersion version, Severit ); } - string finalErrors = foundErrors.ToString(); + var finalErrors = foundErrors.ToString(); Console.WriteLine(finalErrors); - for (int i = 0; i < errors.Length; i++) { + for (var i = 0; i < errors.Length; i++) { if (sink.Errors.Count <= i) { Assert.Fail("No error {0}: {1}", i, FormatError(errors[i])); } @@ -3119,34 +3117,34 @@ private void CheckAst(PythonAst ast, Action checkBody) { checkBody(ast.Body); } - private static Action Zero = CheckConstant(0); - private static Action One = CheckConstant(1); - private static Action Two = CheckConstant(2); - private static Action Three = CheckConstant(3); - private static Action Four = CheckConstant(4); - private static Action None = CheckConstant(null); - private static Action Fob = CheckNameExpr("fob"); - private static Action Ellipsis = CheckConstant(Microsoft.PythonTools.Parsing.Ellipsis.Value); - private static Action Oar = CheckNameExpr("oar"); - private static Action Baz = CheckNameExpr("baz"); - private static Action Quox = CheckNameExpr("quox"); - private static Action Exception = CheckNameExpr("Exception"); - private static Action Pass = CheckEmptyStmt(); - private static Action Break = CheckBreakStmt(); - private static Action Continue = CheckContinueStmt(); + private static readonly Action Zero = CheckConstant(0); + private static readonly Action One = CheckConstant(1); + private static readonly Action Two = CheckConstant(2); + private static readonly Action Three = CheckConstant(3); + private static readonly Action Four = CheckConstant(4); + private static readonly Action None = CheckConstant(null); + private static readonly Action Fob = CheckNameExpr("fob"); + private static readonly Action Ellipsis = CheckConstant(Microsoft.Python.Parsing.Ellipsis.Value); + private static readonly Action Oar = CheckNameExpr("oar"); + private static readonly Action Baz = CheckNameExpr("baz"); + private static readonly Action Quox = CheckNameExpr("quox"); + private static readonly Action Exception = CheckNameExpr("Exception"); + private static readonly Action Pass = CheckEmptyStmt(); + private static readonly Action Break = CheckBreakStmt(); + private static readonly Action Continue = CheckContinueStmt(); private static Action CheckSuite(params Action[] statements) { return stmt => { Assert.AreEqual(typeof(SuiteStatement), stmt.GetType()); - SuiteStatement suite = (SuiteStatement)stmt; + var suite = (SuiteStatement)stmt; Assert.AreEqual(statements.Length, suite.Statements.Count); - for (int i = 0; i < suite.Statements.Count; i++) { + for (var i = 0; i < suite.Statements.Count; i++) { try { statements[i](suite.Statements[i]); } catch (AssertFailedException e) { Trace.TraceError(e.ToString()); - throw new AssertFailedException(String.Format("Suite Item {0}: {1}", i, e.Message), e); + throw new AssertFailedException(string.Format("Suite Item {0}: {1}", i, e.Message), e); } } }; @@ -3155,7 +3153,7 @@ private static Action CheckSuite(params Action[] statement private static Action CheckForStmt(Action left, Action list, Action body, Action _else = null) { return stmt => { Assert.AreEqual(typeof(ForStatement), stmt.GetType()); - ForStatement forStmt = (ForStatement)stmt; + var forStmt = (ForStatement)stmt; left(forStmt.Left); list(forStmt.List); @@ -3220,7 +3218,7 @@ private static Action CheckTryStmt(Action body, Action CheckPrintStmt(Action[] expressions Assert.AreEqual(expressions.Length, printStmt.Expressions.Count); Assert.AreEqual(printStmt.TrailingComma, trailingComma); - for (int i = 0; i < expressions.Length; i++) { + for (var i = 0; i < expressions.Length; i++) { expressions[i](printStmt.Expressions[i]); } @@ -3311,7 +3309,7 @@ private static Action IfTest(Action expectedTest, A private static Action> IfTests(params Action[] expectedTests) { return tests => { Assert.AreEqual(expectedTests.Length, tests.Count); - for (int i = 0; i < expectedTests.Length; i++) { + for (var i = 0; i < expectedTests.Length; i++) { expectedTests[i](tests[i]); } }; @@ -3322,7 +3320,7 @@ private static Action CheckIfStmt(Action> test Assert.AreEqual(typeof(IfStatement), stmt.GetType()); var ifStmt = (IfStatement)stmt; - tests(ifStmt.TestsInternal); + tests(ifStmt.Tests); if (_else != null) { _else(ifStmt.ElseStatement); @@ -3350,19 +3348,19 @@ private static Action CheckFromImport(string fromName, string[] names Assert.AreEqual(fiStmt.Root.MakeString(), fromName); Assert.AreEqual(names.Length, fiStmt.Names.Count); - for (int i = 0; i < names.Length; i++) { + for (var i = 0; i < names.Length; i++) { Assert.AreEqual(names[i], fiStmt.Names[i].Name); } if (asNames == null) { if (fiStmt.AsNames != null) { - for (int i = 0; i < fiStmt.AsNames.Count; i++) { + for (var i = 0; i < fiStmt.AsNames.Count; i++) { Assert.AreEqual(null, fiStmt.AsNames[i]); } } } else { Assert.AreEqual(asNames.Length, fiStmt.AsNames.Count); - for (int i = 0; i < asNames.Length; i++) { + for (var i = 0; i < asNames.Length; i++) { Assert.AreEqual(asNames[i], fiStmt.AsNames[i].Name); } } @@ -3375,19 +3373,19 @@ private static Action CheckImport(string[] names, string[] asNames = var fiStmt = (ImportStatement)stmt; Assert.AreEqual(names.Length, fiStmt.Names.Count); - for (int i = 0; i < names.Length; i++) { + for (var i = 0; i < names.Length; i++) { Assert.AreEqual(names[i], fiStmt.Names[i].MakeString()); } if (asNames == null) { if (fiStmt.AsNames != null) { - for (int i = 0; i < fiStmt.AsNames.Count; i++) { + for (var i = 0; i < fiStmt.AsNames.Count; i++) { Assert.AreEqual(null, fiStmt.AsNames[i]); } } } else { Assert.AreEqual(asNames.Length, fiStmt.AsNames.Count); - for (int i = 0; i < asNames.Length; i++) { + for (var i = 0; i < asNames.Length; i++) { Assert.AreEqual(asNames[i], fiStmt.AsNames[i].Name); } } @@ -3397,7 +3395,7 @@ private static Action CheckImport(string[] names, string[] asNames = private static Action CheckExprStmt(Action expr) { return stmt => { Assert.AreEqual(typeof(ExpressionStatement), stmt.GetType()); - ExpressionStatement exprStmt = (ExpressionStatement)stmt; + var exprStmt = (ExpressionStatement)stmt; expr(exprStmt.Expression); }; } @@ -3447,7 +3445,7 @@ private static Action CheckFuncDef(string name, Action[] a } Assert.AreEqual(args?.Length ?? 0, funcDef.Parameters.Length); - for (int i = 0; i < (args?.Length ?? 0); i++) { + for (var i = 0; i < (args?.Length ?? 0); i++) { args[i](funcDef.Parameters[i]); } @@ -3476,7 +3474,7 @@ private static Action CheckCoroutineDef(Action checkFuncDe private static void CheckDecorators(Action[] decorators, DecoratorStatement foundDecorators) { if (decorators != null) { Assert.AreEqual(decorators.Length, foundDecorators.Decorators.Length); - for (int i = 0; i < decorators.Length; i++) { + for (var i = 0; i < decorators.Length; i++) { decorators[i](foundDecorators.Decorators[i]); } } else { @@ -3495,7 +3493,7 @@ private static Action CheckClassDef(string name, Action bo if (bases != null) { Assert.AreEqual(bases.Length, classDef.Bases.Length); - for (int i = 0; i < bases.Length; i++) { + for (var i = 0; i < bases.Length; i++) { bases[i](classDef.Bases[i]); } } else { @@ -3533,7 +3531,7 @@ private static Action CheckSublistParameter(params string[] names) { var sublistParam = (SublistParameter)param; Assert.AreEqual(names.Length, sublistParam.Tuple.Items.Count); - for (int i = 0; i < names.Length; i++) { + for (var i = 0; i < names.Length; i++) { Assert.AreEqual(names[i], ((NameExpression)sublistParam.Tuple.Items[i]).Name); } }; @@ -3546,7 +3544,7 @@ private static Action CheckBinaryStmt(Action lhs, PythonO private static Action CheckBinaryExpression(Action lhs, PythonOperator op, Action rhs) { return expr => { Assert.AreEqual(typeof(BinaryExpression), expr.GetType()); - BinaryExpression bin = (BinaryExpression)expr; + var bin = (BinaryExpression)expr; Assert.AreEqual(bin.Operator, op); lhs(bin.Left); rhs(bin.Right); @@ -3588,7 +3586,7 @@ private static Action CheckAwaitExpression(Action value) private static Action CheckAndExpression(Action lhs, Action rhs) { return expr => { Assert.AreEqual(typeof(AndExpression), expr.GetType()); - AndExpression bin = (AndExpression)expr; + var bin = (AndExpression)expr; lhs(bin.Left); rhs(bin.Right); }; @@ -3597,7 +3595,7 @@ private static Action CheckAndExpression(Action lhs, Act private static Action CheckOrExpression(Action lhs, Action rhs) { return expr => { Assert.AreEqual(typeof(OrExpression), expr.GetType()); - OrExpression bin = (OrExpression)expr; + var bin = (OrExpression)expr; lhs(bin.Left); rhs(bin.Right); }; @@ -3614,7 +3612,7 @@ private static Action CheckCallExpression(Action target, target(call.Target); Assert.AreEqual(args.Length, call.Args.Count); - for (int i = 0; i < args.Length; i++) { + for (var i = 0; i < args.Length; i++) { args[i](call.Args[i]); } }; @@ -3694,7 +3692,7 @@ private static Action CheckNameStmt(string name) { private static Action PositionalArg(Action value) { return arg => { - Assert.AreEqual(true, String.IsNullOrEmpty(arg.Name)); + Assert.AreEqual(true, string.IsNullOrEmpty(arg.Name)); value(arg.Expression); }; } @@ -3737,7 +3735,7 @@ private static Action CheckDictionaryExpr(params Action CheckTupleExpr(params Action[] ite var tupleExpr = (TupleExpression)expr; Assert.AreEqual(items.Length, tupleExpr.Items.Count); - for (int i = 0; i < tupleExpr.Items.Count; i++) { + for (var i = 0; i < tupleExpr.Items.Count; i++) { items[i](tupleExpr.Items[i]); } }; @@ -3779,7 +3777,7 @@ private static Action CheckListExpr(params Action[] item var listExpr = (ListExpression)expr; Assert.AreEqual(items.Length, listExpr.Items.Count); - for (int i = 0; i < listExpr.Items.Count; i++) { + for (var i = 0; i < listExpr.Items.Count; i++) { items[i](listExpr.Items[i]); } }; @@ -3795,7 +3793,7 @@ private static Action CheckAssignment(Action[] lhs, Actio var assign = (AssignmentStatement)expr; Assert.AreEqual(assign.Left.Count, lhs.Length); - for (int i = 0; i < lhs.Length; i++) { + for (var i = 0; i < lhs.Length; i++) { lhs[i](assign.Left[i]); } rhs(assign.Right); @@ -3882,7 +3880,7 @@ private Action CheckWithStmt(Action[] expr, Action CheckConstant(object value, string expectedRep if (value is byte[]) { Assert.AreEqual(typeof(AsciiString), ((ConstantExpression)expr).Value.GetType()); - byte[] b1 = (byte[])value; - byte[] b2 = ((AsciiString)((ConstantExpression)expr).Value).Bytes.ToArray(); + var b1 = (byte[])value; + var b2 = ((AsciiString)((ConstantExpression)expr).Value).Bytes.ToArray(); Assert.AreEqual(b1.Length, b2.Length); - for (int i = 0; i < b1.Length; i++) { + for (var i = 0; i < b1.Length; i++) { Assert.AreEqual(b1[i], b2[i]); } } else { @@ -3936,7 +3934,7 @@ private Action CheckDelStmt(params Action[] deletes) { var del = (DelStatement)stmt; Assert.AreEqual(deletes.Length, del.Expressions.Count); - for (int i = 0; i < deletes.Length; i++) { + for (var i = 0; i < deletes.Length; i++) { deletes[i](del.Expressions[i]); } }; @@ -3967,7 +3965,7 @@ private Action CheckGlobal(params string[] names) { var global = (GlobalStatement)stmt; Assert.AreEqual(names.Length, global.Names.Count); - for (int i = 0; i < names.Length; i++) { + for (var i = 0; i < names.Length; i++) { Assert.AreEqual(names[i], global.Names[i].Name); } }; @@ -3979,15 +3977,14 @@ private Action CheckNonlocal(params string[] names) { var nonlocal = (NonlocalStatement)stmt; Assert.AreEqual(names.Length, nonlocal.Names.Count); - for (int i = 0; i < names.Length; i++) { + for (var i = 0; i < names.Length; i++) { Assert.AreEqual(names[i], nonlocal.Names[i].Name); } }; } - private Action CheckStrOrBytesStmt(PythonLanguageVersion version, string str) { - return CheckExprStmt(CheckStrOrBytes(version, str)); - } + private Action CheckStrOrBytesStmt(PythonLanguageVersion version, string str) + => CheckExprStmt(CheckStrOrBytes(version, str)); private Action CheckStrOrBytes(PythonLanguageVersion version, string str) { return expr => { @@ -4033,7 +4030,7 @@ private Action CheckListComp(Action item, params Action< Assert.AreEqual(iterators.Length, listComp.Iterators.Count); item(listComp.Item); - for (int i = 0; i < iterators.Length; i++) { + for (var i = 0; i < iterators.Length; i++) { iterators[i](listComp.Iterators[i]); } }; @@ -4047,7 +4044,7 @@ private Action CheckGeneratorComp(Action item, params Ac Assert.AreEqual(iterators.Length, listComp.Iterators.Count); item(listComp.Item); - for (int i = 0; i < iterators.Length; i++) { + for (var i = 0; i < iterators.Length; i++) { iterators[i](listComp.Iterators[i]); } }; @@ -4063,7 +4060,7 @@ private Action CheckDictComp(Action key, Action CheckSetComp(Action item, params Action CheckSetLiteral(params Action[] values) { var setLiteral = (SetExpression)expr; Assert.AreEqual(values.Length, setLiteral.Items.Count); - for (int i = 0; i < values.Length; i++) { + for (var i = 0; i < values.Length; i++) { values[i](setLiteral.Items[i]); } }; @@ -4128,8 +4125,8 @@ private Action CompIf(Action test) { } private byte[] ToBytes(string str) { - byte[] res = new byte[str.Length]; - for (int i = 0; i < str.Length; i++) { + var res = new byte[str.Length]; + for (var i = 0; i < str.Length; i++) { res[i] = (byte)str[i]; } return res; @@ -4143,15 +4140,15 @@ private static Action IgnoreStmt() { return stmt => { }; } - private static Action[] NoParameters = new Action[0]; + private static readonly Action[] NoParameters = new Action[0]; private static void CollectFiles(string dir, List files, IEnumerable exceptions = null) { - foreach (string file in Directory.GetFiles(dir)) { + foreach (var file in Directory.GetFiles(dir)) { if (file.EndsWithOrdinal(".py", ignoreCase: true)) { files.Add(file); } } - foreach (string nestedDir in Directory.GetDirectories(dir)) { + foreach (var nestedDir in Directory.GetDirectories(dir)) { if (exceptions == null || !exceptions.Contains(Path.GetFileName(nestedDir))) { CollectFiles(nestedDir, files, exceptions); } diff --git a/src/Analysis/Engine/Test/PythonInstallPathResolver.cs b/src/Parsing/Test/PythonInstallPathResolver.cs similarity index 87% rename from src/Analysis/Engine/Test/PythonInstallPathResolver.cs rename to src/Parsing/Test/PythonInstallPathResolver.cs index 0add4dbbe..31676648e 100644 --- a/src/Analysis/Engine/Test/PythonInstallPathResolver.cs +++ b/src/Parsing/Test/PythonInstallPathResolver.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,16 +8,15 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Runtime.InteropServices; -using Microsoft.PythonTools.Interpreter; +using Microsoft.Python.Analysis.Core.Interpreter; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Parsing.Tests { public static class PythonInstallPathResolver { private static readonly Lazy _instance = new Lazy(() => { switch (Environment.OSVersion.Platform) { @@ -41,4 +39,4 @@ public interface IPythonInstallPathResolver { InterpreterConfiguration GetCondaPythonConfiguration(InterpreterArchitecture architecture, Version version); InterpreterConfiguration GetIronPythonConfiguration(bool x64); } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/PythonVersion.cs b/src/Parsing/Test/PythonVersion.cs similarity index 85% rename from src/Analysis/Engine/Test/PythonVersion.cs rename to src/Parsing/Test/PythonVersion.cs index 4dea24e40..a0d7be0ac 100644 --- a/src/Analysis/Engine/Test/PythonVersion.cs +++ b/src/Parsing/Test/PythonVersion.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,15 +8,14 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Analysis.Core.Interpreter; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Parsing.Tests { public class PythonVersion { public readonly InterpreterConfiguration Configuration; public readonly bool IsCPython; diff --git a/src/Analysis/Engine/Test/PythonVersionExtensions.cs b/src/Parsing/Test/PythonVersionExtensions.cs similarity index 88% rename from src/Analysis/Engine/Test/PythonVersionExtensions.cs rename to src/Parsing/Test/PythonVersionExtensions.cs index e5107bdfa..3506f408d 100644 --- a/src/Analysis/Engine/Test/PythonVersionExtensions.cs +++ b/src/Parsing/Test/PythonVersionExtensions.cs @@ -9,16 +9,16 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System.IO; -using Microsoft.PythonTools.Interpreter; +using Microsoft.Python.Analysis.Core.Interpreter; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Parsing.Tests { public static class PythonVersionExtensions { public static void AssertInstalled(this InterpreterConfiguration self) { if(self == null || !File.Exists(self.InterpreterPath)) { @@ -26,4 +26,4 @@ public static void AssertInstalled(this InterpreterConfiguration self) { } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/PythonVersions.cs b/src/Parsing/Test/PythonVersions.cs similarity index 97% rename from src/Analysis/Engine/Test/PythonVersions.cs rename to src/Parsing/Test/PythonVersions.cs index bd1e1b2b8..bebec8bb5 100644 --- a/src/Analysis/Engine/Test/PythonVersions.cs +++ b/src/Parsing/Test/PythonVersions.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -17,11 +16,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.PythonTools.Interpreter; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Analysis.Core.Interpreter; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Parsing.Tests { public static class PythonVersions { public static readonly InterpreterConfiguration Python27 = GetCPythonVersion(PythonLanguageVersion.V27, InterpreterArchitecture.x86); public static readonly InterpreterConfiguration Python35 = GetCPythonVersion(PythonLanguageVersion.V35, InterpreterArchitecture.x86); @@ -159,4 +157,4 @@ private static InterpreterConfiguration NotInstalled(string version) { return null; } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/TestExpressions.cs b/src/Parsing/Test/TestExpressions.cs similarity index 93% rename from src/Analysis/Engine/Test/TestExpressions.cs rename to src/Parsing/Test/TestExpressions.cs index 0168948f4..e767b9747 100644 --- a/src/Analysis/Engine/Test/TestExpressions.cs +++ b/src/Parsing/Test/TestExpressions.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -19,13 +19,9 @@ using System.Linq; using System.Text; -namespace AnalysisTests { +namespace Microsoft.Python.Parsing.Tests { public static class TestExpressions { - public static IEnumerable Snippets2x { - get { - return Expressions.Concat(Statements2x); - } - } + public static IEnumerable Snippets2x => Expressions.Concat(Statements2x); public static readonly string[] Expressions = new[] { // expressions diff --git a/src/Analysis/Engine/Test/TokenizerRoundTripTest.cs b/src/Parsing/Test/TokenizerRoundTripTest.cs similarity index 98% rename from src/Analysis/Engine/Test/TokenizerRoundTripTest.cs rename to src/Parsing/Test/TokenizerRoundTripTest.cs index 9be9d4d66..22a45441d 100644 --- a/src/Analysis/Engine/Test/TokenizerRoundTripTest.cs +++ b/src/Parsing/Test/TokenizerRoundTripTest.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -18,11 +18,11 @@ using System.Collections.Generic; using System.IO; using System.Text; -using Microsoft.PythonTools.Parsing; +using Microsoft.Python.Core.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using TestUtilities; -namespace AnalysisTests { +namespace Microsoft.Python.Parsing.Tests { /// /// Test cases to verify that the tokenizer successfully preserves all information for round tripping source code. /// diff --git a/src/Analysis/Engine/Test/UnixPythonInstallPathResolver.cs b/src/Parsing/Test/UnixPythonInstallPathResolver.cs similarity index 97% rename from src/Analysis/Engine/Test/UnixPythonInstallPathResolver.cs rename to src/Parsing/Test/UnixPythonInstallPathResolver.cs index 7d4e9ef57..e1716ab99 100644 --- a/src/Analysis/Engine/Test/UnixPythonInstallPathResolver.cs +++ b/src/Parsing/Test/UnixPythonInstallPathResolver.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -20,9 +19,9 @@ using System.IO; using System.Linq; using System.Text.RegularExpressions; -using Microsoft.PythonTools.Interpreter; +using Microsoft.Python.Analysis.Core.Interpreter; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Parsing.Tests { internal class UnixPythonInstallPathResolver : IPythonInstallPathResolver { private static readonly Regex _pythonNameRegex = new Regex(@"^python(\d+(.\d+)?)?$", RegexOptions.Compiled); private readonly Dictionary _coreCache; @@ -132,4 +131,4 @@ private static string[] RunPythonAndGetOutput(string pythonFilePath, string argu } } } -} \ No newline at end of file +} diff --git a/src/Analysis/Engine/Test/WindowsPythonInstallPathResolver.cs b/src/Parsing/Test/WindowsPythonInstallPathResolver.cs similarity index 97% rename from src/Analysis/Engine/Test/WindowsPythonInstallPathResolver.cs rename to src/Parsing/Test/WindowsPythonInstallPathResolver.cs index d9694867c..abcc3d445 100644 --- a/src/Analysis/Engine/Test/WindowsPythonInstallPathResolver.cs +++ b/src/Parsing/Test/WindowsPythonInstallPathResolver.cs @@ -1,5 +1,4 @@ -// Python Tools for Visual Studio -// Copyright(c) Microsoft Corporation +// Copyright(c) Microsoft Corporation // All rights reserved. // // Licensed under the Apache License, Version 2.0 (the License); you may not use @@ -9,7 +8,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -20,11 +19,12 @@ using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using Microsoft.PythonTools.Analysis.Infrastructure; -using Microsoft.PythonTools.Interpreter; +using Microsoft.Python.Analysis.Core.Interpreter; +using Microsoft.Python.Core; +using Microsoft.Python.Core.IO; using Microsoft.Win32; -namespace Microsoft.PythonTools.Analysis { +namespace Microsoft.Python.Parsing.Tests { internal sealed class WindowsPythonInstallPathResolver : IPythonInstallPathResolver { private readonly List _registryCache; @@ -274,4 +274,4 @@ public static ProcessorArchitecture GetBinaryType(string path) { return ProcessorArchitecture.None; } } -} \ No newline at end of file +} diff --git a/src/UnitTests/Core/Impl/AssemblyExtensions.cs b/src/UnitTests/Core/Impl/AssemblyExtensions.cs index 4d34293c6..4c4955e07 100644 --- a/src/UnitTests/Core/Impl/AssemblyExtensions.cs +++ b/src/UnitTests/Core/Impl/AssemblyExtensions.cs @@ -9,14 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.IO; -using System.Linq; using System.Reflection; namespace TestUtilities { diff --git a/src/UnitTests/Core/Impl/AssemblyLoader.cs b/src/UnitTests/Core/Impl/AssemblyLoader.cs index 409f7ba3d..8f76d984d 100644 --- a/src/UnitTests/Core/Impl/AssemblyLoader.cs +++ b/src/UnitTests/Core/Impl/AssemblyLoader.cs @@ -9,13 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/src/UnitTests/Core/Impl/Ben.Demystifier/ILReader.cs b/src/UnitTests/Core/Impl/Ben.Demystifier/ILReader.cs index 706a5932a..2a75c8e32 100644 --- a/src/UnitTests/Core/Impl/Ben.Demystifier/ILReader.cs +++ b/src/UnitTests/Core/Impl/Ben.Demystifier/ILReader.cs @@ -12,7 +12,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/UnitTests/Core/Impl/Ben.Demystifier/StringBuilderExtensions.cs b/src/UnitTests/Core/Impl/Ben.Demystifier/StringBuilderExtensions.cs index 4eb700108..f2cfa0105 100644 --- a/src/UnitTests/Core/Impl/Ben.Demystifier/StringBuilderExtensions.cs +++ b/src/UnitTests/Core/Impl/Ben.Demystifier/StringBuilderExtensions.cs @@ -12,7 +12,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. @@ -119,7 +119,7 @@ private static void AppendMethod(this StringBuilder builder, ResolvedMethod meth if (method.IsLambda) { builder.Append(" => { }"); - if (method.Ordinal.HasValue){ + if (method.Ordinal.HasValue) { builder.Append(" ["); builder.Append(method.Ordinal); builder.Append("]"); @@ -131,8 +131,9 @@ private static void AppendMethod(this StringBuilder builder, ResolvedMethod meth public static StringBuilder AppendMethodName(this StringBuilder stringBuilder, string name, string declaringTypeName, bool isSubMethodOrLambda) { if (!string.IsNullOrEmpty(declaringTypeName)) { if (name == ".ctor") { - if (!isSubMethodOrLambda) + if (!isSubMethodOrLambda) { stringBuilder.Append("new "); + } stringBuilder.Append(declaringTypeName); } else if (name == ".cctor") { @@ -188,7 +189,7 @@ private static StringBuilder AppendParameter(this StringBuilder stringBuilder, R return stringBuilder; } - + private static bool ShowInStackTrace(MethodBase method) { try { var type = method.DeclaringType; @@ -411,7 +412,10 @@ private static bool TryResolveGeneratedName(ref MethodBase method switch (kind) { case GeneratedNameKind.LocalFunction: { var localNameStart = generatedName.IndexOf((char)kind, closeBracketOffset + 1); - if (localNameStart < 0) break; + if (localNameStart < 0) { + break; + } + localNameStart += 3; if (localNameStart < generatedName.Length) { @@ -436,10 +440,14 @@ private static bool TryResolveGeneratedName(ref MethodBase method var matchName = methodName; var candidateMethods = dt.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName); - if (TryResolveSourceMethod(candidateMethods, kind, matchHint, ref method, ref type, out ordinal)) return true; + if (TryResolveSourceMethod(candidateMethods, kind, matchHint, ref method, ref type, out ordinal)) { + return true; + } var candidateConstructors = dt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName); - if (TryResolveSourceMethod(candidateConstructors, kind, matchHint, ref method, ref type, out ordinal)) return true; + if (TryResolveSourceMethod(candidateConstructors, kind, matchHint, ref method, ref type, out ordinal)) { + return true; + } const int MaxResolveDepth = 10; for (var i = 0; i < MaxResolveDepth; i++) { @@ -449,15 +457,18 @@ private static bool TryResolveGeneratedName(ref MethodBase method } candidateMethods = dt.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName); - if (TryResolveSourceMethod(candidateMethods, kind, matchHint, ref method, ref type, out ordinal)) return true; + if (TryResolveSourceMethod(candidateMethods, kind, matchHint, ref method, ref type, out ordinal)) { + return true; + } candidateConstructors = dt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName); - if (TryResolveSourceMethod(candidateConstructors, kind, matchHint, ref method, ref type, out ordinal)) return true; + if (TryResolveSourceMethod(candidateConstructors, kind, matchHint, ref method, ref type, out ordinal)) { + return true; + } if (methodName == ".cctor") { candidateConstructors = dt.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly).Where(m => m.Name == matchName); - foreach (var cctor in candidateConstructors) - { + foreach (var cctor in candidateConstructors) { method = cctor; type = dt; return true; @@ -559,9 +570,14 @@ private static string GetMatchHint(GeneratedNameKind kind, MethodBase method) { switch (kind) { case GeneratedNameKind.LocalFunction: var start = methodName.IndexOf("|", StringComparison.Ordinal); - if (start < 1) return null; + if (start < 1) { + return null; + } + var end = methodName.IndexOf("_", start, StringComparison.Ordinal) + 1; - if (end <= start) return null; + if (end <= start) { + return null; + } return methodName.Substring(start, end - start); default: @@ -587,7 +603,7 @@ private static bool TryParseGeneratedName(string name, out GeneratedNameKind kin if (closeBracketOffset >= 0 && closeBracketOffset + 1 < name.Length) { int c = name[closeBracketOffset + 1]; // Note '0' is not special. - if ((c >= '1' && c <= '9') || (c >= 'a' && c <= 'z')) { + if ((c >= '1' && c <= '9') || (c >= 'a' && c <= 'z')) { kind = (GeneratedNameKind)c; return true; } @@ -599,7 +615,7 @@ private static bool TryParseGeneratedName(string name, out GeneratedNameKind kin closeBracketOffset = -1; return false; } - + private static int IndexOfBalancedParenthesis(string str, int openingOffset, char closing) { var opening = str[openingOffset]; @@ -792,4 +808,4 @@ public ResolvedParameter(string name, string type, Type resolvedType, string pre } } } -} \ No newline at end of file +} diff --git a/src/UnitTests/Core/Impl/Ben.Demystifier/TypeNameHelper.cs b/src/UnitTests/Core/Impl/Ben.Demystifier/TypeNameHelper.cs index 2a0e0f85a..e3f9eb6cf 100644 --- a/src/UnitTests/Core/Impl/Ben.Demystifier/TypeNameHelper.cs +++ b/src/UnitTests/Core/Impl/Ben.Demystifier/TypeNameHelper.cs @@ -15,7 +15,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/UnitTests/Core/Impl/EventTaskSource.cs b/src/UnitTests/Core/Impl/EventTaskSource.cs index cf4ab3876..eb7fa322d 100644 --- a/src/UnitTests/Core/Impl/EventTaskSource.cs +++ b/src/UnitTests/Core/Impl/EventTaskSource.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/UnitTests/Core/Impl/FluentAssertions/CollectionAssertionsExtensions.cs b/src/UnitTests/Core/Impl/FluentAssertions/CollectionAssertionsExtensions.cs index 453af3a7a..4ddcf50d9 100644 --- a/src/UnitTests/Core/Impl/FluentAssertions/CollectionAssertionsExtensions.cs +++ b/src/UnitTests/Core/Impl/FluentAssertions/CollectionAssertionsExtensions.cs @@ -9,14 +9,12 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. -using System; using System.Collections.Generic; -using System.Linq; using FluentAssertions; using FluentAssertions.Collections; diff --git a/src/UnitTests/Core/Impl/MSTest/PermutationalTestMethodAttribute.cs b/src/UnitTests/Core/Impl/MSTest/PermutationalTestMethodAttribute.cs index 8f22e0ecd..524c7da90 100644 --- a/src/UnitTests/Core/Impl/MSTest/PermutationalTestMethodAttribute.cs +++ b/src/UnitTests/Core/Impl/MSTest/PermutationalTestMethodAttribute.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Reflection; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -81,4 +80,4 @@ private int[] MakePermutationPlusOne(int[] permutation, int insertIndex) { return permutationPlusOne; } } -} \ No newline at end of file +} diff --git a/src/UnitTests/Core/Impl/PathUtils.cs b/src/UnitTests/Core/Impl/PathUtils.cs index 2cbd98df8..eb6752ec9 100644 --- a/src/UnitTests/Core/Impl/PathUtils.cs +++ b/src/UnitTests/Core/Impl/PathUtils.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/UnitTests/Core/Impl/TaskObserver.cs b/src/UnitTests/Core/Impl/TaskObserver.cs index b657ab97c..73041992f 100644 --- a/src/UnitTests/Core/Impl/TaskObserver.cs +++ b/src/UnitTests/Core/Impl/TaskObserver.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. diff --git a/src/UnitTests/Core/Impl/TestData.cs b/src/UnitTests/Core/Impl/TestData.cs index c5f033dbd..3b67963b9 100644 --- a/src/UnitTests/Core/Impl/TestData.cs +++ b/src/UnitTests/Core/Impl/TestData.cs @@ -9,14 +9,13 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License. using System; using System.IO; -using System.Linq; using System.Reflection; using System.Text; using System.Threading; @@ -28,7 +27,7 @@ public static class TestData { private static readonly AsyncLocal TestRunScopeAsyncLocal = new AsyncLocal(); private static string GetRootDir() { - var dir = PathUtils.GetParent((typeof(TestData)).Assembly.Location); + var dir = PathUtils.GetParent(typeof(TestData).Assembly.Location); while (!string.IsNullOrEmpty(dir) && Directory.Exists(dir) && !File.Exists(PathUtils.GetAbsoluteFilePath(dir, "build.root"))) { diff --git a/src/UnitTests/Core/Impl/TestEnvironmentImpl.cs b/src/UnitTests/Core/Impl/TestEnvironmentImpl.cs index 844c8659e..db1d02cc0 100644 --- a/src/UnitTests/Core/Impl/TestEnvironmentImpl.cs +++ b/src/UnitTests/Core/Impl/TestEnvironmentImpl.cs @@ -9,7 +9,7 @@ // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -// MERCHANTABLITY OR NON-INFRINGEMENT. +// MERCHANTABILITY OR NON-INFRINGEMENT. // // See the Apache Version 2.0 License for specific language governing // permissions and limitations under the License.