Skip to content

UnsetType union types lowering is incomplete #916

Closed

Description

@CharString

Description

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

  1. overlorde commented on Feb 10, 2026

    @overlorde
    Contributor

    I'd like to work on this. The fix is adding __bool__() -> Literal[False] to the UnsetType stub so type checkers can narrow via truthiness.

  2. added a commit that references this issue on Feb 10, 2026
    5da04f9
  3. Siyet commented on Apr 8, 2026

    @Siyet
    Contributor

    Ported to the community fork msgspec-arise: issue #26, PR #33

  4. added a commit that references this issue on Apr 8, 2026
    c01df28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions