From 87982d02a2d929c93cc6bcc233d138659cd70ce4 Mon Sep 17 00:00:00 2001 From: Sebastiaan Huber Date: Wed, 7 Jun 2023 12:03:46 +0200 Subject: [PATCH] Dependencies: Update requirement `mypy==1.3.0` (#270) Also move the configuration from `tox.ini` to `pyproject.toml` and change the `.pre-commit-config.yaml` to use the local install of `mypy` instead of in the pre-commit virtual environment. --- .pre-commit-config.yaml | 26 +++++++++++++++----------- pyproject.toml | 21 ++++++++++++++++++++- src/plumpy/__init__.py | 4 ++-- src/plumpy/base/state_machine.py | 10 +++++----- src/plumpy/events.py | 2 +- src/plumpy/mixins.py | 2 +- src/plumpy/persistence.py | 6 +++--- src/plumpy/processes.py | 7 +++++-- src/plumpy/utils.py | 2 +- tox.ini | 24 ------------------------ 10 files changed, 53 insertions(+), 51 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f9220e9..688d0c0f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,17 +27,6 @@ repos: args: ['-i'] additional_dependencies: ['toml'] -- repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.790 - hooks: - - id: mypy - args: [--config-file=tox.ini] - additional_dependencies: ['aio_pika~=6.6'] - files: > - (?x)^( - plumpy/.*py| - )$ - - repo: https://github.com/PyCQA/pylint rev: v2.12.2 hooks: @@ -48,3 +37,18 @@ repos: docs/source/conf.py| test/.*| )$ + +- repo: local + hooks: + - id: mypy + name: mypy + entry: mypy + args: [--config-file=pyproject.toml] + language: python + types: [python] + require_serial: true + pass_filenames: true + files: >- + (?x)^( + src/.*py| + )$ diff --git a/pyproject.toml b/pyproject.toml index 68c25710..af490dc1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,9 +50,10 @@ docs = [ 'sphinx-book-theme~=0.0.39', ] pre-commit = [ - 'mypy==0.790', + 'mypy==1.3.0', 'pre-commit~=2.2', 'pylint==2.12.2', + 'types-pyyaml' ] tests = [ 'importlib-resources~=5.2', @@ -84,6 +85,24 @@ include_trailing_comma = true line_length = 120 multi_line_output = 3 +[tool.mypy] +show_error_codes = true +disallow_untyped_defs = true +disallow_incomplete_defs = true +check_untyped_defs = true +warn_unused_ignores = true +warn_redundant_casts = true + +[[tool.mypy.overrides]] +module = [ + 'aiocontextvars.*', + 'frozendict.*', + 'kiwipy.*', + 'nest_asyncio.*', + 'tblib.*', +] +ignore_missing_imports = true + [tool.pylint.format] max-line-length = 120 diff --git a/src/plumpy/__init__.py b/src/plumpy/__init__.py index e1a3cc5a..6b90cfeb 100644 --- a/src/plumpy/__init__.py +++ b/src/plumpy/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # pylint: disable=undefined-variable -# type: ignore[name-defined] +# mypy: disable-error-code="name-defined" __version__ = '0.21.7' import logging @@ -33,7 +33,7 @@ # for more details class NullHandler(logging.Handler): - def emit(self, record): + def emit(self, record): # type: ignore[no-untyped-def] pass diff --git a/src/plumpy/base/state_machine.py b/src/plumpy/base/state_machine.py index c9a08848..274ac968 100644 --- a/src/plumpy/base/state_machine.py +++ b/src/plumpy/base/state_machine.py @@ -76,12 +76,12 @@ def event( """A decorator to check for correct transitions, raising ``EventError`` on invalid transitions.""" if from_states != '*': if inspect.isclass(from_states): - from_states = (from_states,) # type: ignore + from_states = (from_states,) if not all(issubclass(state, State) for state in from_states): # type: ignore raise TypeError(f'from_states: {from_states}') if to_states != '*': if inspect.isclass(to_states): - to_states = (to_states,) # type: ignore + to_states = (to_states,) if not all(issubclass(state, State) for state in to_states): # type: ignore raise TypeError(f'to_states: {to_states}') @@ -111,7 +111,7 @@ def transition(self: Any, *a: Any, **kw: Any) -> Any: return transition if inspect.isfunction(from_states): - return wrapper(from_states) # type: ignore + return wrapper(from_states) return wrapper @@ -397,8 +397,8 @@ def _create_state_instance(self, state: Union[Hashable, State, Type[State]], *ar return state_cls(self, *args, **kwargs) def _ensure_state_class(self, state: Union[Hashable, Type[State]]) -> Type[State]: - if inspect.isclass(state) and issubclass(state, State): # type: ignore - return cast(Type[State], state) + if inspect.isclass(state) and issubclass(state, State): + return state try: return self.get_states_map()[cast(Hashable, state)] # pylint: disable=unsubscriptable-object diff --git a/src/plumpy/events.py b/src/plumpy/events.py index 64f5dd9c..735fb3f6 100644 --- a/src/plumpy/events.py +++ b/src/plumpy/events.py @@ -23,7 +23,7 @@ def new_event_loop(*args: Any, **kwargs: Any) -> asyncio.AbstractEventLoop: raise NotImplementedError('this method is not implemented because `plumpy` uses a single reentrant loop') -class PlumpyEventLoopPolicy(asyncio.DefaultEventLoopPolicy): # type: ignore +class PlumpyEventLoopPolicy(asyncio.DefaultEventLoopPolicy): """Custom event policy that always returns the same event loop that is made reentrant by ``nest_asyncio``.""" _loop: Optional[asyncio.AbstractEventLoop] = None diff --git a/src/plumpy/mixins.py b/src/plumpy/mixins.py index 05cb4c11..6302184b 100644 --- a/src/plumpy/mixins.py +++ b/src/plumpy/mixins.py @@ -15,7 +15,7 @@ class ContextMixin(persistence.Savable): CONTEXT: str = '_context' def __init__(self, *args: Any, **kwargs: Any): - super().__init__(*args, **kwargs) # type: ignore + super().__init__(*args, **kwargs) self._context: Optional[AttributesDict] = AttributesDict() @property diff --git a/src/plumpy/persistence.py b/src/plumpy/persistence.py index 10bfbed9..0c9b3313 100644 --- a/src/plumpy/persistence.py +++ b/src/plumpy/persistence.py @@ -73,7 +73,7 @@ def _bundle_constructor(loader: yaml.Loader, data: Any) -> Generator[Bundle, Non yaml.add_representer(Bundle, _bundle_representer) -yaml.add_constructor(_BUNDLE_TAG, _bundle_constructor) +yaml.add_constructor(_BUNDLE_TAG, _bundle_constructor) # type: ignore[arg-type] class Persister(metaclass=abc.ABCMeta): @@ -647,5 +647,5 @@ def load_instance_state(self, saved_state: SAVED_STATE_TYPE, load_context: LoadS super().load_instance_state(saved_state, load_context) if self._callbacks: # typing says asyncio.Future._callbacks needs to be called, but in the python 3.7 code it is a simple list - for callback in self._callbacks: # type: ignore - self.remove_done_callback(callback) + for callback in self._callbacks: + self.remove_done_callback(callback) # type: ignore[arg-type] diff --git a/src/plumpy/processes.py b/src/plumpy/processes.py index 0b72727e..40b2ccbb 100644 --- a/src/plumpy/processes.py +++ b/src/plumpy/processes.py @@ -72,7 +72,10 @@ class ProcessStateMachineMeta(abc.ABCMeta, state_machine.StateMachineMeta): # Make ProcessStateMachineMeta instances (classes) YAML - able -yaml.representer.Representer.add_representer(ProcessStateMachineMeta, yaml.representer.Representer.represent_name) +yaml.representer.Representer.add_representer( + ProcessStateMachineMeta, + yaml.representer.Representer.represent_name # type: ignore[arg-type] +) def ensure_not_closed(func: Callable[..., Any]) -> Callable[..., Any]: @@ -731,7 +734,7 @@ def on_create(self) -> None: """Entering the CREATED state.""" self._creation_time = time.time() - def recursively_copy_dictionaries(value): + def recursively_copy_dictionaries(value: Any) -> Any: """Recursively copy the mapping but only create copies of the dictionaries not the values.""" if isinstance(value, dict): return {key: recursively_copy_dictionaries(subvalue) for key, subvalue in value.items()} diff --git a/src/plumpy/utils.py b/src/plumpy/utils.py index 91cbe21e..a11ebd01 100644 --- a/src/plumpy/utils.py +++ b/src/plumpy/utils.py @@ -171,7 +171,7 @@ def load_function(name: str, instance: Optional[Any] = None) -> Callable[..., An obj = load_object(name) if inspect.ismethod(obj): if instance is not None: - return obj.__get__(instance, instance.__class__) + return obj.__get__(instance, instance.__class__) # type: ignore[attr-defined] return obj diff --git a/tox.ini b/tox.ini index 1759c26e..39cc11f5 100644 --- a/tox.ini +++ b/tox.ini @@ -42,27 +42,3 @@ commands = --re-ignore _build/.* \ --port 0 --open-browser \ -n -b {posargs:html} docs/source/ docs/_build/{posargs:html} - - -[mypy] -show_error_codes = True -disallow_untyped_defs = True -disallow_incomplete_defs = True -check_untyped_defs = True -warn_unused_ignores = True -warn_redundant_casts = True - -[mypy-aiocontextvars.*] -ignore_missing_imports = True - -[mypy-frozendict.*] -ignore_missing_imports = True - -[mypy-kiwipy.*] -ignore_missing_imports = True - -[mypy-nest_asyncio.*] -ignore_missing_imports = True - -[mypy-tblib.*] -ignore_missing_imports = True