@zzzen/pyright-internal 1.2.0-dev.20231224 → 1.2.0-dev.20231231
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/binder.js +1 -3
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +34 -14
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +3 -0
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +16 -16
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +2 -9
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/namedTuples.js +1 -1
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/protocols.js +3 -3
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +165 -126
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -1
- package/dist/analyzer/typeGuards.js +2 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +10 -9
- package/dist/analyzer/typeUtils.js +14 -13
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +24 -36
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +7 -1
- package/dist/analyzer/types.js +55 -5
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/diagnostic.d.ts +1 -0
- package/dist/common/diagnostic.js +18 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/localization/localize.d.ts +18 -0
- package/dist/localization/localize.js +10 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +11 -1
- package/dist/parser/parser.js +1 -1
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +6 -3
- package/dist/pyright.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +7 -7
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +2 -2
- package/dist/tests/typeEvaluator5.test.js +1 -1
- package/dist/tests/typePrinter.test.js +2 -10
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/package.json +1 -1
@@ -706,7 +706,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
706
706
|
// Make sure the resulting type is assignable to the expected type.
|
707
707
|
if (!assignType(inferenceContext.expectedType, typeResult.type, diag,
|
708
708
|
/* destTypeVarContext */ undefined,
|
709
|
-
/* srcTypeVarContext */ undefined,
|
709
|
+
/* srcTypeVarContext */ undefined, 1024 /* AssignTypeFlags.IgnoreTypeVarScope */)) {
|
710
710
|
typeResult.typeErrors = true;
|
711
711
|
typeResult.expectedTypeDiagAddendum = diag;
|
712
712
|
diag.addTextRange(node);
|
@@ -1398,15 +1398,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1398
1398
|
}
|
1399
1399
|
return undefined;
|
1400
1400
|
}
|
1401
|
-
function getBoundMagicMethod(classType, memberName, selfType, recursionCount = 0) {
|
1401
|
+
function getBoundMagicMethod(classType, memberName, selfType, diag, recursionCount = 0) {
|
1402
1402
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1403
1403
|
return undefined;
|
1404
1404
|
}
|
1405
1405
|
recursionCount++;
|
1406
1406
|
const boundMethodResult = getTypeOfBoundMember(
|
1407
1407
|
/* errorNode */ undefined, classType, memberName,
|
1408
|
-
/* usage */ undefined,
|
1409
|
-
/* diag */ undefined, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, selfType, recursionCount);
|
1408
|
+
/* usage */ undefined, diag, 16 /* MemberAccessFlags.SkipInstanceMembers */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, selfType, recursionCount);
|
1410
1409
|
if (!boundMethodResult || boundMethodResult.typeErrors) {
|
1411
1410
|
return undefined;
|
1412
1411
|
}
|
@@ -1414,7 +1413,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1414
1413
|
return boundMethodResult.type;
|
1415
1414
|
}
|
1416
1415
|
if ((0, types_1.isClassInstance)(boundMethodResult.type)) {
|
1417
|
-
return getBoundMagicMethod(boundMethodResult.type, '__call__', selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType), recursionCount);
|
1416
|
+
return getBoundMagicMethod(boundMethodResult.type, '__call__', selfType !== null && selfType !== void 0 ? selfType : types_1.ClassType.cloneAsInstance(classType), diag, recursionCount);
|
1418
1417
|
}
|
1419
1418
|
if ((0, types_1.isAnyOrUnknown)(boundMethodResult.type)) {
|
1420
1419
|
return (0, typeUtils_1.getUnknownTypeForCallable)();
|
@@ -1574,10 +1573,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1574
1573
|
const kwSeparatorIndex = functionType.details.parameters.findIndex((param) => param.category === 1 /* ParameterCategory.ArgsList */);
|
1575
1574
|
// Add a keyword separator if necessary.
|
1576
1575
|
if (kwSeparatorIndex < 0) {
|
1577
|
-
types_1.FunctionType.
|
1578
|
-
category: 1 /* ParameterCategory.ArgsList */,
|
1579
|
-
type: types_1.AnyType.create(),
|
1580
|
-
});
|
1576
|
+
types_1.FunctionType.addKeywordOnlyParameterSeparator(newFunction);
|
1581
1577
|
}
|
1582
1578
|
tdEntries.forEach((tdEntry, name) => {
|
1583
1579
|
types_1.FunctionType.addParameter(newFunction, {
|
@@ -1738,6 +1734,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1738
1734
|
specializedType.typeArguments.length > 0) {
|
1739
1735
|
return specializedType.typeArguments[0];
|
1740
1736
|
}
|
1737
|
+
return types_1.UnknownType.create();
|
1741
1738
|
}
|
1742
1739
|
}
|
1743
1740
|
if (errorNode) {
|
@@ -2970,9 +2967,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2970
2967
|
// Verify that the name does not refer to a (non type alias) variable.
|
2971
2968
|
if (effectiveTypeInfo.includesVariableDecl && !type.typeAliasInfo) {
|
2972
2969
|
let isAllowedTypeForVariable = (0, types_1.isTypeVar)(type) || (0, typeUtils_1.isTypeAliasPlaceholder)(type);
|
2973
|
-
if ((0, types_1.isClass)(type) &&
|
2970
|
+
if ((0, types_1.isClass)(type) &&
|
2971
|
+
!type.includeSubclasses &&
|
2972
|
+
!symbol.hasTypedDeclarations() &&
|
2973
|
+
types_1.ClassType.isValidTypeAliasClass(type)) {
|
2974
2974
|
// This check exempts class types that are created by calling
|
2975
|
-
// NewType, NamedTuple,
|
2975
|
+
// NewType, NamedTuple, etc.
|
2976
2976
|
isAllowedTypeForVariable = true;
|
2977
2977
|
}
|
2978
2978
|
// Disable for assignments in the typings.pyi file, since it defines special forms.
|
@@ -4530,10 +4530,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4530
4530
|
hasDeclaredType: true,
|
4531
4531
|
});
|
4532
4532
|
});
|
4533
|
-
|
4533
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
4534
|
+
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4534
4535
|
}
|
4535
4536
|
else if ((0, types_1.isParamSpec)(typeArgType)) {
|
4536
|
-
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, (0, typeUtils_1.convertToInstance)(typeArgType), diag, typeVarContext,
|
4537
|
+
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, (0, typeUtils_1.convertToInstance)(typeArgType), diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4537
4538
|
}
|
4538
4539
|
else if ((0, types_1.isInstantiableClass)(typeArgType) && types_1.ClassType.isBuiltIn(typeArgType, 'Concatenate')) {
|
4539
4540
|
const concatTypeArgs = typeArgType.typeArguments;
|
@@ -4541,12 +4542,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4541
4542
|
if (concatTypeArgs && concatTypeArgs.length > 0) {
|
4542
4543
|
concatTypeArgs.forEach((typeArg, index) => {
|
4543
4544
|
if (index === concatTypeArgs.length - 1) {
|
4544
|
-
|
4545
|
-
types_1.FunctionType.addParameter(functionType, {
|
4546
|
-
category: 0 /* ParameterCategory.Simple */,
|
4547
|
-
isNameSynthesized: false,
|
4548
|
-
type: types_1.UnknownType.create(),
|
4549
|
-
});
|
4545
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
4550
4546
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
4551
4547
|
functionType.details.paramSpec = typeArg;
|
4552
4548
|
}
|
@@ -4566,7 +4562,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4566
4562
|
}
|
4567
4563
|
});
|
4568
4564
|
}
|
4569
|
-
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext,
|
4565
|
+
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, functionType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4570
4566
|
}
|
4571
4567
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgType)) {
|
4572
4568
|
const functionType = types_1.FunctionType.createSynthesizedInstance('', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */);
|
@@ -4606,7 +4602,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4606
4602
|
}
|
4607
4603
|
}
|
4608
4604
|
}
|
4609
|
-
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext,
|
4605
|
+
(0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, param, typeArgType, diag, typeVarContext, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */);
|
4610
4606
|
}
|
4611
4607
|
});
|
4612
4608
|
if (!diag.isEmpty()) {
|
@@ -5251,6 +5247,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5251
5247
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
5252
5248
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.useTupleInstead());
|
5253
5249
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.tupleInAnnotation() + diag.getString(), node);
|
5250
|
+
return { type: types_1.UnknownType.create() };
|
5254
5251
|
}
|
5255
5252
|
if ((flags & 128 /* EvaluatorFlags.ExpectingInstantiableType */) !== 0 &&
|
5256
5253
|
node.expressions.length === 0 &&
|
@@ -5552,11 +5549,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5552
5549
|
if (lambdaParams.length > 0) {
|
5553
5550
|
const lastParam = lambdaParams[lambdaParams.length - 1];
|
5554
5551
|
if (lastParam.category === 0 /* ParameterCategory.Simple */ && !lastParam.name) {
|
5555
|
-
types_1.FunctionType.
|
5556
|
-
category: 0 /* ParameterCategory.Simple */,
|
5557
|
-
name: '',
|
5558
|
-
type: types_1.UnknownType.create(),
|
5559
|
-
});
|
5552
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(expectedType);
|
5560
5553
|
}
|
5561
5554
|
}
|
5562
5555
|
function getLambdaType() {
|
@@ -6542,8 +6535,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6542
6535
|
}
|
6543
6536
|
if (types_1.ClassType.isBuiltIn(expandedCallType)) {
|
6544
6537
|
const className = (_a = expandedCallType.aliasName) !== null && _a !== void 0 ? _a : expandedCallType.details.name;
|
6545
|
-
// Handle
|
6546
|
-
if (
|
6538
|
+
// Handle a call to a metaclass explicitly.
|
6539
|
+
if ((0, typeUtils_1.isInstantiableMetaclass)(expandedCallType)) {
|
6547
6540
|
if (expandedCallType.typeArguments && expandedCallType.isTypeArgumentExplicit) {
|
6548
6541
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
|
6549
6542
|
type: printType(expandedCallType),
|
@@ -6552,9 +6545,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6552
6545
|
}
|
6553
6546
|
// Validate the constructor arguments.
|
6554
6547
|
(0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedCallType, skipUnknownArgCheck, inferenceContext);
|
6555
|
-
|
6556
|
-
|
6557
|
-
|
6548
|
+
// The one-parameter form of "type" returns the class
|
6549
|
+
// for the specified object.
|
6550
|
+
if (expandedCallType.details.name === 'type' && argList.length === 1) {
|
6558
6551
|
const argType = getTypeOfArgument(argList[0]).type;
|
6559
6552
|
const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
|
6560
6553
|
if ((0, types_1.isClassInstance)(subtype) ||
|
@@ -6570,9 +6563,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6570
6563
|
return { returnType };
|
6571
6564
|
}
|
6572
6565
|
if (argList.length >= 2) {
|
6573
|
-
// The two-parameter form of
|
6566
|
+
// The two-parameter form of a call to a metaclass returns a new class
|
6574
6567
|
// built from the specified base types.
|
6575
|
-
return {
|
6568
|
+
return {
|
6569
|
+
returnType: createClassFromMetaclass(errorNode, argList, expandedCallType) || types_1.AnyType.create(),
|
6570
|
+
};
|
6576
6571
|
}
|
6577
6572
|
// If the parameter to type() is not statically known,
|
6578
6573
|
// fall back to Any.
|
@@ -7646,9 +7641,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7646
7641
|
}
|
7647
7642
|
const effectiveReturnType = getFunctionEffectiveReturnType(type);
|
7648
7643
|
let effectiveExpectedType = inferenceContext.expectedType;
|
7649
|
-
let effectiveFlags =
|
7644
|
+
let effectiveFlags = 2048 /* AssignTypeFlags.PopulatingExpectedType */;
|
7650
7645
|
if ((0, typeUtils_1.containsLiteralType)(effectiveExpectedType, /* includeTypeArgs */ true)) {
|
7651
|
-
effectiveFlags |=
|
7646
|
+
effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
7652
7647
|
}
|
7653
7648
|
// If the expected type is a union, we don't know which type is expected.
|
7654
7649
|
// We may or may not be able to make use of the expected type. We'll evaluate
|
@@ -7704,7 +7699,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7704
7699
|
effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
|
7705
7700
|
unknownIfNotFound: true,
|
7706
7701
|
});
|
7707
|
-
effectiveFlags |=
|
7702
|
+
effectiveFlags |= 4096 /* AssignTypeFlags.SkipPopulateUnknownExpectedType */;
|
7708
7703
|
}
|
7709
7704
|
}
|
7710
7705
|
}
|
@@ -8710,7 +8705,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8710
8705
|
if (errorNode.parent.nodeType !== 3 /* ParseNodeType.Assignment */ ||
|
8711
8706
|
errorNode.parent.rightExpression !== errorNode ||
|
8712
8707
|
errorNode.parent.leftExpression.nodeType !== 38 /* ParseNodeType.Name */) {
|
8713
|
-
|
8708
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeMustBeAssigned(), errorNode);
|
8714
8709
|
return undefined;
|
8715
8710
|
}
|
8716
8711
|
const nameNode = errorNode.parent.leftExpression;
|
@@ -8718,11 +8713,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8718
8713
|
if (firstArg.valueExpression && firstArg.valueExpression.nodeType === 48 /* ParseNodeType.StringList */) {
|
8719
8714
|
const typeAliasName = firstArg.valueExpression.strings.map((s) => s.value).join('');
|
8720
8715
|
if (typeAliasName !== nameNode.value) {
|
8721
|
-
|
8716
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeNameMismatch(), firstArg.valueExpression);
|
8722
8717
|
}
|
8723
8718
|
}
|
8724
8719
|
else {
|
8725
|
-
|
8720
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeNameArg(), firstArg.valueExpression || errorNode);
|
8726
8721
|
return undefined;
|
8727
8722
|
}
|
8728
8723
|
let valueExpr;
|
@@ -8777,12 +8772,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8777
8772
|
}
|
8778
8773
|
});
|
8779
8774
|
if (!isTypeParamListValid) {
|
8780
|
-
|
8775
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasTypeParamInvalid(), typeParamsExpr);
|
8781
8776
|
return undefined;
|
8782
8777
|
}
|
8783
8778
|
}
|
8784
8779
|
return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
|
8785
|
-
/* isPep695Syntax */
|
8780
|
+
/* isPep695Syntax */ true,
|
8786
8781
|
/* typeParamNodes */ undefined, () => typeParameters);
|
8787
8782
|
}
|
8788
8783
|
function getBooleanValue(node) {
|
@@ -8794,7 +8789,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8794
8789
|
return true;
|
8795
8790
|
}
|
8796
8791
|
}
|
8797
|
-
|
8792
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.expectedBoolLiteral(), node);
|
8798
8793
|
return false;
|
8799
8794
|
}
|
8800
8795
|
function getFunctionFullName(functionNode, moduleName, functionName) {
|
@@ -8814,7 +8809,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8814
8809
|
// in the Python specification: The static type checker will treat
|
8815
8810
|
// the new type as if it were a subclass of the original type.
|
8816
8811
|
function createNewType(errorNode, argList) {
|
8817
|
-
var _a;
|
8812
|
+
var _a, _b, _c;
|
8818
8813
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8819
8814
|
let className = '';
|
8820
8815
|
if (argList.length !== 2) {
|
@@ -8831,26 +8826,36 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8831
8826
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeBadName(), (_a = argList[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
8832
8827
|
return undefined;
|
8833
8828
|
}
|
8829
|
+
if (((_b = errorNode.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* ParseNodeType.Assignment */ &&
|
8830
|
+
errorNode.parent.leftExpression.nodeType === 38 /* ParseNodeType.Name */ &&
|
8831
|
+
errorNode.parent.leftExpression.value !== className) {
|
8832
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeNameMismatch(), errorNode.parent.leftExpression);
|
8833
|
+
return undefined;
|
8834
|
+
}
|
8834
8835
|
let baseClass = getTypeOfArgumentExpectingType(argList[1]).type;
|
8835
8836
|
let isBaseClassAny = false;
|
8836
8837
|
if ((0, types_1.isAnyOrUnknown)(baseClass)) {
|
8837
8838
|
if (objectType && (0, types_1.isClassInstance)(objectType)) {
|
8838
8839
|
baseClass = types_1.ClassType.cloneAsInstantiable(objectType);
|
8839
8840
|
}
|
8841
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.newTypeAnyOrUnknown(), (_c = argList[1].node) !== null && _c !== void 0 ? _c : errorNode);
|
8840
8842
|
isBaseClassAny = true;
|
8841
8843
|
}
|
8842
8844
|
if (!(0, types_1.isInstantiableClass)(baseClass)) {
|
8843
8845
|
addError(localize_1.Localizer.Diagnostic.newTypeNotAClass(), argList[1].node || errorNode);
|
8844
8846
|
return undefined;
|
8845
8847
|
}
|
8846
|
-
if (types_1.ClassType.isProtocolClass(baseClass)) {
|
8848
|
+
if (types_1.ClassType.isProtocolClass(baseClass) || types_1.ClassType.isTypedDictClass(baseClass)) {
|
8847
8849
|
addError(localize_1.Localizer.Diagnostic.newTypeProtocolClass(), argList[1].node || errorNode);
|
8848
8850
|
}
|
8849
8851
|
else if (baseClass.literalValue !== undefined) {
|
8850
8852
|
addError(localize_1.Localizer.Diagnostic.newTypeLiteral(), argList[1].node || errorNode);
|
8851
8853
|
}
|
8854
|
+
else if (types_1.ClassType.isNewTypeClass(baseClass)) {
|
8855
|
+
addError(localize_1.Localizer.Diagnostic.newTypeNewTypeClass(), argList[1].node || errorNode);
|
8856
|
+
}
|
8852
8857
|
let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
|
8853
|
-
classFlags |= 4096 /* ClassTypeFlags.Final */;
|
8858
|
+
classFlags |= 4096 /* ClassTypeFlags.Final */ | 268435456 /* ClassTypeFlags.NewTypeClass */ | 536870912 /* ClassTypeFlags.ValidTypeAliasClass */;
|
8854
8859
|
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
|
8855
8860
|
/* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
|
8856
8861
|
classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
|
@@ -8887,7 +8892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8887
8892
|
return classType;
|
8888
8893
|
}
|
8889
8894
|
// Implements the semantics of the multi-parameter variant of the "type" call.
|
8890
|
-
function
|
8895
|
+
function createClassFromMetaclass(errorNode, argList, metaclass) {
|
8891
8896
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8892
8897
|
const arg0Type = getTypeOfArgument(argList[0]).type;
|
8893
8898
|
if (!(0, types_1.isClassInstance)(arg0Type) || !types_1.ClassType.isBuiltIn(arg0Type, 'str')) {
|
@@ -8895,10 +8900,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8895
8900
|
}
|
8896
8901
|
const className = arg0Type.literalValue || '_';
|
8897
8902
|
const arg1Type = getTypeOfArgument(argList[1]).type;
|
8903
|
+
// TODO - properly handle case where tuple of base classes is provided.
|
8898
8904
|
if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
|
8899
8905
|
return undefined;
|
8900
8906
|
}
|
8901
|
-
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri,
|
8907
|
+
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 536870912 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode),
|
8902
8908
|
/* declaredMetaclass */ undefined, arg1Type.details.effectiveMetaclass);
|
8903
8909
|
arg1Type.tupleTypeArguments.forEach((typeArg) => {
|
8904
8910
|
const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
|
@@ -8936,14 +8942,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8936
8942
|
}
|
8937
8943
|
return { type: type !== null && type !== void 0 ? type : types_1.UnknownType.create() };
|
8938
8944
|
}
|
8939
|
-
function getTypeOfMagicMethodCall(objType, methodName, argList, errorNode, inferenceContext) {
|
8945
|
+
function getTypeOfMagicMethodCall(objType, methodName, argList, errorNode, inferenceContext, diag) {
|
8940
8946
|
let magicMethodSupported = true;
|
8941
8947
|
// Create a helper lambda for object subtypes.
|
8942
8948
|
const handleSubtype = (subtype) => {
|
8943
8949
|
let magicMethodType;
|
8944
8950
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
8945
8951
|
if ((0, types_1.isClass)(concreteSubtype)) {
|
8946
|
-
magicMethodType = getBoundMagicMethod(concreteSubtype, methodName, subtype);
|
8952
|
+
magicMethodType = getBoundMagicMethod(concreteSubtype, methodName, subtype, diag);
|
8947
8953
|
}
|
8948
8954
|
if (magicMethodType) {
|
8949
8955
|
const functionArgs = argList.map((arg) => {
|
@@ -9283,7 +9289,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9283
9289
|
mappingType = (0, typeUtils_1.selfSpecializeClass)(mappingType);
|
9284
9290
|
if (assignType(types_1.ClassType.cloneAsInstance(mappingType), unexpandedType,
|
9285
9291
|
/* diag */ undefined, mappingTypeVarContext,
|
9286
|
-
/* srcTypeVarContext */ undefined,
|
9292
|
+
/* srcTypeVarContext */ undefined, 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */)) {
|
9287
9293
|
const specializedMapping = (0, typeUtils_1.applySolvedTypeVars)(mappingType, mappingTypeVarContext);
|
9288
9294
|
const typeArgs = specializedMapping.typeArguments;
|
9289
9295
|
if (typeArgs && typeArgs.length >= 2) {
|
@@ -9711,11 +9717,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9711
9717
|
if (paramsArePositionOnly &&
|
9712
9718
|
!isImplicitPositionOnlyParam &&
|
9713
9719
|
functionType.details.parameters.length > 0) {
|
9714
|
-
|
9715
|
-
types_1.FunctionType.addParameter(functionType, {
|
9716
|
-
category: 0 /* ParameterCategory.Simple */,
|
9717
|
-
type: types_1.UnknownType.create(),
|
9718
|
-
});
|
9720
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
9719
9721
|
}
|
9720
9722
|
if (!isImplicitPositionOnlyParam) {
|
9721
9723
|
paramsArePositionOnly = false;
|
@@ -9732,11 +9734,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9732
9734
|
types_1.FunctionType.addParameter(functionType, functionParam);
|
9733
9735
|
});
|
9734
9736
|
if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
|
9735
|
-
|
9736
|
-
types_1.FunctionType.addParameter(functionType, {
|
9737
|
-
category: 0 /* ParameterCategory.Simple */,
|
9738
|
-
type: types_1.UnknownType.create(),
|
9739
|
-
});
|
9737
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
9740
9738
|
}
|
9741
9739
|
let typeErrors = false;
|
9742
9740
|
// If we're speculatively evaluating the lambda, create another speculative
|
@@ -10047,12 +10045,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10047
10045
|
});
|
10048
10046
|
});
|
10049
10047
|
if (typeList.length > 0) {
|
10050
|
-
|
10051
|
-
types_1.FunctionType.addParameter(functionType, {
|
10052
|
-
category: 0 /* ParameterCategory.Simple */,
|
10053
|
-
isNameSynthesized: false,
|
10054
|
-
type: types_1.UnknownType.create(),
|
10055
|
-
});
|
10048
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
10056
10049
|
}
|
10057
10050
|
}
|
10058
10051
|
else if ((0, typeUtils_1.isEllipsisType)(typeArgs[0].type)) {
|
@@ -10068,12 +10061,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10068
10061
|
if (concatTypeArgs && concatTypeArgs.length > 0) {
|
10069
10062
|
concatTypeArgs.forEach((typeArg, index) => {
|
10070
10063
|
if (index === concatTypeArgs.length - 1) {
|
10071
|
-
|
10072
|
-
types_1.FunctionType.addParameter(functionType, {
|
10073
|
-
category: 0 /* ParameterCategory.Simple */,
|
10074
|
-
isNameSynthesized: false,
|
10075
|
-
type: types_1.UnknownType.create(),
|
10076
|
-
});
|
10064
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
10077
10065
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
10078
10066
|
functionType.details.paramSpec = typeArg;
|
10079
10067
|
}
|
@@ -10308,14 +10296,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10308
10296
|
name: classType.details.name,
|
10309
10297
|
}), (_a = typeArgs[0].node) !== null && _a !== void 0 ? _a : errorNode);
|
10310
10298
|
}
|
10311
|
-
|
10299
|
+
let enclosingClass = ParseTreeUtils.getEnclosingClass(errorNode);
|
10300
|
+
// If `Self` appears anywhere outside of the class body (e.g. a decorator,
|
10301
|
+
// base class list, metaclass argument, type parameter list), it is
|
10302
|
+
// considered illegal.
|
10303
|
+
if (enclosingClass && !ParseTreeUtils.isNodeContainedWithin(errorNode, enclosingClass.suite)) {
|
10304
|
+
enclosingClass = undefined;
|
10305
|
+
}
|
10312
10306
|
const enclosingClassTypeResult = enclosingClass ? getTypeOfClass(enclosingClass) : undefined;
|
10313
10307
|
if (!enclosingClassTypeResult) {
|
10314
|
-
if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
|
10308
|
+
if ((flags & (256 /* EvaluatorFlags.ExpectingTypeAnnotation */ | 128 /* EvaluatorFlags.ExpectingInstantiableType */)) !== 0) {
|
10315
10309
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeContext(), errorNode);
|
10316
10310
|
}
|
10317
10311
|
return types_1.UnknownType.create();
|
10318
10312
|
}
|
10313
|
+
else if ((0, typeUtils_1.isInstantiableMetaclass)(enclosingClassTypeResult.classType)) {
|
10314
|
+
// If `Self` appears within a metaclass, it is considered illegal.
|
10315
|
+
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.selfTypeMetaclass(), errorNode);
|
10316
|
+
return types_1.UnknownType.create();
|
10317
|
+
}
|
10319
10318
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(errorNode);
|
10320
10319
|
if (enclosingFunction) {
|
10321
10320
|
const functionInfo = (0, decorators_1.getFunctionInfoFromDecorators)(evaluatorInterface, enclosingFunction,
|
@@ -10485,6 +10484,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10485
10484
|
if (!typeArgs || typeArgs.length === 0) {
|
10486
10485
|
return { type: types_1.AnyType.create() };
|
10487
10486
|
}
|
10487
|
+
if (typeArgs[0].typeList) {
|
10488
|
+
addError(localize_1.Localizer.Diagnostic.typeArgListNotAllowed(), typeArgs[0].node);
|
10489
|
+
}
|
10488
10490
|
return {
|
10489
10491
|
type: types_1.TypeBase.cloneForAnnotated(typeArgs[0].type),
|
10490
10492
|
isReadOnly: typeArgs[0].isReadOnly,
|
@@ -11094,11 +11096,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11094
11096
|
setSymbolResolutionPartialType(typeAliasSymbol.symbol, typeAliasDecl, typeAliasTypeVar);
|
11095
11097
|
}
|
11096
11098
|
const typeParameters = getTypeParamCallback();
|
11097
|
-
typeAliasTypeVar.details.recursiveTypeParameters = typeParameters;
|
11098
|
-
|
11099
|
-
|
11100
|
-
|
11101
|
-
|
11099
|
+
typeAliasTypeVar.details.recursiveTypeParameters = typeParameters || [];
|
11100
|
+
const aliasTypeResult = getTypeOfExpressionExpectingType(valueNode, {
|
11101
|
+
allowForwardReference: true,
|
11102
|
+
enforceTypeAnnotationRules: true,
|
11103
|
+
});
|
11102
11104
|
let isIncomplete = false;
|
11103
11105
|
let aliasType = aliasTypeResult.type;
|
11104
11106
|
if (aliasTypeResult.isIncomplete) {
|
@@ -11363,6 +11365,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11363
11365
|
}
|
11364
11366
|
}
|
11365
11367
|
}
|
11368
|
+
else if (types_1.ClassType.isTypedDictClass(classType)) {
|
11369
|
+
if (arg.name.value === 'total') {
|
11370
|
+
// The "total" and "readonly" parameters apply only for TypedDict classes.
|
11371
|
+
// PEP 589 specifies that the parameter must be either True or False.
|
11372
|
+
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
11373
|
+
if (constArgValue === undefined) {
|
11374
|
+
addError(localize_1.Localizer.Diagnostic.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
11375
|
+
}
|
11376
|
+
else if (arg.name.value === 'total' && !constArgValue) {
|
11377
|
+
classType.details.flags |= 256 /* ClassTypeFlags.CanOmitDictValues */;
|
11378
|
+
}
|
11379
|
+
}
|
11380
|
+
else {
|
11381
|
+
addError(localize_1.Localizer.Diagnostic.typedDictInitsubclassParameter().format({ name: arg.name.value }), arg);
|
11382
|
+
}
|
11383
|
+
}
|
11366
11384
|
else if (arg.name.value === 'metaclass') {
|
11367
11385
|
if (metaclassNode) {
|
11368
11386
|
addError(localize_1.Localizer.Diagnostic.metaclassDuplicate(), arg);
|
@@ -11371,17 +11389,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11371
11389
|
metaclassNode = arg.valueExpression;
|
11372
11390
|
}
|
11373
11391
|
}
|
11374
|
-
else if (types_1.ClassType.isTypedDictClass(classType) && arg.name.value === 'total') {
|
11375
|
-
// The "total" and "readonly" parameters apply only for TypedDict classes.
|
11376
|
-
// PEP 589 specifies that the parameter must be either True or False.
|
11377
|
-
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
11378
|
-
if (constArgValue === undefined) {
|
11379
|
-
addError(localize_1.Localizer.Diagnostic.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
11380
|
-
}
|
11381
|
-
else if (arg.name.value === 'total' && !constArgValue) {
|
11382
|
-
classType.details.flags |= 256 /* ClassTypeFlags.CanOmitDictValues */;
|
11383
|
-
}
|
11384
|
-
}
|
11385
11392
|
else {
|
11386
11393
|
// Collect arguments that will be passed to the `__init_subclass__`
|
11387
11394
|
// method described in PEP 487.
|
@@ -12272,11 +12279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12272
12279
|
if (paramsArePositionOnly &&
|
12273
12280
|
!isImplicitPositionOnlyParam &&
|
12274
12281
|
functionType.details.parameters.length > firstNonClsSelfParamIndex) {
|
12275
|
-
|
12276
|
-
types_1.FunctionType.addParameter(functionType, {
|
12277
|
-
category: 0 /* ParameterCategory.Simple */,
|
12278
|
-
type: types_1.UnknownType.create(),
|
12279
|
-
});
|
12282
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
12280
12283
|
}
|
12281
12284
|
if (!isImplicitPositionOnlyParam) {
|
12282
12285
|
paramsArePositionOnly = false;
|
@@ -12315,11 +12318,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12315
12318
|
}
|
12316
12319
|
});
|
12317
12320
|
if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
|
12318
|
-
|
12319
|
-
types_1.FunctionType.addParameter(functionType, {
|
12320
|
-
category: 0 /* ParameterCategory.Simple */,
|
12321
|
-
type: types_1.UnknownType.create(),
|
12322
|
-
});
|
12321
|
+
types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
|
12323
12322
|
}
|
12324
12323
|
// Update the types for the nodes associated with the parameters.
|
12325
12324
|
paramTypes.forEach((paramType, index) => {
|
@@ -12915,7 +12914,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12915
12914
|
const additionalHelp = new diagnostic_1.DiagnosticAddendum();
|
12916
12915
|
if ((0, types_1.isClass)(subtype)) {
|
12917
12916
|
let enterType = getTypeOfMagicMethodCall(subtype, enterMethodName, [], node.expression,
|
12918
|
-
/* inferenceContext */ undefined);
|
12917
|
+
/* inferenceContext */ undefined, additionalHelp.createAddendum());
|
12919
12918
|
if (enterType) {
|
12920
12919
|
// For "async while", an implicit "await" is performed.
|
12921
12920
|
if (isAsync) {
|
@@ -14505,7 +14504,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14505
14504
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
14506
14505
|
// Determine if this node is within a quoted type annotation.
|
14507
14506
|
const isWithinTypeAnnotation = ParseTreeUtils.isWithinTypeAnnotation(node, !(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(node)));
|
14508
|
-
|
14507
|
+
// Determine if this is part of a "type" statement.
|
14508
|
+
const isWithinTypeAliasStatement = !!ParseTreeUtils.getParentNodeOfType(node, 77 /* ParseNodeType.TypeAlias */);
|
14509
|
+
const allowForwardReferences = isWithinTypeAnnotation || isWithinTypeAliasStatement || fileInfo.isStubFile;
|
14509
14510
|
let symbol;
|
14510
14511
|
const typeParamSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(node);
|
14511
14512
|
if (typeParamSymbol) {
|
@@ -16057,16 +16058,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16057
16058
|
let errorSource;
|
16058
16059
|
let includeDiagAddendum = true;
|
16059
16060
|
if (variance === 3 /* Variance.Covariant */) {
|
16060
|
-
effectiveFlags = flags |
|
16061
|
+
effectiveFlags = flags | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16061
16062
|
errorSource = localize_1.Localizer.DiagnosticAddendum.typeVarIsCovariant;
|
16062
16063
|
}
|
16063
16064
|
else if (variance === 4 /* Variance.Contravariant */) {
|
16064
16065
|
effectiveFlags =
|
16065
|
-
(flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) |
|
16066
|
+
(flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16066
16067
|
errorSource = localize_1.Localizer.DiagnosticAddendum.typeVarIsContravariant;
|
16067
16068
|
}
|
16068
16069
|
else {
|
16069
|
-
effectiveFlags = flags | 1 /* AssignTypeFlags.EnforceInvariance */ |
|
16070
|
+
effectiveFlags = flags | 1 /* AssignTypeFlags.EnforceInvariance */ | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
16070
16071
|
errorSource = localize_1.Localizer.DiagnosticAddendum.typeVarIsInvariant;
|
16071
16072
|
// Omit the diagnostic addendum for the invariant case because it's obvious
|
16072
16073
|
// why two types are not the same.
|
@@ -16189,7 +16190,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16189
16190
|
}
|
16190
16191
|
// Strip flags we don't want to propagate to other calls.
|
16191
16192
|
const originalFlags = flags;
|
16192
|
-
flags &= ~
|
16193
|
+
flags &= ~128 /* AssignTypeFlags.AllowBoolTypeGuard */;
|
16193
16194
|
// Before performing any other checks, see if the dest type is a
|
16194
16195
|
// TypeVar that we are attempting to match.
|
16195
16196
|
if ((0, types_1.isTypeVar)(destType)) {
|
@@ -16414,7 +16415,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16414
16415
|
// PEP 544 says that if the dest type is a type[Proto] class,
|
16415
16416
|
// the source must be a "concrete" (non-protocol) class.
|
16416
16417
|
if (types_1.ClassType.isProtocolClass(destType) &&
|
16417
|
-
(flags &
|
16418
|
+
(flags & 16384 /* AssignTypeFlags.IgnoreProtocolAssignmentCheck */) === 0) {
|
16418
16419
|
if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
|
16419
16420
|
(0, types_1.isInstantiableClass)(srcType) &&
|
16420
16421
|
!srcType.includeSubclasses) {
|
@@ -16466,7 +16467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16466
16467
|
}
|
16467
16468
|
else if (types_1.ClassType.isBuiltIn(destType, 'TypeGuard')) {
|
16468
16469
|
// All the source to be a "bool".
|
16469
|
-
if ((originalFlags &
|
16470
|
+
if ((originalFlags & 128 /* AssignTypeFlags.AllowBoolTypeGuard */) !== 0) {
|
16470
16471
|
if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
|
16471
16472
|
return true;
|
16472
16473
|
}
|
@@ -16560,7 +16561,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16560
16561
|
let concreteSrcType = makeTopLevelTypeVarsConcrete(srcType);
|
16561
16562
|
if ((0, types_1.isClassInstance)(concreteSrcType)) {
|
16562
16563
|
const boundMethod = getBoundMagicMethod(concreteSrcType, '__call__',
|
16563
|
-
/* selfType */ undefined,
|
16564
|
+
/* selfType */ undefined,
|
16565
|
+
/* diag */ undefined, recursionCount);
|
16564
16566
|
if (boundMethod) {
|
16565
16567
|
concreteSrcType = (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
|
16566
16568
|
}
|
@@ -16680,6 +16682,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16680
16682
|
}
|
16681
16683
|
// Sort the subtypes so we have a deterministic order for unions.
|
16682
16684
|
let sortedSrcTypes = (0, typeUtils_1.sortTypes)(srcType.subtypes);
|
16685
|
+
let matchedSomeSubtypes = false;
|
16683
16686
|
// Handle the case where the source and dest are both unions. Try
|
16684
16687
|
// to eliminate as many exact type matches between the src and dest.
|
16685
16688
|
if ((0, types_1.isUnion)(destType)) {
|
@@ -16706,6 +16709,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16706
16709
|
const srcTypeIndex = remainingSrcSubtypes.findIndex((srcSubtype) => (0, types_1.isTypeSame)(srcSubtype, destSubtype, {}, recursionCount));
|
16707
16710
|
if (srcTypeIndex >= 0) {
|
16708
16711
|
remainingSrcSubtypes.splice(srcTypeIndex, 1);
|
16712
|
+
matchedSomeSubtypes = true;
|
16709
16713
|
}
|
16710
16714
|
else {
|
16711
16715
|
remainingDestSubtypes.push(destSubtype);
|
@@ -16743,7 +16747,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16743
16747
|
return false;
|
16744
16748
|
});
|
16745
16749
|
if (destTypeIndex >= 0) {
|
16746
|
-
if (
|
16750
|
+
if (assignType(remainingDestSubtypes[destTypeIndex], srcSubtype, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
16751
|
+
// Note that we have matched at least one subtype indicating
|
16752
|
+
// there is at least some overlap.
|
16753
|
+
matchedSomeSubtypes = true;
|
16754
|
+
}
|
16755
|
+
else {
|
16747
16756
|
canUseFastPath = false;
|
16748
16757
|
}
|
16749
16758
|
remainingDestSubtypes.splice(destTypeIndex, 1);
|
@@ -16781,7 +16790,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16781
16790
|
sortedSrcTypes = remainingSrcSubtypes;
|
16782
16791
|
}
|
16783
16792
|
else if (remainingSrcSubtypes.length === 0) {
|
16784
|
-
if ((flags &
|
16793
|
+
if ((flags & 2048 /* AssignTypeFlags.PopulatingExpectedType */) !== 0) {
|
16785
16794
|
// If we're populating an expected type, try not to leave
|
16786
16795
|
// any TypeVars unsolved. Assign the full type to the remaining
|
16787
16796
|
// dest TypeVars.
|
@@ -16804,6 +16813,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16804
16813
|
if (canUseFastPath) {
|
16805
16814
|
return true;
|
16806
16815
|
}
|
16816
|
+
// If we're looking for type overlaps and at least one type was matched,
|
16817
|
+
// consider it as assignable.
|
16818
|
+
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlapCheck */) !== 0 && matchedSomeSubtypes) {
|
16819
|
+
return true;
|
16820
|
+
}
|
16807
16821
|
}
|
16808
16822
|
let isIncompatible = false;
|
16809
16823
|
sortedSrcTypes.forEach((subtype) => {
|
@@ -16822,8 +16836,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16822
16836
|
isIncompatible = true;
|
16823
16837
|
}
|
16824
16838
|
}
|
16839
|
+
else {
|
16840
|
+
matchedSomeSubtypes = true;
|
16841
|
+
}
|
16825
16842
|
}, /* sortSubtypes */ true);
|
16826
16843
|
if (isIncompatible) {
|
16844
|
+
// If we're looking for type overlaps and at least one type was matched,
|
16845
|
+
// consider it as assignable.
|
16846
|
+
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlapCheck */) !== 0 && matchedSomeSubtypes) {
|
16847
|
+
return true;
|
16848
|
+
}
|
16827
16849
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
|
16828
16850
|
return false;
|
16829
16851
|
}
|
@@ -17061,7 +17083,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17061
17083
|
}
|
17062
17084
|
}
|
17063
17085
|
}
|
17064
|
-
const boundMethod = getBoundMagicMethod(objType, '__call__',
|
17086
|
+
const boundMethod = getBoundMagicMethod(objType, '__call__',
|
17087
|
+
/* selfType */ undefined,
|
17088
|
+
/* diag */ undefined, recursionCount);
|
17065
17089
|
if (boundMethod) {
|
17066
17090
|
return (0, typeUtils_1.removeParamSpecVariadicsFromSignature)(boundMethod);
|
17067
17091
|
}
|
@@ -17094,7 +17118,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17094
17118
|
// Is an additional specialization step required?
|
17095
17119
|
if (doSpecializationStep) {
|
17096
17120
|
assignType(specializedSrcType, specializedDestType,
|
17097
|
-
/* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) |
|
17121
|
+
/* diag */ undefined, srcTypeVarContext, destTypeVarContext, (flags ^ 2 /* AssignTypeFlags.ReverseTypeVarMatching */) | 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */, recursionCount);
|
17098
17122
|
if ((flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) === 0) {
|
17099
17123
|
specializedDestType = (0, typeUtils_1.applySolvedTypeVars)(destType, destTypeVarContext);
|
17100
17124
|
}
|
@@ -17208,9 +17232,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17208
17232
|
function assignFunction(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
|
17209
17233
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
17210
17234
|
let canAssign = true;
|
17211
|
-
const checkReturnType = (flags &
|
17235
|
+
const checkReturnType = (flags & 64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */) === 0;
|
17212
17236
|
const reverseMatching = (flags & 2 /* AssignTypeFlags.ReverseTypeVarMatching */) !== 0;
|
17213
|
-
flags &= ~
|
17237
|
+
flags &= ~64 /* AssignTypeFlags.SkipFunctionReturnTypeCheck */;
|
17214
17238
|
destType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(destType);
|
17215
17239
|
srcType = (0, typeUtils_1.removeParamSpecVariadicsFromFunction)(srcType);
|
17216
17240
|
const destParamDetails = (0, parameterUtils_1.getParameterListDetails)(destType);
|
@@ -17234,17 +17258,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17234
17258
|
const destParamType = destParam.type;
|
17235
17259
|
const destParamName = (_c = destParam.param.name) !== null && _c !== void 0 ? _c : '';
|
17236
17260
|
const srcParamName = (_d = srcParam.param.name) !== null && _d !== void 0 ? _d : '';
|
17237
|
-
if (destParamName
|
17261
|
+
if (destParamName) {
|
17238
17262
|
const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
|
17239
17263
|
if (!isDestPositionalOnly &&
|
17240
17264
|
destParam.param.category !== 1 /* ParameterCategory.ArgsList */ &&
|
17241
|
-
srcParam.param.category !== 1 /* ParameterCategory.ArgsList */
|
17242
|
-
|
17243
|
-
|
17244
|
-
|
17245
|
-
|
17246
|
-
|
17247
|
-
|
17265
|
+
srcParam.param.category !== 1 /* ParameterCategory.ArgsList */) {
|
17266
|
+
if (srcParam.source === parameterUtils_1.ParameterSource.PositionOnly) {
|
17267
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamPositionOnly().format({
|
17268
|
+
name: destParamName,
|
17269
|
+
}));
|
17270
|
+
canAssign = false;
|
17271
|
+
}
|
17272
|
+
else if (destParamName !== srcParamName) {
|
17273
|
+
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamName().format({
|
17274
|
+
srcName: srcParamName,
|
17275
|
+
destName: destParamName,
|
17276
|
+
}));
|
17277
|
+
canAssign = false;
|
17278
|
+
}
|
17248
17279
|
}
|
17249
17280
|
}
|
17250
17281
|
if (!!destParam.param.hasDefault &&
|
@@ -17269,7 +17300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17269
17300
|
if (!assignFunctionParameter(destParamType, srcParamType, paramIndex, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
|
17270
17301
|
// Handle the special case where the source parameter is a synthesized
|
17271
17302
|
// TypeVar for "self" or "cls".
|
17272
|
-
if ((flags &
|
17303
|
+
if ((flags & 512 /* AssignTypeFlags.SkipSelfClsTypeCheck */) === 0 ||
|
17273
17304
|
!(0, types_1.isTypeVar)(srcParamType) ||
|
17274
17305
|
!srcParamType.details.isSynthesized) {
|
17275
17306
|
canAssign = false;
|
@@ -17599,7 +17630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17599
17630
|
// solver to retain literals.
|
17600
17631
|
if (srcType.details.declaredReturnType &&
|
17601
17632
|
(0, typeUtils_1.containsLiteralType)(srcType.details.declaredReturnType, /* includeTypeArgs */ true)) {
|
17602
|
-
effectiveFlags |=
|
17633
|
+
effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
|
17603
17634
|
}
|
17604
17635
|
if ((0, types_1.isNever)(srcReturnType)) {
|
17605
17636
|
// We'll allow any function that returns NoReturn to match any
|
@@ -18343,7 +18374,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18343
18374
|
}
|
18344
18375
|
}
|
18345
18376
|
else if (!assignType(memberTypeFirstParamType, firstParamType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), typeVarContext,
|
18346
|
-
/* srcTypeVarContext */ undefined,
|
18377
|
+
/* srcTypeVarContext */ undefined, 8192 /* AssignTypeFlags.AllowUnspecifiedTypeArguments */, recursionCount)) {
|
18347
18378
|
if (memberTypeFirstParam.name &&
|
18348
18379
|
!memberTypeFirstParam.isNameSynthesized &&
|
18349
18380
|
memberTypeFirstParam.hasDeclaredType) {
|
@@ -18415,6 +18446,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18415
18446
|
case 31 /* ParseNodeType.List */:
|
18416
18447
|
case 45 /* ParseNodeType.Set */:
|
18417
18448
|
return false;
|
18449
|
+
case 7 /* ParseNodeType.BinaryOperation */:
|
18450
|
+
return (node.operator === 6 /* OperatorType.BitwiseOr */ &&
|
18451
|
+
isLegalTypeAliasExpressionForm(node.leftExpression) &&
|
18452
|
+
isLegalTypeAliasExpressionForm(node.rightExpression));
|
18453
|
+
case 24 /* ParseNodeType.Index */:
|
18454
|
+
return isLegalTypeAliasExpressionForm(node.baseExpression);
|
18455
|
+
case 35 /* ParseNodeType.MemberAccess */:
|
18456
|
+
return isLegalTypeAliasExpressionForm(node.leftExpression);
|
18418
18457
|
}
|
18419
18458
|
return true;
|
18420
18459
|
}
|