Skip to content

Improve __init__.pyi and _typing_utils.pyi typings - #1055

Merged
sobolevn merged 2 commits into
msgspec:mainfrom
sobolevn:improve-init-typing
Jun 12, 2026
Merged

Improve __init__.pyi and _typing_utils.pyi typings#1055
sobolevn merged 2 commits into
msgspec:mainfrom
sobolevn:improve-init-typing

Conversation

@sobolevn

Copy link
Copy Markdown
Member

Multiple changes:

  1. Style: None must be the last item in a union
  2. Using Final for constants. It changes the inferce:

Before:

» mypy ex.py
ex.py:3: note: Revealed type is "msgspec.UnsetType"
Success: no issues found in 1 source file

After:

» mypy ex.py
ex.py:3: note: Revealed type is "Literal[msgspec.UnsetType.UNSET]?"
Success: no issues found in 1 source file
  1. Using TypeIs instead of TypeGuard, so we can better narrow in the negative case as well. This check is symmetric.
  2. Renaming T -> _T to remove type-checking name from possible imports.
  3. Fixing bases type, it can accept all types, not just structs

@sobolevn
sobolevn enabled auto-merge June 12, 2026 12:17
@sobolevn
sobolevn added this pull request to the merge queue Jun 12, 2026
Merged via the queue into msgspec:main with commit 619c98e Jun 12, 2026
11 checks passed
@sobolevn
sobolevn deleted the improve-init-typing branch June 12, 2026 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants