@zzzen/pyright-internal 1.2.0-dev.20240908 → 1.2.0-dev.20240922
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/analysis.d.ts +1 -0
- package/dist/analyzer/analysis.js +2 -0
- package/dist/analyzer/analysis.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +6 -2
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/cacheManager.d.ts +2 -2
- package/dist/analyzer/cacheManager.js.map +1 -1
- package/dist/analyzer/checker.js +31 -156
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +21 -3
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -2
- package/dist/analyzer/constraintSolver.js +5 -20
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constraintTracker.d.ts +0 -4
- package/dist/analyzer/constraintTracker.js +0 -21
- package/dist/analyzer/constraintTracker.js.map +1 -1
- package/dist/analyzer/constructors.js +0 -1
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +2 -3
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +1 -2
- package/dist/analyzer/protocols.js +2 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.d.ts +1 -1
- package/dist/analyzer/service.d.ts +2 -1
- package/dist/analyzer/service.js +56 -42
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +8 -4
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +1 -2
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +168 -108
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +27 -2
- package/dist/analyzer/typeEvaluatorTypes.js +62 -1
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.d.ts +3 -12
- package/dist/analyzer/typeGuards.js +282 -456
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.d.ts +1 -2
- package/dist/analyzer/typePrinter.js +4 -24
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +12 -1
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +0 -17
- package/dist/analyzer/typeUtils.js +7 -59
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +1 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +1 -0
- package/dist/analyzer/types.js +12 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +23 -16
- package/dist/backgroundAnalysisBase.js +65 -35
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.js +9 -0
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -0
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +1 -1
- package/dist/common/uri/uriUtils.d.ts +1 -1
- package/dist/common/uri/uriUtils.js +6 -1
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +2 -2
- package/dist/languageServerBase.js +1 -3
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +6 -1
- package/dist/languageService/analyzerServiceExecutor.js +8 -7
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/fileWatcherDynamicFeature.d.ts +5 -1
- package/dist/languageService/fileWatcherDynamicFeature.js +12 -2
- package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +1 -1
- package/dist/languageService/hoverProvider.js +9 -10
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +8 -0
- package/dist/localization/localize.js +2 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +157 -153
- package/dist/localization/package.nls.de.json +130 -126
- package/dist/localization/package.nls.en-us.json +1632 -406
- package/dist/localization/package.nls.es.json +153 -149
- package/dist/localization/package.nls.fr.json +131 -127
- package/dist/localization/package.nls.it.json +145 -141
- package/dist/localization/package.nls.ja.json +144 -140
- package/dist/localization/package.nls.ko.json +157 -153
- package/dist/localization/package.nls.pl.json +180 -176
- package/dist/localization/package.nls.pt-br.json +141 -137
- package/dist/localization/package.nls.qps-ploc.json +394 -390
- package/dist/localization/package.nls.ru.json +172 -168
- package/dist/localization/package.nls.tr.json +155 -151
- package/dist/localization/package.nls.zh-cn.json +151 -147
- package/dist/localization/package.nls.zh-tw.json +135 -131
- package/dist/parser/unicode.js +136 -8
- package/dist/parser/unicode.js.map +1 -1
- package/dist/tests/checker.test.js +9 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +40 -3
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/envVarUtils.test.js +0 -3
- package/dist/tests/envVarUtils.test.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +0 -3
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -5
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/fourslash/testStateUtils.d.ts +1 -0
- package/dist/tests/harness/fourslash/testStateUtils.js +5 -0
- package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
- package/dist/tests/harness/vfs/filesystem.js +6 -3
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/service.test.js +31 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator6.test.js +5 -1
- package/dist/tests/typeEvaluator6.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +5 -1
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typeEvaluator8.test.js +2 -2
- package/dist/workspaceFactory.d.ts +2 -20
- package/dist/workspaceFactory.js +20 -58
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -209,6 +209,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
209
209
|
let intClass;
|
210
210
|
let strClass;
|
211
211
|
let dictClass;
|
212
|
+
let moduleTypeClass;
|
212
213
|
let typedDictPrivateClass;
|
213
214
|
let supportsKeysAndGetItemClass;
|
214
215
|
let mappingClass;
|
@@ -490,6 +491,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
490
491
|
intClass = getBuiltInType(node, 'int');
|
491
492
|
strClass = getBuiltInType(node, 'str');
|
492
493
|
dictClass = getBuiltInType(node, 'dict');
|
494
|
+
moduleTypeClass = getTypingType(node, 'ModuleType');
|
493
495
|
typedDictPrivateClass = getTypingType(node, '_TypedDict');
|
494
496
|
awaitableClass = getTypingType(node, 'Awaitable');
|
495
497
|
mappingClass = getTypingType(node, 'Mapping');
|
@@ -567,6 +569,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
567
569
|
};
|
568
570
|
}
|
569
571
|
}
|
572
|
+
if (inferenceContext) {
|
573
|
+
// Handle TypeForm assignments.
|
574
|
+
typeResult.type = convertToTypeFormType(inferenceContext.expectedType, typeResult.type);
|
575
|
+
}
|
570
576
|
// Don't allow speculative caching for assignment expressions because
|
571
577
|
// the target name node won't have a corresponding type cached speculatively.
|
572
578
|
const allowSpeculativeCaching = node.nodeType !== 4 /* ParseNodeType.AssignmentExpression */;
|
@@ -1720,6 +1726,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1720
1726
|
function getDeclaredTypeForExpression(expression, usage) {
|
1721
1727
|
var _a, _b;
|
1722
1728
|
let symbol;
|
1729
|
+
let selfType;
|
1723
1730
|
let classOrObjectBase;
|
1724
1731
|
let memberAccessClass;
|
1725
1732
|
let bindFunction = true;
|
@@ -1752,11 +1759,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1752
1759
|
return getDeclaredTypeForExpression(expression.d.valueExpr, usage);
|
1753
1760
|
}
|
1754
1761
|
case 35 /* ParseNodeType.MemberAccess */: {
|
1755
|
-
const baseType =
|
1762
|
+
const baseType = getTypeOfExpression(expression.d.leftExpr, 2 /* EvalFlags.MemberAccessBaseDefaults */).type;
|
1763
|
+
const baseTypeConcrete = makeTopLevelTypeVarsConcrete(baseType);
|
1756
1764
|
let classMemberInfo;
|
1757
|
-
if ((0, types_1.isClassInstance)(
|
1758
|
-
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(
|
1759
|
-
classOrObjectBase =
|
1765
|
+
if ((0, types_1.isClassInstance)(baseTypeConcrete)) {
|
1766
|
+
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseTypeConcrete, expression.d.member.d.value, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
1767
|
+
classOrObjectBase = baseTypeConcrete;
|
1760
1768
|
memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
|
1761
1769
|
// If this is an instance member (e.g. a dataclass field), don't
|
1762
1770
|
// bind it to the object if it's a function.
|
@@ -1765,11 +1773,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1765
1773
|
}
|
1766
1774
|
useDescriptorSetterType = true;
|
1767
1775
|
}
|
1768
|
-
else if ((0, types_1.isInstantiableClass)(
|
1769
|
-
classMemberInfo = (0, typeUtils_1.lookUpClassMember)(
|
1770
|
-
classOrObjectBase =
|
1776
|
+
else if ((0, types_1.isInstantiableClass)(baseTypeConcrete)) {
|
1777
|
+
classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseTypeConcrete, expression.d.member.d.value, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
1778
|
+
classOrObjectBase = baseTypeConcrete;
|
1771
1779
|
memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
|
1772
1780
|
}
|
1781
|
+
if ((0, types_1.isTypeVar)(baseType)) {
|
1782
|
+
selfType = baseType;
|
1783
|
+
}
|
1773
1784
|
if (classMemberInfo) {
|
1774
1785
|
symbol = classMemberInfo.symbol;
|
1775
1786
|
}
|
@@ -1810,11 +1821,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1810
1821
|
}
|
1811
1822
|
if (classOrObjectBase) {
|
1812
1823
|
if (memberAccessClass && (0, types_1.isInstantiableClass)(memberAccessClass)) {
|
1813
|
-
declaredType = (0, typeUtils_1.partiallySpecializeType)(declaredType, memberAccessClass, getTypeClassType());
|
1824
|
+
declaredType = (0, typeUtils_1.partiallySpecializeType)(declaredType, memberAccessClass, getTypeClassType(), selfType);
|
1814
1825
|
}
|
1815
1826
|
if ((0, types_1.isFunction)(declaredType) || (0, types_1.isOverloaded)(declaredType)) {
|
1816
1827
|
if (bindFunction) {
|
1817
|
-
declaredType = bindFunctionToClassOrObject(classOrObjectBase, declaredType
|
1828
|
+
declaredType = bindFunctionToClassOrObject(classOrObjectBase, declaredType,
|
1829
|
+
/* memberClass */ undefined,
|
1830
|
+
/* treatConstructorAsClassMethod */ undefined, selfType);
|
1818
1831
|
}
|
1819
1832
|
}
|
1820
1833
|
}
|
@@ -2026,6 +2039,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2026
2039
|
function getTupleClassType() {
|
2027
2040
|
return tupleClass && (0, types_1.isInstantiableClass)(tupleClass) ? tupleClass : undefined;
|
2028
2041
|
}
|
2042
|
+
function getDictClassType() {
|
2043
|
+
return dictClass && (0, types_1.isInstantiableClass)(dictClass) ? dictClass : undefined;
|
2044
|
+
}
|
2045
|
+
function getStrClassType() {
|
2046
|
+
return strClass && (0, types_1.isInstantiableClass)(strClass) ? strClass : undefined;
|
2047
|
+
}
|
2029
2048
|
function getObjectType() {
|
2030
2049
|
return objectClass ? (0, typeUtils_1.convertToInstance)(objectClass) : types_1.UnknownType.create();
|
2031
2050
|
}
|
@@ -3185,7 +3204,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3185
3204
|
}
|
3186
3205
|
}
|
3187
3206
|
if (((_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) && types_1.TypeBase.isInstantiable(type)) {
|
3188
|
-
|
3207
|
+
let typeFormType = type;
|
3208
|
+
if ((flags & 2 /* EvalFlags.NoSpecialize */) === 0) {
|
3209
|
+
typeFormType = specializeTypeAliasWithDefaults(typeFormType, /* errorNode */ undefined);
|
3210
|
+
}
|
3211
|
+
type = types_1.TypeBase.cloneWithTypeForm(type, (0, typeUtils_1.convertToInstance)(typeFormType));
|
3189
3212
|
}
|
3190
3213
|
return type;
|
3191
3214
|
}
|
@@ -3222,13 +3245,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3222
3245
|
}
|
3223
3246
|
// If the value is a special form (like a TypeVar or `Any`) and is being
|
3224
3247
|
// evaluated in a value expression context, convert it from its special
|
3225
|
-
// meaning to its runtime value.
|
3226
|
-
|
3248
|
+
// meaning to its runtime value. If convertModule is true, a module is
|
3249
|
+
// converted to an instance of types.ModuleType.
|
3250
|
+
function convertSpecialFormToRuntimeValue(type, flags, convertModule = false) {
|
3227
3251
|
var _a, _b, _c, _d;
|
3228
3252
|
const exemptFlags = 256 /* EvalFlags.TypeExpression */ | 128 /* EvalFlags.InstantiableType */ | 33554432 /* EvalFlags.NoConvertSpecialForm */;
|
3229
3253
|
if ((flags & exemptFlags) !== 0) {
|
3230
3254
|
return type;
|
3231
3255
|
}
|
3256
|
+
if (convertModule && (0, types_1.isModule)(type) && moduleTypeClass && (0, types_1.isInstantiableClass)(moduleTypeClass)) {
|
3257
|
+
return types_1.ClassType.cloneAsInstance(moduleTypeClass);
|
3258
|
+
}
|
3232
3259
|
// Isinstance treats traditional (non-PEP 695) type aliases that are unions
|
3233
3260
|
// as tuples of classes rather than unions.
|
3234
3261
|
if ((flags & 536870912 /* EvalFlags.IsinstanceArg */) !== 0) {
|
@@ -3654,6 +3681,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3654
3681
|
}
|
3655
3682
|
// Detect, report, and fill in missing type arguments if appropriate.
|
3656
3683
|
typeResult.type = reportMissingTypeArgs(node, typeResult.type, flags);
|
3684
|
+
// Add TypeForm details if appropriate.
|
3685
|
+
typeResult.type = addTypeFormForSymbol(node, typeResult.type, flags, /* includesVarDecl */ false);
|
3657
3686
|
}
|
3658
3687
|
if (baseTypeResult.isIncomplete) {
|
3659
3688
|
typeResult.isIncomplete = true;
|
@@ -3681,7 +3710,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3681
3710
|
return typeResult;
|
3682
3711
|
}
|
3683
3712
|
function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
|
3684
|
-
var _a, _b, _c;
|
3713
|
+
var _a, _b, _c, _d;
|
3685
3714
|
let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
|
3686
3715
|
const memberName = node.d.member.d.value;
|
3687
3716
|
let diag = new diagnostic_1.DiagnosticAddendum();
|
@@ -3694,12 +3723,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3694
3723
|
const isRequired = false;
|
3695
3724
|
const isNotRequired = false;
|
3696
3725
|
let memberAccessDeprecationInfo;
|
3726
|
+
if ((_a = usage === null || usage === void 0 ? void 0 : usage.setType) === null || _a === void 0 ? void 0 : _a.isIncomplete) {
|
3727
|
+
isIncomplete = true;
|
3728
|
+
}
|
3697
3729
|
// If the base type was incomplete and unbound, don't proceed
|
3698
3730
|
// because false positive errors will be generated.
|
3699
3731
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
|
3700
3732
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3701
3733
|
}
|
3702
|
-
if (((
|
3734
|
+
if (((_b = baseType.props) === null || _b === void 0 ? void 0 : _b.specialForm) && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
|
3703
3735
|
baseType = baseType.props.specialForm;
|
3704
3736
|
}
|
3705
3737
|
if ((0, types_1.isParamSpec)(baseType) && baseType.priv.paramSpecAccess) {
|
@@ -3777,7 +3809,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3777
3809
|
types_1.ClassType.isSameGenericClass(enumMemberResult.type, baseType) &&
|
3778
3810
|
enumMemberResult.type.priv.literalValue !== undefined) {
|
3779
3811
|
const diagMessage = usage.method === 'set' ? localize_1.LocMessage.enumMemberSet() : localize_1.LocMessage.enumMemberDelete();
|
3780
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.d.member, (
|
3812
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.d.member, (_c = diag.getEffectiveTextRange()) !== null && _c !== void 0 ? _c : node.d.member);
|
3781
3813
|
}
|
3782
3814
|
}
|
3783
3815
|
}
|
@@ -3980,7 +4012,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
3980
4012
|
const rule = isFunctionRule
|
3981
4013
|
? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
|
3982
4014
|
: diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
|
3983
|
-
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.d.member, (
|
4015
|
+
addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.d.member, (_d = diag.getEffectiveTextRange()) !== null && _d !== void 0 ? _d : node.d.member);
|
3984
4016
|
}
|
3985
4017
|
// If this is member access on a function, use "Any" so if the
|
3986
4018
|
// reportFunctionMemberAccess rule is disabled, we don't trigger
|
@@ -4251,8 +4283,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4251
4283
|
else {
|
4252
4284
|
accessMethodName = '__delete__';
|
4253
4285
|
}
|
4286
|
+
const subDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
|
4254
4287
|
const methodTypeResult = getTypeOfBoundMember(errorNode, concreteMemberType, accessMethodName,
|
4255
|
-
/* usage */ undefined,
|
4288
|
+
/* usage */ undefined, subDiag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */);
|
4256
4289
|
if (!methodTypeResult || methodTypeResult.typeErrors) {
|
4257
4290
|
// Provide special error messages for properties.
|
4258
4291
|
if (types_1.ClassType.isPropertyClass(concreteMemberType) && usage.method !== 'get') {
|
@@ -4268,6 +4301,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4268
4301
|
const methodClassType = methodTypeResult.classType;
|
4269
4302
|
let methodType = methodTypeResult.type;
|
4270
4303
|
if (methodTypeResult.typeErrors || !methodClassType) {
|
4304
|
+
if (diag && subDiag) {
|
4305
|
+
diag.addAddendum(subDiag);
|
4306
|
+
}
|
4271
4307
|
return { type: types_1.UnknownType.create(), typeErrors: true };
|
4272
4308
|
}
|
4273
4309
|
if (!(0, types_1.isFunction)(methodType) && !(0, types_1.isOverloaded)(methodType)) {
|
@@ -4830,13 +4866,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4830
4866
|
// Handles index expressions that are providing type arguments for a
|
4831
4867
|
// generic type alias.
|
4832
4868
|
function createSpecializedTypeAlias(node, baseType, flags) {
|
4833
|
-
var _a, _b, _c;
|
4834
|
-
|
4869
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
4870
|
+
let aliasInfo = (_a = baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
|
4871
|
+
let aliasBaseType = baseType;
|
4872
|
+
if (!aliasInfo && ((_b = baseType.props) === null || _b === void 0 ? void 0 : _b.typeForm)) {
|
4873
|
+
aliasInfo = (_d = (_c = baseType.props.typeForm) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.typeAliasInfo;
|
4874
|
+
aliasBaseType = (0, typeUtils_1.convertToInstantiable)(baseType.props.typeForm);
|
4875
|
+
}
|
4835
4876
|
if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) || (aliasInfo.typeParams.length === 0 && aliasInfo.typeArgs)) {
|
4836
4877
|
return undefined;
|
4837
4878
|
}
|
4838
4879
|
// If this is not instantiable, then the index expression isn't a specialization.
|
4839
|
-
if (!types_1.TypeBase.isInstantiable(
|
4880
|
+
if (!types_1.TypeBase.isInstantiable(aliasBaseType)) {
|
4840
4881
|
return undefined;
|
4841
4882
|
}
|
4842
4883
|
// If this is already specialized, the index expression isn't a specialization.
|
@@ -4868,7 +4909,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4868
4909
|
}
|
4869
4910
|
if (typeArgs.length > typeParams.length) {
|
4870
4911
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgsTooMany().format({
|
4871
|
-
name: printType(
|
4912
|
+
name: printType(aliasBaseType),
|
4872
4913
|
expected: typeParams.length,
|
4873
4914
|
received: typeArgs.length,
|
4874
4915
|
}), typeArgs[typeParams.length].node);
|
@@ -4876,15 +4917,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4876
4917
|
}
|
4877
4918
|
else if (typeArgs.length < minTypeArgCount) {
|
4878
4919
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgsTooFew().format({
|
4879
|
-
name: printType(
|
4920
|
+
name: printType(aliasBaseType),
|
4880
4921
|
expected: typeParams.length,
|
4881
4922
|
received: typeArgs.length,
|
4882
4923
|
}), node.d.items[node.d.items.length - 1]);
|
4883
4924
|
reportedError = true;
|
4884
4925
|
}
|
4885
4926
|
// Handle the mypy_extensions.FlexibleAlias type specially.
|
4886
|
-
if ((0, types_1.isInstantiableClass)(
|
4887
|
-
|
4927
|
+
if ((0, types_1.isInstantiableClass)(aliasBaseType) &&
|
4928
|
+
aliasBaseType.shared.fullName === 'mypy_extensions.FlexibleAlias' &&
|
4888
4929
|
typeArgs.length >= 1) {
|
4889
4930
|
return { node, type: typeArgs[0].type };
|
4890
4931
|
}
|
@@ -4960,7 +5001,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4960
5001
|
typeArgType = types_1.UnknownType.create();
|
4961
5002
|
}
|
4962
5003
|
if ((flags & 16384 /* EvalFlags.EnforceVarianceConsistency */) !== 0) {
|
4963
|
-
const usageVariances = inferVarianceForTypeAlias(
|
5004
|
+
const usageVariances = inferVarianceForTypeAlias(aliasBaseType);
|
4964
5005
|
if (usageVariances && index < usageVariances.length) {
|
4965
5006
|
const usageVariance = usageVariances[index];
|
4966
5007
|
if (!(0, typeUtils_1.isVarianceOfTypeArgCompatible)(typeArgType, usageVariance)) {
|
@@ -4983,12 +5024,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4983
5024
|
}
|
4984
5025
|
});
|
4985
5026
|
if (!diag.isEmpty()) {
|
4986
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeNotSpecializable().format({ type: printType(
|
5027
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeNotSpecializable().format({ type: printType(aliasBaseType) }) + diag.getString(), node, (_e = diag.getEffectiveTextRange()) !== null && _e !== void 0 ? _e : node);
|
4987
5028
|
reportedError = true;
|
4988
5029
|
}
|
4989
5030
|
const solutionSet = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints).getMainSolutionSet();
|
4990
5031
|
const aliasTypeArgs = [];
|
4991
|
-
(
|
5032
|
+
(_f = aliasInfo.typeParams) === null || _f === void 0 ? void 0 : _f.forEach((typeParam) => {
|
4992
5033
|
let typeVarType = solutionSet.getType(typeParam);
|
4993
5034
|
// Fill in any unsolved type arguments with unknown.
|
4994
5035
|
if (!typeVarType) {
|
@@ -4997,14 +5038,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
4997
5038
|
}
|
4998
5039
|
aliasTypeArgs.push(typeVarType);
|
4999
5040
|
});
|
5000
|
-
let type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(
|
5041
|
+
let type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(aliasBaseType, constraints), {
|
5001
5042
|
...aliasInfo,
|
5002
5043
|
typeArgs: aliasTypeArgs,
|
5003
5044
|
});
|
5004
5045
|
if (isTypeFormSupported(node)) {
|
5005
5046
|
type = types_1.TypeBase.cloneWithTypeForm(type, reportedError ? undefined : (0, typeUtils_1.convertToInstance)(type));
|
5006
5047
|
}
|
5007
|
-
|
5048
|
+
if ((_g = baseType.props) === null || _g === void 0 ? void 0 : _g.typeAliasInfo) {
|
5049
|
+
return { type, node };
|
5050
|
+
}
|
5051
|
+
return { type: types_1.TypeBase.cloneWithTypeForm(baseType, (0, typeUtils_1.convertToInstance)(type)), node };
|
5008
5052
|
}
|
5009
5053
|
function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
|
5010
5054
|
var _a, _b, _c;
|
@@ -5759,7 +5803,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5759
5803
|
entryTypes.push({ type: types_1.UnknownType.create(/* isIncomplete */ true), isUnbounded: false });
|
5760
5804
|
}
|
5761
5805
|
else {
|
5762
|
-
let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None
|
5806
|
+
let entryType = convertSpecialFormToRuntimeValue(typeResult.type, 0 /* EvalFlags.None */,
|
5807
|
+
/* convertModule */ true);
|
5763
5808
|
entryType = stripLiterals ? (0, typeUtils_1.stripTypeForm)(stripLiteralValue(entryType)) : entryType;
|
5764
5809
|
entryTypes.push({ type: entryType, isUnbounded: !!typeResult.unpackedType });
|
5765
5810
|
}
|
@@ -5826,7 +5871,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5826
5871
|
}
|
5827
5872
|
else if ((0, types_1.isClass)(baseTypeResult.type) && types_1.ClassType.isBuiltIn(baseTypeResult.type, 'TypeForm')) {
|
5828
5873
|
// Handle the "typing.TypeForm" call.
|
5829
|
-
typeResult = getTypeOfTypeForm(node);
|
5874
|
+
typeResult = getTypeOfTypeForm(node, baseTypeResult.type);
|
5830
5875
|
}
|
5831
5876
|
else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
|
5832
5877
|
node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
|
@@ -5931,21 +5976,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5931
5976
|
}
|
5932
5977
|
return typeResult;
|
5933
5978
|
}
|
5934
|
-
function getTypeOfTypeForm(node) {
|
5979
|
+
function getTypeOfTypeForm(node, typeFormClass) {
|
5980
|
+
var _a;
|
5935
5981
|
if (node.d.args.length !== 1 ||
|
5936
5982
|
node.d.args[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
|
5937
5983
|
node.d.args[0].d.name !== undefined) {
|
5938
5984
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeFormArgs(), node);
|
5939
5985
|
return { type: types_1.UnknownType.create() };
|
5940
5986
|
}
|
5941
|
-
|
5987
|
+
const typeFormResult = getTypeOfArgExpectingType((0, typeUtils_1.convertNodeToArg)(node.d.args[0]), {
|
5942
5988
|
typeFormArg: isTypeFormSupported(node),
|
5943
5989
|
noNonTypeSpecialForms: true,
|
5944
5990
|
typeExpression: true,
|
5945
5991
|
});
|
5992
|
+
if (!typeFormResult.typeErrors && ((_a = typeFormResult.type.props) === null || _a === void 0 ? void 0 : _a.typeForm)) {
|
5993
|
+
typeFormResult.type = (0, typeUtils_1.convertToInstance)(types_1.ClassType.specialize(typeFormClass, [(0, typeUtils_1.convertToInstance)(typeFormResult.type.props.typeForm)]));
|
5994
|
+
}
|
5995
|
+
return typeFormResult;
|
5946
5996
|
}
|
5947
5997
|
function getTypeOfAssertType(node, inferenceContext) {
|
5948
|
-
var _a;
|
5949
5998
|
if (node.d.args.length !== 2 ||
|
5950
5999
|
node.d.args[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
|
5951
6000
|
node.d.args[0].d.name !== undefined ||
|
@@ -5965,24 +6014,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
5965
6014
|
// The spec is unclear on whether this is the correct behavior, but it seems to be
|
5966
6015
|
// what mypy does -- and what various library authors expect.
|
5967
6016
|
const arg0Type = stripTypeGuard(arg0TypeResult.type);
|
5968
|
-
|
6017
|
+
if (!(0, types_1.isTypeSame)(assertedType, arg0Type, {
|
5969
6018
|
treatAnySameAsUnknown: true,
|
5970
6019
|
ignorePseudoGeneric: true,
|
5971
|
-
})
|
5972
|
-
// Handle TypeForm types specially.
|
5973
|
-
if (!assertSuccess &&
|
5974
|
-
((_a = arg0Type.props) === null || _a === void 0 ? void 0 : _a.typeForm) &&
|
5975
|
-
(0, types_1.isClassInstance)(assertedType) &&
|
5976
|
-
types_1.ClassType.isBuiltIn(assertedType, 'TypeForm')) {
|
5977
|
-
const typeFormType = assertedType.priv.typeArgs && assertedType.priv.typeArgs.length >= 1
|
5978
|
-
? assertedType.priv.typeArgs[0]
|
5979
|
-
: types_1.UnknownType.create();
|
5980
|
-
assertSuccess = (0, types_1.isTypeSame)(arg0Type.props.typeForm, typeFormType, {
|
5981
|
-
treatAnySameAsUnknown: true,
|
5982
|
-
ignorePseudoGeneric: true,
|
5983
|
-
});
|
5984
|
-
}
|
5985
|
-
if (!assertSuccess) {
|
6020
|
+
})) {
|
5986
6021
|
const srcDestTypes = printSrcDestTypes(arg0TypeResult.type, assertedType, { expandTypeAlias: true });
|
5987
6022
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssertTypeFailure, localize_1.LocMessage.assertTypeTypeMismatch().format({
|
5988
6023
|
expected: srcDestTypes.destType,
|
@@ -6386,7 +6421,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6386
6421
|
}
|
6387
6422
|
// Clone the constraints so we don't modify the original.
|
6388
6423
|
const effectiveConstraints = (_a = constraints === null || constraints === void 0 ? void 0 : constraints.clone()) !== null && _a !== void 0 ? _a : new constraintTracker_1.ConstraintTracker();
|
6389
|
-
effectiveConstraints.unlock();
|
6390
6424
|
// Use speculative mode so we don't output any diagnostics or
|
6391
6425
|
// record any final types in the type cache.
|
6392
6426
|
const callResult = useSpeculativeMode(speculativeNode, () => {
|
@@ -6498,7 +6532,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6498
6532
|
// And run through the first expanded argument list one more time to
|
6499
6533
|
// populate the type cache.
|
6500
6534
|
const finalConstraints = constraints !== null && constraints !== void 0 ? constraints : matchedOverloads[0].constraints;
|
6501
|
-
finalConstraints.unlock();
|
6502
6535
|
const finalCallResult = validateArgTypesWithContext(errorNode, matchedOverloads[0].matchResults, finalConstraints, skipUnknownArgCheck, inferenceContext);
|
6503
6536
|
if (finalCallResult.isTypeIncomplete) {
|
6504
6537
|
isTypeIncomplete = true;
|
@@ -6672,7 +6705,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6672
6705
|
}
|
6673
6706
|
}
|
6674
6707
|
const effectiveConstraints = constraints !== null && constraints !== void 0 ? constraints : new constraintTracker_1.ConstraintTracker();
|
6675
|
-
effectiveConstraints.unlock();
|
6676
6708
|
return validateArgTypesWithContext(errorNode, bestMatch, effectiveConstraints, skipUnknownArgCheck, inferenceContext);
|
6677
6709
|
}
|
6678
6710
|
// If there is only one possible arg/param match among the overloads,
|
@@ -7066,27 +7098,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7066
7098
|
// The one-parameter form of "type" returns the class
|
7067
7099
|
// for the specified object.
|
7068
7100
|
if (expandedCallType.shared.name === 'type' && argList.length === 1) {
|
7069
|
-
const
|
7101
|
+
const argTypeResult = getTypeOfArg(argList[0], /* inferenceContext */ undefined);
|
7102
|
+
const argType = argTypeResult.type;
|
7070
7103
|
const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
|
7071
|
-
if ((0, types_1.isInstantiableClass)(subtype) && subtype.shared.effectiveMetaclass) {
|
7072
|
-
return subtype.shared.effectiveMetaclass;
|
7073
|
-
}
|
7074
7104
|
if ((0, types_1.isNever)(subtype)) {
|
7075
7105
|
return subtype;
|
7076
7106
|
}
|
7107
|
+
if ((0, types_1.isClass)(subtype)) {
|
7108
|
+
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
7109
|
+
}
|
7077
7110
|
if (types_1.TypeBase.isInstance(subtype)) {
|
7078
|
-
if ((0, types_1.
|
7079
|
-
return (0, typeUtils_1.convertToInstantiable)(
|
7080
|
-
}
|
7081
|
-
if ((0, types_1.isFunction)(subtype)) {
|
7082
|
-
return types_1.FunctionType.cloneAsInstantiable(subtype);
|
7111
|
+
if ((0, types_1.isFunction)(subtype) || (0, types_1.isTypeVar)(subtype)) {
|
7112
|
+
return (0, typeUtils_1.convertToInstantiable)(subtype);
|
7083
7113
|
}
|
7084
7114
|
}
|
7085
7115
|
return types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(expandedCallType), [
|
7086
7116
|
types_1.UnknownType.create(),
|
7087
7117
|
]);
|
7088
7118
|
});
|
7089
|
-
return { returnType };
|
7119
|
+
return { returnType, isTypeIncomplete: argTypeResult.isIncomplete };
|
7090
7120
|
}
|
7091
7121
|
if (argList.length >= 2) {
|
7092
7122
|
// The two-parameter form of a call to a metaclass returns a new class
|
@@ -8377,9 +8407,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
8377
8407
|
});
|
8378
8408
|
});
|
8379
8409
|
}
|
8380
|
-
// Lock the type var map so it cannot be modified when revalidating
|
8381
|
-
// the arguments in a second pass.
|
8382
|
-
constraints.lock();
|
8383
8410
|
}
|
8384
8411
|
let sawParamSpecArgs = false;
|
8385
8412
|
let sawParamSpecKwargs = false;
|
@@ -9683,8 +9710,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
9683
9710
|
typeErrors = true;
|
9684
9711
|
}
|
9685
9712
|
// Strip any literal values and TypeForm types.
|
9686
|
-
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags)));
|
9687
|
-
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags)));
|
9713
|
+
const keyTypes = keyTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, /* convertModule */ true)));
|
9714
|
+
const valueTypes = valueTypeResults.map((t) => (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(t.type), flags, /* convertModule */ true)));
|
9688
9715
|
keyType = keyTypes.length > 0 ? (0, types_1.combineTypes)(keyTypes) : fallbackType;
|
9689
9716
|
// If the value type differs and we're not using "strict inference mode",
|
9690
9717
|
// we need to back off because we can't properly represent the mappings
|
@@ -10035,7 +10062,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10035
10062
|
else {
|
10036
10063
|
entryTypeResult = getTypeOfExpression(entry, flags | 268435456 /* EvalFlags.StripTupleLiterals */);
|
10037
10064
|
}
|
10038
|
-
entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags));
|
10065
|
+
entryTypeResult.type = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(entryTypeResult.type, flags, /* convertModule */ true));
|
10039
10066
|
if (entryTypeResult.isIncomplete) {
|
10040
10067
|
isIncomplete = true;
|
10041
10068
|
}
|
@@ -11908,6 +11935,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11908
11935
|
function createSubclass(errorNode, type1, type2) {
|
11909
11936
|
var _a, _b;
|
11910
11937
|
(0, debug_1.assert)((0, types_1.isInstantiableClass)(type1) && (0, types_1.isInstantiableClass)(type2));
|
11938
|
+
// If both classes are class objects (type[A] and type[B]), create a new
|
11939
|
+
// class object (type[A & B]) rather than "type[A] & type[B]".
|
11940
|
+
let createClassObject = false;
|
11941
|
+
if (types_1.TypeBase.getInstantiableDepth(type1) > 0 && types_1.TypeBase.getInstantiableDepth(type2) > 0) {
|
11942
|
+
type1 = types_1.ClassType.cloneAsInstance(type1);
|
11943
|
+
type2 = types_1.ClassType.cloneAsInstance(type2);
|
11944
|
+
createClassObject = true;
|
11945
|
+
}
|
11911
11946
|
const className = `<subclass of ${printType((0, typeUtils_1.convertToInstance)(type1), {
|
11912
11947
|
omitTypeArgsIfUnknown: true,
|
11913
11948
|
})} and ${printType((0, typeUtils_1.convertToInstance)(type2), { omitTypeArgsIfUnknown: true })}>`;
|
@@ -11925,6 +11960,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
11925
11960
|
(0, typeUtils_1.computeMroLinearization)(newClassType);
|
11926
11961
|
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_a = type1.props) === null || _a === void 0 ? void 0 : _a.condition);
|
11927
11962
|
newClassType = (0, typeUtils_1.addConditionToType)(newClassType, (_b = type2.props) === null || _b === void 0 ? void 0 : _b.condition);
|
11963
|
+
if (createClassObject) {
|
11964
|
+
newClassType = types_1.ClassType.cloneAsInstantiable(newClassType);
|
11965
|
+
}
|
11928
11966
|
return newClassType;
|
11929
11967
|
}
|
11930
11968
|
function getTypeOfClass(node) {
|
@@ -13370,7 +13408,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13370
13408
|
skipInference = true;
|
13371
13409
|
}
|
13372
13410
|
if (!skipInference) {
|
13373
|
-
inferredParamType = convertSpecialFormToRuntimeValue(defaultValueType, 0 /* EvalFlags.None
|
13411
|
+
inferredParamType = convertSpecialFormToRuntimeValue(defaultValueType, 0 /* EvalFlags.None */,
|
13412
|
+
/* convertModule */ true);
|
13374
13413
|
inferredParamType = (0, typeUtils_1.stripTypeForm)(inferredParamType);
|
13375
13414
|
inferredParamType = stripLiteralValue(inferredParamType);
|
13376
13415
|
}
|
@@ -14359,7 +14398,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14359
14398
|
const typeAnnotation = ParseTreeUtils.getTypeAnnotationForParam(functionNode, paramIndex);
|
14360
14399
|
if (typeAnnotation) {
|
14361
14400
|
const param = functionNode.d.params[paramIndex];
|
14362
|
-
|
14401
|
+
let annotatedType = getTypeOfParamAnnotation(typeAnnotation, functionNode.d.params[paramIndex].d.category);
|
14402
|
+
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(param);
|
14403
|
+
annotatedType = (0, typeUtils_1.makeTypeVarsBound)(annotatedType, liveTypeVarScopes);
|
14363
14404
|
const adjType = transformVariadicParamType(node, node.d.category, adjustParamAnnotatedType(param, annotatedType));
|
14364
14405
|
writeTypeCache(node.d.name, { type: adjType }, 0 /* EvalFlags.None */);
|
14365
14406
|
return;
|
@@ -15406,7 +15447,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15406
15447
|
else {
|
15407
15448
|
const synthesizedType = symbol.getSynthesizedType();
|
15408
15449
|
if (synthesizedType) {
|
15409
|
-
synthesizedTypes.push(synthesizedType);
|
15450
|
+
synthesizedTypes.push({ type: synthesizedType, node });
|
15410
15451
|
}
|
15411
15452
|
else {
|
15412
15453
|
(0, collectionUtils_1.appendArray)(declarations, symbol.getDeclarations());
|
@@ -15495,7 +15536,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15495
15536
|
return { decls: declarations, synthesizedTypes };
|
15496
15537
|
}
|
15497
15538
|
function getTypeForDeclaration(declaration) {
|
15498
|
-
var _a, _b;
|
15539
|
+
var _a, _b, _c;
|
15499
15540
|
switch (declaration.type) {
|
15500
15541
|
case 0 /* DeclarationType.Intrinsic */: {
|
15501
15542
|
if (declaration.intrinsicType === 'Any') {
|
@@ -15556,12 +15597,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15556
15597
|
return { type: getTypeOfTypeAlias(declaration.node) };
|
15557
15598
|
}
|
15558
15599
|
case 2 /* DeclarationType.Param */: {
|
15559
|
-
let typeAnnotationNode = declaration.node.d.annotation
|
15600
|
+
let typeAnnotationNode = (_a = declaration.node.d.annotation) !== null && _a !== void 0 ? _a : declaration.node.d.annotationComment;
|
15560
15601
|
// If there wasn't an annotation, see if the parent function
|
15561
15602
|
// has a function-level annotation comment that provides
|
15562
15603
|
// this parameter's annotation type.
|
15563
15604
|
if (!typeAnnotationNode) {
|
15564
|
-
if (((
|
15605
|
+
if (((_b = declaration.node.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 31 /* ParseNodeType.Function */) {
|
15565
15606
|
const functionNode = declaration.node.parent;
|
15566
15607
|
if (functionNode.d.funcAnnotationComment &&
|
15567
15608
|
!functionNode.d.funcAnnotationComment.d.isEllipsis) {
|
@@ -15595,7 +15636,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15595
15636
|
}
|
15596
15637
|
else {
|
15597
15638
|
const declNode = declaration.isDefinedByMemberAccess &&
|
15598
|
-
((
|
15639
|
+
((_c = declaration.node.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 35 /* ParseNodeType.MemberAccess */
|
15599
15640
|
? declaration.node.parent
|
15600
15641
|
: declaration.node;
|
15601
15642
|
declaredType = getTypeOfAnnotation(typeAnnotationNode, {
|
@@ -16019,7 +16060,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16019
16060
|
includesVariableDecl: includesVariableTypeDecl(typedDecls),
|
16020
16061
|
includesIllegalTypeAliasDecl: !typedDecls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
|
16021
16062
|
includesSpeculativeResult: false,
|
16022
|
-
isRecursiveDefinition: !declaredType,
|
16063
|
+
isRecursiveDefinition: !declaredType && !speculativeTypeTracker.isSpeculative(/* node */ undefined),
|
16023
16064
|
};
|
16024
16065
|
return result;
|
16025
16066
|
}
|
@@ -16558,7 +16599,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16558
16599
|
paramType = types_1.UnknownType.create();
|
16559
16600
|
}
|
16560
16601
|
if (stripLiteralArgTypes) {
|
16561
|
-
paramType = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(paramType), 0 /* EvalFlags.None
|
16602
|
+
paramType = (0, typeUtils_1.stripTypeForm)(convertSpecialFormToRuntimeValue(stripLiteralValue(paramType), 0 /* EvalFlags.None */,
|
16603
|
+
/* convertModule */ true));
|
16562
16604
|
}
|
16563
16605
|
paramTypes.push(paramType);
|
16564
16606
|
writeTypeCache(param.d.name, { type: paramType }, 0 /* EvalFlags.None */);
|
@@ -16965,7 +17007,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16965
17007
|
// in this case. Adding more information is unnecessary and confusing.
|
16966
17008
|
(flags & 1 /* AssignTypeFlags.Invariant */) === 0 ? diag : undefined, constraints, flags, recursionCount);
|
16967
17009
|
}
|
16968
|
-
if (constraints && curSrcType.priv.typeArgs
|
17010
|
+
if (constraints && curSrcType.priv.typeArgs) {
|
16969
17011
|
// Populate the typeVar map with type arguments of the source.
|
16970
17012
|
const srcTypeArgs = curSrcType.priv.typeArgs;
|
16971
17013
|
for (let i = 0; i < destType.shared.typeParams.length; i++) {
|
@@ -17046,6 +17088,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17046
17088
|
// why two types are not the same.
|
17047
17089
|
includeDiagAddendum = false;
|
17048
17090
|
}
|
17091
|
+
// Special-case TypeForm to retain literals when solving TypeVars.
|
17092
|
+
if (types_1.ClassType.isBuiltIn(destType, 'TypeForm')) {
|
17093
|
+
effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
17094
|
+
}
|
17049
17095
|
if (!assignType(variance === 4 /* Variance.Contravariant */ ? srcTypeArg : destTypeArg, variance === 4 /* Variance.Contravariant */ ? destTypeArg : srcTypeArg, assignmentDiag, constraints, effectiveFlags, recursionCount)) {
|
17050
17096
|
// Don't report errors with type variables in "pseudo-random"
|
17051
17097
|
// classes since these type variables are not real.
|
@@ -17154,6 +17200,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17154
17200
|
flags |= 4 /* AssignTypeFlags.SkipRecursiveTypeCheck */;
|
17155
17201
|
}
|
17156
17202
|
}
|
17203
|
+
// If one or both of the types has an instantiable depth greater than
|
17204
|
+
// zero, convert both to instances first.
|
17205
|
+
if (types_1.TypeBase.isInstantiable(destType) && types_1.TypeBase.isInstantiable(srcType)) {
|
17206
|
+
if (types_1.TypeBase.getInstantiableDepth(destType) > 0 || types_1.TypeBase.getInstantiableDepth(srcType) > 0) {
|
17207
|
+
return assignType((0, typeUtils_1.convertToInstance)(destType), (0, typeUtils_1.convertToInstance)(srcType), diag, constraints, flags, recursionCount);
|
17208
|
+
}
|
17209
|
+
}
|
17157
17210
|
// Transform recursive type aliases if necessary.
|
17158
17211
|
const transformedDestType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(destType);
|
17159
17212
|
const transformedSrcType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(srcType);
|
@@ -17179,10 +17232,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17179
17232
|
if ((0, types_1.isUnbound)(destType) || (0, types_1.isUnbound)(srcType)) {
|
17180
17233
|
return true;
|
17181
17234
|
}
|
17182
|
-
// Handle TypeForm assignments.
|
17183
|
-
if (assignToTypeFormType(destType, srcType, constraints, flags, recursionCount)) {
|
17184
|
-
return true;
|
17185
|
-
}
|
17186
17235
|
if ((0, types_1.isTypeVar)(destType)) {
|
17187
17236
|
if ((0, typeUtils_1.isTypeVarSame)(destType, srcType)) {
|
17188
17237
|
return true;
|
@@ -17327,7 +17376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17327
17376
|
// If both the source and dest are unions, use assignFromUnionType which has
|
17328
17377
|
// special-case logic to handle this case.
|
17329
17378
|
if ((0, types_1.isUnion)(srcType)) {
|
17330
|
-
return assignFromUnionType(destType, srcType,
|
17379
|
+
return assignFromUnionType(destType, srcType, diag, constraints, flags, recursionCount);
|
17331
17380
|
}
|
17332
17381
|
const clonedConstraints = constraints === null || constraints === void 0 ? void 0 : constraints.clone();
|
17333
17382
|
if (assignToUnionType(destType, srcType, /* diag */ undefined, clonedConstraints, flags, recursionCount)) {
|
@@ -17372,7 +17421,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17372
17421
|
// PEP 544 says that if the dest type is a type[Proto] class,
|
17373
17422
|
// the source must be a "concrete" (non-protocol) class.
|
17374
17423
|
if (types_1.ClassType.isProtocolClass(destType)) {
|
17375
|
-
if (
|
17424
|
+
if ((flags & 65536 /* AssignTypeFlags.AllowProtocolClassSource */) === 0 &&
|
17425
|
+
types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
17376
17426
|
(0, types_1.isInstantiableClass)(srcType) &&
|
17377
17427
|
!srcType.priv.includeSubclasses) {
|
17378
17428
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolSourceIsNotConcrete().format({
|
@@ -17416,7 +17466,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17416
17466
|
}
|
17417
17467
|
if ((0, types_1.isClassInstance)(destType)) {
|
17418
17468
|
if (types_1.ClassType.isBuiltIn(destType, 'type')) {
|
17419
|
-
if ((0, types_1.isInstantiableClass)(srcType) &&
|
17469
|
+
if ((0, types_1.isInstantiableClass)(srcType) &&
|
17470
|
+
isSpecialFormClass(srcType, flags) &&
|
17471
|
+
types_1.TypeBase.getInstantiableDepth(srcType) === 0) {
|
17420
17472
|
return false;
|
17421
17473
|
}
|
17422
17474
|
if ((0, types_1.isAnyOrUnknown)(srcType) && (flags & 16 /* AssignTypeFlags.OverloadOverlap */) !== 0) {
|
@@ -17652,20 +17704,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17652
17704
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
17653
17705
|
return false;
|
17654
17706
|
}
|
17655
|
-
// If the
|
17656
|
-
// type has an implicit TypeForm type that can be assigned to it.
|
17657
|
-
//
|
17658
|
-
function
|
17659
|
-
var _a, _b;
|
17660
|
-
|
17661
|
-
|
17707
|
+
// If the expected type is an explicit TypeForm type, see if the source
|
17708
|
+
// type has an implicit TypeForm type that can be assigned to it. If so,
|
17709
|
+
// convert to an explicit TypeForm type.
|
17710
|
+
function convertToTypeFormType(expectedType, srcType) {
|
17711
|
+
var _a, _b, _c;
|
17712
|
+
// Is the source is a TypeForm type?
|
17713
|
+
if (!((_a = srcType.props) === null || _a === void 0 ? void 0 : _a.typeForm)) {
|
17714
|
+
return srcType;
|
17662
17715
|
}
|
17663
|
-
const destTypeFormType = destType.priv.typeArgs && destType.priv.typeArgs.length > 0
|
17664
|
-
? destType.priv.typeArgs[0]
|
17665
|
-
: types_1.UnknownType.create();
|
17666
17716
|
let srcTypeFormType;
|
17667
17717
|
// Is the source is a TypeForm type?
|
17668
|
-
if ((
|
17718
|
+
if ((_b = srcType.props) === null || _b === void 0 ? void 0 : _b.typeForm) {
|
17669
17719
|
srcTypeFormType = srcType.props.typeForm;
|
17670
17720
|
}
|
17671
17721
|
else if ((0, types_1.isClass)(srcType)) {
|
@@ -17676,7 +17726,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17676
17726
|
}
|
17677
17727
|
else if (types_1.ClassType.isBuiltIn(srcType, 'type')) {
|
17678
17728
|
srcTypeFormType =
|
17679
|
-
((
|
17729
|
+
((_c = srcType.priv.typeArgs) === null || _c === void 0 ? void 0 : _c.length) && srcType.priv.typeArgs.length > 0
|
17680
17730
|
? srcType.priv.typeArgs[0]
|
17681
17731
|
: types_1.UnknownType.create();
|
17682
17732
|
}
|
@@ -17687,9 +17737,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17687
17737
|
}
|
17688
17738
|
}
|
17689
17739
|
if (!srcTypeFormType) {
|
17690
|
-
return
|
17740
|
+
return srcType;
|
17691
17741
|
}
|
17692
|
-
|
17742
|
+
let resultType;
|
17743
|
+
(0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
|
17744
|
+
if (resultType || !(0, types_1.isClassInstance)(subtype) || !types_1.ClassType.isBuiltIn(subtype, 'TypeForm')) {
|
17745
|
+
return;
|
17746
|
+
}
|
17747
|
+
const destTypeFormType = subtype.priv.typeArgs && subtype.priv.typeArgs.length > 0
|
17748
|
+
? subtype.priv.typeArgs[0]
|
17749
|
+
: types_1.UnknownType.create();
|
17750
|
+
if (assignType(destTypeFormType, srcTypeFormType)) {
|
17751
|
+
resultType = types_1.ClassType.specialize(subtype, [srcTypeFormType]);
|
17752
|
+
}
|
17753
|
+
});
|
17754
|
+
return resultType !== null && resultType !== void 0 ? resultType : srcType;
|
17693
17755
|
}
|
17694
17756
|
function assignFromUnionType(destType, srcType, diag, constraints, flags, recursionCount) {
|
17695
17757
|
// Start by checking for an exact match. This is needed to handle unions
|
@@ -17887,9 +17949,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
17887
17949
|
// Finds unsolved type variables in the destType and establishes constraints
|
17888
17950
|
// in the constraint tracker for them based on the srcType.
|
17889
17951
|
function setConstraintsForFreeTypeVars(destType, srcType, constraints) {
|
17890
|
-
if (constraints.isLocked()) {
|
17891
|
-
return;
|
17892
|
-
}
|
17893
17952
|
const typeVars = (0, typeUtils_1.getTypeVarArgsRecursive)(destType);
|
17894
17953
|
typeVars.forEach((typeVar) => {
|
17895
17954
|
if (!types_1.TypeVarType.isBound(typeVar) && !constraints.getMainConstraintSet().getTypeVar(typeVar)) {
|
@@ -19485,11 +19544,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19485
19544
|
// contain references to themselves or their subclasses, so if
|
19486
19545
|
// we attempt to call assignType, we'll risk infinite recursion.
|
19487
19546
|
// Instead, we'll assume it's assignable.
|
19488
|
-
|
19489
|
-
|
19490
|
-
|
19491
|
-
: firstParamType);
|
19492
|
-
}
|
19547
|
+
constraints.setBounds(memberTypeFirstParamType, types_1.TypeBase.isInstantiable(memberTypeFirstParamType)
|
19548
|
+
? (0, typeUtils_1.convertToInstance)(firstParamType)
|
19549
|
+
: firstParamType);
|
19493
19550
|
}
|
19494
19551
|
else {
|
19495
19552
|
const subDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
@@ -19830,6 +19887,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19830
19887
|
getBoundMagicMethod,
|
19831
19888
|
getTypeOfMagicMethodCall,
|
19832
19889
|
bindFunctionToClassOrObject,
|
19890
|
+
getCallbackProtocolType,
|
19833
19891
|
getCallSignatureInfo,
|
19834
19892
|
getAbstractSymbols,
|
19835
19893
|
narrowConstrainedTypeVar,
|
@@ -19841,6 +19899,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
19841
19899
|
assignClassToSelf,
|
19842
19900
|
getTypedDictClassType,
|
19843
19901
|
getTupleClassType,
|
19902
|
+
getDictClassType,
|
19903
|
+
getStrClassType,
|
19844
19904
|
getObjectType,
|
19845
19905
|
getNoneType,
|
19846
19906
|
getUnionClassType,
|