-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mypy static type checking for frontend to pre-commit
- Loading branch information
Showing
5 changed files
with
59 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[mypy] | ||
# https://mypy.readthedocs.io/en/stable/config_file.html | ||
|
||
python_version = 3.10 | ||
disallow_incomplete_defs = True | ||
no_implicit_optional = True | ||
install_types = True | ||
exclude = frontend/utils/request_wrapper.py | ||
ignore_missing_imports = True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
def register_page(page_dict: dict[str, callable]) -> callable: | ||
"""decorator to register page automatically in page dict""" | ||
from typing import Callable, TypeVar | ||
|
||
F = TypeVar("F", bound=Callable[..., None]) | ||
|
||
|
||
def register_page(page_registry_dict: dict[str, F]) -> Callable[[F], F]: | ||
""" | ||
Streamlit page decorator (factory) which takes the page registry dict | ||
as argument and returns the actual decorator, which itself registers | ||
all decorated page functions automatically in page dict. | ||
Args: | ||
page_registry_dict: the dict where to register the page | ||
Returns: | ||
Callable: the actual decorator, a callable which takes a callable as | ||
argument and returns it. | ||
""" | ||
|
||
def inner(func): | ||
page_dict[func.__name__] = func | ||
page_registry_dict[func.__name__] = func | ||
|
||
return inner |