Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed recent regression that results in a spurious type error when ac… #9264

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/pyright-internal/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,9 @@ export function getUnknownTypeForCallable(): FunctionType {
// "self specializes" the class, filling in its own type parameters
// as type arguments.
export function selfSpecializeClass(type: ClassType, options?: SelfSpecializeOptions): ClassType {
if (!requiresTypeArgs(type)) {
// We can't use requiresTypeArgs(type) here because it returns false
// if the type parameters have default values.
if (type.shared.typeParams.length === 0) {
return type;
}

Expand Down
17 changes: 17 additions & 0 deletions packages/pyright-internal/src/tests/samples/self11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This sample tests a case where "self" refers to a class with type
# parameters that have default values. This is a case that regressed.


class Base: ...


class A(Base): ...


class B[T: Base = A]:
def __init__(self, x: T) -> None:
self._x = x

@property
def x(self) -> T:
return self._x
6 changes: 6 additions & 0 deletions packages/pyright-internal/src/tests/typeEvaluator8.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ test('Self10', () => {
TestUtils.validateResults(analysisResults, 2);
});

test('Self11', () => {
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['self11.py']);

TestUtils.validateResults(analysisResults, 0);
});

test('UnusedVariable1', () => {
const configOptions = new ConfigOptions(Uri.empty());

Expand Down
Loading