Skip to content

Commit c01df28

Browse files
overlordejcrist
andauthored
Fix UnsetType truthiness narrowing in type stubs (#975)
Closes #916 Co-authored-by: Jim Crist-Harif <[email protected]>
1 parent a5a5ca2 commit c01df28

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎src/msgspec/__init__.pyi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ T = TypeVar("T")
7070

7171
class UnsetType(enum.Enum):
7272
UNSET = "UNSET"
73+
def __bool__(self) -> Literal[False]: ...
7374

7475
UNSET = UnsetType.UNSET
7576

‎tests/typing/basic_typing_examples.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def check_unset_type_lowering(x: int | msgspec.UnsetType) -> None:
3535
reveal_type(x) # assert "unset" not in typ.lower()
3636

3737

38+
def check_unset_type_truthiness_lowering(x: str | msgspec.UnsetType) -> None:
39+
if x:
40+
reveal_type(x) # assert "unset" not in typ.lower()
41+
42+
3843
def check_nodefault() -> None:
3944
reveal_type(msgspec.NODEFAULT) # assert "Any" not in typ
4045
str(msgspec.NODEFAULT)

0 commit comments

Comments
 (0)