Skip to content

Commit

Permalink
Fixed bug that results in a crash under certain circumstances when a …
Browse files Browse the repository at this point in the history
…ParamSpec without a scope is used illegally to specialize a class. This addresses #8757.
  • Loading branch information
erictraut committed Aug 16, 2024
1 parent deaf264 commit 8067c7c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10287,7 +10287,7 @@ export function createTypeEvaluator(
paramSpecTarget = TypeVarType.cloneForParamSpecAccess(varArgListParamType, /* access */ undefined);
} else {
positionalOnlyLimitIndex = varArgListParamIndex;
positionalArgCount = varArgListParamIndex;
positionalArgCount = Math.min(varArgListParamIndex, positionalArgCount);
positionParamLimitIndex = varArgListParamIndex;
}
}
Expand Down
20 changes: 20 additions & 0 deletions packages/pyright-internal/src/tests/samples/paramSpec52.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This sample tests an illegal use of a ParamSpec that resulted in
# a crash.

from typing import Callable, Generic, ParamSpec

P = ParamSpec("P")


class A(Generic[P]):
def __call__(self, a: int, b: int, *args: P.args, **kwargs: P.kwargs) -> None:
...


class B:
# This should generate an error.
x: A[P]


# This should generate an error, not crash.
B().x(1)
5 changes: 5 additions & 0 deletions packages/pyright-internal/src/tests/typeEvaluator4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,8 @@ test('ParamSpec51', () => {
const results = TestUtils.typeAnalyzeSampleFiles(['paramSpec51.py']);
TestUtils.validateResults(results, 0);
});

test('ParamSpec52', () => {
const results = TestUtils.typeAnalyzeSampleFiles(['paramSpec52.py']);
TestUtils.validateResults(results, 2);
});

0 comments on commit 8067c7c

Please sign in to comment.