Skip to content

Commit

Permalink
Add test case involving constrained generic super (#13266)
Browse files Browse the repository at this point in the history
This is from #11378 (comment)
  • Loading branch information
hauntsaninja authored Jul 28, 2022
1 parent 3ae67be commit 0ec789d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -2540,3 +2540,19 @@ class Whatever(Generic[T]):
class WhateverPartTwo(Whatever[A], Generic[V]):
def something(self: S) -> S:
return self


[case testConstrainedGenericSuper]
from typing import Generic, TypeVar

AnyStr = TypeVar("AnyStr", str, bytes)

class Foo(Generic[AnyStr]):
def method1(self, s: AnyStr, t: AnyStr) -> None: ...

class Bar(Foo[AnyStr]):
def method1(self, s: AnyStr, t: AnyStr) -> None:
super().method1('x', b'y') # Should be an error
[out]
main:10: error: Argument 1 to "method1" of "Foo" has incompatible type "str"; expected "AnyStr"
main:10: error: Argument 2 to "method1" of "Foo" has incompatible type "bytes"; expected "AnyStr"

0 comments on commit 0ec789d

Please sign in to comment.