Skip to content

Commit 84f2b01

Browse files
Rework typing of the 'Step' __call__ method
Following python/mypy#5876 recommendation around how to make generic callback protocols, this seems like the best way overall
1 parent 3678bde commit 84f2b01

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ disable = [
9595
# Stylistic decisions
9696
"too-few-public-methods",
9797
"too-many-arguments",
98+
# XXX: Mypy and pylint sometimes conflict here, but mypy will check too
99+
# Mainly around callback protocols
100+
# See https://github.com/python/mypy/issues/5876
101+
"arguments-differ",
98102
# TODO: enable those, we want documentation
99103
"missing-class-docstring",
100104
"missing-function-docstring",

src/dwas/_steps/steps.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,31 @@ def __call__(self, step: StepHandler) -> None:
6060
We will strive to provide both types in examples.
6161
"""
6262

63-
__call__: Callable[..., None]
64-
"""
65-
The method to run when the :term:`step` is invoked.
63+
# XXX: pylint will complain about the *args/**kwargs with 'arguments-differ'
64+
# However, this is the canonical way mypy does for callback protocols
65+
# that can accept any kind of parameters.
66+
# To avoid the issue, you can also not inherit from 'Step', all the
67+
# type checking should still work.
68+
#
69+
# See https://github.com/python/mypy/issues/5876.
70+
#
71+
def __call__(self, *args: Any, **kwargs: Any) -> None:
72+
"""
73+
The method to run when the :term:`step` is invoked.
6674
67-
:Parameters:
75+
:Parameters:
6876
69-
It can take any amount of parameters, that can be passed by keyword, so
70-
positional only arguments are not supported.
77+
It can take any amount of parameters, that can be passed by keyword, so
78+
positional only arguments are not supported.
7179
72-
Parameters will then be passed using parametrization, with a few specific
73-
parameters being reserved by the system. Namely:
80+
Parameters will then be passed using parametrization, with a few specific
81+
parameters being reserved by the system. Namely:
7482
75-
- ``step``, which is used to pass the :py:class:`StepHandler`.
83+
- ``step``, which is used to pass the :py:class:`StepHandler`.
7684
77-
For passing other arguments, see :py:func:`dwas.parametrize` and
78-
:py:func:`dwas.set_defaults`.
79-
"""
85+
For passing other arguments, see :py:func:`dwas.parametrize` and
86+
:py:func:`dwas.set_defaults`.
87+
"""
8088

8189

8290
@runtime_checkable

0 commit comments

Comments
 (0)