Skip to content

Add test case involving constrained generic super #13266

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

Merged
merged 1 commit into from
Jul 28, 2022
Merged
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
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"