diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dc323f61..0ce51ab7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,7 +68,7 @@ repos: # Ruff is a code style and formatter # It works on files in-place - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.7 + rev: v0.15.9 hooks: - id: ruff-check name: ruff @@ -90,7 +90,7 @@ repos: # The project's documentation can be found at: # https://mypy.readthedocs.io/en/stable/index.html - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.19.1 + rev: v1.20.0 hooks: - id: mypy exclude: ^tests/.*$ diff --git a/oteapi/models/genericconfig.py b/oteapi/models/genericconfig.py index f685602a..d582318e 100644 --- a/oteapi/models/genericconfig.py +++ b/oteapi/models/genericconfig.py @@ -9,7 +9,7 @@ from pydantic.fields import PydanticUndefined if TYPE_CHECKING: # pragma: no cover - from typing import Any + from typing import Any, cast class AttrDict(BaseModel, MutableMapping): # noqa: PLW1641 @@ -103,6 +103,10 @@ def update( # type: ignore[override] ) -> None: if other and isinstance(other, Mapping): for key, value in other.items(): + if not isinstance(key, str): + raise TypeError( + "Keys must be of type `str`, not " f"`{type(key).__name__}`." + ) setattr(self, key, value) elif other and isinstance(other, BaseModel): for key, value in other: @@ -117,7 +121,11 @@ def update( # type: ignore[override] raise ValueError( "`other` must be an iterable of objects of length two." ) - for key, value in other: # type: ignore[misc] + + if TYPE_CHECKING: # pragma: no cover + other = cast(Iterable[tuple[str, Any]], other) + + for key, value in other: setattr(self, key, value) elif other: raise TypeError( diff --git a/pyproject.toml b/pyproject.toml index 8230491e..be49acaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,9 @@ exclude = [ ".codecov.yml", ] +[tool.black] +target-version = ["py310","py311","py312","py313"] + [tool.mypy] python_version = "3.10" ignore_missing_imports = true