Skip to content

Fix crash on incorrect typing.ClassVar annotation - #1097

Merged
sobolevn merged 1 commit into
msgspec:mainfrom
sobolevn:issue-1096
Jun 21, 2026
Merged

sobolevn merged 1 commit into
msgspec:mainfrom
sobolevn:issue-1096

Conversation

@sobolevn

Copy link
Copy Markdown
Member

Closes #1096

@sobolevn
sobolevn added this pull request to the merge queue Jun 21, 2026
Merged via the queue into msgspec:main with commit 948cd0f Jun 21, 2026
24 checks passed
@sobolevn
sobolevn deleted the issue-1096 branch June 21, 2026 16:39
@codspeed

codspeed Bot commented Jun 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 7 improved benchmarks
❌ 4 regressed benchmarks
✅ 128 untouched benchmarks
⏩ 135 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation test_decode_type[arm-msgpack-False] 803.1 µs 865.3 µs -7.19%
❌ Simulation test_decode_type[arm-json-None] 867.2 µs 898.1 µs -3.45%
❌ Simulation test_decode_type[arm-json-False] 921.3 µs 951.9 µs -3.21%
❌ Simulation test_decode_type[arm-msgpack-True] 789.5 µs 813.9 µs -2.99%
⚡ Simulation test_decode_type[arm-msgpack-memoryview] 23.2 µs 22.1 µs +4.62%
⚡ Simulation test_decode_type[arm-msgpack-None] 748 µs 717.8 µs +4.22%
⚡ Simulation test_decode_type[arm-json-True] 938.5 µs 908 µs +3.36%
⚡ Simulation test_decode_type[arm-json-enum] 1.2 ms 1.1 ms +3.06%
⚡ Simulation test_encode_type[arm-json-datetime] 1.7 ms 1.7 ms +3.02%
⚡ Simulation test_decode_convert_type_non_strict[arm-msgpack-int] 2.3 ms 2.2 ms +2.42%
⚡ Simulation test_decode_type[arm-msgpack-float] 2.2 ms 2.2 ms +2.35%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing sobolevn:issue-1096 (a447893) with main (551e2dc)

Open in CodSpeed

Footnotes

  1. 135 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@ofek

ofek commented Jun 21, 2026

Copy link
Copy Markdown
Member

Can we please somehow mark the CodSpeed jobs as allowed-to-fail on main so that it doesn't look like our CI is perpetually broken?

image

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]>
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.

typing.ClassVar string annotation can crash msgspec

3 participants