Skip to content

Commit c998d21

Browse files
authored
Add regression test for narrowing union of mixins (#19266)
For #16413
1 parent 183fc96 commit c998d21

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test-data/unit/check-narrowing.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2577,3 +2577,26 @@ def check_d(arg: D[T]) -> None:
25772577
return
25782578
reveal_type(arg) # N: Revealed type is "tuple[T`-1, fallback=__main__.D[Any]]"
25792579
[builtins fixtures/tuple.pyi]
2580+
2581+
2582+
[case testNarrowingUnionMixins]
2583+
class Base: ...
2584+
2585+
class FooMixin:
2586+
def foo(self) -> None: ...
2587+
2588+
class BarMixin:
2589+
def bar(self) -> None: ...
2590+
2591+
def baz(item: Base) -> None:
2592+
if not isinstance(item, (FooMixin, BarMixin)):
2593+
raise
2594+
2595+
reveal_type(item) # N: Revealed type is "Union[__main__.<subclass of "__main__.Base" and "__main__.FooMixin">, __main__.<subclass of "__main__.Base" and "__main__.BarMixin">]"
2596+
if isinstance(item, FooMixin):
2597+
reveal_type(item) # N: Revealed type is "__main__.FooMixin"
2598+
item.foo()
2599+
else:
2600+
reveal_type(item) # N: Revealed type is "__main__.<subclass of "__main__.Base" and "__main__.BarMixin">"
2601+
item.bar()
2602+
[builtins fixtures/isinstance.pyi]

0 commit comments

Comments
 (0)