Last active
April 6, 2023 19:09
-
-
Save mcwitt/672ce16a53466fdc340d684b1dc8cf2c to your computer and use it in GitHub Desktop.
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
# mypy mypy_repro.py fails with | |
# mypy_repro.py:28: error: Incompatible return value type (got "Union[List[Bar], List[Baz]]", expected "List[A]") [return-value] | |
# no issues with pyright | |
# mypy --version: mypy 1.2.0 (compiled: yes) | |
from typing import List, TypeVar, Union | |
TFoo = TypeVar("TFoo", bound="Foo") | |
class Foo: | |
def wrap(self: TFoo) -> List[TFoo]: | |
return [self] | |
class Bar(Foo): | |
... | |
class Baz(Foo): | |
... | |
A = TypeVar("A", bound=Union[Bar, Baz]) | |
def foo(x: A) -> List[A]: | |
return x.wrap() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment