Skip to content

Fix Python 3.14 compatibility in config_store.py#10692

Open
ddelgadovargas-cyber wants to merge 4 commits into
pyg-team:masterfrom
ddelgadovargas-cyber:fix_config_store
Open

Fix Python 3.14 compatibility in config_store.py#10692
ddelgadovargas-cyber wants to merge 4 commits into
pyg-team:masterfrom
ddelgadovargas-cyber:fix_config_store

Conversation

@ddelgadovargas-cyber
Copy link
Copy Markdown

I got this error in Python3.14:

test/test_config_store.py:24: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
config_store.py:262: in to_dataclass
    annotation = map_annotation(annotation, mapping=MAPPING)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

annotation = float | torch.Tensor | str
mapping = {<class 'torch.nn.modules.module.Module'>: typing.Any, <class 'torch.Tensor'>: typing.Any}

    def map_annotation(
        annotation: Any,
        mapping: Optional[Dict[Any, Any]] = None,
    ) -> Any:
        origin = getattr(annotation, '__origin__', None)
        args: Tuple[Any, ...] = getattr(annotation, '__args__', tuple())
        if origin in {Union, list, dict, tuple}:
            assert origin is not None
            args = tuple(map_annotation(a, mapping) for a in args)
            if type(annotation).__name__ == 'GenericAlias':
                # If annotated with `list[...]` or `dict[...]`:
                annotation = origin[args]
            else:
                # If annotated with `typing.List[...]` or `typing.Dict[...]`:
                annotation = copy.copy(annotation)
>               annotation.__args__ = args
E               AttributeError: readonly attribute

config_store.py:176: AttributeError

In Python 3.14, the __args__ attribute of generic aliases (like typing.Dict) is read-only. The original code attempted to copy the annotation and mutate __args__. This change replaced this logic to use origin[args] directly, which is the standard way to construct these types in modern Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant