You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7c2f473
Browse filesBrowse the repository at this point in the historyBrowse files
Fix unquoted Struct forward references on Python 3.14 (msgspec#1168)
Fixesmsgspec#1165.
On Python 3.14, Struct field collection invoked the class __annotate__
function with annotationlib.Format.VALUE. That evaluates annotations
immediately, so an unquoted forward reference raises NameError while the
class is still being created. Ordinary 3.14 classes do not do this.
This change evaluates annotations through
annotationlib.call_annotate_function(..., Format.FORWARDREF), matching
the annotationlib metaclass guidance. Compiler-generated annotate
functions often raise NotImplementedError if FORWARDREF is passed
directly; call_annotate_function implements that format.
Field names (and ClassVar detection) still run at class creation time;
types continue to resolve later through the existing delayed annotation
path.
Quoted annotations and from __future__ import annotations are unchanged.
Older Python versions are unaffected because they never take the
__annotate__ path.
Tests cover quoted forward refs, future-annotations forward refs,
unquoted forward refs and self-recursive structs on 3.14+, JSON
encode/decode after both types are defined, and existing ClassVar cases
on 3.14.
---------
Co-authored-by: MarkGus0 <[email protected]>
Co-authored-by: MarkGus0 <[email protected]>
Co-authored-by: VyrnSynx <[email protected]>
Copy file name to clipboardExpand all lines: docs/changelog.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,8 @@
37
37
- Fix the `msgspec.json.decode` docstring to say `dec_hook` should raise
38
38
`NotImplementedError` for unsupported types, not `TypeError` ({issue}`774`).
39
39
- Fix backing type declaration of `Ext.code` ({pr}`1135`).
40
+
- Fix `NameError` when creating a `Struct` with an unquoted forward
41
+
reference on Python 3.14 ({issue}`1165`).
40
42
- msgspec moved to the [msgspec GitHub organization](https://github.com/msgspec/msgspec);
41
43
documentation now lives at [msgspec.dev](https://msgspec.dev) (repository
0 commit comments