Skip to content

Commit

Permalink
Dependencies: Update requirement mypy==1.3.0 (#270)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sphuber authored Jun 7, 2023
1 parent a7a6a6a commit 87982d0
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 51 deletions.
26 changes: 15 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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|
)$
21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/plumpy/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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


Expand Down
10 changes: 5 additions & 5 deletions src/plumpy/base/state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/plumpy/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
7 changes: 5 additions & 2 deletions src/plumpy/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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()}
Expand Down
2 changes: 1 addition & 1 deletion src/plumpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 0 additions & 24 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 87982d0

Please sign in to comment.