Skip to content

Declare Struct instance defaults in the type stub - #1173

Merged
Siyet merged 1 commit into
msgspec:mainfrom
vzer200:fix/struct-defaults-typing
Sep 11, 2026
Merged

Siyet merged 1 commit into
msgspec:mainfrom
vzer200:fix/struct-defaults-typing

Conversation

@vzer200

@vzer200 vzer200 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

__struct_defaults__ is available on both Struct classes and instances, but only the metaclass stub declares it. Access through an instance therefore fails type checking even though it works at runtime.

Add the missing Struct annotation and cover class and instance access in the existing typing examples. Runtime behavior is unchanged.

Fixes #779.

Validation: the new instance assertion fails with mypy, pyright, and pyrefly before the change; all three typing suites and stubtest pass afterward. On CPython 3.12, all 6,412 unit tests and 7 package doctests pass, with 118 skips; the repository's lint, format, and spelling checks pass. Windows validation used UTF-8 mode for the existing C-source text checks and a private LLVM-MinGW compiler adapter to build the unchanged extension. Neither is included in this patch.

Implemented and independently reviewed by automated agents before submission.

@Siyet Siyet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for the fix! The type stub now matches the existing runtime behavior.

@Siyet
Siyet added this pull request to the merge queue Sep 11, 2026
Merged via the queue into msgspec:main with commit 924f477 Sep 11, 2026
27 of 28 checks passed

This branch was successfully deployed

1 active deployment
docs-preview — 3b9ab257 Deployed Sep 11, 2026 by vzer200 via Deploy preview #440
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.

__struct_defaults__ is missing from Python type specification

2 participants