Skip to content

Commit

Permalink
Fixed another ParamSpec-related issue. This addresses #5454.
Browse files Browse the repository at this point in the history
  • Loading branch information
msfterictraut committed Jul 11, 2023
1 parent 3a34332 commit 7a01bd8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9384,6 +9384,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
paramSpecScopeId === typeResult.type.details.typeVarScopeId ||
paramSpecScopeId === typeResult.type.details.constructorTypeVarScopeId
) {
hasParamSpecArgsKwargs = true;
paramSpecArgList = [];
paramSpecTarget = TypeVarType.cloneForParamSpecAccess(
typeResult.type.details.paramSpec,
Expand Down Expand Up @@ -10041,20 +10042,24 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
reportedArgError = true;
}
} else if (argList[argIndex].argumentCategory === ArgumentCategory.Simple) {
if (!isDiagnosticSuppressedForNode(errorNode)) {
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
addDiagnostic(
fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
DiagnosticRule.reportGeneralTypeIssues,
positionParamLimitIndex === 1
? Localizer.Diagnostic.argPositionalExpectedOne()
: Localizer.Diagnostic.argPositionalExpectedCount().format({
expected: positionParamLimitIndex,
}),
argList[argIndex].valueExpression || errorNode
);
if (paramSpecArgList) {
paramSpecArgList.push(argList[argIndex]);
} else {
if (!isDiagnosticSuppressedForNode(errorNode)) {
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
addDiagnostic(
fileInfo.diagnosticRuleSet.reportGeneralTypeIssues,
DiagnosticRule.reportGeneralTypeIssues,
positionParamLimitIndex === 1
? Localizer.Diagnostic.argPositionalExpectedOne()
: Localizer.Diagnostic.argPositionalExpectedCount().format({
expected: positionParamLimitIndex,
}),
argList[argIndex].valueExpression || errorNode
);
}
reportedArgError = true;
}
reportedArgError = true;
} else if (argList[argIndex].argumentCategory === ArgumentCategory.UnpackedList) {
// Handle the case where a *args: P.args is passed as an argument to
// a function that accepts a ParamSpec.
Expand Down
11 changes: 11 additions & 0 deletions packages/pyright-internal/src/tests/samples/paramSpec45.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ def func3(y: str) -> int:


print(func1(func2, x="..."), func1(func3, y="..."))


def func4(fn: Callable[P, int], *args: P.args, **kwargs: P.kwargs) -> int:
return fn(*args, **kwargs)


def func5(x: int, y: int) -> int:
return x + y


func5(func4(lambda x: x, 1), func4(lambda x, y: x + y, 2, 3))

0 comments on commit 7a01bd8

Please sign in to comment.