Skip to content

Commit 8b68e62

Browse files
committed
Add more typing to hooks
1 parent 1b4d1a3 commit 8b68e62

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

dash/_hooks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import typing as _t
2+
from importlib import metadata as _importlib_metadata
3+
4+
import flask as _f
25

36
_ns = {
47
"setup": [],
@@ -26,12 +29,12 @@ def setup(func):
2629
return func
2730

2831

29-
def route(name=None, methods=("GET",)):
32+
def route(name: _t.Optional[str] = None, methods: _t.Sequence[str] = ("GET",)):
3033
"""
3134
Add a route to the Dash server.
3235
"""
3336

34-
def wrap(func):
37+
def wrap(func: _t.Callable[[], _f.Response]):
3538
_name = name or func.__name__
3639
_ns["routes"].append((_name, func, methods))
3740
return func
@@ -62,9 +65,8 @@ class HooksManager:
6265

6366
# pylint: disable=too-few-public-methods
6467
class HookErrorHandler:
65-
def __init__(self, original, hooks):
68+
def __init__(self, original):
6669
self.original = original
67-
self.hooks = hooks
6870

6971
def __call__(self, err: Exception):
7072
result = None
@@ -84,9 +86,7 @@ def register_setuptools(cls):
8486
if cls._registered:
8587
return
8688

87-
import importlib.metadata # pylint: disable=import-outside-toplevel
88-
89-
for dist in importlib.metadata.distributions():
89+
for dist in _importlib_metadata.distributions():
9090
for entry in dist.entry_points:
9191
if entry.group != "dash":
9292
continue

dash/dash.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,8 @@ def _setup_hooks(self):
605605
):
606606
self.callback(*callback_args, **callback_kwargs)(callback)
607607

608-
error_handler = self._hooks.get_hooks("error")
609-
if error_handler:
610-
self._on_error = self._hooks.HookErrorHandler(self._on_error, error_handler)
608+
if self._hooks.get_hooks("error"):
609+
self._on_error = self._hooks.HookErrorHandler(self._on_error)
611610

612611
def init_app(self, app=None, **kwargs):
613612
"""Initialize the parts of Dash that require a flask app."""

0 commit comments

Comments
 (0)