Skip to content

Commit 5da04f9

Browse files
committed
Fix UnsetType truthiness narrowing in type stubs
Closes msgspec#916
1 parent a9ed8f1 commit 5da04f9

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)