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 a bug that results in a false positive when a class parameteriz… #9342

Merged
merged 1 commit into from
Oct 28, 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: 4 additions & 0 deletions packages/pyright-internal/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ export function selfSpecializeClass(type: ClassType, options?: SelfSpecializeOpt
}

const typeParams = type.shared.typeParams.map((typeParam) => {
if (isTypeVarTuple(typeParam)) {
typeParam = TypeVarType.cloneForUnpacked(typeParam);
}

return options?.useBoundTypeVars ? TypeVarType.cloneAsBound(typeParam) : typeParam;
});
return ClassType.specialize(type, typeParams);
Expand Down
11 changes: 11 additions & 0 deletions packages/pyright-internal/src/tests/samples/typeVarTuple30.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This sample tests the case where a TypeVarTuple is used in a class
# and a `Self` type is involved.

class Parent[*Ts]:
def __init__(self, *args: *Ts): ...

def method(self):
Child(self)


class Child(Parent[*tuple[Parent, ...]]): ...
8 changes: 8 additions & 0 deletions packages/pyright-internal/src/tests/typeEvaluator6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,14 @@ test('TypeVarTuple29', () => {
TestUtils.validateResults(analysisResults, 0);
});

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

configOptions.defaultPythonVersion = pythonVersion3_12;
const analysisResults = TestUtils.typeAnalyzeSampleFiles(['typeVarTuple30.py'], configOptions);
TestUtils.validateResults(analysisResults, 0);
});

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

Expand Down
Loading