From c99674030d5427b94f6f86eff23796c4addc0447 Mon Sep 17 00:00:00 2001 From: MUHAMED FAZAL PS Date: Mon, 29 Jun 2026 16:44:32 +0530 Subject: [PATCH] fix: detect ClassVar wrapped in ForwardRef on Python 3.14 Python 3.14 uses annotationlib which returns annotations as ForwardRef objects instead of plain strings. str(ForwardRef(...)) produces a repr string like 'ForwardRef(...)' which does not match the ClassVar prefix checks. Fix by extracting __forward_arg__ from ForwardRef objects when available, which returns the raw annotation string. Fixes #1575 --- src/attr/_make.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/attr/_make.py b/src/attr/_make.py index 793bfd89d..c4ca760ff 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -299,7 +299,12 @@ def _is_class_var(annot): annotations which would put attrs-based classes at a performance disadvantage compared to plain old classes. """ - annot = str(annot) + # Python 3.14+ wraps deferred annotations in ForwardRef. + # Extract the inner string to get the actual annotation text. + if hasattr(annot, "__forward_arg__"): + annot = annot.__forward_arg__ + else: + annot = str(annot) # Annotation can be quoted. if annot.startswith(("'", '"')) and annot.endswith(("'", '"')):