@zzzen/pyright-internal 1.2.0-dev.20241103 → 1.2.0-dev.20241117
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.d.ts +1 -0
- package/dist/analyzer/binder.js +35 -12
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +2 -2
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/dataClasses.js +0 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -1
- package/dist/analyzer/importResolver.js +5 -5
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +6 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +6 -3
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/service.js +3 -3
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/serviceUtils.d.ts +0 -2
- package/dist/analyzer/serviceUtils.js +3 -5
- package/dist/analyzer/serviceUtils.js.map +1 -1
- package/dist/analyzer/symbol.js +1 -1
- package/dist/analyzer/symbol.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +216 -155
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +19 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +9 -7
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +10 -8
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/common/asyncInitialization.d.ts +1 -0
- package/dist/common/asyncInitialization.js +20 -0
- package/dist/common/asyncInitialization.js.map +1 -0
- package/dist/common/pathConsts.d.ts +3 -0
- package/dist/common/pathConsts.js +4 -1
- package/dist/common/pathConsts.js.map +1 -1
- package/dist/common/tomlUtils.d.ts +6 -0
- package/dist/common/tomlUtils.js +28 -0
- package/dist/common/tomlUtils.js.map +1 -0
- package/dist/languageService/autoImporter.d.ts +6 -2
- package/dist/languageService/autoImporter.js +15 -15
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/completionProvider.js +3 -1
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +2 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +21 -13
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +5 -4
- package/dist/localization/localize.js +5 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +1 -2
- package/dist/localization/package.nls.de.json +2 -3
- package/dist/localization/package.nls.en-us.json +19 -4
- package/dist/localization/package.nls.es.json +2 -3
- package/dist/localization/package.nls.fr.json +1 -2
- package/dist/localization/package.nls.it.json +2 -3
- package/dist/localization/package.nls.ja.json +1 -2
- package/dist/localization/package.nls.ko.json +1 -2
- package/dist/localization/package.nls.pl.json +1 -2
- package/dist/localization/package.nls.pt-br.json +1 -2
- package/dist/localization/package.nls.qps-ploc.json +1 -2
- package/dist/localization/package.nls.ru.json +1 -2
- package/dist/localization/package.nls.tr.json +1 -2
- package/dist/localization/package.nls.zh-cn.json +1 -2
- package/dist/localization/package.nls.zh-tw.json +1 -2
- package/dist/nodeMain.d.ts +1 -1
- package/dist/nodeMain.js +2 -2
- package/dist/nodeMain.js.map +1 -1
- package/dist/nodeServer.d.ts +1 -1
- package/dist/nodeServer.js +3 -5
- package/dist/nodeServer.js.map +1 -1
- package/dist/parser/parseNodes.d.ts +3 -2
- package/dist/parser/parseNodes.js +2 -1
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +2 -1
- package/dist/parser/parser.js +36 -7
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +2 -4
- package/dist/pyright.js.map +1 -1
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js +73 -0
- package/dist/tests/fourslash/signature.dataclassAlias.fourslash.js.map +1 -0
- package/dist/tests/harness/fourslash/testState.js +14 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.js +2 -2
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/lsp/languageServer.d.ts +1 -1
- package/dist/tests/lsp/languageServer.js +3 -1
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +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 +1 -1
- package/dist/tests/typeEvaluator5.test.js +2 -2
- package/dist/tests/typeEvaluator6.test.js +11 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +3 -3
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +2 -2
@@ -191,25 +191,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
191
191
|
let incompleteGenerationCount = 0;
|
192
192
|
const returnTypeInferenceContextStack = [];
|
193
193
|
let returnTypeInferenceTypeCache;
|
194
|
-
let isPrefetchedTypesInitialized = false;
|
195
194
|
const signatureTrackerStack = [];
|
196
|
-
|
197
|
-
let noneTypeClass;
|
198
|
-
let objectClass;
|
199
|
-
let typeClass;
|
200
|
-
let unionTypeClass;
|
201
|
-
let awaitableClass;
|
202
|
-
let functionClass;
|
203
|
-
let tupleClass;
|
204
|
-
let boolClass;
|
205
|
-
let intClass;
|
206
|
-
let strClass;
|
207
|
-
let dictClass;
|
208
|
-
let moduleTypeClass;
|
209
|
-
let typedDictClass;
|
210
|
-
let typedDictPrivateClass;
|
211
|
-
let supportsKeysAndGetItemClass;
|
212
|
-
let mappingClass;
|
195
|
+
let prefetched;
|
213
196
|
function runWithCancellationToken(token, callback) {
|
214
197
|
try {
|
215
198
|
cancellationToken = token;
|
@@ -480,43 +463,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
480
463
|
}
|
481
464
|
function initializePrefetchedTypes(node) {
|
482
465
|
var _a;
|
483
|
-
if (!
|
466
|
+
if (!prefetched) {
|
484
467
|
// Some of these types have cyclical dependencies on each other,
|
485
468
|
// so don't re-enter this block once we start executing it.
|
486
|
-
|
487
|
-
objectClass = getBuiltInType(node, 'object');
|
488
|
-
typeClass = getBuiltInType(node, 'type');
|
489
|
-
functionClass = getBuiltInType(node, 'function');
|
490
|
-
unionTypeClass = getTypesType(node, 'UnionType');
|
491
|
-
if (unionTypeClass && (0, types_1.isClass)(unionTypeClass)) {
|
492
|
-
unionTypeClass.shared.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
|
469
|
+
prefetched = {};
|
470
|
+
prefetched.objectClass = getBuiltInType(node, 'object');
|
471
|
+
prefetched.typeClass = getBuiltInType(node, 'type');
|
472
|
+
prefetched.functionClass = getBuiltInType(node, 'function');
|
473
|
+
prefetched.unionTypeClass = getTypesType(node, 'UnionType');
|
474
|
+
if (prefetched.unionTypeClass && (0, types_1.isClass)(prefetched.unionTypeClass)) {
|
475
|
+
prefetched.unionTypeClass.shared.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
|
493
476
|
}
|
494
477
|
// Initialize and cache "Collection" to break a cyclical dependency
|
495
478
|
// that occurs when resolving tuple below.
|
496
479
|
getTypingType(node, 'Collection');
|
497
|
-
noneTypeClass = (_a = getTypeshedType(node, 'NoneType')) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
498
|
-
tupleClass = getBuiltInType(node, 'tuple');
|
499
|
-
boolClass = getBuiltInType(node, 'bool');
|
500
|
-
intClass = getBuiltInType(node, 'int');
|
501
|
-
strClass = getBuiltInType(node, 'str');
|
502
|
-
dictClass = getBuiltInType(node, 'dict');
|
503
|
-
moduleTypeClass = getTypingType(node, 'ModuleType');
|
504
|
-
typedDictClass = getTypingType(node, 'TypedDict');
|
505
|
-
typedDictPrivateClass = getTypingType(node, '_TypedDict');
|
506
|
-
awaitableClass = getTypingType(node, 'Awaitable');
|
507
|
-
mappingClass = getTypingType(node, 'Mapping');
|
508
|
-
supportsKeysAndGetItemClass = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
509
|
-
if (!supportsKeysAndGetItemClass) {
|
480
|
+
prefetched.noneTypeClass = (_a = getTypeshedType(node, 'NoneType')) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
481
|
+
prefetched.tupleClass = getBuiltInType(node, 'tuple');
|
482
|
+
prefetched.boolClass = getBuiltInType(node, 'bool');
|
483
|
+
prefetched.intClass = getBuiltInType(node, 'int');
|
484
|
+
prefetched.strClass = getBuiltInType(node, 'str');
|
485
|
+
prefetched.dictClass = getBuiltInType(node, 'dict');
|
486
|
+
prefetched.moduleTypeClass = getTypingType(node, 'ModuleType');
|
487
|
+
prefetched.typedDictClass = getTypingType(node, 'TypedDict');
|
488
|
+
prefetched.typedDictPrivateClass = getTypingType(node, '_TypedDict');
|
489
|
+
prefetched.awaitableClass = getTypingType(node, 'Awaitable');
|
490
|
+
prefetched.mappingClass = getTypingType(node, 'Mapping');
|
491
|
+
prefetched.supportsKeysAndGetItemClass = getTypeshedType(node, 'SupportsKeysAndGetItem');
|
492
|
+
if (!prefetched.supportsKeysAndGetItemClass) {
|
510
493
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
511
|
-
supportsKeysAndGetItemClass = mappingClass;
|
494
|
+
prefetched.supportsKeysAndGetItemClass = prefetched.mappingClass;
|
512
495
|
}
|
513
496
|
// Wire up the `Any` class to the special-form version of our internal AnyType.
|
514
|
-
if (
|
497
|
+
if (prefetched.objectClass &&
|
498
|
+
(0, types_1.isInstantiableClass)(prefetched.objectClass) &&
|
499
|
+
prefetched.typeClass &&
|
500
|
+
(0, types_1.isInstantiableClass)(prefetched.typeClass)) {
|
515
501
|
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltIn */ | 8388608 /* ClassTypeFlags.SpecialFormClass */ | 16777216 /* ClassTypeFlags.IllegalIsinstanceClass */,
|
516
502
|
/* typeSourceId */ -1,
|
517
503
|
/* declaredMetaclass */ undefined,
|
518
|
-
/* effectiveMetaclass */ typeClass);
|
519
|
-
anyClass.shared.baseClasses.push(objectClass);
|
504
|
+
/* effectiveMetaclass */ prefetched.typeClass);
|
505
|
+
anyClass.shared.baseClasses.push(prefetched.objectClass);
|
520
506
|
(0, typeUtils_1.computeMroLinearization)(anyClass);
|
521
507
|
const anySpecialForm = types_1.AnyType.createSpecialForm();
|
522
508
|
if ((0, types_1.isAny)(anySpecialForm)) {
|
@@ -1122,8 +1108,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1122
1108
|
}
|
1123
1109
|
if (types_1.ClassType.isBuiltIn(subtype, 'LiteralString')) {
|
1124
1110
|
// Handle "LiteralString" specially.
|
1125
|
-
if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
1126
|
-
let strInstance = types_1.ClassType.cloneAsInstance(strClass);
|
1111
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) && (0, types_1.isInstantiableClass)(prefetched.strClass)) {
|
1112
|
+
let strInstance = types_1.ClassType.cloneAsInstance(prefetched.strClass);
|
1127
1113
|
strInstance = types_1.TypeBase.cloneForCondition(strInstance, (0, typeUtils_1.getTypeCondition)(subtype));
|
1128
1114
|
return strInstance;
|
1129
1115
|
}
|
@@ -1212,6 +1198,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1212
1198
|
if (tupleBaseClass && (0, types_1.isClass)(tupleBaseClass) && tupleBaseClass.priv.tupleTypeArgs) {
|
1213
1199
|
return (0, typeUtils_1.isUnboundedTupleClass)(tupleBaseClass) || tupleBaseClass.priv.tupleTypeArgs.length === 0;
|
1214
1200
|
}
|
1201
|
+
// Handle TypedDicts specially. If one or more entries are required
|
1202
|
+
// or known to exist, we can say for sure that the type is not falsy.
|
1203
|
+
if (types_1.ClassType.isTypedDictClass(type)) {
|
1204
|
+
const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, type, /* allowNarrowed */ true);
|
1205
|
+
if (tdEntries) {
|
1206
|
+
for (const tdEntry of tdEntries.knownItems.values()) {
|
1207
|
+
if (tdEntry.isRequired || tdEntry.isProvided) {
|
1208
|
+
return false;
|
1209
|
+
}
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
}
|
1215
1213
|
// Check for bool, int, str and bytes literals that are never falsy.
|
1216
1214
|
if (type.priv.literalValue !== undefined) {
|
1217
1215
|
if (types_1.ClassType.isBuiltIn(type, ['bool', 'int', 'str', 'bytes'])) {
|
@@ -1425,7 +1423,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1425
1423
|
function stripTypeGuard(type) {
|
1426
1424
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
1427
1425
|
if ((0, types_1.isClassInstance)(subtype) && types_1.ClassType.isBuiltIn(subtype, ['TypeGuard', 'TypeIs'])) {
|
1428
|
-
return boolClass ? (0, typeUtils_1.convertToInstance)(boolClass) : types_1.UnknownType.create();
|
1426
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.boolClass) ? (0, typeUtils_1.convertToInstance)(prefetched.boolClass) : types_1.UnknownType.create();
|
1429
1427
|
}
|
1430
1428
|
return subtype;
|
1431
1429
|
});
|
@@ -1854,10 +1852,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1854
1852
|
// (object that provides an __await__ that returns a generator object).
|
1855
1853
|
// If errorNode is undefined, no errors are reported.
|
1856
1854
|
function getTypeOfAwaitable(type, errorNode) {
|
1857
|
-
if (!
|
1855
|
+
if (!(prefetched === null || prefetched === void 0 ? void 0 : prefetched.awaitableClass) ||
|
1856
|
+
!(0, types_1.isInstantiableClass)(prefetched.awaitableClass) ||
|
1857
|
+
prefetched.awaitableClass.shared.typeParams.length !== 1) {
|
1858
1858
|
return types_1.UnknownType.create();
|
1859
1859
|
}
|
1860
|
-
const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(awaitableClass);
|
1860
|
+
const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(prefetched.awaitableClass);
|
1861
1861
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
1862
1862
|
subtype = makeTopLevelTypeVarsConcrete(subtype);
|
1863
1863
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
@@ -1919,8 +1919,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1919
1919
|
if (!isAsync && (0, types_1.isClassInstance)(subtype)) {
|
1920
1920
|
const getItemReturnType = (_b = getTypeOfMagicMethodCall(subtype, '__getitem__', [
|
1921
1921
|
{
|
1922
|
-
type: intClass && (0, types_1.isInstantiableClass)(intClass)
|
1923
|
-
? types_1.ClassType.cloneAsInstance(intClass)
|
1922
|
+
type: (prefetched === null || prefetched === void 0 ? void 0 : prefetched.intClass) && (0, types_1.isInstantiableClass)(prefetched.intClass)
|
1923
|
+
? types_1.ClassType.cloneAsInstance(prefetched.intClass)
|
1924
1924
|
: types_1.UnknownType.create(),
|
1925
1925
|
},
|
1926
1926
|
], errorNode)) === null || _b === void 0 ? void 0 : _b.type;
|
@@ -2047,29 +2047,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2047
2047
|
return isTypeHashable;
|
2048
2048
|
}
|
2049
2049
|
function getTypedDictClassType() {
|
2050
|
-
return typedDictPrivateClass && (0, types_1.isInstantiableClass)(typedDictPrivateClass)
|
2050
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.typedDictPrivateClass) && (0, types_1.isInstantiableClass)(prefetched.typedDictPrivateClass)
|
2051
|
+
? prefetched.typedDictPrivateClass
|
2052
|
+
: undefined;
|
2051
2053
|
}
|
2052
2054
|
function getTupleClassType() {
|
2053
|
-
return tupleClass && (0, types_1.isInstantiableClass)(tupleClass) ? tupleClass : undefined;
|
2055
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.tupleClass) && (0, types_1.isInstantiableClass)(prefetched.tupleClass) ? prefetched.tupleClass : undefined;
|
2054
2056
|
}
|
2055
2057
|
function getDictClassType() {
|
2056
|
-
return dictClass && (0, types_1.isInstantiableClass)(dictClass) ? dictClass : undefined;
|
2058
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.dictClass) && (0, types_1.isInstantiableClass)(prefetched.dictClass) ? prefetched.dictClass : undefined;
|
2057
2059
|
}
|
2058
2060
|
function getStrClassType() {
|
2059
|
-
return strClass && (0, types_1.isInstantiableClass)(strClass) ? strClass : undefined;
|
2061
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) && (0, types_1.isInstantiableClass)(prefetched.strClass) ? prefetched.strClass : undefined;
|
2060
2062
|
}
|
2061
2063
|
function getObjectType() {
|
2062
|
-
return objectClass ? (0, typeUtils_1.convertToInstance)(objectClass) : types_1.UnknownType.create();
|
2064
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.objectClass) ? (0, typeUtils_1.convertToInstance)(prefetched.objectClass) : types_1.UnknownType.create();
|
2063
2065
|
}
|
2064
2066
|
function getNoneType() {
|
2065
|
-
return noneTypeClass ? (0, typeUtils_1.convertToInstance)(noneTypeClass) : types_1.UnknownType.create();
|
2067
|
+
return (prefetched === null || prefetched === void 0 ? void 0 : prefetched.noneTypeClass) ? (0, typeUtils_1.convertToInstance)(prefetched.noneTypeClass) : types_1.UnknownType.create();
|
2066
2068
|
}
|
2067
2069
|
function getUnionClassType() {
|
2068
|
-
|
2070
|
+
var _a;
|
2071
|
+
return (_a = prefetched === null || prefetched === void 0 ? void 0 : prefetched.unionTypeClass) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
2069
2072
|
}
|
2070
2073
|
function getTypeClassType() {
|
2071
|
-
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
2072
|
-
return typeClass;
|
2074
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.typeClass) && (0, types_1.isInstantiableClass)(prefetched.typeClass)) {
|
2075
|
+
return prefetched.typeClass;
|
2073
2076
|
}
|
2074
2077
|
return undefined;
|
2075
2078
|
}
|
@@ -2457,9 +2460,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2457
2460
|
if (isThisClass && isInstanceMember && memberClass) {
|
2458
2461
|
const inheritedSlotsNames = types_1.ClassType.getInheritedSlotsNames(memberClass);
|
2459
2462
|
if (inheritedSlotsNames && memberClass.shared.localSlotsNames) {
|
2460
|
-
// Skip this check if the local slots is specified but empty
|
2461
|
-
//
|
2462
|
-
|
2463
|
+
// Skip this check if the local slots is specified but empty
|
2464
|
+
// and the class isn't final. This pattern is used in a
|
2465
|
+
// legitimate manner for mix-in classes.
|
2466
|
+
if ((memberClass.shared.localSlotsNames.length > 0 || types_1.ClassType.isFinal(memberClass)) &&
|
2463
2467
|
!inheritedSlotsNames.some((name) => name === memberName)) {
|
2464
2468
|
// Determine whether the assignment corresponds to a descriptor
|
2465
2469
|
// that was assigned as a class variable. If so, then slots will not
|
@@ -2652,8 +2656,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2652
2656
|
return (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: getObjectType(), isUnbounded: true }]);
|
2653
2657
|
}
|
2654
2658
|
else if (subtype.priv.paramSpecAccess === 'kwargs') {
|
2655
|
-
if (
|
2656
|
-
|
2659
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.dictClass) &&
|
2660
|
+
(0, types_1.isInstantiableClass)(prefetched.dictClass) &&
|
2661
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) &&
|
2662
|
+
(0, types_1.isInstantiableClass)(prefetched.strClass)) {
|
2663
|
+
return types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(prefetched.dictClass, [
|
2664
|
+
(0, typeUtils_1.convertToInstance)(prefetched.strClass),
|
2665
|
+
getObjectType(),
|
2666
|
+
]));
|
2657
2667
|
}
|
2658
2668
|
return types_1.UnknownType.create();
|
2659
2669
|
}
|
@@ -2670,8 +2680,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2670
2680
|
// If it's in a union, convert to type or object.
|
2671
2681
|
if (subtype.priv.isInUnion) {
|
2672
2682
|
if (types_1.TypeBase.isInstantiable(subtype)) {
|
2673
|
-
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
2674
|
-
return typeClass;
|
2683
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.typeClass) && (0, types_1.isInstantiableClass)(prefetched.typeClass)) {
|
2684
|
+
return prefetched.typeClass;
|
2675
2685
|
}
|
2676
2686
|
}
|
2677
2687
|
else {
|
@@ -2953,7 +2963,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2953
2963
|
}
|
2954
2964
|
}
|
2955
2965
|
}
|
2956
|
-
function verifyRaiseExceptionType(node) {
|
2966
|
+
function verifyRaiseExceptionType(node, allowNone) {
|
2957
2967
|
const baseExceptionType = getBuiltInType(node, 'BaseException');
|
2958
2968
|
const exceptionType = getTypeOfExpression(node).type;
|
2959
2969
|
// Validate that the argument of "raise" is an exception object or class.
|
@@ -2963,7 +2973,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2963
2973
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
2964
2974
|
(0, typeUtils_1.doForEachSubtype)(exceptionType, (subtype) => {
|
2965
2975
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
2966
|
-
if ((0, types_1.isAnyOrUnknown)(concreteSubtype) || (0, types_1.isNever)(concreteSubtype)
|
2976
|
+
if ((0, types_1.isAnyOrUnknown)(concreteSubtype) || (0, types_1.isNever)(concreteSubtype)) {
|
2977
|
+
return;
|
2978
|
+
}
|
2979
|
+
if (allowNone && (0, typeUtils_1.isNoneInstance)(concreteSubtype)) {
|
2967
2980
|
return;
|
2968
2981
|
}
|
2969
2982
|
if ((0, types_1.isInstantiableClass)(concreteSubtype) && concreteSubtype.priv.literalValue === undefined) {
|
@@ -3277,8 +3290,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3277
3290
|
if ((flags & exemptFlags) !== 0) {
|
3278
3291
|
return type;
|
3279
3292
|
}
|
3280
|
-
if (convertModule &&
|
3281
|
-
|
3293
|
+
if (convertModule &&
|
3294
|
+
(0, types_1.isModule)(type) &&
|
3295
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.moduleTypeClass) &&
|
3296
|
+
(0, types_1.isInstantiableClass)(prefetched.moduleTypeClass)) {
|
3297
|
+
return types_1.ClassType.cloneAsInstance(prefetched.moduleTypeClass);
|
3282
3298
|
}
|
3283
3299
|
// Isinstance treats traditional (non-PEP 695) type aliases that are unions
|
3284
3300
|
// as tuples of classes rather than unions.
|
@@ -3999,7 +4015,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3999
4015
|
}
|
4000
4016
|
}
|
4001
4017
|
else {
|
4002
|
-
type = getTypeOfMemberAccessWithBaseType(node, {
|
4018
|
+
type = getTypeOfMemberAccessWithBaseType(node, {
|
4019
|
+
type: (prefetched === null || prefetched === void 0 ? void 0 : prefetched.functionClass)
|
4020
|
+
? (0, typeUtils_1.convertToInstance)(prefetched.functionClass)
|
4021
|
+
: types_1.UnknownType.create(),
|
4022
|
+
}, usage, flags).type;
|
4003
4023
|
}
|
4004
4024
|
break;
|
4005
4025
|
}
|
@@ -4523,8 +4543,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4523
4543
|
isAsymmetric = false;
|
4524
4544
|
}
|
4525
4545
|
else {
|
4526
|
-
let getterType =
|
4527
|
-
const setterType =
|
4546
|
+
let getterType = getTypeOfMember(getterSymbolResult);
|
4547
|
+
const setterType = getTypeOfMember(setterSymbolResult);
|
4528
4548
|
// If this is an overload, find the appropriate overload.
|
4529
4549
|
if ((0, types_1.isOverloaded)(getterType)) {
|
4530
4550
|
const getOverloads = types_1.OverloadedType.getOverloads(getterType).filter((overload) => {
|
@@ -4626,8 +4646,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4626
4646
|
argList.push({
|
4627
4647
|
argCategory: 0 /* ArgCategory.Simple */,
|
4628
4648
|
typeResult: {
|
4629
|
-
type: strClass && (0, types_1.isInstantiableClass)(strClass)
|
4630
|
-
? types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(strClass), memberName)
|
4649
|
+
type: (prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) && (0, types_1.isInstantiableClass)(prefetched.strClass)
|
4650
|
+
? types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneAsInstance(prefetched.strClass), memberName)
|
4631
4651
|
: types_1.AnyType.create(),
|
4632
4652
|
},
|
4633
4653
|
});
|
@@ -4887,7 +4907,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4887
4907
|
},
|
4888
4908
|
});
|
4889
4909
|
}
|
4890
|
-
else if ((0, types_1.isTypeVarTuple)(param) && tupleClass && (0, types_1.isInstantiableClass)(tupleClass)) {
|
4910
|
+
else if ((0, types_1.isTypeVarTuple)(param) && (prefetched === null || prefetched === void 0 ? void 0 : prefetched.tupleClass) && (0, types_1.isInstantiableClass)(prefetched.tupleClass)) {
|
4891
4911
|
defaultType = (0, tuples_1.makeTupleObject)(evaluatorInterface, [{ type: types_1.UnknownType.create(), isUnbounded: true }],
|
4892
4912
|
/* isUnpacked */ true);
|
4893
4913
|
}
|
@@ -5709,10 +5729,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5709
5729
|
setTypeResultForNode(node, { type: types_1.UnknownType.create() });
|
5710
5730
|
}
|
5711
5731
|
else if (node.nodeType === 18 /* ParseNodeType.Dictionary */ && supportsDictExpression) {
|
5712
|
-
const inlinedTypeDict = typedDictClass && (0, types_1.isInstantiableClass)(typedDictClass)
|
5713
|
-
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, typedDictClass)
|
5732
|
+
const inlinedTypeDict = (prefetched === null || prefetched === void 0 ? void 0 : prefetched.typedDictClass) && (0, types_1.isInstantiableClass)(prefetched.typedDictClass)
|
5733
|
+
? (0, typedDicts_1.createTypedDictTypeInlined)(evaluatorInterface, node, prefetched.typedDictClass)
|
5714
5734
|
: undefined;
|
5715
|
-
const keyTypeFallback = strClass && (0, types_1.isInstantiableClass)(strClass)
|
5735
|
+
const keyTypeFallback = (prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) && (0, types_1.isInstantiableClass)(prefetched.strClass)
|
5736
|
+
? prefetched.strClass
|
5737
|
+
: types_1.UnknownType.create();
|
5716
5738
|
typeResult = {
|
5717
5739
|
type: keyTypeFallback,
|
5718
5740
|
inlinedTypeDict,
|
@@ -6091,7 +6113,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6091
6113
|
return getNoneType();
|
6092
6114
|
}
|
6093
6115
|
function getTypeOfSuperCall(node) {
|
6094
|
-
var _a, _b;
|
6116
|
+
var _a, _b, _c;
|
6095
6117
|
if (node.d.args.length > 2) {
|
6096
6118
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.superCallArgCount(), node.d.args[2]);
|
6097
6119
|
}
|
@@ -6251,7 +6273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6251
6273
|
else if (effectiveTargetClass &&
|
6252
6274
|
!(0, types_1.isAnyOrUnknown)(effectiveTargetClass) &&
|
6253
6275
|
!(0, typeUtils_1.derivesFromAnyOrUnknown)(effectiveTargetClass)) {
|
6254
|
-
resultType = objectClass !== null &&
|
6276
|
+
resultType = (_b = prefetched === null || prefetched === void 0 ? void 0 : prefetched.objectClass) !== null && _b !== void 0 ? _b : types_1.UnknownType.create();
|
6255
6277
|
}
|
6256
6278
|
else {
|
6257
6279
|
resultType = types_1.UnknownType.create();
|
@@ -6269,7 +6291,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6269
6291
|
// If this is a zero-argument form of super(), synthesize
|
6270
6292
|
// a Self type to bind to.
|
6271
6293
|
bindToSelfType = types_1.TypeBase.cloneForCondition(types_1.TypeVarType.cloneAsBound((0, typeUtils_1.synthesizeTypeVarForSelfCls)(types_1.ClassType.cloneIncludeSubclasses(bindToType, /* includeSubclasses */ false),
|
6272
|
-
/* isClsParam */ false)), (
|
6294
|
+
/* isClsParam */ false)), (_c = bindToType.props) === null || _c === void 0 ? void 0 : _c.condition);
|
6273
6295
|
}
|
6274
6296
|
}
|
6275
6297
|
const type = resultIsInstance ? (0, typeUtils_1.convertToInstance)(resultType, /* includeSubclasses */ false) : resultType;
|
@@ -6304,9 +6326,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6304
6326
|
return { type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(nextBaseClassType) : nextBaseClassType };
|
6305
6327
|
}
|
6306
6328
|
// There's not much we can say about the type. Simply return object or type.
|
6307
|
-
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
6329
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.typeClass) && (0, types_1.isInstantiableClass)(prefetched.typeClass)) {
|
6308
6330
|
return {
|
6309
|
-
type: resultIsInstance ? getObjectType() : (0, typeUtils_1.convertToInstance)(typeClass),
|
6331
|
+
type: resultIsInstance ? getObjectType() : (0, typeUtils_1.convertToInstance)(prefetched.typeClass),
|
6310
6332
|
};
|
6311
6333
|
}
|
6312
6334
|
}
|
@@ -7294,7 +7316,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7294
7316
|
// If this is a tuple with specified element types, use those
|
7295
7317
|
// specified types rather than using the more generic iterator
|
7296
7318
|
// type which will be a union of all element types.
|
7297
|
-
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), tupleClass);
|
7319
|
+
const combinedArgType = (0, typeUtils_1.combineSameSizedTuples)(makeTopLevelTypeVarsConcrete(argType), prefetched === null || prefetched === void 0 ? void 0 : prefetched.tupleClass);
|
7298
7320
|
if ((0, types_1.isClassInstance)(combinedArgType) && (0, typeUtils_1.isTupleClass)(combinedArgType)) {
|
7299
7321
|
const tupleTypeArgs = (_a = combinedArgType.priv.tupleTypeArgs) !== null && _a !== void 0 ? _a : [];
|
7300
7322
|
if (tupleTypeArgs.length !== 1 || !tupleTypeArgs[0].isUnbounded) {
|
@@ -7847,8 +7869,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7847
7869
|
}
|
7848
7870
|
else {
|
7849
7871
|
const strObjType = getBuiltInObject(errorNode, 'str');
|
7850
|
-
if (supportsKeysAndGetItemClass &&
|
7851
|
-
(0, types_1.isInstantiableClass)(supportsKeysAndGetItemClass) &&
|
7872
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.supportsKeysAndGetItemClass) &&
|
7873
|
+
(0, types_1.isInstantiableClass)(prefetched.supportsKeysAndGetItemClass) &&
|
7852
7874
|
strObjType &&
|
7853
7875
|
(0, types_1.isClassInstance)(strObjType)) {
|
7854
7876
|
const mappingConstraints = new constraintTracker_1.ConstraintTracker();
|
@@ -7858,9 +7880,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7858
7880
|
if ((0, types_1.isTypeVar)(argType)) {
|
7859
7881
|
isValidMappingType = true;
|
7860
7882
|
}
|
7861
|
-
else if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), argType,
|
7883
|
+
else if (assignType(types_1.ClassType.cloneAsInstance(prefetched.supportsKeysAndGetItemClass), argType,
|
7862
7884
|
/* diag */ undefined, mappingConstraints)) {
|
7863
|
-
const specializedMapping = solveAndApplyConstraints(supportsKeysAndGetItemClass, mappingConstraints);
|
7885
|
+
const specializedMapping = solveAndApplyConstraints(prefetched.supportsKeysAndGetItemClass, mappingConstraints);
|
7864
7886
|
const typeArgs = specializedMapping.priv.typeArgs;
|
7865
7887
|
if (typeArgs && typeArgs.length >= 2) {
|
7866
7888
|
if (assignType(strObjType, typeArgs[0])) {
|
@@ -8848,7 +8870,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8848
8870
|
return { isCompatible: false, argType, isTypeIncomplete, skippedBareTypeVarExpectedType, condition };
|
8849
8871
|
}
|
8850
8872
|
if (!options.skipUnknownArgCheck) {
|
8851
|
-
const simplifiedType = (0, types_1.removeUnbound)(argType);
|
8873
|
+
const simplifiedType = makeTopLevelTypeVarsConcrete((0, types_1.removeUnbound)(argType));
|
8852
8874
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
8853
8875
|
function getDiagAddendum() {
|
8854
8876
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
@@ -9318,7 +9340,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9318
9340
|
// in the Python specification: The static type checker will treat
|
9319
9341
|
// the new type as if it were a subclass of the original type.
|
9320
9342
|
function createNewType(errorNode, argList) {
|
9321
|
-
var _a, _b, _c, _d;
|
9343
|
+
var _a, _b, _c, _d, _e;
|
9322
9344
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
9323
9345
|
let className = '';
|
9324
9346
|
if (argList.length !== 2) {
|
@@ -9344,12 +9366,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9344
9366
|
let baseClass = getTypeOfArgExpectingType(argList[1]).type;
|
9345
9367
|
let isBaseClassAny = false;
|
9346
9368
|
if ((0, types_1.isAnyOrUnknown)(baseClass)) {
|
9347
|
-
baseClass = objectClass !== null &&
|
9348
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (
|
9369
|
+
baseClass = (_c = prefetched === null || prefetched === void 0 ? void 0 : prefetched.objectClass) !== null && _c !== void 0 ? _c : types_1.UnknownType.create();
|
9370
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeAnyOrUnknown(), (_d = argList[1].node) !== null && _d !== void 0 ? _d : errorNode);
|
9349
9371
|
isBaseClassAny = true;
|
9350
9372
|
}
|
9351
9373
|
// Specifically disallow Annotated.
|
9352
|
-
if (((
|
9374
|
+
if (((_e = baseClass.props) === null || _e === void 0 ? void 0 : _e.specialForm) &&
|
9353
9375
|
(0, types_1.isClassInstance)(baseClass.props.specialForm) &&
|
9354
9376
|
types_1.ClassType.isBuiltIn(baseClass.props.specialForm, 'Annotated')) {
|
9355
9377
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeNotAClass(), argList[1].node || errorNode);
|
@@ -9417,8 +9439,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9417
9439
|
function getTypeOfConstant(node, flags) {
|
9418
9440
|
let type;
|
9419
9441
|
if (node.d.constType === 26 /* KeywordType.None */) {
|
9420
|
-
if (noneTypeClass) {
|
9421
|
-
type =
|
9442
|
+
if (prefetched === null || prefetched === void 0 ? void 0 : prefetched.noneTypeClass) {
|
9443
|
+
type =
|
9444
|
+
(flags & 128 /* EvalFlags.InstantiableType */) !== 0
|
9445
|
+
? prefetched.noneTypeClass
|
9446
|
+
: (0, typeUtils_1.convertToInstance)(prefetched.noneTypeClass);
|
9422
9447
|
if (isTypeFormSupported(node)) {
|
9423
9448
|
type = types_1.TypeBase.cloneWithTypeForm(type, (0, typeUtils_1.convertToInstance)(type));
|
9424
9449
|
}
|
@@ -9510,15 +9535,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9510
9535
|
return handleSubtype(subtype);
|
9511
9536
|
}
|
9512
9537
|
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
9513
|
-
if (objectClass && (0, types_1.isInstantiableClass)(objectClass)) {
|
9538
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.objectClass) && (0, types_1.isInstantiableClass)(prefetched.objectClass)) {
|
9514
9539
|
// Use 'object' for 'None'.
|
9515
|
-
return handleSubtype(types_1.ClassType.cloneAsInstance(objectClass));
|
9540
|
+
return handleSubtype(types_1.ClassType.cloneAsInstance(prefetched.objectClass));
|
9516
9541
|
}
|
9517
9542
|
}
|
9518
9543
|
if ((0, typeUtils_1.isNoneTypeClass)(subtype)) {
|
9519
|
-
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
9544
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.typeClass) && (0, types_1.isInstantiableClass)(prefetched.typeClass)) {
|
9520
9545
|
// Use 'type' for 'type[None]'.
|
9521
|
-
return handleSubtype(types_1.ClassType.cloneAsInstance(typeClass));
|
9546
|
+
return handleSubtype(types_1.ClassType.cloneAsInstance(prefetched.typeClass));
|
9522
9547
|
}
|
9523
9548
|
}
|
9524
9549
|
magicMethodSupported = false;
|
@@ -9805,8 +9830,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9805
9830
|
else if (entryNode.nodeType === 19 /* ParseNodeType.DictionaryExpandEntry */) {
|
9806
9831
|
let expectedType;
|
9807
9832
|
if (expectedKeyType && expectedValueType) {
|
9808
|
-
if (
|
9809
|
-
|
9833
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.supportsKeysAndGetItemClass) &&
|
9834
|
+
(0, types_1.isInstantiableClass)(prefetched.supportsKeysAndGetItemClass)) {
|
9835
|
+
expectedType = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(prefetched.supportsKeysAndGetItemClass, [
|
9836
|
+
expectedKeyType,
|
9837
|
+
expectedValueType,
|
9838
|
+
]));
|
9810
9839
|
}
|
9811
9840
|
}
|
9812
9841
|
const entryInferenceContext = (0, typeUtils_1.makeInferenceContext)(expectedType);
|
@@ -9829,8 +9858,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9829
9858
|
}
|
9830
9859
|
else if ((0, types_1.isClassInstance)(unexpandedType) && types_1.ClassType.isTypedDictClass(unexpandedType)) {
|
9831
9860
|
// Handle dictionary expansion for a TypedDict.
|
9832
|
-
if (strClass && (0, types_1.isInstantiableClass)(strClass)) {
|
9833
|
-
const strObject = types_1.ClassType.cloneAsInstance(strClass);
|
9861
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) && (0, types_1.isInstantiableClass)(prefetched.strClass)) {
|
9862
|
+
const strObject = types_1.ClassType.cloneAsInstance(prefetched.strClass);
|
9834
9863
|
const tdEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, unexpandedType,
|
9835
9864
|
/* allowNarrowed */ true);
|
9836
9865
|
tdEntries.knownItems.forEach((entry, name) => {
|
@@ -9852,9 +9881,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9852
9881
|
addUnknown = false;
|
9853
9882
|
}
|
9854
9883
|
}
|
9855
|
-
else if (
|
9884
|
+
else if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.supportsKeysAndGetItemClass) &&
|
9885
|
+
(0, types_1.isInstantiableClass)(prefetched.supportsKeysAndGetItemClass)) {
|
9856
9886
|
const mappingConstraints = new constraintTracker_1.ConstraintTracker();
|
9857
|
-
supportsKeysAndGetItemClass = (0, typeUtils_1.selfSpecializeClass)(supportsKeysAndGetItemClass);
|
9887
|
+
const supportsKeysAndGetItemClass = (0, typeUtils_1.selfSpecializeClass)(prefetched.supportsKeysAndGetItemClass);
|
9858
9888
|
if (assignType(types_1.ClassType.cloneAsInstance(supportsKeysAndGetItemClass), unexpandedType,
|
9859
9889
|
/* diag */ undefined, mappingConstraints, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
|
9860
9890
|
const specializedMapping = solveAndApplyConstraints(supportsKeysAndGetItemClass, mappingConstraints);
|
@@ -10691,7 +10721,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10691
10721
|
}
|
10692
10722
|
// Creates an Optional[X] type.
|
10693
10723
|
function createOptionalType(classType, errorNode, typeArgs, flags) {
|
10694
|
-
var _a;
|
10724
|
+
var _a, _b, _c;
|
10695
10725
|
if (!typeArgs) {
|
10696
10726
|
// If no type arguments are provided, the resulting type
|
10697
10727
|
// depends on whether we're evaluating a type annotation or
|
@@ -10710,14 +10740,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10710
10740
|
if (!validateTypeArg(typeArgs[0])) {
|
10711
10741
|
typeArg0Type = types_1.UnknownType.create();
|
10712
10742
|
}
|
10713
|
-
let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneTypeClass !== null &&
|
10714
|
-
if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10715
|
-
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
10743
|
+
let optionalType = (0, types_1.combineTypes)([typeArg0Type, (_a = prefetched === null || prefetched === void 0 ? void 0 : prefetched.noneTypeClass) !== null && _a !== void 0 ? _a : types_1.UnknownType.create()]);
|
10744
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.unionTypeClass) && (0, types_1.isInstantiableClass)(prefetched.unionTypeClass)) {
|
10745
|
+
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, types_1.ClassType.cloneAsInstance(prefetched.unionTypeClass));
|
10716
10746
|
}
|
10717
|
-
if ((
|
10747
|
+
if ((_b = typeArg0Type.props) === null || _b === void 0 ? void 0 : _b.typeForm) {
|
10718
10748
|
const typeFormType = (0, types_1.combineTypes)([
|
10719
10749
|
typeArg0Type.props.typeForm,
|
10720
|
-
(0, typeUtils_1.convertToInstance)(noneTypeClass !== null &&
|
10750
|
+
(0, typeUtils_1.convertToInstance)((_c = prefetched === null || prefetched === void 0 ? void 0 : prefetched.noneTypeClass) !== null && _c !== void 0 ? _c : types_1.UnknownType.create()),
|
10721
10751
|
]);
|
10722
10752
|
optionalType = types_1.TypeBase.cloneWithTypeForm(optionalType, typeFormType);
|
10723
10753
|
}
|
@@ -10741,6 +10771,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10741
10771
|
}
|
10742
10772
|
// Creates a type that represents a Literal.
|
10743
10773
|
function createLiteralType(classType, node, flags) {
|
10774
|
+
var _a;
|
10744
10775
|
if (node.d.items.length === 0) {
|
10745
10776
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.literalEmptyArgs(), node.d.leftExpr);
|
10746
10777
|
return types_1.UnknownType.create();
|
@@ -10797,7 +10828,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10797
10828
|
type = cloneBuiltinClassWithLiteral(node, classType, 'bool', false);
|
10798
10829
|
}
|
10799
10830
|
else if (itemExpr.d.constType === 26 /* KeywordType.None */) {
|
10800
|
-
type = noneTypeClass !== null &&
|
10831
|
+
type = (_a = prefetched === null || prefetched === void 0 ? void 0 : prefetched.noneTypeClass) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
10801
10832
|
}
|
10802
10833
|
}
|
10803
10834
|
else if (itemExpr.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
|
@@ -10847,8 +10878,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10847
10878
|
literalTypes.push(type);
|
10848
10879
|
}
|
10849
10880
|
let result = (0, types_1.combineTypes)(literalTypes, { skipElideRedundantLiterals: true });
|
10850
|
-
if ((0, types_1.isUnion)(result) && unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
10851
|
-
result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
10881
|
+
if ((0, types_1.isUnion)(result) && (prefetched === null || prefetched === void 0 ? void 0 : prefetched.unionTypeClass) && (0, types_1.isInstantiableClass)(prefetched.unionTypeClass)) {
|
10882
|
+
result = types_1.TypeBase.cloneAsSpecialForm(result, types_1.ClassType.cloneAsInstance(prefetched.unionTypeClass));
|
10852
10883
|
}
|
10853
10884
|
if (isTypeFormSupported(node) && isValidTypeForm) {
|
10854
10885
|
result = types_1.TypeBase.cloneWithTypeForm(result, (0, typeUtils_1.convertToInstance)(result));
|
@@ -11352,8 +11383,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11352
11383
|
isValidTypeForm = false;
|
11353
11384
|
}
|
11354
11385
|
let unionType = (0, types_1.combineTypes)(types, { skipElideRedundantLiterals: true });
|
11355
|
-
if (unionTypeClass && (0, types_1.isInstantiableClass)(unionTypeClass)) {
|
11356
|
-
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(unionTypeClass));
|
11386
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.unionTypeClass) && (0, types_1.isInstantiableClass)(prefetched.unionTypeClass)) {
|
11387
|
+
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, types_1.ClassType.cloneAsInstance(prefetched.unionTypeClass));
|
11357
11388
|
}
|
11358
11389
|
if (!isValidTypeForm || types.some((t) => { var _a; return !((_a = t.props) === null || _a === void 0 ? void 0 : _a.typeForm); })) {
|
11359
11390
|
if ((_a = unionType.props) === null || _a === void 0 ? void 0 : _a.typeForm) {
|
@@ -11552,6 +11583,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11552
11583
|
// Handles some special-case type annotations that are found
|
11553
11584
|
// within the typings.pyi file.
|
11554
11585
|
function handleTypingStubTypeAnnotation(node) {
|
11586
|
+
var _a;
|
11555
11587
|
if (!node.parent || node.parent.nodeType !== 54 /* ParseNodeType.TypeAnnotation */) {
|
11556
11588
|
return undefined;
|
11557
11589
|
}
|
@@ -11624,7 +11656,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11624
11656
|
// Handle 'LiteralString' specially because we want it to act as
|
11625
11657
|
// though it derives from 'str'.
|
11626
11658
|
if (assignedName === 'LiteralString') {
|
11627
|
-
specialType.shared.baseClasses.push(strClass !== null &&
|
11659
|
+
specialType.shared.baseClasses.push((_a = prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) !== null && _a !== void 0 ? _a : types_1.AnyType.create());
|
11628
11660
|
(0, typeUtils_1.computeMroLinearization)(specialType);
|
11629
11661
|
if (isTypeFormSupported(node)) {
|
11630
11662
|
specialType = types_1.TypeBase.cloneWithTypeForm(specialType, (0, typeUtils_1.convertToInstance)(specialType));
|
@@ -12056,6 +12088,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12056
12088
|
}
|
12057
12089
|
argType = (0, typeUtils_1.stripTypeFormRecursive)(argType);
|
12058
12090
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
12091
|
+
// If the specified base class is type(T), use the metaclass
|
12092
|
+
// of T if it's known.
|
12093
|
+
if ((0, types_1.isClass)(argType) &&
|
12094
|
+
types_1.TypeBase.getInstantiableDepth(argType) > 0 &&
|
12095
|
+
argType.shared.effectiveMetaclass &&
|
12096
|
+
(0, types_1.isClass)(argType.shared.effectiveMetaclass)) {
|
12097
|
+
argType = argType.shared.effectiveMetaclass;
|
12098
|
+
}
|
12059
12099
|
if ((0, typeUtils_1.isMetaclassInstance)(argType)) {
|
12060
12100
|
(0, debug_1.assert)((0, types_1.isClassInstance)(argType));
|
12061
12101
|
argType =
|
@@ -12371,11 +12411,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12371
12411
|
}
|
12372
12412
|
// Determine the effective metaclass.
|
12373
12413
|
if (metaclassNode) {
|
12374
|
-
|
12414
|
+
let metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
12375
12415
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
12376
12416
|
if ((0, typeUtils_1.requiresSpecialization)(metaclassType, { ignorePseudoGeneric: true })) {
|
12377
12417
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.metaclassIsGeneric(), metaclassNode);
|
12378
12418
|
}
|
12419
|
+
// If the specified metaclass is type(T), use the metaclass
|
12420
|
+
// of T if it's known.
|
12421
|
+
if (types_1.TypeBase.getInstantiableDepth(metaclassType) > 0 &&
|
12422
|
+
(0, types_1.isClass)(metaclassType) &&
|
12423
|
+
metaclassType.shared.effectiveMetaclass &&
|
12424
|
+
(0, types_1.isClass)(metaclassType.shared.effectiveMetaclass)) {
|
12425
|
+
metaclassType = metaclassType.shared.effectiveMetaclass;
|
12426
|
+
}
|
12379
12427
|
classType.shared.declaredMetaclass = metaclassType;
|
12380
12428
|
if ((0, types_1.isInstantiableClass)(metaclassType)) {
|
12381
12429
|
if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
|
@@ -12647,12 +12695,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12647
12695
|
return paramTypes;
|
12648
12696
|
}
|
12649
12697
|
function computeEffectiveMetaclass(classType, errorNode) {
|
12698
|
+
var _a;
|
12650
12699
|
let effectiveMetaclass = classType.shared.declaredMetaclass;
|
12651
12700
|
let reportedMetaclassConflict = false;
|
12652
12701
|
if (!effectiveMetaclass || (0, types_1.isInstantiableClass)(effectiveMetaclass)) {
|
12653
12702
|
for (const baseClass of classType.shared.baseClasses) {
|
12654
12703
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
12655
|
-
const baseClassMeta = baseClass.shared.effectiveMetaclass || typeClass;
|
12704
|
+
const baseClassMeta = (_a = baseClass.shared.effectiveMetaclass) !== null && _a !== void 0 ? _a : prefetched === null || prefetched === void 0 ? void 0 : prefetched.typeClass;
|
12656
12705
|
if (baseClassMeta && (0, types_1.isInstantiableClass)(baseClassMeta)) {
|
12657
12706
|
// Make sure there is no metaclass conflict.
|
12658
12707
|
if (!effectiveMetaclass) {
|
@@ -13735,6 +13784,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13735
13784
|
}
|
13736
13785
|
const exceptionTypeResult = getTypeOfExpression(node.d.typeExpr);
|
13737
13786
|
const exceptionTypes = exceptionTypeResult.type;
|
13787
|
+
let includesBaseException = false;
|
13738
13788
|
function getExceptionType(exceptionType, errorNode) {
|
13739
13789
|
var _a, _b;
|
13740
13790
|
exceptionType = makeTopLevelTypeVarsConcrete(exceptionType);
|
@@ -13742,6 +13792,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13742
13792
|
return exceptionType;
|
13743
13793
|
}
|
13744
13794
|
if ((0, types_1.isInstantiableClass)(exceptionType)) {
|
13795
|
+
if (types_1.ClassType.isBuiltIn(exceptionType, 'BaseException')) {
|
13796
|
+
includesBaseException = true;
|
13797
|
+
}
|
13745
13798
|
return types_1.ClassType.cloneAsInstance(exceptionType);
|
13746
13799
|
}
|
13747
13800
|
if ((0, types_1.isClassInstance)(exceptionType)) {
|
@@ -13768,9 +13821,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13768
13821
|
}
|
13769
13822
|
return getExceptionType(subType, node.d.typeExpr);
|
13770
13823
|
});
|
13771
|
-
// If this is an except group, wrap the exception type in an
|
13824
|
+
// If this is an except group, wrap the exception type in an ExceptionGroup
|
13825
|
+
// or BaseExceptionGroup depending on whether the target exception is
|
13826
|
+
// a BaseException.
|
13772
13827
|
if (node.d.isExceptGroup) {
|
13773
|
-
targetType = getBuiltInObject(node, 'BaseExceptionGroup', [
|
13828
|
+
targetType = getBuiltInObject(node, includesBaseException ? 'BaseExceptionGroup' : 'ExceptionGroup', [
|
13829
|
+
targetType,
|
13830
|
+
]);
|
13774
13831
|
}
|
13775
13832
|
if (node.d.name) {
|
13776
13833
|
assignTypeToExpression(node.d.name, { type: targetType }, node.d.name);
|
@@ -14769,8 +14826,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14769
14826
|
return { type: types_1.UnknownType.create() };
|
14770
14827
|
}
|
14771
14828
|
}
|
14772
|
-
if (typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
|
14773
|
-
let typeType = createSpecialType(typeClass, typeArgs, 1,
|
14829
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.typeClass) && (0, types_1.isInstantiableClass)(prefetched.typeClass)) {
|
14830
|
+
let typeType = createSpecialType(prefetched.typeClass, typeArgs, 1,
|
14774
14831
|
/* allowParamSpec */ undefined,
|
14775
14832
|
/* isSpecialForm */ false);
|
14776
14833
|
if ((0, types_1.isInstantiableClass)(typeType)) {
|
@@ -15164,9 +15221,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15164
15221
|
// aliased symbols in outer scopes if they haven't yet been assigned
|
15165
15222
|
// within the local scope.
|
15166
15223
|
let scopeTypeHonorsCodeFlow = scopeType !== 2 /* ScopeType.Function */ && scopeType !== 1 /* ScopeType.Comprehension */;
|
15167
|
-
// Type parameter scopes don't honor code flow
|
15168
|
-
|
15169
|
-
if (scopeType === 0 /* ScopeType.TypeParameter */ && symbolWithScope && symbolWithScope.scope === scope) {
|
15224
|
+
// Type parameter scopes don't honor code flow.
|
15225
|
+
if ((symbolWithScope === null || symbolWithScope === void 0 ? void 0 : symbolWithScope.scope.type) === 0 /* ScopeType.TypeParameter */) {
|
15170
15226
|
scopeTypeHonorsCodeFlow = false;
|
15171
15227
|
}
|
15172
15228
|
if (symbolWithScope && honorCodeFlow && scopeTypeHonorsCodeFlow) {
|
@@ -15980,6 +16036,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15980
16036
|
'TypedDict',
|
15981
16037
|
'NamedTuple',
|
15982
16038
|
'NewType',
|
16039
|
+
'TypeAliasType',
|
15983
16040
|
];
|
15984
16041
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, exemptBuiltins)) {
|
15985
16042
|
isUnambiguousType = true;
|
@@ -16840,12 +16897,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16840
16897
|
if (types_1.ClassType.isBuiltIn(destType, 'Mapping')) {
|
16841
16898
|
const mappingValueType = (0, typedDicts_1.getTypedDictMappingEquivalent)(evaluatorInterface, srcType);
|
16842
16899
|
if (mappingValueType &&
|
16843
|
-
mappingClass &&
|
16844
|
-
(0, types_1.isInstantiableClass)(mappingClass) &&
|
16845
|
-
strClass &&
|
16846
|
-
(0, types_1.isInstantiableClass)(strClass)) {
|
16847
|
-
srcType = types_1.ClassType.specialize(mappingClass, [
|
16848
|
-
types_1.ClassType.cloneAsInstance(strClass),
|
16900
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.mappingClass) &&
|
16901
|
+
(0, types_1.isInstantiableClass)(prefetched.mappingClass) &&
|
16902
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) &&
|
16903
|
+
(0, types_1.isInstantiableClass)(prefetched.strClass)) {
|
16904
|
+
srcType = types_1.ClassType.specialize(prefetched.mappingClass, [
|
16905
|
+
types_1.ClassType.cloneAsInstance(prefetched.strClass),
|
16849
16906
|
mappingValueType,
|
16850
16907
|
]);
|
16851
16908
|
}
|
@@ -16853,11 +16910,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16853
16910
|
else if (types_1.ClassType.isBuiltIn(destType, ['dict', 'MutableMapping'])) {
|
16854
16911
|
const dictValueType = (0, typedDicts_1.getTypedDictDictEquivalent)(evaluatorInterface, srcType, recursionCount);
|
16855
16912
|
if (dictValueType &&
|
16856
|
-
dictClass &&
|
16857
|
-
(0, types_1.isInstantiableClass)(dictClass) &&
|
16858
|
-
strClass &&
|
16859
|
-
(0, types_1.isInstantiableClass)(strClass)) {
|
16860
|
-
srcType = types_1.ClassType.specialize(dictClass, [
|
16913
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.dictClass) &&
|
16914
|
+
(0, types_1.isInstantiableClass)(prefetched.dictClass) &&
|
16915
|
+
prefetched.strClass &&
|
16916
|
+
(0, types_1.isInstantiableClass)(prefetched.strClass)) {
|
16917
|
+
srcType = types_1.ClassType.specialize(prefetched.dictClass, [
|
16918
|
+
types_1.ClassType.cloneAsInstance(prefetched.strClass),
|
16919
|
+
dictValueType,
|
16920
|
+
]);
|
16861
16921
|
}
|
16862
16922
|
}
|
16863
16923
|
}
|
@@ -17179,7 +17239,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17179
17239
|
errorSource = localize_1.LocAddendum.typeVarIsCovariant;
|
17180
17240
|
}
|
17181
17241
|
else if (variance === 4 /* Variance.Contravariant */) {
|
17182
|
-
effectiveFlags =
|
17242
|
+
effectiveFlags = flags | 2 /* AssignTypeFlags.Contravariant */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
17183
17243
|
errorSource = localize_1.LocAddendum.typeVarIsContravariant;
|
17184
17244
|
}
|
17185
17245
|
else {
|
@@ -17620,10 +17680,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17620
17680
|
}
|
17621
17681
|
}
|
17622
17682
|
else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
|
17623
|
-
strClass &&
|
17624
|
-
(0, types_1.isInstantiableClass)(strClass) &&
|
17683
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.strClass) &&
|
17684
|
+
(0, types_1.isInstantiableClass)(prefetched.strClass) &&
|
17625
17685
|
(flags & 1 /* AssignTypeFlags.Invariant */) === 0) {
|
17626
|
-
concreteSrcType = types_1.ClassType.cloneAsInstance(strClass);
|
17686
|
+
concreteSrcType = types_1.ClassType.cloneAsInstance(prefetched.strClass);
|
17627
17687
|
}
|
17628
17688
|
if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, constraints, flags, recursionCount,
|
17629
17689
|
/* reportErrorsUsingObjType */ true)) {
|
@@ -17638,8 +17698,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17638
17698
|
return assignType(destCallbackType, concreteSrcType, diag, constraints, flags, recursionCount);
|
17639
17699
|
}
|
17640
17700
|
// All functions are considered instances of "builtins.function".
|
17641
|
-
if (functionClass) {
|
17642
|
-
return assignType(destType, (0, typeUtils_1.convertToInstance)(functionClass), diag, constraints, flags, recursionCount);
|
17701
|
+
if (prefetched === null || prefetched === void 0 ? void 0 : prefetched.functionClass) {
|
17702
|
+
return assignType(destType, (0, typeUtils_1.convertToInstance)(prefetched.functionClass), diag, constraints, flags, recursionCount);
|
17643
17703
|
}
|
17644
17704
|
}
|
17645
17705
|
else if ((0, types_1.isModule)(concreteSrcType)) {
|
@@ -17669,9 +17729,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17669
17729
|
if ((0, types_1.isAnyOrUnknown)(metaclass)) {
|
17670
17730
|
return true;
|
17671
17731
|
}
|
17672
|
-
|
17673
|
-
|
17674
|
-
|
17732
|
+
if (assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass,
|
17733
|
+
/* diag */ undefined, constraints, flags, recursionCount,
|
17734
|
+
/* reportErrorsUsingObjType */ true)) {
|
17735
|
+
return true;
|
17675
17736
|
}
|
17676
17737
|
}
|
17677
17738
|
}
|
@@ -17792,8 +17853,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17792
17853
|
}
|
17793
17854
|
// Are we trying to assign None to a protocol?
|
17794
17855
|
if ((0, typeUtils_1.isNoneInstance)(srcType) && (0, types_1.isClassInstance)(destType) && types_1.ClassType.isProtocolClass(destType)) {
|
17795
|
-
if (noneTypeClass && (0, types_1.isInstantiableClass)(noneTypeClass)) {
|
17796
|
-
return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(noneTypeClass), diag, constraints, flags, recursionCount);
|
17856
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.noneTypeClass) && (0, types_1.isInstantiableClass)(prefetched.noneTypeClass)) {
|
17857
|
+
return (0, protocols_1.assignClassToProtocol)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstance(prefetched.noneTypeClass), diag, constraints, flags, recursionCount);
|
17797
17858
|
}
|
17798
17859
|
}
|
17799
17860
|
if ((0, typeUtils_1.isNoneInstance)(destType)) {
|
@@ -18315,8 +18376,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18315
18376
|
for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
|
18316
18377
|
if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
|
18317
18378
|
let fieldIsPartOfFunction = false;
|
18318
|
-
if (functionClass && (0, types_1.isClass)(functionClass)) {
|
18319
|
-
if (types_1.ClassType.getSymbolTable(functionClass).has(field[0])) {
|
18379
|
+
if ((prefetched === null || prefetched === void 0 ? void 0 : prefetched.functionClass) && (0, types_1.isClass)(prefetched.functionClass)) {
|
18380
|
+
if (types_1.ClassType.getSymbolTable(prefetched.functionClass).has(field[0])) {
|
18320
18381
|
fieldIsPartOfFunction = true;
|
18321
18382
|
}
|
18322
18383
|
}
|
@@ -18939,9 +19000,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18939
19000
|
// type at runtime.
|
18940
19001
|
if ((0, types_1.isClassInstance)(srcReturnType) &&
|
18941
19002
|
types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'TypeIs']) &&
|
18942
|
-
boolClass &&
|
18943
|
-
(0, types_1.isInstantiableClass)(boolClass)) {
|
18944
|
-
if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClass), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), constraints, flags, recursionCount)) {
|
19003
|
+
(prefetched === null || prefetched === void 0 ? void 0 : prefetched.boolClass) &&
|
19004
|
+
(0, types_1.isInstantiableClass)(prefetched.boolClass)) {
|
19005
|
+
if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(prefetched.boolClass), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), constraints, flags, recursionCount)) {
|
18945
19006
|
isReturnTypeCompatible = true;
|
18946
19007
|
}
|
18947
19008
|
}
|
@@ -19480,7 +19541,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19480
19541
|
}
|
19481
19542
|
// Now check the return type.
|
19482
19543
|
const baseReturnType = getEffectiveReturnType(baseMethod);
|
19483
|
-
const overrideReturnType = getEffectiveReturnType(overrideMethod);
|
19544
|
+
const overrideReturnType = solveAndApplyConstraints(getEffectiveReturnType(overrideMethod), constraints);
|
19484
19545
|
if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), constraints, 0 /* AssignTypeFlags.Default */)) {
|
19485
19546
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideReturnType().format({
|
19486
19547
|
baseType: printType(baseReturnType),
|