Skip to content

Commit 60d547d

Browse files
committed
chore: Fix pyright complaining about event calls
1 parent d8526a2 commit 60d547d

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,5 @@ convention = "google"
197197
[tool.ruff.lint.flake8-pytest-style]
198198
fixture-parentheses = true
199199
mark-parentheses = true
200+
201+
[tool.pyright]

statemachine/transition_mixin.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1+
from typing import Any
12
from typing import Callable
3+
from typing import TypeVar
24

35
from .callbacks import CallbackGroup
6+
from .i18n import _
7+
8+
T = TypeVar("T", bound=Callable)
49

510

611
class AddCallbacksMixin:
7-
def _add_callback(self, callback, grouper: CallbackGroup, is_event=False, **kwargs):
12+
def _add_callback(self, callback: T, grouper: CallbackGroup, is_event=False, **kwargs) -> T:
813
raise NotImplementedError
914

10-
def __call__(self, f):
11-
return self._add_callback(f, CallbackGroup.ON, is_event=True)
15+
def __call__(self, *args, **kwargs) -> Any:
16+
if len(args) == 1 and callable(args[0]):
17+
return self._add_callback(args[0], CallbackGroup.ON, is_event=True)
18+
raise ValueError(
19+
_("Unsupported call signature. Call %s only to register callbacks").format(
20+
self.__class__.__name__
21+
)
22+
)
1223

1324
def before(self, f: Callable):
1425
"""Adds a ``before`` :ref:`transition actions` callback to every :ref:`transition` in the

0 commit comments

Comments
 (0)