diff --git a/zmk/build.py b/zmk/build.py index 0d22d9c..a4ecd7f 100644 --- a/zmk/build.py +++ b/zmk/build.py @@ -5,7 +5,7 @@ from collections.abc import Iterable, Mapping, Sequence from dataclasses import asdict, dataclass, field from pathlib import Path -from typing import Any, Self, TypeVar, cast, overload +from typing import Any, TypeVar, cast, overload import dacite @@ -57,7 +57,7 @@ class BuildMatrix: _data: dict[str, Any] | None @classmethod - def from_repo(cls, repo: Repo) -> Self: + def from_repo(cls, repo: Repo) -> "BuildMatrix": """Get the build matrix for a repo""" return cls(repo.build_matrix_path) diff --git a/zmk/hardware.py b/zmk/hardware.py index 6d2e07e..e2bdc8c 100644 --- a/zmk/hardware.py +++ b/zmk/hardware.py @@ -6,7 +6,7 @@ from dataclasses import dataclass, field from functools import reduce from pathlib import Path -from typing import Any, Literal, Self, TypeAlias, TypeGuard +from typing import Any, Literal, Type, TypeAlias, TypeGuard, TypeVar import dacite @@ -22,6 +22,9 @@ # TODO: dict should match { id: str, features: list[Feature] } Variant: TypeAlias = str | dict[str, str] +# TODO: replace with typing.Self once minimum Python version is >= 3.11 +_Self = TypeVar("_Self", bound="Hardware") + @dataclass class Hardware: @@ -47,7 +50,7 @@ def __rich__(self) -> Any: return f"{self.id} [dim]{self.name}" @classmethod - def from_dict(cls, data) -> Self: + def from_dict(cls: "Type[_Self]", data) -> _Self: """Read a hardware description from a dict""" return dacite.from_dict(cls, data)