Skip to content

__annotations__ is no longer eagerly evaluated in Python 3.14, leading to AttributeError: 'Config' object has no attribute '__annotations__' when modifying the config. #86

@k-chrispens

Description

@k-chrispens

In Python 3.14, the __annotations__ of a class, etc. are no longer eagerly evaluated leading to an error when modifying the config.

To replicate - install rcsb-api with Python 3.14:

from rcsbapi.config import config
config.DATA_API_REQUESTS_PER_SECOND = 50

Returns:

File ~/Downloads/altloc_analysis/.pixi/envs/default/lib/python3.14/site-packages/rcsbapi/config.py:43, in Config.__setattr__(self, name, value)
     40     raise AttributeError(f"'{name}' is not a valid attribute of Config class")
     42 # Enforce consistent typing
---> 43 expected_type = self.__annotations__.get(name, None)
     44 if expected_type and not isinstance(value, expected_type):
     45     raise TypeError(f"Expected type '{expected_type.__name__}' for attribute '{name}', but got '{type(value).__name__}'")

AttributeError: 'Config' object has no attribute '__annotations__'

Fix options:
For now, just include from __future__ import annotations at the top of config.py, but possibly use something from annotationslib (introduced in Python 3.14) in the future?

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