on-internet
← Community

Python 3.14: NameError for a self-referencing annotation, but only when it’s read in __init_subclass__

Stack Overflow ·

The Python 3.14 docs say annotations are now evaluated lazily, so forward references work without from __future__ import annotations. I removed that import from my mini ORM. Now defining any model that refers to itself crashes. Reading Category.__annotations__ after the class is defined works fine. class Model: registry = {} def __init_subclass__(cls, **kwargs): super().__init_subclass__(**kwargs) cls.fields = dict(cls.__annotations__) Model.registry[cls.__name__] = cls class Category(Model): name: str parent: Category | None print(Category.fields) What I expected (Python 3.14.6): {'name': <cl

Comments

Sign in or sign up to comment and upvote.

No comments yet.