Skip to content

Commit

Permalink
Add a test case for no overload overlap with self-types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilevkivskyi committed Jun 15, 2024
1 parent 740d39e commit 8a8103a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -4542,6 +4542,23 @@ reveal_type(Child().foo("...")) # N: Revealed type is "builtins.st
reveal_type(Child().foo(x)) # N: Revealed type is "Union[__main__.Child, builtins.str]"
reveal_type(Child().foo(3).child_only()) # N: Revealed type is "builtins.int"

[case testOverloadAndSelfTypesGenericNoOverlap]
from typing import Generic, TypeVar, Any, overload, Self, Union

T = TypeVar("T", bound=Any)
class C(Generic[T]):
@overload
def get(self, obj: None) -> Self: ...
@overload
def get(self, obj: Any) -> T: ...
def get(self, obj: Union[Any, None]) -> Union[T, Self]:
return self

class D(C[int]): ...
d: D
reveal_type(d.get(None)) # N: Revealed type is "__main__.D"
reveal_type(d.get("whatever")) # N: Revealed type is "builtins.int"

[case testOverloadAndClassTypes]
from typing import overload, Union, TypeVar, Type

Expand Down

0 comments on commit 8a8103a

Please sign in to comment.