@zzzen/pyright-internal 1.2.0-dev.20230903 → 1.2.0-dev.20230910
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/checker.js +39 -14
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +5 -0
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +16 -7
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +2 -0
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +16 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/importResolver.js +4 -7
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/parentDirectoryCache.js +1 -1
- package/dist/analyzer/parentDirectoryCache.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -2
- package/dist/analyzer/program.js +30 -24
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +10 -8
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.js +14 -12
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.js +162 -102
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +9 -8
- package/dist/analyzer/typeEvaluatorTypes.js +11 -8
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +38 -6
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +6 -4
- package/dist/analyzer/typeUtils.js +81 -54
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js +8 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.js +2 -2
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +6 -0
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/pathUtils.d.ts +2 -15
- package/dist/common/pathUtils.js +9 -84
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +22 -13
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +3 -2
- package/dist/languageService/completionProvider.js +12 -6
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +9 -0
- package/dist/localization/localize.js +7 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -2
- package/dist/localization/package.nls.de.json +8 -2
- package/dist/localization/package.nls.en-us.json +9 -3
- package/dist/localization/package.nls.es.json +8 -2
- package/dist/localization/package.nls.fr.json +8 -2
- package/dist/localization/package.nls.it.json +8 -2
- package/dist/localization/package.nls.ja.json +8 -2
- package/dist/localization/package.nls.ko.json +8 -2
- package/dist/localization/package.nls.pl.json +8 -2
- package/dist/localization/package.nls.pt-br.json +8 -2
- package/dist/localization/package.nls.qps-ploc.json +8 -2
- package/dist/localization/package.nls.ru.json +8 -2
- package/dist/localization/package.nls.tr.json +8 -2
- package/dist/localization/package.nls.zh-cn.json +8 -2
- package/dist/localization/package.nls.zh-tw.json +8 -2
- package/dist/server.js +2 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/checker.test.js +2 -2
- package/dist/tests/completions.test.js +27 -0
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +5 -5
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +5 -5
- package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +11 -9
- package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +14 -14
- package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +12 -12
- package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +9 -9
- package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +3 -3
- package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +4 -4
- package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +8 -8
- package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -0
- package/dist/tests/fourslash/importnotresolved.fourslash.js +2 -2
- package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js +1 -1
- package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
- package/dist/tests/harness/fourslash/testState.Consts.js +2 -0
- package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +4 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.js +10 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/pathUtils.test.js +13 -21
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +5 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/workspaceFactory.js +8 -14
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -728,7 +728,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
728
728
|
const isEmptyVariadic = (0, types_1.isClassInstance)(typeResult.type) &&
|
729
729
|
types_1.ClassType.isTupleClass(typeResult.type) &&
|
730
730
|
((_a = typeResult.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 0;
|
731
|
-
|
731
|
+
const isEllipsis = (0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis');
|
732
|
+
if (!isEmptyVariadic && !isEllipsis) {
|
732
733
|
addExpectedClassDiagnostic(typeResult.type, node);
|
733
734
|
typeResult.type = types_1.UnknownType.create();
|
734
735
|
typeResult.typeErrors = true;
|
@@ -1243,8 +1244,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1243
1244
|
// to handle the case where we're fetching the object member from a
|
1244
1245
|
// metaclass but binding to the class.
|
1245
1246
|
function getTypeOfObjectMember(errorNode, objectType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
|
1246
|
-
|
1247
|
-
/* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags |
|
1247
|
+
let memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstantiable(objectType),
|
1248
|
+
/* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 16 /* DisallowClassVarWrites */, bindToType);
|
1249
|
+
if (!memberInfo) {
|
1250
|
+
const metaclass = objectType.details.effectiveMetaclass;
|
1251
|
+
if (metaclass &&
|
1252
|
+
(0, types_1.isInstantiableClass)(metaclass) &&
|
1253
|
+
!types_1.ClassType.isBuiltIn(metaclass, 'type') &&
|
1254
|
+
!types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
|
1255
|
+
memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
|
1256
|
+
/* isAccessedThroughObject */ false, memberName, usage,
|
1257
|
+
/* diag */ undefined, memberAccessFlags | 2 /* AccessInstanceMembersOnly */, types_1.ClassType.cloneAsInstantiable(objectType));
|
1258
|
+
}
|
1259
|
+
}
|
1248
1260
|
if (memberInfo) {
|
1249
1261
|
return {
|
1250
1262
|
type: memberInfo.type,
|
@@ -1261,7 +1273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1261
1273
|
let memberInfo;
|
1262
1274
|
const classDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
1263
1275
|
const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
1264
|
-
let considerMetaclassOnly = (memberAccessFlags &
|
1276
|
+
let considerMetaclassOnly = (memberAccessFlags & 64 /* ConsiderMetaclassOnly */) !== 0;
|
1265
1277
|
if (types_1.ClassType.isPartiallyEvaluated(classType)) {
|
1266
1278
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
|
1267
1279
|
return { type: types_1.UnknownType.create() };
|
@@ -1489,7 +1501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1489
1501
|
const classTypeInfo = getTypeOfClass(enclosingClass);
|
1490
1502
|
if (classTypeInfo) {
|
1491
1503
|
const classMemberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, expression.value, 8 /* SkipInstanceVariables */ |
|
1492
|
-
|
1504
|
+
32 /* DeclaredTypesOnly */);
|
1493
1505
|
if (classMemberInfo) {
|
1494
1506
|
symbol = classMemberInfo.symbol;
|
1495
1507
|
}
|
@@ -1506,7 +1518,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1506
1518
|
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
|
1507
1519
|
let classMemberInfo;
|
1508
1520
|
if ((0, types_1.isClassInstance)(baseType)) {
|
1509
|
-
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value,
|
1521
|
+
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 32 /* DeclaredTypesOnly */);
|
1510
1522
|
classOrObjectBase = baseType;
|
1511
1523
|
memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
|
1512
1524
|
// If this is an instance member (e.g. a dataclass field), don't
|
@@ -1517,7 +1529,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1517
1529
|
useDescriptorSetterType = true;
|
1518
1530
|
}
|
1519
1531
|
else if ((0, types_1.isInstantiableClass)(baseType)) {
|
1520
|
-
classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ |
|
1532
|
+
classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ | 32 /* DeclaredTypesOnly */);
|
1521
1533
|
classOrObjectBase = baseType;
|
1522
1534
|
memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
|
1523
1535
|
}
|
@@ -2212,7 +2224,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2212
2224
|
}
|
2213
2225
|
}
|
2214
2226
|
// Look up the member info again, now that we've potentially updated it.
|
2215
|
-
memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName,
|
2227
|
+
memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 32 /* DeclaredTypesOnly */);
|
2216
2228
|
if (!memberInfo && srcExprNode && !isTypeIncomplete) {
|
2217
2229
|
reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, srcType, node,
|
2218
2230
|
/* ignoreEmptyContainers */ true);
|
@@ -2351,8 +2363,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2351
2363
|
// If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
|
2352
2364
|
// *tuple[*Ts].
|
2353
2365
|
if ((0, types_1.isVariadicTypeVar)(subtype)) {
|
2366
|
+
// If it's in a union, convert to type or object.
|
2354
2367
|
if (subtype.isVariadicInUnion) {
|
2355
|
-
|
2368
|
+
if (types_1.TypeBase.isInstantiable(subtype)) {
|
2369
|
+
if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
|
2370
|
+
return typeClassType;
|
2371
|
+
}
|
2372
|
+
}
|
2373
|
+
else if (objectType) {
|
2374
|
+
return objectType;
|
2375
|
+
}
|
2376
|
+
return types_1.AnyType.create();
|
2356
2377
|
}
|
2357
2378
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2358
2379
|
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
|
@@ -3230,9 +3251,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3230
3251
|
nestedClassCount++;
|
3231
3252
|
}
|
3232
3253
|
else if (curNode.nodeType === 28 /* Function */) {
|
3233
|
-
const
|
3234
|
-
if (
|
3235
|
-
const functionDetails =
|
3254
|
+
const functionType = getTypeOfFunctionPredecorated(curNode);
|
3255
|
+
if (functionType) {
|
3256
|
+
const functionDetails = functionType.details;
|
3236
3257
|
typeParametersForScope = functionDetails.typeParameters;
|
3237
3258
|
// Was this type parameter "rescoped" to a callable found within the
|
3238
3259
|
// return type annotation? If so, it is not available for use within
|
@@ -3696,20 +3717,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3696
3717
|
if (flags & 1 /* AccessClassMembersOnly */) {
|
3697
3718
|
classLookupFlags |= 8 /* SkipInstanceVariables */;
|
3698
3719
|
}
|
3699
|
-
if (flags & 2 /*
|
3720
|
+
if (flags & 2 /* AccessInstanceMembersOnly */) {
|
3721
|
+
classLookupFlags |= 16 /* SkipClassVariables */;
|
3722
|
+
}
|
3723
|
+
if (flags & 4 /* SkipBaseClasses */) {
|
3700
3724
|
classLookupFlags |= 2 /* SkipBaseClasses */;
|
3701
3725
|
}
|
3702
|
-
if (flags &
|
3726
|
+
if (flags & 8 /* SkipObjectBaseClass */) {
|
3703
3727
|
classLookupFlags |= 4 /* SkipObjectBaseClass */;
|
3704
3728
|
}
|
3705
|
-
if (flags &
|
3706
|
-
classLookupFlags |=
|
3729
|
+
if (flags & 512 /* SkipTypeBaseClass */) {
|
3730
|
+
classLookupFlags |= 64 /* SkipTypeBaseClass */;
|
3707
3731
|
}
|
3708
|
-
if (flags &
|
3732
|
+
if (flags & 256 /* SkipOriginalClass */) {
|
3709
3733
|
classLookupFlags |= 1 /* SkipOriginalClass */;
|
3710
3734
|
}
|
3711
3735
|
// Always look for a member with a declared type first.
|
3712
|
-
let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags |
|
3736
|
+
let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags | 32 /* DeclaredTypesOnly */);
|
3713
3737
|
// If we couldn't find a symbol with a declared type, use
|
3714
3738
|
// a symbol with an inferred type.
|
3715
3739
|
if (!memberInfo) {
|
@@ -3746,7 +3770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3746
3770
|
if (typeResult) {
|
3747
3771
|
if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
|
3748
3772
|
type = typeResult.type;
|
3749
|
-
flags &=
|
3773
|
+
flags &= 16 /* DisallowClassVarWrites */;
|
3750
3774
|
}
|
3751
3775
|
}
|
3752
3776
|
}
|
@@ -3848,7 +3872,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3848
3872
|
// No attribute of that name was found. If this is a member access
|
3849
3873
|
// through an object, see if there's an attribute access override
|
3850
3874
|
// method ("__getattr__", etc.).
|
3851
|
-
if ((flags & (1 /* AccessClassMembersOnly */ |
|
3875
|
+
if ((flags & (1 /* AccessClassMembersOnly */ | 128 /* SkipAttributeAccessOverride */)) ===
|
3852
3876
|
0) {
|
3853
3877
|
const generalAttrType = applyAttributeAccessOverride(classType, errorNode, usage, memberName);
|
3854
3878
|
if (generalAttrType) {
|
@@ -3869,7 +3893,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3869
3893
|
// if they apply. Also binds methods to the class/object through which it
|
3870
3894
|
// is accessed.
|
3871
3895
|
function applyDescriptorAccessMethod(type, memberInfo, baseTypeClass, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag) {
|
3872
|
-
const treatConstructorAsClassMember = (flags &
|
3896
|
+
const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
|
3873
3897
|
let isTypeValid = true;
|
3874
3898
|
let isAsymmetricAccessor = false;
|
3875
3899
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
@@ -4111,7 +4135,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4111
4135
|
}
|
4112
4136
|
if (usage.method === 'set') {
|
4113
4137
|
if (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.symbol.isClassVar()) {
|
4114
|
-
if (flags &
|
4138
|
+
if (flags & 16 /* DisallowClassVarWrites */) {
|
4115
4139
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberSetClassVar().format({ name: memberName }));
|
4116
4140
|
isTypeValid = false;
|
4117
4141
|
return undefined;
|
@@ -4248,7 +4272,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4248
4272
|
// See if the class has a "__getattribute__" or "__getattr__" method.
|
4249
4273
|
// If so, arbitrary members are supported.
|
4250
4274
|
return (_a = getTypeOfClassMember(errorNode, classType, name, { method: 'get' },
|
4251
|
-
/* diag */ undefined,
|
4275
|
+
/* diag */ undefined, 8 /* SkipObjectBaseClass */ | 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
|
4252
4276
|
};
|
4253
4277
|
let accessMemberType;
|
4254
4278
|
if (usage.method === 'get') {
|
@@ -4663,7 +4687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4663
4687
|
(flags & 128 /* ExpectingInstantiableType */) === 0) {
|
4664
4688
|
const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
|
4665
4689
|
/* usage */ undefined,
|
4666
|
-
/* diag */ undefined,
|
4690
|
+
/* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */);
|
4667
4691
|
if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
|
4668
4692
|
// If the class doesn't derive from Generic, a type argument should not be allowed.
|
4669
4693
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsExpectingNone().format({
|
@@ -4899,10 +4923,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4899
4923
|
const itemMethodType = (0, types_1.isClassInstance)(baseType)
|
4900
4924
|
? (_a = getTypeOfObjectMember(node, baseType, magicMethodName,
|
4901
4925
|
/* usage */ undefined,
|
4902
|
-
/* diag */ undefined,
|
4926
|
+
/* diag */ undefined, 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type
|
4903
4927
|
: (_b = getTypeOfClassMember(node, baseType, magicMethodName,
|
4904
4928
|
/* usage */ undefined,
|
4905
|
-
/* diag */ undefined,
|
4929
|
+
/* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
|
4906
4930
|
if (!itemMethodType) {
|
4907
4931
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
4908
4932
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
|
@@ -5269,7 +5293,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5269
5293
|
matchingSubtype = subtype;
|
5270
5294
|
}
|
5271
5295
|
}
|
5272
|
-
}
|
5296
|
+
},
|
5297
|
+
/* sortSubtypes */ true);
|
5273
5298
|
effectiveExpectedType = matchingSubtype;
|
5274
5299
|
}
|
5275
5300
|
let expectedTypeDiagAddendum;
|
@@ -6106,7 +6131,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6106
6131
|
if (!isDiagnosticSuppressedForNode(errorNode)) {
|
6107
6132
|
const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
|
6108
6133
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
6109
|
-
const argTypes = argList.map((t) =>
|
6134
|
+
const argTypes = argList.map((t) => {
|
6135
|
+
const typeString = printType(getTypeOfArgument(t).type);
|
6136
|
+
if (t.argumentCategory === 1 /* UnpackedList */) {
|
6137
|
+
return `*${typeString}`;
|
6138
|
+
}
|
6139
|
+
if (t.argumentCategory === 2 /* UnpackedDictionary */) {
|
6140
|
+
return `**${typeString}`;
|
6141
|
+
}
|
6142
|
+
return typeString;
|
6143
|
+
});
|
6110
6144
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
|
6111
6145
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }) + diagAddendum.getString(), errorNode);
|
6112
6146
|
}
|
@@ -6610,7 +6644,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6610
6644
|
var _a, _b;
|
6611
6645
|
const memberType = (_a = getTypeOfObjectMember(errorNode, expandedCallType, '__call__',
|
6612
6646
|
/* usage */ undefined,
|
6613
|
-
/* diag */ undefined,
|
6647
|
+
/* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
|
6614
6648
|
if (!memberType) {
|
6615
6649
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
|
6616
6650
|
type: printType(expandedCallType),
|
@@ -7563,7 +7597,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7563
7597
|
return subtype;
|
7564
7598
|
}
|
7565
7599
|
return undefined;
|
7566
|
-
}
|
7600
|
+
},
|
7601
|
+
/* sortSubtypes */ true);
|
7567
7602
|
if ((0, types_1.isClassInstance)(filteredType)) {
|
7568
7603
|
effectiveExpectedType = filteredType;
|
7569
7604
|
}
|
@@ -8676,6 +8711,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8676
8711
|
functionType.details.paramSpec = typeResult.type;
|
8677
8712
|
return functionType;
|
8678
8713
|
}
|
8714
|
+
if ((0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis')) {
|
8715
|
+
types_1.FunctionType.addDefaultParameters(functionType);
|
8716
|
+
return functionType;
|
8717
|
+
}
|
8679
8718
|
}
|
8680
8719
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
|
8681
8720
|
return undefined;
|
@@ -8933,12 +8972,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8933
8972
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
8934
8973
|
magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, magicMethodName,
|
8935
8974
|
/* usage */ undefined,
|
8936
|
-
/* diag */ undefined,
|
8975
|
+
/* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
|
8937
8976
|
}
|
8938
8977
|
else if ((0, types_1.isInstantiableClass)(concreteSubtype)) {
|
8939
8978
|
magicMethodType = (_b = getTypeOfClassMember(errorNode, concreteSubtype, magicMethodName,
|
8940
8979
|
/* usage */ undefined,
|
8941
|
-
/* diag */ undefined,
|
8980
|
+
/* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
|
8942
8981
|
}
|
8943
8982
|
if (magicMethodType) {
|
8944
8983
|
const functionArgs = args.map((arg) => {
|
@@ -9027,7 +9066,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9027
9066
|
matchingSubtypeResult = subtypeResult;
|
9028
9067
|
}
|
9029
9068
|
}
|
9030
|
-
}
|
9069
|
+
},
|
9070
|
+
/* sortSubtypes */ true);
|
9031
9071
|
effectiveExpectedType = matchingSubtype;
|
9032
9072
|
}
|
9033
9073
|
let expectedTypeDiagAddendum = undefined;
|
@@ -9344,7 +9384,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9344
9384
|
matchingSubtypeResult = subtypeResult;
|
9345
9385
|
}
|
9346
9386
|
}
|
9347
|
-
}
|
9387
|
+
},
|
9388
|
+
/* sortSubtypes */ true);
|
9348
9389
|
effectiveExpectedType = matchingSubtype;
|
9349
9390
|
}
|
9350
9391
|
let expectedTypeDiagAddendum;
|
@@ -11812,8 +11853,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11812
11853
|
const initSubclassMethodInfo = getTypeOfClassMemberName(errorNode, classType,
|
11813
11854
|
/* isAccessedThroughObject */ false, '__init_subclass__', { method: 'get' },
|
11814
11855
|
/* diag */ undefined, 1 /* AccessClassMembersOnly */ |
|
11815
|
-
|
11816
|
-
|
11856
|
+
8 /* SkipObjectBaseClass */ |
|
11857
|
+
256 /* SkipOriginalClass */, classType);
|
11817
11858
|
if (initSubclassMethodInfo) {
|
11818
11859
|
const initSubclassMethodType = initSubclassMethodInfo.type;
|
11819
11860
|
if (initSubclassMethodType) {
|
@@ -11824,7 +11865,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11824
11865
|
}
|
11825
11866
|
else if (classType.details.effectiveMetaclass && (0, types_1.isClass)(classType.details.effectiveMetaclass)) {
|
11826
11867
|
// See if the metaclass has a `__new__` method that accepts keyword parameters.
|
11827
|
-
const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__',
|
11868
|
+
const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 64 /* SkipTypeBaseClass */);
|
11828
11869
|
if (newMethodMember) {
|
11829
11870
|
const newMethodType = getTypeOfMember(newMethodMember);
|
11830
11871
|
if ((0, types_1.isFunction)(newMethodType)) {
|
@@ -11887,20 +11928,72 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11887
11928
|
});
|
11888
11929
|
}
|
11889
11930
|
function getTypeOfFunction(node) {
|
11890
|
-
|
11891
|
-
|
11892
|
-
|
11893
|
-
|
11894
|
-
if (cachedFunctionType) {
|
11895
|
-
if (!(0, types_1.isFunction)(cachedFunctionType)) {
|
11931
|
+
// Is this predecorated function type cached?
|
11932
|
+
let functionType = readTypeCache(node.name, 0 /* None */);
|
11933
|
+
if (functionType) {
|
11934
|
+
if (!(0, types_1.isFunction)(functionType)) {
|
11896
11935
|
// This can happen in certain rare circumstances where the
|
11897
11936
|
// function declaration falls within an unreachable code block.
|
11898
11937
|
return undefined;
|
11899
11938
|
}
|
11900
|
-
|
11901
|
-
|
11902
|
-
|
11903
|
-
|
11939
|
+
}
|
11940
|
+
else {
|
11941
|
+
functionType = getTypeOfFunctionPredecorated(node);
|
11942
|
+
}
|
11943
|
+
// Is the decorated function type cached?
|
11944
|
+
let decoratedType = readTypeCache(node, 0 /* None */);
|
11945
|
+
if (decoratedType) {
|
11946
|
+
return { functionType, decoratedType };
|
11947
|
+
}
|
11948
|
+
// Populate the cache with a temporary value to handle recursion.
|
11949
|
+
writeTypeCache(node, { type: functionType }, /* flags */ undefined);
|
11950
|
+
// If it's an async function, wrap the return type in an Awaitable or Generator.
|
11951
|
+
// Set the "partially evaluated" flag around this logic to detect recursion.
|
11952
|
+
functionType.details.flags |= 131072 /* PartiallyEvaluated */;
|
11953
|
+
const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
|
11954
|
+
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
11955
|
+
// Apply all of the decorators in reverse order.
|
11956
|
+
decoratedType = preDecoratedType;
|
11957
|
+
let foundUnknown = false;
|
11958
|
+
for (let i = node.decorators.length - 1; i >= 0; i--) {
|
11959
|
+
const decorator = node.decorators[i];
|
11960
|
+
const newDecoratedType = (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
|
11961
|
+
const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
|
11962
|
+
if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
|
11963
|
+
// Report this error only on the first unknown type.
|
11964
|
+
if (!foundUnknown) {
|
11965
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
11966
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
11967
|
+
foundUnknown = true;
|
11968
|
+
}
|
11969
|
+
}
|
11970
|
+
else {
|
11971
|
+
// Apply the decorator only if the type is known.
|
11972
|
+
decoratedType = newDecoratedType;
|
11973
|
+
}
|
11974
|
+
}
|
11975
|
+
// See if there are any overloads provided by previous function declarations.
|
11976
|
+
if ((0, types_1.isFunction)(decoratedType)) {
|
11977
|
+
if (types_1.FunctionType.isOverloaded(decoratedType)) {
|
11978
|
+
// Mark all the parameters as accessed.
|
11979
|
+
node.parameters.forEach((param) => {
|
11980
|
+
markParamAccessed(param);
|
11981
|
+
});
|
11982
|
+
}
|
11983
|
+
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
|
11984
|
+
}
|
11985
|
+
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
11986
|
+
return { functionType, decoratedType };
|
11987
|
+
}
|
11988
|
+
// Evaluates the type of a "def" statement without applying an async
|
11989
|
+
// modifier or any decorators.
|
11990
|
+
function getTypeOfFunctionPredecorated(node) {
|
11991
|
+
var _a, _b, _c;
|
11992
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
11993
|
+
// Is this type already cached?
|
11994
|
+
const cachedFunctionType = readTypeCache(node.name, 0 /* None */);
|
11995
|
+
if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
|
11996
|
+
return cachedFunctionType;
|
11904
11997
|
}
|
11905
11998
|
let functionDecl;
|
11906
11999
|
const decl = AnalyzerNodeInfo.getDeclaration(node);
|
@@ -11912,11 +12005,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11912
12005
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
|
11913
12006
|
let containingClassType;
|
11914
12007
|
if (containingClassNode) {
|
11915
|
-
|
11916
|
-
if (!classInfo) {
|
11917
|
-
return undefined;
|
11918
|
-
}
|
11919
|
-
containingClassType = classInfo.classType;
|
12008
|
+
containingClassType = (_a = getTypeOfClass(containingClassNode)) === null || _a === void 0 ? void 0 : _a.classType;
|
11920
12009
|
}
|
11921
12010
|
let functionFlags = (0, decorators_1.getFunctionFlagsFromDecorators)(evaluatorInterface, node, !!containingClassNode);
|
11922
12011
|
if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
|
@@ -11945,14 +12034,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11945
12034
|
functionType.details.builtInName = node.name.value;
|
11946
12035
|
}
|
11947
12036
|
functionType.details.declaration = functionDecl;
|
11948
|
-
// Allow recursion by registering the partially-constructed
|
11949
|
-
// function type.
|
12037
|
+
// Allow recursion by caching and registering the partially-constructed function type.
|
11950
12038
|
const scope = ScopeUtils.getScopeForNode(node);
|
11951
12039
|
const functionSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(node.name.value);
|
11952
12040
|
if (functionDecl && functionSymbol) {
|
11953
12041
|
setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
|
11954
12042
|
}
|
11955
|
-
writeTypeCache(node, { type: functionType }, /* flags */ undefined);
|
11956
12043
|
writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
|
11957
12044
|
// Is this an "__init__" method within a pseudo-generic class? If so,
|
11958
12045
|
// we'll add generic types to the constructor's parameters.
|
@@ -11992,14 +12079,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11992
12079
|
else {
|
11993
12080
|
functionType.details.typeParameters = typeParametersSeen;
|
11994
12081
|
}
|
11995
|
-
const markParamAccessed = (param) => {
|
11996
|
-
if (param.name) {
|
11997
|
-
const symbolWithScope = lookUpSymbolRecursive(param.name, param.name.value, /* honorCodeFlow */ false);
|
11998
|
-
if (symbolWithScope) {
|
11999
|
-
setSymbolAccessed(fileInfo, symbolWithScope.symbol, param.name);
|
12000
|
-
}
|
12001
|
-
}
|
12002
|
-
};
|
12003
12082
|
let paramsArePositionOnly = true;
|
12004
12083
|
const isFirstParamClsOrSelf = containingClassType &&
|
12005
12084
|
(types_1.FunctionType.isClassMethod(functionType) ||
|
@@ -12181,7 +12260,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12181
12260
|
// If there was a defined return type, analyze that first so when we
|
12182
12261
|
// walk the contents of the function, return statements can be
|
12183
12262
|
// validated against this type.
|
12184
|
-
const returnTypeAnnotationNode = (
|
12263
|
+
const returnTypeAnnotationNode = (_b = node.returnTypeAnnotation) !== null && _b !== void 0 ? _b : (_c = node.functionAnnotationComment) === null || _c === void 0 ? void 0 : _c.returnTypeAnnotation;
|
12185
12264
|
if (returnTypeAnnotationNode) {
|
12186
12265
|
// Temporarily set the return type to unknown in case of recursion.
|
12187
12266
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
@@ -12234,43 +12313,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12234
12313
|
}
|
12235
12314
|
validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index));
|
12236
12315
|
});
|
12237
|
-
// If it's an async function, wrap the return type in an Awaitable or Generator.
|
12238
|
-
const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
|
12239
12316
|
// Clear the "partially evaluated" flag to indicate that the functionType
|
12240
12317
|
// is fully evaluated.
|
12241
12318
|
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
12242
|
-
|
12243
|
-
|
12244
|
-
|
12245
|
-
|
12246
|
-
|
12247
|
-
const
|
12248
|
-
|
12249
|
-
|
12250
|
-
// Report this error only on the first unknown type.
|
12251
|
-
if (!foundUnknown) {
|
12252
|
-
addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
|
12253
|
-
foundUnknown = true;
|
12254
|
-
}
|
12255
|
-
}
|
12256
|
-
else {
|
12257
|
-
// Apply the decorator only if the type is known.
|
12258
|
-
decoratedType = newDecoratedType;
|
12259
|
-
}
|
12260
|
-
}
|
12261
|
-
// See if there are any overloads provided by previous function declarations.
|
12262
|
-
if ((0, types_1.isFunction)(decoratedType)) {
|
12263
|
-
if (types_1.FunctionType.isOverloaded(decoratedType)) {
|
12264
|
-
// Mark all the parameters as accessed.
|
12265
|
-
node.parameters.forEach((param) => {
|
12266
|
-
markParamAccessed(param);
|
12267
|
-
});
|
12319
|
+
writeTypeCache(node.name, { type: functionType }, 0 /* None */);
|
12320
|
+
return functionType;
|
12321
|
+
}
|
12322
|
+
function markParamAccessed(param) {
|
12323
|
+
if (param.name) {
|
12324
|
+
const symbolWithScope = lookUpSymbolRecursive(param.name, param.name.value, /* honorCodeFlow */ false);
|
12325
|
+
if (symbolWithScope) {
|
12326
|
+
setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(param), symbolWithScope.symbol, param.name);
|
12268
12327
|
}
|
12269
|
-
decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
|
12270
12328
|
}
|
12271
|
-
writeTypeCache(node.name, { type: functionType }, 0 /* None */);
|
12272
|
-
writeTypeCache(node, { type: decoratedType }, 0 /* None */);
|
12273
|
-
return { functionType, decoratedType };
|
12274
12329
|
}
|
12275
12330
|
// If the declared return type of a function contains type variables that
|
12276
12331
|
// are found nowhere else in the signature and are contained within a
|
@@ -14228,7 +14283,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14228
14283
|
if ((0, types_1.isInstantiableClass)(subtype)) {
|
14229
14284
|
// Try to find a member that has a declared type. If so, that
|
14230
14285
|
// overrides any inferred types.
|
14231
|
-
let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName,
|
14286
|
+
let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
|
14232
14287
|
if (!member) {
|
14233
14288
|
member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName);
|
14234
14289
|
}
|
@@ -14245,7 +14300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14245
14300
|
else if ((0, types_1.isClassInstance)(subtype)) {
|
14246
14301
|
// Try to find a member that has a declared type. If so, that
|
14247
14302
|
// overrides any inferred types.
|
14248
|
-
let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName,
|
14303
|
+
let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
|
14249
14304
|
if (!member) {
|
14250
14305
|
member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName);
|
14251
14306
|
}
|
@@ -14311,7 +14366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14311
14366
|
}
|
14312
14367
|
else if ((0, types_1.isInstantiableClass)(baseType)) {
|
14313
14368
|
const initMethodType = (_b = getTypeOfObjectMember(argNode.parent.leftExpression, types_1.ClassType.cloneAsInstance(baseType), '__init__', { method: 'get' },
|
14314
|
-
/* diag */ undefined,
|
14369
|
+
/* diag */ undefined, 8 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
|
14315
14370
|
if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
|
14316
14371
|
const paramDecl = getDeclarationFromFunctionNamedParameter(initMethodType, paramName);
|
14317
14372
|
if (paramDecl) {
|
@@ -15778,7 +15833,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15778
15833
|
if (destType.typeArguments) {
|
15779
15834
|
// If the dest type is specialized, make sure the specialized source
|
15780
15835
|
// type arguments are assignable to the dest type arguments.
|
15781
|
-
return assignTypeArguments(destType, curSrcType,
|
15836
|
+
return assignTypeArguments(destType, curSrcType,
|
15837
|
+
// Don't emit a diag addendum if we're in an invariant context. It's
|
15838
|
+
// sufficient to simply indicate that the types are not the same
|
15839
|
+
// in this case. Adding more information is unnecessary and confusing.
|
15840
|
+
(flags & 1 /* EnforceInvariance */) === 0 ? diag : undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
|
15782
15841
|
}
|
15783
15842
|
if (destTypeVarContext && curSrcType.typeArguments && !destTypeVarContext.isLocked()) {
|
15784
15843
|
// Populate the typeVar map with type arguments of the source.
|
@@ -16187,9 +16246,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16187
16246
|
}
|
16188
16247
|
if ((0, types_1.isInstantiableClass)(destType)) {
|
16189
16248
|
if ((0, types_1.isInstantiableClass)(expandedSrcType)) {
|
16190
|
-
// PEP 544 says that if the dest type is a
|
16249
|
+
// PEP 544 says that if the dest type is a type[Proto] class,
|
16191
16250
|
// the source must be a "concrete" (non-protocol) class.
|
16192
|
-
if (types_1.ClassType.isProtocolClass(destType)
|
16251
|
+
if (types_1.ClassType.isProtocolClass(destType) &&
|
16252
|
+
(flags & 4096 /* IgnoreProtocolAssignmentCheck */) === 0) {
|
16193
16253
|
if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
16194
16254
|
(0, types_1.isInstantiableClass)(srcType) &&
|
16195
16255
|
!srcType.includeSubclasses) {
|