@zzzen/pyright-internal 1.2.0-dev.20221016 → 1.2.0-dev.20221127
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 +1 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +3 -3
- package/dist/analyzer/dataClasses.js +77 -57
- 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 +4 -3
- 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 +76 -77
- 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 +9 -6
- package/dist/analyzer/service.js +58 -27
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +5 -2
- package/dist/analyzer/sourceFile.js +21 -8
- 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 +643 -254
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +15 -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 +135 -26
- 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 +112 -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 +5 -4
- package/dist/analyzer/types.js +43 -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 +13 -3
- 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 +7 -5
- package/dist/languageServerBase.js +30 -20
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +6 -2
- package/dist/languageService/analyzerServiceExecutor.js +7 -4
- 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 +1 -0
- package/dist/languageService/completionProvider.js +66 -28
- 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/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 +19 -13
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +2 -1
- 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/checker.test.js +25 -2
- 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 +25 -0
- 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 +28 -6
- 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 +4 -2
- 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 +77 -161
- 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/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/pathUtils.test.js +7 -0
- package/dist/tests/pathUtils.test.js.map +1 -1
- 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 +40 -10
- 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 +2 -0
- package/dist/workspaceMap.js +45 -12
- 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
@@ -677,9 +677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
677
677
|
}
|
678
678
|
if (reportExpectingTypeErrors && !typeResult.isIncomplete) {
|
679
679
|
if (flags & 128 /* TypeVarTupleDisallowed */) {
|
680
|
-
if ((0, types_1.
|
681
|
-
typeResult.type.details.isVariadic &&
|
682
|
-
!typeResult.type.isVariadicInUnion) {
|
680
|
+
if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicInUnion) {
|
683
681
|
addError(localize_1.Localizer.Diagnostic.typeVarTupleContext(), node);
|
684
682
|
typeResult.type = types_1.UnknownType.create();
|
685
683
|
}
|
@@ -691,6 +689,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
691
689
|
if (!isEmptyVariadic) {
|
692
690
|
addExpectedClassDiagnostic(typeResult.type, node);
|
693
691
|
typeResult.type = types_1.UnknownType.create();
|
692
|
+
typeResult.typeErrors = true;
|
694
693
|
}
|
695
694
|
}
|
696
695
|
}
|
@@ -779,8 +778,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
779
778
|
typeResult = { type: types_1.ClassType.cloneForUnpacked(iterType) };
|
780
779
|
}
|
781
780
|
else {
|
782
|
-
const
|
783
|
-
|
781
|
+
const iteratorTypeResult = (_a = getTypeOfIterator(iterTypeResult, /* isAsync */ false, node)) !== null && _a !== void 0 ? _a : {
|
782
|
+
type: types_1.UnknownType.create(!!iterTypeResult.isIncomplete),
|
783
|
+
isIncomplete: iterTypeResult.isIncomplete,
|
784
|
+
};
|
785
|
+
typeResult = {
|
786
|
+
type: iteratorTypeResult.type,
|
787
|
+
unpackedType: iterType,
|
788
|
+
isIncomplete: iteratorTypeResult.isIncomplete,
|
789
|
+
};
|
784
790
|
}
|
785
791
|
}
|
786
792
|
return typeResult;
|
@@ -869,17 +875,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
869
875
|
// the resulting formatted string is also LiteralString.
|
870
876
|
node.expressions.forEach((expr) => {
|
871
877
|
const exprType = getTypeOfExpression(expr).type;
|
872
|
-
|
878
|
+
(0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
|
879
|
+
if (!(0, types_1.isClassInstance)(exprSubtype)) {
|
880
|
+
isLiteralString = false;
|
881
|
+
return;
|
882
|
+
}
|
883
|
+
if (types_1.ClassType.isBuiltIn(exprSubtype, 'LiteralString')) {
|
884
|
+
return;
|
885
|
+
}
|
886
|
+
if (types_1.ClassType.isBuiltIn(exprSubtype, 'str') && exprSubtype.literalValue !== undefined) {
|
887
|
+
return;
|
888
|
+
}
|
873
889
|
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;
|
890
|
+
});
|
883
891
|
});
|
884
892
|
if (!isBytes && isLiteralString) {
|
885
893
|
const literalStringType = getTypingType(node, 'LiteralString');
|
@@ -1092,6 +1100,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1092
1100
|
if ((0, typeUtils_1.isTupleClass)(type) && type.tupleTypeArguments) {
|
1093
1101
|
return (0, typeUtils_1.isUnboundedTupleClass)(type) || type.tupleTypeArguments.length === 0;
|
1094
1102
|
}
|
1103
|
+
// Handle subclasses of tuple, such as NamedTuple.
|
1104
|
+
const tupleBaseClass = type.details.mro.find((mroClass) => !(0, types_1.isClass)(mroClass) || (0, typeUtils_1.isTupleClass)(mroClass));
|
1105
|
+
if (tupleBaseClass && (0, types_1.isClass)(tupleBaseClass) && tupleBaseClass.tupleTypeArguments) {
|
1106
|
+
return (0, typeUtils_1.isUnboundedTupleClass)(tupleBaseClass) || tupleBaseClass.tupleTypeArguments.length === 0;
|
1107
|
+
}
|
1095
1108
|
// Check for Literal[False] and Literal[True].
|
1096
1109
|
if (types_1.ClassType.isBuiltIn(type, 'bool') && type.literalValue !== undefined) {
|
1097
1110
|
return type.literalValue === false;
|
@@ -1402,8 +1415,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1402
1415
|
case 7 /* Class */: {
|
1403
1416
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
1404
1417
|
let methodType;
|
1405
|
-
// Try to get the __init__ method first because it typically has
|
1406
|
-
//
|
1418
|
+
// Try to get the `__init__` method first because it typically has more
|
1419
|
+
// type information than `__new__`.
|
1407
1420
|
methodType = getBoundMethod(subtype, '__init__');
|
1408
1421
|
// Is this the __init__ method provided by the object class?
|
1409
1422
|
const isObjectInit = !!methodType &&
|
@@ -1413,7 +1426,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1413
1426
|
// If there was no `__init__` or the only `__init__` that was found
|
1414
1427
|
// was form the `object` class, see if we can find a better `__new__`
|
1415
1428
|
// method.
|
1416
|
-
if (!methodType ||
|
1429
|
+
if (!methodType ||
|
1430
|
+
isObjectInit ||
|
1431
|
+
isSkipConstructor ||
|
1432
|
+
(methodType &&
|
1433
|
+
(0, types_1.isFunction)(methodType) &&
|
1434
|
+
(types_1.FunctionType.hasDefaultParameters(methodType) ||
|
1435
|
+
methodType.details.parameters.length === 0))) {
|
1417
1436
|
const constructorType = getBoundMethod(subtype, '__new__',
|
1418
1437
|
/* recursionCount */ undefined,
|
1419
1438
|
/* treatConstructorAsClassMember */ true);
|
@@ -1615,14 +1634,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1615
1634
|
}
|
1616
1635
|
// Validates that the type is an iterator and returns the iterated type
|
1617
1636
|
// (i.e. the type returned from the '__next__' or '__anext__' method).
|
1618
|
-
function getTypeOfIterator(
|
1637
|
+
function getTypeOfIterator(typeResult, isAsync, errorNode) {
|
1619
1638
|
const iterMethodName = isAsync ? '__aiter__' : '__iter__';
|
1620
1639
|
const nextMethodName = isAsync ? '__anext__' : '__next__';
|
1621
1640
|
let isValidIterator = true;
|
1622
|
-
type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
|
1641
|
+
let type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(typeResult.type);
|
1623
1642
|
type = makeTopLevelTypeVarsConcrete(type);
|
1624
1643
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1625
|
-
if (errorNode) {
|
1644
|
+
if (errorNode && !typeResult.isIncomplete) {
|
1626
1645
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
|
1627
1646
|
}
|
1628
1647
|
type = (0, types_1.removeNoneFromUnion)(type);
|
@@ -1677,7 +1696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1677
1696
|
return subtype;
|
1678
1697
|
}
|
1679
1698
|
if ((0, types_1.isClassInstance)(subtype)) {
|
1680
|
-
|
1699
|
+
let nextReturnType = getSpecializedReturnType(subtype, nextMethodName, [], errorNode);
|
1681
1700
|
if (!nextReturnType) {
|
1682
1701
|
iterReturnTypeDiag.addMessage(localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
|
1683
1702
|
name: nextMethodName,
|
@@ -1685,6 +1704,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1685
1704
|
}));
|
1686
1705
|
}
|
1687
1706
|
else {
|
1707
|
+
// Convert any unpacked TypeVarTuples into object instances. We don't
|
1708
|
+
// know anything more about them.
|
1709
|
+
nextReturnType = (0, typeUtils_1.mapSubtypes)(nextReturnType, (returnSubtype) => {
|
1710
|
+
if ((0, types_1.isTypeVar)(returnSubtype) && (0, types_1.isUnpackedVariadicTypeVar)(returnSubtype)) {
|
1711
|
+
return objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create();
|
1712
|
+
}
|
1713
|
+
return returnSubtype;
|
1714
|
+
});
|
1688
1715
|
if (!isAsync) {
|
1689
1716
|
return nextReturnType;
|
1690
1717
|
}
|
@@ -1704,21 +1731,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1704
1731
|
diag.addAddendum(iterReturnTypeDiag);
|
1705
1732
|
}
|
1706
1733
|
}
|
1707
|
-
if (errorNode) {
|
1734
|
+
if (errorNode && !typeResult.isIncomplete) {
|
1708
1735
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIterable().format({ type: printType(subtype) }) + diag.getString(), errorNode);
|
1709
1736
|
}
|
1710
1737
|
isValidIterator = false;
|
1711
1738
|
return undefined;
|
1712
1739
|
});
|
1713
|
-
return isValidIterator ? iterableType : undefined;
|
1740
|
+
return isValidIterator ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
|
1714
1741
|
}
|
1715
1742
|
// Validates that the type is an iterable and returns the iterable type argument.
|
1716
|
-
function getTypeOfIterable(
|
1743
|
+
function getTypeOfIterable(typeResult, isAsync, errorNode) {
|
1717
1744
|
const iterMethodName = isAsync ? '__aiter__' : '__iter__';
|
1718
1745
|
let isValidIterable = true;
|
1719
|
-
type = makeTopLevelTypeVarsConcrete(type);
|
1746
|
+
let type = makeTopLevelTypeVarsConcrete(typeResult.type);
|
1720
1747
|
if ((0, typeUtils_1.isOptionalType)(type)) {
|
1721
|
-
if (errorNode) {
|
1748
|
+
if (errorNode && !typeResult.isIncomplete) {
|
1722
1749
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportOptionalIterable, diagnosticRules_1.DiagnosticRule.reportOptionalIterable, localize_1.Localizer.Diagnostic.noneNotIterable(), errorNode);
|
1723
1750
|
}
|
1724
1751
|
type = (0, types_1.removeNoneFromUnion)(type);
|
@@ -1747,7 +1774,47 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1747
1774
|
isValidIterable = false;
|
1748
1775
|
return undefined;
|
1749
1776
|
});
|
1750
|
-
return isValidIterable ? iterableType : undefined;
|
1777
|
+
return isValidIterable ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
|
1778
|
+
}
|
1779
|
+
function isTypeHashable(type) {
|
1780
|
+
let isTypeHashable = true;
|
1781
|
+
(0, typeUtils_1.doForEachSubtype)(makeTopLevelTypeVarsConcrete(type), (subtype) => {
|
1782
|
+
if ((0, types_1.isClassInstance)(subtype)) {
|
1783
|
+
// Assume the class is hashable.
|
1784
|
+
let isObjectHashable = true;
|
1785
|
+
// Have we already computed and cached the hashability?
|
1786
|
+
if (subtype.details.isInstanceHashable !== undefined) {
|
1787
|
+
isObjectHashable = subtype.details.isInstanceHashable;
|
1788
|
+
}
|
1789
|
+
else {
|
1790
|
+
const hashMember = (0, typeUtils_1.lookUpObjectMember)(subtype, '__hash__', 4 /* SkipObjectBaseClass */);
|
1791
|
+
if (hashMember && hashMember.isTypeDeclared) {
|
1792
|
+
const decls = hashMember.symbol.getTypedDeclarations();
|
1793
|
+
const synthesizedType = hashMember.symbol.getSynthesizedType();
|
1794
|
+
// Handle the case where the type is synthesized (used for
|
1795
|
+
// dataclasses).
|
1796
|
+
if (synthesizedType) {
|
1797
|
+
isObjectHashable = !(0, types_1.isNoneInstance)(synthesizedType);
|
1798
|
+
}
|
1799
|
+
else {
|
1800
|
+
// Assume that if '__hash__' is declared as a variable, it is
|
1801
|
+
// not hashable. If it's declared as a function, it is. We'll
|
1802
|
+
// skip evaluating its full type because that's not needed in
|
1803
|
+
// this case.
|
1804
|
+
if (decls.every((decl) => decl.type === 1 /* Variable */)) {
|
1805
|
+
isObjectHashable = false;
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
}
|
1809
|
+
// Cache the hashability for next time.
|
1810
|
+
subtype.details.isInstanceHashable = isObjectHashable;
|
1811
|
+
}
|
1812
|
+
if (!isObjectHashable) {
|
1813
|
+
isTypeHashable = false;
|
1814
|
+
}
|
1815
|
+
}
|
1816
|
+
});
|
1817
|
+
return isTypeHashable;
|
1751
1818
|
}
|
1752
1819
|
function getTypedDictClassType() {
|
1753
1820
|
return typedDictClassType;
|
@@ -1834,10 +1901,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1834
1901
|
const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode,
|
1835
1902
|
/* reference */ undefined,
|
1836
1903
|
/* targetSymbolId */ undefined,
|
1837
|
-
/*
|
1904
|
+
/* typeAtStart */ types_1.UnboundType.create(), {
|
1838
1905
|
skipNoReturnCallAnalysis: true,
|
1839
1906
|
});
|
1840
|
-
return codeFlowResult.type !== undefined;
|
1907
|
+
return codeFlowResult.type !== undefined && !(0, types_1.isNever)(codeFlowResult.type);
|
1841
1908
|
}
|
1842
1909
|
// Determines whether there is a code flow path from sourceNode to sinkNode.
|
1843
1910
|
function isFlowPathBetweenNodes(sourceNode, sinkNode, allowSelf = true) {
|
@@ -2158,6 +2225,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2158
2225
|
type = makeTopLevelTypeVarsConcrete(type);
|
2159
2226
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
2160
2227
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2228
|
+
var _a, _b;
|
2161
2229
|
// Is this subtype a tuple?
|
2162
2230
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(subtype);
|
2163
2231
|
if (tupleType && tupleType.tupleTypeArguments) {
|
@@ -2214,7 +2282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2214
2282
|
else {
|
2215
2283
|
// The assigned expression isn't a tuple, so it had better
|
2216
2284
|
// be some iterable type.
|
2217
|
-
const iterableType = getTypeOfIterator(subtype, /* isAsync */ false, srcExpr) || types_1.UnknownType.create();
|
2285
|
+
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
2286
|
for (let index = 0; index < targetExpressions.length; index++) {
|
2219
2287
|
targetTypes[index].push((0, typeUtils_1.addConditionToType)(iterableType, (0, typeUtils_1.getTypeCondition)(subtype)));
|
2220
2288
|
}
|
@@ -2266,9 +2334,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2266
2334
|
return types_1.UnknownType.create();
|
2267
2335
|
}
|
2268
2336
|
}
|
2337
|
+
// If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
|
2338
|
+
// *tuple[*Ts].
|
2269
2339
|
if ((0, types_1.isVariadicTypeVar)(subtype)) {
|
2270
2340
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2271
|
-
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
2341
|
+
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
|
2272
2342
|
/* isTypeArgumentExplicit */ true,
|
2273
2343
|
/* isUnpackedTuple */ true));
|
2274
2344
|
}
|
@@ -2533,7 +2603,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2533
2603
|
if (!(0, typeUtils_1.derivesFromClassRecursive)(concreteSubtype, baseExceptionType,
|
2534
2604
|
/* ignoreUnknown */ false)) {
|
2535
2605
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
|
2536
|
-
type: printType(subtype
|
2606
|
+
type: printType(subtype),
|
2537
2607
|
}));
|
2538
2608
|
}
|
2539
2609
|
else {
|
@@ -2545,7 +2615,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2545
2615
|
});
|
2546
2616
|
if (callResult && callResult.argumentErrors) {
|
2547
2617
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeNotInstantiable().format({
|
2548
|
-
type: printType(subtype
|
2618
|
+
type: printType(subtype),
|
2549
2619
|
}));
|
2550
2620
|
}
|
2551
2621
|
}
|
@@ -2554,13 +2624,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2554
2624
|
if (!(0, typeUtils_1.derivesFromClassRecursive)(types_1.ClassType.cloneAsInstantiable(concreteSubtype), baseExceptionType,
|
2555
2625
|
/* ignoreUnknown */ false)) {
|
2556
2626
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
|
2557
|
-
type: printType(subtype
|
2627
|
+
type: printType(subtype),
|
2558
2628
|
}));
|
2559
2629
|
}
|
2560
2630
|
}
|
2561
2631
|
else {
|
2562
2632
|
diagAddendum.addMessage(localize_1.Localizer.Diagnostic.exceptionTypeIncorrect().format({
|
2563
|
-
type: printType(subtype
|
2633
|
+
type: printType(subtype),
|
2564
2634
|
}));
|
2565
2635
|
}
|
2566
2636
|
}
|
@@ -2642,7 +2712,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2642
2712
|
if (!classMember) {
|
2643
2713
|
return undefined;
|
2644
2714
|
}
|
2645
|
-
const
|
2715
|
+
const memberTypeResult = getTypeOfMemberInternal(classMember, objType);
|
2716
|
+
if (!memberTypeResult) {
|
2717
|
+
return undefined;
|
2718
|
+
}
|
2719
|
+
const memberType = memberTypeResult.type;
|
2646
2720
|
if ((0, types_1.isAnyOrUnknown)(memberType)) {
|
2647
2721
|
return memberType;
|
2648
2722
|
}
|
@@ -2684,6 +2758,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2684
2758
|
};
|
2685
2759
|
}
|
2686
2760
|
}
|
2761
|
+
// Does this name refer to a PEP 695-style type parameter?
|
2687
2762
|
const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
|
2688
2763
|
if (typeParamSymbol) {
|
2689
2764
|
symbol = typeParamSymbol;
|
@@ -2693,7 +2768,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2693
2768
|
else {
|
2694
2769
|
// Look for the scope that contains the value definition and
|
2695
2770
|
// see if it has a declared type.
|
2696
|
-
|
2771
|
+
let symbolWithScope = lookUpSymbolRecursive(node, name, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
|
2772
|
+
if (!symbolWithScope) {
|
2773
|
+
// If the node is part of a "from X import Y as Z" statement and the node
|
2774
|
+
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
2775
|
+
// since the non-aliased name is not in the symbol table.
|
2776
|
+
const alias = getAliasFromImport(node);
|
2777
|
+
if (alias) {
|
2778
|
+
symbolWithScope = lookUpSymbolRecursive(alias, alias.value, !allowForwardReferences, allowForwardReferences && (flags & 1024 /* ExpectingTypeAnnotation */) !== 0);
|
2779
|
+
}
|
2780
|
+
}
|
2697
2781
|
if (symbolWithScope) {
|
2698
2782
|
let useCodeFlowAnalysis = !allowForwardReferences;
|
2699
2783
|
// If the symbol is implicitly imported from the builtin
|
@@ -2723,9 +2807,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2723
2807
|
// If the symbol is declared outside of our execution scope, use its effective
|
2724
2808
|
// type. If it's declared inside our execution scope, it generally starts
|
2725
2809
|
// as unbound at the start of the code flow.
|
2726
|
-
|
2727
|
-
|
2728
|
-
|
2810
|
+
let typeAtStart = effectiveType;
|
2811
|
+
if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
|
2812
|
+
typeAtStart = types_1.UnboundType.create();
|
2813
|
+
// Is this a module-level scope? If so, see if it's an alias of a builtin.
|
2814
|
+
if (symbolWithScope.scope.type === 3 /* Module */) {
|
2815
|
+
(0, debug_1.assert)(symbolWithScope.scope.parent);
|
2816
|
+
const builtInSymbol = symbolWithScope.scope.parent.lookUpSymbol(name);
|
2817
|
+
if (builtInSymbol) {
|
2818
|
+
const builtInEffectiveType = getEffectiveTypeOfSymbolForUsage(builtInSymbol);
|
2819
|
+
typeAtStart = builtInEffectiveType.type;
|
2820
|
+
}
|
2821
|
+
}
|
2822
|
+
}
|
2729
2823
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol.id, typeAtStart,
|
2730
2824
|
/* startNode */ undefined, {
|
2731
2825
|
skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
|
@@ -2793,6 +2887,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2793
2887
|
}
|
2794
2888
|
if ((0, types_1.isTypeVar)(type) &&
|
2795
2889
|
!type.details.isParamSpec &&
|
2890
|
+
!type.isVariadicInUnion &&
|
2796
2891
|
(flags & 64 /* ExpectingType */) === 0 &&
|
2797
2892
|
type.details.name === name) {
|
2798
2893
|
// Handle the special case of a PEP 604 union. These can appear within
|
@@ -2956,7 +3051,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2956
3051
|
}
|
2957
3052
|
// If this type var is variadic, the name refers to the packed form. It
|
2958
3053
|
// must be unpacked in most contexts.
|
2959
|
-
if (
|
3054
|
+
if ((0, types_1.isUnpackedVariadicTypeVar)(type)) {
|
2960
3055
|
type = types_1.TypeVarType.cloneForPacked(type);
|
2961
3056
|
}
|
2962
3057
|
return type;
|
@@ -2983,11 +3078,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2983
3078
|
type.typeAliasInfo.typeParameters &&
|
2984
3079
|
type.typeAliasInfo.typeParameters.length > 0 &&
|
2985
3080
|
!type.typeAliasInfo.typeArguments) {
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
3081
|
+
let reportMissingTypeArguments = false;
|
3082
|
+
const defaultTypeArgs = [];
|
3083
|
+
type.typeAliasInfo.typeParameters.forEach((param) => {
|
3084
|
+
if (param.details.defaultType) {
|
3085
|
+
defaultTypeArgs.push(param.details.defaultType);
|
3086
|
+
}
|
3087
|
+
else {
|
3088
|
+
defaultTypeArgs.push(types_1.UnknownType.create());
|
3089
|
+
reportMissingTypeArguments = true;
|
3090
|
+
}
|
3091
|
+
});
|
3092
|
+
const typeVarContext = (0, typeUtils_1.buildTypeVarContext)(type.typeAliasInfo.typeParameters, defaultTypeArgs, type.typeAliasInfo.typeVarScopeId);
|
3093
|
+
if (reportMissingTypeArguments) {
|
3094
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportMissingTypeArgument, diagnosticRules_1.DiagnosticRule.reportMissingTypeArgument, localize_1.Localizer.Diagnostic.typeArgsMissingForAlias().format({
|
3095
|
+
name: type.typeAliasInfo.name,
|
3096
|
+
}), node);
|
3097
|
+
}
|
3098
|
+
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
3099
|
}
|
2992
3100
|
}
|
2993
3101
|
return type;
|
@@ -3131,9 +3239,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3131
3239
|
writeTypeCache(node.memberName, typeResult.type, flags, /* isIncomplete */ true);
|
3132
3240
|
// If the type is initially unbound, see if there's a parent class that
|
3133
3241
|
// potentially initialized the value.
|
3134
|
-
let
|
3135
|
-
let
|
3136
|
-
if ((0, types_1.isUnbound)(
|
3242
|
+
let typeAtStart = typeResult.type;
|
3243
|
+
let isTypeAtStartIncomplete = !!typeResult.isIncomplete;
|
3244
|
+
if ((0, types_1.isUnbound)(typeAtStart)) {
|
3137
3245
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
3138
3246
|
let classMemberInfo;
|
3139
3247
|
if ((0, types_1.isInstantiableClass)(baseType)) {
|
@@ -3143,14 +3251,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3143
3251
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, node.memberName.value, 1 /* SkipOriginalClass */);
|
3144
3252
|
}
|
3145
3253
|
if (classMemberInfo) {
|
3146
|
-
|
3147
|
-
|
3254
|
+
typeAtStart = getTypeOfMember(classMemberInfo);
|
3255
|
+
isTypeAtStartIncomplete = false;
|
3148
3256
|
}
|
3149
3257
|
}
|
3150
3258
|
// See if we can refine the type based on code flow analysis.
|
3151
|
-
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId,
|
3259
|
+
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, typeAtStart,
|
3152
3260
|
/* startNode */ undefined, {
|
3153
|
-
|
3261
|
+
isTypeAtStartIncomplete,
|
3154
3262
|
skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
|
3155
3263
|
});
|
3156
3264
|
if (codeFlowTypeResult.type) {
|
@@ -4051,7 +4159,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4051
4159
|
// See if we can refine the type based on code flow analysis.
|
4052
4160
|
const codeFlowTypeResult = getFlowTypeOfReference(node, symbol_1.indeterminateSymbolId, indexTypeResult.type,
|
4053
4161
|
/* startNode */ undefined, {
|
4054
|
-
|
4162
|
+
isTypeAtStartIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
4055
4163
|
skipConditionalNarrowing: (flags & 1024 /* ExpectingTypeAnnotation */) !== 0,
|
4056
4164
|
});
|
4057
4165
|
if (codeFlowTypeResult.type) {
|
@@ -4080,6 +4188,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4080
4188
|
return indexTypeResult;
|
4081
4189
|
}
|
4082
4190
|
function adjustTypeArgumentsForVariadicTypeVar(typeArgs, typeParameters, errorNode) {
|
4191
|
+
var _a;
|
4083
4192
|
const variadicIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
4084
4193
|
// Do we need to adjust the type arguments to map to a variadic type
|
4085
4194
|
// param at the end of the list?
|
@@ -4127,7 +4236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4127
4236
|
// Add an empty tuple that maps to the TypeVarTuple type parameter.
|
4128
4237
|
typeArgs.push({
|
4129
4238
|
node: errorNode,
|
4130
|
-
type: (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
4239
|
+
type: (_a = typeParameters[variadicIndex].details.defaultType) !== null && _a !== void 0 ? _a : (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [],
|
4131
4240
|
/* isTypeArgumentExplicit */ true,
|
4132
4241
|
/* isUnpackedTuple */ true)),
|
4133
4242
|
});
|
@@ -4180,7 +4289,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4180
4289
|
];
|
4181
4290
|
}
|
4182
4291
|
}
|
4183
|
-
if (typeArgs.length > typeParameters.length &&
|
4292
|
+
if (typeArgs.length > typeParameters.length &&
|
4293
|
+
!typeParameters.some((typeVar) => typeVar.details.isVariadic && !typeVar.isVariadicInUnion)) {
|
4184
4294
|
addError(localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
|
4185
4295
|
name: printType(baseType),
|
4186
4296
|
expected: typeParameters.length,
|
@@ -4196,6 +4306,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4196
4306
|
const typeVarContext = new typeVarContext_1.TypeVarContext(baseType.typeAliasInfo.typeVarScopeId);
|
4197
4307
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
4198
4308
|
typeParameters.forEach((param, index) => {
|
4309
|
+
var _a;
|
4199
4310
|
if (param.details.isParamSpec && index < typeArgs.length) {
|
4200
4311
|
const typeArgType = typeArgs[index].type;
|
4201
4312
|
if (typeArgs[index].typeList) {
|
@@ -4258,7 +4369,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4258
4369
|
if (index < typeArgs.length && typeArgs[index].typeList) {
|
4259
4370
|
addError(localize_1.Localizer.Diagnostic.typeArgListNotAllowed(), typeArgs[index].node);
|
4260
4371
|
}
|
4261
|
-
const typeArgType = index < typeArgs.length
|
4372
|
+
const typeArgType = index < typeArgs.length
|
4373
|
+
? (0, typeUtils_1.convertToInstance)(typeArgs[index].type)
|
4374
|
+
: (_a = param.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4262
4375
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 128 /* RetainLiteralsForTypeVar */);
|
4263
4376
|
}
|
4264
4377
|
});
|
@@ -4312,7 +4425,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4312
4425
|
// See if the class has a custom metaclass that supports __getitem__, etc.
|
4313
4426
|
if (concreteSubtype.details.effectiveMetaclass &&
|
4314
4427
|
(0, types_1.isInstantiableClass)(concreteSubtype.details.effectiveMetaclass) &&
|
4315
|
-
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, 'type')) {
|
4428
|
+
!types_1.ClassType.isBuiltIn(concreteSubtype.details.effectiveMetaclass, ['type', '_InitVarMeta'])) {
|
4316
4429
|
const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
|
4317
4430
|
/* usage */ undefined,
|
4318
4431
|
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
|
@@ -4370,7 +4483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4370
4483
|
}
|
4371
4484
|
if (concreteSubtype.typeArguments) {
|
4372
4485
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classAlreadySpecialized().format({
|
4373
|
-
type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype),
|
4486
|
+
type: printType((0, typeUtils_1.convertToInstance)(concreteSubtype), { expandTypeAlias: true }),
|
4374
4487
|
}), node.baseExpression);
|
4375
4488
|
return concreteSubtype;
|
4376
4489
|
}
|
@@ -4552,12 +4665,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4552
4665
|
}
|
4553
4666
|
});
|
4554
4667
|
unpackedListArgs.forEach((arg) => {
|
4668
|
+
var _a, _b;
|
4555
4669
|
const typeResult = getTypeOfExpression(arg.valueExpression);
|
4556
|
-
const exprType = typeResult.type;
|
4557
4670
|
if (typeResult.isIncomplete) {
|
4558
4671
|
isPositionalIndexTypeIncomplete = true;
|
4559
4672
|
}
|
4560
|
-
const iterableType = getTypeOfIterator(
|
4673
|
+
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
4674
|
tupleEntries.push(iterableType);
|
4562
4675
|
});
|
4563
4676
|
positionalIndexType = makeTupleObject(tupleEntries, unpackedListArgs.length > 0);
|
@@ -4640,7 +4753,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4640
4753
|
adjFlags &= ~(2 /* DoNotSpecialize */ |
|
4641
4754
|
32 /* ParamSpecDisallowed */ |
|
4642
4755
|
128 /* TypeVarTupleDisallowed */ |
|
4643
|
-
1048576 /* RequiredAllowed */
|
4756
|
+
1048576 /* RequiredAllowed */ |
|
4757
|
+
16384 /* EnforceTypeVarVarianceConsistency */);
|
4644
4758
|
if (!isAnnotatedClass) {
|
4645
4759
|
adjFlags |= 131072 /* ClassVarDisallowed */ | 16 /* FinalDisallowed */;
|
4646
4760
|
}
|
@@ -5036,7 +5150,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5036
5150
|
const typeResult = getTypeOfExpression(arg0Value, /* flags */ undefined, expectedType);
|
5037
5151
|
const type = typeResult.type;
|
5038
5152
|
const exprString = ParseTreeUtils.printExpression(arg0Value);
|
5039
|
-
const typeString = printType(type,
|
5153
|
+
const typeString = printType(type, { expandTypeAlias: true });
|
5040
5154
|
if (expectedText !== undefined) {
|
5041
5155
|
if (expectedText !== typeString) {
|
5042
5156
|
addError(localize_1.Localizer.Diagnostic.revealTypeExpectedTextMismatch().format({
|
@@ -5076,7 +5190,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5076
5190
|
const typeOfSymbol = getEffectiveTypeOfSymbol(symbol);
|
5077
5191
|
infoMessages.push(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({
|
5078
5192
|
name,
|
5079
|
-
type: printType(typeOfSymbol,
|
5193
|
+
type: printType(typeOfSymbol, { expandTypeAlias: true }),
|
5080
5194
|
}));
|
5081
5195
|
}
|
5082
5196
|
});
|
@@ -5811,7 +5925,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5811
5925
|
const exprNode = errorNode.nodeType === 9 /* Call */ ? errorNode.leftExpression : errorNode;
|
5812
5926
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotCallable().format({
|
5813
5927
|
expression: ParseTreeUtils.printExpression(exprNode),
|
5814
|
-
type: printType(callTypeResult.type,
|
5928
|
+
type: printType(callTypeResult.type, { expandTypeAlias: true }),
|
5815
5929
|
}), exprNode);
|
5816
5930
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
5817
5931
|
}
|
@@ -6129,18 +6243,64 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6129
6243
|
specializedInitSelfType,
|
6130
6244
|
};
|
6131
6245
|
}
|
6246
|
+
// Expands any unpacked tuples within an argument list.
|
6247
|
+
function expandArgList(argList) {
|
6248
|
+
var _a;
|
6249
|
+
const expandedArgList = [];
|
6250
|
+
for (const arg of argList) {
|
6251
|
+
if (arg.argumentCategory === 1 /* UnpackedList */) {
|
6252
|
+
const argType = getTypeOfArgument(arg).type;
|
6253
|
+
// If this is a tuple with specified element types, use those
|
6254
|
+
// specified types rather than using the more generic iterator
|
6255
|
+
// type which will be a union of all element types.
|
6256
|
+
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClassType);
|
6257
|
+
if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
|
6258
|
+
const tupleTypeArgs = (_a = combinedArgType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [];
|
6259
|
+
if (tupleTypeArgs.length !== 1) {
|
6260
|
+
for (const tupleTypeArg of tupleTypeArgs) {
|
6261
|
+
if (tupleTypeArg.isUnbounded) {
|
6262
|
+
expandedArgList.push({
|
6263
|
+
...arg,
|
6264
|
+
argumentCategory: 1 /* UnpackedList */,
|
6265
|
+
valueExpression: undefined,
|
6266
|
+
typeResult: {
|
6267
|
+
type: (0, typeUtils_1.specializeTupleClass)(combinedArgType, [tupleTypeArg]),
|
6268
|
+
},
|
6269
|
+
});
|
6270
|
+
}
|
6271
|
+
else {
|
6272
|
+
expandedArgList.push({
|
6273
|
+
...arg,
|
6274
|
+
argumentCategory: 0 /* Simple */,
|
6275
|
+
valueExpression: undefined,
|
6276
|
+
typeResult: {
|
6277
|
+
type: tupleTypeArg.type,
|
6278
|
+
},
|
6279
|
+
});
|
6280
|
+
}
|
6281
|
+
}
|
6282
|
+
continue;
|
6283
|
+
}
|
6284
|
+
}
|
6285
|
+
}
|
6286
|
+
expandedArgList.push(arg);
|
6287
|
+
}
|
6288
|
+
return expandedArgList;
|
6289
|
+
}
|
6132
6290
|
// Matches the arguments passed to a function to the corresponding parameters in that
|
6133
6291
|
// function. This matching is done based on positions and keywords. Type evaluation and
|
6134
6292
|
// validation is left to the caller.
|
6135
6293
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
6136
6294
|
function matchFunctionArgumentsToParameters(errorNode, argList, type, overloadIndex) {
|
6137
|
-
var _a;
|
6295
|
+
var _a, _b, _c, _d, _e;
|
6138
6296
|
const paramDetails = (0, typeUtils_1.getParameterListDetails)(type);
|
6139
6297
|
let argIndex = 0;
|
6140
6298
|
let matchedUnpackedListOfUnknownLength = false;
|
6141
6299
|
let reportedArgError = false;
|
6142
6300
|
let isTypeIncomplete = false;
|
6143
6301
|
let isVariadicTypeVarFullyMatched = false;
|
6302
|
+
// Expand any unpacked tuples in the arg list.
|
6303
|
+
argList = expandArgList(argList);
|
6144
6304
|
// Build a map of parameters by name.
|
6145
6305
|
const paramMap = new Map();
|
6146
6306
|
paramDetails.params.forEach((paramInfo) => {
|
@@ -6224,24 +6384,44 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6224
6384
|
activeParam = param;
|
6225
6385
|
}
|
6226
6386
|
}
|
6227
|
-
|
6387
|
+
const foundUnpackedListArg = argList.find((arg) => arg.argumentCategory === 1 /* UnpackedList */) !== undefined;
|
6228
6388
|
// Map the positional args to parameters.
|
6229
6389
|
let paramIndex = 0;
|
6230
|
-
let unpackedArgIndex = 0;
|
6231
6390
|
while (argIndex < positionalArgCount) {
|
6232
6391
|
if (argIndex < positionalOnlyLimitIndex && argList[argIndex].name) {
|
6233
6392
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argList[argIndex].name);
|
6234
6393
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.argPositional(), argList[argIndex].name);
|
6235
6394
|
reportedArgError = true;
|
6236
6395
|
}
|
6396
|
+
const remainingArgCount = positionalArgCount - argIndex;
|
6397
|
+
const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
|
6237
6398
|
if (paramIndex >= positionParamLimitIndex) {
|
6238
|
-
if (!
|
6239
|
-
|
6240
|
-
|
6241
|
-
|
6242
|
-
|
6243
|
-
|
6244
|
-
|
6399
|
+
if (!type.details.paramSpec) {
|
6400
|
+
let tooManyPositionals = false;
|
6401
|
+
if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
|
6402
|
+
// If this is an unpacked iterable, we will conservatively assume that it
|
6403
|
+
// might have zero iterations unless we can tell from its type that it
|
6404
|
+
// definitely has at least one iterable value.
|
6405
|
+
const argType = getTypeOfArgument(argList[argIndex]).type;
|
6406
|
+
if ((0, types_1.isClassInstance)(argType) &&
|
6407
|
+
(0, typeUtils_1.isTupleClass)(argType) &&
|
6408
|
+
!(0, typeUtils_1.isUnboundedTupleClass)(argType) &&
|
6409
|
+
argType.tupleTypeArguments !== undefined &&
|
6410
|
+
argType.tupleTypeArguments.length > 0) {
|
6411
|
+
tooManyPositionals = true;
|
6412
|
+
}
|
6413
|
+
}
|
6414
|
+
else {
|
6415
|
+
tooManyPositionals = true;
|
6416
|
+
}
|
6417
|
+
if (tooManyPositionals) {
|
6418
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
|
6419
|
+
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
6420
|
+
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
6421
|
+
expected: positionParamLimitIndex,
|
6422
|
+
}), (_b = argList[argIndex].valueExpression) !== null && _b !== void 0 ? _b : errorNode);
|
6423
|
+
reportedArgError = true;
|
6424
|
+
}
|
6245
6425
|
}
|
6246
6426
|
break;
|
6247
6427
|
}
|
@@ -6250,15 +6430,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6250
6430
|
}
|
6251
6431
|
(0, debug_1.assert)(paramDetails.params[paramIndex], 'paramIndex params entry is undefined');
|
6252
6432
|
const paramType = paramDetails.params[paramIndex].type;
|
6433
|
+
const paramName = paramDetails.params[paramIndex].param.name;
|
6434
|
+
const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* VarArgList */ &&
|
6435
|
+
(0, types_1.isVariadicTypeVar)(paramType);
|
6253
6436
|
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
6437
|
let isArgCompatibleWithVariadic = false;
|
6260
6438
|
const argTypeResult = getTypeOfArgument(argList[argIndex]);
|
6261
|
-
const argType = argTypeResult.type;
|
6262
6439
|
let listElementType;
|
6263
6440
|
let advanceToNextArg = false;
|
6264
6441
|
// Handle the case where *args is being passed to a function defined
|
@@ -6270,32 +6447,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6270
6447
|
? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
|
6271
6448
|
: localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
|
6272
6449
|
expected: positionParamLimitIndex,
|
6273
|
-
}), argList[argIndex].valueExpression
|
6450
|
+
}), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
|
6274
6451
|
reportedArgError = true;
|
6275
6452
|
}
|
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)) {
|
6453
|
+
const argType = argTypeResult.type;
|
6454
|
+
if (isParamVariadic && (0, types_1.isUnpackedVariadicTypeVar)(argType)) {
|
6299
6455
|
// Allow an unpacked variadic type variable to satisfy an
|
6300
6456
|
// unpacked variadic type variable.
|
6301
6457
|
listElementType = argType;
|
@@ -6307,7 +6463,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6307
6463
|
(0, typeUtils_1.isTupleClass)(argType) &&
|
6308
6464
|
argType.tupleTypeArguments &&
|
6309
6465
|
argType.tupleTypeArguments.length === 1 &&
|
6310
|
-
(0, types_1.
|
6466
|
+
(0, types_1.isUnpackedVariadicTypeVar)(argType.tupleTypeArguments[0].type)) {
|
6311
6467
|
// Handle the case where an unpacked variadic type var has
|
6312
6468
|
// been packaged into a tuple.
|
6313
6469
|
listElementType = argType.tupleTypeArguments[0].type;
|
@@ -6315,13 +6471,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6315
6471
|
advanceToNextArg = true;
|
6316
6472
|
isVariadicTypeVarFullyMatched = true;
|
6317
6473
|
}
|
6474
|
+
else if (isParamVariadic && (0, types_1.isClassInstance)(argType) && (0, typeUtils_1.isTupleClass)(argType)) {
|
6475
|
+
// Handle the case where an unpacked tuple argument is
|
6476
|
+
// matched to a TypeVarTuple parameter.
|
6477
|
+
isArgCompatibleWithVariadic = true;
|
6478
|
+
advanceToNextArg = true;
|
6479
|
+
// Determine whether we should treat the variadic type as fully matched.
|
6480
|
+
// This depends on how many args and unmatched parameters exist.
|
6481
|
+
if (remainingArgCount < remainingParamCount) {
|
6482
|
+
isVariadicTypeVarFullyMatched = true;
|
6483
|
+
}
|
6484
|
+
listElementType = types_1.ClassType.cloneForUnpacked(argType);
|
6485
|
+
}
|
6318
6486
|
else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
|
6319
6487
|
listElementType = undefined;
|
6320
6488
|
}
|
6321
6489
|
else {
|
6322
6490
|
listElementType =
|
6323
|
-
getTypeOfIterator(argType,
|
6324
|
-
|
6491
|
+
(_e = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
6492
|
+
/* isAsync */ false, argList[argIndex].valueExpression)) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : types_1.UnknownType.create();
|
6325
6493
|
if (paramDetails.params[paramIndex].param.category !== 1 /* VarArgList */) {
|
6326
6494
|
matchedUnpackedListOfUnknownLength = true;
|
6327
6495
|
}
|
@@ -6335,7 +6503,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6335
6503
|
if (funcArg && argTypeResult.isIncomplete) {
|
6336
6504
|
isTypeIncomplete = true;
|
6337
6505
|
}
|
6338
|
-
const paramName = paramDetails.params[paramIndex].param.name;
|
6339
6506
|
// It's not allowed to use unpacked arguments with a variadic *args
|
6340
6507
|
// parameter unless the argument is a variadic arg as well.
|
6341
6508
|
if (isParamVariadic && !isArgCompatibleWithVariadic) {
|
@@ -6355,6 +6522,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6355
6522
|
errorNode: argList[argIndex].valueExpression || errorNode,
|
6356
6523
|
paramName,
|
6357
6524
|
isParamNameSynthesized: paramDetails.params[paramIndex].param.isNameSynthesized,
|
6525
|
+
mapsToVarArgList: isParamVariadic && remainingArgCount > remainingParamCount,
|
6358
6526
|
});
|
6359
6527
|
}
|
6360
6528
|
}
|
@@ -6392,8 +6560,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6392
6560
|
paramCategory = (0, types_1.isVariadicTypeVar)(effectiveParamType)
|
6393
6561
|
? 1 /* VarArgList */
|
6394
6562
|
: 0 /* Simple */;
|
6395
|
-
const remainingArgCount = positionalArgCount - argIndex;
|
6396
|
-
const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
|
6397
6563
|
if (remainingArgCount <= remainingParamCount) {
|
6398
6564
|
if (remainingArgCount < remainingParamCount) {
|
6399
6565
|
// Have we run out of arguments and still have parameters left to fill?
|
@@ -6796,7 +6962,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6796
6962
|
!isVariadicTypeVarFullyMatched) {
|
6797
6963
|
const paramType = paramDetails.params[paramDetails.argsIndex].type;
|
6798
6964
|
const variadicArgs = validateArgTypeParams.filter((argParam) => argParam.mapsToVarArgList);
|
6799
|
-
if ((0, types_1.
|
6965
|
+
if ((0, types_1.isVariadicTypeVar)(paramType) && !paramType.isVariadicInUnion) {
|
6800
6966
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
6801
6967
|
const tupleTypeArgs = variadicArgs.map((argParam) => {
|
6802
6968
|
var _a;
|
@@ -6816,9 +6982,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6816
6982
|
isUnbounded: argParam.argument.argumentCategory === 1 /* UnpackedList */,
|
6817
6983
|
};
|
6818
6984
|
});
|
6819
|
-
|
6820
|
-
|
6821
|
-
|
6985
|
+
let specializedTuple;
|
6986
|
+
if (tupleTypeArgs.length === 1 &&
|
6987
|
+
!tupleTypeArgs[0].isUnbounded &&
|
6988
|
+
((0, types_1.isUnpackedClass)(tupleTypeArgs[0].type) || (0, types_1.isVariadicTypeVar)(tupleTypeArgs[0].type))) {
|
6989
|
+
// If there is a single unpacked tuple or unpacked variadic type variable
|
6990
|
+
// (including an unpacked TypeVarTuple union) within this tuple,
|
6991
|
+
// simplify the type.
|
6992
|
+
specializedTuple = tupleTypeArgs[0].type;
|
6993
|
+
}
|
6994
|
+
else {
|
6995
|
+
specializedTuple = types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleTypeArgs,
|
6996
|
+
/* isTypeArgumentExplicit */ true,
|
6997
|
+
/* isUnpackedTuple */ true));
|
6998
|
+
}
|
6822
6999
|
const combinedArg = {
|
6823
7000
|
paramCategory: 1 /* VarArgList */,
|
6824
7001
|
paramType,
|
@@ -7500,7 +7677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7500
7677
|
if (!suppressPartialUnknown) {
|
7501
7678
|
const diagAddendum = getDiagAddendum();
|
7502
7679
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentType().format({
|
7503
|
-
type: printType(simplifiedType,
|
7680
|
+
type: printType(simplifiedType, { expandTypeAlias: true }),
|
7504
7681
|
}));
|
7505
7682
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportUnknownArgumentType, diagnosticRules_1.DiagnosticRule.reportUnknownArgumentType, localize_1.Localizer.Diagnostic.argTypePartiallyUnknown() + diagAddendum.getString(), argParam.errorNode);
|
7506
7683
|
}
|
@@ -7510,9 +7687,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7510
7687
|
return { isCompatible, argType, isTypeIncomplete, condition };
|
7511
7688
|
}
|
7512
7689
|
function createTypeVarType(errorNode, argList) {
|
7513
|
-
var _a, _b, _c, _d, _e;
|
7690
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
7514
7691
|
let typeVarName = '';
|
7515
7692
|
let firstConstraintArg;
|
7693
|
+
let defaultValueNode;
|
7516
7694
|
if (argList.length === 0) {
|
7517
7695
|
addError(localize_1.Localizer.Diagnostic.typeVarFirstArg(), errorNode);
|
7518
7696
|
return undefined;
|
@@ -7526,10 +7704,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7526
7704
|
}
|
7527
7705
|
const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false);
|
7528
7706
|
// Parse the remaining parameters.
|
7707
|
+
const paramNameMap = new Map();
|
7529
7708
|
for (let i = 1; i < argList.length; i++) {
|
7530
7709
|
const paramNameNode = argList[i].name;
|
7531
7710
|
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
7532
|
-
const paramNameMap = new Map();
|
7533
7711
|
if (paramName) {
|
7534
7712
|
if (paramNameMap.get(paramName)) {
|
7535
7713
|
addError(localize_1.Localizer.Diagnostic.duplicateParam().format({ name: paramName }), argList[i].valueExpression || errorNode);
|
@@ -7541,14 +7719,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7541
7719
|
else {
|
7542
7720
|
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
7721
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7544
|
-
addError(localize_1.Localizer.Diagnostic.
|
7722
|
+
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), argList[i].valueExpression || errorNode);
|
7545
7723
|
}
|
7546
7724
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(argType);
|
7547
7725
|
}
|
7548
7726
|
}
|
7549
7727
|
else if (paramName === 'covariant') {
|
7550
7728
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7551
|
-
if (typeVar.details.declaredVariance === 4 /* Contravariant */
|
7729
|
+
if (typeVar.details.declaredVariance === 4 /* Contravariant */ ||
|
7730
|
+
typeVar.details.declaredVariance === 0 /* Auto */) {
|
7552
7731
|
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7553
7732
|
}
|
7554
7733
|
else {
|
@@ -7558,7 +7737,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7558
7737
|
}
|
7559
7738
|
else if (paramName === 'contravariant') {
|
7560
7739
|
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7561
|
-
if (typeVar.details.declaredVariance === 3 /* Covariant */
|
7740
|
+
if (typeVar.details.declaredVariance === 3 /* Covariant */ ||
|
7741
|
+
typeVar.details.declaredVariance === 0 /* Auto */) {
|
7562
7742
|
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7563
7743
|
}
|
7564
7744
|
else {
|
@@ -7566,8 +7746,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7566
7746
|
}
|
7567
7747
|
}
|
7568
7748
|
}
|
7749
|
+
else if (paramName === 'infer_variance') {
|
7750
|
+
if (argList[i].valueExpression && getBooleanValue(argList[i].valueExpression)) {
|
7751
|
+
if (typeVar.details.declaredVariance === 3 /* Covariant */ ||
|
7752
|
+
typeVar.details.declaredVariance === 4 /* Contravariant */) {
|
7753
|
+
addError(localize_1.Localizer.Diagnostic.typeVarVariance(), argList[i].valueExpression);
|
7754
|
+
}
|
7755
|
+
else {
|
7756
|
+
typeVar.details.declaredVariance = 0 /* Auto */;
|
7757
|
+
}
|
7758
|
+
}
|
7759
|
+
}
|
7760
|
+
else if (paramName === 'default') {
|
7761
|
+
defaultValueNode = argList[i].valueExpression;
|
7762
|
+
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;
|
7763
|
+
typeVar.details.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
7764
|
+
}
|
7569
7765
|
else {
|
7570
|
-
addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((
|
7766
|
+
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
7767
|
}
|
7572
7768
|
paramNameMap.set(paramName, paramName);
|
7573
7769
|
}
|
@@ -7576,9 +7772,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7576
7772
|
addError(localize_1.Localizer.Diagnostic.typeVarBoundAndConstrained(), argList[i].valueExpression || errorNode);
|
7577
7773
|
}
|
7578
7774
|
else {
|
7579
|
-
const argType = (
|
7775
|
+
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
7776
|
if ((0, typeUtils_1.requiresSpecialization)(argType, /* ignorePseudoGeneric */ true)) {
|
7581
|
-
addError(localize_1.Localizer.Diagnostic.
|
7777
|
+
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), argList[i].valueExpression || errorNode);
|
7582
7778
|
}
|
7583
7779
|
types_1.TypeVarType.addConstraint(typeVar, (0, typeUtils_1.convertToInstance)(argType));
|
7584
7780
|
if (firstConstraintArg === undefined) {
|
@@ -7590,6 +7786,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7590
7786
|
if (typeVar.details.constraints.length === 1 && firstConstraintArg) {
|
7591
7787
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarSingleConstraint(), firstConstraintArg.valueExpression || errorNode);
|
7592
7788
|
}
|
7789
|
+
// If a default is provided, make sure it is compatible with the bound
|
7790
|
+
// or constraint.
|
7791
|
+
if (typeVar.details.defaultType && defaultValueNode) {
|
7792
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext(types_1.WildcardTypeVarScopeId);
|
7793
|
+
const concreteDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext,
|
7794
|
+
/* unknownIfNotFound */ true);
|
7795
|
+
if (typeVar.details.boundType) {
|
7796
|
+
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
7797
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarDefaultBoundMismatch(), defaultValueNode);
|
7798
|
+
}
|
7799
|
+
}
|
7800
|
+
else if (typeVar.details.constraints.length > 0) {
|
7801
|
+
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
7802
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarDefaultConstraintMismatch(), defaultValueNode);
|
7803
|
+
}
|
7804
|
+
}
|
7805
|
+
}
|
7593
7806
|
return typeVar;
|
7594
7807
|
}
|
7595
7808
|
function createTypeVarTupleType(errorNode, argList) {
|
@@ -7610,12 +7823,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7610
7823
|
typeVar.details.isVariadic = true;
|
7611
7824
|
// Parse the remaining parameters.
|
7612
7825
|
for (let i = 1; i < argList.length; i++) {
|
7613
|
-
|
7826
|
+
const paramNameNode = argList[i].name;
|
7827
|
+
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
7828
|
+
if (paramName) {
|
7829
|
+
if (paramName === 'default') {
|
7830
|
+
const expr = argList[i].valueExpression;
|
7831
|
+
if (expr) {
|
7832
|
+
typeVar.details.defaultType = getTypeVarTupleDefaultType(expr);
|
7833
|
+
}
|
7834
|
+
}
|
7835
|
+
else {
|
7836
|
+
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);
|
7837
|
+
}
|
7838
|
+
}
|
7614
7839
|
}
|
7615
7840
|
return typeVar;
|
7616
7841
|
}
|
7842
|
+
function getTypeVarTupleDefaultType(node) {
|
7843
|
+
const argType = getTypeOfExpressionExpectingType(node, { allowUnpackedTuple: true }).type;
|
7844
|
+
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
7845
|
+
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
7846
|
+
if (!isUnpackedTuple && !isUnpackedTypeVarTuple) {
|
7847
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarTupleDefaultNotUnpacked(), node);
|
7848
|
+
return undefined;
|
7849
|
+
}
|
7850
|
+
return (0, typeUtils_1.convertToInstance)(argType);
|
7851
|
+
}
|
7617
7852
|
function createParamSpecType(errorNode, argList) {
|
7618
|
-
var _a, _b;
|
7619
7853
|
if (argList.length === 0) {
|
7620
7854
|
addError(localize_1.Localizer.Diagnostic.paramSpecFirstArg(), errorNode);
|
7621
7855
|
return undefined;
|
@@ -7631,8 +7865,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7631
7865
|
const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true);
|
7632
7866
|
// Parse the remaining parameters.
|
7633
7867
|
for (let i = 1; i < argList.length; i++) {
|
7634
|
-
|
7635
|
-
|
7868
|
+
const paramNameNode = argList[i].name;
|
7869
|
+
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
7870
|
+
if (paramName) {
|
7871
|
+
if (paramName === 'default') {
|
7872
|
+
const expr = argList[i].valueExpression;
|
7873
|
+
if (expr) {
|
7874
|
+
paramSpec.details.defaultType = getParamSpecDefaultType(expr);
|
7875
|
+
}
|
7876
|
+
}
|
7877
|
+
else {
|
7878
|
+
addError(localize_1.Localizer.Diagnostic.paramSpecUnknownParam().format({ name: paramName }), paramNameNode || argList[i].valueExpression || errorNode);
|
7879
|
+
}
|
7636
7880
|
}
|
7637
7881
|
else {
|
7638
7882
|
addError(localize_1.Localizer.Diagnostic.paramSpecUnknownArg(), argList[i].valueExpression || errorNode);
|
@@ -7641,6 +7885,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7641
7885
|
}
|
7642
7886
|
return paramSpec;
|
7643
7887
|
}
|
7888
|
+
function getParamSpecDefaultType(node) {
|
7889
|
+
const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* SkipArgsKwargsCompatibilityCheck */ | 65536 /* ParamSpecValue */);
|
7890
|
+
types_1.TypeBase.setSpecialForm(functionType);
|
7891
|
+
if (node.nodeType === 18 /* Ellipsis */) {
|
7892
|
+
types_1.FunctionType.addDefaultParameters(functionType);
|
7893
|
+
return functionType;
|
7894
|
+
}
|
7895
|
+
if (node.nodeType === 52 /* Tuple */) {
|
7896
|
+
node.expressions.forEach((paramExpr, index) => {
|
7897
|
+
const typeResult = getTypeOfExpressionExpectingType(paramExpr);
|
7898
|
+
types_1.FunctionType.addParameter(functionType, {
|
7899
|
+
category: 0 /* Simple */,
|
7900
|
+
name: `__p${index}`,
|
7901
|
+
isNameSynthesized: true,
|
7902
|
+
hasDeclaredType: true,
|
7903
|
+
type: (0, typeUtils_1.convertToInstance)(typeResult.type),
|
7904
|
+
});
|
7905
|
+
});
|
7906
|
+
// Update the type cache so we don't attempt to re-evaluate this node.
|
7907
|
+
// The type doesn't matter, so use Any.
|
7908
|
+
writeTypeCache(node, types_1.AnyType.create(), /* flags */ undefined, /* isIncomplete */ false);
|
7909
|
+
return functionType;
|
7910
|
+
}
|
7911
|
+
else {
|
7912
|
+
const typeResult = getTypeOfExpressionExpectingType(node, { allowParamSpec: true });
|
7913
|
+
if (typeResult.typeErrors) {
|
7914
|
+
return undefined;
|
7915
|
+
}
|
7916
|
+
if ((0, types_1.isParamSpec)(typeResult.type)) {
|
7917
|
+
functionType.details.paramSpec = typeResult.type;
|
7918
|
+
return functionType;
|
7919
|
+
}
|
7920
|
+
}
|
7921
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
|
7922
|
+
return undefined;
|
7923
|
+
}
|
7644
7924
|
function getBooleanValue(node) {
|
7645
7925
|
if (node.nodeType === 11 /* Constant */) {
|
7646
7926
|
if (node.constType === 15 /* False */) {
|
@@ -8166,6 +8446,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8166
8446
|
type = mapSubtypesExpandTypeVars(rightType,
|
8167
8447
|
/* conditionFilter */ undefined, (rightSubtypeExpanded, rightSubtypeUnexpanded) => {
|
8168
8448
|
return mapSubtypesExpandTypeVars(concreteLeftType, (0, typeUtils_1.getTypeCondition)(rightSubtypeExpanded), (leftSubtype) => {
|
8449
|
+
var _a;
|
8169
8450
|
if ((0, types_1.isAnyOrUnknown)(leftSubtype) || (0, types_1.isAnyOrUnknown)(rightSubtypeUnexpanded)) {
|
8170
8451
|
return (0, typeUtils_1.preserveUnknown)(leftSubtype, rightSubtypeExpanded);
|
8171
8452
|
}
|
@@ -8174,9 +8455,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8174
8455
|
if (!returnType) {
|
8175
8456
|
// If __contains__ was not supported, fall back
|
8176
8457
|
// on an iterable.
|
8177
|
-
const iteratorType = getTypeOfIterator(rightSubtypeExpanded,
|
8458
|
+
const iteratorType = (_a = getTypeOfIterator({ type: rightSubtypeExpanded, isIncomplete: rightTypeResult.isIncomplete },
|
8178
8459
|
/* isAsync */ false,
|
8179
|
-
/* errorNode */ undefined);
|
8460
|
+
/* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
|
8180
8461
|
if (iteratorType && assignType(iteratorType, leftSubtype)) {
|
8181
8462
|
returnType = getBuiltInObject(errorNode, 'bool');
|
8182
8463
|
}
|
@@ -8609,6 +8890,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8609
8890
|
isIncomplete = true;
|
8610
8891
|
}
|
8611
8892
|
const keyType = keyTypeResult.type;
|
8893
|
+
if (!keyTypeResult.isIncomplete && !keyTypeResult.typeErrors) {
|
8894
|
+
verifySetEntryOrDictKeyIsHashable(entryNode.keyExpression, keyType, /* isDictKey */ true);
|
8895
|
+
}
|
8612
8896
|
let valueTypeResult;
|
8613
8897
|
if (expectedTypedDictEntries &&
|
8614
8898
|
(0, types_1.isClassInstance)(keyType) &&
|
@@ -8754,6 +9038,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8754
9038
|
expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expectedType);
|
8755
9039
|
let isIncomplete = false;
|
8756
9040
|
let typeErrors = false;
|
9041
|
+
const verifyHashable = node.nodeType === 45 /* Set */;
|
8757
9042
|
if (!(0, types_1.isClassInstance)(expectedType)) {
|
8758
9043
|
return undefined;
|
8759
9044
|
}
|
@@ -8790,6 +9075,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8790
9075
|
if (entryTypeResult.expectedTypeDiagAddendum) {
|
8791
9076
|
expectedTypeDiagAddendum.addAddendum(entryTypeResult.expectedTypeDiagAddendum);
|
8792
9077
|
}
|
9078
|
+
if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
|
9079
|
+
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9080
|
+
}
|
8793
9081
|
});
|
8794
9082
|
const isExpectedTypeListOrSet = (0, types_1.isClassInstance)(expectedType) && types_1.ClassType.isBuiltIn(expectedType, builtInClassName);
|
8795
9083
|
const specializedEntryType = inferTypeArgFromExpectedType(expectedEntryType, entryTypes,
|
@@ -8803,6 +9091,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8803
9091
|
// Attempts to infer the type of a list or set statement with no "expected type".
|
8804
9092
|
function getTypeOfListOrSetInferred(node, hasExpectedType) {
|
8805
9093
|
const builtInClassName = node.nodeType === 31 /* List */ ? 'list' : 'set';
|
9094
|
+
const verifyHashable = node.nodeType === 45 /* Set */;
|
8806
9095
|
let isEmptyContainer = false;
|
8807
9096
|
let isIncomplete = false;
|
8808
9097
|
let typeErrors = false;
|
@@ -8825,6 +9114,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8825
9114
|
if (index < maxEntriesToUseForInference) {
|
8826
9115
|
entryTypes.push(entryTypeResult.type);
|
8827
9116
|
}
|
9117
|
+
if (verifyHashable && !entryTypeResult.isIncomplete && !entryTypeResult.typeErrors) {
|
9118
|
+
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9119
|
+
}
|
8828
9120
|
});
|
8829
9121
|
entryTypes = entryTypes.map((t) => stripLiteralValue(t));
|
8830
9122
|
let inferredEntryType = hasExpectedType ? types_1.AnyType.create() : types_1.UnknownType.create();
|
@@ -8856,6 +9148,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8856
9148
|
: types_1.UnknownType.create();
|
8857
9149
|
return { type, isIncomplete, typeErrors };
|
8858
9150
|
}
|
9151
|
+
function verifySetEntryOrDictKeyIsHashable(entry, type, isDictKey) {
|
9152
|
+
// Verify that the type is hashable.
|
9153
|
+
if (!isTypeHashable(type)) {
|
9154
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(entry);
|
9155
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
9156
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.unhashableType().format({ type: printType(type) }));
|
9157
|
+
const message = isDictKey
|
9158
|
+
? localize_1.Localizer.Diagnostic.unhashableDictKey()
|
9159
|
+
: localize_1.Localizer.Diagnostic.unhashableSetEntry();
|
9160
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
|
9161
|
+
}
|
9162
|
+
}
|
8859
9163
|
function inferTypeArgFromExpectedType(expectedType, entryTypes, isNarrowable) {
|
8860
9164
|
let targetTypeVar;
|
8861
9165
|
let useSynthesizedTypeVar = false;
|
@@ -8956,8 +9260,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8956
9260
|
return { type: sentType || types_1.UnknownType.create(), isIncomplete };
|
8957
9261
|
}
|
8958
9262
|
function getTypeOfYieldFrom(node) {
|
8959
|
-
var _a;
|
8960
|
-
const
|
9263
|
+
var _a, _b;
|
9264
|
+
const yieldFromTypeResult = getTypeOfExpression(node.expression);
|
9265
|
+
const yieldFromType = yieldFromTypeResult.type;
|
8961
9266
|
let generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(yieldFromType);
|
8962
9267
|
let returnedType;
|
8963
9268
|
// Is the expression a Generator type?
|
@@ -8969,7 +9274,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8969
9274
|
returnedType = types_1.UnknownType.create();
|
8970
9275
|
}
|
8971
9276
|
else {
|
8972
|
-
const iterableType = (_a = getTypeOfIterable(
|
9277
|
+
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
9278
|
// Does the iterable return a Generator?
|
8974
9279
|
generatorTypeArgs = (0, typeUtils_1.getGeneratorTypeArgs)(iterableType);
|
8975
9280
|
if (generatorTypeArgs) {
|
@@ -9006,9 +9311,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9006
9311
|
// Remove any expected subtypes that don't satisfy the minimum
|
9007
9312
|
// parameter count requirement.
|
9008
9313
|
expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
|
9009
|
-
const
|
9010
|
-
const
|
9011
|
-
const hasVarArgs = params.some((param) => param.category !== 0 /* Simple */);
|
9314
|
+
const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
|
9315
|
+
const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
|
9012
9316
|
return (hasVarArgs ||
|
9013
9317
|
(functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
|
9014
9318
|
});
|
@@ -9099,6 +9403,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9099
9403
|
return { type: functionType, isIncomplete };
|
9100
9404
|
}
|
9101
9405
|
function getTypeOfListComprehension(node, expectedType) {
|
9406
|
+
var _a;
|
9102
9407
|
let isIncomplete = false;
|
9103
9408
|
let typeErrors = false;
|
9104
9409
|
let isAsync = node.forIfNodes.some((comp) => {
|
@@ -9112,7 +9417,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9112
9417
|
}
|
9113
9418
|
let expectedElementType;
|
9114
9419
|
if (expectedType) {
|
9115
|
-
expectedElementType = getTypeOfIterator(expectedType, isAsync, /* errorNode */ undefined);
|
9420
|
+
expectedElementType = (_a = getTypeOfIterator({ type: expectedType }, isAsync, /* errorNode */ undefined)) === null || _a === void 0 ? void 0 : _a.type;
|
9116
9421
|
}
|
9117
9422
|
const elementTypeResult = getElementTypeFromListComprehension(node, expectedElementType);
|
9118
9423
|
if (elementTypeResult.isIncomplete) {
|
@@ -9160,7 +9465,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9160
9465
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
9161
9466
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.typeOfSymbol().format({
|
9162
9467
|
name: nameValue,
|
9163
|
-
type: printType(simplifiedType,
|
9468
|
+
type: printType(simplifiedType, { expandTypeAlias: true }),
|
9164
9469
|
}));
|
9165
9470
|
addDiagnostic(diagLevel, rule, localize_1.Localizer.Diagnostic.typePartiallyUnknown().format({ name: nameValue }) + diagAddendum.getString(), errorNode);
|
9166
9471
|
}
|
@@ -9175,9 +9480,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9175
9480
|
isIncomplete = true;
|
9176
9481
|
}
|
9177
9482
|
const iterableType = stripLiteralValue(iterableTypeResult.type);
|
9178
|
-
const
|
9483
|
+
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
9484
|
const targetExpr = node.targetExpression;
|
9180
|
-
assignTypeToExpression(targetExpr,
|
9485
|
+
assignTypeToExpression(targetExpr, itemTypeResult.type, !!itemTypeResult.isIncomplete, node.iterableExpression);
|
9181
9486
|
}
|
9182
9487
|
else {
|
9183
9488
|
(0, debug_1.assert)(node.nodeType === 34 /* ListComprehensionIf */);
|
@@ -9907,7 +10212,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9907
10212
|
else {
|
9908
10213
|
// If this is an unpacked TypeVar, note that it is in a union so we can differentiate
|
9909
10214
|
// between Unpack[Vs] and Union[Unpack[Vs]].
|
9910
|
-
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.
|
10215
|
+
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
|
9911
10216
|
typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
|
9912
10217
|
}
|
9913
10218
|
types.push(typeArgType);
|
@@ -10201,7 +10506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10201
10506
|
/* honorCodeFlow */ false);
|
10202
10507
|
if (symbolWithScope) {
|
10203
10508
|
const decls = symbolWithScope.symbol.getDeclarations();
|
10204
|
-
if (decls.length === 1 && (
|
10509
|
+
if (decls.length === 1 && isPossibleTypeAliasOrTypedDict(decls[0])) {
|
10205
10510
|
typeAliasNameNode = node.leftExpression;
|
10206
10511
|
isSpeculativeTypeAlias = true;
|
10207
10512
|
}
|
@@ -10296,6 +10601,33 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10296
10601
|
/* allowAssignmentToFinalVar */ true, expectedTypeDiagAddendum);
|
10297
10602
|
writeTypeCache(node, rightHandType, 0 /* None */, isIncomplete);
|
10298
10603
|
}
|
10604
|
+
function isPossibleTypeAliasOrTypedDict(decl) {
|
10605
|
+
var _a;
|
10606
|
+
if ((0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)) {
|
10607
|
+
return true;
|
10608
|
+
}
|
10609
|
+
if (decl.type === 1 /* Variable */ &&
|
10610
|
+
decl.node.parent &&
|
10611
|
+
decl.node.parent.nodeType === 3 /* Assignment */ &&
|
10612
|
+
((_a = decl.node.parent.rightExpression) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
10613
|
+
const callLeftNode = decl.node.parent.rightExpression.leftExpression;
|
10614
|
+
// Use a simple heuristic to determine whether this is potentially
|
10615
|
+
// a call to the TypedDict call. This avoids the expensive (and potentially
|
10616
|
+
// recursive) call to getTypeOfExpression in cases where it's not needed.
|
10617
|
+
if ((callLeftNode.nodeType === 38 /* Name */ && callLeftNode.value) === 'TypedDict' ||
|
10618
|
+
(callLeftNode.nodeType === 35 /* MemberAccess */ &&
|
10619
|
+
callLeftNode.memberName.value === 'TypedDict' &&
|
10620
|
+
callLeftNode.leftExpression.nodeType === 38 /* Name */)) {
|
10621
|
+
// See if this is a call to TypedDict. We want to support
|
10622
|
+
// recursive type references in a TypedDict call.
|
10623
|
+
const callType = getTypeOfExpression(callLeftNode, 2 /* DoNotSpecialize */).type;
|
10624
|
+
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
10625
|
+
return true;
|
10626
|
+
}
|
10627
|
+
}
|
10628
|
+
}
|
10629
|
+
return false;
|
10630
|
+
}
|
10299
10631
|
// Evaluates the type of a type alias (i.e. "type") statement. This code
|
10300
10632
|
// path does not handle traditional type aliases, which are treated as
|
10301
10633
|
// variables since they use normal variable assignment syntax.
|
@@ -10765,7 +11097,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10765
11097
|
}
|
10766
11098
|
if (dataClassBehaviors) {
|
10767
11099
|
(0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
|
10768
|
-
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, classType, initSubclassArgs);
|
11100
|
+
(0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs);
|
10769
11101
|
}
|
10770
11102
|
// Run any class hooks that depend on this class.
|
10771
11103
|
runClassTypeHooks(classType);
|
@@ -11002,7 +11334,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11002
11334
|
if ((0, types_1.isOverloadedFunction)(decoratorType)) {
|
11003
11335
|
const dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
|
11004
11336
|
if (dataclassBehaviors) {
|
11005
|
-
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, originalClassType, dataclassBehaviors,
|
11337
|
+
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, decoratorNode, originalClassType, dataclassBehaviors,
|
11006
11338
|
/* callNode */ undefined);
|
11007
11339
|
return inputClassType;
|
11008
11340
|
}
|
@@ -11035,7 +11367,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11035
11367
|
dataclassBehaviors = (0, dataClasses_1.getDataclassDecoratorBehaviors)(decoratorType);
|
11036
11368
|
}
|
11037
11369
|
if (dataclassBehaviors) {
|
11038
|
-
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, originalClassType, dataclassBehaviors, callNode);
|
11370
|
+
(0, dataClasses_1.applyDataClassDecorator)(evaluatorInterface, decoratorNode, originalClassType, dataclassBehaviors, callNode);
|
11039
11371
|
return inputClassType;
|
11040
11372
|
}
|
11041
11373
|
}
|
@@ -12016,18 +12348,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12016
12348
|
let useAwaitableGenerator = false;
|
12017
12349
|
if (functionDecl.yieldStatements) {
|
12018
12350
|
functionDecl.yieldStatements.forEach((yieldNode) => {
|
12351
|
+
var _a;
|
12019
12352
|
if (isNodeReachable(yieldNode)) {
|
12020
12353
|
if (yieldNode.nodeType === 61 /* YieldFrom */) {
|
12021
|
-
const
|
12022
|
-
if ((0, types_1.isClassInstance)(
|
12023
|
-
types_1.ClassType.isBuiltIn(
|
12354
|
+
const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
|
12355
|
+
if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
|
12356
|
+
types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
|
12024
12357
|
// Handle old-style (pre-await) Coroutines.
|
12025
12358
|
inferredYieldTypes.push();
|
12026
12359
|
useAwaitableGenerator = true;
|
12027
12360
|
}
|
12028
12361
|
else {
|
12029
|
-
const yieldType = getTypeOfIterator(
|
12030
|
-
/* isAsync */ false, yieldNode);
|
12362
|
+
const yieldType = (_a = getTypeOfIterator(iteratorTypeResult,
|
12363
|
+
/* isAsync */ false, yieldNode)) === null || _a === void 0 ? void 0 : _a.type;
|
12031
12364
|
inferredYieldTypes.push(yieldType !== null && yieldType !== void 0 ? yieldType : types_1.UnknownType.create());
|
12032
12365
|
}
|
12033
12366
|
}
|
@@ -12100,12 +12433,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12100
12433
|
return true;
|
12101
12434
|
}
|
12102
12435
|
function evaluateTypesForForStatement(node) {
|
12103
|
-
var _a;
|
12436
|
+
var _a, _b;
|
12104
12437
|
if (readTypeCache(node, 0 /* None */)) {
|
12105
12438
|
return;
|
12106
12439
|
}
|
12107
12440
|
const iteratorTypeResult = getTypeOfExpression(node.iterableExpression);
|
12108
|
-
const iteratedType = (_a = getTypeOfIterator(iteratorTypeResult
|
12441
|
+
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
12442
|
assignTypeToExpression(node.targetExpression, iteratedType, !!iteratorTypeResult.isIncomplete, node.targetExpression);
|
12110
12443
|
writeTypeCache(node, iteratedType, 0 /* None */, !!iteratorTypeResult.isIncomplete);
|
12111
12444
|
}
|
@@ -12115,9 +12448,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12115
12448
|
if (readTypeCache(node, 0 /* None */)) {
|
12116
12449
|
return;
|
12117
12450
|
}
|
12118
|
-
const
|
12451
|
+
const exceptionTypeResult = getTypeOfExpression(node.typeExpression);
|
12452
|
+
const exceptionTypes = exceptionTypeResult.type;
|
12119
12453
|
function getExceptionType(exceptionType, errorNode) {
|
12120
|
-
var _a;
|
12454
|
+
var _a, _b;
|
12121
12455
|
exceptionType = makeTopLevelTypeVarsConcrete(exceptionType);
|
12122
12456
|
if ((0, types_1.isAnyOrUnknown)(exceptionType)) {
|
12123
12457
|
return exceptionType;
|
@@ -12126,7 +12460,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12126
12460
|
return types_1.ClassType.cloneAsInstance(exceptionType);
|
12127
12461
|
}
|
12128
12462
|
if ((0, types_1.isClassInstance)(exceptionType)) {
|
12129
|
-
const iterableType = (_a = getTypeOfIterator(exceptionType,
|
12463
|
+
const iterableType = (_b = (_a = getTypeOfIterator({ type: exceptionType, isIncomplete: exceptionTypeResult.isIncomplete },
|
12464
|
+
/* isAsync */ false, errorNode)) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
12130
12465
|
return (0, typeUtils_1.mapSubtypes)(iterableType, (subtype) => {
|
12131
12466
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
12132
12467
|
return subtype;
|
@@ -12172,32 +12507,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12172
12507
|
// Verify that the target has an __enter__ or __aenter__ method defined.
|
12173
12508
|
const enterMethodName = isAsync ? '__aenter__' : '__enter__';
|
12174
12509
|
const scopedType = (0, typeUtils_1.mapSubtypes)(exprType, (subtype) => {
|
12175
|
-
var _a;
|
12176
12510
|
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
12177
12511
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
12178
12512
|
return subtype;
|
12179
12513
|
}
|
12180
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
12181
12514
|
const additionalHelp = new diagnostic_1.DiagnosticAddendum();
|
12182
|
-
if ((0, types_1.
|
12183
|
-
|
12515
|
+
if ((0, types_1.isClass)(subtype)) {
|
12516
|
+
let enterType = getTypeOfMagicMethodReturn(subtype, [], enterMethodName, node.expression,
|
12517
|
+
/* expectedType */ undefined);
|
12184
12518
|
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
12519
|
// For "async while", an implicit "await" is performed.
|
12193
12520
|
if (isAsync) {
|
12194
|
-
|
12521
|
+
enterType = getTypeOfAwaitable(enterType, node.expression);
|
12195
12522
|
}
|
12196
|
-
return
|
12523
|
+
return enterType;
|
12197
12524
|
}
|
12198
12525
|
if (!isAsync) {
|
12199
|
-
|
12200
|
-
|
12526
|
+
if (getTypeOfMagicMethodReturn(subtype, [], '__aenter__', node.expression,
|
12527
|
+
/* expectedType */ undefined)) {
|
12201
12528
|
additionalHelp.addMessage(localize_1.Localizer.DiagnosticAddendum.asyncHelp());
|
12202
12529
|
}
|
12203
12530
|
}
|
@@ -12214,9 +12541,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12214
12541
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
12215
12542
|
return;
|
12216
12543
|
}
|
12217
|
-
|
12218
|
-
|
12219
|
-
const exitType =
|
12544
|
+
if ((0, types_1.isClass)(subtype)) {
|
12545
|
+
const anyArg = { type: types_1.AnyType.create() };
|
12546
|
+
const exitType = getTypeOfMagicMethodReturn(subtype, [anyArg, anyArg, anyArg], exitMethodName, node.expression,
|
12547
|
+
/* expectedType */ undefined);
|
12220
12548
|
if (exitType) {
|
12221
12549
|
return;
|
12222
12550
|
}
|
@@ -12528,6 +12856,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12528
12856
|
}
|
12529
12857
|
getTypeOfAnnotation(annotationNode, {
|
12530
12858
|
isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
|
12859
|
+
allowUnpackedTuple: annotationParent.nodeType === 41 /* Parameter */ &&
|
12860
|
+
annotationParent.category === 1 /* VarArgList */,
|
12861
|
+
allowUnpackedTypedDict: annotationParent.nodeType === 41 /* Parameter */ &&
|
12862
|
+
annotationParent.category === 2 /* VarArgDictionary */,
|
12531
12863
|
});
|
12532
12864
|
return;
|
12533
12865
|
}
|
@@ -12588,6 +12920,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12588
12920
|
break;
|
12589
12921
|
}
|
12590
12922
|
}
|
12923
|
+
else if (parent.nodeType === 48 /* StringList */ && nodeToEvaluate === parent.typeAnnotation) {
|
12924
|
+
// Forward-declared type annotation expressions need to be be evaluated
|
12925
|
+
// in context so they have the appropriate flags set. Most of these cases
|
12926
|
+
// will have been detected above when calling getParentAnnotationNode,
|
12927
|
+
// but TypeAlias expressions are not handled there.
|
12928
|
+
nodeToEvaluate = parent;
|
12929
|
+
continue;
|
12930
|
+
}
|
12591
12931
|
else {
|
12592
12932
|
// Check for expression types that are always contextual.
|
12593
12933
|
if (nodeToEvaluate.nodeType !== 15 /* Dictionary */ &&
|
@@ -12903,17 +13243,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12903
13243
|
}
|
12904
13244
|
// Attempts to determine the type of the reference expression at the
|
12905
13245
|
// 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,
|
13246
|
+
// about that expression, it returns un undefined type. Normally
|
13247
|
+
// flow analysis starts from the reference node, but startNode can be
|
13248
|
+
// specified to override this in a few special cases (functions and
|
13249
|
+
// lambdas) to support analysis of captured variables.
|
13250
|
+
function getFlowTypeOfReference(reference, targetSymbolId, typeAtStart, startNode, options) {
|
12911
13251
|
var _a;
|
12912
13252
|
// See if this execution scope requires code flow for this reference expression.
|
12913
13253
|
const referenceKey = (0, codeFlowTypes_1.createKeyForReference)(reference);
|
12914
13254
|
const executionNode = ParseTreeUtils.getExecutionScopeNode((_a = startNode === null || startNode === void 0 ? void 0 : startNode.parent) !== null && _a !== void 0 ? _a : reference);
|
12915
13255
|
const codeFlowExpressions = AnalyzerNodeInfo.getCodeFlowExpressions(executionNode);
|
12916
|
-
if (!codeFlowExpressions ||
|
13256
|
+
if (!codeFlowExpressions ||
|
13257
|
+
(!codeFlowExpressions.has(referenceKey) && !codeFlowExpressions.has(codeFlowTypes_1.wildcardImportReferenceKey))) {
|
12917
13258
|
return { type: undefined, isIncomplete: false };
|
12918
13259
|
}
|
12919
13260
|
if (checkCodeFlowTooComplex(reference)) {
|
@@ -12935,7 +13276,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12935
13276
|
if (flowNode === undefined) {
|
12936
13277
|
return { type: undefined, isIncomplete: false };
|
12937
13278
|
}
|
12938
|
-
return analyzer.getTypeFromCodeFlow(flowNode, reference, targetSymbolId,
|
13279
|
+
return analyzer.getTypeFromCodeFlow(flowNode, reference, targetSymbolId, typeAtStart, options);
|
12939
13280
|
}
|
12940
13281
|
// Specializes the specified (potentially generic) class type using
|
12941
13282
|
// the specified type arguments, reporting errors as appropriate.
|
@@ -13068,6 +13409,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13068
13409
|
}
|
13069
13410
|
const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
13070
13411
|
if (typeArgs) {
|
13412
|
+
let minTypeArgCount = typeParameters.length;
|
13413
|
+
const firstNonDefaultParam = typeParameters.findIndex((param) => !!param.details.defaultType);
|
13414
|
+
if (firstNonDefaultParam >= 0) {
|
13415
|
+
minTypeArgCount = firstNonDefaultParam;
|
13416
|
+
}
|
13071
13417
|
if (typeArgCount > typeParameters.length) {
|
13072
13418
|
if (!types_1.ClassType.isPartiallyEvaluated(classType) && !types_1.ClassType.isTupleClass(classType)) {
|
13073
13419
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
@@ -13086,11 +13432,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13086
13432
|
typeArgCount = typeParameters.length;
|
13087
13433
|
}
|
13088
13434
|
}
|
13089
|
-
else if (typeArgCount <
|
13435
|
+
else if (typeArgCount < minTypeArgCount) {
|
13090
13436
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
13091
13437
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
|
13092
13438
|
name: classType.aliasName || classType.details.name,
|
13093
|
-
expected:
|
13439
|
+
expected: minTypeArgCount,
|
13094
13440
|
received: typeArgCount,
|
13095
13441
|
}), typeArgs.length > 0 ? typeArgs[0].node.parent : errorNode);
|
13096
13442
|
}
|
@@ -13148,6 +13494,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13148
13494
|
}
|
13149
13495
|
}
|
13150
13496
|
fullTypeParams.forEach((typeParam, index) => {
|
13497
|
+
var _a;
|
13151
13498
|
if (typeArgs && index < typeArgs.length) {
|
13152
13499
|
if (typeParam.details.isParamSpec) {
|
13153
13500
|
const typeArg = typeArgs[index];
|
@@ -13199,7 +13546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13199
13546
|
typeArgTypes.push((0, typeUtils_1.convertToInstance)(typeArgs[index].type));
|
13200
13547
|
return;
|
13201
13548
|
}
|
13202
|
-
typeArgTypes.push(types_1.UnknownType.create());
|
13549
|
+
typeArgTypes.push((_a = typeParam.details.defaultType) !== null && _a !== void 0 ? _a : types_1.UnknownType.create());
|
13203
13550
|
});
|
13204
13551
|
typeArgTypes = typeArgTypes.map((typeArgType, index) => {
|
13205
13552
|
if (index < typeArgCount) {
|
@@ -13208,19 +13555,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13208
13555
|
// Determine if the variance must match.
|
13209
13556
|
if (adjustedTypeArgType && (flags & 16384 /* EnforceTypeVarVarianceConsistency */) !== 0) {
|
13210
13557
|
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
|
-
}
|
13558
|
+
const declaredVariance = destType.details.declaredVariance;
|
13559
|
+
if (!(0, typeUtils_1.isVarianceOfTypeArgumentCompatible)(adjustedTypeArgType, declaredVariance)) {
|
13560
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.varianceMismatch().format({
|
13561
|
+
typeVarName: printType(adjustedTypeArgType),
|
13562
|
+
className: classType.details.name,
|
13563
|
+
}));
|
13564
|
+
adjustedTypeArgType = undefined;
|
13224
13565
|
}
|
13225
13566
|
}
|
13226
13567
|
if (adjustedTypeArgType) {
|
@@ -13272,11 +13613,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13272
13613
|
// be a value expression from which we can retrieve the type.
|
13273
13614
|
return getTypeOfExpressionExpectingType(arg.valueExpression);
|
13274
13615
|
}
|
13275
|
-
function getTypeOfExpressionExpectingType(node,
|
13616
|
+
function getTypeOfExpressionExpectingType(node, options) {
|
13276
13617
|
let flags = 64 /* ExpectingType */ |
|
13277
13618
|
8 /* EvaluateStringLiteralAsType */ |
|
13278
|
-
32 /* ParamSpecDisallowed */ |
|
13279
|
-
128 /* TypeVarTupleDisallowed */ |
|
13280
13619
|
131072 /* ClassVarDisallowed */;
|
13281
13620
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13282
13621
|
if (fileInfo.isStubFile) {
|
@@ -13285,12 +13624,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13285
13624
|
else {
|
13286
13625
|
flags |= 4194304 /* InterpreterParsesStringLiteral */;
|
13287
13626
|
}
|
13288
|
-
if (!allowFinal) {
|
13627
|
+
if (!(options === null || options === void 0 ? void 0 : options.allowFinal)) {
|
13289
13628
|
flags |= 16 /* FinalDisallowed */;
|
13290
13629
|
}
|
13291
|
-
if (allowRequired) {
|
13630
|
+
if (options === null || options === void 0 ? void 0 : options.allowRequired) {
|
13292
13631
|
flags |= 1048576 /* RequiredAllowed */ | 1024 /* ExpectingTypeAnnotation */;
|
13293
13632
|
}
|
13633
|
+
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTuple) {
|
13634
|
+
flags |= 2097152 /* AllowUnpackedTupleOrTypeVarTuple */;
|
13635
|
+
}
|
13636
|
+
else {
|
13637
|
+
flags |= 128 /* TypeVarTupleDisallowed */;
|
13638
|
+
}
|
13639
|
+
if (!(options === null || options === void 0 ? void 0 : options.allowParamSpec)) {
|
13640
|
+
flags |= 32 /* ParamSpecDisallowed */;
|
13641
|
+
}
|
13294
13642
|
return getTypeOfExpression(node, flags);
|
13295
13643
|
}
|
13296
13644
|
function getBuiltInType(node, name) {
|
@@ -13494,6 +13842,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13494
13842
|
}
|
13495
13843
|
return declarations.length === 0 ? undefined : declarations;
|
13496
13844
|
}
|
13845
|
+
function getAliasFromImport(node) {
|
13846
|
+
if (node.parent &&
|
13847
|
+
node.parent.nodeType === 23 /* ImportFromAs */ &&
|
13848
|
+
node.parent.alias &&
|
13849
|
+
node === node.parent.name) {
|
13850
|
+
return node.parent.alias;
|
13851
|
+
}
|
13852
|
+
return undefined;
|
13853
|
+
}
|
13497
13854
|
function getDeclarationsForNameNode(node, skipUnreachableCode = true) {
|
13498
13855
|
var _a;
|
13499
13856
|
if (skipUnreachableCode && AnalyzerNodeInfo.isCodeUnreachable(node)) {
|
@@ -13503,14 +13860,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13503
13860
|
// If the node is part of a "from X import Y as Z" statement and the node
|
13504
13861
|
// is the "Y" (non-aliased) name, we need to look up the alias symbol
|
13505
13862
|
// since the non-aliased name is not in the symbol table.
|
13506
|
-
|
13507
|
-
|
13508
|
-
node.parent.alias &&
|
13509
|
-
node === node.parent.name) {
|
13863
|
+
const alias = getAliasFromImport(node);
|
13864
|
+
if (alias) {
|
13510
13865
|
const scope = ScopeUtils.getScopeForNode(node);
|
13511
13866
|
if (scope) {
|
13512
13867
|
// Look up the alias symbol.
|
13513
|
-
const symbolInScope = scope.lookUpSymbolRecursive(
|
13868
|
+
const symbolInScope = scope.lookUpSymbolRecursive(alias.value);
|
13514
13869
|
if (symbolInScope) {
|
13515
13870
|
// The alias could have more decls that don't refer to this import. Filter
|
13516
13871
|
// out the one(s) that specifically associated with this import statement.
|
@@ -13623,7 +13978,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13623
13978
|
if (paramDecl) {
|
13624
13979
|
declarations.push(paramDecl);
|
13625
13980
|
}
|
13626
|
-
else if (types_1.ClassType.isDataClass(baseType)) {
|
13981
|
+
else if (types_1.ClassType.isDataClass(baseType) || types_1.ClassType.isTypedDictClass(baseType)) {
|
13627
13982
|
const lookupResults = (0, typeUtils_1.lookUpClassMember)(baseType, paramName);
|
13628
13983
|
if (lookupResults) {
|
13629
13984
|
(0, collectionUtils_1.appendArray)(declarations, lookupResults.symbol.getDeclarations());
|
@@ -13743,7 +14098,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13743
14098
|
const constraints = declaration.node.boundExpression.expressions.map((constraint) => {
|
13744
14099
|
const constraintType = getTypeOfExpressionExpectingType(constraint).type;
|
13745
14100
|
if ((0, typeUtils_1.requiresSpecialization)(constraintType, /* ignorePseudoGeneric */ true)) {
|
13746
|
-
addError(localize_1.Localizer.Diagnostic.
|
14101
|
+
addError(localize_1.Localizer.Diagnostic.typeVarBoundGeneric(), constraint);
|
13747
14102
|
}
|
13748
14103
|
return (0, typeUtils_1.convertToInstance)(constraintType);
|
13749
14104
|
});
|
@@ -13758,13 +14113,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13758
14113
|
else {
|
13759
14114
|
const boundType = getTypeOfExpressionExpectingType(declaration.node.boundExpression).type;
|
13760
14115
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, /* ignorePseudoGeneric */ true)) {
|
13761
|
-
addError(localize_1.Localizer.Diagnostic.
|
14116
|
+
addError(localize_1.Localizer.Diagnostic.typeVarConstraintGeneric(), declaration.node.boundExpression);
|
13762
14117
|
}
|
13763
14118
|
if (declaration.node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVar) {
|
13764
14119
|
typeVar.details.boundType = (0, typeUtils_1.convertToInstance)(boundType);
|
13765
14120
|
}
|
13766
14121
|
}
|
13767
14122
|
}
|
14123
|
+
if (declaration.node.defaultExpression) {
|
14124
|
+
// TODO - need to finish. For now, just evaluate the expression
|
14125
|
+
// to generate any errors.
|
14126
|
+
getTypeOfExpression(declaration.node.defaultExpression, 2097152 /* AllowUnpackedTupleOrTypeVarTuple */);
|
14127
|
+
}
|
13768
14128
|
typeVar.details.isTypeParamSyntax = true;
|
13769
14129
|
// Associate the type variable with the owning scope.
|
13770
14130
|
const scopeNode = ParseTreeUtils.getTypeVarScopeNode(declaration.node);
|
@@ -13794,9 +14154,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13794
14154
|
: undefined;
|
13795
14155
|
let declaredType;
|
13796
14156
|
if (declaration.isRuntimeTypeExpression) {
|
13797
|
-
declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode,
|
13798
|
-
|
13799
|
-
|
14157
|
+
declaredType = (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(typeAnnotationNode, {
|
14158
|
+
allowFinal: true,
|
14159
|
+
allowRequired: true,
|
14160
|
+
}).type);
|
13800
14161
|
}
|
13801
14162
|
else {
|
13802
14163
|
const declNode = declaration.isDefinedByMemberAccess &&
|
@@ -14090,6 +14451,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14090
14451
|
const decls = symbol.getDeclarations();
|
14091
14452
|
const isFinalVar = (0, symbolUtils_1.isFinalVariable)(symbol);
|
14092
14453
|
let isIncomplete = false;
|
14454
|
+
let sawPendingEvaluation = false;
|
14093
14455
|
let includesVariableDecl = false;
|
14094
14456
|
let includesSpeculativeResult = false;
|
14095
14457
|
let declIndexToConsider;
|
@@ -14138,7 +14500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14138
14500
|
}
|
14139
14501
|
if (considerDecl) {
|
14140
14502
|
const isExplicitTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(decl);
|
14141
|
-
const isTypeAlias = isExplicitTypeAlias || (
|
14503
|
+
const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
|
14142
14504
|
if (isExplicitTypeAlias) {
|
14143
14505
|
sawExplicitTypeAlias = true;
|
14144
14506
|
}
|
@@ -14208,13 +14570,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14208
14570
|
}
|
14209
14571
|
}
|
14210
14572
|
isIncomplete = true;
|
14573
|
+
// Note that at least one decl could not be evaluated because
|
14574
|
+
// it was already in the process of being evaluated.
|
14575
|
+
sawPendingEvaluation = true;
|
14211
14576
|
}
|
14212
14577
|
}
|
14213
14578
|
});
|
14214
14579
|
if (typesToCombine.length > 0) {
|
14215
14580
|
const result = {
|
14216
14581
|
type: (0, types_1.combineTypes)(typesToCombine),
|
14217
|
-
isIncomplete:
|
14582
|
+
isIncomplete: sawPendingEvaluation,
|
14218
14583
|
includesVariableDecl,
|
14219
14584
|
includesIllegalTypeAliasDecl: !decls.every((decl) => (0, declarationUtils_1.isPossibleTypeAliasDeclaration)(decl)),
|
14220
14585
|
isRecursiveDefinition: false,
|
@@ -14759,9 +15124,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14759
15124
|
}
|
14760
15125
|
}
|
14761
15126
|
else {
|
14762
|
-
const
|
15127
|
+
const removedArgTypes = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture).map((t) => {
|
15128
|
+
if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
|
15129
|
+
return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
|
15130
|
+
}
|
15131
|
+
return t.type;
|
15132
|
+
});
|
14763
15133
|
srcTypeArgs.splice(destUnboundedIndex, 0, {
|
14764
|
-
type:
|
15134
|
+
type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
|
14765
15135
|
isUnbounded: false,
|
14766
15136
|
});
|
14767
15137
|
}
|
@@ -14979,14 +15349,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14979
15349
|
// and added to the map.
|
14980
15350
|
function assignType(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags = 0 /* Default */, recursionCount = 0) {
|
14981
15351
|
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
15352
|
// Handle the case where the dest and src types are the same object.
|
14991
15353
|
// We can normally shortcut this and say that they are compatible,
|
14992
15354
|
// but if the type includes TypeVars, we need to go through
|
@@ -15238,34 +15600,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15238
15600
|
}
|
15239
15601
|
}
|
15240
15602
|
// Is the src a specialized "Type" object?
|
15241
|
-
if ((0, types_1.isClassInstance)(
|
15242
|
-
const srcTypeArgs =
|
15603
|
+
if ((0, types_1.isClassInstance)(expandedSrcType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
|
15604
|
+
const srcTypeArgs = expandedSrcType.typeArguments;
|
15605
|
+
let typeTypeArg;
|
15243
15606
|
if (srcTypeArgs && srcTypeArgs.length >= 1) {
|
15244
|
-
|
15245
|
-
|
15607
|
+
typeTypeArg = srcTypeArgs[0];
|
15608
|
+
if ((0, types_1.isAnyOrUnknown)(typeTypeArg)) {
|
15609
|
+
if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(expandedSrcType, 'type')) {
|
15246
15610
|
return true;
|
15247
15611
|
}
|
15248
15612
|
return types_1.TypeBase.isInstantiable(destType);
|
15249
15613
|
}
|
15250
|
-
|
15251
|
-
|
15252
|
-
|
15253
|
-
|
15254
|
-
|
15255
|
-
|
15256
|
-
|
15257
|
-
}));
|
15258
|
-
return false;
|
15614
|
+
}
|
15615
|
+
else {
|
15616
|
+
typeTypeArg = objectType !== null && objectType !== void 0 ? objectType : types_1.AnyType.create();
|
15617
|
+
}
|
15618
|
+
if ((0, types_1.isClassInstance)(typeTypeArg) || (0, types_1.isTypeVar)(typeTypeArg)) {
|
15619
|
+
if (assignType(destType, (0, typeUtils_1.convertToInstantiable)(typeTypeArg), diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
15620
|
+
return true;
|
15259
15621
|
}
|
15622
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format({
|
15623
|
+
sourceType: printType(srcType),
|
15624
|
+
destType: printType(destType),
|
15625
|
+
}));
|
15626
|
+
return false;
|
15260
15627
|
}
|
15261
15628
|
}
|
15262
15629
|
if ((0, types_1.isInstantiableClass)(destType)) {
|
15263
|
-
|
15264
|
-
if ((0, types_1.isInstantiableClass)(concreteSrcType)) {
|
15630
|
+
if ((0, types_1.isInstantiableClass)(expandedSrcType)) {
|
15265
15631
|
// PEP 544 says that if the dest type is a Type[Proto] class,
|
15266
15632
|
// the source must be a "concrete" (non-protocol) class.
|
15267
15633
|
if (types_1.ClassType.isProtocolClass(destType)) {
|
15268
|
-
if (types_1.ClassType.isProtocolClass(
|
15634
|
+
if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
15269
15635
|
(0, types_1.isInstantiableClass)(srcType) &&
|
15270
15636
|
!srcType.includeSubclasses) {
|
15271
15637
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.protocolSourceIsNotConcrete().format({
|
@@ -15275,7 +15641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15275
15641
|
return false;
|
15276
15642
|
}
|
15277
15643
|
}
|
15278
|
-
if (assignClass(destType,
|
15644
|
+
if (assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
15279
15645
|
/* reportErrorsUsingObjType */ false)) {
|
15280
15646
|
return true;
|
15281
15647
|
}
|
@@ -15628,6 +15994,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15628
15994
|
// matches for types like `tuple[Any]` and `tuple[int]` from being considered
|
15629
15995
|
// proper subtypes of each other.
|
15630
15996
|
function isProperSubtype(destType, srcType, recursionCount) {
|
15997
|
+
// If the destType has a condition, don't consider the srcType a proper subtype.
|
15998
|
+
if (destType.condition) {
|
15999
|
+
return false;
|
16000
|
+
}
|
15631
16001
|
// Shortcut the check if either type is Any or Unknown.
|
15632
16002
|
if ((0, types_1.isAnyOrUnknown)(destType) || (0, types_1.isAnyOrUnknown)(srcType)) {
|
15633
16003
|
return true;
|
@@ -15694,9 +16064,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15694
16064
|
// If so, we need to use a slower path.
|
15695
16065
|
if (!(0, typeUtils_1.requiresSpecialization)(destType)) {
|
15696
16066
|
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)) {
|
16067
|
+
if (assignType(subtype, srcType, diagAddendum === null || diagAddendum === void 0 ? void 0 : diagAddendum.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
15700
16068
|
foundMatch = true;
|
15701
16069
|
break;
|
15702
16070
|
}
|
@@ -16394,7 +16762,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16394
16762
|
const effectiveDestType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? destType : srcType;
|
16395
16763
|
const effectiveSrcType = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcType : destType;
|
16396
16764
|
if (effectiveDestType.details.paramSpec) {
|
16397
|
-
const requiredMatchParamCount =
|
16765
|
+
const requiredMatchParamCount = effectiveDestType.details.parameters.filter((p) => {
|
16766
|
+
if (!p.name) {
|
16767
|
+
return false;
|
16768
|
+
}
|
16398
16769
|
if (p.category === 0 /* Simple */ && (0, types_1.isParamSpec)(p.type)) {
|
16399
16770
|
return false;
|
16400
16771
|
}
|
@@ -16515,7 +16886,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16515
16886
|
// replace that type argument in the assigned type. This function assumes
|
16516
16887
|
// that the caller has already verified that the assignedType is assignable
|
16517
16888
|
// to the declaredType.
|
16518
|
-
function replaceTypeArgsWithAny(declaredType, assignedType) {
|
16889
|
+
function replaceTypeArgsWithAny(declaredType, assignedType, recursionCount = 0) {
|
16890
|
+
if (recursionCount > types_1.maxTypeRecursionCount) {
|
16891
|
+
return undefined;
|
16892
|
+
}
|
16893
|
+
recursionCount++;
|
16519
16894
|
// If this is a tuple with defined tuple type arguments, don't overwrite them.
|
16520
16895
|
if (assignedType.tupleTypeArguments) {
|
16521
16896
|
return undefined;
|
@@ -16536,6 +16911,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16536
16911
|
replacedTypeArg = true;
|
16537
16912
|
return expectedTypeArgType;
|
16538
16913
|
}
|
16914
|
+
else if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
|
16915
|
+
// Recursively replace Any in the type argument.
|
16916
|
+
const recursiveReplacement = replaceTypeArgsWithAny(expectedTypeArgType, typeArg, recursionCount);
|
16917
|
+
if (recursiveReplacement) {
|
16918
|
+
replacedTypeArg = true;
|
16919
|
+
return recursiveReplacement;
|
16920
|
+
}
|
16921
|
+
}
|
16539
16922
|
}
|
16540
16923
|
return typeArg;
|
16541
16924
|
});
|
@@ -16575,10 +16958,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16575
16958
|
// use the concrete type.
|
16576
16959
|
return declaredSubtype;
|
16577
16960
|
}
|
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
16961
|
return assignedSubtype;
|
16583
16962
|
}
|
16584
16963
|
return undefined;
|
@@ -16591,7 +16970,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16591
16970
|
return narrowedSubtype;
|
16592
16971
|
});
|
16593
16972
|
// If the result of narrowing is Any, stick with the declared (unnarrowed) type.
|
16594
|
-
|
16973
|
+
// If the result of narrowing is an Unknown that is complete, stick with Unknown.
|
16974
|
+
// If it's incomplete, propagate the incomplete type for the benefit of
|
16975
|
+
// code flow analysis.
|
16976
|
+
if ((0, types_1.isAnyOrUnknown)(assignedType) && !(0, typeUtils_1.isIncompleteUnknown)(assignedType)) {
|
16595
16977
|
return declaredType;
|
16596
16978
|
}
|
16597
16979
|
return narrowedType;
|
@@ -16698,6 +17080,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16698
17080
|
const overrideParam = overrideParamDetails.params[i].param;
|
16699
17081
|
if (i >= baseParamDetails.positionOnlyParamCount &&
|
16700
17082
|
!(0, symbolNameUtils_1.isPrivateOrProtectedName)(baseParam.name || '') &&
|
17083
|
+
baseParamDetails.params[i].source !== typeUtils_1.ParameterSource.PositionOnly &&
|
16701
17084
|
baseParam.category === 0 /* Simple */ &&
|
16702
17085
|
baseParam.name !== overrideParam.name) {
|
16703
17086
|
if (overrideParam.category === 0 /* Simple */) {
|
@@ -17108,11 +17491,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17108
17491
|
function printFunctionParts(type) {
|
17109
17492
|
return TypePrinter.printFunctionParts(type, evaluatorOptions.printTypeFlags, getFunctionEffectiveReturnType);
|
17110
17493
|
}
|
17111
|
-
function printType(type,
|
17494
|
+
function printType(type, options) {
|
17112
17495
|
let flags = evaluatorOptions.printTypeFlags;
|
17113
|
-
if (expandTypeAlias) {
|
17496
|
+
if (options === null || options === void 0 ? void 0 : options.expandTypeAlias) {
|
17114
17497
|
flags |= 32 /* ExpandTypeAlias */;
|
17115
17498
|
}
|
17499
|
+
if (options === null || options === void 0 ? void 0 : options.enforcePythonSyntax) {
|
17500
|
+
flags |= 256 /* PythonSyntax */;
|
17501
|
+
}
|
17502
|
+
if (options === null || options === void 0 ? void 0 : options.useTypingUnpack) {
|
17503
|
+
flags |= 512 /* UseTypingUnpack */;
|
17504
|
+
}
|
17116
17505
|
return TypePrinter.printType(type, flags, getFunctionEffectiveReturnType);
|
17117
17506
|
}
|
17118
17507
|
// Calls back into the parser to parse the contents of a string literal.
|