@zzzen/pyright-internal 1.2.0-dev.20231105 → 1.2.0-dev.20231119
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +76 -77
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +12 -33
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +30 -21
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +3 -5
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.d.ts +6 -3
- package/dist/analyzer/constructors.js +53 -29
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +10 -15
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +6 -3
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/decorators.js +1 -1
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +1 -1
- package/dist/analyzer/docStringConversion.js.map +1 -1
- package/dist/analyzer/docStringUtils.js +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -1
- package/dist/analyzer/importResolver.js +23 -6
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +1 -1
- package/dist/analyzer/importStatementUtils.js +33 -5
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/operations.js +12 -6
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +9 -5
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +17 -2
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +20 -15
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +19 -12
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +20 -23
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +1 -1
- package/dist/analyzer/protocols.js +14 -18
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +1 -2
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.js +33 -2
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -1
- package/dist/analyzer/sourceFileInfoUtils.js +9 -3
- package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +3 -0
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +3 -1
- package/dist/analyzer/typeEvaluator.js +561 -574
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -2
- package/dist/analyzer/typeGuards.js +26 -11
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.js +43 -1
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.d.ts +1 -0
- package/dist/analyzer/typeVarContext.js +3 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/types.d.ts +4 -2
- package/dist/analyzer/types.js +13 -5
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +18 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +3 -0
- package/dist/common/serviceProviderExtensions.d.ts +2 -1
- package/dist/common/serviceProviderExtensions.js +1 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/textEditTracker.js +2 -2
- package/dist/common/textEditTracker.js.map +1 -1
- package/dist/languageServerBase.d.ts +4 -4
- package/dist/languageServerBase.js +10 -7
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -1
- package/dist/languageService/completionProvider.js +9 -13
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +7 -3
- package/dist/localization/localize.js +5 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -2
- package/dist/localization/package.nls.de.json +5 -2
- package/dist/localization/package.nls.en-us.json +11 -7
- package/dist/localization/package.nls.es.json +5 -2
- package/dist/localization/package.nls.fr.json +5 -2
- package/dist/localization/package.nls.it.json +5 -2
- package/dist/localization/package.nls.ja.json +5 -2
- package/dist/localization/package.nls.ko.json +5 -2
- package/dist/localization/package.nls.pl.json +5 -2
- package/dist/localization/package.nls.pt-br.json +5 -2
- package/dist/localization/package.nls.qps-ploc.json +5 -2
- package/dist/localization/package.nls.ru.json +5 -2
- package/dist/localization/package.nls.tr.json +5 -2
- package/dist/localization/package.nls.zh-cn.json +5 -2
- package/dist/localization/package.nls.zh-tw.json +5 -2
- package/dist/pyright.js +17 -1
- package/dist/pyright.js.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tests/config.test.js +7 -5
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +4 -2
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +0 -22
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/completions.params.fourslash.js +11 -0
- package/dist/tests/fourslash/completions.params.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js +10 -0
- package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
- package/dist/tests/fourslash/signature.dunderNew.fourslash.js +1 -1
- package/dist/tests/fourslash/signature.dunderNew.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +3 -3
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +15 -0
- package/dist/tests/parseTreeUtils.test.js.map +1 -1
- package/dist/tests/textEditUtil.test.js +25 -0
- package/dist/tests/textEditUtil.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +8 -0
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +3 -3
- package/dist/tests/typeEvaluator4.test.js +6 -6
- package/package.json +1 -1
@@ -115,6 +115,7 @@ export declare class Checker extends ParseTreeWalker {
|
|
115
115
|
private _validateTypeGuardFunction;
|
116
116
|
private _validateDunderSignatures;
|
117
117
|
private _validateFunctionReturn;
|
118
|
+
private _validateReturnTypeIsNotContravariant;
|
118
119
|
private _reportUnknownReturnResult;
|
119
120
|
private _validateFinalMemberOverrides;
|
120
121
|
private _reportDuplicateEnumMembers;
|
package/dist/analyzer/checker.js
CHANGED
@@ -46,6 +46,7 @@ const localize_1 = require("../localization/localize");
|
|
46
46
|
const parseNodes_1 = require("../parser/parseNodes");
|
47
47
|
const stringTokenUtils_1 = require("../parser/stringTokenUtils");
|
48
48
|
const AnalyzerNodeInfo = __importStar(require("./analyzerNodeInfo"));
|
49
|
+
const constructors_1 = require("./constructors");
|
49
50
|
const declaration_1 = require("./declaration");
|
50
51
|
const declarationUtils_1 = require("./declarationUtils");
|
51
52
|
const deprecatedSymbols_1 = require("./deprecatedSymbols");
|
@@ -176,7 +177,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
176
177
|
this._validateBaseClassOverrides(classTypeResult.classType);
|
177
178
|
this._validateMultipleInheritanceBaseClasses(classTypeResult.classType, node.name);
|
178
179
|
this._validateMultipleInheritanceCompatibility(classTypeResult.classType, node.name);
|
179
|
-
this._validateConstructorConsistency(classTypeResult.classType);
|
180
|
+
this._validateConstructorConsistency(classTypeResult.classType, node.name);
|
180
181
|
this._validateFinalMemberOverrides(classTypeResult.classType);
|
181
182
|
this._validateInstanceVariableInitialization(node, classTypeResult.classType);
|
182
183
|
this._validateFinalClassNotAbstract(classTypeResult.classType, node);
|
@@ -2460,21 +2461,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2460
2461
|
return;
|
2461
2462
|
}
|
2462
2463
|
let isValidType = true;
|
2464
|
+
const diag = new diagnostic_1.DiagnosticAddendum();
|
2463
2465
|
(0, typeUtils_1.doForEachSubtype)(arg1Type, (arg1Subtype) => {
|
2464
2466
|
if ((0, types_1.isClassInstance)(arg1Subtype) && types_1.ClassType.isTupleClass(arg1Subtype) && arg1Subtype.tupleTypeArguments) {
|
2465
|
-
if (arg1Subtype.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck))) {
|
2467
|
+
if (arg1Subtype.tupleTypeArguments.some((typeArg) => !this._isTypeSupportedTypeForIsInstance(typeArg.type, isInstanceCheck, diag))) {
|
2466
2468
|
isValidType = false;
|
2467
2469
|
}
|
2468
2470
|
}
|
2469
2471
|
else {
|
2470
|
-
if (!this._isTypeSupportedTypeForIsInstance(arg1Subtype, isInstanceCheck)) {
|
2472
|
+
if (!this._isTypeSupportedTypeForIsInstance(arg1Subtype, isInstanceCheck, diag)) {
|
2471
2473
|
isValidType = false;
|
2472
2474
|
}
|
2473
2475
|
}
|
2474
2476
|
});
|
2475
2477
|
if (!isValidType) {
|
2476
|
-
const diag = new diagnostic_1.DiagnosticAddendum();
|
2477
|
-
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarNotAllowed());
|
2478
2478
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, isInstanceCheck
|
2479
2479
|
? localize_1.Localizer.Diagnostic.isInstanceInvalidType().format({
|
2480
2480
|
type: this._evaluator.printType(arg1Type),
|
@@ -2555,12 +2555,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2555
2555
|
if (!isValidType) {
|
2556
2556
|
return;
|
2557
2557
|
}
|
2558
|
-
// According to PEP 544, protocol classes cannot be used as the right-hand
|
2559
|
-
// argument to isinstance or issubclass unless they are annotated as
|
2560
|
-
// "runtime checkable".
|
2561
|
-
if (classTypeList.some((type) => types_1.ClassType.isProtocolClass(type) && !types_1.ClassType.isRuntimeCheckable(type))) {
|
2562
|
-
this._evaluator.addError(localize_1.Localizer.Diagnostic.protocolUsedInCall().format({ name: callName }), node.arguments[1].valueExpression);
|
2563
|
-
}
|
2564
2558
|
if ((0, typeUtils_1.derivesFromAnyOrUnknown)(arg0Type)) {
|
2565
2559
|
return;
|
2566
2560
|
}
|
@@ -2651,7 +2645,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2651
2645
|
}
|
2652
2646
|
// Determines whether the specified type is allowed as the second argument
|
2653
2647
|
// to an isinstance or issubclass check.
|
2654
|
-
_isTypeSupportedTypeForIsInstance(type, isInstanceCheck) {
|
2648
|
+
_isTypeSupportedTypeForIsInstance(type, isInstanceCheck, diag) {
|
2655
2649
|
let isSupported = true;
|
2656
2650
|
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
2657
2651
|
subtype = this._evaluator.makeTopLevelTypeVarsConcrete(subtype);
|
@@ -2663,23 +2657,33 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
2663
2657
|
break;
|
2664
2658
|
case 6 /* Class */:
|
2665
2659
|
if ((0, typeUtils_1.isNoneInstance)(subtype)) {
|
2660
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.noneNotAllowed());
|
2666
2661
|
isSupported = false;
|
2667
2662
|
}
|
2668
2663
|
else if (subtype.isTypeArgumentExplicit && !subtype.includeSubclasses) {
|
2669
2664
|
// If it's a class, make sure that it has not been given explicit
|
2670
2665
|
// type arguments. This will result in a TypeError exception.
|
2666
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.genericClassNotAllowed());
|
2667
|
+
isSupported = false;
|
2668
|
+
}
|
2669
|
+
else if (types_1.ClassType.isProtocolClass(subtype) &&
|
2670
|
+
!types_1.ClassType.isRuntimeCheckable(subtype) &&
|
2671
|
+
!subtype.includeSubclasses) {
|
2672
|
+
// According to PEP 544, protocol classes cannot be used as the right-hand
|
2673
|
+
// argument to isinstance or issubclass unless they are annotated as
|
2674
|
+
// "runtime checkable".
|
2675
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.protocolRequiresRuntimeCheckable());
|
2671
2676
|
isSupported = false;
|
2672
2677
|
}
|
2673
2678
|
break;
|
2674
2679
|
case 4 /* Function */:
|
2675
2680
|
if (!types_1.TypeBase.isInstantiable(subtype) || subtype.isCallableWithTypeArgs) {
|
2681
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.genericClassNotAllowed());
|
2676
2682
|
isSupported = false;
|
2677
2683
|
}
|
2678
2684
|
break;
|
2679
|
-
case
|
2680
|
-
|
2681
|
-
break;
|
2682
|
-
default:
|
2685
|
+
case 9 /* TypeVar */:
|
2686
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeVarNotAllowed());
|
2683
2687
|
isSupported = false;
|
2684
2688
|
break;
|
2685
2689
|
}
|
@@ -3156,10 +3160,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3156
3160
|
let declaredReturnType = functionType.details.declaredReturnType;
|
3157
3161
|
if (declaredReturnType) {
|
3158
3162
|
this._reportUnknownReturnResult(node, declaredReturnType);
|
3159
|
-
|
3160
|
-
declaredReturnType.details.declaredVariance === 4 /* Contravariant */) {
|
3161
|
-
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnTypeContravariant(), returnAnnotation);
|
3162
|
-
}
|
3163
|
+
this._validateReturnTypeIsNotContravariant(declaredReturnType, returnAnnotation);
|
3163
3164
|
}
|
3164
3165
|
// Wrap the declared type in a generator type if the function is a generator.
|
3165
3166
|
if (types_1.FunctionType.isGenerator(functionType)) {
|
@@ -3200,6 +3201,18 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3200
3201
|
else {
|
3201
3202
|
const inferredReturnType = this._evaluator.getFunctionInferredReturnType(functionType);
|
3202
3203
|
this._reportUnknownReturnResult(node, inferredReturnType);
|
3204
|
+
this._validateReturnTypeIsNotContravariant(inferredReturnType, node.name);
|
3205
|
+
}
|
3206
|
+
}
|
3207
|
+
_validateReturnTypeIsNotContravariant(returnType, errorNode) {
|
3208
|
+
let isContraTypeVar = false;
|
3209
|
+
(0, typeUtils_1.doForEachSubtype)(returnType, (subtype) => {
|
3210
|
+
if ((0, types_1.isTypeVar)(subtype) && subtype.details.declaredVariance === 4 /* Contravariant */) {
|
3211
|
+
isContraTypeVar = true;
|
3212
|
+
}
|
3213
|
+
});
|
3214
|
+
if (isContraTypeVar) {
|
3215
|
+
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.returnTypeContravariant(), errorNode);
|
3203
3216
|
}
|
3204
3217
|
}
|
3205
3218
|
_reportUnknownReturnResult(node, returnType) {
|
@@ -3626,35 +3639,34 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3626
3639
|
});
|
3627
3640
|
}
|
3628
3641
|
// Validates that the __init__ and __new__ method signatures are consistent.
|
3629
|
-
_validateConstructorConsistency(classType) {
|
3630
|
-
|
3631
|
-
const
|
3632
|
-
if (
|
3642
|
+
_validateConstructorConsistency(classType, errorNode) {
|
3643
|
+
// If the class has a custom metaclass with a __call__ method, skip this check.
|
3644
|
+
const callMethodResult = (0, constructors_1.getBoundCallMethod)(this._evaluator, errorNode, classType);
|
3645
|
+
if (callMethodResult) {
|
3633
3646
|
return;
|
3634
3647
|
}
|
3635
|
-
|
3636
|
-
|
3637
|
-
|
3638
|
-
!
|
3648
|
+
const newMethodResult = (0, constructors_1.getBoundNewMethod)(this._evaluator, errorNode, classType);
|
3649
|
+
if (!newMethodResult ||
|
3650
|
+
newMethodResult.typeErrors ||
|
3651
|
+
!newMethodResult.classType ||
|
3652
|
+
!(0, types_1.isClass)(newMethodResult.classType)) {
|
3639
3653
|
return;
|
3640
3654
|
}
|
3641
|
-
|
3642
|
-
|
3643
|
-
|
3644
|
-
|
3645
|
-
|
3646
|
-
|
3647
|
-
return;
|
3648
|
-
}
|
3655
|
+
const initMethodResult = (0, constructors_1.getBoundInitMethod)(this._evaluator, errorNode, types_1.ClassType.cloneAsInstance(classType));
|
3656
|
+
if (!initMethodResult ||
|
3657
|
+
initMethodResult.typeErrors ||
|
3658
|
+
!initMethodResult.classType ||
|
3659
|
+
!(0, types_1.isClass)(initMethodResult.classType)) {
|
3660
|
+
return;
|
3649
3661
|
}
|
3650
|
-
|
3651
|
-
|
3662
|
+
// If both the __new__ and __init__ come from subclasses, don't bother
|
3663
|
+
// checking for this class.
|
3664
|
+
if (!types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType) &&
|
3665
|
+
!types_1.ClassType.isSameGenericClass(newMethodResult.classType, classType)) {
|
3652
3666
|
return;
|
3653
3667
|
}
|
3654
|
-
newMemberType =
|
3655
|
-
|
3656
|
-
/* treatConstructorAsClassMember */ true);
|
3657
|
-
if (!newMemberType) {
|
3668
|
+
let newMemberType = newMethodResult.type;
|
3669
|
+
if (!(0, types_1.isFunction)(newMemberType) && !(0, types_1.isOverloadedFunction)(newMemberType)) {
|
3658
3670
|
return;
|
3659
3671
|
}
|
3660
3672
|
if ((0, types_1.isOverloadedFunction)(newMemberType)) {
|
@@ -3664,14 +3676,10 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3664
3676
|
return;
|
3665
3677
|
}
|
3666
3678
|
}
|
3667
|
-
let initMemberType =
|
3679
|
+
let initMemberType = initMethodResult.type;
|
3668
3680
|
if (!(0, types_1.isFunction)(initMemberType) && !(0, types_1.isOverloadedFunction)(initMemberType)) {
|
3669
3681
|
return;
|
3670
3682
|
}
|
3671
|
-
initMemberType = this._evaluator.bindFunctionToClassOrObject(types_1.ClassType.cloneAsInstance(classType), initMemberType);
|
3672
|
-
if (!initMemberType) {
|
3673
|
-
return;
|
3674
|
-
}
|
3675
3683
|
if ((0, types_1.isOverloadedFunction)(initMemberType)) {
|
3676
3684
|
// Find the implementation, not the overloaded signatures.
|
3677
3685
|
initMemberType = types_1.OverloadedFunctionType.getImplementation(initMemberType);
|
@@ -3679,9 +3687,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3679
3687
|
return;
|
3680
3688
|
}
|
3681
3689
|
}
|
3682
|
-
if (!(0, types_1.isFunction)(initMemberType) || !(0, types_1.isFunction)(newMemberType)) {
|
3683
|
-
return;
|
3684
|
-
}
|
3685
3690
|
// If either of the functions has a default parameter signature
|
3686
3691
|
// (* args: Any, ** kwargs: Any), don't proceed with the check.
|
3687
3692
|
if (types_1.FunctionType.hasDefaultParameters(initMemberType) || types_1.FunctionType.hasDefaultParameters(newMemberType)) {
|
@@ -3704,9 +3709,9 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3704
3709
|
/* diag */ undefined,
|
3705
3710
|
/* destTypeVarContext */ undefined,
|
3706
3711
|
/* srcTypeVarContext */ undefined, 32 /* SkipFunctionReturnTypeCheck */)) {
|
3707
|
-
const displayOnInit = types_1.ClassType.isSameGenericClass(
|
3708
|
-
const initDecl =
|
3709
|
-
const newDecl =
|
3712
|
+
const displayOnInit = types_1.ClassType.isSameGenericClass(initMethodResult.classType, classType);
|
3713
|
+
const initDecl = initMemberType.details.declaration;
|
3714
|
+
const newDecl = newMemberType.details.declaration;
|
3710
3715
|
if (initDecl && newDecl) {
|
3711
3716
|
const mainDecl = displayOnInit ? initDecl : newDecl;
|
3712
3717
|
const mainDeclNode = mainDecl.node.nodeType === 28 /* Function */ ? mainDecl.node.name : mainDecl.node;
|
@@ -3720,14 +3725,14 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3720
3725
|
type: newSignature,
|
3721
3726
|
}));
|
3722
3727
|
const diagnostic = this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportInconsistentConstructor, diagnosticRules_1.DiagnosticRule.reportInconsistentConstructor, localize_1.Localizer.Diagnostic.constructorParametersMismatch().format({
|
3723
|
-
classType: this._evaluator.printType(types_1.ClassType.cloneAsInstance(displayOnInit ?
|
3728
|
+
classType: this._evaluator.printType(types_1.ClassType.cloneAsInstance(displayOnInit ? initMethodResult.classType : newMethodResult.classType)),
|
3724
3729
|
}) + diagAddendum.getString(), mainDeclNode);
|
3725
3730
|
if (diagnostic) {
|
3726
3731
|
const secondaryDecl = displayOnInit ? newDecl : initDecl;
|
3727
3732
|
diagnostic.addRelatedInfo((displayOnInit
|
3728
3733
|
? localize_1.Localizer.DiagnosticAddendum.newMethodLocation()
|
3729
3734
|
: localize_1.Localizer.DiagnosticAddendum.initMethodLocation()).format({
|
3730
|
-
type: this._evaluator.printType(types_1.ClassType.cloneAsInstance(displayOnInit ?
|
3735
|
+
type: this._evaluator.printType(types_1.ClassType.cloneAsInstance(displayOnInit ? newMethodResult.classType : initMethodResult.classType)),
|
3731
3736
|
}), secondaryDecl.path, secondaryDecl.range);
|
3732
3737
|
}
|
3733
3738
|
}
|
@@ -3996,7 +4001,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
3996
4001
|
});
|
3997
4002
|
}
|
3998
4003
|
_validateOverrideDecoratorPresent(symbol, overrideType, baseMember) {
|
3999
|
-
var _a;
|
4000
4004
|
// Skip this check if disabled.
|
4001
4005
|
if (this._fileInfo.diagnosticRuleSet.reportImplicitOverride === 'none') {
|
4002
4006
|
return;
|
@@ -4009,12 +4013,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4009
4013
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4010
4014
|
}
|
4011
4015
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4012
|
-
|
4013
|
-
|
4014
|
-
const fgetType = (_a = this._evaluator.getDeclaredTypeOfSymbol(fgetSymbol)) === null || _a === void 0 ? void 0 : _a.type;
|
4015
|
-
if (fgetType && (0, types_1.isFunction)(fgetType)) {
|
4016
|
-
overrideFunction = fgetType;
|
4017
|
-
}
|
4016
|
+
if (overrideType.fgetFunction) {
|
4017
|
+
overrideFunction = overrideType.fgetFunction;
|
4018
4018
|
}
|
4019
4019
|
}
|
4020
4020
|
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.details.declaration) || types_1.FunctionType.isOverridden(overrideFunction)) {
|
@@ -4039,7 +4039,6 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4039
4039
|
// decorator. In this case, an error is reported because no base class has declared
|
4040
4040
|
// a method of the same name.
|
4041
4041
|
_validateOverrideDecoratorNotPresent(symbol, overrideType) {
|
4042
|
-
var _a;
|
4043
4042
|
let overrideFunction;
|
4044
4043
|
if ((0, types_1.isFunction)(overrideType)) {
|
4045
4044
|
overrideFunction = overrideType;
|
@@ -4048,12 +4047,8 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4048
4047
|
overrideFunction = types_1.OverloadedFunctionType.getImplementation(overrideType);
|
4049
4048
|
}
|
4050
4049
|
else if ((0, types_1.isClassInstance)(overrideType) && types_1.ClassType.isPropertyClass(overrideType)) {
|
4051
|
-
|
4052
|
-
|
4053
|
-
const fgetType = (_a = this._evaluator.getDeclaredTypeOfSymbol(fgetSymbol)) === null || _a === void 0 ? void 0 : _a.type;
|
4054
|
-
if (fgetType && (0, types_1.isFunction)(fgetType)) {
|
4055
|
-
overrideFunction = fgetType;
|
4056
|
-
}
|
4050
|
+
if (overrideType.fgetFunction) {
|
4051
|
+
overrideFunction = overrideType.fgetFunction;
|
4057
4052
|
}
|
4058
4053
|
}
|
4059
4054
|
if (!(overrideFunction === null || overrideFunction === void 0 ? void 0 : overrideFunction.details.declaration) || !types_1.FunctionType.isOverridden(overrideFunction)) {
|
@@ -4171,16 +4166,20 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4171
4166
|
}
|
4172
4167
|
}
|
4173
4168
|
else {
|
4174
|
-
const basePropFields = baseType.details.fields;
|
4175
|
-
const subclassPropFields = overrideType.details.fields;
|
4176
4169
|
const baseClassType = baseClass;
|
4177
|
-
|
4170
|
+
const propMethodInfo = [
|
4171
|
+
['fget', (c) => c.fgetFunction],
|
4172
|
+
['fset', (c) => c.fsetFunction],
|
4173
|
+
['fdel', (c) => c.fdelFunction],
|
4174
|
+
];
|
4175
|
+
propMethodInfo.forEach((info) => {
|
4178
4176
|
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
4179
|
-
const
|
4180
|
-
const
|
4177
|
+
const [methodName, methodAccessor] = info;
|
4178
|
+
const baseClassPropMethod = methodAccessor(baseType);
|
4179
|
+
const subclassPropMethod = methodAccessor(overrideType);
|
4181
4180
|
// Is the method present on the base class but missing in the subclass?
|
4182
4181
|
if (baseClassPropMethod) {
|
4183
|
-
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(
|
4182
|
+
const baseClassMethodType = (0, typeUtils_1.partiallySpecializeType)(baseClassPropMethod, baseClassType);
|
4184
4183
|
if ((0, types_1.isFunction)(baseClassMethodType)) {
|
4185
4184
|
if (!subclassPropMethod) {
|
4186
4185
|
// The method is missing.
|
@@ -4200,7 +4199,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4200
4199
|
}
|
4201
4200
|
}
|
4202
4201
|
else {
|
4203
|
-
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(
|
4202
|
+
const subclassMethodType = (0, typeUtils_1.partiallySpecializeType)(subclassPropMethod, childClassType);
|
4204
4203
|
if ((0, types_1.isFunction)(subclassMethodType)) {
|
4205
4204
|
if (!this._evaluator.validateOverrideMethod(baseClassMethodType, subclassMethodType, childClassType, diagAddendum.createAddendum())) {
|
4206
4205
|
diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.propertyMethodIncompatible().format({
|
@@ -4331,7 +4330,7 @@ class Checker extends parseTreeWalker_1.ParseTreeWalker {
|
|
4331
4330
|
// __new__ overrides should have a "cls" parameter.
|
4332
4331
|
if (node.parameters.length === 0 ||
|
4333
4332
|
!node.parameters[0].name ||
|
4334
|
-
!['cls', '_cls', '__cls', '__mcls', 'mcls', 'mcs'].some((name) => node.parameters[0].name.value === name)) {
|
4333
|
+
!['cls', '_cls', '__cls', '__mcls', 'mcls', 'mcs', 'metacls'].some((name) => node.parameters[0].name.value === name)) {
|
4335
4334
|
this._evaluator.addDiagnostic(this._fileInfo.diagnosticRuleSet.reportSelfClsParameterName, diagnosticRules_1.DiagnosticRule.reportSelfClsParameterName, localize_1.Localizer.Diagnostic.newClsParam(), node.parameters.length > 0 ? node.parameters[0] : node.name);
|
4336
4335
|
}
|
4337
4336
|
if (classType) {
|