@zzzen/pyright-internal 1.2.0-dev.20230507 → 1.2.0-dev.20230521
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 +1 -0
- package/dist/analyzer/analyzerFileInfo.js +4 -3
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +17 -15
- package/dist/analyzer/backgroundAnalysisProgram.js +43 -53
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.d.ts +0 -2
- package/dist/analyzer/binder.js +2 -20
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -1
- package/dist/analyzer/checker.js +97 -29
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +14 -15
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +5 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +248 -189
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +5 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +1 -0
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +1 -1
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/enums.js +8 -0
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +4 -4
- package/dist/analyzer/importResolver.js +93 -69
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.d.ts +2 -2
- package/dist/analyzer/importStatementUtils.js +2 -2
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +2 -5
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +1 -1
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +2 -34
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +2 -2
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +1 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +18 -34
- package/dist/analyzer/program.js +57 -259
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +4 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +8 -16
- package/dist/analyzer/service.js +33 -47
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -15
- package/dist/analyzer/sourceFile.js +14 -96
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +1 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/symbol.d.ts +3 -1
- package/dist/analyzer/symbol.js +5 -0
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +495 -196
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +7 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +1 -0
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +3 -3
- package/dist/analyzer/typePrinter.js +255 -101
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +12 -7
- package/dist/analyzer/typeUtils.js +174 -49
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +1 -2
- package/dist/analyzer/typeVarContext.js +16 -34
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +138 -41
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +10 -3
- package/dist/analyzer/types.js +32 -16
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +25 -19
- package/dist/backgroundAnalysisBase.js +161 -115
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +1 -1
- package/dist/backgroundThreadBase.js +1 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +3 -4
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.js +1 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +26 -5
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/logTracker.d.ts +2 -0
- package/dist/common/logTracker.js +8 -1
- package/dist/common/logTracker.js.map +1 -1
- package/dist/common/lspUtils.d.ts +4 -1
- package/dist/common/lspUtils.js +38 -1
- package/dist/common/lspUtils.js.map +1 -1
- package/dist/common/pythonVersion.d.ts +2 -1
- package/dist/common/pythonVersion.js +1 -0
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/common/textRange.js +1 -1
- package/dist/common/textRange.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +3 -3
- package/dist/common/workspaceEditUtils.js +15 -17
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -5
- package/dist/languageServerBase.js +35 -62
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +51 -52
- package/dist/languageService/autoImporter.js +126 -211
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +8 -33
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +42 -81
- package/dist/languageService/completionProvider.js +608 -841
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.d.ts +2 -2
- package/dist/languageService/documentSymbolCollector.js +40 -30
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.d.ts +13 -35
- package/dist/languageService/documentSymbolProvider.js +52 -264
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -3
- package/dist/languageService/hoverProvider.js +11 -97
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/referencesProvider.d.ts +3 -3
- package/dist/languageService/referencesProvider.js +6 -8
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +0 -1
- package/dist/languageService/renameProvider.js +2 -6
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +23 -0
- package/dist/languageService/symbolIndexer.js +105 -0
- package/dist/languageService/symbolIndexer.js.map +1 -0
- package/dist/languageService/tooltipUtils.d.ts +8 -1
- package/dist/languageService/tooltipUtils.js +102 -1
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.d.ts +17 -0
- package/dist/languageService/workspaceSymbolProvider.js +133 -0
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -0
- package/dist/localization/localize.d.ts +38 -4
- package/dist/localization/localize.js +21 -4
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +23 -6
- package/dist/parser/parseNodes.d.ts +8 -8
- package/dist/parser/parseNodes.js +20 -10
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -3
- package/dist/parser/parser.js +136 -159
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.d.ts +3 -13
- package/dist/parser/stringTokenUtils.js +8 -181
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +3 -0
- package/dist/parser/tokenizer.js +211 -24
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +31 -1
- package/dist/parser/tokenizerTypes.js +51 -1
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +26 -4
- package/dist/pyright.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.js +1 -1
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +15 -20
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/checker.test.js +14 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/completions.test.js +11 -236
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +36 -2
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js +1 -16
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +14 -8
- package/dist/tests/harness/fourslash/testState.js +27 -37
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/importResolver.test.js +84 -4
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/textRange.test.js +45 -0
- package/dist/tests/textRange.test.js.map +1 -0
- package/dist/tests/tokenizer.test.js +272 -58
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +16 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +14 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +29 -9
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +15 -10
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.js +3 -5
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
- package/dist/languageService/importAdder.d.ts +0 -40
- package/dist/languageService/importAdder.js +0 -388
- package/dist/languageService/importAdder.js.map +0 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +0 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.js +0 -81
- package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +0 -1
- package/dist/tests/importAdder.test.js +0 -1325
- package/dist/tests/importAdder.test.js.map +0 -1
- /package/dist/tests/{importAdder.test.d.ts → textRange.test.d.ts} +0 -0
@@ -166,7 +166,7 @@ const printExpressionTypes = false;
|
|
166
166
|
exports.maxCodeComplexity = 768;
|
167
167
|
function createTypeEvaluator(importLookup, evaluatorOptions) {
|
168
168
|
const symbolResolutionStack = [];
|
169
|
-
const
|
169
|
+
const asymmetricAccessorAssignmentCache = new Set();
|
170
170
|
const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
|
171
171
|
const suppressedNodeStack = [];
|
172
172
|
let functionRecursionMap = new Set();
|
@@ -300,10 +300,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
300
300
|
if (isSpeculativeModeInUse(/* node */ undefined)) {
|
301
301
|
return;
|
302
302
|
}
|
303
|
-
|
303
|
+
asymmetricAccessorAssignmentCache.add(node.id);
|
304
304
|
}
|
305
|
-
function
|
306
|
-
return
|
305
|
+
function isAsymmetricAccessorAssignment(node) {
|
306
|
+
return asymmetricAccessorAssignmentCache.has(node.id);
|
307
307
|
}
|
308
308
|
// Determines whether the specified node is contained within
|
309
309
|
// the function node corresponding to the function that we
|
@@ -446,7 +446,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
446
446
|
}
|
447
447
|
}
|
448
448
|
function getTypeOfExpression(node, flags = 0 /* None */, inferenceContext) {
|
449
|
-
var _a
|
449
|
+
var _a;
|
450
450
|
// Is this type already cached?
|
451
451
|
const cacheEntry = readTypeCacheEntry(node);
|
452
452
|
if (cacheEntry &&
|
@@ -646,6 +646,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
646
646
|
}
|
647
647
|
}
|
648
648
|
writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
|
649
|
+
// If there was an expected type, make sure that the result type is compatible.
|
649
650
|
if (inferenceContext &&
|
650
651
|
!(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) &&
|
651
652
|
!(0, types_1.isNever)(inferenceContext.expectedType)) {
|
@@ -653,9 +654,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
653
654
|
if (!typeResult.isIncomplete && !typeResult.expectedTypeDiagAddendum) {
|
654
655
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
655
656
|
// Make sure the resulting type is assignable to the expected type.
|
656
|
-
|
657
|
-
// it is provided.
|
658
|
-
if (!assignType(inferenceContext.expectedType, typeResult.type, diag, new typeVarContext_1.TypeVarContext((_b = inferenceContext.typeVarContext) === null || _b === void 0 ? void 0 : _b.getSolveForScopes()))) {
|
657
|
+
if (!assignType(inferenceContext.expectedType, typeResult.type, diag)) {
|
659
658
|
typeResult.typeErrors = true;
|
660
659
|
typeResult.expectedTypeDiagAddendum = diag;
|
661
660
|
diag.addTextRange(node);
|
@@ -823,7 +822,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
823
822
|
let isLiteralString = true;
|
824
823
|
// If all of the format expressions are of type LiteralString, then
|
825
824
|
// the resulting formatted string is also LiteralString.
|
826
|
-
node.
|
825
|
+
node.fieldExpressions.forEach((expr) => {
|
827
826
|
const exprType = getTypeOfExpression(expr).type;
|
828
827
|
(0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
|
829
828
|
if (!(0, types_1.isClassInstance)(exprSubtype)) {
|
@@ -1226,7 +1225,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1226
1225
|
type: memberInfo.type,
|
1227
1226
|
classType: memberInfo.classType,
|
1228
1227
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1229
|
-
|
1228
|
+
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1230
1229
|
};
|
1231
1230
|
}
|
1232
1231
|
return undefined;
|
@@ -1273,7 +1272,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1273
1272
|
return {
|
1274
1273
|
type: memberInfo.type,
|
1275
1274
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1276
|
-
|
1275
|
+
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1277
1276
|
};
|
1278
1277
|
}
|
1279
1278
|
// Determine whether to use the class or metaclass diagnostic addendum.
|
@@ -1385,12 +1384,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1385
1384
|
const isObjectInit = !!methodType &&
|
1386
1385
|
(0, types_1.isFunction)(methodType) &&
|
1387
1386
|
methodType.details.fullName === 'builtins.object.__init__';
|
1388
|
-
const isSkipConstructor = !!methodType && (0, types_1.isFunction)(methodType) && types_1.FunctionType.isSkipConstructorCheck(methodType);
|
1389
1387
|
const isDefaultParams = methodType && (0, types_1.isFunction)(methodType) && types_1.FunctionType.hasDefaultParameters(methodType);
|
1390
1388
|
// If there was no `__init__` or the only `__init__` that was found was from
|
1391
1389
|
// the `object` class or accepts only default parameters(* args, ** kwargs),
|
1392
1390
|
// see if we can find a better signature from the `__new__` method.
|
1393
|
-
if (!methodType || isObjectInit ||
|
1391
|
+
if (!methodType || isObjectInit || isDefaultParams) {
|
1394
1392
|
const constructorType = getBoundMethod(subtype, '__new__',
|
1395
1393
|
/* recursionCount */ undefined,
|
1396
1394
|
/* treatConstructorAsClassMember */ true);
|
@@ -1534,8 +1532,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1534
1532
|
if ((0, types_1.isClassInstance)(declaredType)) {
|
1535
1533
|
const setterInfo = (0, typeUtils_1.lookUpClassMember)(declaredType, '__set__');
|
1536
1534
|
const setter = setterInfo ? getTypeOfMember(setterInfo) : undefined;
|
1537
|
-
if (setter && (0, types_1.isFunction)(setter) && setter.details.parameters.length >= 3) {
|
1535
|
+
if (setterInfo && setter && (0, types_1.isFunction)(setter) && setter.details.parameters.length >= 3) {
|
1538
1536
|
declaredType = setter.details.parameters[2].type;
|
1537
|
+
if ((0, types_1.isClass)(setterInfo.classType)) {
|
1538
|
+
const typeVarMap = (0, typeUtils_1.buildTypeVarContextFromSpecializedClass)(setterInfo.classType);
|
1539
|
+
declaredType = (0, typeUtils_1.applySolvedTypeVars)(declaredType, typeVarMap);
|
1540
|
+
}
|
1539
1541
|
if ((0, types_1.isAnyOrUnknown)(declaredType)) {
|
1540
1542
|
return undefined;
|
1541
1543
|
}
|
@@ -2021,7 +2023,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2021
2023
|
}
|
2022
2024
|
else {
|
2023
2025
|
// Constrain the resulting type to match the declared type.
|
2024
|
-
destType = narrowTypeBasedOnAssignment(declaredType, type);
|
2026
|
+
destType = narrowTypeBasedOnAssignment(nameNode, declaredType, type);
|
2025
2027
|
}
|
2026
2028
|
}
|
2027
2029
|
else {
|
@@ -2100,7 +2102,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2100
2102
|
setErrorNode: srcExpr,
|
2101
2103
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2102
2104
|
}, 0 /* None */);
|
2103
|
-
if (setTypeResult.
|
2105
|
+
if (setTypeResult.isAsymmetricAccessor) {
|
2104
2106
|
setAsymmetricDescriptorAssignment(target);
|
2105
2107
|
}
|
2106
2108
|
writeTypeCache(target.memberName, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
@@ -2320,6 +2322,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2320
2322
|
// If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
|
2321
2323
|
// *tuple[*Ts].
|
2322
2324
|
if ((0, types_1.isVariadicTypeVar)(subtype)) {
|
2325
|
+
if (subtype.isVariadicInUnion) {
|
2326
|
+
return subtype;
|
2327
|
+
}
|
2323
2328
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2324
2329
|
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
|
2325
2330
|
/* isTypeArgumentExplicit */ true,
|
@@ -2538,7 +2543,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2538
2543
|
// is a enum because the annotated type in an enum doesn't reflect
|
2539
2544
|
// the type of the symbol.
|
2540
2545
|
if (!(0, types_1.isClassInstance)(type) || !types_1.ClassType.isEnumClass(type)) {
|
2541
|
-
type = narrowTypeBasedOnAssignment(annotationType, type);
|
2546
|
+
type = narrowTypeBasedOnAssignment(target, annotationType, type);
|
2542
2547
|
}
|
2543
2548
|
}
|
2544
2549
|
}
|
@@ -3199,6 +3204,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3199
3204
|
container: typeAliasNode.name.value,
|
3200
3205
|
}), node);
|
3201
3206
|
}
|
3207
|
+
else {
|
3208
|
+
// If this is a TypeAliasType call, the recursiveTypeParameters will already
|
3209
|
+
// be populated, and we need to verify that the type parameter is in the
|
3210
|
+
// list of allowed type parameters.
|
3211
|
+
const allowedTypeParams = leftType.details.recursiveTypeParameters;
|
3212
|
+
if (allowedTypeParams) {
|
3213
|
+
if (!allowedTypeParams.some((param) => param.details.name === type.details.name)) {
|
3214
|
+
// Return the original type.
|
3215
|
+
return { type, isRescoped: false, foundInterveningClass: false };
|
3216
|
+
}
|
3217
|
+
}
|
3218
|
+
}
|
3202
3219
|
return {
|
3203
3220
|
type: types_1.TypeVarType.cloneForScopeId(type, leftType.details.recursiveTypeAliasScopeId, leftType.details.recursiveTypeAliasName, 2 /* TypeAlias */),
|
3204
3221
|
isRescoped: false,
|
@@ -3281,7 +3298,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3281
3298
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
3282
3299
|
let type;
|
3283
3300
|
let isIncomplete = !!baseTypeResult.isIncomplete;
|
3284
|
-
let
|
3301
|
+
let isAsymmetricAccessor;
|
3285
3302
|
const isRequired = false;
|
3286
3303
|
const isNotRequired = false;
|
3287
3304
|
// If the base type was incomplete and unbound, don't proceed
|
@@ -3340,7 +3357,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3340
3357
|
}
|
3341
3358
|
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3342
3359
|
}
|
3343
|
-
if (flags &
|
3360
|
+
if (flags & 256 /* ExpectingTypeAnnotation */) {
|
3344
3361
|
if (!isIncomplete) {
|
3345
3362
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarNoMember().format({
|
3346
3363
|
type: printType(baseType),
|
@@ -3365,8 +3382,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3365
3382
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
|
3366
3383
|
isIncomplete = true;
|
3367
3384
|
}
|
3368
|
-
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.
|
3369
|
-
|
3385
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3386
|
+
isAsymmetricAccessor = true;
|
3370
3387
|
}
|
3371
3388
|
}
|
3372
3389
|
else {
|
@@ -3383,8 +3400,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3383
3400
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
|
3384
3401
|
isIncomplete = true;
|
3385
3402
|
}
|
3386
|
-
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.
|
3387
|
-
|
3403
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3404
|
+
isAsymmetricAccessor = true;
|
3388
3405
|
}
|
3389
3406
|
}
|
3390
3407
|
break;
|
@@ -3584,7 +3601,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3584
3601
|
/* ignoreEmptyContainers */ false);
|
3585
3602
|
}
|
3586
3603
|
}
|
3587
|
-
return { type, isIncomplete,
|
3604
|
+
return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired };
|
3588
3605
|
}
|
3589
3606
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3590
3607
|
var _a, _b;
|
@@ -3719,7 +3736,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3719
3736
|
isClassMember: !memberInfo.isInstanceMember,
|
3720
3737
|
isClassVar: memberInfo.isClassVar,
|
3721
3738
|
classType: memberInfo.classType,
|
3722
|
-
|
3739
|
+
isAsymmetricAccessor: descriptorResult.isAsymmetricAccessor,
|
3723
3740
|
};
|
3724
3741
|
}
|
3725
3742
|
// No attribute of that name was found. If this is a member access
|
@@ -3731,11 +3748,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3731
3748
|
if (generalAttrType) {
|
3732
3749
|
return {
|
3733
3750
|
symbol: undefined,
|
3734
|
-
type: generalAttrType,
|
3751
|
+
type: generalAttrType.type,
|
3735
3752
|
isTypeIncomplete: false,
|
3736
3753
|
isClassMember: false,
|
3737
3754
|
isClassVar: false,
|
3738
|
-
|
3755
|
+
isAsymmetricAccessor: generalAttrType.isAsymmetricAccessor,
|
3739
3756
|
};
|
3740
3757
|
}
|
3741
3758
|
}
|
@@ -3748,7 +3765,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3748
3765
|
function applyDescriptorAccessMethod(type, memberInfo, baseTypeClass, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag) {
|
3749
3766
|
const treatConstructorAsClassMember = (flags & 16 /* TreatConstructorAsClassMethod */) !== 0;
|
3750
3767
|
let isTypeValid = true;
|
3751
|
-
let
|
3768
|
+
let isAsymmetricAccessor = false;
|
3752
3769
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
3753
3770
|
var _a, _b, _c;
|
3754
3771
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
@@ -3933,7 +3950,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3933
3950
|
// Determine if we're calling __set__ on an asymmetric descriptor or property.
|
3934
3951
|
if (usage.method === 'set' && (0, types_1.isClass)(accessMethod.classType)) {
|
3935
3952
|
if (isAsymmetricDescriptorClass(accessMethod.classType)) {
|
3936
|
-
|
3953
|
+
isAsymmetricAccessor = true;
|
3937
3954
|
}
|
3938
3955
|
}
|
3939
3956
|
if (returnType) {
|
@@ -3968,16 +3985,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3968
3985
|
// If this function is an instance member (e.g. a lambda that was
|
3969
3986
|
// assigned to an instance variable), don't perform any binding.
|
3970
3987
|
if (!isAccessedThroughObject || (memberInfo && !memberInfo.isInstanceMember)) {
|
3971
|
-
// Skip binding if the class appears to be a metaclass (i.e. a subclass of
|
3972
|
-
// `type`) because the first parameter of instance methods in a metaclass
|
3973
|
-
// are not `self` instances.
|
3974
|
-
const isMetaclass = !isAccessedThroughObject &&
|
3975
|
-
(0, types_1.isClass)(baseTypeClass) &&
|
3976
|
-
(flags & 16 /* TreatConstructorAsClassMethod */) === 0 &&
|
3977
|
-
baseTypeClass.details.mro.some((mroType) => (0, types_1.isClass)(mroType) && types_1.ClassType.isBuiltIn(mroType, 'type'));
|
3978
|
-
if (isMetaclass) {
|
3979
|
-
return concreteSubtype;
|
3980
|
-
}
|
3981
3988
|
return bindFunctionToClassOrObject(isAccessedThroughObject ? types_1.ClassType.cloneAsInstance(baseTypeClass) : baseTypeClass, concreteSubtype, memberInfo && (0, types_1.isInstantiableClass)(memberInfo.classType) ? memberInfo.classType : undefined, errorNode,
|
3982
3989
|
/* recursionCount */ undefined, treatConstructorAsClassMember, bindToType);
|
3983
3990
|
}
|
@@ -4047,7 +4054,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4047
4054
|
if (!isTypeValid) {
|
4048
4055
|
return undefined;
|
4049
4056
|
}
|
4050
|
-
return { type,
|
4057
|
+
return { type, isAsymmetricAccessor };
|
4051
4058
|
}
|
4052
4059
|
function isAsymmetricDescriptorClass(classType) {
|
4053
4060
|
var _a;
|
@@ -4081,6 +4088,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4081
4088
|
classType.isAsymmetricDescriptor = isAsymmetric;
|
4082
4089
|
return isAsymmetric;
|
4083
4090
|
}
|
4091
|
+
function isClassWithAsymmetricAttributeAccessor(classType) {
|
4092
|
+
var _a;
|
4093
|
+
// If the value has already been cached in this type, return the cached value.
|
4094
|
+
if (classType.isAsymmetricAttributeAccessor !== undefined) {
|
4095
|
+
return classType.isAsymmetricAttributeAccessor;
|
4096
|
+
}
|
4097
|
+
let isAsymmetric = false;
|
4098
|
+
const getterSymbolResult = (0, typeUtils_1.lookUpClassMember)(classType, '__getattr__', 2 /* SkipBaseClasses */);
|
4099
|
+
const setterSymbolResult = (0, typeUtils_1.lookUpClassMember)(classType, '__setattr__', 2 /* SkipBaseClasses */);
|
4100
|
+
if (!getterSymbolResult || !setterSymbolResult) {
|
4101
|
+
isAsymmetric = false;
|
4102
|
+
}
|
4103
|
+
else {
|
4104
|
+
const getterType = getEffectiveTypeOfSymbol(getterSymbolResult.symbol);
|
4105
|
+
const setterType = getEffectiveTypeOfSymbol(setterSymbolResult.symbol);
|
4106
|
+
// If either the setter or getter is an overload (or some other non-function type),
|
4107
|
+
// conservatively assume that it's not asymmetric.
|
4108
|
+
if ((0, types_1.isFunction)(getterType) && (0, types_1.isFunction)(setterType)) {
|
4109
|
+
// If there's no declared return type on the getter, assume it's symmetric.
|
4110
|
+
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
4111
|
+
const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
|
4112
|
+
const getterReturnType = (_a = types_1.FunctionType.getSpecializedReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4113
|
+
if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
|
4114
|
+
isAsymmetric = true;
|
4115
|
+
}
|
4116
|
+
}
|
4117
|
+
}
|
4118
|
+
}
|
4119
|
+
// Cache the value for next time.
|
4120
|
+
classType.isAsymmetricAttributeAccessor = isAsymmetric;
|
4121
|
+
return isAsymmetric;
|
4122
|
+
}
|
4084
4123
|
// Applies the __getattr__, __setattr__ or __delattr__ method if present.
|
4085
4124
|
function applyAttributeAccessOverride(classType, errorNode, usage, memberName) {
|
4086
4125
|
var _a, _b, _c, _d, _e;
|
@@ -4135,7 +4174,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4135
4174
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
|
4136
4175
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
4137
4176
|
/* skipUnknownArgCheck */ true);
|
4138
|
-
|
4177
|
+
let isAsymmetricAccessor = false;
|
4178
|
+
if (usage.method === 'set') {
|
4179
|
+
isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
|
4180
|
+
}
|
4181
|
+
return {
|
4182
|
+
type: (_e = callResult.returnType) !== null && _e !== void 0 ? _e : types_1.UnknownType.create(),
|
4183
|
+
isAsymmetricAccessor,
|
4184
|
+
};
|
4139
4185
|
}
|
4140
4186
|
}
|
4141
4187
|
}
|
@@ -4471,6 +4517,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4471
4517
|
let isIncomplete = baseTypeResult.isIncomplete;
|
4472
4518
|
let isRequired = false;
|
4473
4519
|
let isNotRequired = false;
|
4520
|
+
let isReadOnly = false;
|
4474
4521
|
const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
|
4475
4522
|
/* conditionFilter */ undefined, (concreteSubtype, unexpandedSubtype) => {
|
4476
4523
|
var _a;
|
@@ -4577,6 +4624,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4577
4624
|
else if (result.isNotRequired) {
|
4578
4625
|
isNotRequired = true;
|
4579
4626
|
}
|
4627
|
+
if (result.isReadOnly) {
|
4628
|
+
isReadOnly = true;
|
4629
|
+
}
|
4580
4630
|
return result.type;
|
4581
4631
|
}
|
4582
4632
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
@@ -4608,7 +4658,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4608
4658
|
}
|
4609
4659
|
});
|
4610
4660
|
}
|
4611
|
-
return { type, isIncomplete, isRequired, isNotRequired };
|
4661
|
+
return { type, isIncomplete, isReadOnly, isRequired, isNotRequired };
|
4612
4662
|
}
|
4613
4663
|
// Determines the effective variance of the type parameters for a generic
|
4614
4664
|
// type alias. Normally, variance is not important for type aliases, but
|
@@ -5059,7 +5109,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5059
5109
|
}
|
5060
5110
|
if (!matchingSubtype) {
|
5061
5111
|
const subtypeResult = useSpeculativeMode(node, () => {
|
5062
|
-
return getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype
|
5112
|
+
return getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
|
5063
5113
|
});
|
5064
5114
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
5065
5115
|
matchingSubtype = subtype;
|
@@ -5070,7 +5120,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5070
5120
|
}
|
5071
5121
|
let expectedTypeDiagAddendum;
|
5072
5122
|
if (effectiveExpectedType) {
|
5073
|
-
const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType
|
5123
|
+
const result = getTypeOfTupleWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
5074
5124
|
if (result && !result.typeErrors) {
|
5075
5125
|
return result;
|
5076
5126
|
}
|
@@ -5246,6 +5296,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5246
5296
|
}
|
5247
5297
|
}
|
5248
5298
|
else {
|
5299
|
+
// Check for an attempt to invoke an abstract static or class method.
|
5300
|
+
if ((0, types_1.isFunction)(baseTypeResult.type) &&
|
5301
|
+
baseTypeResult.type.boundToType &&
|
5302
|
+
(0, types_1.isInstantiableClass)(baseTypeResult.type.boundToType) &&
|
5303
|
+
!baseTypeResult.type.boundToType.includeSubclasses) {
|
5304
|
+
if (types_1.FunctionType.isAbstractMethod(baseTypeResult.type)) {
|
5305
|
+
if (types_1.FunctionType.isStaticMethod(baseTypeResult.type) ||
|
5306
|
+
types_1.FunctionType.isClassMethod(baseTypeResult.type)) {
|
5307
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.abstractMethodInvocation().format({
|
5308
|
+
method: baseTypeResult.type.details.name,
|
5309
|
+
}), node.leftExpression);
|
5310
|
+
}
|
5311
|
+
}
|
5312
|
+
}
|
5249
5313
|
const callResult = validateCallArguments(node, argList, baseTypeResult,
|
5250
5314
|
/* typeVarContext */ undefined,
|
5251
5315
|
/* skipUnknownArgCheck */ false, inferenceContext);
|
@@ -6059,7 +6123,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6059
6123
|
if (functionResult.isTypeIncomplete) {
|
6060
6124
|
isTypeIncomplete = true;
|
6061
6125
|
}
|
6062
|
-
|
6126
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
|
6063
6127
|
if (functionResult.argumentErrors) {
|
6064
6128
|
argumentErrors = true;
|
6065
6129
|
}
|
@@ -6105,7 +6169,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6105
6169
|
return (0, typeUtils_1.convertToInstance)(castToType);
|
6106
6170
|
}
|
6107
6171
|
const functionResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6108
|
-
|
6172
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
|
6109
6173
|
if (functionResult.isTypeIncomplete) {
|
6110
6174
|
isTypeIncomplete = true;
|
6111
6175
|
}
|
@@ -6169,13 +6233,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6169
6233
|
return types_1.AnyType.create();
|
6170
6234
|
}
|
6171
6235
|
if (className === 'TypeVar') {
|
6172
|
-
return createTypeVarType(errorNode, argList);
|
6236
|
+
return createTypeVarType(errorNode, expandedSubtype, argList);
|
6173
6237
|
}
|
6174
6238
|
if (className === 'TypeVarTuple') {
|
6175
|
-
return createTypeVarTupleType(errorNode, argList);
|
6239
|
+
return createTypeVarTupleType(errorNode, expandedSubtype, argList);
|
6176
6240
|
}
|
6177
6241
|
if (className === 'ParamSpec') {
|
6178
|
-
return createParamSpecType(errorNode, argList);
|
6242
|
+
return createParamSpecType(errorNode, expandedSubtype, argList);
|
6243
|
+
}
|
6244
|
+
if (className === 'TypeAliasType') {
|
6245
|
+
const newTypeAlias = createTypeAliasType(errorNode, argList);
|
6246
|
+
if (newTypeAlias) {
|
6247
|
+
return newTypeAlias;
|
6248
|
+
}
|
6179
6249
|
}
|
6180
6250
|
if (className === 'NamedTuple') {
|
6181
6251
|
return (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList,
|
@@ -6241,7 +6311,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6241
6311
|
}
|
6242
6312
|
// Assume this is a call to the constructor.
|
6243
6313
|
const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedSubtype, skipUnknownArgCheck, inferenceContext);
|
6244
|
-
|
6314
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, constructorResult.overloadsUsedForCall);
|
6245
6315
|
if (constructorResult.argumentErrors) {
|
6246
6316
|
argumentErrors = true;
|
6247
6317
|
}
|
@@ -6284,7 +6354,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6284
6354
|
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */)) === null || _e === void 0 ? void 0 : _e.type;
|
6285
6355
|
if (memberType) {
|
6286
6356
|
const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6287
|
-
|
6357
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
|
6288
6358
|
if (functionResult.argumentErrors) {
|
6289
6359
|
argumentErrors = true;
|
6290
6360
|
}
|
@@ -6329,7 +6399,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6329
6399
|
case 10 /* TypeVar */: {
|
6330
6400
|
expandedSubtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedSubtype);
|
6331
6401
|
const callResult = validateCallArguments(errorNode, argList, { type: expandedSubtype }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6332
|
-
|
6402
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, callResult.overloadsUsedForCall);
|
6333
6403
|
if (callResult.argumentErrors) {
|
6334
6404
|
argumentErrors = true;
|
6335
6405
|
}
|
@@ -7033,7 +7103,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7033
7103
|
// (i.e. an arg starting with a "**"), we will assume that all parameters
|
7034
7104
|
// are matched.
|
7035
7105
|
if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(typeResult.type)) {
|
7036
|
-
const unassignedParams =
|
7106
|
+
const unassignedParams = Array.from(paramMap.keys()).filter((name) => {
|
7037
7107
|
const entry = paramMap.get(name);
|
7038
7108
|
return !entry || entry.argsReceived < entry.argsNeeded;
|
7039
7109
|
});
|
@@ -7215,18 +7285,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7215
7285
|
// Prepopulate the typeVarContext based on the specialized expected type if the
|
7216
7286
|
// callee has a declared return type. This will allow us to more closely match
|
7217
7287
|
// the expected type if possible.
|
7218
|
-
//
|
7219
|
-
|
7220
|
-
|
7221
|
-
|
7222
|
-
(0, types_1.
|
7223
|
-
|
7224
|
-
|
7225
|
-
|
7226
|
-
|
7227
|
-
|
7228
|
-
|
7229
|
-
|
7288
|
+
// Determine which type arguments are needed to match the expected type.
|
7289
|
+
if ((0, types_1.isClassInstance)(effectiveReturnType)) {
|
7290
|
+
// If the return type is a class and the expected type is a union that contains
|
7291
|
+
// that class, see if we can eliminate the other subtypes in the union.
|
7292
|
+
if ((0, types_1.isUnion)(effectiveExpectedType)) {
|
7293
|
+
const filteredType = (0, typeUtils_1.mapSubtypes)(effectiveExpectedType, (subtype) => {
|
7294
|
+
return (0, types_1.isClassInstance)(subtype) && types_1.ClassType.isSameGenericClass(effectiveReturnType, subtype)
|
7295
|
+
? subtype
|
7296
|
+
: undefined;
|
7297
|
+
});
|
7298
|
+
if ((0, types_1.isClassInstance)(filteredType)) {
|
7299
|
+
effectiveExpectedType = filteredType;
|
7300
|
+
}
|
7301
|
+
}
|
7302
|
+
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7303
|
+
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7304
|
+
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, ParseTreeUtils.getTypeVarScopesForNode(errorNode));
|
7305
|
+
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7306
|
+
/* typeArguments */ undefined,
|
7307
|
+
/* isTypeArgumentExplicit */ false);
|
7308
|
+
effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext);
|
7309
|
+
}
|
7230
7310
|
}
|
7231
7311
|
else if ((0, types_1.isFunction)(effectiveReturnType)) {
|
7232
7312
|
// If the return type is a callable and the expected type is a union that
|
@@ -7336,7 +7416,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7336
7416
|
// If we skipped a overload arg during the first pass,
|
7337
7417
|
// add another pass to ensure that we handle all of the
|
7338
7418
|
// type variables.
|
7339
|
-
if (i === 0 && argResult.skippedOverloadArg) {
|
7419
|
+
if (i === 0 && (argResult.skippedOverloadArg || argResult.skippedBareTypeVarExpectedType)) {
|
7340
7420
|
passCount++;
|
7341
7421
|
}
|
7342
7422
|
});
|
@@ -7444,11 +7524,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7444
7524
|
if (typeVarScopes.some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope))) {
|
7445
7525
|
unknownIfNotFound = false;
|
7446
7526
|
}
|
7447
|
-
let specializedReturnType = (0, typeUtils_1.
|
7527
|
+
let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
7448
7528
|
unknownIfNotFound,
|
7449
7529
|
useUnknownOverDefault: skipUnknownArgCheck,
|
7450
7530
|
eliminateUnsolvedInUnions,
|
7451
|
-
|
7531
|
+
applyInScopePlaceholders: true,
|
7532
|
+
});
|
7533
|
+
specializedReturnType = (0, typeUtils_1.addConditionToType)(specializedReturnType, typeCondition);
|
7452
7534
|
// If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
|
7453
7535
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
7454
7536
|
specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpackedTuple */ false);
|
@@ -7559,6 +7641,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7559
7641
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecNotBound().format({ type: printType(paramSpec) }), ((_a = argList[0]) === null || _a === void 0 ? void 0 : _a.valueExpression) || errorNode);
|
7560
7642
|
return false;
|
7561
7643
|
}
|
7644
|
+
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
7562
7645
|
const srcTypeVarContext = new typeVarContext_1.TypeVarContext(paramSpecType.details.typeVarScopeId);
|
7563
7646
|
let reportedArgError = false;
|
7564
7647
|
// Build a map of all named parameters.
|
@@ -7621,7 +7704,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7621
7704
|
if (paramType) {
|
7622
7705
|
const argResult = validateArgType({
|
7623
7706
|
paramCategory: 0 /* Simple */,
|
7624
|
-
paramType,
|
7707
|
+
paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes),
|
7625
7708
|
requiresTypeVarMatching: false,
|
7626
7709
|
argument: arg,
|
7627
7710
|
errorNode: arg.valueExpression || errorNode,
|
@@ -7654,7 +7737,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7654
7737
|
});
|
7655
7738
|
// Report any missing parameters.
|
7656
7739
|
if (!reportedArgError) {
|
7657
|
-
let unassignedParams =
|
7740
|
+
let unassignedParams = Array.from(paramMap.keys());
|
7658
7741
|
// Parameters that have defaults can be left unspecified.
|
7659
7742
|
unassignedParams = unassignedParams.filter((name) => {
|
7660
7743
|
const paramInfo = paramMap.get(name);
|
@@ -7672,7 +7755,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7672
7755
|
}
|
7673
7756
|
}
|
7674
7757
|
if (!reportedArgError) {
|
7675
|
-
|
7758
|
+
(0, typeUtils_1.applySourceContextTypeVarsToSignature)(typeVarContext, srcTypeVarContext);
|
7676
7759
|
}
|
7677
7760
|
return !reportedArgError;
|
7678
7761
|
}
|
@@ -7683,14 +7766,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7683
7766
|
let isTypeIncomplete = !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete);
|
7684
7767
|
let isCompatible = true;
|
7685
7768
|
const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
|
7769
|
+
let skippedBareTypeVarExpectedType = false;
|
7686
7770
|
if (argParam.argument.valueExpression) {
|
7687
7771
|
let expectedType;
|
7688
|
-
|
7689
|
-
|
7690
|
-
argParam.paramType
|
7691
|
-
|
7692
|
-
|
7693
|
-
|
7772
|
+
const isBareTypeVarExpectedType = (0, types_1.isTypeVar)(argParam.paramType) && argParam.paramType.scopeId === (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId);
|
7773
|
+
if (!options.skipBareTypeVarExpectedType || !isBareTypeVarExpectedType) {
|
7774
|
+
expectedType = argParam.paramType;
|
7775
|
+
// If the parameter type is a function with a ParamSpec, don't apply
|
7776
|
+
// the solved TypeVars if the typeVarContext has more than one signature.
|
7777
|
+
// This will expand the ParamSpec into an overload, which will cause problems.
|
7778
|
+
const skipApplySolvedTypeVars = (0, types_1.isFunction)(argParam.paramType) &&
|
7779
|
+
!!argParam.paramType.details.paramSpec &&
|
7780
|
+
typeVarContext.getSignatureContexts().length > 1;
|
7781
|
+
if (!skipApplySolvedTypeVars) {
|
7782
|
+
expectedType = (0, typeUtils_1.applySolvedTypeVars)(expectedType, typeVarContext, {
|
7783
|
+
useNarrowBoundOnly: !!options.useNarrowBoundOnly,
|
7784
|
+
});
|
7785
|
+
}
|
7786
|
+
}
|
7787
|
+
else {
|
7788
|
+
skippedBareTypeVarExpectedType = true;
|
7694
7789
|
}
|
7695
7790
|
// If the expected type is unknown, don't use an expected type. Instead,
|
7696
7791
|
// use default rules for evaluating the expression type.
|
@@ -7707,14 +7802,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7707
7802
|
32 /* DisallowParamSpec */ |
|
7708
7803
|
64 /* DisallowTypeVarTuple */
|
7709
7804
|
: 0 /* None */;
|
7710
|
-
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType,
|
7805
|
+
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)));
|
7711
7806
|
argType = exprTypeResult.type;
|
7807
|
+
// If the type includes multiple instances of a generic function
|
7808
|
+
// signature, force the type arguments for the duplicates to have
|
7809
|
+
// unique names.
|
7810
|
+
argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker);
|
7712
7811
|
if (exprTypeResult.isIncomplete) {
|
7713
7812
|
isTypeIncomplete = true;
|
7714
7813
|
}
|
7715
7814
|
if (exprTypeResult.typeErrors) {
|
7716
7815
|
isCompatible = false;
|
7717
7816
|
}
|
7817
|
+
else if (expectedType && (0, typeUtils_1.requiresSpecialization)(expectedType)) {
|
7818
|
+
// Assign the argument type back to the expected type to assign
|
7819
|
+
// values to any in-scope placeholder type variables.
|
7820
|
+
const typeVarContextClone = typeVarContext.clone();
|
7821
|
+
if (assignType(expectedType, argType, /* diag */ undefined, typeVarContextClone)) {
|
7822
|
+
typeVarContext.copyFromClone(typeVarContextClone);
|
7823
|
+
}
|
7824
|
+
else {
|
7825
|
+
isCompatible = false;
|
7826
|
+
}
|
7827
|
+
}
|
7718
7828
|
expectedTypeDiag = exprTypeResult.expectedTypeDiagAddendum;
|
7719
7829
|
}
|
7720
7830
|
if (argParam.argument && argParam.argument.name && !isSpeculativeModeInUse(argParam.errorNode)) {
|
@@ -7743,10 +7853,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7743
7853
|
}
|
7744
7854
|
}
|
7745
7855
|
}
|
7746
|
-
// If the type includes multiple instances of a generic function
|
7747
|
-
// signature, force the type arguments for the duplicates to have
|
7748
|
-
// unique names.
|
7749
|
-
argType = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(argType, signatureTracker);
|
7750
7856
|
// If we're assigning to a var arg dictionary with a TypeVar type,
|
7751
7857
|
// strip literals before performing the assignment. This is used in
|
7752
7858
|
// places like a dict constructor.
|
@@ -7778,14 +7884,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7778
7884
|
// an overloaded callback protocol.
|
7779
7885
|
if (options.skipOverloadArg) {
|
7780
7886
|
if ((0, types_1.isOverloadedFunction)(argType)) {
|
7781
|
-
return {
|
7887
|
+
return {
|
7888
|
+
isCompatible,
|
7889
|
+
argType,
|
7890
|
+
isTypeIncomplete,
|
7891
|
+
skippedOverloadArg: true,
|
7892
|
+
skippedBareTypeVarExpectedType,
|
7893
|
+
condition,
|
7894
|
+
};
|
7782
7895
|
}
|
7783
7896
|
const concreteParamType = makeTopLevelTypeVarsConcrete(argParam.paramType);
|
7784
7897
|
if ((0, types_1.isFunction)(concreteParamType) || (0, types_1.isOverloadedFunction)(concreteParamType)) {
|
7785
7898
|
if ((0, types_1.isInstantiableClass)(argType)) {
|
7786
7899
|
const constructor = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, argType);
|
7787
7900
|
if (constructor && (0, types_1.isOverloadedFunction)(constructor)) {
|
7788
|
-
return {
|
7901
|
+
return {
|
7902
|
+
isCompatible,
|
7903
|
+
argType,
|
7904
|
+
isTypeIncomplete,
|
7905
|
+
skippedOverloadArg: true,
|
7906
|
+
skippedBareTypeVarExpectedType,
|
7907
|
+
condition,
|
7908
|
+
};
|
7789
7909
|
}
|
7790
7910
|
}
|
7791
7911
|
if ((0, types_1.isClassInstance)(argType)) {
|
@@ -7793,7 +7913,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7793
7913
|
if (callMember) {
|
7794
7914
|
const memberType = getTypeOfMember(callMember);
|
7795
7915
|
if ((0, types_1.isOverloadedFunction)(memberType)) {
|
7796
|
-
return {
|
7916
|
+
return {
|
7917
|
+
isCompatible,
|
7918
|
+
argType,
|
7919
|
+
isTypeIncomplete,
|
7920
|
+
skippedOverloadArg: true,
|
7921
|
+
skippedBareTypeVarExpectedType,
|
7922
|
+
condition,
|
7923
|
+
};
|
7797
7924
|
}
|
7798
7925
|
}
|
7799
7926
|
}
|
@@ -7850,7 +7977,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7850
7977
|
}
|
7851
7978
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), argParam.errorNode, (_a = diag.getEffectiveTextRange()) !== null && _a !== void 0 ? _a : argParam.errorNode);
|
7852
7979
|
}
|
7853
|
-
return { isCompatible: false, argType, isTypeIncomplete, condition };
|
7980
|
+
return { isCompatible: false, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
|
7854
7981
|
}
|
7855
7982
|
if (!options.skipUnknownArgCheck) {
|
7856
7983
|
const simplifiedType = (0, types_1.removeUnbound)(argType);
|
@@ -7906,9 +8033,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7906
8033
|
}
|
7907
8034
|
}
|
7908
8035
|
}
|
7909
|
-
return { isCompatible, argType, isTypeIncomplete, condition };
|
8036
|
+
return { isCompatible, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
|
7910
8037
|
}
|
7911
|
-
function createTypeVarType(errorNode, argList) {
|
8038
|
+
function createTypeVarType(errorNode, classType, argList) {
|
7912
8039
|
var _a, _b, _c, _d, _e, _f, _g;
|
7913
8040
|
let typeVarName = '';
|
7914
8041
|
let firstConstraintArg;
|
@@ -7981,8 +8108,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7981
8108
|
}
|
7982
8109
|
else if (paramName === 'default') {
|
7983
8110
|
defaultValueNode = argList[i].valueExpression;
|
7984
|
-
const argType = (_d = (_c = argList[i].typeResult) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : getTypeOfExpressionExpectingType(
|
8111
|
+
const argType = (_d = (_c = argList[i].typeResult) === null || _c === void 0 ? void 0 : _c.type) !== null && _d !== void 0 ? _d : getTypeOfExpressionExpectingType(defaultValueNode, {
|
8112
|
+
allowTypeVarsWithoutScopeId: true,
|
8113
|
+
}).type;
|
7985
8114
|
typeVar.details.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
8115
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8116
|
+
if (!fileInfo.isStubFile &&
|
8117
|
+
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8118
|
+
classType.details.moduleName !== 'typing_extensions') {
|
8119
|
+
addError(localize_1.Localizer.Diagnostic.typeVarDefaultIllegal(), defaultValueNode);
|
8120
|
+
}
|
7986
8121
|
}
|
7987
8122
|
else {
|
7988
8123
|
addError(localize_1.Localizer.Diagnostic.typeVarUnknownParam().format({ name: paramName }), ((_e = argList[i].node) === null || _e === void 0 ? void 0 : _e.name) || argList[i].valueExpression || errorNode);
|
@@ -8028,7 +8163,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8028
8163
|
}
|
8029
8164
|
return typeVar;
|
8030
8165
|
}
|
8031
|
-
function createTypeVarTupleType(errorNode, argList) {
|
8166
|
+
function createTypeVarTupleType(errorNode, classType, argList) {
|
8032
8167
|
var _a, _b;
|
8033
8168
|
let typeVarName = '';
|
8034
8169
|
if (argList.length === 0) {
|
@@ -8054,6 +8189,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8054
8189
|
if (expr) {
|
8055
8190
|
typeVar.details.defaultType = getTypeVarTupleDefaultType(expr);
|
8056
8191
|
}
|
8192
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8193
|
+
if (!fileInfo.isStubFile &&
|
8194
|
+
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8195
|
+
classType.details.moduleName !== 'typing_extensions') {
|
8196
|
+
addError(localize_1.Localizer.Diagnostic.typeVarDefaultIllegal(), expr);
|
8197
|
+
}
|
8057
8198
|
}
|
8058
8199
|
else {
|
8059
8200
|
addError(localize_1.Localizer.Diagnostic.typeVarTupleUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
|
@@ -8063,7 +8204,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8063
8204
|
return typeVar;
|
8064
8205
|
}
|
8065
8206
|
function getTypeVarTupleDefaultType(node) {
|
8066
|
-
const argType = getTypeOfExpressionExpectingType(node, {
|
8207
|
+
const argType = getTypeOfExpressionExpectingType(node, {
|
8208
|
+
allowUnpackedTuple: true,
|
8209
|
+
allowTypeVarsWithoutScopeId: true,
|
8210
|
+
}).type;
|
8067
8211
|
const isUnpackedTuple = (0, types_1.isClass)(argType) && (0, typeUtils_1.isTupleClass)(argType) && argType.isUnpacked;
|
8068
8212
|
const isUnpackedTypeVarTuple = (0, types_1.isUnpackedVariadicTypeVar)(argType);
|
8069
8213
|
if (!isUnpackedTuple && !isUnpackedTypeVarTuple) {
|
@@ -8072,7 +8216,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8072
8216
|
}
|
8073
8217
|
return (0, typeUtils_1.convertToInstance)(argType);
|
8074
8218
|
}
|
8075
|
-
function createParamSpecType(errorNode, argList) {
|
8219
|
+
function createParamSpecType(errorNode, classType, argList) {
|
8076
8220
|
if (argList.length === 0) {
|
8077
8221
|
addError(localize_1.Localizer.Diagnostic.paramSpecFirstArg(), errorNode);
|
8078
8222
|
return undefined;
|
@@ -8096,6 +8240,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8096
8240
|
if (expr) {
|
8097
8241
|
paramSpec.details.defaultType = getParamSpecDefaultType(expr);
|
8098
8242
|
}
|
8243
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8244
|
+
if (!fileInfo.isStubFile &&
|
8245
|
+
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
8246
|
+
classType.details.moduleName !== 'typing_extensions') {
|
8247
|
+
addError(localize_1.Localizer.Diagnostic.typeVarDefaultIllegal(), expr);
|
8248
|
+
}
|
8099
8249
|
}
|
8100
8250
|
else {
|
8101
8251
|
addError(localize_1.Localizer.Diagnostic.paramSpecUnknownParam().format({ name: paramName }), paramNameNode || argList[i].valueExpression || errorNode);
|
@@ -8117,7 +8267,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8117
8267
|
}
|
8118
8268
|
if (node.nodeType === 31 /* List */) {
|
8119
8269
|
node.entries.forEach((paramExpr, index) => {
|
8120
|
-
const typeResult = getTypeOfExpressionExpectingType(paramExpr);
|
8270
|
+
const typeResult = getTypeOfExpressionExpectingType(paramExpr, { allowTypeVarsWithoutScopeId: true });
|
8121
8271
|
types_1.FunctionType.addParameter(functionType, {
|
8122
8272
|
category: 0 /* Simple */,
|
8123
8273
|
name: `__p${index}`,
|
@@ -8132,7 +8282,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8132
8282
|
return functionType;
|
8133
8283
|
}
|
8134
8284
|
else {
|
8135
|
-
const typeResult = getTypeOfExpressionExpectingType(node, {
|
8285
|
+
const typeResult = getTypeOfExpressionExpectingType(node, {
|
8286
|
+
allowParamSpec: true,
|
8287
|
+
allowTypeVarsWithoutScopeId: true,
|
8288
|
+
});
|
8136
8289
|
if (typeResult.typeErrors) {
|
8137
8290
|
return undefined;
|
8138
8291
|
}
|
@@ -8144,6 +8297,91 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8144
8297
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
|
8145
8298
|
return undefined;
|
8146
8299
|
}
|
8300
|
+
// Handles a call to TypeAliasType(). This special form allows a caller to programmatically
|
8301
|
+
// create a type alias as defined in PEP 695. If one or more of the arguments is incorrect,
|
8302
|
+
// it returns undefined so the normal constructor evaluation can be performed (and type errors
|
8303
|
+
// emitted).
|
8304
|
+
function createTypeAliasType(errorNode, argList) {
|
8305
|
+
if (errorNode.nodeType !== 9 /* Call */ || !errorNode.parent || argList.length < 2) {
|
8306
|
+
return undefined;
|
8307
|
+
}
|
8308
|
+
if (errorNode.parent.nodeType !== 3 /* Assignment */ ||
|
8309
|
+
errorNode.parent.rightExpression !== errorNode ||
|
8310
|
+
errorNode.parent.leftExpression.nodeType !== 38 /* Name */) {
|
8311
|
+
addError(localize_1.Localizer.Diagnostic.typeAliasTypeMustBeAssigned(), errorNode);
|
8312
|
+
return undefined;
|
8313
|
+
}
|
8314
|
+
const nameNode = errorNode.parent.leftExpression;
|
8315
|
+
const firstArg = argList[0];
|
8316
|
+
if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* StringList */) {
|
8317
|
+
const typeAliasName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8318
|
+
if (typeAliasName !== nameNode.value) {
|
8319
|
+
addError(localize_1.Localizer.Diagnostic.typeAliasTypeNameMismatch(), firstArg.valueExpression);
|
8320
|
+
}
|
8321
|
+
}
|
8322
|
+
else {
|
8323
|
+
addError(localize_1.Localizer.Diagnostic.typeAliasTypeNameArg(), firstArg.valueExpression || errorNode);
|
8324
|
+
return undefined;
|
8325
|
+
}
|
8326
|
+
let valueExpr;
|
8327
|
+
let typeParamsExpr;
|
8328
|
+
// Parse the remaining parameters.
|
8329
|
+
for (let i = 1; i < argList.length; i++) {
|
8330
|
+
const paramNameNode = argList[i].name;
|
8331
|
+
const paramName = paramNameNode ? paramNameNode.value : undefined;
|
8332
|
+
if (paramName) {
|
8333
|
+
if (paramName === 'type_params' && !typeParamsExpr) {
|
8334
|
+
typeParamsExpr = argList[i].valueExpression;
|
8335
|
+
}
|
8336
|
+
else if (paramName === 'value' && !valueExpr) {
|
8337
|
+
valueExpr = argList[i].valueExpression;
|
8338
|
+
}
|
8339
|
+
else {
|
8340
|
+
return undefined;
|
8341
|
+
}
|
8342
|
+
}
|
8343
|
+
else if (i === 1) {
|
8344
|
+
valueExpr = argList[i].valueExpression;
|
8345
|
+
}
|
8346
|
+
else {
|
8347
|
+
return undefined;
|
8348
|
+
}
|
8349
|
+
}
|
8350
|
+
// The value expression is not optional, so bail if it's not present.
|
8351
|
+
if (!valueExpr) {
|
8352
|
+
return undefined;
|
8353
|
+
}
|
8354
|
+
let typeParameters;
|
8355
|
+
if (typeParamsExpr) {
|
8356
|
+
if (typeParamsExpr.nodeType !== 52 /* Tuple */) {
|
8357
|
+
addError(localize_1.Localizer.Diagnostic.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8358
|
+
return undefined;
|
8359
|
+
}
|
8360
|
+
typeParameters = [];
|
8361
|
+
let isTypeParamListValid = true;
|
8362
|
+
typeParamsExpr.expressions.map((expr) => {
|
8363
|
+
let entryType = getTypeOfExpression(expr, 128 /* ExpectingType */).type;
|
8364
|
+
if ((0, types_1.isTypeVar)(entryType)) {
|
8365
|
+
if (entryType.scopeId) {
|
8366
|
+
isTypeParamListValid = false;
|
8367
|
+
}
|
8368
|
+
else {
|
8369
|
+
entryType = types_1.TypeVarType.cloneForScopeId(entryType, ParseTreeUtils.getScopeIdForNode(nameNode), nameNode.value, 2 /* TypeAlias */);
|
8370
|
+
}
|
8371
|
+
typeParameters.push(entryType);
|
8372
|
+
}
|
8373
|
+
else {
|
8374
|
+
isTypeParamListValid = false;
|
8375
|
+
}
|
8376
|
+
});
|
8377
|
+
if (!isTypeParamListValid) {
|
8378
|
+
addError(localize_1.Localizer.Diagnostic.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8379
|
+
return undefined;
|
8380
|
+
}
|
8381
|
+
}
|
8382
|
+
return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
|
8383
|
+
/* typeParamNodes */ undefined, () => typeParameters);
|
8384
|
+
}
|
8147
8385
|
function getBooleanValue(node) {
|
8148
8386
|
if (node.nodeType === 11 /* Constant */) {
|
8149
8387
|
if (node.constType === 15 /* False */) {
|
@@ -8190,19 +8428,31 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8190
8428
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeBadName(), (_a = argList[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
8191
8429
|
return undefined;
|
8192
8430
|
}
|
8193
|
-
|
8194
|
-
|
8195
|
-
|
8196
|
-
|
8197
|
-
|
8198
|
-
else if (baseClass.literalValue !== undefined) {
|
8199
|
-
addError(localize_1.Localizer.Diagnostic.newTypeLiteral(), argList[1].node || errorNode);
|
8431
|
+
let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
|
8432
|
+
let isBaseClassAny = false;
|
8433
|
+
if ((0, types_1.isAnyOrUnknown)(baseClass)) {
|
8434
|
+
if (objectType && (0, types_1.isClassInstance)(objectType)) {
|
8435
|
+
baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
|
8200
8436
|
}
|
8201
|
-
|
8202
|
-
|
8203
|
-
|
8204
|
-
|
8205
|
-
|
8437
|
+
isBaseClassAny = true;
|
8438
|
+
}
|
8439
|
+
if (!(0, types_1.isInstantiableClass)(baseClass)) {
|
8440
|
+
addError(localize_1.Localizer.Diagnostic.newTypeNotAClass(), argList[1].node || errorNode);
|
8441
|
+
return undefined;
|
8442
|
+
}
|
8443
|
+
if (types_1.ClassType.isProtocolClass(baseClass)) {
|
8444
|
+
addError(localize_1.Localizer.Diagnostic.newTypeProtocolClass(), argList[1].node || errorNode);
|
8445
|
+
}
|
8446
|
+
else if (baseClass.literalValue !== undefined) {
|
8447
|
+
addError(localize_1.Localizer.Diagnostic.newTypeLiteral(), argList[1].node || errorNode);
|
8448
|
+
}
|
8449
|
+
let classFlags = baseClass.details.flags & ~(1 /* BuiltInClass */ | 2 /* SpecialBuiltIn */);
|
8450
|
+
classFlags |= 4096 /* Final */;
|
8451
|
+
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.filePath, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
|
8452
|
+
/* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
|
8453
|
+
classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
|
8454
|
+
(0, typeUtils_1.computeMroLinearization)(classType);
|
8455
|
+
if (!isBaseClassAny) {
|
8206
8456
|
// Synthesize an __init__ method that accepts only the specified type.
|
8207
8457
|
const initType = types_1.FunctionType.createSynthesizedInstance('__init__');
|
8208
8458
|
types_1.FunctionType.addParameter(initType, {
|
@@ -8230,12 +8480,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8230
8480
|
types_1.FunctionType.addDefaultParameters(newType);
|
8231
8481
|
newType.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
|
8232
8482
|
classType.details.fields.set('__new__', symbol_1.Symbol.createWithType(4 /* ClassMember */, newType));
|
8233
|
-
return classType;
|
8234
8483
|
}
|
8235
|
-
|
8236
|
-
addError(localize_1.Localizer.Diagnostic.newTypeNotAClass(), argList[1].node || errorNode);
|
8237
|
-
}
|
8238
|
-
return undefined;
|
8484
|
+
return classType;
|
8239
8485
|
}
|
8240
8486
|
// Implements the semantics of the multi-parameter variant of the "type" call.
|
8241
8487
|
function createType(errorNode, argList) {
|
@@ -8377,7 +8623,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8377
8623
|
return;
|
8378
8624
|
}
|
8379
8625
|
const subtypeResult = useSpeculativeMode(node, () => {
|
8380
|
-
return getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype
|
8626
|
+
return getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
|
8381
8627
|
});
|
8382
8628
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
8383
8629
|
// If this is the first result we're seeing or it's the first result
|
@@ -8393,7 +8639,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8393
8639
|
let expectedTypeDiagAddendum = undefined;
|
8394
8640
|
if (effectiveExpectedType) {
|
8395
8641
|
expectedTypeDiagAddendum = new diagnostic_1.DiagnosticAddendum();
|
8396
|
-
const result = getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType
|
8642
|
+
const result = getTypeOfDictionaryWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType), expectedTypeDiagAddendum);
|
8397
8643
|
if (result) {
|
8398
8644
|
return result;
|
8399
8645
|
}
|
@@ -8450,7 +8696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8450
8696
|
const expectedValueType = specializedDict.typeArguments[1];
|
8451
8697
|
// Infer the key and value types if possible.
|
8452
8698
|
if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
8453
|
-
/* forceStrictInference */ true, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum
|
8699
|
+
/* forceStrictInference */ true, expectedKeyType, expectedValueType, undefined, expectedDiagAddendum)) {
|
8454
8700
|
isIncomplete = true;
|
8455
8701
|
}
|
8456
8702
|
// Dict and MutableMapping types have invariant value types, so they
|
@@ -8459,9 +8705,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8459
8705
|
const isValueTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
8460
8706
|
(types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'dict') ||
|
8461
8707
|
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'MutableMapping'));
|
8462
|
-
const specializedKeyType =
|
8708
|
+
const specializedKeyType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedKeyType), keyTypes.map((result) => result.type),
|
8463
8709
|
/* isNarrowable */ false);
|
8464
|
-
const specializedValueType =
|
8710
|
+
const specializedValueType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedValueType), valueTypes.map((result) => result.type), !isValueTypeInvariant);
|
8465
8711
|
if (!specializedKeyType || !specializedValueType) {
|
8466
8712
|
return undefined;
|
8467
8713
|
}
|
@@ -8518,7 +8764,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8518
8764
|
}
|
8519
8765
|
return { type, isIncomplete };
|
8520
8766
|
}
|
8521
|
-
function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum
|
8767
|
+
function getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes, forceStrictInference, expectedKeyType, expectedValueType, expectedTypedDictEntries, expectedDiagAddendum) {
|
8522
8768
|
let isIncomplete = false;
|
8523
8769
|
// Infer the key and value types if possible.
|
8524
8770
|
node.entries.forEach((entryNode, index) => {
|
@@ -8526,7 +8772,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8526
8772
|
let addUnknown = true;
|
8527
8773
|
if (entryNode.nodeType === 17 /* DictionaryKeyEntry */) {
|
8528
8774
|
const keyTypeResult = getTypeOfExpression(entryNode.keyExpression,
|
8529
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)
|
8775
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedKeyType !== null && expectedKeyType !== void 0 ? expectedKeyType : (forceStrictInference ? types_1.NeverType.createNever() : undefined)));
|
8530
8776
|
if (keyTypeResult.isIncomplete) {
|
8531
8777
|
isIncomplete = true;
|
8532
8778
|
}
|
@@ -8545,12 +8791,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8545
8791
|
expectedTypedDictEntries.has(keyType.literalValue)) {
|
8546
8792
|
const effectiveValueType = expectedTypedDictEntries.get(keyType.literalValue).valueType;
|
8547
8793
|
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
8548
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType
|
8794
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
|
8549
8795
|
}
|
8550
8796
|
else {
|
8551
8797
|
const effectiveValueType = expectedValueType !== null && expectedValueType !== void 0 ? expectedValueType : (forceStrictInference ? types_1.NeverType.createNever() : undefined);
|
8552
8798
|
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
8553
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType
|
8799
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(effectiveValueType));
|
8554
8800
|
}
|
8555
8801
|
if (expectedDiagAddendum && valueTypeResult.expectedTypeDiagAddendum) {
|
8556
8802
|
expectedDiagAddendum.addAddendum(valueTypeResult.expectedTypeDiagAddendum);
|
@@ -8574,7 +8820,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8574
8820
|
}
|
8575
8821
|
}
|
8576
8822
|
const unexpandedTypeResult = getTypeOfExpression(entryNode.expandExpression,
|
8577
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedType
|
8823
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
8578
8824
|
if (unexpandedTypeResult.isIncomplete) {
|
8579
8825
|
isIncomplete = true;
|
8580
8826
|
}
|
@@ -8661,7 +8907,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8661
8907
|
return;
|
8662
8908
|
}
|
8663
8909
|
const subtypeResult = useSpeculativeMode(node, () => {
|
8664
|
-
return getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype
|
8910
|
+
return getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(subtype));
|
8665
8911
|
});
|
8666
8912
|
if (subtypeResult && assignType(subtype, subtypeResult.type)) {
|
8667
8913
|
// If this is the first result we're seeing or it's the first result
|
@@ -8676,7 +8922,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8676
8922
|
}
|
8677
8923
|
let expectedTypeDiagAddendum;
|
8678
8924
|
if (effectiveExpectedType) {
|
8679
|
-
const result = getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType
|
8925
|
+
const result = getTypeOfListOrSetWithContext(node, (0, typeUtils_1.makeInferenceContext)(effectiveExpectedType));
|
8680
8926
|
if (result && !result.typeErrors) {
|
8681
8927
|
return result;
|
8682
8928
|
}
|
@@ -8718,7 +8964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8718
8964
|
}
|
8719
8965
|
else {
|
8720
8966
|
entryTypeResult = getTypeOfExpression(entry,
|
8721
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedEntryType
|
8967
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedEntryType));
|
8722
8968
|
}
|
8723
8969
|
entryTypes.push(entryTypeResult.type);
|
8724
8970
|
if (entryTypeResult.isIncomplete) {
|
@@ -8736,7 +8982,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8736
8982
|
});
|
8737
8983
|
const isTypeInvariant = (0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
8738
8984
|
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, builtInClassName);
|
8739
|
-
const specializedEntryType =
|
8985
|
+
const specializedEntryType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedEntryType), entryTypes, !isTypeInvariant);
|
8740
8986
|
if (!specializedEntryType) {
|
8741
8987
|
return { type: types_1.UnknownType.create(), isIncomplete, typeErrors: true, expectedTypeDiagAddendum };
|
8742
8988
|
}
|
@@ -8819,17 +9065,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8819
9065
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, message + diag.getString(), entry);
|
8820
9066
|
}
|
8821
9067
|
}
|
8822
|
-
function
|
8823
|
-
var _a;
|
9068
|
+
function inferTypeArgFromExpectedEntryType(inferenceContext, entryTypes, isNarrowable) {
|
8824
9069
|
// If the expected type is Any, the resulting type becomes Any.
|
8825
9070
|
if ((0, types_1.isAnyOrUnknown)(inferenceContext.expectedType)) {
|
8826
9071
|
return inferenceContext.expectedType;
|
8827
9072
|
}
|
8828
|
-
const typeVarContext =
|
9073
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
9074
|
+
const expectedType = inferenceContext.expectedType;
|
8829
9075
|
let isCompatible = true;
|
8830
9076
|
entryTypes.forEach((entryType) => {
|
8831
|
-
if (isCompatible &&
|
8832
|
-
!assignType(inferenceContext.expectedType, entryType, /* diag */ undefined, typeVarContext)) {
|
9077
|
+
if (isCompatible && !assignType(expectedType, entryType, /* diag */ undefined, typeVarContext)) {
|
8833
9078
|
isCompatible = false;
|
8834
9079
|
}
|
8835
9080
|
});
|
@@ -8842,10 +9087,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8842
9087
|
? combinedTypes
|
8843
9088
|
: stripLiteralValue(combinedTypes);
|
8844
9089
|
}
|
8845
|
-
|
8846
|
-
return (0, typeUtils_1.applySolvedTypeVars)(inferenceContext.expectedType, typeVarContext);
|
8847
|
-
}
|
8848
|
-
return inferenceContext.expectedType;
|
9090
|
+
return (0, typeUtils_1.applySolvedTypeVars)(inferenceContext.expectedType, typeVarContext, { applyInScopePlaceholders: true });
|
8849
9091
|
}
|
8850
9092
|
function getTypeOfYield(node) {
|
8851
9093
|
let expectedYieldType;
|
@@ -8988,18 +9230,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8988
9230
|
type: types_1.UnknownType.create(),
|
8989
9231
|
});
|
8990
9232
|
}
|
8991
|
-
|
9233
|
+
const expectedReturnType = expectedFunctionType
|
8992
9234
|
? getFunctionEffectiveReturnType(expectedFunctionType)
|
8993
9235
|
: undefined;
|
8994
|
-
if (expectedReturnType && (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.typeVarContext)) {
|
8995
|
-
expectedReturnType = (0, typeUtils_1.applySolvedTypeVars)(expectedReturnType, inferenceContext.typeVarContext);
|
8996
|
-
}
|
8997
9236
|
// If we're speculatively evaluating the lambda, create another speculative
|
8998
9237
|
// evaluation scope for the return expression and do not allow retention
|
8999
9238
|
// of the cached types.
|
9000
9239
|
const inferLambdaReturnType = () => {
|
9001
9240
|
const returnTypeResult = getTypeOfExpression(node.expression,
|
9002
|
-
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType
|
9241
|
+
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
|
9003
9242
|
functionType.inferredReturnType = returnTypeResult.type;
|
9004
9243
|
if (returnTypeResult.isIncomplete) {
|
9005
9244
|
isIncomplete = true;
|
@@ -9572,7 +9811,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9572
9811
|
}
|
9573
9812
|
return (0, typeUtils_1.synthesizeTypeVarForSelfCls)(enclosingClassTypeResult.classType, /* isClsParam */ true);
|
9574
9813
|
}
|
9575
|
-
function
|
9814
|
+
function createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags) {
|
9576
9815
|
// If no type arguments are provided, the resulting type
|
9577
9816
|
// depends on whether we're evaluating a type annotation or
|
9578
9817
|
// we're in some other context.
|
@@ -9580,7 +9819,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9580
9819
|
return { type: classType };
|
9581
9820
|
}
|
9582
9821
|
if (!typeArgs || typeArgs.length !== 1) {
|
9583
|
-
addError(
|
9822
|
+
addError(classType.details.name === 'ReadOnly'
|
9823
|
+
? localize_1.Localizer.Diagnostic.readOnlyArgCount()
|
9824
|
+
: classType.details.name === 'Required'
|
9825
|
+
? localize_1.Localizer.Diagnostic.requiredArgCount()
|
9826
|
+
: localize_1.Localizer.Diagnostic.notRequiredArgCount(), errorNode);
|
9584
9827
|
return { type: classType };
|
9585
9828
|
}
|
9586
9829
|
const typeArgType = typeArgs[0].type;
|
@@ -9599,17 +9842,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9599
9842
|
if ((flags & 1048576 /* AllowRequired */) !== 0) {
|
9600
9843
|
isUsageLegal = true;
|
9601
9844
|
}
|
9602
|
-
|
9603
|
-
|
9604
|
-
|
9845
|
+
let isReadOnly = typeArgs[0].isReadOnly;
|
9846
|
+
let isRequired = typeArgs[0].isRequired;
|
9847
|
+
let isNotRequired = typeArgs[0].isNotRequired;
|
9848
|
+
if (classType.details.name === 'ReadOnly') {
|
9849
|
+
// Nested ReadOnly are not allowed.
|
9850
|
+
if (typeArgs[0].isReadOnly) {
|
9851
|
+
isUsageLegal = false;
|
9852
|
+
}
|
9853
|
+
isReadOnly = true;
|
9854
|
+
}
|
9855
|
+
else {
|
9856
|
+
// Nested Required/NotRequired are not allowed.
|
9857
|
+
if (typeArgs[0].isRequired || typeArgs[0].isNotRequired) {
|
9858
|
+
isUsageLegal = false;
|
9859
|
+
}
|
9860
|
+
isRequired = classType.details.name === 'Required';
|
9861
|
+
isNotRequired = classType.details.name === 'NotRequired';
|
9605
9862
|
}
|
9863
|
+
isRequired = classType.details.name === 'Required';
|
9864
|
+
isNotRequired = classType.details.name === 'NotRequired';
|
9606
9865
|
if (!isUsageLegal) {
|
9607
|
-
addError(
|
9608
|
-
? localize_1.Localizer.Diagnostic.
|
9609
|
-
:
|
9866
|
+
addError(classType.details.name === 'ReadOnly'
|
9867
|
+
? localize_1.Localizer.Diagnostic.readOnlyNotInTypedDict()
|
9868
|
+
: classType.details.name === 'Required'
|
9869
|
+
? localize_1.Localizer.Diagnostic.requiredNotInTypedDict()
|
9870
|
+
: localize_1.Localizer.Diagnostic.notRequiredNotInTypedDict(), errorNode);
|
9610
9871
|
return { type: types_1.ClassType.cloneForSpecialization(classType, [(0, typeUtils_1.convertToInstance)(typeArgType)], !!typeArgs) };
|
9611
9872
|
}
|
9612
|
-
return { type: typeArgType, isRequired, isNotRequired
|
9873
|
+
return { type: typeArgType, isReadOnly, isRequired, isNotRequired };
|
9613
9874
|
}
|
9614
9875
|
function createUnpackType(classType, errorNode, typeArgs, flags) {
|
9615
9876
|
// If no type arguments are provided, the resulting type
|
@@ -9696,6 +9957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9696
9957
|
}
|
9697
9958
|
return {
|
9698
9959
|
type: types_1.TypeBase.cloneForAnnotated(typeArgs[0].type),
|
9960
|
+
isReadOnly: typeArgs[0].isReadOnly,
|
9699
9961
|
isRequired: typeArgs[0].isRequired,
|
9700
9962
|
isNotRequired: typeArgs[0].isNotRequired,
|
9701
9963
|
};
|
@@ -9946,7 +10208,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9946
10208
|
names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
|
9947
10209
|
}), errorNode);
|
9948
10210
|
}
|
9949
|
-
return types_1.TypeBase.cloneForTypeAlias(type, name.value,
|
10211
|
+
return types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, typeParameters.length > 0 ? typeParameters : undefined);
|
9950
10212
|
}
|
9951
10213
|
function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
|
9952
10214
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -9974,7 +10236,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9974
10236
|
// methods that are abstract are overridden and shouldn't
|
9975
10237
|
// cause the TypedDict to be marked as abstract.
|
9976
10238
|
if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, '_TypedDict')) {
|
9977
|
-
baseClass.details.flags &= ~
|
10239
|
+
baseClass.details.flags &= ~1024 /* SupportsAbstractMethods */;
|
9978
10240
|
}
|
9979
10241
|
}
|
9980
10242
|
}
|
@@ -10030,6 +10292,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10030
10292
|
['NoReturn', { alias: '', module: 'builtins' }],
|
10031
10293
|
['Never', { alias: '', module: 'builtins' }],
|
10032
10294
|
['LiteralString', { alias: '', module: 'builtins' }],
|
10295
|
+
['ReadOnly', { alias: '', module: 'builtins' }],
|
10033
10296
|
]);
|
10034
10297
|
const aliasMapEntry = specialTypes.get(assignedName);
|
10035
10298
|
if (aliasMapEntry) {
|
@@ -10190,7 +10453,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10190
10453
|
if (assignType(declaredType, srcType)) {
|
10191
10454
|
// Narrow the resulting type if possible.
|
10192
10455
|
if (!(0, types_1.isAnyOrUnknown)(srcType)) {
|
10193
|
-
srcType = narrowTypeBasedOnAssignment(declaredType, srcType);
|
10456
|
+
srcType = narrowTypeBasedOnAssignment(node, declaredType, srcType);
|
10194
10457
|
}
|
10195
10458
|
}
|
10196
10459
|
}
|
@@ -10260,52 +10523,60 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10260
10523
|
// variables since they use normal variable assignment syntax.
|
10261
10524
|
function getTypeOfTypeAlias(node) {
|
10262
10525
|
var _a;
|
10263
|
-
|
10526
|
+
return getTypeOfTypeAliasCommon(node, node.name, node.expression, (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.parameters, () => {
|
10527
|
+
let typeParameters = [];
|
10528
|
+
if (node.typeParameters) {
|
10529
|
+
typeParameters = evaluateTypeParameterList(node.typeParameters);
|
10530
|
+
}
|
10531
|
+
return typeParameters;
|
10532
|
+
});
|
10533
|
+
}
|
10534
|
+
// This function is common to the handling of "type" statements and explicit
|
10535
|
+
// calls to the TypeAliasType constructor.
|
10536
|
+
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, typeParamNodes, getTypeParamCallback) {
|
10537
|
+
const cachedType = readTypeCache(nameNode, 0 /* None */);
|
10264
10538
|
if (cachedType) {
|
10265
10539
|
return cachedType;
|
10266
10540
|
}
|
10267
10541
|
// Synthesize a type variable that represents the type alias while we're
|
10268
10542
|
// evaluating it. This allows us to handle recursive definitions.
|
10269
|
-
const typeAliasTypeVar = types_1.TypeVarType.createInstantiable(`__type_alias_${
|
10543
|
+
const typeAliasTypeVar = types_1.TypeVarType.createInstantiable(`__type_alias_${nameNode.value}`);
|
10270
10544
|
typeAliasTypeVar.details.isSynthesized = true;
|
10271
|
-
typeAliasTypeVar.details.recursiveTypeAliasName =
|
10272
|
-
const scopeId = ParseTreeUtils.getScopeIdForNode(
|
10545
|
+
typeAliasTypeVar.details.recursiveTypeAliasName = nameNode.value;
|
10546
|
+
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
10273
10547
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10274
10548
|
typeAliasTypeVar.scopeId = scopeId;
|
10275
10549
|
// Write the type to the type cache. It will be replaced below.
|
10276
|
-
writeTypeCache(
|
10550
|
+
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
10277
10551
|
// Set a partial type to handle recursive (self-referential) type aliases.
|
10278
|
-
const scope = ScopeUtils.getScopeForNode(
|
10279
|
-
const typeAliasSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(
|
10280
|
-
const typeAliasDecl = AnalyzerNodeInfo.getDeclaration(
|
10552
|
+
const scope = ScopeUtils.getScopeForNode(declNode);
|
10553
|
+
const typeAliasSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(nameNode.value);
|
10554
|
+
const typeAliasDecl = AnalyzerNodeInfo.getDeclaration(declNode);
|
10281
10555
|
if (typeAliasDecl && typeAliasSymbol) {
|
10282
10556
|
setSymbolResolutionPartialType(typeAliasSymbol.symbol, typeAliasDecl, typeAliasTypeVar);
|
10283
10557
|
}
|
10284
|
-
|
10285
|
-
|
10286
|
-
|
10287
|
-
|
10288
|
-
}
|
10289
|
-
if (!isLegalTypeAliasExpressionForm(node.expression)) {
|
10290
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIllegalExpressionForm(), node.expression);
|
10558
|
+
const typeParameters = getTypeParamCallback();
|
10559
|
+
typeAliasTypeVar.details.recursiveTypeParameters = typeParameters;
|
10560
|
+
if (!isLegalTypeAliasExpressionForm(valueNode)) {
|
10561
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIllegalExpressionForm(), valueNode);
|
10291
10562
|
}
|
10292
|
-
const aliasTypeResult = getTypeOfExpressionExpectingType(
|
10563
|
+
const aliasTypeResult = getTypeOfExpressionExpectingType(valueNode, { allowForwardReference: true });
|
10293
10564
|
let isIncomplete = false;
|
10294
10565
|
let aliasType = aliasTypeResult.type;
|
10295
10566
|
if (aliasTypeResult.isIncomplete) {
|
10296
10567
|
isIncomplete = true;
|
10297
10568
|
}
|
10298
|
-
aliasType = transformTypeForTypeAlias(aliasType,
|
10569
|
+
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, typeParameters, typeParamNodes);
|
10299
10570
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
10300
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(
|
10301
|
-
name:
|
10302
|
-
}),
|
10571
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10572
|
+
name: nameNode.value,
|
10573
|
+
}), valueNode);
|
10303
10574
|
aliasType = types_1.UnknownType.create();
|
10304
10575
|
}
|
10305
10576
|
// Set the resulting type to the boundType of the original type alias
|
10306
10577
|
// to support recursive type aliases.
|
10307
10578
|
typeAliasTypeVar.details.boundType = aliasType;
|
10308
|
-
writeTypeCache(
|
10579
|
+
writeTypeCache(nameNode, { type: aliasType, isIncomplete }, 0 /* None */);
|
10309
10580
|
return aliasType;
|
10310
10581
|
}
|
10311
10582
|
function evaluateTypesForAugmentedAssignment(node) {
|
@@ -10411,7 +10682,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10411
10682
|
argType = types_1.UnknownType.create();
|
10412
10683
|
}
|
10413
10684
|
else {
|
10414
|
-
argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
|
10685
|
+
argType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(arg.valueExpression, exprFlags).type);
|
10415
10686
|
}
|
10416
10687
|
// In some stub files, classes are conditionally defined (e.g. based
|
10417
10688
|
// on platform type). We'll assume that the conditional logic is correct
|
@@ -10508,7 +10779,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10508
10779
|
// built-in protocol classes.
|
10509
10780
|
if (types_1.ClassType.supportsAbstractMethods(argType) ||
|
10510
10781
|
(types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
|
10511
|
-
classType.details.flags |=
|
10782
|
+
classType.details.flags |= 1024 /* SupportsAbstractMethods */;
|
10512
10783
|
}
|
10513
10784
|
if (types_1.ClassType.isPropertyClass(argType)) {
|
10514
10785
|
classType.details.flags |= 2048 /* PropertyClass */;
|
@@ -10560,16 +10831,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10560
10831
|
metaclassNode = arg.valueExpression;
|
10561
10832
|
}
|
10562
10833
|
}
|
10563
|
-
else if (
|
10564
|
-
|
10834
|
+
else if (types_1.ClassType.isTypedDictClass(classType) &&
|
10835
|
+
(arg.name.value === 'total' || arg.name.value === 'readonly')) {
|
10836
|
+
// The "total" and "readonly" parameters apply only for TypedDict classes.
|
10565
10837
|
// PEP 589 specifies that the parameter must be either True or False.
|
10566
10838
|
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
10567
10839
|
if (constArgValue === undefined) {
|
10568
|
-
addError(localize_1.Localizer.Diagnostic.
|
10840
|
+
addError(localize_1.Localizer.Diagnostic.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
10569
10841
|
}
|
10570
|
-
else if (!constArgValue) {
|
10842
|
+
else if (arg.name.value === 'total' && !constArgValue) {
|
10571
10843
|
classType.details.flags |= 256 /* CanOmitDictValues */;
|
10572
10844
|
}
|
10845
|
+
else if (arg.name.value === 'readonly' && constArgValue) {
|
10846
|
+
classType.details.flags |= 512 /* DictValuesReadOnly */;
|
10847
|
+
}
|
10573
10848
|
}
|
10574
10849
|
else {
|
10575
10850
|
// Collect arguments that will be passed to the `__init_subclass__`
|
@@ -10706,7 +10981,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10706
10981
|
classType.details.flags |= 1048576 /* EnumClass */;
|
10707
10982
|
}
|
10708
10983
|
else if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
|
10709
|
-
classType.details.flags |=
|
10984
|
+
classType.details.flags |= 1024 /* SupportsAbstractMethods */;
|
10710
10985
|
}
|
10711
10986
|
}
|
10712
10987
|
}
|
@@ -10781,7 +11056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10781
11056
|
// This needs to be done after dataclass processing.
|
10782
11057
|
if (classType.details.localSlotsNames) {
|
10783
11058
|
let isLimitedToSlots = true;
|
10784
|
-
const extendedSlotsNames =
|
11059
|
+
const extendedSlotsNames = Array.from(classType.details.localSlotsNames);
|
10785
11060
|
classType.details.baseClasses.forEach((baseClass) => {
|
10786
11061
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
10787
11062
|
if (!types_1.ClassType.isBuiltIn(baseClass, 'object') &&
|
@@ -11005,7 +11280,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11005
11280
|
decoratorCallType.details.builtInName === 'dataclass_transform') {
|
11006
11281
|
originalClassType.details.classDataClassTransform = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
11007
11282
|
}
|
11008
|
-
else if (decoratorCallType.details.
|
11283
|
+
else if (decoratorCallType.details.builtInName === 'deprecated') {
|
11009
11284
|
originalClassType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11010
11285
|
return inputClassType;
|
11011
11286
|
}
|
@@ -11830,7 +12105,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11830
12105
|
undecoratedType.details.decoratorDataClassBehaviors = (0, dataClasses_1.validateDataClassTransformDecorator)(evaluatorInterface, decoratorNode.expression);
|
11831
12106
|
return inputFunctionType;
|
11832
12107
|
}
|
11833
|
-
if (decoratorCallType.details.
|
12108
|
+
if (decoratorCallType.details.builtInName === 'deprecated') {
|
11834
12109
|
undecoratedType.details.deprecatedMessage = getCustomDeprecationMessage(decoratorNode);
|
11835
12110
|
return inputFunctionType;
|
11836
12111
|
}
|
@@ -13164,8 +13439,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13164
13439
|
return { type: createUnpackType(classType, errorNode, typeArgs, flags) };
|
13165
13440
|
}
|
13166
13441
|
case 'Required':
|
13167
|
-
case 'NotRequired':
|
13168
|
-
|
13442
|
+
case 'NotRequired':
|
13443
|
+
case 'ReadOnly': {
|
13444
|
+
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
13169
13445
|
}
|
13170
13446
|
case 'Self': {
|
13171
13447
|
return { type: createSelfType(classType, errorNode, typeArgs) };
|
@@ -13448,8 +13724,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13448
13724
|
}
|
13449
13725
|
function getTypeOfExpressionExpectingType(node, options) {
|
13450
13726
|
let flags = 128 /* ExpectingType */ | 8 /* EvaluateStringLiteralAsType */ | 131072 /* DisallowClassVar */;
|
13727
|
+
if (!(options === null || options === void 0 ? void 0 : options.allowTypeVarsWithoutScopeId)) {
|
13728
|
+
flags |= 4096 /* DisallowTypeVarsWithoutScopeId */;
|
13729
|
+
}
|
13451
13730
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13452
|
-
if (fileInfo.isStubFile) {
|
13731
|
+
if (fileInfo.isStubFile || (options === null || options === void 0 ? void 0 : options.allowForwardReference)) {
|
13453
13732
|
flags |= 4 /* AllowForwardReferences */;
|
13454
13733
|
}
|
13455
13734
|
else {
|
@@ -15802,10 +16081,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15802
16081
|
/* diag */ undefined, destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
|
15803
16082
|
filteredOverloads.push(overload);
|
15804
16083
|
if (destTypeVarContextClone) {
|
15805
|
-
|
16084
|
+
(0, collectionUtils_1.appendArray)(destTypeVarSignatures, destTypeVarContextClone.getSignatureContexts());
|
15806
16085
|
}
|
15807
16086
|
if (srcTypeVarContextClone) {
|
15808
|
-
|
16087
|
+
(0, collectionUtils_1.appendArray)(srcTypeVarSignatures, srcTypeVarContextClone.getSignatureContexts());
|
15809
16088
|
}
|
15810
16089
|
}
|
15811
16090
|
});
|
@@ -16840,7 +17119,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16840
17119
|
}
|
16841
17120
|
// Apply any solved source TypeVars to the dest TypeVar solutions. This
|
16842
17121
|
// allows for higher-order functions to accept generic callbacks.
|
16843
|
-
|
17122
|
+
(0, typeUtils_1.applySourceContextTypeVars)(destTypeVarContext, srcTypeVarContext);
|
16844
17123
|
return canAssign;
|
16845
17124
|
}
|
16846
17125
|
// If the declaredType contains type arguments that are "Any" and
|
@@ -16848,7 +17127,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16848
17127
|
// replace that type argument in the assigned type. This function assumes
|
16849
17128
|
// that the caller has already verified that the assignedType is assignable
|
16850
17129
|
// to the declaredType.
|
16851
|
-
function replaceTypeArgsWithAny(declaredType, assignedType, recursionCount = 0) {
|
17130
|
+
function replaceTypeArgsWithAny(node, declaredType, assignedType, recursionCount = 0) {
|
16852
17131
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
16853
17132
|
return undefined;
|
16854
17133
|
}
|
@@ -16863,7 +17142,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16863
17142
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(assignedType));
|
16864
17143
|
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, types_1.ClassType.cloneForSpecialization(assignedType,
|
16865
17144
|
/* typeArguments */ undefined,
|
16866
|
-
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext,
|
17145
|
+
/* isTypeArgumentExplicit */ false), declaredType, typeVarContext, ParseTreeUtils.getTypeVarScopesForNode(node));
|
16867
17146
|
let replacedTypeArg = false;
|
16868
17147
|
const newTypeArgs = assignedType.typeArguments.map((typeArg, index) => {
|
16869
17148
|
const typeParam = assignedType.details.typeParameters[index];
|
@@ -16875,7 +17154,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16875
17154
|
}
|
16876
17155
|
else if ((0, types_1.isClassInstance)(expectedTypeArgType) && (0, types_1.isClassInstance)(typeArg)) {
|
16877
17156
|
// Recursively replace Any in the type argument.
|
16878
|
-
const recursiveReplacement = replaceTypeArgsWithAny(expectedTypeArgType, typeArg, recursionCount);
|
17157
|
+
const recursiveReplacement = replaceTypeArgsWithAny(node, expectedTypeArgType, typeArg, recursionCount);
|
16879
17158
|
if (recursiveReplacement) {
|
16880
17159
|
replacedTypeArg = true;
|
16881
17160
|
return recursiveReplacement;
|
@@ -16892,7 +17171,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16892
17171
|
}
|
16893
17172
|
// When a value is assigned to a variable with a declared type,
|
16894
17173
|
// we may be able to narrow the type based on the assignment.
|
16895
|
-
function narrowTypeBasedOnAssignment(declaredType, assignedType) {
|
17174
|
+
function narrowTypeBasedOnAssignment(node, declaredType, assignedType) {
|
16896
17175
|
const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedType, (assignedSubtype) => {
|
16897
17176
|
const narrowedSubtype = (0, typeUtils_1.mapSubtypes)(declaredType, (declaredSubtype) => {
|
16898
17177
|
// We can't narrow "Any".
|
@@ -16903,13 +17182,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16903
17182
|
// If the source is generic and has unspecified type arguments,
|
16904
17183
|
// see if we can determine then based on the declared type.
|
16905
17184
|
if ((0, types_1.isInstantiableClass)(declaredSubtype) && (0, types_1.isInstantiableClass)(assignedSubtype)) {
|
16906
|
-
const result = replaceTypeArgsWithAny(declaredSubtype, assignedSubtype);
|
17185
|
+
const result = replaceTypeArgsWithAny(node, declaredSubtype, assignedSubtype);
|
16907
17186
|
if (result) {
|
16908
17187
|
assignedSubtype = result;
|
16909
17188
|
}
|
16910
17189
|
}
|
16911
17190
|
else if ((0, types_1.isClassInstance)(declaredSubtype) && (0, types_1.isClassInstance)(assignedSubtype)) {
|
16912
|
-
const result = replaceTypeArgsWithAny(types_1.ClassType.cloneAsInstantiable(declaredSubtype), types_1.ClassType.cloneAsInstantiable(assignedSubtype));
|
17191
|
+
const result = replaceTypeArgsWithAny(node, types_1.ClassType.cloneAsInstantiable(declaredSubtype), types_1.ClassType.cloneAsInstantiable(assignedSubtype));
|
16913
17192
|
if (result) {
|
16914
17193
|
assignedSubtype = types_1.ClassType.cloneAsInstance(result);
|
16915
17194
|
}
|
@@ -17374,6 +17653,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17374
17653
|
return types_1.FunctionType.clone(memberType, /* stripFirstParam */ true);
|
17375
17654
|
}
|
17376
17655
|
if (types_1.FunctionType.isInstanceMethod(memberType)) {
|
17656
|
+
// If the baseType is a metaclass, don't specialize the function.
|
17657
|
+
if ((0, typeUtils_1.isInstantiableMetaclass)(baseType)) {
|
17658
|
+
return memberType;
|
17659
|
+
}
|
17377
17660
|
const baseObj = (0, types_1.isClassInstance)(baseType)
|
17378
17661
|
? baseType
|
17379
17662
|
: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeClassType)(baseType));
|
@@ -17576,7 +17859,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17576
17859
|
const textValue = node.strings[0].value;
|
17577
17860
|
// Determine the offset within the file where the string
|
17578
17861
|
// literal's contents begin.
|
17579
|
-
|
17862
|
+
let valueOffset = node.strings[0].start;
|
17863
|
+
if (node.strings[0].nodeType === 49 /* String */) {
|
17864
|
+
valueOffset += node.strings[0].token.prefixLength + node.strings[0].token.quoteMarkLength;
|
17865
|
+
}
|
17580
17866
|
const parseOptions = new parser_1.ParseOptions();
|
17581
17867
|
parseOptions.isStubFile = fileInfo.isStubFile;
|
17582
17868
|
parseOptions.pythonVersion = fileInfo.executionEnvironment.pythonVersion;
|
@@ -17614,6 +17900,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17614
17900
|
function printControlFlowGraph(flowNode, reference, callName, logger) {
|
17615
17901
|
return codeFlowEngine.printControlFlowGraph(flowNode, reference, callName, logger);
|
17616
17902
|
}
|
17903
|
+
function printTypeVarContext(typeVarContext) {
|
17904
|
+
const contexts = typeVarContext.getSignatureContexts();
|
17905
|
+
contexts.forEach((context, index) => {
|
17906
|
+
if (contexts.length > 1) {
|
17907
|
+
console.log(`Signature context ${index + 1}:`);
|
17908
|
+
}
|
17909
|
+
context.getTypeVars().forEach((typeVarEntry) => {
|
17910
|
+
const type = context.getTypeVarType(typeVarEntry.typeVar);
|
17911
|
+
console.log(` ${typeVarEntry.typeVar.details.name}: ${type ? printType(type) : '<none>'}`);
|
17912
|
+
});
|
17913
|
+
});
|
17914
|
+
}
|
17617
17915
|
const evaluatorInterface = {
|
17618
17916
|
runWithCancellationToken,
|
17619
17917
|
getType,
|
@@ -17640,7 +17938,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17640
17938
|
validateOverloadedFunctionArguments,
|
17641
17939
|
isAfterNodeReachable,
|
17642
17940
|
isNodeReachable,
|
17643
|
-
isAsymmetricDescriptorAssignment,
|
17941
|
+
isAsymmetricDescriptorAssignment: isAsymmetricAccessorAssignment,
|
17644
17942
|
suppressDiagnostics,
|
17645
17943
|
getDeclarationsForStringNode,
|
17646
17944
|
getDeclarationsForNameNode,
|
@@ -17707,6 +18005,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17707
18005
|
setTypeForNode,
|
17708
18006
|
checkForCancellation,
|
17709
18007
|
printControlFlowGraph,
|
18008
|
+
printTypeVarContext,
|
17710
18009
|
};
|
17711
18010
|
const codeFlowEngine = (0, codeFlowEngine_1.getCodeFlowEngine)(evaluatorInterface, speculativeTypeTracker);
|
17712
18011
|
return evaluatorInterface;
|