Skip to content

Instantly share code, notes, and snippets.

@mcwitt
Last active April 6, 2023 19:09
Show Gist options
  • Save mcwitt/672ce16a53466fdc340d684b1dc8cf2c to your computer and use it in GitHub Desktop.
Save mcwitt/672ce16a53466fdc340d684b1dc8cf2c to your computer and use it in GitHub Desktop.
# 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