@zzzen/pyright-internal 1.2.0-dev.20231231 → 1.2.0-dev.20240114
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.js +12 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -0
- package/dist/analyzer/checker.js +191 -36
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +6 -6
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +11 -1
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +2 -2
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +9 -9
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -2
- package/dist/analyzer/importResolver.js +93 -24
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +13 -5
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +4 -3
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +37 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +4 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +2 -0
- package/dist/analyzer/protocols.js +90 -14
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scopeUtils.d.ts +1 -0
- package/dist/analyzer/scopeUtils.js +12 -1
- package/dist/analyzer/scopeUtils.js.map +1 -1
- package/dist/analyzer/service.d.ts +1 -1
- package/dist/analyzer/service.js +7 -6
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +2 -2
- package/dist/analyzer/sourceFile.js +5 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +399 -223
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -3
- package/dist/analyzer/typeEvaluatorTypes.js +4 -4
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +22 -13
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +4 -2
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -1
- package/dist/analyzer/typeUtils.js +19 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +10 -6
- package/dist/analyzer/types.js +41 -26
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +12 -11
- package/dist/backgroundAnalysisBase.js +62 -65
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +6 -4
- package/dist/backgroundThreadBase.js +64 -54
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/quickActionCommand.js +1 -1
- package/dist/commands/quickActionCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +6 -3
- package/dist/common/cancellationUtils.js +29 -5
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/commandUtils.d.ts +2 -0
- package/dist/common/commandUtils.js +24 -0
- package/dist/common/commandUtils.js.map +1 -0
- package/dist/common/extensibility.d.ts +7 -6
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileBasedCancellationUtils.js +19 -13
- package/dist/common/fileBasedCancellationUtils.js.map +1 -1
- package/dist/common/fullAccessHost.d.ts +1 -1
- package/dist/common/fullAccessHost.js +2 -2
- package/dist/common/fullAccessHost.js.map +1 -1
- package/dist/common/host.d.ts +2 -2
- package/dist/common/host.js.map +1 -1
- package/dist/common/realFileSystem.js +52 -20
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.js +8 -1
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/uri/baseUri.d.ts +4 -1
- package/dist/common/uri/baseUri.js +7 -1
- package/dist/common/uri/baseUri.js.map +1 -1
- package/dist/common/uri/emptyUri.d.ts +3 -0
- package/dist/common/uri/emptyUri.js +9 -0
- package/dist/common/uri/emptyUri.js.map +1 -1
- package/dist/common/uri/fileUri.d.ts +2 -0
- package/dist/common/uri/fileUri.js +6 -0
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/memoization.js +1 -1
- package/dist/common/uri/memoization.js.map +1 -1
- package/dist/common/uri/uri.d.ts +4 -1
- package/dist/common/uri/uri.js +5 -2
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +2 -0
- package/dist/common/uri/uriUtils.js +18 -1
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/common/uri/webUri.d.ts +2 -0
- package/dist/common/uri/webUri.js +7 -1
- package/dist/common/uri/webUri.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +6 -5
- package/dist/common/workspaceEditUtils.js +18 -17
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -0
- package/dist/languageServerBase.js +28 -25
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.d.ts +1 -2
- package/dist/languageService/analyzerServiceExecutor.js +6 -5
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.js +3 -3
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +9 -7
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/codeActionProvider.js +3 -2
- package/dist/languageService/codeActionProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -4
- package/dist/languageService/completionProvider.js +14 -18
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolProvider.js +5 -4
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/navigationUtils.js +2 -1
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/languageService/renameProvider.js +2 -2
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +2 -1
- package/dist/languageService/workspaceSymbolProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +32 -4
- package/dist/localization/localize.js +15 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +19 -4
- package/dist/localization/package.nls.de.json +19 -4
- package/dist/localization/package.nls.en-us.json +16 -3
- package/dist/localization/package.nls.es.json +19 -4
- package/dist/localization/package.nls.fr.json +18 -3
- package/dist/localization/package.nls.it.json +19 -4
- package/dist/localization/package.nls.ja.json +19 -4
- package/dist/localization/package.nls.ko.json +19 -4
- package/dist/localization/package.nls.pl.json +19 -4
- package/dist/localization/package.nls.pt-br.json +19 -4
- package/dist/localization/package.nls.qps-ploc.json +19 -4
- package/dist/localization/package.nls.ru.json +18 -3
- package/dist/localization/package.nls.tr.json +19 -4
- package/dist/localization/package.nls.zh-cn.json +19 -4
- package/dist/localization/package.nls.zh-tw.json +19 -4
- package/dist/parser/parser.d.ts +0 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +2 -4
- package/dist/parser/tokenizer.js +5 -6
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +2 -2
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +3 -3
- package/dist/pyright.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +8 -8
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/completions.test.js +3 -3
- package/dist/tests/completions.test.js.map +1 -1
- package/dist/tests/config.test.js +10 -2
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/filesystem.test.js +4 -4
- package/dist/tests/filesystem.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +22 -8
- package/dist/tests/fourSlashParser.test.js.map +1 -1
- package/dist/tests/fourslash/rename.multipleDecl.fourslash.d.ts +1 -1
- package/dist/tests/harness/fourslash/fourSlashParser.js +4 -0
- package/dist/tests/harness/fourslash/fourSlashParser.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.d.ts +3 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.d.ts +13 -0
- package/dist/tests/harness/fourslash/testState.js +13 -8
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/factory.d.ts +1 -1
- package/dist/tests/harness/vfs/factory.js +4 -4
- package/dist/tests/harness/vfs/factory.js.map +1 -1
- package/dist/tests/importStatementUtils.test.js +1 -1
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/ipythonMode.test.js +11 -12
- package/dist/tests/ipythonMode.test.js.map +1 -1
- package/dist/tests/localizer.test.js +1 -1
- package/dist/tests/localizer.test.js.map +1 -1
- package/dist/tests/serialization.test.d.ts +2 -0
- package/dist/tests/serialization.test.js +88 -0
- package/dist/tests/serialization.test.js.map +1 -0
- package/dist/tests/service.test.js +1 -1
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +2 -3
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/sourceFile.test.js +3 -3
- package/dist/tests/sourceFile.test.js.map +1 -1
- package/dist/tests/sourceMapperUtils.test.js +2 -2
- package/dist/tests/sourceMapperUtils.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testStateUtils.js +2 -2
- package/dist/tests/testStateUtils.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +1 -2
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +13 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +17 -5
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +9 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -6
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/uri.test.js +37 -7
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/tests/workspaceEditUtils.test.js +8 -8
- package/dist/tests/workspaceEditUtils.test.js.map +1 -1
- package/dist/workspaceFactory.js +1 -1
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +2 -1
@@ -187,6 +187,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
187
187
|
let noneType;
|
188
188
|
let objectType;
|
189
189
|
let typeClassType;
|
190
|
+
let unionClassType;
|
190
191
|
let awaitableProtocolType;
|
191
192
|
let functionObj;
|
192
193
|
let tupleClassType;
|
@@ -462,6 +463,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
462
463
|
objectType = getBuiltInObject(node, 'object');
|
463
464
|
typeClassType = getBuiltInType(node, 'type');
|
464
465
|
functionObj = getBuiltInObject(node, 'function');
|
466
|
+
unionClassType = getTypesType(node, 'UnionType');
|
467
|
+
if (unionClassType && (0, types_1.isClass)(unionClassType)) {
|
468
|
+
unionClassType.details.flags |= 1073741824 /* ClassTypeFlags.SpecialFormClass */;
|
469
|
+
}
|
465
470
|
// Initialize and cache "Collection" to break a cyclical dependency
|
466
471
|
// that occurs when resolving tuple below.
|
467
472
|
getTypingType(node, 'Collection');
|
@@ -482,6 +487,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
482
487
|
// Fall back on 'Mapping' if 'SupportsKeysAndGetItem' is not available.
|
483
488
|
mappingType = getTypingType(node, 'Mapping');
|
484
489
|
}
|
490
|
+
// Wire up the `Any` class to the special-form version of our internal AnyType.
|
491
|
+
const objectClass = getBuiltInType(node, 'object');
|
492
|
+
if (objectClass &&
|
493
|
+
(0, types_1.isInstantiableClass)(objectClass) &&
|
494
|
+
typeClassType &&
|
495
|
+
(0, types_1.isInstantiableClass)(typeClassType)) {
|
496
|
+
const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */,
|
497
|
+
/* typeSourceId */ -1,
|
498
|
+
/* declaredMetaclass */ undefined,
|
499
|
+
/* effectiveMetaclass */ typeClassType);
|
500
|
+
anyClass.details.baseClasses.push(objectClass);
|
501
|
+
(0, typeUtils_1.computeMroLinearization)(anyClass);
|
502
|
+
const anySpecialForm = types_1.AnyType.createSpecialForm();
|
503
|
+
if ((0, types_1.isAny)(anySpecialForm)) {
|
504
|
+
anySpecialForm.specialForm = anyClass;
|
505
|
+
}
|
506
|
+
}
|
485
507
|
}
|
486
508
|
}
|
487
509
|
function getTypeOfExpression(node, flags = 0 /* EvaluatorFlags.None */, inferenceContext) {
|
@@ -755,7 +777,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
755
777
|
const isEmptyVariadic = (0, types_1.isClassInstance)(typeResult.type) &&
|
756
778
|
types_1.ClassType.isTupleClass(typeResult.type) &&
|
757
779
|
((_a = typeResult.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 0;
|
758
|
-
const isEllipsis = (0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis');
|
780
|
+
const isEllipsis = (0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, ['EllipsisType', 'ellipsis']);
|
759
781
|
if (!isEmptyVariadic && !isEllipsis) {
|
760
782
|
addExpectedClassDiagnostic(typeResult.type, node);
|
761
783
|
typeResult.type = types_1.UnknownType.create();
|
@@ -783,11 +805,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
783
805
|
return typeResult;
|
784
806
|
}
|
785
807
|
function getTypeOfEllipsis(flags, typeResult, node) {
|
808
|
+
var _a, _b;
|
786
809
|
if ((flags & 1 /* EvaluatorFlags.ConvertEllipsisToAny */) !== 0) {
|
787
810
|
typeResult = { type: types_1.AnyType.create(/* isEllipsis */ true) };
|
788
811
|
}
|
789
812
|
else {
|
790
|
-
const ellipsisType = getBuiltInObject(node, 'ellipsis')
|
813
|
+
const ellipsisType = (_b = (_a = getBuiltInObject(node, 'EllipsisType')) !== null && _a !== void 0 ? _a : getBuiltInObject(node, 'ellipsis')) !== null && _b !== void 0 ? _b : types_1.AnyType.create();
|
791
814
|
typeResult = { type: ellipsisType };
|
792
815
|
}
|
793
816
|
return typeResult;
|
@@ -1637,7 +1660,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1637
1660
|
return getDeclaredTypeForExpression(expression.valueExpression, usage);
|
1638
1661
|
}
|
1639
1662
|
case 35 /* ParseNodeType.MemberAccess */: {
|
1640
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression,
|
1663
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */).type);
|
1641
1664
|
let classMemberInfo;
|
1642
1665
|
if ((0, types_1.isClassInstance)(baseType)) {
|
1643
1666
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 64 /* MemberAccessFlags.DeclaredTypesOnly */);
|
@@ -1924,10 +1947,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1924
1947
|
function getNoneType() {
|
1925
1948
|
return noneType !== null && noneType !== void 0 ? noneType : types_1.UnknownType.create();
|
1926
1949
|
}
|
1950
|
+
function getUnionClassType() {
|
1951
|
+
return unionClassType !== null && unionClassType !== void 0 ? unionClassType : types_1.UnknownType.create();
|
1952
|
+
}
|
1927
1953
|
function getTypingType(node, symbolName) {
|
1928
1954
|
var _a;
|
1929
1955
|
return ((_a = getTypeOfModule(node, symbolName, ['typing'])) !== null && _a !== void 0 ? _a : getTypeOfModule(node, symbolName, ['typing_extensions']));
|
1930
1956
|
}
|
1957
|
+
function getTypesType(node, symbolName) {
|
1958
|
+
return getTypeOfModule(node, symbolName, ['types']);
|
1959
|
+
}
|
1931
1960
|
function getTypeshedType(node, symbolName) {
|
1932
1961
|
return getTypeOfModule(node, symbolName, ['_typeshed']);
|
1933
1962
|
}
|
@@ -2193,7 +2222,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2193
2222
|
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* EvaluatorFlags.None */);
|
2194
2223
|
}
|
2195
2224
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2196
|
-
const baseTypeResult = getTypeOfExpression(target.leftExpression,
|
2225
|
+
const baseTypeResult = getTypeOfExpression(target.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
|
2197
2226
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2198
2227
|
// Handle member accesses (e.g. self.x or cls.y).
|
2199
2228
|
if (target.leftExpression.nodeType === 38 /* ParseNodeType.Name */) {
|
@@ -2653,7 +2682,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2653
2682
|
// Is the source expression a TypeVar() call?
|
2654
2683
|
if ((0, types_1.isTypeVar)(type)) {
|
2655
2684
|
if (srcExpr && srcExpr.nodeType === 9 /* ParseNodeType.Call */) {
|
2656
|
-
const callType = getTypeOfExpression(srcExpr.leftExpression,
|
2685
|
+
const callType = getTypeOfExpression(srcExpr.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
|
2657
2686
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
2658
2687
|
(types_1.ClassType.isBuiltIn(callType, 'TypeVar') ||
|
2659
2688
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
@@ -2812,7 +2841,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2812
2841
|
break;
|
2813
2842
|
}
|
2814
2843
|
case 35 /* ParseNodeType.MemberAccess */: {
|
2815
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression,
|
2844
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* EvaluatorFlags.MemberAccessBaseDefaults */);
|
2816
2845
|
const delAccessResult = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* EvaluatorFlags.None */);
|
2817
2846
|
const resultToCache = {
|
2818
2847
|
type: delAccessResult.type,
|
@@ -2857,7 +2886,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2857
2886
|
}
|
2858
2887
|
}
|
2859
2888
|
function getTypeOfName(node, flags) {
|
2860
|
-
var _a;
|
2861
2889
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
2862
2890
|
const name = node.value;
|
2863
2891
|
let symbol;
|
@@ -3012,17 +3040,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3012
3040
|
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) === 0) {
|
3013
3041
|
reportUseOfTypeCheckOnly(type, node);
|
3014
3042
|
}
|
3015
|
-
if ((flags & 16777216 /* EvaluatorFlags.TreatPep695TypeAliasAsObject */) !== 0) {
|
3016
|
-
if (((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.name) && type.typeAliasInfo.isPep695Syntax && types_1.TypeBase.isSpecialForm(type)) {
|
3017
|
-
const typeAliasType = getTypingType(node, 'TypeAliasType');
|
3018
|
-
if (typeAliasType && (0, types_1.isInstantiableClass)(typeAliasType)) {
|
3019
|
-
type = types_1.ClassType.cloneAsInstance(typeAliasType);
|
3020
|
-
}
|
3021
|
-
else {
|
3022
|
-
type = types_1.UnknownType.create();
|
3023
|
-
}
|
3024
|
-
}
|
3025
|
-
}
|
3026
3043
|
if ((flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0) {
|
3027
3044
|
if ((flags & 1024 /* EvaluatorFlags.AllowGenericClassType */) === 0) {
|
3028
3045
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
@@ -3269,6 +3286,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3269
3286
|
if (param.details.defaultType || param.details.isParamSpec) {
|
3270
3287
|
defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
|
3271
3288
|
}
|
3289
|
+
else if (param.details.isVariadic && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
3290
|
+
defaultType = types_1.ClassType.cloneForUnpacked((0, typeUtils_1.specializeTupleClass)(types_1.ClassType.cloneAsInstance(tupleClassType), [
|
3291
|
+
{ type: types_1.UnknownType.create(), isUnbounded: true },
|
3292
|
+
]));
|
3293
|
+
}
|
3272
3294
|
else {
|
3273
3295
|
defaultType = types_1.UnknownType.create();
|
3274
3296
|
}
|
@@ -3390,7 +3412,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3390
3412
|
function getTypeOfMemberAccess(node, flags) {
|
3391
3413
|
var _a;
|
3392
3414
|
// Compute flags specifically for evaluating the left expression.
|
3393
|
-
let leftExprFlags =
|
3415
|
+
let leftExprFlags = 2 /* EvaluatorFlags.MemberAccessBaseDefaults */;
|
3394
3416
|
leftExprFlags |=
|
3395
3417
|
flags &
|
3396
3418
|
(256 /* EvaluatorFlags.ExpectingTypeAnnotation */ |
|
@@ -3461,8 +3483,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3461
3483
|
// cases where a type is passed as an argument (e.g. "defaultdict(list)").
|
3462
3484
|
// It can also come up in cases like "isinstance(x, (list, dict))".
|
3463
3485
|
// We need to check for functions as well to handle Callable.
|
3464
|
-
if ((0, types_1.isInstantiableClass)(typeResult.type) ||
|
3465
|
-
|
3486
|
+
if (((0, types_1.isInstantiableClass)(typeResult.type) && !typeResult.type.includeSubclasses) ||
|
3487
|
+
typeResult.type.specialForm) {
|
3466
3488
|
const argNode = ParseTreeUtils.getParentNodeOfType(node, 1 /* ParseNodeType.Argument */);
|
3467
3489
|
if (argNode && ((_a = argNode === null || argNode === void 0 ? void 0 : argNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* ParseNodeType.Call */) {
|
3468
3490
|
skipPartialUnknownCheck = true;
|
@@ -3493,12 +3515,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3493
3515
|
if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
|
3494
3516
|
return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
|
3495
3517
|
}
|
3496
|
-
|
3497
|
-
|
3498
|
-
if ((0, types_1.isUnion)(baseType) && types_1.TypeBase.isSpecialForm(baseType)) {
|
3499
|
-
if (objectType) {
|
3500
|
-
baseType = objectType;
|
3501
|
-
}
|
3518
|
+
if (baseType.specialForm) {
|
3519
|
+
baseType = baseType.specialForm;
|
3502
3520
|
}
|
3503
3521
|
if ((0, types_1.isParamSpec)(baseType) && baseType.paramSpecAccess) {
|
3504
3522
|
baseType = makeTopLevelTypeVarsConcrete(baseType);
|
@@ -4348,7 +4366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4348
4366
|
}
|
4349
4367
|
}
|
4350
4368
|
}
|
4351
|
-
const indexTypeResult = getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'get' }, flags
|
4369
|
+
const indexTypeResult = getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'get' }, flags);
|
4352
4370
|
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(node)) {
|
4353
4371
|
// We limit type narrowing for index expressions to built-in types that are
|
4354
4372
|
// known to have symmetric __getitem__ and __setitem__ methods (i.e. the value
|
@@ -4383,10 +4401,46 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4383
4401
|
}
|
4384
4402
|
return indexTypeResult;
|
4385
4403
|
}
|
4404
|
+
// If the list of type parameters includes a TypeVarTuple, we may need to adjust
|
4405
|
+
// the supplied type arguments to map to the type parameter list.
|
4386
4406
|
function adjustTypeArgumentsForVariadicTypeVar(typeArgs, typeParameters, errorNode) {
|
4387
4407
|
const variadicIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
4408
|
+
// Is there a *tuple[T, ...] somewhere in the type arguments that we can expand if needed?
|
4409
|
+
let srcUnboundedTupleType;
|
4410
|
+
let srcUnboundedTupleIndex = typeArgs.findIndex((arg) => {
|
4411
|
+
if ((0, types_1.isUnpackedClass)(arg.type) &&
|
4412
|
+
arg.type.tupleTypeArguments &&
|
4413
|
+
arg.type.tupleTypeArguments.length === 1 &&
|
4414
|
+
arg.type.tupleTypeArguments[0].isUnbounded) {
|
4415
|
+
srcUnboundedTupleType = arg.type.tupleTypeArguments[0].type;
|
4416
|
+
return true;
|
4417
|
+
}
|
4418
|
+
return false;
|
4419
|
+
});
|
4420
|
+
if (srcUnboundedTupleType &&
|
4421
|
+
srcUnboundedTupleIndex >= 0 &&
|
4422
|
+
variadicIndex >= 0 &&
|
4423
|
+
typeArgs.length < typeParameters.length) {
|
4424
|
+
// "Smear" the tuple type across type argument slots prior to the variadic type var.
|
4425
|
+
while (variadicIndex > srcUnboundedTupleIndex) {
|
4426
|
+
typeArgs = [
|
4427
|
+
...typeArgs.slice(0, srcUnboundedTupleIndex),
|
4428
|
+
{ node: typeArgs[srcUnboundedTupleIndex].node, type: srcUnboundedTupleType },
|
4429
|
+
...typeArgs.slice(srcUnboundedTupleIndex),
|
4430
|
+
];
|
4431
|
+
srcUnboundedTupleIndex++;
|
4432
|
+
}
|
4433
|
+
// "Smear" the tuple type across type argument slots following the variadic type var.
|
4434
|
+
while (typeArgs.length < typeParameters.length) {
|
4435
|
+
typeArgs = [
|
4436
|
+
...typeArgs.slice(0, srcUnboundedTupleIndex + 1),
|
4437
|
+
{ node: typeArgs[srcUnboundedTupleIndex].node, type: srcUnboundedTupleType },
|
4438
|
+
...typeArgs.slice(srcUnboundedTupleIndex + 1),
|
4439
|
+
];
|
4440
|
+
}
|
4441
|
+
}
|
4388
4442
|
// Do we need to adjust the type arguments to map to a variadic type
|
4389
|
-
// param
|
4443
|
+
// param somewhere in the list?
|
4390
4444
|
if (variadicIndex >= 0) {
|
4391
4445
|
const variadicTypeVar = typeParameters[variadicIndex];
|
4392
4446
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
@@ -4485,26 +4539,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4485
4539
|
];
|
4486
4540
|
}
|
4487
4541
|
}
|
4488
|
-
|
4489
|
-
|
4490
|
-
|
4491
|
-
|
4492
|
-
|
4493
|
-
|
4494
|
-
|
4495
|
-
|
4496
|
-
|
4497
|
-
|
4498
|
-
|
4499
|
-
|
4500
|
-
|
4501
|
-
|
4502
|
-
|
4503
|
-
|
4504
|
-
|
4505
|
-
|
4506
|
-
}), node.items[node.items.length - 1]);
|
4507
|
-
}
|
4542
|
+
let minTypeArgCount = typeParameters.length;
|
4543
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.defaultType);
|
4544
|
+
if (firstDefaultParamIndex >= 0) {
|
4545
|
+
minTypeArgCount = firstDefaultParamIndex;
|
4546
|
+
}
|
4547
|
+
if (typeArgs.length > typeParameters.length) {
|
4548
|
+
addError(localize_1.Localizer.Diagnostic.typeArgsTooMany().format({
|
4549
|
+
name: printType(baseType),
|
4550
|
+
expected: typeParameters.length,
|
4551
|
+
received: typeArgs.length,
|
4552
|
+
}), typeArgs[typeParameters.length].node);
|
4553
|
+
}
|
4554
|
+
else if (typeArgs.length < minTypeArgCount) {
|
4555
|
+
addError(localize_1.Localizer.Diagnostic.typeArgsTooFew().format({
|
4556
|
+
name: printType(baseType),
|
4557
|
+
expected: typeParameters.length,
|
4558
|
+
received: typeArgs.length,
|
4559
|
+
}), node.items[node.items.length - 1]);
|
4508
4560
|
}
|
4509
4561
|
// Handle the mypy_extensions.FlexibleAlias type specially.
|
4510
4562
|
if ((0, types_1.isInstantiableClass)(baseType) &&
|
@@ -4520,7 +4572,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4520
4572
|
const typeList = typeArgs[index].typeList;
|
4521
4573
|
if (typeList) {
|
4522
4574
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
4523
|
-
types_1.TypeBase.setSpecialForm(functionType);
|
4524
4575
|
typeList.forEach((paramType, paramIndex) => {
|
4525
4576
|
types_1.FunctionType.addParameter(functionType, {
|
4526
4577
|
category: 0 /* ParameterCategory.Simple */,
|
@@ -4530,7 +4581,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4530
4581
|
hasDeclaredType: true,
|
4531
4582
|
});
|
4532
4583
|
});
|
4533
|
-
|
4584
|
+
if (typeList.length > 0) {
|
4585
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
4586
|
+
}
|
4534
4587
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4535
4588
|
}
|
4536
4589
|
else if ((0, types_1.isParamSpec)(typeArgType)) {
|
@@ -4566,7 +4619,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4566
4619
|
}
|
4567
4620
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
4568
4621
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */);
|
4569
|
-
types_1.TypeBase.setSpecialForm(functionType);
|
4570
4622
|
types_1.FunctionType.addDefaultParameters(functionType);
|
4571
4623
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext);
|
4572
4624
|
}
|
@@ -4602,6 +4654,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4602
4654
|
}
|
4603
4655
|
}
|
4604
4656
|
}
|
4657
|
+
if ((0, types_1.isUnpacked)(typeArgType) && !(0, types_1.isVariadicTypeVar)(param)) {
|
4658
|
+
const messageDiag = diag.createAddendum();
|
4659
|
+
messageDiag.addMessage(localize_1.Localizer.Diagnostic.unpackedArgInTypeArgument());
|
4660
|
+
messageDiag.addTextRange(typeArgs[index].node);
|
4661
|
+
typeArgType = types_1.UnknownType.create();
|
4662
|
+
}
|
4605
4663
|
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4606
4664
|
}
|
4607
4665
|
});
|
@@ -4691,7 +4749,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4691
4749
|
}
|
4692
4750
|
if (types_1.ClassType.isSpecialBuiltIn(concreteSubtype, 'Literal')) {
|
4693
4751
|
// Special-case Literal types.
|
4694
|
-
return createLiteralType(node, flags);
|
4752
|
+
return createLiteralType(concreteSubtype, node, flags);
|
4695
4753
|
}
|
4696
4754
|
if (types_1.ClassType.isBuiltIn(concreteSubtype, 'InitVar')) {
|
4697
4755
|
// Special-case InitVar, used in data classes.
|
@@ -4917,7 +4975,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4917
4975
|
}), node.baseExpression);
|
4918
4976
|
return { type: types_1.UnknownType.create() };
|
4919
4977
|
}
|
4920
|
-
// Handle the special case where the object is a
|
4978
|
+
// Handle the special case where the object is a tuple and
|
4921
4979
|
// the index is a constant number (integer) or a slice with integer
|
4922
4980
|
// start and end values. In these cases, we can determine
|
4923
4981
|
// the exact type by indexing into the tuple type array.
|
@@ -4950,39 +5008,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4950
5008
|
}
|
4951
5009
|
else if ((0, types_1.isClassInstance)(valueType) && types_1.ClassType.isBuiltIn(valueType, 'slice')) {
|
4952
5010
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
|
4953
|
-
if (tupleType &&
|
4954
|
-
|
4955
|
-
|
4956
|
-
|
4957
|
-
let value = defaultValue;
|
4958
|
-
if (expression) {
|
4959
|
-
const valType = getTypeOfExpression(expression).type;
|
4960
|
-
if ((0, types_1.isClassInstance)(valType) &&
|
4961
|
-
types_1.ClassType.isBuiltIn(valType, 'int') &&
|
4962
|
-
(0, typeUtils_1.isLiteralType)(valType) &&
|
4963
|
-
typeof valType.literalValue === 'number') {
|
4964
|
-
value = valType.literalValue;
|
4965
|
-
if (value < 0) {
|
4966
|
-
value = tupleType.tupleTypeArguments.length + value;
|
4967
|
-
}
|
4968
|
-
}
|
4969
|
-
else {
|
4970
|
-
value = -1;
|
4971
|
-
}
|
4972
|
-
}
|
4973
|
-
return value;
|
4974
|
-
};
|
4975
|
-
const startValue = getSliceParameter(index0Expr.startValue, 0);
|
4976
|
-
const endValue = getSliceParameter(index0Expr.endValue, tupleType.tupleTypeArguments.length);
|
4977
|
-
if (startValue >= 0 &&
|
4978
|
-
endValue > 0 &&
|
4979
|
-
endValue <= tupleType.tupleTypeArguments.length &&
|
4980
|
-
tupleClassType &&
|
4981
|
-
(0, types_1.isInstantiableClass)(tupleClassType)) {
|
4982
|
-
return {
|
4983
|
-
type: types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleClassType, tupleType.tupleTypeArguments.slice(startValue, endValue))),
|
4984
|
-
};
|
4985
|
-
}
|
5011
|
+
if (tupleType && index0Expr.nodeType === 46 /* ParseNodeType.Slice */) {
|
5012
|
+
const slicedTupleType = getSlicedTupleType(tupleType, index0Expr);
|
5013
|
+
if (slicedTupleType) {
|
5014
|
+
return { type: slicedTupleType };
|
4986
5015
|
}
|
4987
5016
|
}
|
4988
5017
|
}
|
@@ -5102,6 +5131,51 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5102
5131
|
isIncomplete: !!callResult.isTypeIncomplete,
|
5103
5132
|
};
|
5104
5133
|
}
|
5134
|
+
// Given a tuple type and a slice expression, determines the resulting
|
5135
|
+
// type if it can be determined. If not, it returns undefined.
|
5136
|
+
function getSlicedTupleType(tupleType, sliceNode) {
|
5137
|
+
// We don't handle step values.
|
5138
|
+
if (sliceNode.stepValue || !tupleType.tupleTypeArguments) {
|
5139
|
+
return undefined;
|
5140
|
+
}
|
5141
|
+
const tupleTypeArgs = tupleType.tupleTypeArguments;
|
5142
|
+
const startValue = getTupleSliceParameter(sliceNode.startValue, 0, tupleTypeArgs);
|
5143
|
+
const endValue = getTupleSliceParameter(sliceNode.endValue, tupleTypeArgs.length, tupleTypeArgs);
|
5144
|
+
if (startValue === undefined || endValue === undefined || endValue < startValue) {
|
5145
|
+
return undefined;
|
5146
|
+
}
|
5147
|
+
const slicedTypeArgs = tupleTypeArgs.slice(startValue, endValue);
|
5148
|
+
return types_1.ClassType.cloneAsInstance((0, typeUtils_1.specializeTupleClass)(tupleType, slicedTypeArgs));
|
5149
|
+
}
|
5150
|
+
function getTupleSliceParameter(expression, defaultValue, tupleTypeArgs) {
|
5151
|
+
let value = defaultValue;
|
5152
|
+
if (expression) {
|
5153
|
+
const valType = getTypeOfExpression(expression).type;
|
5154
|
+
if (!(0, types_1.isClassInstance)(valType) || !types_1.ClassType.isBuiltIn(valType, 'int') || !(0, typeUtils_1.isLiteralType)(valType)) {
|
5155
|
+
return undefined;
|
5156
|
+
}
|
5157
|
+
value = valType.literalValue;
|
5158
|
+
const unboundedIndex = tupleTypeArgs.findIndex((typeArg) => typeArg.isUnbounded || (0, types_1.isVariadicTypeVar)(typeArg.type));
|
5159
|
+
if (value < 0) {
|
5160
|
+
value = tupleTypeArgs.length + value;
|
5161
|
+
if (value < 0) {
|
5162
|
+
return undefined;
|
5163
|
+
}
|
5164
|
+
else if (unboundedIndex >= 0 && value <= unboundedIndex) {
|
5165
|
+
return undefined;
|
5166
|
+
}
|
5167
|
+
}
|
5168
|
+
else {
|
5169
|
+
if (value > tupleTypeArgs.length) {
|
5170
|
+
return undefined;
|
5171
|
+
}
|
5172
|
+
else if (unboundedIndex >= 0 && value > unboundedIndex) {
|
5173
|
+
return undefined;
|
5174
|
+
}
|
5175
|
+
}
|
5176
|
+
}
|
5177
|
+
return value;
|
5178
|
+
}
|
5105
5179
|
function getTypeArgs(node, flags, options) {
|
5106
5180
|
const typeArgs = [];
|
5107
5181
|
let adjFlags = flags;
|
@@ -5117,7 +5191,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5117
5191
|
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass)) {
|
5118
5192
|
adjFlags |= 131072 /* EvaluatorFlags.DisallowClassVar */ | 16 /* EvaluatorFlags.DisallowFinal */;
|
5119
5193
|
}
|
5120
|
-
adjFlags |= 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */;
|
5194
|
+
adjFlags |= 2097152 /* EvaluatorFlags.AllowUnpackedTupleOrTypeVarTuple */ | 134217728 /* EvaluatorFlags.AllowConcatenate */;
|
5121
5195
|
}
|
5122
5196
|
// Create a local function that validates a single type argument.
|
5123
5197
|
const getTypeArgTypeResult = (expr, argIndex) => {
|
@@ -5173,13 +5247,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5173
5247
|
const typeResult = getTypeArgTypeResult(arg.valueExpression, index);
|
5174
5248
|
if (arg.argumentCategory !== 0 /* ArgumentCategory.Simple */) {
|
5175
5249
|
if (arg.argumentCategory === 1 /* ArgumentCategory.UnpackedList */) {
|
5176
|
-
if ((0
|
5177
|
-
|
5178
|
-
|
5179
|
-
|
5180
|
-
|
5181
|
-
|
5182
|
-
|
5250
|
+
if (!(options === null || options === void 0 ? void 0 : options.isAnnotatedClass) || index === 0) {
|
5251
|
+
if ((0, types_1.isVariadicTypeVar)(typeResult.type) && !typeResult.type.isVariadicUnpacked) {
|
5252
|
+
typeResult.type = types_1.TypeVarType.cloneForUnpacked(typeResult.type);
|
5253
|
+
}
|
5254
|
+
else if ((0, types_1.isInstantiableClass)(typeResult.type) &&
|
5255
|
+
!typeResult.type.includeSubclasses &&
|
5256
|
+
(0, typeUtils_1.isTupleClass)(typeResult.type)) {
|
5257
|
+
typeResult.type = types_1.ClassType.cloneForUnpacked(typeResult.type);
|
5258
|
+
}
|
5259
|
+
else {
|
5260
|
+
addError(localize_1.Localizer.Diagnostic.unpackNotAllowed(), arg.valueExpression);
|
5261
|
+
}
|
5183
5262
|
}
|
5184
5263
|
}
|
5185
5264
|
}
|
@@ -5422,7 +5501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5422
5501
|
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5423
5502
|
}
|
5424
5503
|
else {
|
5425
|
-
baseTypeResult = getTypeOfExpression(node.leftExpression,
|
5504
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */ | (flags & 4 /* EvaluatorFlags.AllowForwardReferences */));
|
5426
5505
|
}
|
5427
5506
|
const argList = ParseTreeUtils.getArgumentsByRuntimeOrder(node).map((arg) => {
|
5428
5507
|
const functionArg = {
|
@@ -5553,7 +5632,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5553
5632
|
}
|
5554
5633
|
}
|
5555
5634
|
function getLambdaType() {
|
5556
|
-
return getTypeOfExpression(node.leftExpression,
|
5635
|
+
return getTypeOfExpression(node.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5557
5636
|
}
|
5558
5637
|
// If one or more of the arguments are incomplete, use speculative mode
|
5559
5638
|
// for the lambda evaluation because it may need to be reevaluated once
|
@@ -5563,7 +5642,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5563
5642
|
: getLambdaType();
|
5564
5643
|
// If bidirectional type inference failed, use normal type inference instead.
|
5565
5644
|
if (typeResult.typeErrors) {
|
5566
|
-
typeResult = getTypeOfExpression(node.leftExpression,
|
5645
|
+
typeResult = getTypeOfExpression(node.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */);
|
5567
5646
|
}
|
5568
5647
|
return typeResult;
|
5569
5648
|
}
|
@@ -5836,9 +5915,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5836
5915
|
resultType = types_1.UnknownType.create();
|
5837
5916
|
}
|
5838
5917
|
return {
|
5839
|
-
type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(resultType) : resultType,
|
5918
|
+
type: resultIsInstance ? (0, typeUtils_1.convertToInstance)(resultType, /* includeSubclasses */ false) : resultType,
|
5840
5919
|
bindToSelfType: bindToType
|
5841
|
-
? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(bindToType, /*
|
5920
|
+
? types_1.TypeBase.cloneForCondition((0, typeUtils_1.synthesizeTypeVarForSelfCls)(types_1.ClassType.cloneIncludeSubclasses(bindToType, /* includeSubclasses */ false),
|
5921
|
+
/* isClsParam */ false), bindToType.condition)
|
5842
5922
|
: undefined,
|
5843
5923
|
};
|
5844
5924
|
}
|
@@ -6334,7 +6414,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6334
6414
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6335
6415
|
}
|
6336
6416
|
recursionCount++;
|
6337
|
-
|
6417
|
+
// Special forms are not callable.
|
6418
|
+
if (callTypeResult.type.specialForm) {
|
6338
6419
|
const exprNode = errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode;
|
6339
6420
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
|
6340
6421
|
type: printType(callTypeResult.type, { expandTypeAlias: true }),
|
@@ -6430,18 +6511,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6430
6511
|
}), errorNode);
|
6431
6512
|
return { returnType: undefined, argumentErrors: true };
|
6432
6513
|
}
|
6433
|
-
// Check for an attempt to invoke an abstract static or class method.
|
6434
|
-
if (expandedCallType.boundToType &&
|
6435
|
-
(0, types_1.isInstantiableClass)(expandedCallType.boundToType) &&
|
6436
|
-
!expandedCallType.boundToType.includeSubclasses) {
|
6437
|
-
if (types_1.FunctionType.isAbstractMethod(expandedCallType)) {
|
6438
|
-
if (types_1.FunctionType.isStaticMethod(expandedCallType) || types_1.FunctionType.isClassMethod(expandedCallType)) {
|
6439
|
-
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.abstractMethodInvocation().format({
|
6440
|
-
method: expandedCallType.details.name,
|
6441
|
-
}), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
|
6442
|
-
}
|
6443
|
-
}
|
6444
|
-
}
|
6445
6514
|
let effectiveTypeVarContext = typeVarContext;
|
6446
6515
|
if (!effectiveTypeVarContext) {
|
6447
6516
|
// If a typeVarContext wasn't provided by the caller, allocate one here.
|
@@ -6494,6 +6563,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6494
6563
|
specializedInitSelfType: functionResult.specializedInitSelfType,
|
6495
6564
|
};
|
6496
6565
|
}
|
6566
|
+
function isMethodUnimplementedAbstract(functionType) {
|
6567
|
+
let isAbstract = false;
|
6568
|
+
// If the function is part of a protocol, it's automatically considered abstract
|
6569
|
+
// unless it's located in a stub, in which case it must be explicitly marked as
|
6570
|
+
// abstract.
|
6571
|
+
if (types_1.FunctionType.isAbstractMethod(functionType)) {
|
6572
|
+
isAbstract = true;
|
6573
|
+
}
|
6574
|
+
else if (functionType.details.methodClass &&
|
6575
|
+
types_1.ClassType.isProtocolClass(functionType.details.methodClass) &&
|
6576
|
+
functionType.details.declaration &&
|
6577
|
+
!AnalyzerNodeInfo.getFileInfo(functionType.details.declaration.node).isStubFile) {
|
6578
|
+
isAbstract = true;
|
6579
|
+
}
|
6580
|
+
if (!isAbstract) {
|
6581
|
+
return false;
|
6582
|
+
}
|
6583
|
+
// Determine if the method is unimplemented by looking at whether its
|
6584
|
+
// body contains a "trivial" implementation.
|
6585
|
+
let implementation = functionType;
|
6586
|
+
// If this is an overloaded method, consider the implementation.
|
6587
|
+
if (functionType.overloaded) {
|
6588
|
+
implementation = types_1.OverloadedFunctionType.getImplementation(functionType.overloaded);
|
6589
|
+
// If there is no implementation and it's in a stub file, assume it's not abstract.
|
6590
|
+
if (!implementation) {
|
6591
|
+
return (functionType.details.declaration !== undefined &&
|
6592
|
+
!AnalyzerNodeInfo.getFileInfo(functionType.details.declaration.node).isStubFile);
|
6593
|
+
}
|
6594
|
+
}
|
6595
|
+
if (!implementation.details.declaration) {
|
6596
|
+
return false;
|
6597
|
+
}
|
6598
|
+
const decl = implementation.details.declaration;
|
6599
|
+
return ParseTreeUtils.isSuiteEmpty(decl.node.suite) || methodAlwaysRaisesNotImplemented(decl);
|
6600
|
+
}
|
6497
6601
|
function validateCallForOverloadedFunction(errorNode, argList, expandedCallType, isCallTypeIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext) {
|
6498
6602
|
var _a, _b;
|
6499
6603
|
// Handle the 'cast' call as a special case.
|
@@ -6610,14 +6714,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6610
6714
|
if (className === 'NewType') {
|
6611
6715
|
return { returnType: createNewType(errorNode, argList) };
|
6612
6716
|
}
|
6613
|
-
if (
|
6614
|
-
className === 'Generic' ||
|
6615
|
-
className === 'Callable' ||
|
6616
|
-
className === 'Concatenate' ||
|
6617
|
-
className === 'Type') {
|
6717
|
+
if (types_1.ClassType.isSpecialFormClass(expandedCallType)) {
|
6618
6718
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
6619
6719
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeNotIntantiable().format({ type: className }), errorNode);
|
6620
|
-
return { returnType: types_1.
|
6720
|
+
return { returnType: types_1.UnknownType.create(), argumentErrors: true };
|
6621
6721
|
}
|
6622
6722
|
if ((0, types_1.isClass)(unexpandedCallType) && (0, enums_1.isKnownEnumType)(className)) {
|
6623
6723
|
return {
|
@@ -7727,6 +7827,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7727
7827
|
let specializedInitSelfType;
|
7728
7828
|
let anyOrUnknownArgument;
|
7729
7829
|
const typeCondition = (0, typeUtils_1.getTypeCondition)(type);
|
7830
|
+
// Check for an attempt to invoke an unimplemented abstract method.
|
7831
|
+
if (type.boundToType && !type.boundToType.includeSubclasses && isMethodUnimplementedAbstract(type)) {
|
7832
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.abstractMethodInvocation().format({
|
7833
|
+
method: type.details.name,
|
7834
|
+
}), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
|
7835
|
+
}
|
7730
7836
|
if (type.boundTypeVarScopeId) {
|
7731
7837
|
// If the function was bound to a class or object and was a constructor, a
|
7732
7838
|
// static method or a class method, it's possible that some of that class's
|
@@ -8211,8 +8317,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8211
8317
|
? 512 /* EvaluatorFlags.AllowMissingTypeArgs */ |
|
8212
8318
|
8 /* EvaluatorFlags.EvaluateStringLiteralAsType */ |
|
8213
8319
|
32 /* EvaluatorFlags.DisallowParamSpec */ |
|
8214
|
-
64 /* EvaluatorFlags.DisallowTypeVarTuple */
|
8215
|
-
16777216 /* EvaluatorFlags.TreatPep695TypeAliasAsObject */
|
8320
|
+
64 /* EvaluatorFlags.DisallowTypeVarTuple */
|
8216
8321
|
: 2 /* EvaluatorFlags.DoNotSpecialize */;
|
8217
8322
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
8218
8323
|
argType = exprTypeResult.type;
|
@@ -8331,8 +8436,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8331
8436
|
}
|
8332
8437
|
}
|
8333
8438
|
}
|
8439
|
+
let assignTypeFlags = skipSolveTypeVars ? 8 /* AssignTypeFlags.SkipSolveTypeVars */ : 0 /* AssignTypeFlags.Default */;
|
8440
|
+
if (argParam.isinstanceParam) {
|
8441
|
+
assignTypeFlags |= 32768 /* AssignTypeFlags.AllowIsinstanceSpecialForms */;
|
8442
|
+
}
|
8334
8443
|
if (!assignType(argParam.paramType, argType, diag.createAddendum(), typeVarContext,
|
8335
|
-
/* srcTypeVarContext */ undefined,
|
8444
|
+
/* srcTypeVarContext */ undefined, assignTypeFlags)) {
|
8336
8445
|
// Mismatching parameter types are common in untyped code; don't bother spending time
|
8337
8446
|
// printing types if the diagnostic is disabled.
|
8338
8447
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(argParam.errorNode);
|
@@ -8593,6 +8702,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8593
8702
|
addError(localize_1.Localizer.Diagnostic.typeVarTupleUnknownParam().format({ name: ((_a = argList[i].name) === null || _a === void 0 ? void 0 : _a.value) || '?' }), ((_b = argList[i].node) === null || _b === void 0 ? void 0 : _b.name) || argList[i].valueExpression || errorNode);
|
8594
8703
|
}
|
8595
8704
|
}
|
8705
|
+
else {
|
8706
|
+
addError(localize_1.Localizer.Diagnostic.typeVarTupleConstraints(), argList[i].valueExpression || errorNode);
|
8707
|
+
}
|
8596
8708
|
}
|
8597
8709
|
return typeVar;
|
8598
8710
|
}
|
@@ -8653,7 +8765,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8653
8765
|
}
|
8654
8766
|
function getParamSpecDefaultType(node) {
|
8655
8767
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */ | 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
8656
|
-
types_1.TypeBase.setSpecialForm(functionType);
|
8657
8768
|
if (node.nodeType === 18 /* ParseNodeType.Ellipsis */) {
|
8658
8769
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8659
8770
|
return functionType;
|
@@ -8669,6 +8780,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8669
8780
|
type: (0, typeUtils_1.convertToInstance)(typeResult.type),
|
8670
8781
|
});
|
8671
8782
|
});
|
8783
|
+
if (node.entries.length > 0) {
|
8784
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
8785
|
+
}
|
8672
8786
|
// Update the type cache so we don't attempt to re-evaluate this node.
|
8673
8787
|
// The type doesn't matter, so use Any.
|
8674
8788
|
writeTypeCache(node, { type: types_1.AnyType.create() }, /* flags */ undefined);
|
@@ -8686,7 +8800,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8686
8800
|
functionType.details.paramSpec = typeResult.type;
|
8687
8801
|
return functionType;
|
8688
8802
|
}
|
8689
|
-
if ((0, types_1.isClassInstance)(typeResult.type) &&
|
8803
|
+
if ((0, types_1.isClassInstance)(typeResult.type) &&
|
8804
|
+
types_1.ClassType.isBuiltIn(typeResult.type, ['EllipsisType', 'ellipsis'])) {
|
8690
8805
|
types_1.FunctionType.addDefaultParameters(functionType);
|
8691
8806
|
return functionType;
|
8692
8807
|
}
|
@@ -8842,17 +8957,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8842
8957
|
isBaseClassAny = true;
|
8843
8958
|
}
|
8844
8959
|
if (!(0, types_1.isInstantiableClass)(baseClass)) {
|
8845
|
-
|
8960
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeNotAClass(), argList[1].node || errorNode);
|
8846
8961
|
return undefined;
|
8847
8962
|
}
|
8848
8963
|
if (types_1.ClassType.isProtocolClass(baseClass) || types_1.ClassType.isTypedDictClass(baseClass)) {
|
8849
|
-
|
8964
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeProtocolClass(), argList[1].node || errorNode);
|
8850
8965
|
}
|
8851
8966
|
else if (baseClass.literalValue !== undefined) {
|
8852
|
-
|
8853
|
-
}
|
8854
|
-
else if (types_1.ClassType.isNewTypeClass(baseClass)) {
|
8855
|
-
addError(localize_1.Localizer.Diagnostic.newTypeNewTypeClass(), argList[1].node || errorNode);
|
8967
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeLiteral(), argList[1].node || errorNode);
|
8856
8968
|
}
|
8857
8969
|
let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
|
8858
8970
|
classFlags |= 4096 /* ClassTypeFlags.Final */ | 268435456 /* ClassTypeFlags.NewTypeClass */ | 536870912 /* ClassTypeFlags.ValidTypeAliasClass */;
|
@@ -9786,9 +9898,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9786
9898
|
// or the final expression contain an "await" operator anywhere within
|
9787
9899
|
// the expression, it is treated as an async generator.
|
9788
9900
|
let isAsync = node.forIfNodes.some((comp) => {
|
9789
|
-
|
9790
|
-
|
9791
|
-
|
9901
|
+
if (comp.nodeType === 33 /* ParseNodeType.ListComprehensionFor */ && comp.isAsync) {
|
9902
|
+
return true;
|
9903
|
+
}
|
9904
|
+
return ParseTreeUtils.containsAwaitNode(comp);
|
9792
9905
|
});
|
9793
9906
|
let type = types_1.UnknownType.create();
|
9794
9907
|
if (ParseTreeUtils.containsAwaitNode(node.expression)) {
|
@@ -9803,14 +9916,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9803
9916
|
typeErrors = true;
|
9804
9917
|
}
|
9805
9918
|
const elementType = elementTypeResult.type;
|
9806
|
-
// Handle the special case where a generator function (e.g. `(await x for x in y)`)
|
9807
|
-
// is expected to be an AsyncGenerator.
|
9808
|
-
if (!isAsync &&
|
9809
|
-
inferenceContext &&
|
9810
|
-
(0, types_1.isClassInstance)(inferenceContext.expectedType) &&
|
9811
|
-
types_1.ClassType.isBuiltIn(inferenceContext.expectedType, 'AsyncGenerator')) {
|
9812
|
-
isAsync = true;
|
9813
|
-
}
|
9814
9919
|
const builtInIteratorType = getTypingType(node, isAsync ? 'AsyncGenerator' : 'Generator');
|
9815
9920
|
if (builtInIteratorType && (0, types_1.isInstantiableClass)(builtInIteratorType)) {
|
9816
9921
|
type = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForSpecialization(builtInIteratorType, isAsync ? [elementType, getNoneType()] : [elementType, getNoneType(), getNoneType()],
|
@@ -9997,9 +10102,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9997
10102
|
// to two arguments.The first argument, if present, should be an ellipsis,
|
9998
10103
|
// a ParamSpec, a Concatenate, or a list of positional parameter types.
|
9999
10104
|
// The second argument, if present, should specify the return type.
|
10000
|
-
function createCallableType(typeArgs, errorNode) {
|
10105
|
+
function createCallableType(classType, typeArgs, errorNode) {
|
10001
10106
|
const functionType = types_1.FunctionType.createInstantiable(0 /* FunctionTypeFlags.None */);
|
10002
|
-
|
10107
|
+
functionType.specialForm = classType;
|
10003
10108
|
functionType.details.declaredReturnType = types_1.UnknownType.create();
|
10004
10109
|
functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(errorNode);
|
10005
10110
|
if (typeArgs && typeArgs.length > 0) {
|
@@ -10132,9 +10237,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10132
10237
|
addExpectedClassDiagnostic(typeArg0Type, typeArgs[0].node);
|
10133
10238
|
typeArg0Type = types_1.UnknownType.create();
|
10134
10239
|
}
|
10135
|
-
|
10136
|
-
if ((0, types_1.
|
10137
|
-
types_1.TypeBase.
|
10240
|
+
let optionalType = (0, types_1.combineTypes)([typeArg0Type, noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create()]);
|
10241
|
+
if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
|
10242
|
+
optionalType = types_1.TypeBase.cloneAsSpecialForm(optionalType, unionClassType);
|
10138
10243
|
}
|
10139
10244
|
return optionalType;
|
10140
10245
|
}
|
@@ -10145,15 +10250,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10145
10250
|
}
|
10146
10251
|
return types_1.UnknownType.create();
|
10147
10252
|
}
|
10148
|
-
function cloneBuiltinClassWithLiteral(node, builtInName, value) {
|
10253
|
+
function cloneBuiltinClassWithLiteral(node, literalClassType, builtInName, value) {
|
10149
10254
|
const type = getBuiltInType(node, builtInName);
|
10150
10255
|
if ((0, types_1.isInstantiableClass)(type)) {
|
10151
|
-
|
10256
|
+
const literalType = types_1.ClassType.cloneWithLiteral(type, value);
|
10257
|
+
literalType.specialForm = literalClassType;
|
10258
|
+
return literalType;
|
10152
10259
|
}
|
10153
10260
|
return types_1.UnknownType.create();
|
10154
10261
|
}
|
10155
10262
|
// Creates a type that represents a Literal.
|
10156
|
-
function createLiteralType(node, flags) {
|
10263
|
+
function createLiteralType(classType, node, flags) {
|
10157
10264
|
if (node.items.length === 0) {
|
10158
10265
|
addError(localize_1.Localizer.Diagnostic.literalEmptyArgs(), node.baseExpression);
|
10159
10266
|
return types_1.UnknownType.create();
|
@@ -10176,33 +10283,36 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10176
10283
|
const isBytes = (itemExpr.strings[0].token.flags & 32 /* StringTokenFlags.Bytes */) !== 0;
|
10177
10284
|
const value = itemExpr.strings.map((s) => s.value).join('');
|
10178
10285
|
if (isBytes) {
|
10179
|
-
type = cloneBuiltinClassWithLiteral(node, 'bytes', value);
|
10286
|
+
type = cloneBuiltinClassWithLiteral(node, classType, 'bytes', value);
|
10180
10287
|
}
|
10181
10288
|
else {
|
10182
|
-
type = cloneBuiltinClassWithLiteral(node, 'str', value);
|
10289
|
+
type = cloneBuiltinClassWithLiteral(node, classType, 'str', value);
|
10183
10290
|
}
|
10184
10291
|
}
|
10185
10292
|
else if (itemExpr.nodeType === 40 /* ParseNodeType.Number */) {
|
10186
10293
|
if (!itemExpr.isImaginary && itemExpr.isInteger) {
|
10187
|
-
type = cloneBuiltinClassWithLiteral(node, 'int', itemExpr.value);
|
10294
|
+
type = cloneBuiltinClassWithLiteral(node, classType, 'int', itemExpr.value);
|
10188
10295
|
}
|
10189
10296
|
}
|
10190
10297
|
else if (itemExpr.nodeType === 11 /* ParseNodeType.Constant */) {
|
10191
10298
|
if (itemExpr.constType === 33 /* KeywordType.True */) {
|
10192
|
-
type = cloneBuiltinClassWithLiteral(node, 'bool', true);
|
10299
|
+
type = cloneBuiltinClassWithLiteral(node, classType, 'bool', true);
|
10193
10300
|
}
|
10194
10301
|
else if (itemExpr.constType === 15 /* KeywordType.False */) {
|
10195
|
-
type = cloneBuiltinClassWithLiteral(node, 'bool', false);
|
10302
|
+
type = cloneBuiltinClassWithLiteral(node, classType, 'bool', false);
|
10196
10303
|
}
|
10197
10304
|
else if (itemExpr.constType === 26 /* KeywordType.None */) {
|
10198
10305
|
type = noneClassType !== null && noneClassType !== void 0 ? noneClassType : types_1.UnknownType.create();
|
10199
10306
|
}
|
10200
10307
|
}
|
10201
|
-
else if (itemExpr.nodeType === 55 /* ParseNodeType.UnaryOperation */
|
10202
|
-
itemExpr.operator === 33 /* OperatorType.Subtract */) {
|
10203
|
-
|
10204
|
-
|
10205
|
-
|
10308
|
+
else if (itemExpr.nodeType === 55 /* ParseNodeType.UnaryOperation */) {
|
10309
|
+
if (itemExpr.operator === 33 /* OperatorType.Subtract */ || itemExpr.operator === 0 /* OperatorType.Add */) {
|
10310
|
+
if (itemExpr.expression.nodeType === 40 /* ParseNodeType.Number */) {
|
10311
|
+
if (!itemExpr.expression.isImaginary && itemExpr.expression.isInteger) {
|
10312
|
+
type = cloneBuiltinClassWithLiteral(node, classType, 'int', itemExpr.operator === 33 /* OperatorType.Subtract */
|
10313
|
+
? -itemExpr.expression.value
|
10314
|
+
: itemExpr.expression.value);
|
10315
|
+
}
|
10206
10316
|
}
|
10207
10317
|
}
|
10208
10318
|
}
|
@@ -10451,7 +10561,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10451
10561
|
}
|
10452
10562
|
return typeArgs[0].type;
|
10453
10563
|
}
|
10454
|
-
function createConcatenateType(errorNode, classType, typeArgs) {
|
10564
|
+
function createConcatenateType(errorNode, classType, typeArgs, flags) {
|
10565
|
+
if ((flags & 134217728 /* EvaluatorFlags.AllowConcatenate */) === 0) {
|
10566
|
+
addError(localize_1.Localizer.Diagnostic.concatenateContext(), errorNode);
|
10567
|
+
return types_1.AnyType.create();
|
10568
|
+
}
|
10455
10569
|
if (!typeArgs || typeArgs.length === 0) {
|
10456
10570
|
addError(localize_1.Localizer.Diagnostic.concatenateTypeArgsMissing(), errorNode);
|
10457
10571
|
}
|
@@ -10497,7 +10611,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10497
10611
|
// Creates one of several "special" types that are defined in typing.pyi
|
10498
10612
|
// but not declared in their entirety. This includes the likes of "Tuple",
|
10499
10613
|
// "Dict", etc.
|
10500
|
-
function createSpecialType(classType, typeArgs, paramLimit, allowParamSpec = false,
|
10614
|
+
function createSpecialType(classType, typeArgs, paramLimit, allowParamSpec = false, isSpecialForm = true) {
|
10501
10615
|
const isTupleTypeParam = types_1.ClassType.isTupleClass(classType);
|
10502
10616
|
if (typeArgs) {
|
10503
10617
|
if (isTupleTypeParam && typeArgs.length === 1 && typeArgs[0].isEmptyTupleShorthand) {
|
@@ -10601,14 +10715,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10601
10715
|
else {
|
10602
10716
|
returnType = types_1.ClassType.cloneForSpecialization(classType, typeArgTypes, typeArgs !== undefined);
|
10603
10717
|
}
|
10604
|
-
if (
|
10605
|
-
types_1.TypeBase.
|
10718
|
+
if (isSpecialForm) {
|
10719
|
+
returnType = types_1.TypeBase.cloneAsSpecialForm(returnType, classType);
|
10606
10720
|
}
|
10607
10721
|
return returnType;
|
10608
10722
|
}
|
10609
10723
|
// Unpacks the index expression for a "Union[X, Y, Z]" type annotation.
|
10610
10724
|
function createUnionType(classType, errorNode, typeArgs, flags) {
|
10725
|
+
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
10611
10726
|
const types = [];
|
10727
|
+
let allowSingleTypeArg = false;
|
10612
10728
|
if (!typeArgs) {
|
10613
10729
|
// If no type arguments are provided, the resulting type
|
10614
10730
|
// depends on whether we're evaluating a type annotation or
|
@@ -10630,15 +10746,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10630
10746
|
}
|
10631
10747
|
// If this is an unpacked tuple, explode out the individual items.
|
10632
10748
|
if ((0, types_1.isUnpackedClass)(typeArg.type) && typeArg.type.tupleTypeArguments) {
|
10633
|
-
|
10634
|
-
|
10635
|
-
|
10749
|
+
if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
|
10750
|
+
typeArg.type.tupleTypeArguments.forEach((tupleTypeArg) => {
|
10751
|
+
types.push((0, typeUtils_1.convertToInstantiable)(tupleTypeArg.type));
|
10752
|
+
});
|
10753
|
+
allowSingleTypeArg = true;
|
10754
|
+
}
|
10755
|
+
else {
|
10756
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unionUnpackedTuple(), errorNode);
|
10757
|
+
types.push(types_1.UnknownType.create());
|
10758
|
+
}
|
10636
10759
|
}
|
10637
10760
|
else {
|
10638
|
-
// If this is an unpacked TypeVar, note that it is in a union so we can differentiate
|
10639
|
-
// between Unpack[Vs] and Union[Unpack[Vs]].
|
10640
10761
|
if ((0, types_1.isTypeVar)(typeArgType) && (0, types_1.isUnpackedVariadicTypeVar)(typeArgType)) {
|
10641
|
-
|
10762
|
+
if (fileInfo.diagnosticRuleSet.enableExperimentalFeatures) {
|
10763
|
+
// If this is an unpacked TypeVar, note that it is in a union so we can
|
10764
|
+
// differentiate between Unpack[Vs] and Union[Unpack[Vs]].
|
10765
|
+
typeArgType = types_1.TypeVarType.cloneForUnpacked(typeArgType, /* isInUnion */ true);
|
10766
|
+
allowSingleTypeArg = true;
|
10767
|
+
}
|
10768
|
+
else {
|
10769
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unionUnpackedTypeVarTuple(), errorNode);
|
10770
|
+
typeArgType = types_1.UnknownType.create();
|
10771
|
+
}
|
10642
10772
|
}
|
10643
10773
|
types.push(typeArgType);
|
10644
10774
|
}
|
@@ -10646,14 +10776,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10646
10776
|
// Validate that we received at least two type arguments. One type argument
|
10647
10777
|
// is allowed if it's an unpacked variadic type var or tuple. None is also allowed
|
10648
10778
|
// since it is used to define NoReturn in typeshed stubs).
|
10649
|
-
if (types.length === 1) {
|
10650
|
-
|
10651
|
-
addError(localize_1.Localizer.Diagnostic.unionTypeArgCount(), errorNode);
|
10652
|
-
}
|
10779
|
+
if (types.length === 1 && !allowSingleTypeArg && !(0, typeUtils_1.isNoneInstance)(types[0])) {
|
10780
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.unionTypeArgCount(), errorNode);
|
10653
10781
|
}
|
10654
|
-
|
10655
|
-
if ((0, types_1.
|
10656
|
-
types_1.TypeBase.
|
10782
|
+
let unionType = (0, types_1.combineTypes)(types);
|
10783
|
+
if (unionClassType && (0, types_1.isInstantiableClass)(unionClassType)) {
|
10784
|
+
unionType = types_1.TypeBase.cloneAsSpecialForm(unionType, unionClassType);
|
10657
10785
|
}
|
10658
10786
|
return unionType;
|
10659
10787
|
}
|
@@ -10744,11 +10872,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10744
10872
|
}
|
10745
10873
|
}
|
10746
10874
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(name);
|
10747
|
-
|
10875
|
+
let typeAlias = types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), fileInfo.moduleName, fileInfo.fileUri, typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
|
10748
10876
|
// All PEP 695 type aliases are special forms because they are
|
10749
10877
|
// TypeAliasType objects at runtime.
|
10750
10878
|
if (isPep695Syntax || isPep695TypeVarType) {
|
10751
|
-
|
10879
|
+
const typeAliasTypeClass = getTypingType(errorNode, 'TypeAliasType');
|
10880
|
+
if (typeAliasTypeClass && (0, types_1.isInstantiableClass)(typeAliasTypeClass)) {
|
10881
|
+
typeAlias = types_1.TypeBase.cloneAsSpecialForm(typeAlias, typeAliasTypeClass);
|
10882
|
+
}
|
10752
10883
|
}
|
10753
10884
|
return typeAlias;
|
10754
10885
|
}
|
@@ -10759,6 +10890,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10759
10890
|
/* typeSourceId */ 0,
|
10760
10891
|
/* declaredMetaclass */ undefined,
|
10761
10892
|
/* effectiveMetaclass */ undefined);
|
10893
|
+
if (aliasMapEntry.isSpecialForm) {
|
10894
|
+
specialClassType.details.flags |= 1073741824 /* ClassTypeFlags.SpecialFormClass */;
|
10895
|
+
}
|
10762
10896
|
const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
|
10763
10897
|
specialClassType.details.declaration = specialBuiltInClassDeclaration;
|
10764
10898
|
if (fileInfo.isTypingExtensionsStubFile) {
|
@@ -10816,28 +10950,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10816
10950
|
const assignedName = nameNode.value;
|
10817
10951
|
const specialTypes = new Map([
|
10818
10952
|
['Tuple', { alias: 'tuple', module: 'builtins' }],
|
10819
|
-
['Generic', { alias: '', module: 'builtins' }],
|
10820
|
-
['Protocol', { alias: '', module: 'builtins' }],
|
10821
|
-
['Callable', { alias: '', module: 'builtins' }],
|
10953
|
+
['Generic', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10954
|
+
['Protocol', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10955
|
+
['Callable', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10822
10956
|
['Type', { alias: 'type', module: 'builtins' }],
|
10823
|
-
['ClassVar', { alias: '', module: 'builtins' }],
|
10824
|
-
['Final', { alias: '', module: 'builtins' }],
|
10825
|
-
['Literal', { alias: '', module: 'builtins' }],
|
10957
|
+
['ClassVar', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10958
|
+
['Final', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10959
|
+
['Literal', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10826
10960
|
['TypedDict', { alias: '_TypedDict', module: 'self' }],
|
10827
|
-
['Union', { alias: '', module: 'builtins' }],
|
10828
|
-
['Optional', { alias: '', module: 'builtins' }],
|
10829
|
-
['Annotated', { alias: '', module: 'builtins' }],
|
10830
|
-
['TypeAlias', { alias: '', module: 'builtins' }],
|
10831
|
-
['Concatenate', { alias: '', module: 'builtins' }],
|
10832
|
-
['TypeGuard', { alias: '', module: 'builtins' }],
|
10833
|
-
['Unpack', { alias: '', module: 'builtins' }],
|
10834
|
-
['Required', { alias: '', module: 'builtins' }],
|
10835
|
-
['NotRequired', { alias: '', module: 'builtins' }],
|
10836
|
-
['Self', { alias: '', module: 'builtins' }],
|
10837
|
-
['NoReturn', { alias: '', module: 'builtins' }],
|
10838
|
-
['Never', { alias: '', module: 'builtins' }],
|
10839
|
-
['LiteralString', { alias: '', module: 'builtins' }],
|
10840
|
-
['ReadOnly', { alias: '', module: 'builtins' }],
|
10961
|
+
['Union', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10962
|
+
['Optional', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10963
|
+
['Annotated', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10964
|
+
['TypeAlias', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10965
|
+
['Concatenate', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10966
|
+
['TypeGuard', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10967
|
+
['Unpack', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10968
|
+
['Required', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10969
|
+
['NotRequired', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10970
|
+
['Self', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10971
|
+
['NoReturn', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10972
|
+
['Never', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10973
|
+
['LiteralString', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10974
|
+
['ReadOnly', { alias: '', module: 'builtins', isSpecialForm: true }],
|
10841
10975
|
]);
|
10842
10976
|
const aliasMapEntry = specialTypes.get(assignedName);
|
10843
10977
|
if (aliasMapEntry) {
|
@@ -11005,7 +11139,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11005
11139
|
// only if the evaluated type is an instantiable type.
|
11006
11140
|
if (!isSpeculativeTypeAlias || isLegalImplicitTypeAliasType(rightHandType)) {
|
11007
11141
|
// If this is a type alias, record its name based on the assignment target.
|
11008
|
-
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode,
|
11142
|
+
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, typeAliasNameNode,
|
11009
11143
|
/* isPep695Syntax */ false,
|
11010
11144
|
/* isPep695TypeVarType */ false);
|
11011
11145
|
(0, debug_1.assert)(typeAliasTypeVar !== undefined);
|
@@ -11049,7 +11183,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11049
11183
|
callLeftNode.leftExpression.nodeType === 38 /* ParseNodeType.Name */)) {
|
11050
11184
|
// See if this is a call to TypedDict. We want to support
|
11051
11185
|
// recursive type references in a TypedDict call.
|
11052
|
-
const callType = getTypeOfExpression(callLeftNode,
|
11186
|
+
const callType = getTypeOfExpression(callLeftNode, 2 /* EvaluatorFlags.CallBaseDefaults */).type;
|
11053
11187
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
11054
11188
|
return true;
|
11055
11189
|
}
|
@@ -11106,7 +11240,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11106
11240
|
if (aliasTypeResult.isIncomplete) {
|
11107
11241
|
isIncomplete = true;
|
11108
11242
|
}
|
11109
|
-
aliasType = transformTypeForTypeAlias(aliasType, nameNode,
|
11243
|
+
aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
|
11110
11244
|
/* isPep695TypeVarType */ true, typeParameters, typeParamNodes);
|
11111
11245
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
11112
11246
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
@@ -11211,8 +11345,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11211
11345
|
262144 /* EvaluatorFlags.DisallowNakedGeneric */ |
|
11212
11346
|
2048 /* EvaluatorFlags.DisallowTypeVarsWithScopeId */ |
|
11213
11347
|
8192 /* EvaluatorFlags.AssociateTypeVarsWithCurrentScope */ |
|
11214
|
-
16384 /* EvaluatorFlags.EnforceTypeVarVarianceConsistency
|
11215
|
-
16777216 /* EvaluatorFlags.TreatPep695TypeAliasAsObject */;
|
11348
|
+
16384 /* EvaluatorFlags.EnforceTypeVarVarianceConsistency */;
|
11216
11349
|
if (fileInfo.isStubFile) {
|
11217
11350
|
exprFlags |= 4 /* EvaluatorFlags.AllowForwardReferences */;
|
11218
11351
|
}
|
@@ -11241,7 +11374,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11241
11374
|
}
|
11242
11375
|
// Any is allowed as a base class. Remove its "special form" flag to avoid
|
11243
11376
|
// false positive errors.
|
11244
|
-
if ((0, types_1.isAny)(argType) &&
|
11377
|
+
if ((0, types_1.isAny)(argType) && argType.specialForm) {
|
11245
11378
|
argType = types_1.AnyType.create();
|
11246
11379
|
}
|
11247
11380
|
if (!(0, types_1.isAnyOrUnknown)(argType) && !(0, types_1.isUnbound)(argType)) {
|
@@ -11296,6 +11429,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11296
11429
|
addError(localize_1.Localizer.Diagnostic.baseClassCircular(), arg);
|
11297
11430
|
argType = types_1.UnknownType.create();
|
11298
11431
|
}
|
11432
|
+
// If the class is attempting to derive from a TypeAliasType,
|
11433
|
+
// generate an error.
|
11434
|
+
if (argType.specialForm && types_1.ClassType.isBuiltIn(argType.specialForm, 'TypeAliasType')) {
|
11435
|
+
addError(localize_1.Localizer.Diagnostic.typeAliasTypeBaseClass(), arg);
|
11436
|
+
argType = types_1.UnknownType.create();
|
11437
|
+
}
|
11299
11438
|
}
|
11300
11439
|
}
|
11301
11440
|
if ((0, types_1.isUnknown)(argType)) {
|
@@ -13365,7 +13504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13365
13504
|
nodeToEvaluate = parent;
|
13366
13505
|
continue;
|
13367
13506
|
}
|
13368
|
-
flags =
|
13507
|
+
flags = 2 /* EvaluatorFlags.CallBaseDefaults */;
|
13369
13508
|
break;
|
13370
13509
|
}
|
13371
13510
|
}
|
@@ -13713,7 +13852,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13713
13852
|
const aliasedName = classType.aliasName || classType.details.name;
|
13714
13853
|
switch (aliasedName) {
|
13715
13854
|
case 'Callable': {
|
13716
|
-
return { type: createCallableType(typeArgs, errorNode) };
|
13855
|
+
return { type: createCallableType(classType, typeArgs, errorNode) };
|
13717
13856
|
}
|
13718
13857
|
case 'Never': {
|
13719
13858
|
if (typeArgs && typeArgs.length > 0) {
|
@@ -13731,7 +13870,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13731
13870
|
return { type: createOptionalType(classType, errorNode, typeArgs, flags) };
|
13732
13871
|
}
|
13733
13872
|
case 'Type': {
|
13734
|
-
let typeType = createSpecialType(classType, typeArgs, 1
|
13873
|
+
let typeType = createSpecialType(classType, typeArgs, 1,
|
13874
|
+
/* allowParamSpec */ undefined,
|
13875
|
+
/* isSpecialForm */ false);
|
13735
13876
|
if ((0, types_1.isInstantiableClass)(typeType)) {
|
13736
13877
|
typeType = (0, typeUtils_1.explodeGenericClass)(typeType);
|
13737
13878
|
}
|
@@ -13769,7 +13910,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13769
13910
|
break;
|
13770
13911
|
}
|
13771
13912
|
case 'Tuple': {
|
13772
|
-
return {
|
13913
|
+
return {
|
13914
|
+
type: createSpecialType(classType, typeArgs,
|
13915
|
+
/* paramLimit */ undefined,
|
13916
|
+
/* allowParamSpec */ false,
|
13917
|
+
/* isSpecialForm */ false),
|
13918
|
+
};
|
13773
13919
|
}
|
13774
13920
|
case 'Union': {
|
13775
13921
|
return { type: createUnionType(classType, errorNode, typeArgs, flags) };
|
@@ -13784,7 +13930,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13784
13930
|
return createAnnotatedType(errorNode, typeArgs);
|
13785
13931
|
}
|
13786
13932
|
case 'Concatenate': {
|
13787
|
-
return { type: createConcatenateType(errorNode, classType, typeArgs) };
|
13933
|
+
return { type: createConcatenateType(errorNode, classType, typeArgs, flags) };
|
13788
13934
|
}
|
13789
13935
|
case 'TypeGuard': {
|
13790
13936
|
return { type: createTypeGuardType(errorNode, classType, typeArgs, flags) };
|
@@ -13828,7 +13974,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13828
13974
|
if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
|
13829
13975
|
let typeType = createSpecialType(typeClassType, typeArgs, 1,
|
13830
13976
|
/* allowParamSpec */ undefined,
|
13831
|
-
/*
|
13977
|
+
/* isSpecialForm */ false);
|
13832
13978
|
if ((0, types_1.isInstantiableClass)(typeType)) {
|
13833
13979
|
typeType = (0, typeUtils_1.explodeGenericClass)(typeType);
|
13834
13980
|
}
|
@@ -13842,7 +13988,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13842
13988
|
type: createSpecialType(classType, typeArgs,
|
13843
13989
|
/* paramLimit */ undefined,
|
13844
13990
|
/* allowParamSpec */ undefined,
|
13845
|
-
/*
|
13991
|
+
/* isSpecialForm */ false),
|
13846
13992
|
};
|
13847
13993
|
}
|
13848
13994
|
}
|
@@ -13857,9 +14003,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13857
14003
|
const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
13858
14004
|
if (typeArgs) {
|
13859
14005
|
let minTypeArgCount = typeParameters.length;
|
13860
|
-
const
|
13861
|
-
if (
|
13862
|
-
minTypeArgCount =
|
14006
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.defaultType);
|
14007
|
+
if (firstDefaultParamIndex >= 0) {
|
14008
|
+
minTypeArgCount = firstDefaultParamIndex;
|
13863
14009
|
}
|
13864
14010
|
// Classes that accept inlined type dict type args allow only one.
|
13865
14011
|
if (typeArgs[0].inlinedTypeDict) {
|
@@ -13957,7 +14103,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13957
14103
|
if (typeParam.details.isParamSpec) {
|
13958
14104
|
const typeArg = typeArgs[index];
|
13959
14105
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
13960
|
-
types_1.TypeBase.setSpecialForm(functionType);
|
13961
14106
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
13962
14107
|
types_1.FunctionType.addDefaultParameters(functionType);
|
13963
14108
|
functionType.details.flags |= 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */;
|
@@ -13975,6 +14120,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13975
14120
|
hasDeclaredType: true,
|
13976
14121
|
});
|
13977
14122
|
});
|
14123
|
+
if (typeArg.typeList.length > 0) {
|
14124
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
14125
|
+
}
|
13978
14126
|
typeArgTypes.push(functionType);
|
13979
14127
|
typeVarContext.setTypeVarType(typeParam, (0, typeUtils_1.convertTypeToParamSpecValue)(functionType));
|
13980
14128
|
return;
|
@@ -14838,7 +14986,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14838
14986
|
}
|
14839
14987
|
// Special-case calls to certain built-in type functions.
|
14840
14988
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* ParseNodeType.Call */) {
|
14841
|
-
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression,
|
14989
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 2 /* EvaluatorFlags.CallBaseDefaults */);
|
14842
14990
|
const callType = baseTypeResult.type;
|
14843
14991
|
const exemptBuiltins = [
|
14844
14992
|
'TypeVar',
|
@@ -15713,7 +15861,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15713
15861
|
function assignClassToSelf(destType, srcType, ignoreBaseClassVariance = true, recursionCount = 0) {
|
15714
15862
|
(0, debug_1.assert)(types_1.ClassType.isSameGenericClass(destType, srcType));
|
15715
15863
|
(0, debug_1.assert)(destType.details.typeParameters.length > 0);
|
15716
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
15717
15864
|
const typeVarContext = new typeVarContext_1.TypeVarContext();
|
15718
15865
|
let isAssignable = true;
|
15719
15866
|
destType.details.fields.forEach((symbol, name) => {
|
@@ -15734,7 +15881,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15734
15881
|
types_1.ClassType.isPropertyClass(destMemberType) &&
|
15735
15882
|
(0, types_1.isClassInstance)(srcMemberType) &&
|
15736
15883
|
types_1.ClassType.isPropertyClass(srcMemberType)) {
|
15737
|
-
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
|
15884
|
+
if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType,
|
15885
|
+
/* diag */ undefined, typeVarContext,
|
15738
15886
|
/* selfTypeVarContext */ undefined, recursionCount)) {
|
15739
15887
|
isAssignable = false;
|
15740
15888
|
}
|
@@ -15753,7 +15901,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15753
15901
|
flags |= 1 /* AssignTypeFlags.EnforceInvariance */;
|
15754
15902
|
}
|
15755
15903
|
}
|
15756
|
-
if (!assignType(destMemberType, srcMemberType,
|
15904
|
+
if (!assignType(destMemberType, srcMemberType,
|
15905
|
+
/* diag */ undefined, typeVarContext,
|
15757
15906
|
/* srcTypeVarContext */ undefined, flags, recursionCount)) {
|
15758
15907
|
isAssignable = false;
|
15759
15908
|
}
|
@@ -16124,6 +16273,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16124
16273
|
if (destType === srcType && !(0, typeUtils_1.requiresSpecialization)(destType)) {
|
16125
16274
|
return true;
|
16126
16275
|
}
|
16276
|
+
// If the source type is a special form, use the literal special form
|
16277
|
+
// class rather than the symbolic form.
|
16278
|
+
if (srcType.specialForm) {
|
16279
|
+
let isSpecialFormExempt = false;
|
16280
|
+
// A few special forms that are normally not compatible with type[T]
|
16281
|
+
// are compatible specifically in the context of isinstance and issubclass.
|
16282
|
+
if ((flags & 32768 /* AssignTypeFlags.AllowIsinstanceSpecialForms */) !== 0) {
|
16283
|
+
if (types_1.ClassType.isBuiltIn(srcType.specialForm, ['Callable', 'UnionType', 'Generic'])) {
|
16284
|
+
isSpecialFormExempt = true;
|
16285
|
+
}
|
16286
|
+
}
|
16287
|
+
if (!isSpecialFormExempt) {
|
16288
|
+
srcType = srcType.specialForm;
|
16289
|
+
}
|
16290
|
+
}
|
16127
16291
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
16128
16292
|
return true;
|
16129
16293
|
}
|
@@ -16321,7 +16485,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16321
16485
|
if ((0, types_1.isAnyOrUnknown)(destType)) {
|
16322
16486
|
return true;
|
16323
16487
|
}
|
16324
|
-
if ((0, types_1.isAnyOrUnknown)(srcType) && !
|
16488
|
+
if ((0, types_1.isAnyOrUnknown)(srcType) && !srcType.specialForm) {
|
16325
16489
|
const targetTypeVarContext = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0 ? destTypeVarContext : srcTypeVarContext;
|
16326
16490
|
if (targetTypeVarContext) {
|
16327
16491
|
// If it's an ellipsis type, convert it to a regular "Any"
|
@@ -16426,8 +16590,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16426
16590
|
return false;
|
16427
16591
|
}
|
16428
16592
|
}
|
16429
|
-
if (
|
16430
|
-
|
16593
|
+
if (!isSpecialFormClass(expandedSrcType, flags) &&
|
16594
|
+
assignClass(destType, expandedSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
|
16595
|
+
/* reportErrorsUsingObjType */ false)) {
|
16431
16596
|
return true;
|
16432
16597
|
}
|
16433
16598
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
@@ -16449,6 +16614,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16449
16614
|
}
|
16450
16615
|
if ((0, types_1.isClassInstance)(destType)) {
|
16451
16616
|
if (types_1.ClassType.isBuiltIn(destType, 'type')) {
|
16617
|
+
if ((0, types_1.isInstantiableClass)(srcType) && isSpecialFormClass(srcType, flags)) {
|
16618
|
+
return false;
|
16619
|
+
}
|
16452
16620
|
if ((0, types_1.isAnyOrUnknown)(srcType) && (flags & 16 /* AssignTypeFlags.OverloadOverlapCheck */) !== 0) {
|
16453
16621
|
return false;
|
16454
16622
|
}
|
@@ -16550,7 +16718,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16550
16718
|
}
|
16551
16719
|
}
|
16552
16720
|
}
|
16553
|
-
else if ((0, types_1.isAnyOrUnknown)(concreteSrcType) && !
|
16721
|
+
else if ((0, types_1.isAnyOrUnknown)(concreteSrcType) && !concreteSrcType.specialForm) {
|
16554
16722
|
return (flags & 16 /* AssignTypeFlags.OverloadOverlapCheck */) === 0;
|
16555
16723
|
}
|
16556
16724
|
else if ((0, types_1.isUnion)(concreteSrcType)) {
|
@@ -16851,6 +17019,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16851
17019
|
}
|
16852
17020
|
return true;
|
16853
17021
|
}
|
17022
|
+
function isSpecialFormClass(classType, flags) {
|
17023
|
+
if ((flags & 32768 /* AssignTypeFlags.AllowIsinstanceSpecialForms */) !== 0) {
|
17024
|
+
return false;
|
17025
|
+
}
|
17026
|
+
return types_1.ClassType.isSpecialFormClass(classType);
|
17027
|
+
}
|
16854
17028
|
// Determines whether a type is "subsumed by" (i.e. is a proper subtype of) one
|
16855
17029
|
// of the other type.
|
16856
17030
|
function isTypeSubsumedByOtherType(type, otherType, allowAnyToSubsume, recursionCount = 0) {
|
@@ -18616,6 +18790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18616
18790
|
isNodeReachable,
|
18617
18791
|
isAsymmetricAccessorAssignment,
|
18618
18792
|
suppressDiagnostics,
|
18793
|
+
isSpecialFormClass,
|
18619
18794
|
getDeclarationsForStringNode,
|
18620
18795
|
getDeclarationsForNameNode,
|
18621
18796
|
getTypeForDeclaration,
|
@@ -18658,6 +18833,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18658
18833
|
getTupleClassType,
|
18659
18834
|
getObjectType,
|
18660
18835
|
getNoneType,
|
18836
|
+
getUnionClassType,
|
18661
18837
|
getBuiltInObject,
|
18662
18838
|
getTypingType,
|
18663
18839
|
assignTypeArguments,
|