File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -2609,3 +2609,12 @@ class B2(B1): # E: A NamedTuple cannot be a dataclass
2609
2609
pass
2610
2610
2611
2611
[builtins fixtures/tuple.pyi]
2612
+
2613
+ [case testDataclassesTypeGuard]
2614
+ import dataclasses
2615
+
2616
+ raw_target: object
2617
+
2618
+ if isinstance(raw_target, type) and dataclasses.is_dataclass(raw_target):
2619
+ reveal_type(raw_target) # N: Revealed type is "type[dataclasses.DataclassInstance]"
2620
+ [builtins fixtures/tuple.pyi]
Original file line number Diff line number Diff line change @@ -777,3 +777,22 @@ def handle(model: Model) -> int:
777
777
return process_model(model)
778
778
return 0
779
779
[builtins fixtures/tuple.pyi]
780
+
781
+
782
+ [case testOverloadedTypeGuardType]
783
+ from __future__ import annotations
784
+ from typing_extensions import TypeIs, Never, overload
785
+
786
+ class X: ...
787
+
788
+ @overload # E: An overloaded function outside a stub file must have an implementation
789
+ def is_xlike(obj: Never) -> TypeIs[X | type[X]]: ... # type: ignore
790
+ @overload
791
+ def is_xlike(obj: type) -> TypeIs[type[X]]: ...
792
+ @overload
793
+ def is_xlike(obj: object) -> TypeIs[X | type[X]]: ...
794
+
795
+ raw_target: object
796
+ if isinstance(raw_target, type) and is_xlike(raw_target):
797
+ reveal_type(raw_target) # N: Revealed type is "type[__main__.X]"
798
+ [builtins fixtures/tuple.pyi]
You can’t perform that action at this time.
0 commit comments