@zzzen/pyright-internal 1.2.0-dev.20221016 → 1.2.0-dev.20221204
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +7 -9
- package/dist/analyzer/backgroundAnalysisProgram.js +14 -52
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +43 -32
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +15 -3
- package/dist/analyzer/checker.js +260 -143
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +2 -2
- package/dist/analyzer/codeFlowEngine.js +85 -88
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +1 -0
- package/dist/analyzer/codeFlowTypes.js +3 -1
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +11 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +3 -3
- package/dist/analyzer/dataClasses.js +92 -59
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +6 -4
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +7 -5
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +3 -0
- package/dist/analyzer/importResolver.js +50 -8
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.d.ts +1 -0
- package/dist/analyzer/namedTuples.js +1 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.d.ts +2 -1
- package/dist/analyzer/packageTypeVerifier.js +16 -10
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -1
- package/dist/analyzer/parseTreeUtils.js +38 -3
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +86 -79
- package/dist/analyzer/parseTreeWalker.js +384 -201
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/program.d.ts +4 -7
- package/dist/analyzer/program.js +84 -79
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +10 -3
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +1 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/regions.d.ts +11 -0
- package/dist/analyzer/regions.js +57 -0
- package/dist/analyzer/regions.js.map +1 -0
- package/dist/analyzer/service.d.ts +11 -6
- package/dist/analyzer/service.js +127 -65
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +5 -2
- package/dist/analyzer/sourceFile.js +23 -10
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.d.ts +6 -1
- package/dist/analyzer/sourceMapper.js +28 -5
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/sourceMapperUtils.d.ts +2 -1
- package/dist/analyzer/sourceMapperUtils.js +17 -5
- package/dist/analyzer/sourceMapperUtils.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +19 -9
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/symbolUtils.d.ts +1 -0
- package/dist/analyzer/symbolUtils.js +5 -1
- package/dist/analyzer/symbolUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +664 -257
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +16 -4
- package/dist/analyzer/typeGuards.js +9 -0
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +3 -1
- package/dist/analyzer/typePrinter.js +143 -28
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +5 -1
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -2
- package/dist/analyzer/typeUtils.js +114 -20
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +8 -6
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +7 -5
- package/dist/analyzer/types.js +45 -20
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +6 -4
- package/dist/backgroundAnalysisBase.js +30 -9
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +2 -1
- package/dist/backgroundThreadBase.js +4 -0
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/createTypeStub.js +3 -1
- package/dist/commands/createTypeStub.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +4 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/core.d.ts +2 -0
- package/dist/common/core.js +24 -3
- package/dist/common/core.js.map +1 -1
- package/dist/common/diagnostic.d.ts +8 -0
- package/dist/common/diagnostic.js +5 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +2 -1
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.d.ts +1 -0
- package/dist/common/pathUtils.js +17 -4
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +1 -1
- package/dist/common/pythonVersion.js +1 -1
- package/dist/common/realFileSystem.js +12 -3
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +6 -1
- package/dist/common/workspaceEditUtils.js +72 -1
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +16 -8
- package/dist/languageServerBase.js +76 -32
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +6 -2
- package/dist/languageService/analyzerServiceExecutor.js +8 -6
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.js +2 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/codeActionProvider.js +30 -0
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -0
- package/dist/languageService/completionProvider.js +84 -32
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +3 -0
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +7 -3
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +1 -1
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -1
- package/dist/languageService/hoverProvider.js +73 -38
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.d.ts +3 -0
- package/dist/languageService/indentationUtils.js +4 -3
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/referencesProvider.js +2 -1
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +1 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +30 -19
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +29 -4
- package/dist/localization/localize.js +20 -5
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +18 -3
- package/dist/parser/parseNodes.d.ts +2 -1
- package/dist/parser/parseNodes.js +6 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.js +29 -15
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +19 -9
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyright.js +4 -4
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -0
- package/dist/pyrightFileSystem.js +3 -0
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -0
- package/dist/readonlyAugmentedFileSystem.js +3 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +2 -0
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +26 -3
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +11 -0
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnostics.test.d.ts +1 -0
- package/dist/tests/diagnostics.test.js +37 -0
- package/dist/tests/diagnostics.test.js.map +1 -0
- package/dist/tests/docStringConversion.test.js +71 -12
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +5 -5
- package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.classVariable.fourslash.js +119 -24
- package/dist/tests/fourslash/completions.classVariable.fourslash.js.map +1 -1
- package/dist/tests/fourslash/{signature.paramspec.fourslash.d.ts → completions.dunderNew.Inheritance.fourslash.d.ts} +0 -0
- package/dist/tests/fourslash/completions.dunderNew.Inheritance.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.dunderNew.Inheritance.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.dunderNew.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.dunderNew.fourslash.js +20 -0
- package/dist/tests/fourslash/completions.dunderNew.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.libStub.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.localCode.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.plainText.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.self.fourslash.js +2 -2
- package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js +2 -2
- package/dist/tests/fourslash/findDefinitions.namespaceImport.fourslash.js.map +1 -1
- package/dist/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.js +32 -0
- package/dist/tests/fourslash/findDefinitions.namespaceImportWithInit.fourslash.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +2 -1
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +4 -4
- package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docstring.alias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.docstring.alias.fourslash.js +24 -0
- package/dist/tests/fourslash/hover.docstring.alias.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.docstring.links.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js +3 -3
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js +13 -0
- package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js +15 -0
- package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js +21 -0
- package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js +17 -0
- package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js +15 -0
- package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +3 -3
- package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +2 -2
- package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.libStub.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.plainText.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +1 -1
- package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -1
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +1 -1
- package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -1
- package/dist/tests/fourslash/shadowedImports.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/shadowedImports.fourslash.js +75 -0
- package/dist/tests/fourslash/shadowedImports.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.dunderNew.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.dunderNew.fourslash.js +24 -0
- package/dist/tests/fourslash/signature.dunderNew.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/runner.js +1 -1
- package/dist/tests/harness/fourslash/runner.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +3 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +5 -4
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +7 -7
- package/dist/tests/harness/fourslash/testState.js +79 -163
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.d.ts +16 -0
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +159 -0
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -0
- package/dist/tests/harness/vfs/filesystem.d.ts +1 -0
- package/dist/tests/harness/vfs/filesystem.js +3 -0
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/indentationUtils.ptvs.test.js +1 -1
- package/dist/tests/indentationUtils.test.js +4 -4
- package/dist/tests/ipythonMode.test.js +39 -0
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/logger.test.js +3 -1
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/parser.test.js +3 -3
- package/dist/tests/pathUtils.test.js +7 -0
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/service.test.d.ts +1 -0
- package/dist/tests/service.test.js +159 -0
- package/dist/tests/service.test.js.map +1 -0
- package/dist/tests/sourceFile.test.js +34 -1
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +39 -4
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +6 -2
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +16 -6
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +15 -3
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +51 -11
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +11 -7
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +48 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typePrinter.test.d.ts +1 -0
- package/dist/tests/typePrinter.test.js +148 -0
- package/dist/tests/typePrinter.test.js.map +1 -0
- package/dist/tests/workspaceEditUtils.test.d.ts +1 -0
- package/dist/tests/workspaceEditUtils.test.js +167 -0
- package/dist/tests/workspaceEditUtils.test.js.map +1 -0
- package/dist/workspaceMap.d.ts +4 -1
- package/dist/workspaceMap.js +64 -16
- package/dist/workspaceMap.js.map +1 -1
- package/package.json +3 -3
- package/dist/tests/fourslash/signature.paramspec.fourslash.js +0 -30
- package/dist/tests/fourslash/signature.paramspec.fourslash.js.map +0 -1
@@ -196,6 +196,9 @@ const maxEntriesToUseForInference = 64;
|
|
196
196
|
// when inferring its type? We need to cut it off at some point
|
197
197
|
// to avoid excessive computation.
|
198
198
|
const maxDeclarationsToUseForInference = 64;
|
199
|
+
// Maximum number of times to attempt effective type evaluation
|
200
|
+
// of a variable that has no type declaration.
|
201
|
+
const maxEffectiveTypeEvaluationAttempts = 16;
|
199
202
|
// Maximum number of combinatoric union type expansions allowed
|
200
203
|
// when resolving an overload.
|
201
204
|
const maxOverloadUnionExpansionCount = 64;
|
@@ -677,9 +680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
677
680
|
}
|
678
681
|
if (reportExpectingTypeErrors && !typeResult.isIncomplete) {
|
679
682
|
if (flags & 128 /* TypeVarTupleDisallowed */) {
|
680
|
-
if ((0, types_1.
|
681
|
-
typeResult.type.details.isVariadic &&
|
682
|
-
!typeResult.type.isVariadicInUnion) {
|
683
|
+
if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicInUnion) {
|
683
684
|
addError(localize_1.Localizer.Diagnostic.typeVarTupleContext(), node);
|
684
685
|
typeResult.type = types_1.UnknownType.create();
|
685
686
|
}
|
@@ -691,6 +692,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
691
692
|
if (!isEmptyVariadic) {
|
692
693
|
addExpectedClassDiagnostic(typeResult.type, node);
|
693
694
|
typeResult.type = types_1.UnknownType.create();
|
695
|
+
typeResult.typeErrors = true;
|
694
696
|
}
|
695
697
|
}
|
696
698
|
}
|
@@ -779,8 +781,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
779
781
|
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
780
782
|
}
|
781
783
|
else {
|
782
|
-
const
|
783
|
-
|
784
|
+
const iteratorTypeResult = (_a = getTypeOfIterator(iterTypeResult, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : {
|
785
|
+
type: types_1.UnknownType.create(!!iterTypeResult.isIncomplete),
|
786
|
+
isIncomplete: iterTypeResult.isIncomplete,
|
787
|
+
};
|
788
|
+
typeResult = {
|
789
|
+
type: iteratorTypeResult.type,
|
790
|
+
unpackedType: iterType,
|
791
|
+
isIncomplete: iteratorTypeResult.isIncomplete,
|
792
|
+
};
|
784
793
|
}
|
785
794
|
}
|
786
795
|
return typeResult;
|
@@ -869,17 +878,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
869
878
|
// the resulting formatted string is also LiteralString.
|
870
879
|
node.expressions.forEach((expr) => {
|
871
880
|
const exprType = getTypeOfExpression(expr).type;
|
872
|
-
|
881
|
+
(0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
|
882
|
+
if (!(0, types_1.isClassInstance)(exprSubtype)) {
|
883
|
+
isLiteralString = false;
|
884
|
+
return;
|
885
|
+
}
|
886
|
+
if (types_1.ClassType.isBuiltIn(exprSubtype, 'LiteralString')) {
|
887
|
+
return;
|
888
|
+
}
|
889
|
+
if (types_1.ClassType.isBuiltIn(exprSubtype, 'str') && exprSubtype.literalValue !== undefined) {
|
890
|
+
return;
|
891
|
+
}
|
873
892
|
isLiteralString = false;
|
874
|
-
|
875
|
-
}
|
876
|
-
if (types_1.ClassType.isBuiltIn(exprType, 'LiteralString')) {
|
877
|
-
return;
|
878
|
-
}
|
879
|
-
if (types_1.ClassType.isBuiltIn(exprType, 'str') && exprType.literalValue !== undefined) {
|
880
|
-
return;
|
881
|
-
}
|
882
|
-
isLiteralString = false;
|
893
|
+
});
|
883
894
|
});
|
884
895
|
if (!isBytes && isLiteralString) {
|
885
896
|
const literalStringType = getTypingType(node, 'LiteralString');
|
@@ -1092,6 +1103,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1092
1103
|
if ((0, typeUtils_1.isTupleClass)(type) && type.tupleTypeArguments) {
|
1093
1104
|
return (0, typeUtils_1.isUnboundedTupleClass)(type) || type.tupleTypeArguments.length === 0;
|
1094
1105
|
}
|
1106
|
+
// Handle subclasses of tuple, such as NamedTuple.
|
1107
|
+
const tupleBaseClass = type.details.mro.find((mroClass) => !(0, types_1.isClass)(mroClass) || (0, typeUtils_1.isTupleClass)(mroClass));
|
1108
|
+
if (tupleBaseClass && (0, types_1.isClass)(tupleBaseClass) && tupleBaseClass.tupleTypeArguments) {
|
1109
|
+
return (0, typeUtils_1.isUnboundedTupleClass)(tupleBaseClass) || tupleBaseClass.tupleTypeArguments.length === 0;
|
1110
|
+
}
|
1095
1111
|
// Check for Literal[False] and Literal[True].
|
1096
1112
|
if (types_1.ClassType.isBuiltIn(type, 'bool') && type.literalValue !== undefined) {
|
1097
1113
|
return type.literalValue === false;
|
@@ -1402,8 +1418,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1402
1418
|
case 7 /* Class */: {
|
1403
1419
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
1404
1420
|
let methodType;
|
1405
|
-
// Try to get the __init__ method first because it typically has
|
1406
|
-
//
|
1421
|
+
// Try to get the `__init__` method first because it typically has more
|
1422
|
+
// type information than `__new__`.
|
1407
1423
|
methodType = getBoundMethod(subtype, '__init__');
|
1408
1424
|
// Is this the __init__ method provided by the object class?
|
1409
1425
|
const isObjectInit = !!methodType &&
|
@@ -1413,7 +1429,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1413
1429
|
// If there was no `__init__` or the only `__init__` that was found
|
1414
1430
|
// was form the `object` class, see if we can find a better `__new__`
|
1415
1431
|
// method.
|
1416
|
-
if (!methodType ||
|
1432
|
+
if (!methodType ||
|
1433
|
+
isObjectInit ||
|
1434
|
+
isSkipConstructor ||
|
1435
|
+
(methodType &&
|
1436
|
+
(0, types_1.isFunction)(methodType) &&
|
1437
|
+
(types_1.FunctionType.hasDefaultParameters(methodType) ||
|
1438
|
+
methodType.details.parameters.length === 0))) {
|
1417
1439
|
const constructorType = getBoundMethod(subtype, '__new__',
|
1418
1440
|
/* recursionCount */ undefined,
|
1419
1441
|
/* treatConstructorAsClassMember */ true);
|
@@ -1615,14 +1637,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1615
1637
|
}
|
1616
1638
|
// Validates that the type is an iterator and returns the iterated type
|
1617
1639
|
// (i.e. the type returned from the '__next__' or '__anext__' method).
|
1618
|
-
function getTypeOfIterator(
|
1640
|
+
function getTypeOfIterator(typeResult, isAsync, errorNode) {
|
1619
1641
|
const iterMethodName = isAsync ? '__aiter__' : '__iter__';
|
1620
1642
|
const nextMethodName = isAsync ? '__anext__' : '__next__';
|
1621
1643
|
let isValidIterator = true;
|
1622
|
-
type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
|
1644
|
+
let type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(typeResult.type);
|
1623
1645
|
type = makeTopLevelTypeVarsConcrete(type);
|
1624
1646
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1625
|
-
if (errorNode) {
|
1647
|
+
if (errorNode && !typeResult.isIncomplete) {
|
1626
1648
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
|
1627
1649
|
}
|
1628
1650
|
type = (0, types_1.removeNoneFromUnion)(type);
|
@@ -1677,7 +1699,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1677
1699
|
return subtype;
|
1678
1700
|
}
|
1679
1701
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1680
|
-
|
1702
|
+
let nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
|
1681
1703
|
if (!nextReturnType) {
|
1682
1704
|
iterReturnTypeDiag.addMessage(localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
|
1683
1705
|
name: nextMethodName,
|
@@ -1685,6 +1707,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1685
1707
|
}));
|
1686
1708
|
}
|
1687
1709
|
else {
|
1710
|
+
// Convert any unpacked TypeVarTuples into object instances. We don't
|
1711
|
+
// know anything more about them.
|
1712
|
+
nextReturnType = (0, typeUtils_1.mapSubtypes)(nextReturnType, (returnSubtype) => {
|
1713
|
+
if ((0, types_1.isTypeVar)(returnSubtype) && (0, types_1.isUnpackedVariadicTypeVar)(returnSubtype)) {
|
1714
|
+
return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
|
1715
|
+
}
|
1716
|
+
return returnSubtype;
|
1717
|
+
});
|
1688
1718
|
if (!isAsync) {
|
1689
1719
|
return nextReturnType;
|
1690
1720
|
}
|
@@ -1704,21 +1734,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1704
1734
|
diag.addAddendum(iterReturnTypeDiag);
|
1705
1735
|
}
|
1706
1736
|
}
|
1707
|
-
if (errorNode) {
|
1737
|
+
if (errorNode && !typeResult.isIncomplete) {
|
1708
1738
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIterable().format({ type: printType(subtype) }) + diag.getString(), errorNode);
|
1709
1739
|
}
|
1710
1740
|
isValidIterator = false;
|
1711
1741
|
return undefined;
|
1712
1742
|
});
|
1713
|
-
return isValidIterator ? iterableType : undefined;
|
1743
|
+
return isValidIterator ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
|
1714
1744
|
}
|
1715
1745
|
// Validates that the type is an iterable and returns the iterable type argument.
|
1716
|
-
function getTypeOfIterable(
|
1746
|
+
function getTypeOfIterable(typeResult, isAsync, errorNode) {
|
1717
1747
|
const iterMethodName = isAsync ? '__aiter__' : '__iter__';
|
1718
1748
|
let isValidIterable = true;
|
1719
|
-
type = makeTopLevelTypeVarsConcrete(type);
|
1749
|
+
let type = makeTopLevelTypeVarsConcrete(typeResult.type);
|
1720
1750
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1721
|
-
if (errorNode) {
|
1751
|
+
if (errorNode && !typeResult.isIncomplete) {
|
1722
1752
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
|
1723
1753
|
}
|
1724
1754
|
type = (0, types_1.removeNoneFromUnion)(type);
|
@@ -1747,7 +1777,47 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1747
1777
|
isValidIterable = false;
|
1748
1778
|
return undefined;
|
1749
1779
|
});
|
1750
|
-
return isValidIterable ? iterableType : undefined;
|
1780
|
+
return isValidIterable ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
|
1781
|
+
}
|
1782
|
+
function isTypeHashable(type) {
|
1783
|
+
let isTypeHashable = true;
|
1784
|
+
(0, typeUtils_1.doForEachSubtype)(makeTopLevelTypeVarsConcrete(type), (subtype) => {
|
1785
|
+
if ((0, types_1.isClassInstance)(subtype)) {
|
1786
|
+
// Assume the class is hashable.
|
1787
|
+
let isObjectHashable = true;
|
1788
|
+
// Have we already computed and cached the hashability?
|
1789
|
+
if (subtype.details.isInstanceHashable !== undefined) {
|
1790
|
+
isObjectHashable = subtype.details.isInstanceHashable;
|
1791
|
+
}
|
1792
|
+
else {
|
1793
|
+
const hashMember = (0, typeUtils_1.lookUpObjectMember)(subtype, '__hash__', 4 /* SkipObjectBaseClass */);
|
1794
|
+
if (hashMember && hashMember.isTypeDeclared) {
|
1795
|
+
const decls = hashMember.symbol.getTypedDeclarations();
|
1796
|
+
const synthesizedType = hashMember.symbol.getSynthesizedType();
|
1797
|
+
// Handle the case where the type is synthesized (used for
|
1798
|
+
// dataclasses).
|
1799
|
+
if (synthesizedType) {
|
1800
|
+
isObjectHashable = !(0, types_1.isNoneInstance)(synthesizedType);
|
1801
|
+
}
|
1802
|
+
else {
|
1803
|
+
// Assume that if '__hash__' is declared as a variable, it is
|
1804
|
+
// not hashable. If it's declared as a function, it is. We'll
|
1805
|
+
// skip evaluating its full type because that's not needed in
|
1806
|
+
// this case.
|
1807
|
+
if (decls.every((decl) => decl.type === 1 /* Variable */)) {
|
1808
|
+
isObjectHashable = false;
|
1809
|
+
}
|
1810
|
+
}
|
1811
|
+
}
|
1812
|
+
// Cache the hashability for next time.
|
1813
|
+
subtype.details.isInstanceHashable = isObjectHashable;
|
1814
|
+
}
|
1815
|
+
if (!isObjectHashable) {
|
1816
|
+
isTypeHashable = false;
|
1817
|
+
}
|
1818
|
+
}
|
1819
|
+
});
|
1820
|
+
return isTypeHashable;
|
1751
1821
|
}
|
1752
1822
|
function getTypedDictClassType() {
|
1753
1823
|
return typedDictClassType;
|
@@ -1834,10 +1904,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1834
1904
|
const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode,
|
1835
1905
|
/* reference */ undefined,
|
1836
1906
|
/* targetSymbolId */ undefined,
|
1837
|
-
/*
|
1907
|
+
/* typeAtStart */ types_1.UnboundType.create(), {
|
1838
1908
|
skipNoReturnCallAnalysis: true,
|
1839
1909
|
});
|
1840
|
-
return codeFlowResult.type !== undefined;
|
1910
|
+
return codeFlowResult.type !== undefined && !(0, types_1.isNever)(codeFlowResult.type);
|
1841
1911
|
}
|
1842
1912
|
// Determines whether there is a code flow path from sourceNode to sinkNode.
|
1843
1913
|
function isFlowPathBetweenNodes(sourceNode, sinkNode, allowSelf = true) {
|
@@ -2158,6 +2228,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2158
2228
|
type = makeTopLevelTypeVarsConcrete(type);
|
2159
2229
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2160
2230
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2231
|
+
var _a, _b;
|
2161
2232
|
// Is this subtype a tuple?
|
2162
2233
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
2163
2234
|
if (tupleType && tupleType.tupleTypeArguments) {
|
@@ -2214,7 +2285,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2214
2285
|
else {
|
2215
2286
|
// The assigned expression isn't a tuple, so it had better
|
2216
2287
|
// be some iterable type.
|
2217
|
-
const iterableType = getTypeOfIterator(subtype, /* isAsync */ false, srcExpr) || types_1.UnknownType.create();
|
2288
|
+
const iterableType = (_b = (_a = getTypeOfIterator({ type: subtype, isIncomplete: isTypeIncomplete }, /* isAsync */ false, srcExpr)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
2218
2289
|
for (let index = 0; index < targetExpressions.length; index++) {
|
2219
2290
|
targetTypes[index].push((0, typeUtils_1.addConditionToType)(iterableType, (0, typeUtils_1.getTypeCondition)(subtype)));
|
2220
2291
|
}
|
@@ -2266,9 +2337,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2266
2337
|
return types_1.UnknownType.create();
|
2267
2338
|
}
|
2268
2339
|
}
|
2340
|
+
// If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
|
2341
|
+
// *tuple[*Ts].
|
2269
2342
|
if ((0, types_1.isVariadicTypeVar)(subtype)) {
|
2270
2343
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2271
|
-
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
2344
|
+
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
|
2272
2345
|
/* isTypeArgumentExplicit */ true,
|
2273
2346
|
/* isUnpackedTuple */ true));
|
2274
2347
|
}
|
@@ -2533,7 +2606,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2533
2606
|
if (!(0, typeUtils_1.derivesFromClassRecursive)(concreteSubtype, baseExceptionType,
|
2534
2607
|
/* ignoreUnknown */ false)) {
|
2535
2608
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
|
2536
|
-
type: printType(subtype
|
2609
|
+
type: printType(subtype),
|
2537
2610
|
}));
|
2538
2611
|
}
|
2539
2612
|
else {
|
@@ -2545,7 +2618,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2545
2618
|
});
|
2546
2619
|
if (callResult && callResult.argumentErrors) {
|
2547
2620
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeNotInstantiable().format({
|
2548
|
-
type: printType(subtype
|
2621
|
+
type: printType(subtype),
|
2549
2622
|
}));
|
2550
2623
|
}
|
2551
2624
|
}
|
@@ -2554,13 +2627,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2554
2627
|
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(concreteSubtype), baseExceptionType,
|
2555
2628
|
/* ignoreUnknown */ false)) {
|
2556
2629
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
|
2557
|
-
type: printType(subtype
|
2630
|
+
type: printType(subtype),
|
2558
2631
|
}));
|
2559
2632
|
}
|
2560
2633
|
}
|
2561
2634
|
else {
|
2562
2635
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
|
2563
|
-
type: printType(subtype
|
2636
|
+
type: printType(subtype),
|
2564
2637
|
}));
|
2565
2638
|
}
|
2566
2639
|
}
|
@@ -2642,7 +2715,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2642
2715
|
if (!classMember) {
|
2643
2716
|
return undefined;
|
2644
2717
|
}
|
2645
|
-
const
|
2718
|
+
const memberTypeResult = getTypeOfMemberInternal(classMember, objType);
|
2719
|
+
if (!memberTypeResult) {
|
2720
|
+
return undefined;
|
2721
|
+
}
|
2722
|
+
const memberType = memberTypeResult.type;
|
2646
2723
|
if ((0, types_1.isAnyOrUnknown)(memberType)) {
|
2647
2724
|
return memberType;
|
2648
2725
|
}
|
@@ -2684,6 +2761,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2684
2761
|
};
|
2685
2762
|
}
|
2686
2763
|
}
|
2764
|
+
// Does this name refer to a PEP 695-style type parameter?
|
2687
2765
|
const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
|
2688
2766
|
if (typeParamSymbol) {
|
2689
2767
|
symbol = typeParamSymbol;
|
@@ -2693,7 +2771,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2693
2771
|
else {
|
2694
2772
|
// Look for the scope that contains the value definition and
|
2695
2773
|
// see if it has a declared type.
|
2696
|
-
|
2774
|
+
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
|
2775
|
+
if (!symbolWithScope) {
|
2776
|
+
// If the node is part of a "from X import Y as Z" statement and the node
|
2777
|
+
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
2778
|
+
// since the non-aliased name is not in the symbol table.
|
2779
|
+
const alias = getAliasFromImport(node);
|
2780
|
+
if (alias) {
|
2781
|
+
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
|
2782
|
+
}
|
2783
|
+
}
|
2697
2784
|
if (symbolWithScope) {
|
2698
2785
|
let useCodeFlowAnalysis = !allowForwardReferences;
|
2699
2786
|
// If the symbol is implicitly imported from the builtin
|
@@ -2723,9 +2810,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2723
2810
|
// If the symbol is declared outside of our execution scope, use its effective
|
2724
2811
|
// type. If it's declared inside our execution scope, it generally starts
|
2725
2812
|
// as unbound at the start of the code flow.
|
2726
|
-
|
2727
|
-
|
2728
|
-
|
2813
|
+
let typeAtStart = effectiveType;
|
2814
|
+
if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
|
2815
|
+
typeAtStart = types_1.UnboundType.create();
|
2816
|
+
// Is this a module-level scope? If so, see if it's an alias of a builtin.
|
2817
|
+
if (symbolWithScope.scope.type === 3 /* Module */) {
|
2818
|
+
(0, debug_1.assert)(symbolWithScope.scope.parent);
|
2819
|
+
const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
|
2820
|
+
if (builtInSymbol) {
|
2821
|
+
const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
|
2822
|
+
typeAtStart = builtInEffectiveType.type;
|
2823
|
+
}
|
2824
|
+
}
|
2825
|
+
}
|
2729
2826
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol.id, typeAtStart,
|
2730
2827
|
/* startNode */ undefined, {
|
2731
2828
|
skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
|
@@ -2793,6 +2890,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2793
2890
|
}
|
2794
2891
|
if ((0, types_1.isTypeVar)(type) &&
|
2795
2892
|
!type.details.isParamSpec &&
|
2893
|
+
!type.isVariadicInUnion &&
|
2796
2894
|
(flags & 64 /* ExpectingType */) === 0 &&
|
2797
2895
|
type.details.name === name) {
|
2798
2896
|
// Handle the special case of a PEP 604 union. These can appear within
|
@@ -2956,7 +3054,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2956
3054
|
}
|
2957
3055
|
// If this type var is variadic, the name refers to the packed form. It
|
2958
3056
|
// must be unpacked in most contexts.
|
2959
|
-
if (
|
3057
|
+
if ((0, types_1.isUnpackedVariadicTypeVar)(type)) {
|
2960
3058
|
type = types_1.TypeVarType.cloneForPacked(type);
|
2961
3059
|
}
|
2962
3060
|
return type;
|
@@ -2983,11 +3081,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2983
3081
|
type.typeAliasInfo.typeParameters &&
|
2984
3082
|
type.typeAliasInfo.typeParameters.length > 0 &&
|
2985
3083
|
!type.typeAliasInfo.typeArguments) {
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
3084
|
+
let reportMissingTypeArguments = false;
|
3085
|
+
const defaultTypeArgs = [];
|
3086
|
+
type.typeAliasInfo.typeParameters.forEach((param) => {
|
3087
|
+
if (param.details.defaultType) {
|
3088
|
+
defaultTypeArgs.push(param.details.defaultType);
|
3089
|
+
}
|
3090
|
+
else {
|
3091
|
+
defaultTypeArgs.push(types_1.UnknownType.create());
|
3092
|
+
reportMissingTypeArguments = true;
|
3093
|
+
}
|
3094
|
+
});
|
3095
|
+
const typeVarContext = (0, typeUtils_1.buildTypeVarContext)(type.typeAliasInfo.typeParameters, defaultTypeArgs, type.typeAliasInfo.typeVarScopeId);
|
3096
|
+
if (reportMissingTypeArguments) {
|
3097
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportMissingTypeArgument, diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.Localizer.Diagnostic.typeArgsMissingForAlias().format({
|
3098
|
+
name: type.typeAliasInfo.name,
|
3099
|
+
}), node);
|
3100
|
+
}
|
3101
|
+
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, /* unknownIfNotFound */ true), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, defaultTypeArgs);
|
2991
3102
|
}
|
2992
3103
|
}
|
2993
3104
|
return type;
|
@@ -3131,9 +3242,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3131
3242
|
writeTypeCache(node.memberName, typeResult.type, flags, /* isIncomplete */ true);
|
3132
3243
|
// If the type is initially unbound, see if there's a parent class that
|
3133
3244
|
// potentially initialized the value.
|
3134
|
-
let
|
3135
|
-
let
|
3136
|
-
if ((0, types_1.isUnbound)(
|
3245
|
+
let typeAtStart = typeResult.type;
|
3246
|
+
let isTypeAtStartIncomplete = !!typeResult.isIncomplete;
|
3247
|
+
if ((0, types_1.isUnbound)(typeAtStart)) {
|
3137
3248
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
3138
3249
|
let classMemberInfo;
|
3139
3250
|
if ((0, types_1.isInstantiableClass)(baseType)) {
|
@@ -3143,14 +3254,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3143
3254
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, node.memberName.value, 1 /* SkipOriginalClass */);
|
3144
3255
|
}
|
3145
3256
|
if (classMemberInfo) {
|
3146
|
-
|
3147
|
-
|
3257
|
+
typeAtStart = getTypeOfMember(classMemberInfo);
|
3258
|
+
isTypeAtStartIncomplete = false;
|
3148
3259
|
}
|
3149
3260
|
}
|
3150
3261
|
// See if we can refine the type based on code flow analysis.
|
3151
|
-
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId,
|
3262
|
+
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, typeAtStart,
|
3152
3263
|
/* startNode */ undefined, {
|
3153
|
-
|
3264
|
+
isTypeAtStartIncomplete,
|
3154
3265
|
skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
|
3155
3266
|
});
|
3156
3267
|
if (codeFlowTypeResult.type) {
|
@@ -4051,7 +4162,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4051
4162
|
// See if we can refine the type based on code flow analysis.
|
4052
4163
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, indexTypeResult.type,
|
4053
4164
|
/* startNode */ undefined, {
|
4054
|
-
|
4165
|
+
isTypeAtStartIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
4055
4166
|
skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
|
4056
4167
|
});
|
4057
4168
|
if (codeFlowTypeResult.type) {
|
@@ -4080,6 +4191,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4080
4191
|
return indexTypeResult;
|
4081
4192
|
}
|
4082
4193
|
function adjustTypeArgumentsForVariadicTypeVar(typeArgs, typeParameters, errorNode) {
|
4194
|
+
var _a;
|
4083
4195
|
const variadicIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
4084
4196
|
// Do we need to adjust the type arguments to map to a variadic type
|
4085
4197
|
// param at the end of the list?
|
@@ -4127,7 +4239,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4127
4239
|
// Add an empty tuple that maps to the TypeVarTuple type parameter.
|
4128
4240
|
typeArgs.push({
|
4129
4241
|
node: errorNode,
|
4130
|
-
type: (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
4242
|
+
type: (_a = typeParameters[variadicIndex].details.defaultType) !== null && _a !== void 0 ? _a : (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
4131
4243
|
/* isTypeArgumentExplicit */ true,
|
4132
4244
|
/* isUnpackedTuple */ true)),
|
4133
4245
|
});
|
@@ -4180,7 +4292,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4180
4292
|
];
|
4181
4293
|
}
|
4182
4294
|
}
|
4183
|
-
if (typeArgs.length > typeParameters.length &&
|
4295
|
+
if (typeArgs.length > typeParameters.length &&
|
4296
|
+
!typeParameters.some((typeVar) => typeVar.details.isVariadic && !typeVar.isVariadicInUnion)) {
|
4184
4297
|
addError(localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
|
4185
4298
|
name: printType(baseType),
|
4186
4299
|
expected: typeParameters.length,
|
@@ -4196,6 +4309,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4196
4309
|
const typeVarContext = new typeVarContext_1.TypeVarContext(baseType.typeAliasInfo.typeVarScopeId);
|
4197
4310
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
4198
4311
|
typeParameters.forEach((param, index) => {
|
4312
|
+
var _a;
|
4199
4313
|
if (param.details.isParamSpec && index < typeArgs.length) {
|
4200
4314
|
const typeArgType = typeArgs[index].type;
|
4201
4315
|
if (typeArgs[index].typeList) {
|
@@ -4258,7 +4372,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4258
4372
|
if (index < typeArgs.length && typeArgs[index].typeList) {
|
4259
4373
|
addError(localize_1.Localizer.Diagnostic.typeArgListNotAllowed(), typeArgs[index].node);
|
4260
4374
|
}
|
4261
|
-
const typeArgType = index < typeArgs.length
|
4375
|
+
const typeArgType = index < typeArgs.length
|
4376
|
+
? (0, typeUtils_1.convertToInstance)(typeArgs[index].type)
|
4377
|
+
: (_a = param.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4262
4378
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 128 /* RetainLiteralsForTypeVar */);
|
4263
4379
|
}
|
4264
4380
|
});
|
@@ -4312,7 +4428,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4312
4428
|
// See if the class has a custom metaclass that supports __getitem__, etc.
|
4313
4429
|
if (concreteSubtype.details.effectiveMetaclass &&
|
4314
4430
|
(0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
|
4315
|
-
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, 'type')) {
|
4431
|
+
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta'])) {
|
4316
4432
|
const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
|
4317
4433
|
/* usage */ undefined,
|
4318
4434
|
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
|
@@ -4370,7 +4486,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4370
4486
|
}
|
4371
4487
|
if (concreteSubtype.typeArguments) {
|
4372
4488
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classAlreadySpecialized().format({
|
4373
|
-
type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype),
|
4489
|
+
type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype), { expandTypeAlias: true }),
|
4374
4490
|
}), node.baseExpression);
|
4375
4491
|
return concreteSubtype;
|
4376
4492
|
}
|
@@ -4552,12 +4668,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4552
4668
|
}
|
4553
4669
|
});
|
4554
4670
|
unpackedListArgs.forEach((arg) => {
|
4671
|
+
var _a, _b;
|
4555
4672
|
const typeResult = getTypeOfExpression(arg.valueExpression);
|
4556
|
-
const exprType = typeResult.type;
|
4557
4673
|
if (typeResult.isIncomplete) {
|
4558
4674
|
isPositionalIndexTypeIncomplete = true;
|
4559
4675
|
}
|
4560
|
-
const iterableType = getTypeOfIterator(
|
4676
|
+
const iterableType = (_b = (_a = getTypeOfIterator(typeResult, /* isAsync */ false, arg.valueExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
4561
4677
|
tupleEntries.push(iterableType);
|
4562
4678
|
});
|
4563
4679
|
positionalIndexType = makeTupleObject(tupleEntries, unpackedListArgs.length > 0);
|
@@ -4640,7 +4756,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4640
4756
|
adjFlags &= ~(2 /* DoNotSpecialize */ |
|
4641
4757
|
32 /* ParamSpecDisallowed */ |
|
4642
4758
|
128 /* TypeVarTupleDisallowed */ |
|
4643
|
-
1048576 /* RequiredAllowed */
|
4759
|
+
1048576 /* RequiredAllowed */ |
|
4760
|
+
16384 /* EnforceTypeVarVarianceConsistency */);
|
4644
4761
|
if (!isAnnotatedClass) {
|
4645
4762
|
adjFlags |= 131072 /* ClassVarDisallowed */ | 16 /* FinalDisallowed */;
|
4646
4763
|
}
|
@@ -5036,7 +5153,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5036
5153
|
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, expectedType);
|
5037
5154
|
const type = typeResult.type;
|
5038
5155
|
const exprString = ParseTreeUtils.printExpression(arg0Value);
|
5039
|
-
const typeString = printType(type,
|
5156
|
+
const typeString = printType(type, { expandTypeAlias: true });
|
5040
5157
|
if (expectedText !== undefined) {
|
5041
5158
|
if (expectedText !== typeString) {
|
5042
5159
|
addError(localize_1.Localizer.Diagnostic.revealTypeExpectedTextMismatch().format({
|
@@ -5076,7 +5193,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5076
5193
|
const typeOfSymbol = getEffectiveTypeOfSymbol(symbol);
|
5077
5194
|
infoMessages.push(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({
|
5078
5195
|
name,
|
5079
|
-
type: printType(typeOfSymbol,
|
5196
|
+
type: printType(typeOfSymbol, { expandTypeAlias: true }),
|
5080
5197
|
}));
|
5081
5198
|
}
|
5082
5199
|
});
|
@@ -5811,7 +5928,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5811
5928
|
const exprNode = errorNode.nodeType === 9 /* Call */ ? errorNode.leftExpression : errorNode;
|
5812
5929
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotCallable().format({
|
5813
5930
|
expression: ParseTreeUtils.printExpression(exprNode),
|
5814
|
-
type: printType(callTypeResult.type,
|
5931
|
+
type: printType(callTypeResult.type, { expandTypeAlias: true }),
|
5815
5932
|
}), exprNode);
|
5816
5933
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
5817
5934
|
}
|
@@ -6129,18 +6246,64 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6129
6246
|
specializedInitSelfType,
|
6130
6247
|
};
|
6131
6248
|
}
|
6249
|
+
// Expands any unpacked tuples within an argument list.
|
6250
|
+
function expandArgList(argList) {
|
6251
|
+
var _a;
|
6252
|
+
const expandedArgList = [];
|
6253
|
+
for (const arg of argList) {
|
6254
|
+
if (arg.argumentCategory === 1 /* UnpackedList */) {
|
6255
|
+
const argType = getTypeOfArgument(arg).type;
|
6256
|
+
// If this is a tuple with specified element types, use those
|
6257
|
+
// specified types rather than using the more generic iterator
|
6258
|
+
// type which will be a union of all element types.
|
6259
|
+
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
|
6260
|
+
if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
|
6261
|
+
const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
|
6262
|
+
if (tupleTypeArgs.length !== 1) {
|
6263
|
+
for (const tupleTypeArg of tupleTypeArgs) {
|
6264
|
+
if (tupleTypeArg.isUnbounded) {
|
6265
|
+
expandedArgList.push({
|
6266
|
+
...arg,
|
6267
|
+
argumentCategory: 1 /* UnpackedList */,
|
6268
|
+
valueExpression: undefined,
|
6269
|
+
typeResult: {
|
6270
|
+
type: (0, typeUtils_1.specializeTupleClass)(combinedArgType, [tupleTypeArg]),
|
6271
|
+
},
|
6272
|
+
});
|
6273
|
+
}
|
6274
|
+
else {
|
6275
|
+
expandedArgList.push({
|
6276
|
+
...arg,
|
6277
|
+
argumentCategory: 0 /* Simple */,
|
6278
|
+
valueExpression: undefined,
|
6279
|
+
typeResult: {
|
6280
|
+
type: tupleTypeArg.type,
|
6281
|
+
},
|
6282
|
+
});
|
6283
|
+
}
|
6284
|
+
}
|
6285
|
+
continue;
|
6286
|
+
}
|
6287
|
+
}
|
6288
|
+
}
|
6289
|
+
expandedArgList.push(arg);
|
6290
|
+
}
|
6291
|
+
return expandedArgList;
|
6292
|
+
}
|
6132
6293
|
// Matches the arguments passed to a function to the corresponding parameters in that
|
6133
6294
|
// function. This matching is done based on positions and keywords. Type evaluation and
|
6134
6295
|
// validation is left to the caller.
|
6135
6296
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
6136
6297
|
function matchFunctionArgumentsToParameters(errorNode, argList, type, overloadIndex) {
|
6137
|
-
var _a;
|
6298
|
+
var _a, _b, _c, _d, _e;
|
6138
6299
|
const paramDetails = (0, typeUtils_1.getParameterListDetails)(type);
|
6139
6300
|
let argIndex = 0;
|
6140
6301
|
let matchedUnpackedListOfUnknownLength = false;
|
6141
6302
|
let reportedArgError = false;
|
6142
6303
|
let isTypeIncomplete = false;
|
6143
6304
|
let isVariadicTypeVarFullyMatched = false;
|
6305
|
+
// Expand any unpacked tuples in the arg list.
|
6306
|
+
argList = expandArgList(argList);
|
6144
6307
|
// Build a map of parameters by name.
|
6145
6308
|
const paramMap = new Map();
|
6146
6309
|
paramDetails.params.forEach((paramInfo) => {
|
@@ -6224,24 +6387,44 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6224
6387
|
activeParam = param;
|
6225
6388
|
}
|
6226
6389
|
}
|
6227
|
-
|
6390
|
+
const foundUnpackedListArg = argList.find((arg) => arg.argumentCategory === 1 /* UnpackedList */) !== undefined;
|
6228
6391
|
// Map the positional args to parameters.
|
6229
6392
|
let paramIndex = 0;
|
6230
|
-
let unpackedArgIndex = 0;
|
6231
6393
|
while (argIndex < positionalArgCount) {
|
6232
6394
|
if (argIndex < positionalOnlyLimitIndex && argList[argIndex].name) {
|
6233
6395
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argList[argIndex].name);
|
6234
6396
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.argPositional(), argList[argIndex].name);
|
6235
6397
|
reportedArgError = true;
|
6236
6398
|
}
|
6399
|
+
const remainingArgCount = positionalArgCount - argIndex;
|
6400
|
+
const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
|
6237
6401
|
if (paramIndex >= positionParamLimitIndex) {
|
6238
|
-
if (!
|
6239
|
-
|
6240
|
-
|
6241
|
-
|
6242
|
-
|
6243
|
-
|
6244
|
-
|
6402
|
+
if (!type.details.paramSpec) {
|
6403
|
+
let tooManyPositionals = false;
|
6404
|
+
if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
|
6405
|
+
// If this is an unpacked iterable, we will conservatively assume that it
|
6406
|
+
// might have zero iterations unless we can tell from its type that it
|
6407
|
+
// definitely has at least one iterable value.
|
6408
|
+
const argType = getTypeOfArgument(argList[argIndex]).type;
|
6409
|
+
if ((0, types_1.isClassInstance)(argType) &&
|
6410
|
+
(0, typeUtils_1.isTupleClass)(argType) &&
|
6411
|
+
!(0, typeUtils_1.isUnboundedTupleClass)(argType) &&
|
6412
|
+
argType.tupleTypeArguments !== undefined &&
|
6413
|
+
argType.tupleTypeArguments.length > 0) {
|
6414
|
+
tooManyPositionals = true;
|
6415
|
+
}
|
6416
|
+
}
|
6417
|
+
else {
|
6418
|
+
tooManyPositionals = true;
|
6419
|
+
}
|
6420
|
+
if (tooManyPositionals) {
|
6421
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
|
6422
|
+
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
6423
|
+
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
6424
|
+
expected: positionParamLimitIndex,
|
6425
|
+
}), (_b = argList[argIndex].valueExpression) !== null && _b !== void 0 ? _b : errorNode);
|
6426
|
+
reportedArgError = true;
|
6427
|
+
}
|
6245
6428
|
}
|
6246
6429
|
break;
|
6247
6430
|
}
|
@@ -6250,15 +6433,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6250
6433
|
}
|
6251
6434
|
(0, debug_1.assert)(paramDetails.params[paramIndex], 'paramIndex params entry is undefined');
|
6252
6435
|
const paramType = paramDetails.params[paramIndex].type;
|
6436
|
+
const paramName = paramDetails.params[paramIndex].param.name;
|
6437
|
+
const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
|
6438
|
+
(0, types_1.isVariadicTypeVar)(paramType);
|
6253
6439
|
if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
|
6254
|
-
if (!argList[argIndex].valueExpression) {
|
6255
|
-
break;
|
6256
|
-
}
|
6257
|
-
const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
|
6258
|
-
(0, types_1.isVariadicTypeVar)(paramType);
|
6259
6440
|
let isArgCompatibleWithVariadic = false;
|
6260
6441
|
const argTypeResult = getTypeOfArgument(argList[argIndex]);
|
6261
|
-
const argType = argTypeResult.type;
|
6262
6442
|
let listElementType;
|
6263
6443
|
let advanceToNextArg = false;
|
6264
6444
|
// Handle the case where *args is being passed to a function defined
|
@@ -6270,32 +6450,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6270
6450
|
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
6271
6451
|
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
6272
6452
|
expected: positionParamLimitIndex,
|
6273
|
-
}), argList[argIndex].valueExpression
|
6453
|
+
}), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
|
6274
6454
|
reportedArgError = true;
|
6275
6455
|
}
|
6276
|
-
|
6277
|
-
|
6278
|
-
// type which will be a union of all element types.
|
6279
|
-
const combinedTupleType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
|
6280
|
-
if (!isParamVariadic &&
|
6281
|
-
combinedTupleType &&
|
6282
|
-
(0, types_1.isClassInstance)(combinedTupleType) &&
|
6283
|
-
combinedTupleType.tupleTypeArguments &&
|
6284
|
-
combinedTupleType.tupleTypeArguments.length > 0 &&
|
6285
|
-
unpackedArgIndex < combinedTupleType.tupleTypeArguments.length) {
|
6286
|
-
listElementType = combinedTupleType.tupleTypeArguments[unpackedArgIndex].type;
|
6287
|
-
// Determine if there are any more unpacked list arguments after
|
6288
|
-
// this one. If not, we'll clear this flag because this unpacked
|
6289
|
-
// list arg is bounded in length.
|
6290
|
-
foundUnpackedListArg =
|
6291
|
-
argList.find((arg, index) => index > argIndex && arg.argumentCategory === 1 /* UnpackedList */) !== undefined;
|
6292
|
-
unpackedArgIndex++;
|
6293
|
-
if (unpackedArgIndex >= combinedTupleType.tupleTypeArguments.length) {
|
6294
|
-
unpackedArgIndex = 0;
|
6295
|
-
advanceToNextArg = true;
|
6296
|
-
}
|
6297
|
-
}
|
6298
|
-
else if (isParamVariadic && (0, types_1.isVariadicTypeVar)(argType)) {
|
6456
|
+
const argType = argTypeResult.type;
|
6457
|
+
if (isParamVariadic && (0, types_1.isUnpackedVariadicTypeVar)(argType)) {
|
6299
6458
|
// Allow an unpacked variadic type variable to satisfy an
|
6300
6459
|
// unpacked variadic type variable.
|
6301
6460
|
listElementType = argType;
|
@@ -6307,7 +6466,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6307
6466
|
(0, typeUtils_1.isTupleClass)(argType) &&
|
6308
6467
|
argType.tupleTypeArguments &&
|
6309
6468
|
argType.tupleTypeArguments.length === 1 &&
|
6310
|
-
(0, types_1.
|
6469
|
+
(0, types_1.isUnpackedVariadicTypeVar)(argType.tupleTypeArguments[0].type)) {
|
6311
6470
|
// Handle the case where an unpacked variadic type var has
|
6312
6471
|
// been packaged into a tuple.
|
6313
6472
|
listElementType = argType.tupleTypeArguments[0].type;
|
@@ -6315,13 +6474,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6315
6474
|
advanceToNextArg = true;
|
6316
6475
|
isVariadicTypeVarFullyMatched = true;
|
6317
6476
|
}
|
6477
|
+
else if (isParamVariadic && (0, types_1.isClassInstance)(argType) && (0, typeUtils_1.isTupleClass)(argType)) {
|
6478
|
+
// Handle the case where an unpacked tuple argument is
|
6479
|
+
// matched to a TypeVarTuple parameter.
|
6480
|
+
isArgCompatibleWithVariadic = true;
|
6481
|
+
advanceToNextArg = true;
|
6482
|
+
// Determine whether we should treat the variadic type as fully matched.
|
6483
|
+
// This depends on how many args and unmatched parameters exist.
|
6484
|
+
if (remainingArgCount < remainingParamCount) {
|
6485
|
+
isVariadicTypeVarFullyMatched = true;
|
6486
|
+
}
|
6487
|
+
listElementType = types_1.ClassType.cloneForUnpacked(argType);
|
6488
|
+
}
|
6318
6489
|
else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
|
6319
6490
|
listElementType = undefined;
|
6320
6491
|
}
|
6321
6492
|
else {
|
6322
6493
|
listElementType =
|
6323
|
-
getTypeOfIterator(argType,
|
6324
|
-
|
6494
|
+
(_e = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
6495
|
+
/* isAsync */ false, argList[argIndex].valueExpression)) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : types_1.UnknownType.create();
|
6325
6496
|
if (paramDetails.params[paramIndex].param.category !== 1 /* VarArgList */) {
|
6326
6497
|
matchedUnpackedListOfUnknownLength = true;
|
6327
6498
|
}
|
@@ -6335,7 +6506,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6335
6506
|
if (funcArg && argTypeResult.isIncomplete) {
|
6336
6507
|
isTypeIncomplete = true;
|
6337
6508
|
}
|
6338
|
-
const paramName = paramDetails.params[paramIndex].param.name;
|
6339
6509
|
// It's not allowed to use unpacked arguments with a variadic *args
|
6340
6510
|
// parameter unless the argument is a variadic arg as well.
|
6341
6511
|
if (isParamVariadic && !isArgCompatibleWithVariadic) {
|
@@ -6355,6 +6525,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6355
6525
|
errorNode: argList[argIndex].valueExpression || errorNode,
|
6356
6526
|
paramName,
|
6357
6527
|
isParamNameSynthesized: paramDetails.params[paramIndex].param.isNameSynthesized,
|
6528
|
+
mapsToVarArgList: isParamVariadic && remainingArgCount > remainingParamCount,
|
6358
6529
|
});
|
6359
6530
|
}
|
6360
6531
|
}
|
@@ -6392,8 +6563,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6392
6563
|
paramCategory = (0, types_1.isVariadicTypeVar)(effectiveParamType)
|
6393
6564
|
? 1 /* VarArgList */
|
6394
6565
|
: 0 /* Simple */;
|
6395
|
-
const remainingArgCount = positionalArgCount - argIndex;
|
6396
|
-
const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
|
6397
6566
|
if (remainingArgCount <= remainingParamCount) {
|
6398
6567
|
if (remainingArgCount < remainingParamCount) {
|
6399
6568
|
// Have we run out of arguments and still have parameters left to fill?
|
@@ -6796,7 +6965,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6796
6965
|
!isVariadicTypeVarFullyMatched) {
|
6797
6966
|
const paramType = paramDetails.params[paramDetails.argsIndex].type;
|
6798
6967
|
const variadicArgs = validateArgTypeParams.filter((argParam) => argParam.mapsToVarArgList);
|
6799
|
-
if ((0, types_1.
|
6968
|
+
if ((0, types_1.isVariadicTypeVar)(paramType) && !paramType.isVariadicInUnion) {
|
6800
6969
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
6801
6970
|
const tupleTypeArgs = variadicArgs.map((argParam) => {
|
6802
6971
|
var _a;
|
@@ -6816,9 +6985,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6816
6985
|
isUnbounded: argParam.argument.argumentCategory === 1 /* UnpackedList */,
|
6817
6986
|
};
|
6818
6987
|
});
|
6819
|
-
|
6820
|
-
|
6821
|
-
|
6988
|
+
let specializedTuple;
|
6989
|
+
if (tupleTypeArgs.length === 1 &&
|
6990
|
+
!tupleTypeArgs[0].isUnbounded &&
|
6991
|
+
((0, types_1.isUnpackedClass)(tupleTypeArgs[0].type) || (0, types_1.isVariadicTypeVar)(tupleTypeArgs[0].type))) {
|
6992
|
+
// If there is a single unpacked tuple or unpacked variadic type variable
|
6993
|
+
// (including an unpacked TypeVarTuple union) within this tuple,
|
6994
|
+
// simplify the type.
|
6995
|
+
specializedTuple = tupleTypeArgs[0].type;
|
6996
|
+
}
|
6997
|
+
else {
|
6998
|
+
specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
|
6999
|
+
/* isTypeArgumentExplicit */ true,
|
7000
|
+
/* isUnpackedTuple */ true));
|
7001
|
+
}
|
6822
7002
|
const combinedArg = {
|
6823
7003
|
paramCategory: 1 /* VarArgList */,
|
6824
7004
|
paramType,
|
@@ -7500,7 +7680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7500
7680
|
if (!suppressPartialUnknown) {
|
7501
7681
|
const diagAddendum = getDiagAddendum();
|
7502
7682
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentType().format({
|
7503
|
-
type: printType(simplifiedType,
|
7683
|
+
type: printType(simplifiedType, { expandTypeAlias: true }),
|
7504
7684
|
}));
|
7505
7685
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportUnknownArgumentType, diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.Localizer.Diagnostic.argTypePartiallyUnknown() + diagAddendum.getString(), argParam.errorNode);
|
7506
7686
|
}
|
@@ -7510,9 +7690,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7510
7690
|
return { isCompatible, argType, isTypeIncomplete, condition };
|
7511
7691
|
}
|
7512
7692
|
function createTypeVarType(errorNode, argList) {
|
7513
|
-
var _a, _b, _c, _d, _e;
|
7693
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
7514
7694
|
let typeVarName = '';
|
7515
7695
|
let firstConstraintArg;
|
7696
|
+
let defaultValueNode;
|
7516
7697
|
if (argList.length === 0) {
|
7517
7698
|
addError(localize_1.Localizer.Diagnostic.typeVarFirstArg(), errorNode);
|
7518
7699
|
return undefined;
|
@@ -7526,10 +7707,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7526
7707
|
}
|
7527
7708
|
const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false);
|
7528
7709
|
// Parse the remaining parameters.
|
7710
|
+
const paramNameMap = new Map();
|
7529
7711
|
for (let i = 1; i < argList.length; i++) {
|
7530
7712
|
const paramNameNode = argList[i].name;
|
7531
7713
|
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
7532
|
-
const paramNameMap = new Map();
|
7533
7714
|
if (paramName) {
|
7534
7715
|
if (paramNameMap.get(paramName)) {
|
7535
7716
|
addError(localize_1.Localizer.Diagnostic.duplicateParam().format({ name: paramName }), argList[i].valueExpression || errorNode);
|
@@ -7541,14 +7722,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7541
7722
|
else {
|
7542
7723
|
const argType = (_b = (_a = argList[i].typeResult) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
7543
7724
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7544
|
-
addError(localize_1.Localizer.Diagnostic.
|
7725
|
+
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
|
7545
7726
|
}
|
7546
7727
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
|
7547
7728
|
}
|
7548
7729
|
}
|
7549
7730
|
else if (paramName === 'covariant') {
|
7550
7731
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7551
|
-
if (typeVar.details.declaredVariance === 4 /* Contravariant */
|
7732
|
+
if (typeVar.details.declaredVariance === 4 /* Contravariant */ ||
|
7733
|
+
typeVar.details.declaredVariance === 0 /* Auto */) {
|
7552
7734
|
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7553
7735
|
}
|
7554
7736
|
else {
|
@@ -7558,7 +7740,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7558
7740
|
}
|
7559
7741
|
else if (paramName === 'contravariant') {
|
7560
7742
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7561
|
-
if (typeVar.details.declaredVariance === 3 /* Covariant */
|
7743
|
+
if (typeVar.details.declaredVariance === 3 /* Covariant */ ||
|
7744
|
+
typeVar.details.declaredVariance === 0 /* Auto */) {
|
7562
7745
|
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7563
7746
|
}
|
7564
7747
|
else {
|
@@ -7566,8 +7749,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7566
7749
|
}
|
7567
7750
|
}
|
7568
7751
|
}
|
7752
|
+
else if (paramName === 'infer_variance') {
|
7753
|
+
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7754
|
+
if (typeVar.details.declaredVariance === 3 /* Covariant */ ||
|
7755
|
+
typeVar.details.declaredVariance === 4 /* Contravariant */) {
|
7756
|
+
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7757
|
+
}
|
7758
|
+
else {
|
7759
|
+
typeVar.details.declaredVariance = 0 /* Auto */;
|
7760
|
+
}
|
7761
|
+
}
|
7762
|
+
}
|
7763
|
+
else if (paramName === 'default') {
|
7764
|
+
defaultValueNode = argList[i].valueExpression;
|
7765
|
+
const argType = (_d = (_c = argList[i].typeResult) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
7766
|
+
typeVar.details.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
7767
|
+
}
|
7569
7768
|
else {
|
7570
|
-
addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((
|
7769
|
+
addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((_e = argList[i].node) === null || _e === void 0 ? void 0 : _e.name) || argList[i].valueExpression || errorNode);
|
7571
7770
|
}
|
7572
7771
|
paramNameMap.set(paramName, paramName);
|
7573
7772
|
}
|
@@ -7576,9 +7775,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7576
7775
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
7577
7776
|
}
|
7578
7777
|
else {
|
7579
|
-
const argType = (
|
7778
|
+
const argType = (_g = (_f = argList[i].typeResult) === null || _f === void 0 ? void 0 : _f.type) !== null && _g !== void 0 ? _g : getTypeOfExpressionExpectingType(argList[i].valueExpression).type;
|
7580
7779
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7581
|
-
addError(localize_1.Localizer.Diagnostic.
|
7780
|
+
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
|
7582
7781
|
}
|
7583
7782
|
types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
|
7584
7783
|
if (firstConstraintArg === undefined) {
|
@@ -7590,6 +7789,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7590
7789
|
if (typeVar.details.constraints.length === 1 && firstConstraintArg) {
|
7591
7790
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarSingleConstraint(), firstConstraintArg.valueExpression || errorNode);
|
7592
7791
|
}
|
7792
|
+
// If a default is provided, make sure it is compatible with the bound
|
7793
|
+
// or constraint.
|
7794
|
+
if (typeVar.details.defaultType && defaultValueNode) {
|
7795
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext(types_1.WildcardTypeVarScopeId);
|
7796
|
+
const concreteDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext,
|
7797
|
+
/* unknownIfNotFound */ true);
|
7798
|
+
if (typeVar.details.boundType) {
|
7799
|
+
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
7800
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarDefaultBoundMismatch(), defaultValueNode);
|
7801
|
+
}
|
7802
|
+
}
|
7803
|
+
else if (typeVar.details.constraints.length > 0) {
|
7804
|
+
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
7805
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarDefaultConstraintMismatch(), defaultValueNode);
|
7806
|
+
}
|
7807
|
+
}
|
7808
|
+
}
|
7593
7809
|
return typeVar;
|
7594
7810
|
}
|
7595
7811
|
function createTypeVarTupleType(errorNode, argList) {
|
@@ -7610,12 +7826,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7610
7826
|
typeVar.details.isVariadic = true;
|
7611
7827
|
// Parse the remaining parameters.
|
7612
7828
|
for (let i = 1; i < argList.length; i++) {
|
7613
|
-
|
7829
|
+
const paramNameNode = argList[i].name;
|
7830
|
+
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
7831
|
+
if (paramName) {
|
7832
|
+
if (paramName === 'default') {
|
7833
|
+
const expr = argList[i].valueExpression;
|
7834
|
+
if (expr) {
|
7835
|
+
typeVar.details.defaultType = getTypeVarTupleDefaultType(expr);
|
7836
|
+
}
|
7837
|
+
}
|
7838
|
+
else {
|
7839
|
+
addError(localize_1.Localizer.Diagnostic.typeVarTupleUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
|
7840
|
+
}
|
7841
|
+
}
|
7614
7842
|
}
|
7615
7843
|
return typeVar;
|
7616
7844
|
}
|
7845
|
+
function getTypeVarTupleDefaultType(node) {
|
7846
|
+
const argType = getTypeOfExpressionExpectingType(node, { allowUnpackedTuple: true }).type;
|
7847
|
+
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
7848
|
+
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
7849
|
+
if (!isUnpackedTuple && !isUnpackedTypeVarTuple) {
|
7850
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarTupleDefaultNotUnpacked(), node);
|
7851
|
+
return undefined;
|
7852
|
+
}
|
7853
|
+
return (0, typeUtils_1.convertToInstance)(argType);
|
7854
|
+
}
|
7617
7855
|
function createParamSpecType(errorNode, argList) {
|
7618
|
-
var _a, _b;
|
7619
7856
|
if (argList.length === 0) {
|
7620
7857
|
addError(localize_1.Localizer.Diagnostic.paramSpecFirstArg(), errorNode);
|
7621
7858
|
return undefined;
|
@@ -7631,8 +7868,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7631
7868
|
const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true);
|
7632
7869
|
// Parse the remaining parameters.
|
7633
7870
|
for (let i = 1; i < argList.length; i++) {
|
7634
|
-
|
7635
|
-
|
7871
|
+
const paramNameNode = argList[i].name;
|
7872
|
+
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
7873
|
+
if (paramName) {
|
7874
|
+
if (paramName === 'default') {
|
7875
|
+
const expr = argList[i].valueExpression;
|
7876
|
+
if (expr) {
|
7877
|
+
paramSpec.details.defaultType = getParamSpecDefaultType(expr);
|
7878
|
+
}
|
7879
|
+
}
|
7880
|
+
else {
|
7881
|
+
addError(localize_1.Localizer.Diagnostic.paramSpecUnknownParam().format({ name: paramName }), paramNameNode || argList[i].valueExpression || errorNode);
|
7882
|
+
}
|
7636
7883
|
}
|
7637
7884
|
else {
|
7638
7885
|
addError(localize_1.Localizer.Diagnostic.paramSpecUnknownArg(), argList[i].valueExpression || errorNode);
|
@@ -7641,6 +7888,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7641
7888
|
}
|
7642
7889
|
return paramSpec;
|
7643
7890
|
}
|
7891
|
+
function getParamSpecDefaultType(node) {
|
7892
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
|
7893
|
+
types_1.TypeBase.setSpecialForm(functionType);
|
7894
|
+
if (node.nodeType === 18 /* Ellipsis */) {
|
7895
|
+
types_1.FunctionType.addDefaultParameters(functionType);
|
7896
|
+
return functionType;
|
7897
|
+
}
|
7898
|
+
if (node.nodeType === 52 /* Tuple */) {
|
7899
|
+
node.expressions.forEach((paramExpr, index) => {
|
7900
|
+
const typeResult = getTypeOfExpressionExpectingType(paramExpr);
|
7901
|
+
types_1.FunctionType.addParameter(functionType, {
|
7902
|
+
category: 0 /* Simple */,
|
7903
|
+
name: `__p${index}`,
|
7904
|
+
isNameSynthesized: true,
|
7905
|
+
hasDeclaredType: true,
|
7906
|
+
type: (0, typeUtils_1.convertToInstance)(typeResult.type),
|
7907
|
+
});
|
7908
|
+
});
|
7909
|
+
// Update the type cache so we don't attempt to re-evaluate this node.
|
7910
|
+
// The type doesn't matter, so use Any.
|
7911
|
+
writeTypeCache(node, types_1.AnyType.create(), /* flags */ undefined, /* isIncomplete */ false);
|
7912
|
+
return functionType;
|
7913
|
+
}
|
7914
|
+
else {
|
7915
|
+
const typeResult = getTypeOfExpressionExpectingType(node, { allowParamSpec: true });
|
7916
|
+
if (typeResult.typeErrors) {
|
7917
|
+
return undefined;
|
7918
|
+
}
|
7919
|
+
if ((0, types_1.isParamSpec)(typeResult.type)) {
|
7920
|
+
functionType.details.paramSpec = typeResult.type;
|
7921
|
+
return functionType;
|
7922
|
+
}
|
7923
|
+
}
|
7924
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
|
7925
|
+
return undefined;
|
7926
|
+
}
|
7644
7927
|
function getBooleanValue(node) {
|
7645
7928
|
if (node.nodeType === 11 /* Constant */) {
|
7646
7929
|
if (node.constType === 15 /* False */) {
|
@@ -8166,6 +8449,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8166
8449
|
type = mapSubtypesExpandTypeVars(rightType,
|
8167
8450
|
/* conditionFilter */ undefined, (rightSubtypeExpanded, rightSubtypeUnexpanded) => {
|
8168
8451
|
return mapSubtypesExpandTypeVars(concreteLeftType, (0, typeUtils_1.getTypeCondition)(rightSubtypeExpanded), (leftSubtype) => {
|
8452
|
+
var _a;
|
8169
8453
|
if ((0, types_1.isAnyOrUnknown)(leftSubtype) || (0, types_1.isAnyOrUnknown)(rightSubtypeUnexpanded)) {
|
8170
8454
|
return (0, typeUtils_1.preserveUnknown)(leftSubtype, rightSubtypeExpanded);
|
8171
8455
|
}
|
@@ -8174,9 +8458,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8174
8458
|
if (!returnType) {
|
8175
8459
|
// If __contains__ was not supported, fall back
|
8176
8460
|
// on an iterable.
|
8177
|
-
const iteratorType = getTypeOfIterator(rightSubtypeExpanded,
|
8461
|
+
const iteratorType = (_a = getTypeOfIterator({ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete },
|
8178
8462
|
/* isAsync */ false,
|
8179
|
-
/* errorNode */ undefined);
|
8463
|
+
/* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
|
8180
8464
|
if (iteratorType && assignType(iteratorType, leftSubtype)) {
|
8181
8465
|
returnType = getBuiltInObject(errorNode, 'bool');
|
8182
8466
|
}
|
@@ -8609,6 +8893,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8609
8893
|
isIncomplete = true;
|
8610
8894
|
}
|
8611
8895
|
const keyType = keyTypeResult.type;
|
8896
|
+
if (!keyTypeResult.isIncomplete && !keyTypeResult.typeErrors) {
|
8897
|
+
verifySetEntryOrDictKeyIsHashable(entryNode.keyExpression, keyType, /* isDictKey */ true);
|
8898
|
+
}
|
8612
8899
|
let valueTypeResult;
|
8613
8900
|
if (expectedTypedDictEntries &&
|
8614
8901
|
(0, types_1.isClassInstance)(keyType) &&
|
@@ -8754,6 +9041,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8754
9041
|
expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedType);
|
8755
9042
|
let isIncomplete = false;
|
8756
9043
|
let typeErrors = false;
|
9044
|
+
const verifyHashable = node.nodeType === 45 /* Set */;
|
8757
9045
|
if (!(0, types_1.isClassInstance)(expectedType)) {
|
8758
9046
|
return undefined;
|
8759
9047
|
}
|
@@ -8790,6 +9078,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8790
9078
|
if (entryTypeResult.expectedTypeDiagAddendum) {
|
8791
9079
|
expectedTypeDiagAddendum.addAddendum(entryTypeResult.expectedTypeDiagAddendum);
|
8792
9080
|
}
|
9081
|
+
if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
|
9082
|
+
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9083
|
+
}
|
8793
9084
|
});
|
8794
9085
|
const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(expectedType) && types_1.ClassType.isBuiltIn(expectedType, builtInClassName);
|
8795
9086
|
const specializedEntryType = inferTypeArgFromExpectedType(expectedEntryType, entryTypes,
|
@@ -8803,6 +9094,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8803
9094
|
// Attempts to infer the type of a list or set statement with no "expected type".
|
8804
9095
|
function getTypeOfListOrSetInferred(node, hasExpectedType) {
|
8805
9096
|
const builtInClassName = node.nodeType === 31 /* List */ ? 'list' : 'set';
|
9097
|
+
const verifyHashable = node.nodeType === 45 /* Set */;
|
8806
9098
|
let isEmptyContainer = false;
|
8807
9099
|
let isIncomplete = false;
|
8808
9100
|
let typeErrors = false;
|
@@ -8813,8 +9105,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8813
9105
|
entryTypeResult = getElementTypeFromListComprehension(entry);
|
8814
9106
|
}
|
8815
9107
|
else {
|
8816
|
-
entryTypeResult = getTypeOfExpression(entry
|
8817
|
-
/* flags */ undefined, hasExpectedType ? types_1.NeverType.createNever() : undefined);
|
9108
|
+
entryTypeResult = getTypeOfExpression(entry);
|
8818
9109
|
}
|
8819
9110
|
if (entryTypeResult.isIncomplete) {
|
8820
9111
|
isIncomplete = true;
|
@@ -8825,6 +9116,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8825
9116
|
if (index < maxEntriesToUseForInference) {
|
8826
9117
|
entryTypes.push(entryTypeResult.type);
|
8827
9118
|
}
|
9119
|
+
if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
|
9120
|
+
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9121
|
+
}
|
8828
9122
|
});
|
8829
9123
|
entryTypes = entryTypes.map((t) => stripLiteralValue(t));
|
8830
9124
|
let inferredEntryType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
|
@@ -8856,6 +9150,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8856
9150
|
: types_1.UnknownType.create();
|
8857
9151
|
return { type, isIncomplete, typeErrors };
|
8858
9152
|
}
|
9153
|
+
function verifySetEntryOrDictKeyIsHashable(entry, type, isDictKey) {
|
9154
|
+
// Verify that the type is hashable.
|
9155
|
+
if (!isTypeHashable(type)) {
|
9156
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(entry);
|
9157
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
9158
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.unhashableType().format({ type: printType(type) }));
|
9159
|
+
const message = isDictKey
|
9160
|
+
? localize_1.Localizer.Diagnostic.unhashableDictKey()
|
9161
|
+
: localize_1.Localizer.Diagnostic.unhashableSetEntry();
|
9162
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
|
9163
|
+
}
|
9164
|
+
}
|
8859
9165
|
function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
|
8860
9166
|
let targetTypeVar;
|
8861
9167
|
let useSynthesizedTypeVar = false;
|
@@ -8956,8 +9262,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8956
9262
|
return { type: sentType || types_1.UnknownType.create(), isIncomplete };
|
8957
9263
|
}
|
8958
9264
|
function getTypeOfYieldFrom(node) {
|
8959
|
-
var _a;
|
8960
|
-
const
|
9265
|
+
var _a, _b;
|
9266
|
+
const yieldFromTypeResult = getTypeOfExpression(node.expression);
|
9267
|
+
const yieldFromType = yieldFromTypeResult.type;
|
8961
9268
|
let generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(yieldFromType);
|
8962
9269
|
let returnedType;
|
8963
9270
|
// Is the expression a Generator type?
|
@@ -8969,7 +9276,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8969
9276
|
returnedType = types_1.UnknownType.create();
|
8970
9277
|
}
|
8971
9278
|
else {
|
8972
|
-
const iterableType = (_a = getTypeOfIterable(
|
9279
|
+
const iterableType = (_b = (_a = getTypeOfIterable(yieldFromTypeResult, /* isAsync */ false, node)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
8973
9280
|
// Does the iterable return a Generator?
|
8974
9281
|
generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(iterableType);
|
8975
9282
|
if (generatorTypeArgs) {
|
@@ -9006,9 +9313,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9006
9313
|
// Remove any expected subtypes that don't satisfy the minimum
|
9007
9314
|
// parameter count requirement.
|
9008
9315
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
9009
|
-
const
|
9010
|
-
const
|
9011
|
-
const hasVarArgs = params.some((param) => param.category !== 0 /* Simple */);
|
9316
|
+
const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
|
9317
|
+
const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
|
9012
9318
|
return (hasVarArgs ||
|
9013
9319
|
(functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
|
9014
9320
|
});
|
@@ -9099,6 +9405,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9099
9405
|
return { type: functionType, isIncomplete };
|
9100
9406
|
}
|
9101
9407
|
function getTypeOfListComprehension(node, expectedType) {
|
9408
|
+
var _a;
|
9102
9409
|
let isIncomplete = false;
|
9103
9410
|
let typeErrors = false;
|
9104
9411
|
let isAsync = node.forIfNodes.some((comp) => {
|
@@ -9112,7 +9419,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9112
9419
|
}
|
9113
9420
|
let expectedElementType;
|
9114
9421
|
if (expectedType) {
|
9115
|
-
expectedElementType = getTypeOfIterator(expectedType, isAsync, /* errorNode */ undefined);
|
9422
|
+
expectedElementType = (_a = getTypeOfIterator({ type: expectedType }, isAsync, /* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
|
9116
9423
|
}
|
9117
9424
|
const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
|
9118
9425
|
if (elementTypeResult.isIncomplete) {
|
@@ -9160,7 +9467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9160
9467
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9161
9468
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({
|
9162
9469
|
name: nameValue,
|
9163
|
-
type: printType(simplifiedType,
|
9470
|
+
type: printType(simplifiedType, { expandTypeAlias: true }),
|
9164
9471
|
}));
|
9165
9472
|
addDiagnostic(diagLevel, rule, localize_1.Localizer.Diagnostic.typePartiallyUnknown().format({ name: nameValue }) + diagAddendum.getString(), errorNode);
|
9166
9473
|
}
|
@@ -9175,9 +9482,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9175
9482
|
isIncomplete = true;
|
9176
9483
|
}
|
9177
9484
|
const iterableType = stripLiteralValue(iterableTypeResult.type);
|
9178
|
-
const
|
9485
|
+
const itemTypeResult = (_a = getTypeOfIterator({ type: iterableType, isIncomplete: iterableTypeResult.isIncomplete }, !!node.isAsync, node.iterableExpression)) !== null && _a !== void 0 ? _a : { type: types_1.UnknownType.create(), isIncomplete: iterableTypeResult.isIncomplete };
|
9179
9486
|
const targetExpr = node.targetExpression;
|
9180
|
-
assignTypeToExpression(targetExpr,
|
9487
|
+
assignTypeToExpression(targetExpr, itemTypeResult.type, !!itemTypeResult.isIncomplete, node.iterableExpression);
|
9181
9488
|
}
|
9182
9489
|
else {
|
9183
9490
|
(0, debug_1.assert)(node.nodeType === 34 /* ListComprehensionIf */);
|
@@ -9907,7 +10214,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9907
10214
|
else {
|
9908
10215
|
// If this is an unpacked TypeVar, note that it is in a union so we can differentiate
|
9909
10216
|
// between Unpack[Vs] and Union[Unpack[Vs]].
|
9910
|
-
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.
|
10217
|
+
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
|
9911
10218
|
typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
|
9912
10219
|
}
|
9913
10220
|
types.push(typeArgType);
|
@@ -10201,7 +10508,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10201
10508
|
/* honorCodeFlow */ false);
|
10202
10509
|
if (symbolWithScope) {
|
10203
10510
|
const decls = symbolWithScope.symbol.getDeclarations();
|
10204
|
-
if (decls.length === 1 && (
|
10511
|
+
if (decls.length === 1 && isPossibleTypeAliasOrTypedDict(decls[0])) {
|
10205
10512
|
typeAliasNameNode = node.leftExpression;
|
10206
10513
|
isSpeculativeTypeAlias = true;
|
10207
10514
|
}
|
@@ -10296,6 +10603,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10296
10603
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
10297
10604
|
writeTypeCache(node, rightHandType, 0 /* None */, isIncomplete);
|
10298
10605
|
}
|
10606
|
+
function isPossibleTypeAliasOrTypedDict(decl) {
|
10607
|
+
var _a;
|
10608
|
+
if ((0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)) {
|
10609
|
+
return true;
|
10610
|
+
}
|
10611
|
+
if (decl.type === 1 /* Variable */ &&
|
10612
|
+
decl.node.parent &&
|
10613
|
+
decl.node.parent.nodeType === 3 /* Assignment */ &&
|
10614
|
+
((_a = decl.node.parent.rightExpression) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
10615
|
+
const callLeftNode = decl.node.parent.rightExpression.leftExpression;
|
10616
|
+
// Use a simple heuristic to determine whether this is potentially
|
10617
|
+
// a call to the TypedDict call. This avoids the expensive (and potentially
|
10618
|
+
// recursive) call to getTypeOfExpression in cases where it's not needed.
|
10619
|
+
if ((callLeftNode.nodeType === 38 /* Name */ && callLeftNode.value) === 'TypedDict' ||
|
10620
|
+
(callLeftNode.nodeType === 35 /* MemberAccess */ &&
|
10621
|
+
callLeftNode.memberName.value === 'TypedDict' &&
|
10622
|
+
callLeftNode.leftExpression.nodeType === 38 /* Name */)) {
|
10623
|
+
// See if this is a call to TypedDict. We want to support
|
10624
|
+
// recursive type references in a TypedDict call.
|
10625
|
+
const callType = getTypeOfExpression(callLeftNode, 2 /* DoNotSpecialize */).type;
|
10626
|
+
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
10627
|
+
return true;
|
10628
|
+
}
|
10629
|
+
}
|
10630
|
+
}
|
10631
|
+
return false;
|
10632
|
+
}
|
10299
10633
|
// Evaluates the type of a type alias (i.e. "type") statement. This code
|
10300
10634
|
// path does not handle traditional type aliases, which are treated as
|
10301
10635
|
// variables since they use normal variable assignment syntax.
|
@@ -10765,7 +11099,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10765
11099
|
}
|
10766
11100
|
if (dataClassBehaviors) {
|
10767
11101
|
(0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
|
10768
|
-
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, classType, initSubclassArgs);
|
11102
|
+
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs, dataClassBehaviors);
|
10769
11103
|
}
|
10770
11104
|
// Run any class hooks that depend on this class.
|
10771
11105
|
runClassTypeHooks(classType);
|
@@ -11002,7 +11336,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11002
11336
|
if ((0, types_1.isOverloadedFunction)(decoratorType)) {
|
11003
11337
|
const dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
|
11004
11338
|
if (dataclassBehaviors) {
|
11005
|
-
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, originalClassType, dataclassBehaviors,
|
11339
|
+
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, decoratorNode, originalClassType, dataclassBehaviors,
|
11006
11340
|
/* callNode */ undefined);
|
11007
11341
|
return inputClassType;
|
11008
11342
|
}
|
@@ -11035,7 +11369,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11035
11369
|
dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
|
11036
11370
|
}
|
11037
11371
|
if (dataclassBehaviors) {
|
11038
|
-
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, originalClassType, dataclassBehaviors, callNode);
|
11372
|
+
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, decoratorNode, originalClassType, dataclassBehaviors, callNode);
|
11039
11373
|
return inputClassType;
|
11040
11374
|
}
|
11041
11375
|
}
|
@@ -12016,18 +12350,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12016
12350
|
let useAwaitableGenerator = false;
|
12017
12351
|
if (functionDecl.yieldStatements) {
|
12018
12352
|
functionDecl.yieldStatements.forEach((yieldNode) => {
|
12353
|
+
var _a;
|
12019
12354
|
if (isNodeReachable(yieldNode)) {
|
12020
12355
|
if (yieldNode.nodeType === 61 /* YieldFrom */) {
|
12021
|
-
const
|
12022
|
-
if ((0, types_1.isClassInstance)(
|
12023
|
-
types_1.ClassType.isBuiltIn(
|
12356
|
+
const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
|
12357
|
+
if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
|
12358
|
+
types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
|
12024
12359
|
// Handle old-style (pre-await) Coroutines.
|
12025
12360
|
inferredYieldTypes.push();
|
12026
12361
|
useAwaitableGenerator = true;
|
12027
12362
|
}
|
12028
12363
|
else {
|
12029
|
-
const yieldType = getTypeOfIterator(
|
12030
|
-
/* isAsync */ false, yieldNode);
|
12364
|
+
const yieldType = (_a = getTypeOfIterator(iteratorTypeResult,
|
12365
|
+
/* isAsync */ false, yieldNode)) === null || _a === void 0 ? void 0 : _a.type;
|
12031
12366
|
inferredYieldTypes.push(yieldType !== null && yieldType !== void 0 ? yieldType : types_1.UnknownType.create());
|
12032
12367
|
}
|
12033
12368
|
}
|
@@ -12100,12 +12435,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12100
12435
|
return true;
|
12101
12436
|
}
|
12102
12437
|
function evaluateTypesForForStatement(node) {
|
12103
|
-
var _a;
|
12438
|
+
var _a, _b;
|
12104
12439
|
if (readTypeCache(node, 0 /* None */)) {
|
12105
12440
|
return;
|
12106
12441
|
}
|
12107
12442
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
12108
|
-
const iteratedType = (_a = getTypeOfIterator(iteratorTypeResult
|
12443
|
+
const iteratedType = (_b = (_a = getTypeOfIterator(iteratorTypeResult, !!node.isAsync, node.iterableExpression)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
12109
12444
|
assignTypeToExpression(node.targetExpression, iteratedType, !!iteratorTypeResult.isIncomplete, node.targetExpression);
|
12110
12445
|
writeTypeCache(node, iteratedType, 0 /* None */, !!iteratorTypeResult.isIncomplete);
|
12111
12446
|
}
|
@@ -12115,9 +12450,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12115
12450
|
if (readTypeCache(node, 0 /* None */)) {
|
12116
12451
|
return;
|
12117
12452
|
}
|
12118
|
-
const
|
12453
|
+
const exceptionTypeResult = getTypeOfExpression(node.typeExpression);
|
12454
|
+
const exceptionTypes = exceptionTypeResult.type;
|
12119
12455
|
function getExceptionType(exceptionType, errorNode) {
|
12120
|
-
var _a;
|
12456
|
+
var _a, _b;
|
12121
12457
|
exceptionType = makeTopLevelTypeVarsConcrete(exceptionType);
|
12122
12458
|
if ((0, types_1.isAnyOrUnknown)(exceptionType)) {
|
12123
12459
|
return exceptionType;
|
@@ -12126,7 +12462,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12126
12462
|
return types_1.ClassType.cloneAsInstance(exceptionType);
|
12127
12463
|
}
|
12128
12464
|
if ((0, types_1.isClassInstance)(exceptionType)) {
|
12129
|
-
const iterableType = (_a = getTypeOfIterator(exceptionType,
|
12465
|
+
const iterableType = (_b = (_a = getTypeOfIterator({ type: exceptionType, isIncomplete: exceptionTypeResult.isIncomplete },
|
12466
|
+
/* isAsync */ false, errorNode)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
12130
12467
|
return (0, typeUtils_1.mapSubtypes)(iterableType, (subtype) => {
|
12131
12468
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
12132
12469
|
return subtype;
|
@@ -12172,32 +12509,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12172
12509
|
// Verify that the target has an __enter__ or __aenter__ method defined.
|
12173
12510
|
const enterMethodName = isAsync ? '__aenter__' : '__enter__';
|
12174
12511
|
const scopedType = (0, typeUtils_1.mapSubtypes)(exprType, (subtype) => {
|
12175
|
-
var _a;
|
12176
12512
|
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
12177
12513
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
12178
12514
|
return subtype;
|
12179
12515
|
}
|
12180
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
12181
12516
|
const additionalHelp = new diagnostic_1.DiagnosticAddendum();
|
12182
|
-
if ((0, types_1.
|
12183
|
-
|
12517
|
+
if ((0, types_1.isClass)(subtype)) {
|
12518
|
+
let enterType = getTypeOfMagicMethodReturn(subtype, [], enterMethodName, node.expression,
|
12519
|
+
/* expectedType */ undefined);
|
12184
12520
|
if (enterType) {
|
12185
|
-
let memberReturnType;
|
12186
|
-
if ((0, types_1.isFunction)(enterType)) {
|
12187
|
-
memberReturnType = getFunctionEffectiveReturnType(enterType);
|
12188
|
-
}
|
12189
|
-
else {
|
12190
|
-
memberReturnType = types_1.UnknownType.create();
|
12191
|
-
}
|
12192
12521
|
// For "async while", an implicit "await" is performed.
|
12193
12522
|
if (isAsync) {
|
12194
|
-
|
12523
|
+
enterType = getTypeOfAwaitable(enterType, node.expression);
|
12195
12524
|
}
|
12196
|
-
return
|
12525
|
+
return enterType;
|
12197
12526
|
}
|
12198
12527
|
if (!isAsync) {
|
12199
|
-
|
12200
|
-
|
12528
|
+
if (getTypeOfMagicMethodReturn(subtype, [], '__aenter__', node.expression,
|
12529
|
+
/* expectedType */ undefined)) {
|
12201
12530
|
additionalHelp.addMessage(localize_1.Localizer.DiagnosticAddendum.asyncHelp());
|
12202
12531
|
}
|
12203
12532
|
}
|
@@ -12214,9 +12543,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12214
12543
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
12215
12544
|
return;
|
12216
12545
|
}
|
12217
|
-
|
12218
|
-
|
12219
|
-
const exitType =
|
12546
|
+
if ((0, types_1.isClass)(subtype)) {
|
12547
|
+
const anyArg = { type: types_1.AnyType.create() };
|
12548
|
+
const exitType = getTypeOfMagicMethodReturn(subtype, [anyArg, anyArg, anyArg], exitMethodName, node.expression,
|
12549
|
+
/* expectedType */ undefined);
|
12220
12550
|
if (exitType) {
|
12221
12551
|
return;
|
12222
12552
|
}
|
@@ -12528,6 +12858,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12528
12858
|
}
|
12529
12859
|
getTypeOfAnnotation(annotationNode, {
|
12530
12860
|
isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
|
12861
|
+
allowUnpackedTuple: annotationParent.nodeType === 41 /* Parameter */ &&
|
12862
|
+
annotationParent.category === 1 /* VarArgList */,
|
12863
|
+
allowUnpackedTypedDict: annotationParent.nodeType === 41 /* Parameter */ &&
|
12864
|
+
annotationParent.category === 2 /* VarArgDictionary */,
|
12531
12865
|
});
|
12532
12866
|
return;
|
12533
12867
|
}
|
@@ -12588,6 +12922,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12588
12922
|
break;
|
12589
12923
|
}
|
12590
12924
|
}
|
12925
|
+
else if (parent.nodeType === 48 /* StringList */ && nodeToEvaluate === parent.typeAnnotation) {
|
12926
|
+
// Forward-declared type annotation expressions need to be be evaluated
|
12927
|
+
// in context so they have the appropriate flags set. Most of these cases
|
12928
|
+
// will have been detected above when calling getParentAnnotationNode,
|
12929
|
+
// but TypeAlias expressions are not handled there.
|
12930
|
+
nodeToEvaluate = parent;
|
12931
|
+
continue;
|
12932
|
+
}
|
12591
12933
|
else {
|
12592
12934
|
// Check for expression types that are always contextual.
|
12593
12935
|
if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
|
@@ -12903,17 +13245,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12903
13245
|
}
|
12904
13246
|
// Attempts to determine the type of the reference expression at the
|
12905
13247
|
// point in the code. If the code flow analysis has nothing to say
|
12906
|
-
// about that expression, it
|
12907
|
-
// starts from the reference node, but startNode can be
|
12908
|
-
// override this in a few special cases (functions and
|
12909
|
-
// support analysis of captured variables.
|
12910
|
-
function getFlowTypeOfReference(reference, targetSymbolId,
|
13248
|
+
// about that expression, it returns un undefined type. Normally
|
13249
|
+
// flow analysis starts from the reference node, but startNode can be
|
13250
|
+
// specified to override this in a few special cases (functions and
|
13251
|
+
// lambdas) to support analysis of captured variables.
|
13252
|
+
function getFlowTypeOfReference(reference, targetSymbolId, typeAtStart, startNode, options) {
|
12911
13253
|
var _a;
|
12912
13254
|
// See if this execution scope requires code flow for this reference expression.
|
12913
13255
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(reference);
|
12914
13256
|
const executionNode = ParseTreeUtils.getExecutionScopeNode((_a = startNode === null || startNode === void 0 ? void 0 : startNode.parent) !== null && _a !== void 0 ? _a : reference);
|
12915
13257
|
const codeFlowExpressions = AnalyzerNodeInfo.getCodeFlowExpressions(executionNode);
|
12916
|
-
if (!codeFlowExpressions ||
|
13258
|
+
if (!codeFlowExpressions ||
|
13259
|
+
(!codeFlowExpressions.has(referenceKey) && !codeFlowExpressions.has(codeFlowTypes_1.wildcardImportReferenceKey))) {
|
12917
13260
|
return { type: undefined, isIncomplete: false };
|
12918
13261
|
}
|
12919
13262
|
if (checkCodeFlowTooComplex(reference)) {
|
@@ -12935,7 +13278,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12935
13278
|
if (flowNode === undefined) {
|
12936
13279
|
return { type: undefined, isIncomplete: false };
|
12937
13280
|
}
|
12938
|
-
return analyzer.getTypeFromCodeFlow(flowNode, reference, targetSymbolId,
|
13281
|
+
return analyzer.getTypeFromCodeFlow(flowNode, reference, targetSymbolId, typeAtStart, options);
|
12939
13282
|
}
|
12940
13283
|
// Specializes the specified (potentially generic) class type using
|
12941
13284
|
// the specified type arguments, reporting errors as appropriate.
|
@@ -13068,6 +13411,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13068
13411
|
}
|
13069
13412
|
const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
13070
13413
|
if (typeArgs) {
|
13414
|
+
let minTypeArgCount = typeParameters.length;
|
13415
|
+
const firstNonDefaultParam = typeParameters.findIndex((param) => !!param.details.defaultType);
|
13416
|
+
if (firstNonDefaultParam >= 0) {
|
13417
|
+
minTypeArgCount = firstNonDefaultParam;
|
13418
|
+
}
|
13071
13419
|
if (typeArgCount > typeParameters.length) {
|
13072
13420
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
13073
13421
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
@@ -13086,11 +13434,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13086
13434
|
typeArgCount = typeParameters.length;
|
13087
13435
|
}
|
13088
13436
|
}
|
13089
|
-
else if (typeArgCount <
|
13437
|
+
else if (typeArgCount < minTypeArgCount) {
|
13090
13438
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
13091
13439
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
|
13092
13440
|
name: classType.aliasName || classType.details.name,
|
13093
|
-
expected:
|
13441
|
+
expected: minTypeArgCount,
|
13094
13442
|
received: typeArgCount,
|
13095
13443
|
}), typeArgs.length > 0 ? typeArgs[0].node.parent : errorNode);
|
13096
13444
|
}
|
@@ -13148,6 +13496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13148
13496
|
}
|
13149
13497
|
}
|
13150
13498
|
fullTypeParams.forEach((typeParam, index) => {
|
13499
|
+
var _a;
|
13151
13500
|
if (typeArgs && index < typeArgs.length) {
|
13152
13501
|
if (typeParam.details.isParamSpec) {
|
13153
13502
|
const typeArg = typeArgs[index];
|
@@ -13199,7 +13548,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13199
13548
|
typeArgTypes.push((0, typeUtils_1.convertToInstance)(typeArgs[index].type));
|
13200
13549
|
return;
|
13201
13550
|
}
|
13202
|
-
typeArgTypes.push(types_1.UnknownType.create());
|
13551
|
+
typeArgTypes.push((_a = typeParam.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create());
|
13203
13552
|
});
|
13204
13553
|
typeArgTypes = typeArgTypes.map((typeArgType, index) => {
|
13205
13554
|
if (index < typeArgCount) {
|
@@ -13208,19 +13557,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13208
13557
|
// Determine if the variance must match.
|
13209
13558
|
if (adjustedTypeArgType && (flags & 16384 /* EnforceTypeVarVarianceConsistency */) !== 0) {
|
13210
13559
|
const destType = typeParameters[index];
|
13211
|
-
|
13212
|
-
|
13213
|
-
|
13214
|
-
|
13215
|
-
|
13216
|
-
|
13217
|
-
|
13218
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatch().format({
|
13219
|
-
typeVarName: printType(adjustedTypeArgType),
|
13220
|
-
className: classType.details.name,
|
13221
|
-
}));
|
13222
|
-
adjustedTypeArgType = undefined;
|
13223
|
-
}
|
13560
|
+
const declaredVariance = destType.details.declaredVariance;
|
13561
|
+
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
|
13562
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatch().format({
|
13563
|
+
typeVarName: printType(adjustedTypeArgType),
|
13564
|
+
className: classType.details.name,
|
13565
|
+
}));
|
13566
|
+
adjustedTypeArgType = undefined;
|
13224
13567
|
}
|
13225
13568
|
}
|
13226
13569
|
if (adjustedTypeArgType) {
|
@@ -13272,11 +13615,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13272
13615
|
// be a value expression from which we can retrieve the type.
|
13273
13616
|
return getTypeOfExpressionExpectingType(arg.valueExpression);
|
13274
13617
|
}
|
13275
|
-
function getTypeOfExpressionExpectingType(node,
|
13618
|
+
function getTypeOfExpressionExpectingType(node, options) {
|
13276
13619
|
let flags = 64 /* ExpectingType */ |
|
13277
13620
|
8 /* EvaluateStringLiteralAsType */ |
|
13278
|
-
32 /* ParamSpecDisallowed */ |
|
13279
|
-
128 /* TypeVarTupleDisallowed */ |
|
13280
13621
|
131072 /* ClassVarDisallowed */;
|
13281
13622
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13282
13623
|
if (fileInfo.isStubFile) {
|
@@ -13285,12 +13626,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13285
13626
|
else {
|
13286
13627
|
flags |= 4194304 /* InterpreterParsesStringLiteral */;
|
13287
13628
|
}
|
13288
|
-
if (!allowFinal) {
|
13629
|
+
if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
|
13289
13630
|
flags |= 16 /* FinalDisallowed */;
|
13290
13631
|
}
|
13291
|
-
if (allowRequired) {
|
13632
|
+
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
13292
13633
|
flags |= 1048576 /* RequiredAllowed */ | 1024 /* ExpectingTypeAnnotation */;
|
13293
13634
|
}
|
13635
|
+
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
13636
|
+
flags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
13637
|
+
}
|
13638
|
+
else {
|
13639
|
+
flags |= 128 /* TypeVarTupleDisallowed */;
|
13640
|
+
}
|
13641
|
+
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
13642
|
+
flags |= 32 /* ParamSpecDisallowed */;
|
13643
|
+
}
|
13294
13644
|
return getTypeOfExpression(node, flags);
|
13295
13645
|
}
|
13296
13646
|
function getBuiltInType(node, name) {
|
@@ -13494,6 +13844,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13494
13844
|
}
|
13495
13845
|
return declarations.length === 0 ? undefined : declarations;
|
13496
13846
|
}
|
13847
|
+
function getAliasFromImport(node) {
|
13848
|
+
if (node.parent &&
|
13849
|
+
node.parent.nodeType === 23 /* ImportFromAs */ &&
|
13850
|
+
node.parent.alias &&
|
13851
|
+
node === node.parent.name) {
|
13852
|
+
return node.parent.alias;
|
13853
|
+
}
|
13854
|
+
return undefined;
|
13855
|
+
}
|
13497
13856
|
function getDeclarationsForNameNode(node, skipUnreachableCode = true) {
|
13498
13857
|
var _a;
|
13499
13858
|
if (skipUnreachableCode && AnalyzerNodeInfo.isCodeUnreachable(node)) {
|
@@ -13503,14 +13862,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13503
13862
|
// If the node is part of a "from X import Y as Z" statement and the node
|
13504
13863
|
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
13505
13864
|
// since the non-aliased name is not in the symbol table.
|
13506
|
-
|
13507
|
-
|
13508
|
-
node.parent.alias &&
|
13509
|
-
node === node.parent.name) {
|
13865
|
+
const alias = getAliasFromImport(node);
|
13866
|
+
if (alias) {
|
13510
13867
|
const scope = ScopeUtils.getScopeForNode(node);
|
13511
13868
|
if (scope) {
|
13512
13869
|
// Look up the alias symbol.
|
13513
|
-
const symbolInScope = scope.lookUpSymbolRecursive(
|
13870
|
+
const symbolInScope = scope.lookUpSymbolRecursive(alias.value);
|
13514
13871
|
if (symbolInScope) {
|
13515
13872
|
// The alias could have more decls that don't refer to this import. Filter
|
13516
13873
|
// out the one(s) that specifically associated with this import statement.
|
@@ -13623,7 +13980,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13623
13980
|
if (paramDecl) {
|
13624
13981
|
declarations.push(paramDecl);
|
13625
13982
|
}
|
13626
|
-
else if (types_1.ClassType.isDataClass(baseType)) {
|
13983
|
+
else if (types_1.ClassType.isDataClass(baseType) || types_1.ClassType.isTypedDictClass(baseType)) {
|
13627
13984
|
const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
|
13628
13985
|
if (lookupResults) {
|
13629
13986
|
(0, collectionUtils_1.appendArray)(declarations, lookupResults.symbol.getDeclarations());
|
@@ -13743,7 +14100,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13743
14100
|
const constraints = declaration.node.boundExpression.expressions.map((constraint) => {
|
13744
14101
|
const constraintType = getTypeOfExpressionExpectingType(constraint).type;
|
13745
14102
|
if ((0, typeUtils_1.requiresSpecialization)(constraintType, /* ignorePseudoGeneric */ true)) {
|
13746
|
-
addError(localize_1.Localizer.Diagnostic.
|
14103
|
+
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), constraint);
|
13747
14104
|
}
|
13748
14105
|
return (0, typeUtils_1.convertToInstance)(constraintType);
|
13749
14106
|
});
|
@@ -13758,13 +14115,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13758
14115
|
else {
|
13759
14116
|
const boundType = getTypeOfExpressionExpectingType(declaration.node.boundExpression).type;
|
13760
14117
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, /* ignorePseudoGeneric */ true)) {
|
13761
|
-
addError(localize_1.Localizer.Diagnostic.
|
14118
|
+
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), declaration.node.boundExpression);
|
13762
14119
|
}
|
13763
14120
|
if (declaration.node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
13764
14121
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(boundType);
|
13765
14122
|
}
|
13766
14123
|
}
|
13767
14124
|
}
|
14125
|
+
if (declaration.node.defaultExpression) {
|
14126
|
+
// TODO - need to finish. For now, just evaluate the expression
|
14127
|
+
// to generate any errors.
|
14128
|
+
getTypeOfExpression(declaration.node.defaultExpression, 2097152 /* AllowUnpackedTupleOrTypeVarTuple */);
|
14129
|
+
}
|
13768
14130
|
typeVar.details.isTypeParamSyntax = true;
|
13769
14131
|
// Associate the type variable with the owning scope.
|
13770
14132
|
const scopeNode = ParseTreeUtils.getTypeVarScopeNode(declaration.node);
|
@@ -13794,9 +14156,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13794
14156
|
: undefined;
|
13795
14157
|
let declaredType;
|
13796
14158
|
if (declaration.isRuntimeTypeExpression) {
|
13797
|
-
declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode,
|
13798
|
-
|
13799
|
-
|
14159
|
+
declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode, {
|
14160
|
+
allowFinal: true,
|
14161
|
+
allowRequired: true,
|
14162
|
+
}).type);
|
13800
14163
|
}
|
13801
14164
|
else {
|
13802
14165
|
const declNode = declaration.isDefinedByMemberAccess &&
|
@@ -14054,6 +14417,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14054
14417
|
return getEffectiveTypeOfSymbolForUsage(symbol).type;
|
14055
14418
|
}
|
14056
14419
|
function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
|
14420
|
+
var _a;
|
14057
14421
|
// If there's a declared type, it takes precedence over inferred types.
|
14058
14422
|
if (symbol.hasTypedDeclarations()) {
|
14059
14423
|
const declaredType = getDeclaredTypeOfSymbol(symbol, usageNode);
|
@@ -14077,12 +14441,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14077
14441
|
}
|
14078
14442
|
// Look in the cache to see if we've computed this already.
|
14079
14443
|
let cacheEntries = effectiveTypeCache.get(symbol.id);
|
14444
|
+
let evaluationAttempts = 0;
|
14080
14445
|
const usageNodeId = usageNode ? usageNode.id : undefined;
|
14081
14446
|
const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
|
14082
14447
|
if (cacheEntries) {
|
14083
14448
|
const result = cacheEntries.get(effectiveTypeCacheKey);
|
14084
14449
|
if (result) {
|
14085
|
-
|
14450
|
+
if (!result.isIncomplete) {
|
14451
|
+
return result;
|
14452
|
+
}
|
14453
|
+
evaluationAttempts = ((_a = result.evaluationAttempts) !== null && _a !== void 0 ? _a : 0) + 1;
|
14086
14454
|
}
|
14087
14455
|
}
|
14088
14456
|
// Infer the type.
|
@@ -14090,6 +14458,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14090
14458
|
const decls = symbol.getDeclarations();
|
14091
14459
|
const isFinalVar = (0, symbolUtils_1.isFinalVariable)(symbol);
|
14092
14460
|
let isIncomplete = false;
|
14461
|
+
let sawPendingEvaluation = false;
|
14093
14462
|
let includesVariableDecl = false;
|
14094
14463
|
let includesSpeculativeResult = false;
|
14095
14464
|
let declIndexToConsider;
|
@@ -14138,7 +14507,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14138
14507
|
}
|
14139
14508
|
if (considerDecl) {
|
14140
14509
|
const isExplicitTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(decl);
|
14141
|
-
const isTypeAlias = isExplicitTypeAlias || (
|
14510
|
+
const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
|
14142
14511
|
if (isExplicitTypeAlias) {
|
14143
14512
|
sawExplicitTypeAlias = true;
|
14144
14513
|
}
|
@@ -14208,16 +14577,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14208
14577
|
}
|
14209
14578
|
}
|
14210
14579
|
isIncomplete = true;
|
14580
|
+
// Note that at least one decl could not be evaluated because
|
14581
|
+
// it was already in the process of being evaluated. Don't set
|
14582
|
+
// this flag if we've already attempted the type evaluation
|
14583
|
+
// many times because this probably means there's a cyclical
|
14584
|
+
// dependency that cannot be broken.
|
14585
|
+
if (evaluationAttempts < maxEffectiveTypeEvaluationAttempts) {
|
14586
|
+
sawPendingEvaluation = true;
|
14587
|
+
}
|
14211
14588
|
}
|
14212
14589
|
}
|
14213
14590
|
});
|
14214
14591
|
if (typesToCombine.length > 0) {
|
14215
14592
|
const result = {
|
14216
14593
|
type: (0, types_1.combineTypes)(typesToCombine),
|
14217
|
-
isIncomplete:
|
14594
|
+
isIncomplete: sawPendingEvaluation,
|
14218
14595
|
includesVariableDecl,
|
14219
14596
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14220
14597
|
isRecursiveDefinition: false,
|
14598
|
+
evaluationAttempts,
|
14221
14599
|
};
|
14222
14600
|
if (!includesSpeculativeResult) {
|
14223
14601
|
// Add the entry to the cache so we don't need to compute it next time.
|
@@ -14235,6 +14613,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14235
14613
|
includesVariableDecl,
|
14236
14614
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14237
14615
|
isRecursiveDefinition: false,
|
14616
|
+
evaluationAttempts,
|
14238
14617
|
};
|
14239
14618
|
}
|
14240
14619
|
function getDeclaredTypeOfSymbol(symbol, usageNode) {
|
@@ -14759,9 +15138,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14759
15138
|
}
|
14760
15139
|
}
|
14761
15140
|
else {
|
14762
|
-
const
|
15141
|
+
const removedArgTypes = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture).map((t) => {
|
15142
|
+
if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
|
15143
|
+
return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
|
15144
|
+
}
|
15145
|
+
return t.type;
|
15146
|
+
});
|
14763
15147
|
srcTypeArgs.splice(destUnboundedIndex, 0, {
|
14764
|
-
type:
|
15148
|
+
type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
|
14765
15149
|
isUnbounded: false,
|
14766
15150
|
});
|
14767
15151
|
}
|
@@ -14979,14 +15363,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14979
15363
|
// and added to the map.
|
14980
15364
|
function assignType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags = 0 /* Default */, recursionCount = 0) {
|
14981
15365
|
var _a, _b;
|
14982
|
-
// If this is a one-element union that contains a variadic type variable,
|
14983
|
-
// pull out the subtype.
|
14984
|
-
if ((0, types_1.isUnion)(destType) && destType.subtypes.length === 1 && (0, types_1.isVariadicTypeVar)(destType.subtypes[0])) {
|
14985
|
-
destType = destType.subtypes[0];
|
14986
|
-
}
|
14987
|
-
if ((0, types_1.isUnion)(srcType) && srcType.subtypes.length === 1 && (0, types_1.isVariadicTypeVar)(srcType.subtypes[0])) {
|
14988
|
-
srcType = srcType.subtypes[0];
|
14989
|
-
}
|
14990
15366
|
// Handle the case where the dest and src types are the same object.
|
14991
15367
|
// We can normally shortcut this and say that they are compatible,
|
14992
15368
|
// but if the type includes TypeVars, we need to go through
|
@@ -15238,34 +15614,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15238
15614
|
}
|
15239
15615
|
}
|
15240
15616
|
// Is the src a specialized "Type" object?
|
15241
|
-
if ((0, types_1.isClassInstance)(
|
15242
|
-
const srcTypeArgs =
|
15617
|
+
if ((0, types_1.isClassInstance)(expandedSrcType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
|
15618
|
+
const srcTypeArgs = expandedSrcType.typeArguments;
|
15619
|
+
let typeTypeArg;
|
15620
|
+
let instantiableType;
|
15243
15621
|
if (srcTypeArgs && srcTypeArgs.length >= 1) {
|
15244
|
-
|
15245
|
-
|
15622
|
+
typeTypeArg = srcTypeArgs[0];
|
15623
|
+
if ((0, types_1.isAnyOrUnknown)(typeTypeArg)) {
|
15624
|
+
if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
|
15246
15625
|
return true;
|
15247
15626
|
}
|
15248
15627
|
return types_1.TypeBase.isInstantiable(destType);
|
15249
15628
|
}
|
15250
|
-
|
15251
|
-
|
15252
|
-
|
15253
|
-
|
15254
|
-
|
15255
|
-
|
15256
|
-
|
15257
|
-
|
15258
|
-
return
|
15629
|
+
instantiableType = (0, typeUtils_1.convertToInstantiable)(typeTypeArg);
|
15630
|
+
}
|
15631
|
+
else {
|
15632
|
+
typeTypeArg = objectType !== null && objectType !== void 0 ? objectType : types_1.AnyType.create();
|
15633
|
+
instantiableType = expandedSrcType;
|
15634
|
+
}
|
15635
|
+
if ((0, types_1.isClassInstance)(typeTypeArg) || (0, types_1.isTypeVar)(typeTypeArg)) {
|
15636
|
+
if (assignType(destType, instantiableType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
15637
|
+
return true;
|
15259
15638
|
}
|
15639
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
15640
|
+
sourceType: printType(srcType),
|
15641
|
+
destType: printType(destType),
|
15642
|
+
}));
|
15643
|
+
return false;
|
15260
15644
|
}
|
15261
15645
|
}
|
15262
15646
|
if ((0, types_1.isInstantiableClass)(destType)) {
|
15263
|
-
|
15264
|
-
if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
|
15647
|
+
if ((0, types_1.isInstantiableClass)(expandedSrcType)) {
|
15265
15648
|
// PEP 544 says that if the dest type is a Type[Proto] class,
|
15266
15649
|
// the source must be a "concrete" (non-protocol) class.
|
15267
15650
|
if (types_1.ClassType.isProtocolClass(destType)) {
|
15268
|
-
if (types_1.ClassType.isProtocolClass(
|
15651
|
+
if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
15269
15652
|
(0, types_1.isInstantiableClass)(srcType) &&
|
15270
15653
|
!srcType.includeSubclasses) {
|
15271
15654
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.protocolSourceIsNotConcrete().format({
|
@@ -15275,7 +15658,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15275
15658
|
return false;
|
15276
15659
|
}
|
15277
15660
|
}
|
15278
|
-
if (assignClass(destType,
|
15661
|
+
if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
15279
15662
|
/* reportErrorsUsingObjType */ false)) {
|
15280
15663
|
return true;
|
15281
15664
|
}
|
@@ -15628,6 +16011,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15628
16011
|
// matches for types like `tuple[Any]` and `tuple[int]` from being considered
|
15629
16012
|
// proper subtypes of each other.
|
15630
16013
|
function isProperSubtype(destType, srcType, recursionCount) {
|
16014
|
+
// If the destType has a condition, don't consider the srcType a proper subtype.
|
16015
|
+
if (destType.condition) {
|
16016
|
+
return false;
|
16017
|
+
}
|
15631
16018
|
// Shortcut the check if either type is Any or Unknown.
|
15632
16019
|
if ((0, types_1.isAnyOrUnknown)(destType) || (0, types_1.isAnyOrUnknown)(srcType)) {
|
15633
16020
|
return true;
|
@@ -15694,9 +16081,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15694
16081
|
// If so, we need to use a slower path.
|
15695
16082
|
if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
|
15696
16083
|
for (const subtype of destType.subtypes) {
|
15697
|
-
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(),
|
15698
|
-
/* destTypeVarContextClone */ undefined,
|
15699
|
-
/* srcTypeVarContextClone */ undefined, flags, recursionCount)) {
|
16084
|
+
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
15700
16085
|
foundMatch = true;
|
15701
16086
|
break;
|
15702
16087
|
}
|
@@ -16394,7 +16779,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16394
16779
|
const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
|
16395
16780
|
const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
|
16396
16781
|
if (effectiveDestType.details.paramSpec) {
|
16397
|
-
const requiredMatchParamCount =
|
16782
|
+
const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
|
16783
|
+
if (!p.name) {
|
16784
|
+
return false;
|
16785
|
+
}
|
16398
16786
|
if (p.category === 0 /* Simple */ && (0, types_1.isParamSpec)(p.type)) {
|
16399
16787
|
return false;
|
16400
16788
|
}
|
@@ -16421,6 +16809,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16421
16809
|
name: p.name,
|
16422
16810
|
isNameSynthesized: p.isNameSynthesized,
|
16423
16811
|
hasDefault: !!p.hasDefault,
|
16812
|
+
defaultValueExpression: p.defaultValueExpression,
|
16424
16813
|
type: types_1.FunctionType.getEffectiveParameterType(effectiveSrcType, index),
|
16425
16814
|
});
|
16426
16815
|
}
|
@@ -16515,7 +16904,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16515
16904
|
// replace that type argument in the assigned type. This function assumes
|
16516
16905
|
// that the caller has already verified that the assignedType is assignable
|
16517
16906
|
// to the declaredType.
|
16518
|
-
function replaceTypeArgsWithAny(declaredType, assignedType) {
|
16907
|
+
function replaceTypeArgsWithAny(declaredType, assignedType, recursionCount = 0) {
|
16908
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
16909
|
+
return undefined;
|
16910
|
+
}
|
16911
|
+
recursionCount++;
|
16519
16912
|
// If this is a tuple with defined tuple type arguments, don't overwrite them.
|
16520
16913
|
if (assignedType.tupleTypeArguments) {
|
16521
16914
|
return undefined;
|
@@ -16536,6 +16929,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16536
16929
|
replacedTypeArg = true;
|
16537
16930
|
return expectedTypeArgType;
|
16538
16931
|
}
|
16932
|
+
else if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
|
16933
|
+
// Recursively replace Any in the type argument.
|
16934
|
+
const recursiveReplacement = replaceTypeArgsWithAny(expectedTypeArgType, typeArg, recursionCount);
|
16935
|
+
if (recursiveReplacement) {
|
16936
|
+
replacedTypeArg = true;
|
16937
|
+
return recursiveReplacement;
|
16938
|
+
}
|
16939
|
+
}
|
16539
16940
|
}
|
16540
16941
|
return typeArg;
|
16541
16942
|
});
|
@@ -16575,10 +16976,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16575
16976
|
// use the concrete type.
|
16576
16977
|
return declaredSubtype;
|
16577
16978
|
}
|
16578
|
-
else if ((0, types_1.isAnyOrUnknown)(assignedSubtype)) {
|
16579
|
-
// Any or Unknown do not narrow because they're assignable to all types.
|
16580
|
-
return declaredSubtype;
|
16581
|
-
}
|
16582
16979
|
return assignedSubtype;
|
16583
16980
|
}
|
16584
16981
|
return undefined;
|
@@ -16591,7 +16988,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16591
16988
|
return narrowedSubtype;
|
16592
16989
|
});
|
16593
16990
|
// If the result of narrowing is Any, stick with the declared (unnarrowed) type.
|
16594
|
-
|
16991
|
+
// If the result of narrowing is an Unknown that is complete, stick with Unknown.
|
16992
|
+
// If it's incomplete, propagate the incomplete type for the benefit of
|
16993
|
+
// code flow analysis.
|
16994
|
+
if ((0, types_1.isAnyOrUnknown)(assignedType) && !(0, typeUtils_1.isIncompleteUnknown)(assignedType)) {
|
16595
16995
|
return declaredType;
|
16596
16996
|
}
|
16597
16997
|
return narrowedType;
|
@@ -16698,6 +17098,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16698
17098
|
const overrideParam = overrideParamDetails.params[i].param;
|
16699
17099
|
if (i >= baseParamDetails.positionOnlyParamCount &&
|
16700
17100
|
!(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
|
17101
|
+
baseParamDetails.params[i].source !== typeUtils_1.ParameterSource.PositionOnly &&
|
16701
17102
|
baseParam.category === 0 /* Simple */ &&
|
16702
17103
|
baseParam.name !== overrideParam.name) {
|
16703
17104
|
if (overrideParam.category === 0 /* Simple */) {
|
@@ -17108,11 +17509,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17108
17509
|
function printFunctionParts(type) {
|
17109
17510
|
return TypePrinter.printFunctionParts(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
|
17110
17511
|
}
|
17111
|
-
function printType(type,
|
17512
|
+
function printType(type, options) {
|
17112
17513
|
let flags = evaluatorOptions.printTypeFlags;
|
17113
|
-
if (expandTypeAlias) {
|
17514
|
+
if (options === null || options === void 0 ? void 0 : options.expandTypeAlias) {
|
17114
17515
|
flags |= 32 /* ExpandTypeAlias */;
|
17115
17516
|
}
|
17517
|
+
if (options === null || options === void 0 ? void 0 : options.enforcePythonSyntax) {
|
17518
|
+
flags |= 256 /* PythonSyntax */;
|
17519
|
+
}
|
17520
|
+
if (options === null || options === void 0 ? void 0 : options.useTypingUnpack) {
|
17521
|
+
flags |= 512 /* UseTypingUnpack */;
|
17522
|
+
}
|
17116
17523
|
return TypePrinter.printType(type, flags, getFunctionEffectiveReturnType);
|
17117
17524
|
}
|
17118
17525
|
// Calls back into the parser to parse the contents of a string literal.
|