Repository navigation
Fix crash on incorrect typing.ClassVar annotation - #1097
Merged
Merged
Conversation
provinzkraut
approved these changes
Jun 21, 2026
Merging this PR will not alter performance
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
Member
This was referenced Jul 2, 2026
Andarius
pushed a commit
to Andarius/msgspec
that referenced
this pull request
Oct 11, 2026
…msgspec#1223) Closes msgspec#1221 The msgspec#1097 fix looks up `ClassVar` on whatever `typing` names in the module namespace, but if that attribute lookup itself raises, the error return is missed: `structmeta_is_classvar` compares the NULL result against `typing.ClassVar`, reports "not a ClassVar", and returns 0 with the exception still pending. On CPython builds with assertions enabled this trips `assert(!PyErr_Occurred())` in `type_new_init` and terminates the interpreter. Return -1 when the lookup fails, matching the error handling already used for the `__origin__` lookup just below. The original AttributeError from msgspec#1096 still propagates exactly as before. Tests: the existing `test_wrong_classvar` regression is parametrized to also cover the subscripted form `typing.ClassVar[int]`, and a new test covers a `typing` stand-in whose `ClassVar` attribute raises an arbitrary error, so the propagation path itself is pinned rather than only the msgspec#1096 case. Verified on a locally built CPython 3.13.7 `--with-pydebug`: the unpatched code stops the interpreter in `test_wrong_classvar` (exit 134); with the patch the full unit suite passes (6298 passed, 313 skipped). Focused tests also pass on a regular 3.13 build, which is what CI runs. Changelog entry included under Unreleased. Tested on Python 3.13 only (debug and regular builds). CI covers 3.10 to 3.15; the change is a two-line error check in version-independent C. --------- Signed-off-by: Charan Rathore <[email protected]>
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.

Closes #1096