forked from microsoft/pyright
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug that caused incorrect type inference for parameters in un…
…annotated methods within child classes who derive from a generic parent class. This addresses a bug reported on stack overflow: https://stackoverflow.com/questions/76466874/trouble-specifying-type-parameter-when-inheriting-from-generic-class.
- Loading branch information
1 parent
43c5fae
commit eff69f5
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/pyright-internal/src/tests/samples/paramInference2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# This sample tests the logic that infers parameter types based on | ||
# annotated base class methods when the base class is generic. | ||
|
||
|
||
from typing import Generic, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
class Parent(Generic[T]): | ||
def method1(self, a: T, b: list[T]) -> None: | ||
... | ||
|
||
|
||
class Child(Parent[float]): | ||
def method1(self, a, b): | ||
reveal_type(self, expected_text="Self@Child") | ||
reveal_type(a, expected_text="float") | ||
reveal_type(b, expected_text="list[float]") | ||
return a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters