diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b8afd8a6..373288d7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,3 +14,9 @@ repos: - id: check-yaml - id: trailing-whitespace - id: check-merge-conflict + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + files: openfeature diff --git a/openfeature/_backports/strenum.py b/openfeature/_backports/strenum.py index dee9aa02..ed2d7b34 100644 --- a/openfeature/_backports/strenum.py +++ b/openfeature/_backports/strenum.py @@ -1,6 +1,8 @@ -try: +import sys + +if sys.version_info >= (3, 11): from enum import StrEnum -except ImportError: +else: from enum import Enum class StrEnum(str, Enum): diff --git a/openfeature/immutable_dict/mapping_proxy_type.py b/openfeature/immutable_dict/mapping_proxy_type.py index 22c6a76c..634dd9b4 100644 --- a/openfeature/immutable_dict/mapping_proxy_type.py +++ b/openfeature/immutable_dict/mapping_proxy_type.py @@ -1,3 +1,6 @@ +import typing + + class MappingProxyType(dict): """ MappingProxyType is an immutable dictionary type, written to @@ -14,16 +17,16 @@ class MappingProxyType(dict): `from types import MappingProxyType` """ - def __hash__(self): + def __hash__(self) -> int: # type:ignore[override] return id(self) - def _immutable(self, *args, **kws): + def _immutable(self, *args: typing.Any, **kws: typing.Any) -> typing.NoReturn: raise TypeError("immutable instance of dictionary") __setitem__ = _immutable __delitem__ = _immutable clear = _immutable - update = _immutable - setdefault = _immutable - pop = _immutable + update = _immutable # type:ignore[assignment] + setdefault = _immutable # type:ignore[assignment] + pop = _immutable # type:ignore[assignment] popitem = _immutable diff --git a/pyproject.toml b/pyproject.toml index 3679563d..c92bfdfd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,6 +25,11 @@ dev = ["pip-tools", "pytest", "pre-commit"] [project.urls] Homepage = "https://github.com/open-feature/python-sdk" +[tool.mypy] +files = "openfeature" +namespace_packages = true +explicit_package_bases = true + [tool.ruff] exclude = [ ".git",