Skip to content

Commit

Permalink
fix: typing issues of funix()
Browse files Browse the repository at this point in the history
  • Loading branch information
luochen1990 committed Jul 14, 2024
1 parent e52d3a3 commit 4635343
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
11 changes: 8 additions & 3 deletions backend/funix/decorator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from inspect import getsource, isgeneratorfunction, signature
from secrets import token_hex
from types import ModuleType
from typing import Callable, Optional, Union
from typing import Callable, Optional, Union, ParamSpec, TypeVar
from uuid import uuid4

from funix.app import app, sock
Expand Down Expand Up @@ -189,6 +189,11 @@ def object_is_handled(object_id: int) -> bool:
return object_id in handled_object


P = ParamSpec("P")
R = TypeVar("R")

RateLimiter = Union[Limiter, list['RateLimiter'], dict[str, 'RateLimiter'], None]

def funix(
path: Optional[str] = None,
title: Optional[str] = None,
Expand All @@ -211,7 +216,7 @@ def funix(
pre_fill: PreFillType = None,
menu: Optional[str] = None,
default: bool = False,
rate_limit: Union[Limiter, list, dict, None] = None,
rate_limit: RateLimiter = None,
reactive: ReactiveType = None,
print_to_web: bool = False,
autorun: bool = False,
Expand Down Expand Up @@ -268,7 +273,7 @@ def funix(
Check code for details
"""

def decorator(function: Callable) -> callable:
def decorator(function: Callable[P, R]) -> Callable[P, R]:
"""
Decorator for functions to convert them to web apps
Expand Down
14 changes: 7 additions & 7 deletions backend/funix/hint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
For yodas only, the destination of the page.
"""

Parameters = str | tuple
Parameters = str | tuple[str, ...]
"""
Parameters.
Expand Down Expand Up @@ -51,9 +51,9 @@
"""

WidgetsValue = (
list[AcceptableWidgets | tuple[AcceptableWidgets, dict]]
list[AcceptableWidgets | tuple[AcceptableWidgets, dict[str, Any]]]
| AcceptableWidgets
| tuple[AcceptableWidgets, dict]
| tuple[AcceptableWidgets, dict[str, Any]]
)
"""
The value of the `widgets`.
Expand Down Expand Up @@ -96,7 +96,7 @@
{("a", "b"): "cell"} -> The parameter `a` and `b` are cells.
"""

WhitelistValues = list[list] | list
WhitelistValues = list[list[str]] | list[str]
"""
The value of the `whitelist`.
Expand All @@ -115,7 +115,7 @@
`["a", "b"]`, for `b` the whitelist is `["c", "d"]`.
"""

ExamplesValues = list[list] | list
ExamplesValues = list[list[str]] | list[str]
"""
The value of the `examples`.
Expand Down Expand Up @@ -226,7 +226,7 @@ class ConditionalVisible(TypedDict):
{"a": {"widget": "sheet"}} -> The parameter `a` has a widget, and the widget is `sheet`.
"""

PreFillArgumentFrom = Callable | tuple[Callable, int]
PreFillArgumentFrom = Callable[..., Any] | tuple[Callable[..., Any], int]
"""
Pre-fill argument from.
Expand All @@ -246,7 +246,7 @@ class ConditionalVisible(TypedDict):

PreFillEmpty = TypeVar("PreFillEmpty")

ReactiveType = Optional[dict[str, Callable | tuple[Callable, dict[str, str]]]]
ReactiveType = Optional[dict[str, Callable[..., Any] | tuple[Callable[..., Any], dict[str, str]]]]
"""
Document is on the way
"""
Expand Down
Empty file added backend/funix/py.typed
Empty file.
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@ homepage = "https://github.com/TexteaInc/funix"
[project.scripts]
funix = "funix.__main__:cli_main"

[tool.pyright]
include = ["src"]
exclude = ["**/node_modules", "**/__pycache__"]
strict = ["src"]
typeCheckingMode = "strict"

useLibraryCodeForTypes = true
reportMissingImports = true
reportMissingTypeStubs = false

[tool.setuptools.packages.find]
where = ["backend"]

0 comments on commit 4635343

Please sign in to comment.