List[Foo] + List[Bar] now returns List[Foo | Bar] (#8293)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Akuli
2022-07-15 20:20:50 +03:00
committed by GitHub
parent 0764f9f31f
commit 3c90c97b9a
2 changed files with 24 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
from typing import List, Union
from typing_extensions import assert_type
# list.__add__ example from #8292
class Foo:
def asd(self) -> int:
return 1
class Bar:
def asd(self) -> int:
return 2
combined = [Foo()] + [Bar()]
assert_type(combined, List[Union[Foo, Bar]])
for item in combined:
assert_type(item.asd(), int)