Skip to content

Struct fields aren't discovered in Python 3.14 #847

@thatch

Description

@thatch

Description

It looks like something is fundamentally broken in how Struct subclasses find their fields under 3.14b1. This was observed on Arm Mac with the latest release, and Linux with latest release as well as main.

Working, on 3.13:

[tim@tangerine ~]$ uvx --from='git+https://github.com/jcrist/msgspec@main' python
      Built msgspec @ git+https://github.com/jcrist/msgspec@bc60e96772c5e8a3babff967d86a9e7dfcdbfb1b
Installed 1 package in 1ms
Python 3.13.2 (main, Feb 12 2025, 14:51:17) [Clang 19.1.6 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from msgspec import Struct
>>> class S(Struct):
...     rule_name: str
...     
>>> S("foo")
S(rule_name='foo')
>>> S()
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    S()
    ~^^
TypeError: Missing required argument 'rule_name'

Broken, on 3.14:

[tim@tangerine ~]$ uvx -p 3.14 --from='git+https://github.com/jcrist/msgspec@main' python
Installed 1 package in 3ms
Python 3.14.0b1 (main, May 14 2025, 15:26:05) [GCC 15.1.1 20250425] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from msgspec import Struct
>>> class S(Struct):
...     rule_name: str
...     
>>> S("foo")
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    S("foo")
    ~^^^^^^^
TypeError: Extra positional arguments provided
>>> S()
S()

cc @nedbat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions