Skip to content

Commit 0f6606f

Browse files
test: add failing TypeGuard test for temporary object (__call__), refs #19575
Add a regression test to check-typeguard.test for TypeGuard narrowing on temporary objects using __call__. This documents the current bug (see #19575).
1 parent 5b28b62 commit 0f6606f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test-data/unit/check-typeguard.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,19 @@ assert a(x=x)
731731
reveal_type(x) # N: Revealed type is "builtins.int"
732732
[builtins fixtures/tuple.pyi]
733733

734+
735+
# https://github.com/python/mypy/issues/19575
736+
[case testNoCrashOnDunderCallTypeGuardTemporaryObject]
737+
from typing_extensions import TypeGuard
738+
class E:
739+
def __init__(self) -> None: ...
740+
def __call__(self, o: object) -> TypeGuard[int]:
741+
return True
742+
x = object()
743+
if E()(x):
744+
reveal_type(x) # N: Revealed type is "builtins.int"
745+
[builtins fixtures/tuple.pyi]
746+
734747
[case testTypeGuardRestrictAwaySingleInvariant]
735748
from typing import List
736749
from typing_extensions import TypeGuard

0 commit comments

Comments
 (0)