Declare Struct instance defaults in the type stub - #1173
Merged
Merged
Conversation
vzer200
had a problem deploying
to
docs-preview
September 8, 2026 10:05 — with
GitHub Actions
Failure
Siyet
approved these changes
Sep 11, 2026
Siyet
left a comment
Contributor
There was a problem hiding this comment.
Thx for the fix! The type stub now matches the existing runtime behavior.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
__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.