Skip to content

0.22.0 regression: tests/unit/test_struct.py::TestClassVar::test_wrong_classvar is breaking assertions in CPython #1221

Description

@mgorny

Description

When running the test suite against CPython build with assertions enabled, I'm getting the following crash:

$ pytest -s tests/unit/test_struct.py::TestClassVar::test_wrong_classvar
========================================================= test session starts =========================================================
platform linux -- Python 3.12.14, pytest-9.1.1, pluggy-1.6.0
rootdir: /tmp/msgspec
configfile: .pytest.toml
collected 1 item                                                                                                                       

tests/unit/test_struct.py python: Objects/typeobject.c:3759: type_new_init: Assertion `!PyErr_Occurred()' failed.
Fatal Python error: Aborted

Current thread 0x00007fb62184cbc0 (most recent call first):
  File "<string>", line 8 in <module>
  File "/tmp/msgspec/tests/unit/utils.py", line 20 in temp_module
  File "/usr/lib/python3.12/contextlib.py", line 137 in __enter__
  File "/tmp/msgspec/tests/unit/test_struct.py", line 2631 in test_wrong_classvar
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/python.py", line 167 in pytest_pyfunc_call
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/python.py", line 1707 in runtest
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 184 in pytest_runtest_call
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 250 in <lambda>
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 361 in from_call
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 249 in call_and_report
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 139 in runtestprotocol
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/runner.py", line 118 in pytest_runtest_protocol
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/main.py", line 408 in pytest_runtestloop
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/main.py", line 384 in _main
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/main.py", line 330 in wrap_session
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/main.py", line 377 in pytest_cmdline_main
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_callers.py", line 121 in _multicall
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_manager.py", line 120 in _hookexec
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/pluggy/_hooks.py", line 512 in __call__
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 229 in _main
  File "/tmp/msgspec/.venv/lib/python3.12/site-packages/_pytest/config/__init__.py", line 253 in _console_main
  File "/tmp/msgspec/.venv/bin/pytest", line 10 in <module>

Extension modules: msgspec._core (total: 1)
Aborted                    (core dumped) pytest -s tests/unit/test_struct.py::TestClassVar::test_wrong_classvar

I've been able to bisect it to:

commit 948cd0f5a316d3217345ba6d04c6c275a85a79b8 (HEAD)
Author: sobolevn <mail@sobolevn.me>
Date:   Sun Jun 21 19:38:24 2026 +0300

    Fix crash on incorrect `typing.ClassVar` annotation (#1097)

it looks like the fix from #1097 is incomplete / incorrect.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions