@zzzen/pyright-internal 1.2.0-dev.20240331 → 1.2.0-dev.20240414
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 +24 -7
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +11 -0
- package/dist/analyzer/cacheManager.js +59 -2
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.d.ts +2 -2
- package/dist/analyzer/checker.js +29 -20
- 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 +44 -11
- 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 +2 -2
- package/dist/analyzer/constructors.js +162 -109
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +17 -7
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/enums.js +7 -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 +1 -1
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +6 -6
- package/dist/analyzer/importStatementUtils.js +43 -43
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +1 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +6 -6
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +8 -5
- package/dist/analyzer/parseTreeUtils.js +36 -14
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +1 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +4 -3
- package/dist/analyzer/program.js +21 -12
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +12 -12
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +10 -10
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pyTypedUtils.d.ts +4 -0
- package/dist/analyzer/pyTypedUtils.js +17 -3
- package/dist/analyzer/pyTypedUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -2
- package/dist/analyzer/service.js +7 -4
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +5 -3
- package/dist/analyzer/sourceFile.js +108 -71
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +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 +2 -1
- package/dist/analyzer/symbolUtils.js +13 -3
- package/dist/analyzer/symbolUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +254 -119
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -1
- package/dist/analyzer/typeGuards.js +107 -59
- 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 +1 -1
- package/dist/analyzer/typeUtils.js +33 -33
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +1 -1
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +30 -21
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +7 -3
- package/dist/analyzer/types.js +48 -8
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.d.ts +1 -0
- package/dist/backgroundAnalysis.js +5 -1
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +2 -1
- package/dist/backgroundAnalysisBase.js +8 -1
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +6 -5
- package/dist/backgroundThreadBase.js +9 -5
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +4 -4
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/extensibility.d.ts +3 -2
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +2 -0
- package/dist/common/serviceProviderExtensions.js +4 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/textEditTracker.d.ts +5 -5
- package/dist/common/textEditTracker.js +33 -33
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/common/workspaceEditUtils.js +2 -2
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +4 -4
- package/dist/languageServerBase.js +1 -1
- package/dist/languageServerBase.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 +2 -2
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -4
- package/dist/languageService/completionProvider.js +15 -37
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +1 -1
- 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 +1 -1
- 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.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 +2 -2
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +2 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +2 -2
- package/dist/languageService/symbolIndexer.js +2 -2
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/languageService/tooltipUtils.d.ts +1 -1
- package/dist/languageService/tooltipUtils.js +4 -4
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +7 -0
- package/dist/localization/localize.js +5 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -0
- package/dist/localization/package.nls.de.json +2 -1
- package/dist/localization/package.nls.en-us.json +28 -23
- package/dist/localization/package.nls.es.json +5 -4
- package/dist/localization/package.nls.fr.json +5 -4
- package/dist/localization/package.nls.it.json +2 -1
- package/dist/localization/package.nls.ja.json +1 -0
- package/dist/localization/package.nls.ko.json +4 -3
- package/dist/localization/package.nls.pl.json +4 -3
- 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 +2 -1
- package/dist/localization/package.nls.tr.json +3 -2
- package/dist/localization/package.nls.zh-cn.json +2 -1
- 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 +10 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -0
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +1 -0
- package/dist/parser/tokenizerTypes.js +1 -0
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/server.d.ts +3 -3
- package/dist/server.js +3 -3
- 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 +7 -7
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +5 -5
- package/dist/tests/harness/fourslash/testState.js +8 -7
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.d.ts +2 -2
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js +5 -5
- package/dist/tests/harness/fourslash/workspaceEditTestUtils.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +4 -4
- 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/lsp/languageServer.js +1 -1
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.d.ts +1 -1
- package/dist/tests/parser.test.js +14 -14
- package/dist/tests/parser.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/testStateUtils.js +5 -3
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/testUtils.d.ts +4 -8
- package/dist/tests/testUtils.js +4 -7
- 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/tokenizer.test.js +4 -4
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +6 -2
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +21 -11
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/package.json +2 -2
@@ -890,12 +890,27 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
890
890
|
typeResult = getTypeOfExpression(node.typeAnnotation, updatedFlags);
|
891
891
|
}
|
892
892
|
else if (!node.typeAnnotation && node.strings.length === 1) {
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
893
|
+
const tokenFlags = node.strings[0].token.flags;
|
894
|
+
if (tokenFlags & 32 /* StringTokenFlags.Bytes */) {
|
895
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationBytesString(), node);
|
896
|
+
typeResult = { type: types_1.UnknownType.create() };
|
897
|
+
}
|
898
|
+
else if (tokenFlags & 8 /* StringTokenFlags.Raw */) {
|
899
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationRawString(), node);
|
900
|
+
typeResult = { type: types_1.UnknownType.create() };
|
901
|
+
}
|
902
|
+
else if (tokenFlags & 64 /* StringTokenFlags.Format */) {
|
903
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.annotationFormatString(), node);
|
904
|
+
typeResult = { type: types_1.UnknownType.create() };
|
905
|
+
}
|
906
|
+
else {
|
907
|
+
// We didn't know at parse time that this string node was going
|
908
|
+
// to be evaluated as a forward-referenced type. We need
|
909
|
+
// to re-invoke the parser at this stage.
|
910
|
+
const expr = parseStringAsTypeAnnotation(node);
|
911
|
+
if (expr) {
|
912
|
+
typeResult = getTypeOfExpression(expr, updatedFlags);
|
913
|
+
}
|
899
914
|
}
|
900
915
|
}
|
901
916
|
if (!typeResult) {
|
@@ -1430,6 +1445,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1430
1445
|
classType: memberInfo.classType,
|
1431
1446
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1432
1447
|
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1448
|
+
narrowedTypeForSet: memberInfo.narrowedTypeForSet,
|
1433
1449
|
memberAccessDeprecationInfo: memberInfo.memberAccessDeprecationInfo,
|
1434
1450
|
typeErrors: memberInfo.isDescriptorError,
|
1435
1451
|
};
|
@@ -2258,6 +2274,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2258
2274
|
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
|
2259
2275
|
}
|
2260
2276
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2277
|
+
var _a;
|
2261
2278
|
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
|
2262
2279
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2263
2280
|
// Handle member accesses (e.g. self.x or cls.y).
|
@@ -2282,7 +2299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2282
2299
|
// Assignments to instance or class variables through "self" or "cls" is not
|
2283
2300
|
// allowed for protocol classes unless it is also declared within the class.
|
2284
2301
|
if (types_1.ClassType.isProtocolClass(classTypeResults.classType)) {
|
2285
|
-
const memberSymbol = classTypeResults.classType.
|
2302
|
+
const memberSymbol = types_1.ClassType.getSymbolTable(classTypeResults.classType).get(target.memberName.value);
|
2286
2303
|
if (memberSymbol) {
|
2287
2304
|
const classLevelDecls = memberSymbol.getDeclarations().filter((decl) => {
|
2288
2305
|
return !ParseTreeUtils.getEnclosingFunction(decl.node);
|
@@ -2305,7 +2322,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2305
2322
|
setAsymmetricDescriptorAssignment(target);
|
2306
2323
|
}
|
2307
2324
|
const resultToCache = {
|
2308
|
-
type,
|
2325
|
+
type: (_a = setTypeResult.narrowedTypeForSet) !== null && _a !== void 0 ? _a : type,
|
2309
2326
|
isIncomplete: isTypeIncomplete,
|
2310
2327
|
memberAccessDeprecationInfo: setTypeResult.memberAccessDeprecationInfo,
|
2311
2328
|
};
|
@@ -2323,7 +2340,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2323
2340
|
const classTypeInfo = getTypeOfClass(classDef);
|
2324
2341
|
if (classTypeInfo && (0, types_1.isInstantiableClass)(classTypeInfo.classType)) {
|
2325
2342
|
let memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, isInstanceMember ? 0 /* MemberAccessFlags.Default */ : 16 /* MemberAccessFlags.SkipInstanceMembers */);
|
2326
|
-
const memberFields = classTypeInfo.classType
|
2343
|
+
const memberFields = types_1.ClassType.getSymbolTable(classTypeInfo.classType);
|
2327
2344
|
if (memberInfo) {
|
2328
2345
|
// Are we accessing an existing member on this class, or is
|
2329
2346
|
// it a member on a parent class?
|
@@ -2331,12 +2348,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2331
2348
|
const isThisClass = memberClass && types_1.ClassType.isSameGenericClass(classTypeInfo.classType, memberClass);
|
2332
2349
|
// Check for an attempt to write to an instance variable that is
|
2333
2350
|
// not defined by __slots__.
|
2334
|
-
if (isThisClass && isInstanceMember) {
|
2335
|
-
|
2351
|
+
if (isThisClass && isInstanceMember && memberClass) {
|
2352
|
+
const inheritedSlotsNames = types_1.ClassType.getInheritedSlotsNames(memberClass);
|
2353
|
+
if (inheritedSlotsNames && memberClass.details.localSlotsNames) {
|
2336
2354
|
// Skip this check if the local slots is specified but empty because this pattern
|
2337
2355
|
// is used in a legitimate manner for mix-in classes.
|
2338
2356
|
if (memberClass.details.localSlotsNames.length > 0 &&
|
2339
|
-
!
|
2357
|
+
!inheritedSlotsNames.some((name) => name === memberName)) {
|
2340
2358
|
// Determine whether the assignment corresponds to a descriptor
|
2341
2359
|
// that was assigned as a class variable. If so, then slots will not
|
2342
2360
|
// apply in this case.
|
@@ -2932,7 +2950,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2932
2950
|
if (typeParamSymbol) {
|
2933
2951
|
symbol = typeParamSymbol;
|
2934
2952
|
(0, debug_1.assert)(symbol.getDeclarations().length === 1);
|
2935
|
-
const decl = (0, symbolUtils_1.
|
2953
|
+
const decl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(symbol);
|
2936
2954
|
(0, debug_1.assert)((decl === null || decl === void 0 ? void 0 : decl.type) === 3 /* DeclarationType.TypeParameter */);
|
2937
2955
|
type = getTypeOfTypeParameter(decl.node);
|
2938
2956
|
setSymbolAccessed(fileInfo, symbol, node);
|
@@ -3532,6 +3550,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3532
3550
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
3533
3551
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
3534
3552
|
let type;
|
3553
|
+
let narrowedTypeForSet;
|
3554
|
+
let typeErrors = false;
|
3535
3555
|
let isIncomplete = !!baseTypeResult.isIncomplete;
|
3536
3556
|
let isAsymmetricAccessor;
|
3537
3557
|
const isRequired = false;
|
@@ -3616,15 +3636,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3616
3636
|
typeResult = getTypeOfBoundMember(node.memberName, baseType, memberName, usage, diag,
|
3617
3637
|
/* memberAccessFlags */ undefined, baseTypeResult.bindToSelfType);
|
3618
3638
|
}
|
3619
|
-
if (typeResult
|
3620
|
-
|
3621
|
-
|
3622
|
-
|
3623
|
-
|
3639
|
+
if (typeResult) {
|
3640
|
+
if (!typeResult.typeErrors) {
|
3641
|
+
type = (0, typeUtils_1.addConditionToType)(typeResult.type, (0, typeUtils_1.getTypeCondition)(baseType),
|
3642
|
+
/* skipSelfCondition */ true);
|
3643
|
+
}
|
3644
|
+
else {
|
3645
|
+
typeErrors = true;
|
3624
3646
|
}
|
3625
3647
|
if (typeResult.isAsymmetricAccessor) {
|
3626
3648
|
isAsymmetricAccessor = true;
|
3627
3649
|
}
|
3650
|
+
if (typeResult.isIncomplete) {
|
3651
|
+
isIncomplete = true;
|
3652
|
+
}
|
3653
|
+
if (typeResult.narrowedTypeForSet) {
|
3654
|
+
narrowedTypeForSet = (0, typeUtils_1.addConditionToType)(typeResult.narrowedTypeForSet, (0, typeUtils_1.getTypeCondition)(baseType),
|
3655
|
+
/* skipSelfCondition */ true);
|
3656
|
+
}
|
3628
3657
|
if (typeResult.memberAccessDeprecationInfo) {
|
3629
3658
|
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3630
3659
|
}
|
@@ -3725,9 +3754,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3725
3754
|
if (typeResult.isIncomplete) {
|
3726
3755
|
isIncomplete = true;
|
3727
3756
|
}
|
3728
|
-
if (typeResult
|
3757
|
+
if (typeResult.memberAccessDeprecationInfo) {
|
3729
3758
|
memberAccessDeprecationInfo = typeResult.memberAccessDeprecationInfo;
|
3730
3759
|
}
|
3760
|
+
if (typeResult.typeErrors) {
|
3761
|
+
typeErrors = true;
|
3762
|
+
}
|
3731
3763
|
return typeResult.type;
|
3732
3764
|
});
|
3733
3765
|
break;
|
@@ -3771,6 +3803,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3771
3803
|
if (usage.setExpectedTypeDiag) {
|
3772
3804
|
diag = usage.setExpectedTypeDiag;
|
3773
3805
|
}
|
3806
|
+
// If the class is a TypedDict, and there's a key with the same name,
|
3807
|
+
// suggest that they user want to use ["key"] name instead.
|
3808
|
+
if ((0, types_1.isClass)(baseType) && baseType.details.typedDictEntries) {
|
3809
|
+
const tdKey = baseType.details.typedDictEntries.knownItems.get(memberName);
|
3810
|
+
if (tdKey) {
|
3811
|
+
const subDiag = new diagnostic_1.DiagnosticAddendum();
|
3812
|
+
subDiag.addMessage(localize_1.LocAddendum.typedDictKeyAccess().format({ name: memberName }));
|
3813
|
+
diag.addAddendum(subDiag);
|
3814
|
+
}
|
3815
|
+
}
|
3774
3816
|
const rule = isFunctionRule
|
3775
3817
|
? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
|
3776
3818
|
: diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
|
@@ -3784,7 +3826,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3784
3826
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) === 0) {
|
3785
3827
|
reportUseOfTypeCheckOnly(type, node.memberName);
|
3786
3828
|
}
|
3787
|
-
return {
|
3829
|
+
return {
|
3830
|
+
type,
|
3831
|
+
isIncomplete,
|
3832
|
+
isAsymmetricAccessor,
|
3833
|
+
narrowedTypeForSet,
|
3834
|
+
isRequired,
|
3835
|
+
isNotRequired,
|
3836
|
+
memberAccessDeprecationInfo,
|
3837
|
+
typeErrors,
|
3838
|
+
};
|
3788
3839
|
}
|
3789
3840
|
function getTypeOfClassMemberName(errorNode, classType, memberName, usage, diag, flags, selfType, recursionCount = 0) {
|
3790
3841
|
var _a, _b, _c;
|
@@ -3820,6 +3871,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3820
3871
|
}
|
3821
3872
|
let type;
|
3822
3873
|
let isTypeIncomplete = false;
|
3874
|
+
let narrowedTypeForSet;
|
3823
3875
|
if (memberInfo.symbol.isInitVar()) {
|
3824
3876
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberIsInitVar().format({ name: memberName }));
|
3825
3877
|
return undefined;
|
@@ -3842,7 +3894,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3842
3894
|
// this is normally considered a type violation. But it is allowed
|
3843
3895
|
// if the class variable is a descriptor object. In this case, we will
|
3844
3896
|
// clear the flag that causes an error to be generated.
|
3845
|
-
if (usage.method === 'set' &&
|
3897
|
+
if (usage.method === 'set' &&
|
3898
|
+
(0, symbolUtils_1.isEffectivelyClassVar)(memberInfo.symbol, types_1.ClassType.isDataClass(containingClassType)) &&
|
3899
|
+
isAccessedThroughObject) {
|
3846
3900
|
const selfClass = (selfType !== null && selfType !== void 0 ? selfType : memberName === '__new__') ? undefined : classType;
|
3847
3901
|
const typeResult = getTypeOfMemberInternal(errorNode, memberInfo, selfClass, flags);
|
3848
3902
|
if (typeResult) {
|
@@ -3942,7 +3996,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3942
3996
|
}
|
3943
3997
|
// Check for an attempt to overwrite or delete a ClassVar member from an instance.
|
3944
3998
|
if (!isDescriptorApplied &&
|
3945
|
-
|
3999
|
+
memberInfo &&
|
4000
|
+
(0, symbolUtils_1.isEffectivelyClassVar)(memberInfo.symbol, types_1.ClassType.isDataClass(classType)) &&
|
3946
4001
|
(flags & 128 /* MemberAccessFlags.DisallowClassVarWrites */) !== 0) {
|
3947
4002
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.memberSetClassVar().format({ name: memberName }));
|
3948
4003
|
isDescriptorError = true;
|
@@ -3971,6 +4026,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3971
4026
|
return resultType;
|
3972
4027
|
});
|
3973
4028
|
if (!isDescriptorError && usage.method === 'set' && usage.setType) {
|
4029
|
+
if (errorNode && memberInfo.symbol.hasTypedDeclarations()) {
|
4030
|
+
// This is an assignment to a member with a declared type. Apply
|
4031
|
+
// narrowing logic based on the assigned type. Skip this for
|
4032
|
+
// descriptor-based accesses.
|
4033
|
+
narrowedTypeForSet = isDescriptorApplied
|
4034
|
+
? usage.setType.type
|
4035
|
+
: narrowTypeBasedOnAssignment(errorNode, type, usage.setType.type);
|
4036
|
+
}
|
3974
4037
|
// Verify that the assigned type is compatible.
|
3975
4038
|
if (!assignType(type, usage.setType.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum())) {
|
3976
4039
|
if (!usage.setType.isIncomplete) {
|
@@ -3980,6 +4043,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3980
4043
|
classType: printObjectTypeForClass(classType),
|
3981
4044
|
}));
|
3982
4045
|
}
|
4046
|
+
// Do not narrow the type in this case. Assume the declared type.
|
4047
|
+
narrowedTypeForSet = type;
|
3983
4048
|
isDescriptorError = true;
|
3984
4049
|
}
|
3985
4050
|
if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
|
@@ -4000,6 +4065,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4000
4065
|
isClassVar: memberInfo.isClassVar,
|
4001
4066
|
classType: memberInfo.classType,
|
4002
4067
|
isAsymmetricAccessor,
|
4068
|
+
narrowedTypeForSet,
|
4003
4069
|
memberAccessDeprecationInfo,
|
4004
4070
|
};
|
4005
4071
|
}
|
@@ -6620,7 +6686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6620
6686
|
// are more complicated and depend on whether the method is defined in a stub file.
|
6621
6687
|
function getAbstractSymbolInfo(classType, symbolName) {
|
6622
6688
|
const isProtocolClass = types_1.ClassType.isProtocolClass(classType);
|
6623
|
-
const symbol =
|
6689
|
+
const symbol = types_1.ClassType.getSymbolTable(classType).get(symbolName);
|
6624
6690
|
if (!symbol) {
|
6625
6691
|
return undefined;
|
6626
6692
|
}
|
@@ -6630,7 +6696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6630
6696
|
if (!symbol.isClassMember() && !symbol.isNamedTupleMemberMember()) {
|
6631
6697
|
return undefined;
|
6632
6698
|
}
|
6633
|
-
const lastDecl = (0, symbolUtils_1.
|
6699
|
+
const lastDecl = (0, symbolUtils_1.getLastTypedDeclarationForSymbol)(symbol);
|
6634
6700
|
if (!lastDecl) {
|
6635
6701
|
return undefined;
|
6636
6702
|
}
|
@@ -6996,7 +7062,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6996
7062
|
// validation is left to the caller.
|
6997
7063
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
6998
7064
|
function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
|
6999
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
7065
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
7000
7066
|
const paramDetails = (0, parameterUtils_1.getParameterListDetails)(typeResult.type);
|
7001
7067
|
let argIndex = 0;
|
7002
7068
|
let matchedUnpackedListOfUnknownLength = false;
|
@@ -7043,8 +7109,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7043
7109
|
// function nested within another function that defines the param
|
7044
7110
|
// spec? We need to handle these two cases differently.
|
7045
7111
|
const paramSpecScopeId = varArgListParam.type.scopeId;
|
7046
|
-
if (
|
7047
|
-
paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
|
7112
|
+
if ((_b = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _b === void 0 ? void 0 : _b.some((id) => id === paramSpecScopeId)) {
|
7048
7113
|
paramSpecArgList = [];
|
7049
7114
|
paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
|
7050
7115
|
}
|
@@ -7055,9 +7120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7055
7120
|
}
|
7056
7121
|
else if (typeResult.type.details.paramSpec) {
|
7057
7122
|
const paramSpecScopeId = typeResult.type.details.paramSpec.scopeId;
|
7058
|
-
if (typeResult.type
|
7059
|
-
paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
|
7060
|
-
paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId) {
|
7123
|
+
if ((_c = (0, typeUtils_1.getTypeVarScopeIds)(typeResult.type)) === null || _c === void 0 ? void 0 : _c.some((id) => id === paramSpecScopeId)) {
|
7061
7124
|
hasParamSpecArgsKwargs = true;
|
7062
7125
|
paramSpecArgList = [];
|
7063
7126
|
paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(typeResult.type.details.paramSpec,
|
@@ -7149,7 +7212,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7149
7212
|
? localize_1.LocMessage.argPositionalExpectedOne()
|
7150
7213
|
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7151
7214
|
expected: positionParamLimitIndex,
|
7152
|
-
}), (
|
7215
|
+
}), (_d = argList[argIndex].valueExpression) !== null && _d !== void 0 ? _d : errorNode);
|
7153
7216
|
}
|
7154
7217
|
reportedArgError = true;
|
7155
7218
|
}
|
@@ -7182,7 +7245,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7182
7245
|
? localize_1.LocMessage.argPositionalExpectedOne()
|
7183
7246
|
: localize_1.LocMessage.argPositionalExpectedCount().format({
|
7184
7247
|
expected: positionParamLimitIndex,
|
7185
|
-
}), (
|
7248
|
+
}), (_e = argList[argIndex].valueExpression) !== null && _e !== void 0 ? _e : errorNode);
|
7186
7249
|
}
|
7187
7250
|
reportedArgError = true;
|
7188
7251
|
}
|
@@ -7224,9 +7287,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7224
7287
|
listElementType = undefined;
|
7225
7288
|
}
|
7226
7289
|
else {
|
7227
|
-
listElementType = (
|
7290
|
+
listElementType = (_f = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
7228
7291
|
/* isAsync */ false, errorNode,
|
7229
|
-
/* emitNotIterableError */ false)) === null ||
|
7292
|
+
/* emitNotIterableError */ false)) === null || _f === void 0 ? void 0 : _f.type;
|
7230
7293
|
if (paramDetails.params[paramIndex].param.category !== 1 /* ParameterCategory.ArgsList */) {
|
7231
7294
|
matchedUnpackedListOfUnknownLength = true;
|
7232
7295
|
}
|
@@ -7258,7 +7321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7258
7321
|
paramType,
|
7259
7322
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7260
7323
|
argument: funcArg,
|
7261
|
-
errorNode: (
|
7324
|
+
errorNode: (_g = argList[argIndex].valueExpression) !== null && _g !== void 0 ? _g : errorNode,
|
7262
7325
|
paramName,
|
7263
7326
|
isParamNameSynthesized: paramDetails.params[paramIndex].param.isNameSynthesized,
|
7264
7327
|
mapsToVarArgList: isParamVariadic && remainingArgCount > remainingParamCount,
|
@@ -7562,7 +7625,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7562
7625
|
paramType,
|
7563
7626
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7564
7627
|
argument: argList[argIndex],
|
7565
|
-
errorNode: (
|
7628
|
+
errorNode: (_h = argList[argIndex].valueExpression) !== null && _h !== void 0 ? _h : errorNode,
|
7566
7629
|
paramName: paramNameValue,
|
7567
7630
|
});
|
7568
7631
|
trySetActive(argList[argIndex], paramDetails.params[paramInfoIndex].param);
|
@@ -7578,7 +7641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7578
7641
|
paramType,
|
7579
7642
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
7580
7643
|
argument: argList[argIndex],
|
7581
|
-
errorNode: (
|
7644
|
+
errorNode: (_j = argList[argIndex].valueExpression) !== null && _j !== void 0 ? _j : errorNode,
|
7582
7645
|
paramName: paramNameValue,
|
7583
7646
|
});
|
7584
7647
|
// Remember that this parameter has already received a value.
|
@@ -7628,7 +7691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7628
7691
|
requiresTypeVarMatching: false,
|
7629
7692
|
argument: argList[argIndex],
|
7630
7693
|
argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
|
7631
|
-
errorNode: (
|
7694
|
+
errorNode: (_k = argList[argIndex].valueExpression) !== null && _k !== void 0 ? _k : errorNode,
|
7632
7695
|
});
|
7633
7696
|
}
|
7634
7697
|
}
|
@@ -7940,12 +8003,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7940
8003
|
typeVarContext.addSolveForScope(type.boundTypeVarScopeId);
|
7941
8004
|
}
|
7942
8005
|
}
|
7943
|
-
//
|
7944
|
-
//
|
7945
|
-
// be constructed. Although this isn't part of the official Python spec, other
|
7946
|
-
// type checkers appear to honor it.
|
8006
|
+
// The type annotation for the "self" parameter in an __init__ method to
|
8007
|
+
// can incluence the type being constructed.
|
7947
8008
|
if (type.details.name === '__init__' &&
|
7948
|
-
types_1.FunctionType.isOverloaded(type) &&
|
7949
8009
|
type.strippedFirstParamType &&
|
7950
8010
|
type.boundToType &&
|
7951
8011
|
(0, types_1.isClassInstance)(type.strippedFirstParamType) &&
|
@@ -8112,9 +8172,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8112
8172
|
// If the function is returning a callable, don't eliminate unsolved
|
8113
8173
|
// type vars within a union. There are legit uses for unsolved type vars
|
8114
8174
|
// within a callable.
|
8115
|
-
if ((0, types_1.isFunction)(returnType) ||
|
8116
|
-
(0, types_1.isOverloadedFunction)(returnType) ||
|
8117
|
-
type.details.typeVarScopeId === types_1.WildcardTypeVarScopeId) {
|
8175
|
+
if ((0, types_1.isFunction)(returnType) || (0, types_1.isOverloadedFunction)(returnType)) {
|
8118
8176
|
eliminateUnsolvedInUnions = false;
|
8119
8177
|
}
|
8120
8178
|
// We'll leave TypeVars unsolved if the call is a recursive
|
@@ -8166,7 +8224,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8166
8224
|
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useTypeIsSemantics));
|
8167
8225
|
}
|
8168
8226
|
}
|
8169
|
-
|
8227
|
+
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
8228
|
+
specializedReturnType = adjustCallableReturnType(type, specializedReturnType, liveTypeVarScopes, signatureTracker.getTrackedSignatures());
|
8170
8229
|
if (specializedInitSelfType) {
|
8171
8230
|
specializedInitSelfType = (0, typeUtils_1.applySolvedTypeVars)(specializedInitSelfType, typeVarContext);
|
8172
8231
|
}
|
@@ -8209,23 +8268,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8209
8268
|
return [];
|
8210
8269
|
}
|
8211
8270
|
// If the return type includes a generic Callable type, set the type var
|
8212
|
-
// scope to
|
8213
|
-
//
|
8214
|
-
//
|
8215
|
-
// the future.
|
8271
|
+
// scope to the scope of the function it was originally associated with
|
8272
|
+
// to allow these type vars to be solved. This won't work with overloads
|
8273
|
+
// or unions of callables. It's intended for a specific use case. We may
|
8274
|
+
// need to make this more sophisticated in the future.
|
8216
8275
|
// The trackedSignatures parameter supplies a list of function signatures
|
8217
8276
|
// that were used for the function and the arguments passed to it. This is
|
8218
8277
|
// important because the callable return value may be called again with
|
8219
8278
|
// one of these signatures, so we may need to "uniquify" the type parameters
|
8220
8279
|
// to avoid conflicts.
|
8221
|
-
function adjustCallableReturnType(returnType, trackedSignatures) {
|
8222
|
-
if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
|
8223
|
-
|
8280
|
+
function adjustCallableReturnType(callableType, returnType, liveTypeVarScopes, trackedSignatures) {
|
8281
|
+
if ((0, types_1.isFunction)(returnType) && !returnType.details.name && callableType.details.typeVarScopeId) {
|
8282
|
+
// What type variables are referenced in the callable return type? Do not include any live type variables.
|
8283
|
+
const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType).filter((t) => !liveTypeVarScopes.some((scopeId) => t.scopeId === scopeId));
|
8224
8284
|
// If there are no unsolved type variables, we're done. If there are
|
8225
|
-
// unsolved type
|
8285
|
+
// unsolved type variables, treat them as though they are rescoped
|
8226
8286
|
// to the callable.
|
8227
8287
|
if (typeVarsInReturnType.length > 0) {
|
8228
|
-
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType,
|
8288
|
+
return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, callableType.details.typeVarScopeId, typeVarsInReturnType, trackedSignatures);
|
8229
8289
|
}
|
8230
8290
|
}
|
8231
8291
|
return returnType;
|
@@ -8493,7 +8553,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8493
8553
|
if ((0, types_1.isFunction)(concreteParamType) || (0, types_1.isOverloadedFunction)(concreteParamType)) {
|
8494
8554
|
if ((0, types_1.isInstantiableClass)(argType)) {
|
8495
8555
|
const constructor = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, argType);
|
8496
|
-
if (constructor
|
8556
|
+
if (constructor) {
|
8497
8557
|
return {
|
8498
8558
|
isCompatible,
|
8499
8559
|
argType,
|
@@ -8740,7 +8800,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8740
8800
|
}
|
8741
8801
|
function verifyTypeVarDefaultIsCompatible(typeVar, defaultValueNode) {
|
8742
8802
|
(0, debug_1.assert)(typeVar.details.isDefaultExplicit);
|
8743
|
-
const typeVarContext = new typeVarContext_1.TypeVarContext(
|
8803
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext(typeVar.scopeId);
|
8744
8804
|
const concreteDefaultType = makeTopLevelTypeVarsConcrete((0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext, {
|
8745
8805
|
unknownIfNotFound: true,
|
8746
8806
|
}));
|
@@ -8794,7 +8854,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8794
8854
|
if (paramName === 'default') {
|
8795
8855
|
const expr = argList[i].valueExpression;
|
8796
8856
|
if (expr) {
|
8797
|
-
const defaultType = getTypeVarTupleDefaultType(expr);
|
8857
|
+
const defaultType = getTypeVarTupleDefaultType(expr, /* isPep695Syntax */ false);
|
8798
8858
|
if (defaultType) {
|
8799
8859
|
typeVar.details.defaultType = defaultType;
|
8800
8860
|
typeVar.details.isDefaultExplicit = true;
|
@@ -8817,10 +8877,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8817
8877
|
}
|
8818
8878
|
return typeVar;
|
8819
8879
|
}
|
8820
|
-
function getTypeVarTupleDefaultType(node) {
|
8880
|
+
function getTypeVarTupleDefaultType(node, isPep695Syntax) {
|
8821
8881
|
const argType = getTypeOfExpressionExpectingType(node, {
|
8822
8882
|
allowUnpackedTuple: true,
|
8823
8883
|
allowTypeVarsWithoutScopeId: true,
|
8884
|
+
allowForwardReference: isPep695Syntax,
|
8824
8885
|
}).type;
|
8825
8886
|
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
8826
8887
|
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
@@ -8853,7 +8914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8853
8914
|
if (paramName === 'default') {
|
8854
8915
|
const expr = argList[i].valueExpression;
|
8855
8916
|
if (expr) {
|
8856
|
-
const defaultType = getParamSpecDefaultType(expr);
|
8917
|
+
const defaultType = getParamSpecDefaultType(expr, /* isPep695Syntax */ false);
|
8857
8918
|
if (defaultType) {
|
8858
8919
|
paramSpec.details.defaultType = defaultType;
|
8859
8920
|
paramSpec.details.isDefaultExplicit = true;
|
@@ -8877,7 +8938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8877
8938
|
}
|
8878
8939
|
return paramSpec;
|
8879
8940
|
}
|
8880
|
-
function getParamSpecDefaultType(node) {
|
8941
|
+
function getParamSpecDefaultType(node, isPep695Syntax) {
|
8881
8942
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
8882
8943
|
if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
|
8883
8944
|
types_1.FunctionType.addDefaultParameters(functionType);
|
@@ -8885,7 +8946,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8885
8946
|
}
|
8886
8947
|
if (node.nodeType === 31 /* ParseNodeType.List */) {
|
8887
8948
|
node.entries.forEach((paramExpr, index) => {
|
8888
|
-
const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
|
8949
|
+
const typeResult = getTypeOfExpressionExpectingType(paramExpr, {
|
8950
|
+
allowTypeVarsWithoutScopeId: true,
|
8951
|
+
allowForwardReference: isPep695Syntax,
|
8952
|
+
});
|
8889
8953
|
types_1.FunctionType.addParameter(functionType, {
|
8890
8954
|
category: 0 /* ParameterCategory.Simple */,
|
8891
8955
|
name: `__p${index}`,
|
@@ -9109,7 +9173,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9109
9173
|
hasDeclaredType: true,
|
9110
9174
|
});
|
9111
9175
|
initType.details.declaredReturnType = getNoneType();
|
9112
|
-
|
9176
|
+
types_1.ClassType.getSymbolTable(classType).set('__init__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, initType));
|
9113
9177
|
// Synthesize a trivial __new__ method.
|
9114
9178
|
const newType = types_1.FunctionType.createSynthesizedInstance('__new__', 1 /* FunctionTypeFlags.ConstructorMethod */);
|
9115
9179
|
types_1.FunctionType.addParameter(newType, {
|
@@ -9121,7 +9185,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9121
9185
|
types_1.FunctionType.addDefaultParameters(newType);
|
9122
9186
|
newType.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
|
9123
9187
|
newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
|
9124
|
-
|
9188
|
+
types_1.ClassType.getSymbolTable(classType).set('__new__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, newType));
|
9125
9189
|
}
|
9126
9190
|
return classType;
|
9127
9191
|
}
|
@@ -9701,7 +9765,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9701
9765
|
return undefined;
|
9702
9766
|
}
|
9703
9767
|
const specializedListOrSet = (0, typeUtils_1.applySolvedTypeVars)(expectedClassType, typeVarContext);
|
9704
|
-
if (!specializedListOrSet.typeArguments
|
9768
|
+
if (!specializedListOrSet.typeArguments) {
|
9705
9769
|
return undefined;
|
9706
9770
|
}
|
9707
9771
|
return specializedListOrSet.typeArguments[0];
|
@@ -10051,7 +10115,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10051
10115
|
if (ParseTreeUtils.containsAwaitNode(node.expression)) {
|
10052
10116
|
isAsync = true;
|
10053
10117
|
}
|
10054
|
-
const
|
10118
|
+
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
10119
|
+
const expectedEntryType = getExpectedEntryTypeForIterable(node, builtInIteratorType, inferenceContext);
|
10055
10120
|
const elementTypeResult = getElementTypeFromListComprehension(node, expectedEntryType);
|
10056
10121
|
if (elementTypeResult.isIncomplete) {
|
10057
10122
|
isIncomplete = true;
|
@@ -10059,8 +10124,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10059
10124
|
if (elementTypeResult.typeErrors) {
|
10060
10125
|
typeErrors = true;
|
10061
10126
|
}
|
10062
|
-
|
10063
|
-
|
10127
|
+
let elementType = elementTypeResult.type;
|
10128
|
+
if (!expectedEntryType || !(0, typeUtils_1.containsLiteralType)(expectedEntryType)) {
|
10129
|
+
elementType = stripLiteralValue(elementType);
|
10130
|
+
}
|
10064
10131
|
if (builtInIteratorType && (0, types_1.isInstantiableClass)(builtInIteratorType)) {
|
10065
10132
|
type = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(builtInIteratorType, isAsync ? [elementType, getNoneType()] : [elementType, getNoneType(), getNoneType()],
|
10066
10133
|
/* isTypeArgumentExplicit */ true));
|
@@ -10437,6 +10504,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10437
10504
|
else {
|
10438
10505
|
type = cloneBuiltinClassWithLiteral(node, classType, 'str', value);
|
10439
10506
|
}
|
10507
|
+
itemExpr.strings.forEach((stringNode) => {
|
10508
|
+
if ((stringNode.token.flags & 512 /* StringTokenFlags.NamedUnicodeEscape */) !== 0) {
|
10509
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalNamedUnicodeEscape(), stringNode);
|
10510
|
+
}
|
10511
|
+
});
|
10440
10512
|
}
|
10441
10513
|
else if (itemExpr.nodeType === 40 /* ParseNodeType.Number */) {
|
10442
10514
|
if (!itemExpr.isImaginary && itemExpr.isInteger) {
|
@@ -11054,6 +11126,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11054
11126
|
if (aliasMapEntry.isSpecialForm) {
|
11055
11127
|
specialClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
|
11056
11128
|
}
|
11129
|
+
// Synthesize a single type parameter with the specified variance if
|
11130
|
+
// specified in the alias map entry.
|
11131
|
+
if (aliasMapEntry.typeParamVariance !== undefined) {
|
11132
|
+
let typeParam = types_1.TypeVarType.createInstance('T');
|
11133
|
+
typeParam = types_1.TypeVarType.cloneForScopeId(typeParam, ParseTreeUtils.getScopeIdForNode(node), assignedName, 0 /* TypeVarScopeType.Class */);
|
11134
|
+
typeParam.details.declaredVariance = aliasMapEntry.typeParamVariance;
|
11135
|
+
specialClassType.details.typeParameters.push(typeParam);
|
11136
|
+
}
|
11057
11137
|
const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
|
11058
11138
|
specialClassType.details.declaration = specialBuiltInClassDeclaration;
|
11059
11139
|
if (fileInfo.isTypingExtensionsStubFile) {
|
@@ -11124,7 +11204,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11124
11204
|
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11125
11205
|
['TypeAlias', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11126
11206
|
['Concatenate', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11127
|
-
[
|
11207
|
+
[
|
11208
|
+
'TypeGuard',
|
11209
|
+
{ alias: '', module: 'builtins', isSpecialForm: true, typeParamVariance: 3 /* Variance.Covariant */ },
|
11210
|
+
],
|
11128
11211
|
['Unpack', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11129
11212
|
['Required', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11130
11213
|
['NotRequired', { alias: '', module: 'builtins', isSpecialForm: true }],
|
@@ -11133,7 +11216,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11133
11216
|
['Never', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11134
11217
|
['LiteralString', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11135
11218
|
['ReadOnly', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11136
|
-
['TypeIs', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11219
|
+
['TypeIs', { alias: '', module: 'builtins', isSpecialForm: true, typeParamVariance: 2 /* Variance.Invariant */ }],
|
11137
11220
|
]);
|
11138
11221
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11139
11222
|
if (aliasMapEntry) {
|
@@ -11511,6 +11594,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11511
11594
|
// all of the type parameters in the specified order.
|
11512
11595
|
let genericTypeParameters;
|
11513
11596
|
let protocolTypeParameters;
|
11597
|
+
let isNamedTupleSubclass = false;
|
11514
11598
|
const initSubclassArgs = [];
|
11515
11599
|
let metaclassNode;
|
11516
11600
|
let exprFlags = 128 /* EvaluatorFlags.ExpectingInstantiableType */ |
|
@@ -11590,6 +11674,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11590
11674
|
// newer), it's considered a (read-only) dataclass.
|
11591
11675
|
if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
|
11592
11676
|
if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
|
11677
|
+
isNamedTupleSubclass = true;
|
11593
11678
|
classType.details.flags |=
|
11594
11679
|
4 /* ClassTypeFlags.DataClass */ |
|
11595
11680
|
32 /* ClassTypeFlags.SkipSynthesizedDataClassEq */ |
|
@@ -11948,46 +12033,62 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11948
12033
|
// See if there's already a non-synthesized __init__ method.
|
11949
12034
|
// We shouldn't override it.
|
11950
12035
|
if (!skipSynthesizedInit) {
|
11951
|
-
const initSymbol =
|
11952
|
-
if (initSymbol) {
|
12036
|
+
const initSymbol = classType.details.fields.get('__init__');
|
12037
|
+
if (initSymbol && initSymbol.isClassMember()) {
|
11953
12038
|
hasExistingInitMethod = true;
|
11954
12039
|
}
|
11955
12040
|
}
|
11956
12041
|
let skipSynthesizeHash = false;
|
11957
|
-
const hashSymbol =
|
12042
|
+
const hashSymbol = classType.details.fields.get('__hash__');
|
11958
12043
|
// If there is a hash symbol defined in the class (i.e. one that we didn't
|
11959
12044
|
// synthesize above), then we shouldn't synthesize a new one for the dataclass.
|
11960
|
-
if (hashSymbol && !hashSymbol.
|
12045
|
+
if (hashSymbol && hashSymbol.isClassMember() && !hashSymbol.getSynthesizedType()) {
|
11961
12046
|
skipSynthesizeHash = true;
|
11962
12047
|
}
|
11963
|
-
(0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
12048
|
+
const synthesizeMethods = () => (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
|
12049
|
+
// If this is a NamedTuple subclass, immediately synthesize dataclass methods
|
12050
|
+
// because we also need to update the MRO classes in this case. For regular
|
12051
|
+
// dataclasses, we'll defer the method synthesis to avoid circular dependencies.
|
12052
|
+
if (isNamedTupleSubclass) {
|
12053
|
+
synthesizeMethods();
|
12054
|
+
}
|
12055
|
+
else {
|
12056
|
+
classType.details.synthesizeMethodsDeferred = () => {
|
12057
|
+
delete classType.details.synthesizeMethodsDeferred;
|
12058
|
+
synthesizeMethods();
|
12059
|
+
};
|
12060
|
+
}
|
11964
12061
|
}
|
11965
12062
|
// Build a complete list of all slots names defined by the class hierarchy.
|
11966
12063
|
// This needs to be done after dataclass processing.
|
11967
|
-
|
11968
|
-
|
11969
|
-
|
11970
|
-
|
11971
|
-
|
11972
|
-
|
11973
|
-
|
11974
|
-
!types_1.ClassType.isBuiltIn(baseClass, '
|
11975
|
-
|
11976
|
-
|
11977
|
-
|
11978
|
-
|
11979
|
-
|
12064
|
+
classType.details.calculateInheritedSlotsNamesDeferred = () => {
|
12065
|
+
delete classType.details.calculateInheritedSlotsNamesDeferred;
|
12066
|
+
if (classType.details.localSlotsNames) {
|
12067
|
+
let isLimitedToSlots = true;
|
12068
|
+
const extendedSlotsNames = Array.from(classType.details.localSlotsNames);
|
12069
|
+
classType.details.baseClasses.forEach((baseClass) => {
|
12070
|
+
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
12071
|
+
if (!types_1.ClassType.isBuiltIn(baseClass, 'object') &&
|
12072
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'type') &&
|
12073
|
+
!types_1.ClassType.isBuiltIn(baseClass, 'Generic')) {
|
12074
|
+
const inheritedSlotsNames = types_1.ClassType.getInheritedSlotsNames(baseClass);
|
12075
|
+
if (inheritedSlotsNames) {
|
12076
|
+
(0, collectionUtils_1.appendArray)(extendedSlotsNames, inheritedSlotsNames);
|
12077
|
+
}
|
12078
|
+
else {
|
12079
|
+
isLimitedToSlots = false;
|
12080
|
+
}
|
11980
12081
|
}
|
11981
12082
|
}
|
12083
|
+
else {
|
12084
|
+
isLimitedToSlots = false;
|
12085
|
+
}
|
12086
|
+
});
|
12087
|
+
if (isLimitedToSlots) {
|
12088
|
+
classType.details.inheritedSlotsNamesCached = extendedSlotsNames;
|
11982
12089
|
}
|
11983
|
-
else {
|
11984
|
-
isLimitedToSlots = false;
|
11985
|
-
}
|
11986
|
-
});
|
11987
|
-
if (isLimitedToSlots) {
|
11988
|
-
classType.details.inheritedSlotsNames = extendedSlotsNames;
|
11989
12090
|
}
|
11990
|
-
}
|
12091
|
+
};
|
11991
12092
|
// Update the undecorated class type.
|
11992
12093
|
writeTypeCache(node.name, { type: classType }, 0 /* EvaluatorFlags.None */);
|
11993
12094
|
// Update the decorated class type.
|
@@ -12841,7 +12942,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12841
12942
|
// of the child class.
|
12842
12943
|
if ((0, typeUtils_1.requiresSpecialization)(inferredParamType) && (0, types_1.isClass)(baseClassMemberInfo.classType)) {
|
12843
12944
|
const typeVarContext = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(baseClassMemberInfo.classType);
|
12844
|
-
|
12945
|
+
// Add the scope of the method to handle any function-scoped TypeVars.
|
12946
|
+
typeVarContext.addSolveForScope(ParseTreeUtils.getScopeIdForNode(baseClassMethodNode));
|
12947
|
+
// Replace any unsolved TypeVars with Unknown (including all function-scoped TypeVars).
|
12948
|
+
inferredParamType = (0, typeUtils_1.applySolvedTypeVars)(inferredParamType, typeVarContext, {
|
12949
|
+
unknownIfNotFound: true,
|
12950
|
+
});
|
12845
12951
|
}
|
12846
12952
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(functionNode);
|
12847
12953
|
if (fileInfo.isInPyTypedPackage && !fileInfo.isStubFile) {
|
@@ -13751,6 +13857,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13751
13857
|
break;
|
13752
13858
|
}
|
13753
13859
|
}
|
13860
|
+
else if (parent.nodeType === 75 /* ParseNodeType.TypeParameter */) {
|
13861
|
+
// If this is a bound or default expression in a type parameter list,
|
13862
|
+
// we need to evaluate it in the context of the type parameter.
|
13863
|
+
if (node === parent.boundExpression || node === parent.defaultExpression) {
|
13864
|
+
getTypeOfTypeParameter(parent);
|
13865
|
+
return;
|
13866
|
+
}
|
13867
|
+
break;
|
13868
|
+
}
|
13754
13869
|
else {
|
13755
13870
|
break;
|
13756
13871
|
}
|
@@ -15052,6 +15167,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15052
15167
|
const constraints = node.boundExpression.expressions.map((constraint) => {
|
15053
15168
|
const constraintType = getTypeOfExpressionExpectingType(constraint, {
|
15054
15169
|
disallowProtocolAndTypedDict: true,
|
15170
|
+
allowForwardReference: true,
|
15055
15171
|
}).type;
|
15056
15172
|
if ((0, typeUtils_1.requiresSpecialization)(constraintType, {
|
15057
15173
|
ignorePseudoGeneric: true,
|
@@ -15071,6 +15187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15071
15187
|
else {
|
15072
15188
|
const boundType = getTypeOfExpressionExpectingType(node.boundExpression, {
|
15073
15189
|
disallowProtocolAndTypedDict: true,
|
15190
|
+
allowForwardReference: true,
|
15074
15191
|
}).type;
|
15075
15192
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
15076
15193
|
addError(localize_1.LocMessage.typeVarConstraintGeneric(), node.boundExpression);
|
@@ -15081,7 +15198,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15081
15198
|
}
|
15082
15199
|
}
|
15083
15200
|
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec) {
|
15084
|
-
const defaultType = node.defaultExpression
|
15201
|
+
const defaultType = node.defaultExpression
|
15202
|
+
? getParamSpecDefaultType(node.defaultExpression, /* isPep695Syntax */ true)
|
15203
|
+
: undefined;
|
15085
15204
|
if (defaultType) {
|
15086
15205
|
typeVar.details.defaultType = defaultType;
|
15087
15206
|
typeVar.details.isDefaultExplicit = true;
|
@@ -15091,7 +15210,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15091
15210
|
}
|
15092
15211
|
}
|
15093
15212
|
else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
|
15094
|
-
const defaultType = node.defaultExpression
|
15213
|
+
const defaultType = node.defaultExpression
|
15214
|
+
? getTypeVarTupleDefaultType(node.defaultExpression, /* isPep695Syntax */ true)
|
15215
|
+
: undefined;
|
15095
15216
|
if (defaultType) {
|
15096
15217
|
typeVar.details.defaultType = defaultType;
|
15097
15218
|
typeVar.details.isDefaultExplicit = true;
|
@@ -15102,7 +15223,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15102
15223
|
}
|
15103
15224
|
else {
|
15104
15225
|
const defaultType = node.defaultExpression
|
15105
|
-
? (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(node.defaultExpression).type)
|
15226
|
+
? (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(node.defaultExpression, { allowForwardReference: true }).type)
|
15106
15227
|
: undefined;
|
15107
15228
|
if (defaultType) {
|
15108
15229
|
typeVar.details.defaultType = defaultType;
|
@@ -15501,7 +15622,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15501
15622
|
// If the symbol is explicitly marked as a ClassVar, consider only the
|
15502
15623
|
// declarations that assign to it from within the class body, not through
|
15503
15624
|
// a member access expression.
|
15504
|
-
if (
|
15625
|
+
if ((0, symbolUtils_1.isEffectivelyClassVar)(symbol, /* isDataclass */ false) &&
|
15626
|
+
decl.type === 1 /* DeclarationType.Variable */ &&
|
15627
|
+
decl.isDefinedByMemberAccess) {
|
15505
15628
|
return;
|
15506
15629
|
}
|
15507
15630
|
if (usageNode !== undefined) {
|
@@ -15729,7 +15852,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15729
15852
|
function getFunctionEffectiveReturnType(type, args, inferTypeIfNeeded = true) {
|
15730
15853
|
const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type, /* includeInferred */ false);
|
15731
15854
|
if (specializedReturnType && !(0, types_1.isUnknown)(specializedReturnType)) {
|
15732
|
-
return adjustCallableReturnType(specializedReturnType, /*
|
15855
|
+
return adjustCallableReturnType(type, specializedReturnType, /* liveTypeVarScopes */ []);
|
15733
15856
|
}
|
15734
15857
|
if (inferTypeIfNeeded) {
|
15735
15858
|
return getFunctionInferredReturnType(type, args);
|
@@ -16152,7 +16275,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16152
16275
|
// Stash the current class type so any references to it are treated
|
16153
16276
|
// as though all TypeParameters are invariant.
|
16154
16277
|
assignClassToSelfStack.push({ class: destType, assumedVariance });
|
16155
|
-
|
16278
|
+
types_1.ClassType.getSymbolTable(destType).forEach((symbol, name) => {
|
16156
16279
|
if (!isAssignable || symbol.isIgnoredForProtocolMatch()) {
|
16157
16280
|
return;
|
16158
16281
|
}
|
@@ -16989,7 +17112,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16989
17112
|
}
|
16990
17113
|
}
|
16991
17114
|
else if (types_1.ClassType.isBuiltIn(destType, ['TypeGuard', 'TypeIs'])) {
|
16992
|
-
//
|
17115
|
+
// Allow the source to be a "bool".
|
16993
17116
|
if ((originalFlags & 128 /* AssignTypeFlags.AllowBoolTypeGuard */) !== 0) {
|
16994
17117
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
|
16995
17118
|
return true;
|
@@ -17095,6 +17218,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17095
17218
|
const constructor = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, concreteSrcType, (0, types_1.isTypeVar)(srcType) ? (0, typeUtils_1.convertToInstance)(srcType) : undefined, recursionCount);
|
17096
17219
|
if (constructor) {
|
17097
17220
|
concreteSrcType = constructor;
|
17221
|
+
// The constructor conversion may result in a union of the
|
17222
|
+
// __init__ and __new__ callables.
|
17223
|
+
if ((0, types_1.isUnion)(concreteSrcType)) {
|
17224
|
+
return assignType(destType, concreteSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
17225
|
+
}
|
17098
17226
|
}
|
17099
17227
|
}
|
17100
17228
|
if ((0, types_1.isAnyOrUnknown)(concreteSrcType)) {
|
@@ -17601,11 +17729,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17601
17729
|
// a normal function wouldn't be compatible with.
|
17602
17730
|
for (const mroClass of objType.details.mro) {
|
17603
17731
|
if ((0, types_1.isClass)(mroClass) && types_1.ClassType.isProtocolClass(mroClass)) {
|
17604
|
-
for (const field of
|
17732
|
+
for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
|
17605
17733
|
if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
|
17606
17734
|
let fieldIsPartOfFunction = false;
|
17607
17735
|
if (functionObj && (0, types_1.isClass)(functionObj)) {
|
17608
|
-
if (
|
17736
|
+
if (types_1.ClassType.getSymbolTable(functionObj).has(field[0])) {
|
17609
17737
|
fieldIsPartOfFunction = true;
|
17610
17738
|
}
|
17611
17739
|
}
|
@@ -18128,10 +18256,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18128
18256
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
18129
18257
|
remainingFunction.details.constructorTypeVarScopeId =
|
18130
18258
|
effectiveSrcType.details.constructorTypeVarScopeId;
|
18259
|
+
remainingFunction.details.methodClass = effectiveSrcType.details.methodClass;
|
18131
18260
|
remainingParams.forEach((param) => {
|
18132
18261
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
18133
18262
|
});
|
18134
18263
|
remainingFunction.details.paramSpec = srcParamSpec ? (0, typeUtils_1.convertToInstance)(srcParamSpec) : undefined;
|
18264
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(remainingFunction, effectiveSrcType.details.higherOrderTypeVarScopeIds);
|
18135
18265
|
if (!assignType(destParamSpec, remainingFunction,
|
18136
18266
|
/* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags)) {
|
18137
18267
|
// If we couldn't assign the function to the ParamSpec, see if we can
|
@@ -18162,12 +18292,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18162
18292
|
(0, typeUtils_1.containsLiteralType)(srcType.details.declaredReturnType, /* includeTypeArgs */ true)) {
|
18163
18293
|
effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
18164
18294
|
}
|
18165
|
-
if ((
|
18166
|
-
// We'll allow any function that returns NoReturn to match any
|
18167
|
-
// function return type, consistent with other type checkers.
|
18168
|
-
isReturnTypeCompatible = true;
|
18169
|
-
}
|
18170
|
-
else if (assignType(destReturnType, srcReturnType, returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, effectiveFlags, recursionCount)) {
|
18295
|
+
if (assignType(destReturnType, srcReturnType, returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, effectiveFlags, recursionCount)) {
|
18171
18296
|
isReturnTypeCompatible = true;
|
18172
18297
|
}
|
18173
18298
|
else {
|
@@ -18820,7 +18945,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18820
18945
|
// See if this class is introducing a new abstract symbol that has not been
|
18821
18946
|
// introduced previously or if it is overriding an abstract symbol with
|
18822
18947
|
// a non-abstract one.
|
18823
|
-
|
18948
|
+
types_1.ClassType.getSymbolTable(mroClass).forEach((symbol, symbolName) => {
|
18824
18949
|
const abstractSymbolInfo = getAbstractSymbolInfo(mroClass, symbolName);
|
18825
18950
|
if (abstractSymbolInfo) {
|
18826
18951
|
symbolTable.set(symbolName, abstractSymbolInfo);
|
@@ -18840,11 +18965,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18840
18965
|
}
|
18841
18966
|
// If the memberType is an instance or class method, creates a new
|
18842
18967
|
// version of the function that has the "self" or "cls" parameter bound
|
18843
|
-
// to it. If
|
18968
|
+
// to it. If treatConstructorAsClassMethod is true, the function is
|
18844
18969
|
// treated like a class method even if it's not marked as such. That's
|
18845
18970
|
// needed to special-case the __new__ magic method when it's invoked as
|
18846
18971
|
// a constructor (as opposed to by name).
|
18847
|
-
function bindFunctionToClassOrObject(baseType, memberType, memberClass,
|
18972
|
+
function bindFunctionToClassOrObject(baseType, memberType, memberClass, treatConstructorAsClassMethod = false, selfType, diag, recursionCount = 0) {
|
18848
18973
|
return (0, typeUtils_1.mapSignatures)(memberType, (functionType) => {
|
18849
18974
|
// If the caller specified no base type, always strip the
|
18850
18975
|
// first parameter. This is used in cases like constructors.
|
@@ -18859,11 +18984,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18859
18984
|
const baseObj = (0, types_1.isClassInstance)(baseType)
|
18860
18985
|
? baseType
|
18861
18986
|
: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType));
|
18862
|
-
|
18863
|
-
|
18987
|
+
let stripFirstParam = false;
|
18988
|
+
if ((0, types_1.isClassInstance)(baseType)) {
|
18989
|
+
stripFirstParam = true;
|
18990
|
+
}
|
18991
|
+
else if (memberClass && (0, typeUtils_1.isInstantiableMetaclass)(memberClass)) {
|
18992
|
+
stripFirstParam = true;
|
18993
|
+
}
|
18994
|
+
return partiallySpecializeFunctionForBoundClassOrObject(baseType, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : types_1.ClassType.cloneAsInstantiable(baseObj), diag, recursionCount, selfType !== null && selfType !== void 0 ? selfType : baseObj, stripFirstParam);
|
18864
18995
|
}
|
18865
18996
|
if (types_1.FunctionType.isClassMethod(functionType) ||
|
18866
|
-
(
|
18997
|
+
(treatConstructorAsClassMethod && types_1.FunctionType.isConstructorMethod(functionType))) {
|
18867
18998
|
const baseClass = (0, types_1.isInstantiableClass)(baseType) ? baseType : types_1.ClassType.cloneAsInstantiable(baseType);
|
18868
18999
|
const clsType = selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : undefined;
|
18869
19000
|
return partiallySpecializeFunctionForBoundClassOrObject(baseClass, functionType, memberClass !== null && memberClass !== void 0 ? memberClass : baseClass, diag, recursionCount, clsType !== null && clsType !== void 0 ? clsType : baseClass,
|
@@ -19069,11 +19200,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
19069
19200
|
if (node.strings[0].nodeType === 49 /* ParseNodeType.String */) {
|
19070
19201
|
valueOffset += node.strings[0].token.prefixLength + node.strings[0].token.quoteMarkLength;
|
19071
19202
|
}
|
19203
|
+
// Construct a temporary dummy string with the text value at the appropriate
|
19204
|
+
// offset so as to mimic the original file. This will keep all of the token
|
19205
|
+
// and diagnostic offsets correct.
|
19206
|
+
const dummyFileContents = ' '.repeat(valueOffset) + textValue;
|
19072
19207
|
const parseOptions = new parser_1.ParseOptions();
|
19073
19208
|
parseOptions.isStubFile = fileInfo.isStubFile;
|
19074
19209
|
parseOptions.pythonVersion = fileInfo.executionEnvironment.pythonVersion;
|
19075
19210
|
parseOptions.reportErrorsForParsedStringContents = true;
|
19076
|
-
const parseResults = parser.parseTextExpression(
|
19211
|
+
const parseResults = parser.parseTextExpression(dummyFileContents, valueOffset, textValue.length, parseOptions,
|
19077
19212
|
/* parseTextMode */ undefined,
|
19078
19213
|
/* initialParenDepth */ undefined, fileInfo.typingSymbolAliases);
|
19079
19214
|
if (parseResults.parseTree && parseResults.parseTree.nodeType !== 62 /* ParseNodeType.FunctionAnnotation */) {
|