### Description ```python from typing import assert_type from msgspec import UnsetType def f(s: str | UnsetType): if s: assert_type(s, str) # this fails ``` `UNSET` is the only `UnsetType` value and `bool(UNSET) is False`. Therefore the if statement should narrow the type of `s` to `str`.
Activity
Fix UnsetType type annotation (msgspec#916)
overlorde commentedon Feb 10, 2026
I'd like to work on this. The fix is adding
__bool__() -> Literal[False]to theUnsetTypestub so type checkers can narrow via truthiness.Fix UnsetType truthiness narrowing in type stubs
Siyet commentedon Apr 8, 2026
Ported to the community fork msgspec-arise: issue #26, PR #33
Fix UnsetType truthiness narrowing in type stubs (#975)