@zzzen/pyright-internal 1.2.0-dev.20240324 → 1.2.0-dev.20240407
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/analyzerFileInfo.d.ts +0 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/binder.js +15 -8
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +12 -0
- package/dist/analyzer/cacheManager.js +63 -3
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +2 -3
- package/dist/analyzer/checker.js +18 -13
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +14 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +1 -0
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +20 -3
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +2 -2
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +3 -2
- package/dist/analyzer/constructors.js +76 -54
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +7 -6
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declaration.js +1 -1
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/enums.js +8 -3
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/functionTransform.js +1 -1
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +19 -17
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +6 -6
- package/dist/analyzer/importStatementUtils.js +42 -42
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +3 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +7 -7
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +6 -5
- package/dist/analyzer/parseTreeUtils.js +12 -13
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +15 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +5 -10
- package/dist/analyzer/program.js +35 -30
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/programTypes.d.ts +11 -0
- package/dist/analyzer/programTypes.js +11 -0
- package/dist/analyzer/programTypes.js.map +1 -0
- package/dist/analyzer/properties.js +10 -10
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +5 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -2
- package/dist/analyzer/service.js +24 -15
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +5 -3
- package/dist/analyzer/sourceFile.js +112 -75
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +4 -4
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +6 -6
- package/dist/analyzer/symbol.d.ts +4 -1
- package/dist/analyzer/symbol.js +10 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/symbolUtils.d.ts +1 -0
- package/dist/analyzer/symbolUtils.js +11 -1
- package/dist/analyzer/symbolUtils.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +2 -2
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +159 -73
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeGuards.js +16 -9
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +1 -1
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -2
- package/dist/analyzer/typeUtils.js +33 -20
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +32 -20
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +5 -1
- package/dist/analyzer/types.js +20 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.d.ts +1 -0
- package/dist/backgroundAnalysis.js +6 -2
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -1
- package/dist/backgroundAnalysisBase.js +6 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +1 -0
- package/dist/backgroundThreadBase.js +19 -10
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/commandController.d.ts +2 -1
- package/dist/commands/commandController.js +3 -0
- package/dist/commands/commandController.js.map +1 -1
- package/dist/commands/createTypeStub.d.ts +1 -1
- package/dist/commands/createTypeStub.js +3 -3
- package/dist/commands/createTypeStub.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.d.ts +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +5 -5
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/commands/quickActionCommand.d.ts +1 -1
- package/dist/commands/quickActionCommand.js +2 -2
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/commands/restartServer.d.ts +1 -1
- package/dist/common/cancellationUtils.js +2 -2
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/caseSensitivityDetector.d.ts +6 -0
- package/dist/common/caseSensitivityDetector.js +18 -0
- package/dist/common/caseSensitivityDetector.js.map +1 -0
- package/dist/common/commandLineOptions.d.ts +3 -2
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/commandUtils.js +1 -1
- package/dist/common/commandUtils.js.map +1 -1
- package/dist/common/configOptions.js +3 -3
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/envVarUtils.d.ts +1 -0
- package/dist/common/envVarUtils.js +42 -7
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +4 -3
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +2 -2
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/fileSystem.d.ts +0 -1
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/fullAccessHost.js +4 -3
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +62 -0
- package/dist/common/languageServerInterface.js +10 -0
- package/dist/common/languageServerInterface.js.map +1 -0
- package/dist/common/realFileSystem.d.ts +8 -4
- package/dist/common/realFileSystem.js +56 -17
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +21 -0
- package/dist/common/serviceKeys.js +26 -0
- package/dist/common/serviceKeys.js.map +1 -0
- package/dist/common/serviceProviderExtensions.d.ts +3 -15
- package/dist/common/serviceProviderExtensions.js +23 -27
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/textEditTracker.d.ts +5 -5
- package/dist/common/textEditTracker.js +35 -35
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/uri/constantUri.d.ts +36 -0
- package/dist/common/uri/constantUri.js +112 -0
- package/dist/common/uri/constantUri.js.map +1 -0
- package/dist/common/uri/emptyUri.d.ts +3 -31
- package/dist/common/uri/emptyUri.js +3 -84
- package/dist/common/uri/emptyUri.js.map +1 -1
- package/dist/common/uri/fileUri.d.ts +1 -0
- package/dist/common/uri/fileUri.js +3 -2
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/uri.d.ts +11 -3
- package/dist/common/uri/uri.js +31 -20
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +11 -5
- package/dist/common/uri/uriUtils.js +31 -53
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/common/workspaceEditUtils.js +4 -4
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +11 -59
- package/dist/languageServerBase.js +18 -8
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +4 -5
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -3
- package/dist/languageService/autoImporter.js +2 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +6 -6
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/codeActionProvider.js +43 -42
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +10 -11
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +3 -3
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/documentHighlightProvider.js +2 -2
- package/dist/languageService/documentHighlightProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +3 -3
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.d.ts +3 -2
- package/dist/languageService/documentSymbolProvider.js +4 -3
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.js +2 -2
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/importSorter.d.ts +2 -2
- package/dist/languageService/importSorter.js +1 -1
- package/dist/languageService/importSorter.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +4 -4
- package/dist/languageService/referencesProvider.js +4 -4
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +4 -4
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +5 -2
- package/dist/languageService/symbolIndexer.js +21 -11
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +2 -2
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +3 -0
- package/dist/localization/localize.js +22 -16
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -0
- package/dist/localization/package.nls.de.json +1 -0
- package/dist/localization/package.nls.en-us.json +1 -0
- package/dist/localization/package.nls.es.json +1 -0
- package/dist/localization/package.nls.fr.json +1 -0
- package/dist/localization/package.nls.it.json +1 -0
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ko.json +1 -0
- package/dist/localization/package.nls.pl.json +1 -0
- package/dist/localization/package.nls.pt-br.json +1 -0
- package/dist/localization/package.nls.qps-ploc.json +1 -0
- package/dist/localization/package.nls.ru.json +1 -0
- package/dist/localization/package.nls.tr.json +1 -0
- package/dist/localization/package.nls.zh-cn.json +1 -0
- package/dist/localization/package.nls.zh-tw.json +1 -0
- package/dist/nodeMain.d.ts +1 -1
- package/dist/nodeMain.js +2 -2
- package/dist/nodeMain.js.map +1 -1
- package/dist/parser/parser.d.ts +7 -4
- package/dist/parser/parser.js +7 -5
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +6 -6
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +3 -1
- package/dist/pyrightFileSystem.js +14 -9
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +0 -1
- package/dist/readonlyAugmentedFileSystem.js +0 -3
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.d.ts +4 -2
- package/dist/server.js +15 -11
- package/dist/server.js.map +1 -1
- package/dist/tests/cacheManager.test.js +35 -0
- package/dist/tests/cacheManager.test.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +18 -18
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/completions.test.js +4 -4
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +19 -14
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/documentSymbolCollector.test.js +2 -3
- package/dist/tests/documentSymbolCollector.test.js.map +1 -1
- package/dist/tests/envVarUtils.test.js +77 -2
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +13 -13
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +10 -10
- package/dist/tests/fourSlashParser.test.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +12 -10
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.d.ts +1 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +3 -2
- package/dist/tests/harness/fourslash/testLanguageService.js +2 -2
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +6 -6
- package/dist/tests/harness/fourslash/testState.js +42 -37
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/harness/testHost.d.ts +7 -0
- package/dist/tests/harness/testHost.js +33 -14
- package/dist/tests/harness/testHost.js.map +1 -1
- package/dist/tests/harness/vfs/factory.d.ts +3 -4
- package/dist/tests/harness/vfs/factory.js +7 -6
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +5 -3
- package/dist/tests/harness/vfs/filesystem.js +22 -15
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/importResolver.test.js +35 -34
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +9 -10
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +1 -1
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/logger.test.js +1 -1
- package/dist/tests/logger.test.js.map +1 -1
- package/dist/tests/lsp/languageServer.js +6 -5
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.d.ts +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js +15 -10
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +1 -2
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/parser.test.js +14 -14
- package/dist/tests/parser.test.js.map +1 -1
- package/dist/tests/pyrightFileSystem.test.js +6 -5
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/serialization.test.js +5 -5
- package/dist/tests/serialization.test.js.map +1 -1
- package/dist/tests/service.test.js +16 -25
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +1 -1
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +8 -5
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +4 -4
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +5 -5
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testStateUtils.js +8 -6
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/testUtils.d.ts +4 -8
- package/dist/tests/testUtils.js +9 -10
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +3 -3
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +11 -5
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/uri.test.js +220 -199
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +7 -7
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +7 -5
- package/dist/tests/zipfs.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +15 -6
- package/dist/workspaceFactory.js +16 -10
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +5 -5
@@ -1421,13 +1421,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1421
1421
|
subDiag = metaclassDiag;
|
1422
1422
|
}
|
1423
1423
|
}
|
1424
|
-
if (memberInfo
|
1424
|
+
if (memberInfo) {
|
1425
|
+
if (memberInfo.isDescriptorError && diag && subDiag) {
|
1426
|
+
diag.addAddendum(subDiag);
|
1427
|
+
}
|
1425
1428
|
return {
|
1426
1429
|
type: memberInfo.type,
|
1427
1430
|
classType: memberInfo.classType,
|
1428
1431
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1429
1432
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1430
1433
|
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1434
|
+
typeErrors: memberInfo.isDescriptorError,
|
1431
1435
|
};
|
1432
1436
|
}
|
1433
1437
|
// If this is a type[Any] or type[Unknown], allow any other members.
|
@@ -1545,7 +1549,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1545
1549
|
let constructorType;
|
1546
1550
|
// Try to get the `__init__` method first because it typically has more
|
1547
1551
|
// type information than `__new__`.
|
1548
|
-
const initMethodResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, callNode, types_1.ClassType.cloneAsInstance(subtype),
|
1552
|
+
const initMethodResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, callNode, types_1.ClassType.cloneAsInstance(subtype),
|
1553
|
+
/* diag */ undefined, 0 /* MemberAccessFlags.Default */);
|
1549
1554
|
if (initMethodResult && !initMethodResult.typeErrors) {
|
1550
1555
|
if ((0, types_1.isFunction)(initMethodResult.type) || (0, types_1.isOverloadedFunction)(initMethodResult.type)) {
|
1551
1556
|
constructorType = initMethodResult.type;
|
@@ -1561,7 +1566,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1561
1566
|
// the `object` class or accepts only default parameters(* args, ** kwargs),
|
1562
1567
|
// see if we can find a better signature from the `__new__` method.
|
1563
1568
|
if (!constructorType || isObjectInit || isDefaultParams) {
|
1564
|
-
const newMethodResult = (0, constructors_1.getBoundNewMethod)(evaluatorInterface, callNode, subtype
|
1569
|
+
const newMethodResult = (0, constructors_1.getBoundNewMethod)(evaluatorInterface, callNode, subtype);
|
1565
1570
|
if (newMethodResult && !newMethodResult.typeErrors) {
|
1566
1571
|
if ((0, types_1.isFunction)(newMethodResult.type) &&
|
1567
1572
|
newMethodResult.type.details.fullName !== 'builtins.object.__new__') {
|
@@ -2277,7 +2282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2277
2282
|
// Assignments to instance or class variables through "self" or "cls" is not
|
2278
2283
|
// allowed for protocol classes unless it is also declared within the class.
|
2279
2284
|
if (types_1.ClassType.isProtocolClass(classTypeResults.classType)) {
|
2280
|
-
const memberSymbol = classTypeResults.classType.
|
2285
|
+
const memberSymbol = types_1.ClassType.getSymbolTable(classTypeResults.classType).get(target.memberName.value);
|
2281
2286
|
if (memberSymbol) {
|
2282
2287
|
const classLevelDecls = memberSymbol.getDeclarations().filter((decl) => {
|
2283
2288
|
return !ParseTreeUtils.getEnclosingFunction(decl.node);
|
@@ -2318,7 +2323,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2318
2323
|
const classTypeInfo = getTypeOfClass(classDef);
|
2319
2324
|
if (classTypeInfo && (0, types_1.isInstantiableClass)(classTypeInfo.classType)) {
|
2320
2325
|
let memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, isInstanceMember ? 0 /* MemberAccessFlags.Default */ : 16 /* MemberAccessFlags.SkipInstanceMembers */);
|
2321
|
-
const memberFields = classTypeInfo.classType
|
2326
|
+
const memberFields = types_1.ClassType.getSymbolTable(classTypeInfo.classType);
|
2322
2327
|
if (memberInfo) {
|
2323
2328
|
// Are we accessing an existing member on this class, or is
|
2324
2329
|
// it a member on a parent class?
|
@@ -2326,12 +2331,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2326
2331
|
const isThisClass = memberClass && types_1.ClassType.isSameGenericClass(classTypeInfo.classType, memberClass);
|
2327
2332
|
// Check for an attempt to write to an instance variable that is
|
2328
2333
|
// not defined by __slots__.
|
2329
|
-
if (isThisClass && isInstanceMember) {
|
2330
|
-
|
2334
|
+
if (isThisClass && isInstanceMember && memberClass) {
|
2335
|
+
const inheritedSlotsNames = types_1.ClassType.getInheritedSlotsNames(memberClass);
|
2336
|
+
if (inheritedSlotsNames && memberClass.details.localSlotsNames) {
|
2331
2337
|
// Skip this check if the local slots is specified but empty because this pattern
|
2332
2338
|
// is used in a legitimate manner for mix-in classes.
|
2333
2339
|
if (memberClass.details.localSlotsNames.length > 0 &&
|
2334
|
-
!
|
2340
|
+
!inheritedSlotsNames.some((name) => name === memberName)) {
|
2335
2341
|
// Determine whether the assignment corresponds to a descriptor
|
2336
2342
|
// that was assigned as a class variable. If so, then slots will not
|
2337
2343
|
// apply in this case.
|
@@ -3611,18 +3617,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3611
3617
|
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
|
3612
3618
|
/* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
|
3613
3619
|
}
|
3614
|
-
if (typeResult) {
|
3620
|
+
if (typeResult && !typeResult.typeErrors) {
|
3615
3621
|
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType),
|
3616
3622
|
/* skipSelfCondition */ true);
|
3617
|
-
|
3618
|
-
|
3619
|
-
|
3620
|
-
|
3621
|
-
|
3622
|
-
|
3623
|
-
|
3624
|
-
|
3625
|
-
|
3623
|
+
if (typeResult.isIncomplete) {
|
3624
|
+
isIncomplete = true;
|
3625
|
+
}
|
3626
|
+
if (typeResult.isAsymmetricAccessor) {
|
3627
|
+
isAsymmetricAccessor = true;
|
3628
|
+
}
|
3629
|
+
if (typeResult.memberAccessDeprecationInfo) {
|
3630
|
+
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3631
|
+
}
|
3626
3632
|
}
|
3627
3633
|
break;
|
3628
3634
|
}
|
@@ -3701,7 +3707,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3701
3707
|
}
|
3702
3708
|
if ((0, typeUtils_1.isNoneInstance)(subtype) && noneType && (0, types_1.isClassInstance)(noneType)) {
|
3703
3709
|
const typeResult = getTypeOfBoundMember(node.memberName, noneType, memberName, usage, diag);
|
3704
|
-
if (typeResult) {
|
3710
|
+
if (typeResult && !typeResult.typeErrors) {
|
3705
3711
|
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType));
|
3706
3712
|
if (typeResult.isIncomplete) {
|
3707
3713
|
isIncomplete = true;
|
@@ -3766,6 +3772,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3766
3772
|
if (usage.setExpectedTypeDiag) {
|
3767
3773
|
diag = usage.setExpectedTypeDiag;
|
3768
3774
|
}
|
3775
|
+
// If the class is a TypedDict, and there's a key with the same name,
|
3776
|
+
// suggest that they user want to use ["key"] name instead.
|
3777
|
+
if ((0, types_1.isClass)(baseType) && baseType.details.typedDictEntries) {
|
3778
|
+
const tdKey = baseType.details.typedDictEntries.knownItems.get(memberName);
|
3779
|
+
if (tdKey) {
|
3780
|
+
const subDiag = new diagnostic_1.DiagnosticAddendum();
|
3781
|
+
subDiag.addMessage(localize_1.LocAddendum.typedDictKeyAccess().format({ name: memberName }));
|
3782
|
+
diag.addAddendum(subDiag);
|
3783
|
+
}
|
3784
|
+
}
|
3769
3785
|
const rule = isFunctionRule
|
3770
3786
|
? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
|
3771
3787
|
: diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
|
@@ -3837,7 +3853,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3837
3853
|
// this is normally considered a type violation. But it is allowed
|
3838
3854
|
// if the class variable is a descriptor object. In this case, we will
|
3839
3855
|
// clear the flag that causes an error to be generated.
|
3840
|
-
if (usage.method === 'set' &&
|
3856
|
+
if (usage.method === 'set' &&
|
3857
|
+
(0, symbolUtils_1.isEffectivelyClassVar)(memberInfo.symbol, types_1.ClassType.isDataClass(containingClassType)) &&
|
3858
|
+
isAccessedThroughObject) {
|
3841
3859
|
const selfClass = (selfType !== null && selfType !== void 0 ? selfType : memberName === '__new__') ? undefined : classType;
|
3842
3860
|
const typeResult = getTypeOfMemberInternal(errorNode, memberInfo, selfClass, flags);
|
3843
3861
|
if (typeResult) {
|
@@ -3937,7 +3955,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3937
3955
|
}
|
3938
3956
|
// Check for an attempt to overwrite or delete a ClassVar member from an instance.
|
3939
3957
|
if (!isDescriptorApplied &&
|
3940
|
-
|
3958
|
+
memberInfo &&
|
3959
|
+
(0, symbolUtils_1.isEffectivelyClassVar)(memberInfo.symbol, types_1.ClassType.isDataClass(classType)) &&
|
3941
3960
|
(flags & 128 /* MemberAccessFlags.DisallowClassVarWrites */) !== 0) {
|
3942
3961
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberSetClassVar().format({ name: memberName }));
|
3943
3962
|
isDescriptorError = true;
|
@@ -4015,7 +4034,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4015
4034
|
}
|
4016
4035
|
const methodTypeResult = getTypeOfBoundMember(errorNode, concreteMemberType, accessMethodName,
|
4017
4036
|
/* usage */ undefined, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
|
4018
|
-
if (!methodTypeResult) {
|
4037
|
+
if (!methodTypeResult || methodTypeResult.typeErrors) {
|
4019
4038
|
// Provide special error messages for properties.
|
4020
4039
|
if (types_1.ClassType.isPropertyClass(concreteMemberType)) {
|
4021
4040
|
if (usage.method !== 'get') {
|
@@ -6615,7 +6634,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6615
6634
|
// are more complicated and depend on whether the method is defined in a stub file.
|
6616
6635
|
function getAbstractSymbolInfo(classType, symbolName) {
|
6617
6636
|
const isProtocolClass = types_1.ClassType.isProtocolClass(classType);
|
6618
|
-
const symbol =
|
6637
|
+
const symbol = types_1.ClassType.getSymbolTable(classType).get(symbolName);
|
6619
6638
|
if (!symbol) {
|
6620
6639
|
return undefined;
|
6621
6640
|
}
|
@@ -6792,7 +6811,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6792
6811
|
const result = {
|
6793
6812
|
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ true),
|
6794
6813
|
};
|
6795
|
-
const initTypeResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, errorNode, types_1.ClassType.cloneAsInstance(expandedCallType),
|
6814
|
+
const initTypeResult = (0, constructors_1.getBoundInitMethod)(evaluatorInterface, errorNode, types_1.ClassType.cloneAsInstance(expandedCallType),
|
6815
|
+
/* diag */ undefined, 0 /* MemberAccessFlags.Default */);
|
6796
6816
|
if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
|
6797
6817
|
validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
|
6798
6818
|
/* typeVarContext */ undefined, skipUnknownArgCheck,
|
@@ -6895,15 +6915,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6895
6915
|
}
|
6896
6916
|
function validateCallForClassInstance(errorNode, argList, expandedCallType, unexpandedCallType, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount) {
|
6897
6917
|
var _a;
|
6918
|
+
const callDiag = new diagnostic_1.DiagnosticAddendum();
|
6898
6919
|
const callMethodResult = getTypeOfBoundMember(errorNode, expandedCallType, '__call__',
|
6899
|
-
/* usage */ undefined,
|
6900
|
-
/* diag */ undefined, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */,
|
6920
|
+
/* usage */ undefined, callDiag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */,
|
6901
6921
|
/* selfType */ undefined, recursionCount);
|
6902
6922
|
const callMethodType = callMethodResult === null || callMethodResult === void 0 ? void 0 : callMethodResult.type;
|
6903
|
-
if (!callMethodType) {
|
6923
|
+
if (!callMethodType || callMethodResult.typeErrors) {
|
6904
6924
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.objectNotCallable().format({
|
6905
6925
|
type: printType(expandedCallType),
|
6906
|
-
}), errorNode);
|
6926
|
+
}) + callDiag.getString(), errorNode);
|
6907
6927
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6908
6928
|
}
|
6909
6929
|
const callResult = validateCallArguments(errorNode, argList, { type: callMethodType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
@@ -9103,7 +9123,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9103
9123
|
hasDeclaredType: true,
|
9104
9124
|
});
|
9105
9125
|
initType.details.declaredReturnType = getNoneType();
|
9106
|
-
|
9126
|
+
types_1.ClassType.getSymbolTable(classType).set('__init__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, initType));
|
9107
9127
|
// Synthesize a trivial __new__ method.
|
9108
9128
|
const newType = types_1.FunctionType.createSynthesizedInstance('__new__', 1 /* FunctionTypeFlags.ConstructorMethod */);
|
9109
9129
|
types_1.FunctionType.addParameter(newType, {
|
@@ -9114,7 +9134,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9114
9134
|
});
|
9115
9135
|
types_1.FunctionType.addDefaultParameters(newType);
|
9116
9136
|
newType.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
|
9117
|
-
|
9137
|
+
newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
|
9138
|
+
types_1.ClassType.getSymbolTable(classType).set('__new__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, newType));
|
9118
9139
|
}
|
9119
9140
|
return classType;
|
9120
9141
|
}
|
@@ -9420,7 +9441,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9420
9441
|
let isIncomplete = false;
|
9421
9442
|
// Infer the key and value types if possible.
|
9422
9443
|
node.entries.forEach((entryNode, index) => {
|
9423
|
-
var _a;
|
9444
|
+
var _a, _b, _c, _d;
|
9424
9445
|
let addUnknown = true;
|
9425
9446
|
if (entryNode.nodeType === 17 /* ParseNodeType.DictionaryKeyEntry */) {
|
9426
9447
|
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
|
@@ -9467,6 +9488,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9467
9488
|
isIncomplete = true;
|
9468
9489
|
}
|
9469
9490
|
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
9491
|
+
// If an existing key has the same literal type, delete the previous
|
9492
|
+
// key since we're overwriting it here.
|
9493
|
+
if ((0, types_1.isClass)(keyType) && (0, typeUtils_1.isLiteralType)(keyType)) {
|
9494
|
+
const existingIndex = keyTypes.findIndex((kt) => (0, types_1.isTypeSame)(keyType, kt.type));
|
9495
|
+
if (existingIndex >= 0) {
|
9496
|
+
keyTypes.splice(existingIndex, 1);
|
9497
|
+
valueTypes.splice(existingIndex, 1);
|
9498
|
+
}
|
9499
|
+
}
|
9470
9500
|
keyTypes.push({ node: entryNode.keyExpression, type: keyType });
|
9471
9501
|
valueTypes.push({ node: entryNode.valueExpression, type: valueType });
|
9472
9502
|
}
|
@@ -9504,10 +9534,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9504
9534
|
/* allowNarrowed */ true);
|
9505
9535
|
tdEntries.knownItems.forEach((entry, name) => {
|
9506
9536
|
if (entry.isRequired || entry.isProvided) {
|
9507
|
-
keyTypes.push({
|
9537
|
+
keyTypes.push({
|
9538
|
+
node: entryNode,
|
9539
|
+
type: types_1.ClassType.cloneWithLiteral(strObject, name),
|
9540
|
+
});
|
9508
9541
|
valueTypes.push({ node: entryNode, type: entry.valueType });
|
9509
9542
|
}
|
9510
9543
|
});
|
9544
|
+
if (!expectedTypedDictEntries) {
|
9545
|
+
keyTypes.push({ node: entryNode, type: types_1.ClassType.cloneAsInstance(strObject) });
|
9546
|
+
valueTypes.push({
|
9547
|
+
node: entryNode,
|
9548
|
+
type: (_c = (_b = (_a = tdEntries.extraItems) === null || _a === void 0 ? void 0 : _a.valueType) !== null && _b !== void 0 ? _b : objectType) !== null && _c !== void 0 ? _c : types_1.UnknownType.create(),
|
9549
|
+
});
|
9550
|
+
}
|
9511
9551
|
addUnknown = false;
|
9512
9552
|
}
|
9513
9553
|
}
|
@@ -9541,7 +9581,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9541
9581
|
}
|
9542
9582
|
// The result should be a tuple.
|
9543
9583
|
if ((0, types_1.isClassInstance)(dictEntryType) && (0, typeUtils_1.isTupleClass)(dictEntryType)) {
|
9544
|
-
const typeArgs = (
|
9584
|
+
const typeArgs = (_d = dictEntryType.tupleTypeArguments) === null || _d === void 0 ? void 0 : _d.map((t) => t.type);
|
9545
9585
|
if (typeArgs && typeArgs.length === 2) {
|
9546
9586
|
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
9547
9587
|
keyTypes.push({ node: entryNode, type: typeArgs[0] });
|
@@ -9675,7 +9715,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9675
9715
|
return undefined;
|
9676
9716
|
}
|
9677
9717
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(expectedClassType, typeVarContext);
|
9678
|
-
if (!specializedListOrSet.typeArguments
|
9718
|
+
if (!specializedListOrSet.typeArguments) {
|
9679
9719
|
return undefined;
|
9680
9720
|
}
|
9681
9721
|
return specializedListOrSet.typeArguments[0];
|
@@ -10025,7 +10065,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10025
10065
|
if (ParseTreeUtils.containsAwaitNode(node.expression)) {
|
10026
10066
|
isAsync = true;
|
10027
10067
|
}
|
10028
|
-
const
|
10068
|
+
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
10069
|
+
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
|
10029
10070
|
const elementTypeResult = getElementTypeFromListComprehension(node, expectedEntryType);
|
10030
10071
|
if (elementTypeResult.isIncomplete) {
|
10031
10072
|
isIncomplete = true;
|
@@ -10033,8 +10074,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10033
10074
|
if (elementTypeResult.typeErrors) {
|
10034
10075
|
typeErrors = true;
|
10035
10076
|
}
|
10036
|
-
|
10037
|
-
|
10077
|
+
let elementType = elementTypeResult.type;
|
10078
|
+
if (!expectedEntryType || !(0, typeUtils_1.containsLiteralType)(expectedEntryType)) {
|
10079
|
+
elementType = stripLiteralValue(elementType);
|
10080
|
+
}
|
10038
10081
|
if (builtInIteratorType && (0, types_1.isInstantiableClass)(builtInIteratorType)) {
|
10039
10082
|
type = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(builtInIteratorType, isAsync ? [elementType, getNoneType()] : [elementType, getNoneType(), getNoneType()],
|
10040
10083
|
/* isTypeArgumentExplicit */ true));
|
@@ -11028,6 +11071,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11028
11071
|
if (aliasMapEntry.isSpecialForm) {
|
11029
11072
|
specialClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
|
11030
11073
|
}
|
11074
|
+
// Synthesize a single type parameter with the specified variance if
|
11075
|
+
// specified in the alias map entry.
|
11076
|
+
if (aliasMapEntry.typeParamVariance !== undefined) {
|
11077
|
+
let typeParam = types_1.TypeVarType.createInstance('T');
|
11078
|
+
typeParam = types_1.TypeVarType.cloneForScopeId(typeParam, ParseTreeUtils.getScopeIdForNode(node), assignedName, 0 /* TypeVarScopeType.Class */);
|
11079
|
+
typeParam.details.declaredVariance = aliasMapEntry.typeParamVariance;
|
11080
|
+
specialClassType.details.typeParameters.push(typeParam);
|
11081
|
+
}
|
11031
11082
|
const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
|
11032
11083
|
specialClassType.details.declaration = specialBuiltInClassDeclaration;
|
11033
11084
|
if (fileInfo.isTypingExtensionsStubFile) {
|
@@ -11098,7 +11149,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11098
11149
|
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11099
11150
|
['TypeAlias', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11100
11151
|
['Concatenate', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11101
|
-
[
|
11152
|
+
[
|
11153
|
+
'TypeGuard',
|
11154
|
+
{ alias: '', module: 'builtins', isSpecialForm: true, typeParamVariance: 3 /* Variance.Covariant */ },
|
11155
|
+
],
|
11102
11156
|
['Unpack', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11103
11157
|
['Required', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11104
11158
|
['NotRequired', { alias: '', module: 'builtins', isSpecialForm: true }],
|
@@ -11107,7 +11161,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11107
11161
|
['Never', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11108
11162
|
['LiteralString', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11109
11163
|
['ReadOnly', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11110
|
-
['TypeIs', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11164
|
+
['TypeIs', { alias: '', module: 'builtins', isSpecialForm: true, typeParamVariance: 2 /* Variance.Invariant */ }],
|
11111
11165
|
]);
|
11112
11166
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11113
11167
|
if (aliasMapEntry) {
|
@@ -11485,6 +11539,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11485
11539
|
// all of the type parameters in the specified order.
|
11486
11540
|
let genericTypeParameters;
|
11487
11541
|
let protocolTypeParameters;
|
11542
|
+
let isNamedTupleSubclass = false;
|
11488
11543
|
const initSubclassArgs = [];
|
11489
11544
|
let metaclassNode;
|
11490
11545
|
let exprFlags = 128 /* EvaluatorFlags.ExpectingInstantiableType */ |
|
@@ -11564,6 +11619,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11564
11619
|
// newer), it's considered a (read-only) dataclass.
|
11565
11620
|
if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
|
11566
11621
|
if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
|
11622
|
+
isNamedTupleSubclass = true;
|
11567
11623
|
classType.details.flags |=
|
11568
11624
|
4 /* ClassTypeFlags.DataClass */ |
|
11569
11625
|
32 /* ClassTypeFlags.SkipSynthesizedDataClassEq */ |
|
@@ -11922,46 +11978,62 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11922
11978
|
// See if there's already a non-synthesized __init__ method.
|
11923
11979
|
// We shouldn't override it.
|
11924
11980
|
if (!skipSynthesizedInit) {
|
11925
|
-
const initSymbol =
|
11926
|
-
if (initSymbol) {
|
11981
|
+
const initSymbol = classType.details.fields.get('__init__');
|
11982
|
+
if (initSymbol && initSymbol.isClassMember()) {
|
11927
11983
|
hasExistingInitMethod = true;
|
11928
11984
|
}
|
11929
11985
|
}
|
11930
11986
|
let skipSynthesizeHash = false;
|
11931
|
-
const hashSymbol =
|
11987
|
+
const hashSymbol = classType.details.fields.get('__hash__');
|
11932
11988
|
// If there is a hash symbol defined in the class (i.e. one that we didn't
|
11933
11989
|
// synthesize above), then we shouldn't synthesize a new one for the dataclass.
|
11934
|
-
if (hashSymbol && !hashSymbol.
|
11990
|
+
if (hashSymbol && hashSymbol.isClassMember() && !hashSymbol.getSynthesizedType()) {
|
11935
11991
|
skipSynthesizeHash = true;
|
11936
11992
|
}
|
11937
|
-
(0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
11993
|
+
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
11994
|
+
// If this is a NamedTuple subclass, immediately synthesize dataclass methods
|
11995
|
+
// because we also need to update the MRO classes in this case. For regular
|
11996
|
+
// dataclasses, we'll defer the method synthesis to avoid circular dependencies.
|
11997
|
+
if (isNamedTupleSubclass) {
|
11998
|
+
synthesizeMethods();
|
11999
|
+
}
|
12000
|
+
else {
|
12001
|
+
classType.details.synthesizeMethodsDeferred = () => {
|
12002
|
+
delete classType.details.synthesizeMethodsDeferred;
|
12003
|
+
synthesizeMethods();
|
12004
|
+
};
|
12005
|
+
}
|
11938
12006
|
}
|
11939
12007
|
// Build a complete list of all slots names defined by the class hierarchy.
|
11940
12008
|
// This needs to be done after dataclass processing.
|
11941
|
-
|
11942
|
-
|
11943
|
-
|
11944
|
-
|
11945
|
-
|
11946
|
-
|
11947
|
-
|
11948
|
-
!types_1.ClassType.isBuiltIn(baseClass, '
|
11949
|
-
|
11950
|
-
|
11951
|
-
|
11952
|
-
|
11953
|
-
|
12009
|
+
classType.details.calculateInheritedSlotsNamesDeferred = () => {
|
12010
|
+
delete classType.details.calculateInheritedSlotsNamesDeferred;
|
12011
|
+
if (classType.details.localSlotsNames) {
|
12012
|
+
let isLimitedToSlots = true;
|
12013
|
+
const extendedSlotsNames = Array.from(classType.details.localSlotsNames);
|
12014
|
+
classType.details.baseClasses.forEach((baseClass) => {
|
12015
|
+
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
12016
|
+
if (!types_1.ClassType.isBuiltIn(baseClass, 'object') &&
|
12017
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'type') &&
|
12018
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'Generic')) {
|
12019
|
+
const inheritedSlotsNames = types_1.ClassType.getInheritedSlotsNames(baseClass);
|
12020
|
+
if (inheritedSlotsNames) {
|
12021
|
+
(0, collectionUtils_1.appendArray)(extendedSlotsNames, inheritedSlotsNames);
|
12022
|
+
}
|
12023
|
+
else {
|
12024
|
+
isLimitedToSlots = false;
|
12025
|
+
}
|
11954
12026
|
}
|
11955
12027
|
}
|
12028
|
+
else {
|
12029
|
+
isLimitedToSlots = false;
|
12030
|
+
}
|
12031
|
+
});
|
12032
|
+
if (isLimitedToSlots) {
|
12033
|
+
classType.details.inheritedSlotsNamesCached = extendedSlotsNames;
|
11956
12034
|
}
|
11957
|
-
else {
|
11958
|
-
isLimitedToSlots = false;
|
11959
|
-
}
|
11960
|
-
});
|
11961
|
-
if (isLimitedToSlots) {
|
11962
|
-
classType.details.inheritedSlotsNames = extendedSlotsNames;
|
11963
12035
|
}
|
11964
|
-
}
|
12036
|
+
};
|
11965
12037
|
// Update the undecorated class type.
|
11966
12038
|
writeTypeCache(node.name, { type: classType }, 0 /* EvaluatorFlags.None */);
|
11967
12039
|
// Update the decorated class type.
|
@@ -12526,6 +12598,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12526
12598
|
else {
|
12527
12599
|
annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
|
12528
12600
|
}
|
12601
|
+
if (annotatedType) {
|
12602
|
+
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
|
12603
|
+
}
|
12529
12604
|
if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
|
12530
12605
|
addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
|
12531
12606
|
name1: annotatedType.details.name,
|
@@ -12631,7 +12706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12631
12706
|
};
|
12632
12707
|
types_1.FunctionType.addParameter(functionType, functionParam);
|
12633
12708
|
if (functionParam.hasDeclaredType) {
|
12634
|
-
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type));
|
12709
|
+
(0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
|
12635
12710
|
}
|
12636
12711
|
if (param.name) {
|
12637
12712
|
const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
|
@@ -12812,7 +12887,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12812
12887
|
// of the child class.
|
12813
12888
|
if ((0, typeUtils_1.requiresSpecialization)(inferredParamType) && (0, types_1.isClass)(baseClassMemberInfo.classType)) {
|
12814
12889
|
const typeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(baseClassMemberInfo.classType);
|
12815
|
-
|
12890
|
+
// Add the scope of the method to handle any function-scoped TypeVars.
|
12891
|
+
typeVarContext.addSolveForScope(ParseTreeUtils.getScopeIdForNode(baseClassMethodNode));
|
12892
|
+
// Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
|
12893
|
+
inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, typeVarContext, {
|
12894
|
+
unknownIfNotFound: true,
|
12895
|
+
});
|
12816
12896
|
}
|
12817
12897
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(functionNode);
|
12818
12898
|
if (fileInfo.isInPyTypedPackage && !fileInfo.isStubFile) {
|
@@ -15472,7 +15552,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15472
15552
|
// If the symbol is explicitly marked as a ClassVar, consider only the
|
15473
15553
|
// declarations that assign to it from within the class body, not through
|
15474
15554
|
// a member access expression.
|
15475
|
-
if (
|
15555
|
+
if ((0, symbolUtils_1.isEffectivelyClassVar)(symbol, /* isDataclass */ false) &&
|
15556
|
+
decl.type === 1 /* DeclarationType.Variable */ &&
|
15557
|
+
decl.isDefinedByMemberAccess) {
|
15476
15558
|
return;
|
15477
15559
|
}
|
15478
15560
|
if (usageNode !== undefined) {
|
@@ -16123,7 +16205,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16123
16205
|
// Stash the current class type so any references to it are treated
|
16124
16206
|
// as though all TypeParameters are invariant.
|
16125
16207
|
assignClassToSelfStack.push({ class: destType, assumedVariance });
|
16126
|
-
|
16208
|
+
types_1.ClassType.getSymbolTable(destType).forEach((symbol, name) => {
|
16127
16209
|
if (!isAssignable || symbol.isIgnoredForProtocolMatch()) {
|
16128
16210
|
return;
|
16129
16211
|
}
|
@@ -16960,7 +17042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16960
17042
|
}
|
16961
17043
|
}
|
16962
17044
|
else if (types_1.ClassType.isBuiltIn(destType, ['TypeGuard', 'TypeIs'])) {
|
16963
|
-
//
|
17045
|
+
// Allow the source to be a "bool".
|
16964
17046
|
if ((originalFlags & 128 /* AssignTypeFlags.AllowBoolTypeGuard */) !== 0) {
|
16965
17047
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
|
16966
17048
|
return true;
|
@@ -17572,11 +17654,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17572
17654
|
// a normal function wouldn't be compatible with.
|
17573
17655
|
for (const mroClass of objType.details.mro) {
|
17574
17656
|
if ((0, types_1.isClass)(mroClass) && types_1.ClassType.isProtocolClass(mroClass)) {
|
17575
|
-
for (const field of
|
17657
|
+
for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
|
17576
17658
|
if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
|
17577
17659
|
let fieldIsPartOfFunction = false;
|
17578
17660
|
if (functionObj && (0, types_1.isClass)(functionObj)) {
|
17579
|
-
if (
|
17661
|
+
if (types_1.ClassType.getSymbolTable(functionObj).has(field[0])) {
|
17580
17662
|
fieldIsPartOfFunction = true;
|
17581
17663
|
}
|
17582
17664
|
}
|
@@ -18791,7 +18873,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18791
18873
|
// See if this class is introducing a new abstract symbol that has not been
|
18792
18874
|
// introduced previously or if it is overriding an abstract symbol with
|
18793
18875
|
// a non-abstract one.
|
18794
|
-
|
18876
|
+
types_1.ClassType.getSymbolTable(mroClass).forEach((symbol, symbolName) => {
|
18795
18877
|
const abstractSymbolInfo = getAbstractSymbolInfo(mroClass, symbolName);
|
18796
18878
|
if (abstractSymbolInfo) {
|
18797
18879
|
symbolTable.set(symbolName, abstractSymbolInfo);
|
@@ -19040,11 +19122,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
19040
19122
|
if (node.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
19041
19123
|
valueOffset += node.strings[0].token.prefixLength + node.strings[0].token.quoteMarkLength;
|
19042
19124
|
}
|
19125
|
+
// Construct a temporary dummy string with the text value at the appropriate
|
19126
|
+
// offset so as to mimic the original file. This will keep all of the token
|
19127
|
+
// and diagnostic offsets correct.
|
19128
|
+
const dummyFileContents = ' '.repeat(valueOffset) + textValue;
|
19043
19129
|
const parseOptions = new parser_1.ParseOptions();
|
19044
19130
|
parseOptions.isStubFile = fileInfo.isStubFile;
|
19045
19131
|
parseOptions.pythonVersion = fileInfo.executionEnvironment.pythonVersion;
|
19046
19132
|
parseOptions.reportErrorsForParsedStringContents = true;
|
19047
|
-
const parseResults = parser.parseTextExpression(
|
19133
|
+
const parseResults = parser.parseTextExpression(dummyFileContents, valueOffset, textValue.length, parseOptions,
|
19048
19134
|
/* parseTextMode */ undefined,
|
19049
19135
|
/* initialParenDepth */ undefined, fileInfo.typingSymbolAliases);
|
19050
19136
|
if (parseResults.parseTree && parseResults.parseTree.nodeType !== 62 /* ParseNodeType.FunctionAnnotation */) {
|