@zzzen/pyright-internal 1.2.0-dev.20240218 → 1.2.0-dev.20240225
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/binder.js +1 -0
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -2
- package/dist/analyzer/checker.js +138 -49
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/dataClasses.js +6 -6
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +6 -6
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +11 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +2 -0
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/namedTuples.js +1 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +11 -1
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/sourceFile.js +4 -4
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +160 -98
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
- package/dist/analyzer/typeGuards.js +5 -5
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +1 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.js +4 -3
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +6 -3
- package/dist/analyzer/typedDicts.js +292 -65
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +31 -23
- package/dist/analyzer/types.js +59 -44
- package/dist/analyzer/types.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +18 -18
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +4 -0
- package/dist/common/cancellationUtils.js +2 -1
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +1 -0
- package/dist/languageService/autoImporter.js +3 -1
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +4 -4
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.js +1 -1
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +30 -2
- package/dist/localization/localize.js +9 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +6 -8
- package/dist/localization/package.nls.de.json +6 -8
- package/dist/localization/package.nls.en-us.json +18 -11
- package/dist/localization/package.nls.es.json +6 -8
- package/dist/localization/package.nls.fr.json +3 -5
- package/dist/localization/package.nls.it.json +6 -8
- package/dist/localization/package.nls.ja.json +7 -9
- package/dist/localization/package.nls.ko.json +6 -8
- package/dist/localization/package.nls.pl.json +6 -8
- package/dist/localization/package.nls.pt-br.json +3 -5
- package/dist/localization/package.nls.qps-ploc.json +0 -2
- package/dist/localization/package.nls.ru.json +3 -5
- package/dist/localization/package.nls.tr.json +6 -8
- package/dist/localization/package.nls.zh-cn.json +3 -5
- package/dist/localization/package.nls.zh-tw.json +6 -8
- package/dist/tests/checker.test.js +0 -4
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +11 -0
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +8 -0
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +12 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +1 -1
- package/dist/tests/typeEvaluator3.test.js +4 -8
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +42 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +4 -4
- package/dist/analyzer/regions.d.ts +0 -11
- package/dist/analyzer/regions.js +0 -62
- package/dist/analyzer/regions.js.map +0 -1
@@ -198,6 +198,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
198
198
|
let dictClassType;
|
199
199
|
let typedDictClassType;
|
200
200
|
let typedDictPrivateClassType;
|
201
|
+
let supportsKeysAndGetItemProtocolType;
|
201
202
|
let mappingType;
|
202
203
|
let printExpressionSpaceCount = 0;
|
203
204
|
let incompleteGenerationCount = 0;
|
@@ -466,7 +467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
466
467
|
functionObj = getBuiltInObject(node, 'function');
|
467
468
|
unionClassType = getTypesType(node, 'UnionType');
|
468
469
|
if (unionClassType && (0, types_1.isClass)(unionClassType)) {
|
469
|
-
unionClassType.details.flags |=
|
470
|
+
unionClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
|
470
471
|
}
|
471
472
|
// Initialize and cache "Collection" to break a cyclical dependency
|
472
473
|
// that occurs when resolving tuple below.
|
@@ -483,10 +484,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
483
484
|
typedDictClassType = getTypingType(node, 'TypedDict');
|
484
485
|
typedDictPrivateClassType = getTypingType(node, '_TypedDict');
|
485
486
|
awaitableProtocolType = getTypingType(node, 'Awaitable');
|
486
|
-
mappingType =
|
487
|
-
|
487
|
+
mappingType = getTypingType(node, 'Mapping');
|
488
|
+
supportsKeysAndGetItemProtocolType = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
489
|
+
if (!supportsKeysAndGetItemProtocolType) {
|
488
490
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
489
|
-
|
491
|
+
supportsKeysAndGetItemProtocolType = mappingType;
|
490
492
|
}
|
491
493
|
// Wire up the `Any` class to the special-form version of our internal AnyType.
|
492
494
|
const objectClass = getBuiltInType(node, 'object');
|
@@ -494,7 +496,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
494
496
|
(0, types_1.isInstantiableClass)(objectClass) &&
|
495
497
|
typeClassType &&
|
496
498
|
(0, types_1.isInstantiableClass)(typeClassType)) {
|
497
|
-
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ |
|
499
|
+
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | -2147483648 /* ClassTypeFlags.SpecialFormClass */,
|
498
500
|
/* typeSourceId */ -1,
|
499
501
|
/* declaredMetaclass */ undefined,
|
500
502
|
/* effectiveMetaclass */ typeClassType);
|
@@ -1582,7 +1584,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1582
1584
|
// If the function includes a `**kwargs: Unpack[TypedDict]` parameter, the
|
1583
1585
|
// parameter is expanded to include individual keyword args.
|
1584
1586
|
function expandTypedKwargs(functionType) {
|
1585
|
-
var _a;
|
1587
|
+
var _a, _b;
|
1586
1588
|
const kwargsIndex = functionType.details.parameters.findIndex((param) => param.category === 2 /* ParameterCategory.KwargsDict */);
|
1587
1589
|
if (kwargsIndex < 0) {
|
1588
1590
|
return functionType;
|
@@ -1592,7 +1594,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1592
1594
|
if (!(0, types_1.isClassInstance)(kwargsType) || !types_1.ClassType.isTypedDictClass(kwargsType) || !kwargsType.isUnpacked) {
|
1593
1595
|
return functionType;
|
1594
1596
|
}
|
1595
|
-
const tdEntries = (_a = kwargsType.typedDictNarrowedEntries) !== null && _a !== void 0 ? _a : kwargsType.details.typedDictEntries;
|
1597
|
+
const tdEntries = (_a = kwargsType.typedDictNarrowedEntries) !== null && _a !== void 0 ? _a : (_b = kwargsType.details.typedDictEntries) === null || _b === void 0 ? void 0 : _b.knownItems;
|
1596
1598
|
if (!tdEntries) {
|
1597
1599
|
return functionType;
|
1598
1600
|
}
|
@@ -6870,7 +6872,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6870
6872
|
function evaluateCastCall(argList, errorNode) {
|
6871
6873
|
// Verify that the cast is necessary.
|
6872
6874
|
const castToType = getTypeOfArgumentExpectingType(argList[0], { enforceTypeAnnotationRules: true }).type;
|
6873
|
-
|
6875
|
+
let castFromType = getTypeOfArgument(argList[1]).type;
|
6876
|
+
if (castFromType.specialForm) {
|
6877
|
+
castFromType = castFromType.specialForm;
|
6878
|
+
}
|
6874
6879
|
if (types_1.TypeBase.isInstantiable(castToType) && !(0, types_1.isUnknown)(castToType)) {
|
6875
6880
|
if ((0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(castToType), castFromType, {
|
6876
6881
|
ignorePseudoGeneric: true,
|
@@ -7345,7 +7350,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7345
7350
|
// keys are present.
|
7346
7351
|
const typedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, argType);
|
7347
7352
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
7348
|
-
typedDictEntries.forEach((entry, name) => {
|
7353
|
+
typedDictEntries.knownItems.forEach((entry, name) => {
|
7349
7354
|
const paramEntry = paramMap.get(name);
|
7350
7355
|
if (paramEntry && !paramEntry.isPositionalOnly) {
|
7351
7356
|
if (paramEntry.argsReceived > 0) {
|
@@ -7422,20 +7427,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7422
7427
|
}
|
7423
7428
|
else {
|
7424
7429
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
7425
|
-
if (
|
7426
|
-
(0, types_1.isInstantiableClass)(
|
7430
|
+
if (supportsKeysAndGetItemProtocolType &&
|
7431
|
+
(0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType) &&
|
7427
7432
|
strObjType &&
|
7428
7433
|
(0, types_1.isClassInstance)(strObjType)) {
|
7429
|
-
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(
|
7434
|
+
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemProtocolType));
|
7430
7435
|
let isValidMappingType = false;
|
7431
7436
|
// If this was a TypeVar (e.g. for pseudo-generic classes),
|
7432
7437
|
// don't emit this error.
|
7433
7438
|
if ((0, types_1.isTypeVar)(argType)) {
|
7434
7439
|
isValidMappingType = true;
|
7435
7440
|
}
|
7436
|
-
else if (assignType(types_1.ClassType.cloneAsInstance(
|
7441
|
+
else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemProtocolType), argType,
|
7437
7442
|
/* diag */ undefined, mappingTypeVarContext)) {
|
7438
|
-
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(
|
7443
|
+
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemProtocolType, mappingTypeVarContext);
|
7439
7444
|
const typeArgs = specializedMapping.typeArguments;
|
7440
7445
|
if (typeArgs && typeArgs.length >= 2) {
|
7441
7446
|
if (assignType(strObjType, typeArgs[0])) {
|
@@ -7645,6 +7650,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7645
7650
|
argumentCategory: 0 /* ArgumentCategory.Simple */,
|
7646
7651
|
typeResult: { type: defaultArgType },
|
7647
7652
|
},
|
7653
|
+
isDefaultArg: true,
|
7648
7654
|
errorNode,
|
7649
7655
|
paramName: param.name,
|
7650
7656
|
isParamNameSynthesized: param.isNameSynthesized,
|
@@ -8076,15 +8082,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8076
8082
|
if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
|
8077
8083
|
specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpackedTuple */ false);
|
8078
8084
|
}
|
8079
|
-
// Handle 'TypeGuard' specially. We'll transform the return type
|
8080
|
-
// object with a type argument that reflects the narrowed type.
|
8085
|
+
// Handle 'TypeGuard' and 'TypeIs' specially. We'll transform the return type
|
8086
|
+
// into a 'bool' object with a type argument that reflects the narrowed type.
|
8081
8087
|
if ((0, types_1.isClassInstance)(specializedReturnType) &&
|
8082
|
-
types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeGuard') &&
|
8088
|
+
types_1.ClassType.isBuiltIn(specializedReturnType, ['TypeGuard', 'TypeIs']) &&
|
8083
8089
|
specializedReturnType.typeArguments &&
|
8084
|
-
specializedReturnType.typeArguments.length > 0
|
8085
|
-
(0, types_1.isClassInstance)(returnType) &&
|
8086
|
-
returnType.typeArguments &&
|
8087
|
-
returnType.typeArguments.length > 0) {
|
8090
|
+
specializedReturnType.typeArguments.length > 0) {
|
8088
8091
|
if (boolClassType && (0, types_1.isInstantiableClass)(boolClassType)) {
|
8089
8092
|
let typeGuardType = specializedReturnType.typeArguments[0];
|
8090
8093
|
// If the first argument is a simple (non-constrained) TypeVar,
|
@@ -8099,21 +8102,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8099
8102
|
]);
|
8100
8103
|
}
|
8101
8104
|
}
|
8102
|
-
|
8103
|
-
|
8104
|
-
// Determine the type of the first parameter.
|
8105
|
-
const paramIndex = type.boundToType ? 1 : 0;
|
8106
|
-
if (paramIndex < type.details.parameters.length) {
|
8107
|
-
const paramType = types_1.FunctionType.getEffectiveParameterType(type, paramIndex);
|
8108
|
-
// If the type guard meets the requirements that the first parameter
|
8109
|
-
// type is a proper subtype of the return type, we can use strict
|
8110
|
-
// type guard semantics.
|
8111
|
-
if (assignType(paramType, returnType.typeArguments[0])) {
|
8112
|
-
useStrictTypeGuardSemantics = true;
|
8113
|
-
}
|
8114
|
-
}
|
8115
|
-
}
|
8116
|
-
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useStrictTypeGuardSemantics));
|
8105
|
+
const useTypeIsSemantics = types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeIs');
|
8106
|
+
specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useTypeIsSemantics));
|
8117
8107
|
}
|
8118
8108
|
}
|
8119
8109
|
specializedReturnType = adjustCallableReturnType(specializedReturnType, signatureTracker.getTrackedSignatures());
|
@@ -8391,6 +8381,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8391
8381
|
isTypeIncomplete = true;
|
8392
8382
|
}
|
8393
8383
|
}
|
8384
|
+
// If the argument came from a parameter's default argument value,
|
8385
|
+
// we may need to specialize the type.
|
8386
|
+
if (argParam.isDefaultArg) {
|
8387
|
+
argType = (0, typeUtils_1.applySolvedTypeVars)(argType, typeVarContext);
|
8388
|
+
}
|
8394
8389
|
}
|
8395
8390
|
// If we're assigning to a var arg dictionary with a TypeVar type,
|
8396
8391
|
// strip literals before performing the assignment. This is used in
|
@@ -8997,7 +8992,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8997
8992
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
|
8998
8993
|
}
|
8999
8994
|
let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
|
9000
|
-
classFlags |=
|
8995
|
+
classFlags |= 8192 /* ClassTypeFlags.Final */ | 536870912 /* ClassTypeFlags.NewTypeClass */ | 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */;
|
9001
8996
|
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
|
9002
8997
|
/* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
|
9003
8998
|
classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
|
@@ -9046,7 +9041,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9046
9041
|
if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
|
9047
9042
|
return undefined;
|
9048
9043
|
}
|
9049
|
-
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri,
|
9044
|
+
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode),
|
9050
9045
|
/* declaredMetaclass */ undefined, arg1Type.details.effectiveMetaclass);
|
9051
9046
|
arg1Type.tupleTypeArguments.forEach((typeArg) => {
|
9052
9047
|
const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
|
@@ -9356,8 +9351,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9356
9351
|
(0, types_1.isClassInstance)(keyType) &&
|
9357
9352
|
types_1.ClassType.isBuiltIn(keyType, 'str') &&
|
9358
9353
|
(0, typeUtils_1.isLiteralType)(keyType) &&
|
9359
|
-
expectedTypedDictEntries.has(keyType.literalValue)) {
|
9360
|
-
const effectiveValueType = expectedTypedDictEntries.get(keyType.literalValue).valueType;
|
9354
|
+
expectedTypedDictEntries.knownItems.has(keyType.literalValue)) {
|
9355
|
+
const effectiveValueType = expectedTypedDictEntries.knownItems.get(keyType.literalValue).valueType;
|
9361
9356
|
entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(effectiveValueType);
|
9362
9357
|
valueTypeResult = getTypeOfExpression(entryNode.valueExpression,
|
9363
9358
|
/* flags */ undefined, entryInferenceContext);
|
@@ -9390,8 +9385,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9390
9385
|
else if (entryNode.nodeType === 16 /* ParseNodeType.DictionaryExpandEntry */) {
|
9391
9386
|
let expectedType;
|
9392
9387
|
if (expectedKeyType && expectedValueType) {
|
9393
|
-
if (
|
9394
|
-
expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(
|
9388
|
+
if (supportsKeysAndGetItemProtocolType && (0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType)) {
|
9389
|
+
expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(supportsKeysAndGetItemProtocolType, [expectedKeyType, expectedValueType],
|
9395
9390
|
/* isTypeArgumentExplicit */ true));
|
9396
9391
|
}
|
9397
9392
|
}
|
@@ -9417,7 +9412,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9417
9412
|
const strObject = types_1.ClassType.cloneAsInstance(strClassType);
|
9418
9413
|
const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, unexpandedType,
|
9419
9414
|
/* allowNarrowed */ true);
|
9420
|
-
tdEntries.forEach((entry, name) => {
|
9415
|
+
tdEntries.knownItems.forEach((entry, name) => {
|
9421
9416
|
if (entry.isRequired || entry.isProvided) {
|
9422
9417
|
keyTypes.push({ node: entryNode, type: types_1.ClassType.cloneWithLiteral(strObject, name) });
|
9423
9418
|
valueTypes.push({ node: entryNode, type: entry.valueType });
|
@@ -9426,13 +9421,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9426
9421
|
addUnknown = false;
|
9427
9422
|
}
|
9428
9423
|
}
|
9429
|
-
else if (
|
9430
|
-
|
9431
|
-
|
9432
|
-
|
9424
|
+
else if (supportsKeysAndGetItemProtocolType &&
|
9425
|
+
(0, types_1.isInstantiableClass)(supportsKeysAndGetItemProtocolType)) {
|
9426
|
+
const mappingTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(supportsKeysAndGetItemProtocolType));
|
9427
|
+
supportsKeysAndGetItemProtocolType = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemProtocolType);
|
9428
|
+
if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemProtocolType), unexpandedType,
|
9433
9429
|
/* diag */ undefined, mappingTypeVarContext,
|
9434
9430
|
/* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
|
9435
|
-
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(
|
9431
|
+
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(supportsKeysAndGetItemProtocolType, mappingTypeVarContext);
|
9436
9432
|
const typeArgs = specializedMapping.typeArguments;
|
9437
9433
|
if (typeArgs && typeArgs.length >= 2) {
|
9438
9434
|
if (forceStrictInference || index < maxEntriesToUseForInference) {
|
@@ -9907,7 +9903,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9907
9903
|
}
|
9908
9904
|
}
|
9909
9905
|
}, {
|
9910
|
-
dependentType: expectedType,
|
9906
|
+
dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
|
9911
9907
|
allowDiagnostics: !forceSpeculative && !isDiagnosticSuppressedForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
|
9912
9908
|
});
|
9913
9909
|
// Mark the function type as no longer being evaluated.
|
@@ -10405,7 +10401,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10405
10401
|
}
|
10406
10402
|
return type;
|
10407
10403
|
}
|
10408
|
-
// Creates a "TypeGuard" type. This is an alias for 'bool', which
|
10404
|
+
// Creates a "TypeGuard" and "TypeIs" type. This is an alias for 'bool', which
|
10409
10405
|
// isn't a generic type and therefore doesn't have a typeParameter.
|
10410
10406
|
// We'll abuse our internal types a bit by specializing it with
|
10411
10407
|
// a type argument anyway.
|
@@ -10923,12 +10919,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10923
10919
|
/* declaredMetaclass */ undefined,
|
10924
10920
|
/* effectiveMetaclass */ undefined);
|
10925
10921
|
if (aliasMapEntry.isSpecialForm) {
|
10926
|
-
specialClassType.details.flags |=
|
10922
|
+
specialClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
|
10927
10923
|
}
|
10928
10924
|
const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
|
10929
10925
|
specialClassType.details.declaration = specialBuiltInClassDeclaration;
|
10930
10926
|
if (fileInfo.isTypingExtensionsStubFile) {
|
10931
|
-
specialClassType.details.flags |=
|
10927
|
+
specialClassType.details.flags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
|
10932
10928
|
}
|
10933
10929
|
const baseClassName = aliasMapEntry.alias || 'object';
|
10934
10930
|
let baseClass;
|
@@ -10948,7 +10944,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10948
10944
|
// cause the TypedDict to be marked as abstract.
|
10949
10945
|
if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, '_TypedDict')) {
|
10950
10946
|
baseClass = types_1.ClassType.cloneWithNewFlags(baseClass, baseClass.details.flags &
|
10951
|
-
~(
|
10947
|
+
~(2048 /* ClassTypeFlags.SupportsAbstractMethods */ | 268435456 /* ClassTypeFlags.TypeCheckOnly */));
|
10952
10948
|
}
|
10953
10949
|
}
|
10954
10950
|
}
|
@@ -11004,6 +11000,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11004
11000
|
['Never', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11005
11001
|
['LiteralString', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11006
11002
|
['ReadOnly', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11003
|
+
['TypeIs', { alias: '', module: 'builtins', isSpecialForm: true }],
|
11007
11004
|
]);
|
11008
11005
|
const aliasMapEntry = specialTypes.get(assignedName);
|
11009
11006
|
if (aliasMapEntry) {
|
@@ -11332,17 +11329,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11332
11329
|
fileInfo.isTypeshedStubFile) {
|
11333
11330
|
classFlags |= 1 /* ClassTypeFlags.BuiltInClass */;
|
11334
11331
|
if (fileInfo.isTypingExtensionsStubFile) {
|
11335
|
-
classFlags |=
|
11332
|
+
classFlags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
|
11336
11333
|
}
|
11337
11334
|
if (node.name.value === 'property') {
|
11338
|
-
classFlags |=
|
11335
|
+
classFlags |= 4096 /* ClassTypeFlags.PropertyClass */;
|
11339
11336
|
}
|
11340
11337
|
if (node.name.value === 'tuple') {
|
11341
|
-
classFlags |=
|
11338
|
+
classFlags |= 1048576 /* ClassTypeFlags.TupleClass */;
|
11342
11339
|
}
|
11343
11340
|
}
|
11344
11341
|
if (fileInfo.isStubFile) {
|
11345
|
-
classFlags |=
|
11342
|
+
classFlags |= 16777216 /* ClassTypeFlags.DefinedInStub */;
|
11346
11343
|
}
|
11347
11344
|
const classType = types_1.ClassType.createInstantiable(node.name.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.name.value), fileInfo.moduleName, fileInfo.fileUri, classFlags,
|
11348
11345
|
/* typeSourceId */ 0,
|
@@ -11365,7 +11362,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11365
11362
|
if (classDecl && classSymbol) {
|
11366
11363
|
setSymbolResolutionPartialType(classSymbol, classDecl, classType);
|
11367
11364
|
}
|
11368
|
-
classType.details.flags |=
|
11365
|
+
classType.details.flags |= 262144 /* ClassTypeFlags.PartiallyEvaluated */;
|
11369
11366
|
classType.details.declaration = classDecl;
|
11370
11367
|
try {
|
11371
11368
|
writeTypeCache(node, { type: classType }, /* flags */ undefined);
|
@@ -11450,10 +11447,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11450
11447
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_7) {
|
11451
11448
|
addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
|
11452
11449
|
}
|
11453
|
-
classType.details.flags |=
|
11450
|
+
classType.details.flags |= 16384 /* ClassTypeFlags.ProtocolClass */;
|
11454
11451
|
}
|
11455
11452
|
if (types_1.ClassType.isBuiltIn(argType, 'property')) {
|
11456
|
-
classType.details.flags |=
|
11453
|
+
classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
|
11457
11454
|
}
|
11458
11455
|
// If the class directly derives from NamedTuple (in Python 3.6 or
|
11459
11456
|
// newer), it's considered a (read-only) dataclass.
|
@@ -11462,13 +11459,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11462
11459
|
classType.details.flags |=
|
11463
11460
|
4 /* ClassTypeFlags.DataClass */ |
|
11464
11461
|
32 /* ClassTypeFlags.SkipSynthesizedDataClassEq */ |
|
11465
|
-
|
11462
|
+
33554432 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
|
11466
11463
|
}
|
11467
11464
|
}
|
11468
11465
|
// If the class directly derives from TypedDict or from a class that is
|
11469
11466
|
// a TypedDict, it is considered a TypedDict.
|
11470
11467
|
if (types_1.ClassType.isBuiltIn(argType, 'TypedDict') || types_1.ClassType.isTypedDictClass(argType)) {
|
11471
11468
|
classType.details.flags |= 128 /* ClassTypeFlags.TypedDictClass */;
|
11469
|
+
// Propagate the "effectively closed" flag from base classes.
|
11470
|
+
if (types_1.ClassType.isTypedDictEffectivelyClosed(argType)) {
|
11471
|
+
classType.details.flags |= 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
11472
|
+
}
|
11472
11473
|
}
|
11473
11474
|
// Validate that the class isn't deriving from itself, creating a
|
11474
11475
|
// circular dependency.
|
@@ -11498,7 +11499,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11498
11499
|
classType.details.baseClasses.push(argType);
|
11499
11500
|
if ((0, types_1.isInstantiableClass)(argType)) {
|
11500
11501
|
if (types_1.ClassType.isEnumClass(argType)) {
|
11501
|
-
classType.details.flags |=
|
11502
|
+
classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
|
11502
11503
|
}
|
11503
11504
|
// Determine if the class is abstract. Protocol classes support abstract methods
|
11504
11505
|
// because they are constructed by the _ProtocolMeta metaclass, which derives
|
@@ -11507,10 +11508,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11507
11508
|
// because of dependencies on some of these built-in protocol classes.
|
11508
11509
|
if (types_1.ClassType.supportsAbstractMethods(argType) ||
|
11509
11510
|
(types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
|
11510
|
-
classType.details.flags |=
|
11511
|
+
classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
|
11511
11512
|
}
|
11512
11513
|
if (types_1.ClassType.isPropertyClass(argType)) {
|
11513
|
-
classType.details.flags |=
|
11514
|
+
classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
|
11514
11515
|
}
|
11515
11516
|
if (types_1.ClassType.isFinal(argType)) {
|
11516
11517
|
const className = printObjectTypeForClass(argType);
|
@@ -11552,7 +11553,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11552
11553
|
}
|
11553
11554
|
}
|
11554
11555
|
else if (types_1.ClassType.isTypedDictClass(classType)) {
|
11555
|
-
if (arg.name.value === 'total') {
|
11556
|
+
if (arg.name.value === 'total' || arg.name.value === 'closed') {
|
11556
11557
|
// The "total" and "readonly" parameters apply only for TypedDict classes.
|
11557
11558
|
// PEP 589 specifies that the parameter must be either True or False.
|
11558
11559
|
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
@@ -11560,7 +11561,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11560
11561
|
addError(localize_1.LocMessage.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
11561
11562
|
}
|
11562
11563
|
else if (arg.name.value === 'total' && !constArgValue) {
|
11563
|
-
classType.details.flags |=
|
11564
|
+
classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
|
11565
|
+
}
|
11566
|
+
else if (arg.name.value === 'closed' && constArgValue) {
|
11567
|
+
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
11568
|
+
classType.details.flags |=
|
11569
|
+
256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
11570
|
+
}
|
11564
11571
|
}
|
11565
11572
|
}
|
11566
11573
|
else {
|
@@ -11681,7 +11688,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11681
11688
|
param.category === 0 /* ParameterCategory.Simple */ &&
|
11682
11689
|
!param.defaultValue);
|
11683
11690
|
if (genericParams.length > 0) {
|
11684
|
-
classType.details.flags |=
|
11691
|
+
classType.details.flags |= 32768 /* ClassTypeFlags.PseudoGenericClass */;
|
11685
11692
|
// Create a type parameter for each simple, named parameter
|
11686
11693
|
// in the __init__ method.
|
11687
11694
|
classType.details.typeParameters = genericParams.map((param) => {
|
@@ -11702,7 +11709,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11702
11709
|
if (classType.details.typeParameters.length === 0 && !types_1.ClassType.isBuiltIn(classType, 'type')) {
|
11703
11710
|
if (classType.details.baseClasses.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.hasCustomClassGetItem(baseClass)) ||
|
11704
11711
|
classType.details.fields.has('__class_getitem__')) {
|
11705
|
-
classType.details.flags |=
|
11712
|
+
classType.details.flags |= 524288 /* ClassTypeFlags.HasCustomClassGetItem */;
|
11706
11713
|
}
|
11707
11714
|
}
|
11708
11715
|
// Determine the effective metaclass.
|
@@ -11715,17 +11722,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11715
11722
|
classType.details.declaredMetaclass = metaclassType;
|
11716
11723
|
if ((0, types_1.isInstantiableClass)(metaclassType)) {
|
11717
11724
|
if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
|
11718
|
-
classType.details.flags |=
|
11725
|
+
classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
|
11719
11726
|
}
|
11720
11727
|
if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
|
11721
|
-
classType.details.flags |=
|
11728
|
+
classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
|
11722
11729
|
}
|
11723
11730
|
}
|
11724
11731
|
}
|
11725
11732
|
}
|
11726
11733
|
const effectiveMetaclass = computeEffectiveMetaclass(classType, node.name);
|
11727
11734
|
// Clear the "partially constructed" flag.
|
11728
|
-
classType.details.flags &= ~
|
11735
|
+
classType.details.flags &= ~262144 /* ClassTypeFlags.PartiallyEvaluated */;
|
11729
11736
|
// Now determine the decorated type of the class.
|
11730
11737
|
let decoratedType = classType;
|
11731
11738
|
let foundUnknown = false;
|
@@ -11787,7 +11794,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11787
11794
|
if (foundInvalidBaseClass) {
|
11788
11795
|
addError(localize_1.LocMessage.typedDictBaseClass() + diag.getString(), node.name);
|
11789
11796
|
}
|
11790
|
-
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType
|
11797
|
+
(0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType);
|
11791
11798
|
}
|
11792
11799
|
// Synthesize dataclass methods.
|
11793
11800
|
if (types_1.ClassType.isDataClass(classType)) {
|
@@ -12460,8 +12467,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12460
12467
|
if (index >= firstNonClsSelfParamIndex) {
|
12461
12468
|
let isImplicitPositionOnlyParam = false;
|
12462
12469
|
if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
|
12463
|
-
if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)
|
12470
|
+
if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
|
12471
|
+
!node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
|
12464
12472
|
isImplicitPositionOnlyParam = true;
|
12473
|
+
// If the parameter name indicates an implicit position-only parameter
|
12474
|
+
// but we have already seen non-position-only parameters, report an error.
|
12475
|
+
if (!paramsArePositionOnly &&
|
12476
|
+
functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
|
12477
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
|
12478
|
+
}
|
12465
12479
|
}
|
12466
12480
|
}
|
12467
12481
|
else {
|
@@ -13980,7 +13994,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13980
13994
|
case 'Concatenate': {
|
13981
13995
|
return { type: createConcatenateType(classType, errorNode, typeArgs, flags) };
|
13982
13996
|
}
|
13983
|
-
case 'TypeGuard':
|
13997
|
+
case 'TypeGuard':
|
13998
|
+
case 'TypeIs': {
|
13984
13999
|
return { type: createTypeGuardType(classType, errorNode, typeArgs, flags) };
|
13985
14000
|
}
|
13986
14001
|
case 'Unpack': {
|
@@ -14527,7 +14542,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14527
14542
|
// is a valid entry in the TypedDict to avoid resolving declarations for
|
14528
14543
|
// synthesized symbols such as 'get'.
|
14529
14544
|
if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isTypedDictClass(subtype)) {
|
14530
|
-
const entry = (_a = subtype.details.typedDictEntries) === null || _a === void 0 ? void 0 : _a.get(node.value);
|
14545
|
+
const entry = (_a = subtype.details.typedDictEntries) === null || _a === void 0 ? void 0 : _a.knownItems.get(node.value);
|
14531
14546
|
if (entry) {
|
14532
14547
|
const symbol = (_b = (0, typeUtils_1.lookUpObjectMember)(subtype, node.value)) === null || _b === void 0 ? void 0 : _b.symbol;
|
14533
14548
|
if (symbol) {
|
@@ -14895,7 +14910,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14895
14910
|
}
|
14896
14911
|
}
|
14897
14912
|
else {
|
14898
|
-
const boundType = getTypeOfExpressionExpectingType(node.boundExpression
|
14913
|
+
const boundType = getTypeOfExpressionExpectingType(node.boundExpression, {
|
14914
|
+
disallowProtocolAndTypedDict: true,
|
14915
|
+
}).type;
|
14899
14916
|
if ((0, typeUtils_1.requiresSpecialization)(boundType, { ignorePseudoGeneric: true })) {
|
14900
14917
|
addError(localize_1.LocMessage.typeVarConstraintGeneric(), node.boundExpression);
|
14901
14918
|
}
|
@@ -15844,26 +15861,66 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15844
15861
|
}
|
15845
15862
|
// Handle typed dicts. They also use a form of structural typing for type
|
15846
15863
|
// checking, as defined in PEP 589.
|
15847
|
-
if (types_1.ClassType.isTypedDictClass(
|
15848
|
-
types_1.ClassType.isTypedDictClass(srcType)
|
15849
|
-
|
15850
|
-
|
15851
|
-
|
15864
|
+
if (types_1.ClassType.isTypedDictClass(srcType)) {
|
15865
|
+
if (types_1.ClassType.isTypedDictClass(destType) && !types_1.ClassType.isSameGenericClass(destType, srcType)) {
|
15866
|
+
if (!(0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount)) {
|
15867
|
+
return false;
|
15868
|
+
}
|
15869
|
+
if (types_1.ClassType.isFinal(destType) !== types_1.ClassType.isFinal(srcType)) {
|
15870
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typedDictFinalMismatch().format({
|
15871
|
+
sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
|
15872
|
+
destType: printType((0, typeUtils_1.convertToInstance)(destType)),
|
15873
|
+
}));
|
15874
|
+
return false;
|
15875
|
+
}
|
15876
|
+
// If invariance is being enforced, the two TypedDicts must be assignable to each other.
|
15877
|
+
if ((flags & 1 /* AssignTypeFlags.EnforceInvariance */) !== 0) {
|
15878
|
+
return (0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, srcType, destType,
|
15879
|
+
/* diag */ undefined,
|
15880
|
+
/* typeVarContext */ undefined, flags, recursionCount);
|
15881
|
+
}
|
15882
|
+
return true;
|
15852
15883
|
}
|
15853
|
-
|
15854
|
-
|
15855
|
-
|
15856
|
-
|
15857
|
-
|
15858
|
-
|
15884
|
+
// Handle some special cases where a TypedDict can act like
|
15885
|
+
// a Mapping[str, T] or a dict[str, T].
|
15886
|
+
if (types_1.ClassType.isBuiltIn(destType, 'Mapping')) {
|
15887
|
+
const mappingValueType = (0, typedDicts_1.getTypedDictMappingEquivalent)(evaluatorInterface, srcType);
|
15888
|
+
if (mappingValueType &&
|
15889
|
+
mappingType &&
|
15890
|
+
(0, types_1.isInstantiableClass)(mappingType) &&
|
15891
|
+
strClassType &&
|
15892
|
+
(0, types_1.isInstantiableClass)(strClassType)) {
|
15893
|
+
srcType = types_1.ClassType.cloneForSpecialization(mappingType, [types_1.ClassType.cloneAsInstance(strClassType), mappingValueType],
|
15894
|
+
/* isTypeArgumentExplicit */ true);
|
15895
|
+
}
|
15859
15896
|
}
|
15860
|
-
|
15861
|
-
|
15862
|
-
|
15863
|
-
|
15864
|
-
|
15897
|
+
else if (types_1.ClassType.isBuiltIn(destType, ['dict', 'MutableMapping'])) {
|
15898
|
+
const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, srcType, recursionCount);
|
15899
|
+
if (dictValueType &&
|
15900
|
+
dictClassType &&
|
15901
|
+
(0, types_1.isInstantiableClass)(dictClassType) &&
|
15902
|
+
strClassType &&
|
15903
|
+
(0, types_1.isInstantiableClass)(strClassType)) {
|
15904
|
+
srcType = types_1.ClassType.cloneForSpecialization(dictClassType, [types_1.ClassType.cloneAsInstance(strClassType), dictValueType],
|
15905
|
+
/* isTypeArgumentExplicit */ true);
|
15906
|
+
}
|
15907
|
+
}
|
15908
|
+
}
|
15909
|
+
// See if the dest type is a TypedDict class and the source is a compatible dict.
|
15910
|
+
if (types_1.ClassType.isTypedDictClass(destType) && types_1.ClassType.isBuiltIn(srcType, 'dict')) {
|
15911
|
+
if (srcType.typeArguments &&
|
15912
|
+
srcType.typeArguments.length === 2 &&
|
15913
|
+
(0, types_1.isClassInstance)(srcType.typeArguments[0]) &&
|
15914
|
+
types_1.ClassType.isBuiltIn(srcType.typeArguments[0], 'str')) {
|
15915
|
+
const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, destType, recursionCount);
|
15916
|
+
if (dictValueType &&
|
15917
|
+
assignType(dictValueType, srcType.typeArguments[1],
|
15918
|
+
/* diag */ undefined,
|
15919
|
+
/* destTypeVarContext */ undefined,
|
15920
|
+
/* srcTypeVarContext */ undefined, 1 /* AssignTypeFlags.EnforceInvariance */, recursionCount + 1)) {
|
15921
|
+
return true;
|
15922
|
+
}
|
15865
15923
|
}
|
15866
|
-
return true;
|
15867
15924
|
}
|
15868
15925
|
// Handle special-case type promotions.
|
15869
15926
|
if (destType.includePromotions) {
|
@@ -16635,7 +16692,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16635
16692
|
}
|
16636
16693
|
if ((0, types_1.isNever)(srcType)) {
|
16637
16694
|
if ((flags & 1 /* AssignTypeFlags.EnforceInvariance */) !== 0) {
|
16638
|
-
|
16695
|
+
if ((0, types_1.isNever)(destType)) {
|
16696
|
+
return true;
|
16697
|
+
}
|
16698
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16699
|
+
return false;
|
16639
16700
|
}
|
16640
16701
|
const targetTypeVarContext = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
|
16641
16702
|
if (targetTypeVarContext) {
|
@@ -16768,7 +16829,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16768
16829
|
return !isLiteral;
|
16769
16830
|
}
|
16770
16831
|
}
|
16771
|
-
else if (types_1.ClassType.isBuiltIn(destType, 'TypeGuard')) {
|
16832
|
+
else if (types_1.ClassType.isBuiltIn(destType, ['TypeGuard', 'TypeIs'])) {
|
16772
16833
|
// All the source to be a "bool".
|
16773
16834
|
if ((originalFlags & 128 /* AssignTypeFlags.AllowBoolTypeGuard */) !== 0) {
|
16774
16835
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
|
@@ -17946,10 +18007,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17946
18007
|
isReturnTypeCompatible = true;
|
17947
18008
|
}
|
17948
18009
|
else {
|
17949
|
-
// Handle the special case where the return type is a TypeGuard[T]
|
17950
|
-
// This should also act as a bool, since that's its
|
18010
|
+
// Handle the special case where the return type is a TypeGuard[T]
|
18011
|
+
// or TypeIs[T]. This should also act as a bool, since that's its
|
18012
|
+
// type at runtime.
|
17951
18013
|
if ((0, types_1.isClassInstance)(srcReturnType) &&
|
17952
|
-
types_1.ClassType.isBuiltIn(srcReturnType, 'TypeGuard') &&
|
18014
|
+
types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'TypeIs']) &&
|
17953
18015
|
boolClassType &&
|
17954
18016
|
(0, types_1.isInstantiableClass)(boolClassType)) {
|
17955
18017
|
if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClassType), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|