From 4bdf6bec1dbd267f03334f03e6e63dc7f8a03a9b Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 21 Mar 2024 16:05:42 +0100 Subject: [PATCH 1/2] update mypy --- deal/_runtime/_decorators.py | 14 +++++++------- deal/_runtime/_validators.py | 4 ++-- deal/_trace.py | 2 ++ pyproject.toml | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/deal/_runtime/_decorators.py b/deal/_runtime/_decorators.py index ee5403f4..023e30c4 100644 --- a/deal/_runtime/_decorators.py +++ b/deal/_runtime/_decorators.py @@ -62,7 +62,7 @@ def pre( exception=exception or _exceptions.PreContractError, ) func = partial(Contracts.attach, 'pres', contract) - return func # type: ignore[return-value] + return func def post( @@ -107,7 +107,7 @@ def post( exception=exception or _exceptions.PostContractError, ) func = partial(Contracts.attach, 'posts', contract) - return func # type: ignore[return-value] + return func def ensure( @@ -155,7 +155,7 @@ def ensure( exception=exception or _exceptions.PostContractError, ) func = partial(Contracts.attach, 'ensures', contract) - return func # type: ignore[return-value] + return func def raises( @@ -204,7 +204,7 @@ def raises( exception=exception or _exceptions.RaisesContractError, ) func = partial(Contracts.attach, 'raises', contract) - return func # type: ignore[return-value] + return func def has( @@ -248,7 +248,7 @@ def has( exception=exception, ) func = partial(Contracts.attach_has, patcher) - return func # type: ignore[return-value] + return func def reason( @@ -303,7 +303,7 @@ def reason( exception=exception or _exceptions.ReasonContractError, ) func = partial(Contracts.attach, 'reasons', contract) - return func # type: ignore[return-value] + return func def inv( @@ -394,7 +394,7 @@ def example(validator: Callable[[], bool]) -> Callable[[C], C]: exception=_exceptions.ExampleContractError, ) func = partial(Contracts.attach, 'examples', contract) - return func # type: ignore[return-value] + return func @overload diff --git a/deal/_runtime/_validators.py b/deal/_runtime/_validators.py index 14b9cead..f2d3f4de 100644 --- a/deal/_runtime/_validators.py +++ b/deal/_runtime/_validators.py @@ -15,8 +15,8 @@ if TYPE_CHECKING: - Args = tuple[object, ...] # type: ignore[misc] - Kwargs = dict[str, object] # type: ignore[misc] + Args = tuple[object, ...] + Kwargs = dict[str, object] @lru_cache(maxsize=16) diff --git a/deal/_trace.py b/deal/_trace.py index 6bf3d61a..28968238 100644 --- a/deal/_trace.py +++ b/deal/_trace.py @@ -56,6 +56,8 @@ def _collect_trace_results(t: Trace, func, file_name: str, func_result) -> Trace last_line = max(all_lines) covered_lines: set[int] = set() + fname: str + lineno: int for fname, lineno in t.counts: # type: ignore assert fname == file_name if lineno < first_line: diff --git a/pyproject.toml b/pyproject.toml index 80e85e7c..69495e6c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ has-astroid = "not is_installed('astroid')" [tool.mypy] files = ["deal"] -python_version = 3.8 +python_version = "3.9" plugins = ["deal.mypy"] ignore_missing_imports = true show_error_codes = true From 2f46dd0254b7f8c5b6da0d422770e20743d57e5e Mon Sep 17 00:00:00 2001 From: gram Date: Thu, 21 Mar 2024 16:05:47 +0100 Subject: [PATCH 2/2] update pytest --- tests/test_state.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/test_state.py b/tests/test_state.py index 8aac7ad2..2fb0277b 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -1,4 +1,5 @@ import os +import warnings import pytest @@ -138,18 +139,19 @@ def set_env_vars(): def test_enable__warnings(restore_state, env_vars, set_env_vars, expected): os.environ.clear() set_env_vars(env_vars) - ewarn = RuntimeWarning if expected else None - with pytest.warns(ewarn) as warns: - deal.enable() if expected: + with pytest.warns(RuntimeWarning) as warns: + deal.enable() assert len(warns) == 1 assert str(warns[0].message) == f'{expected}. Is it intentional?' else: - assert len(warns) == 0 + with warnings.catch_warnings(): + warnings.simplefilter('error') + deal.enable() - with pytest.warns(None) as warns: + with warnings.catch_warnings(): + warnings.simplefilter('error') deal.enable(warn=False) - assert len(warns) == 0 @pytest.mark.parametrize('env_vars, expected', [ @@ -162,15 +164,16 @@ def test_enable__warnings(restore_state, env_vars, set_env_vars, expected): def test_disable__warnings(restore_state, env_vars, set_env_vars, expected): os.environ.clear() set_env_vars(env_vars) - ewarn = RuntimeWarning if expected else None - with pytest.warns(ewarn) as warns: - deal.disable() if expected: + with pytest.warns(RuntimeWarning) as warns: + deal.disable() assert len(warns) == 1 assert str(warns[0].message) == f'{expected}. Is it intentional?' else: - assert len(warns) == 0 + with warnings.catch_warnings(): + warnings.simplefilter('error') + deal.disable() - with pytest.warns(None) as warns: + with warnings.catch_warnings(): + warnings.simplefilter('error') deal.disable(warn=False) - assert len(warns) == 0