Skip to content

Commit a0a4300

Browse files
luochen1990Yazawazi
authored andcommitted
fix: typing issues of funix()
1 parent 6c6f0dd commit a0a4300

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

backend/funix/decorator/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from inspect import getsource, isgeneratorfunction, signature
99
from secrets import token_hex
1010
from types import ModuleType
11-
from typing import Callable, Optional, Union
11+
from typing import Callable, Optional, Union, ParamSpec, TypeVar
1212
from uuid import uuid4
1313

1414
from docstring_parser import parse
@@ -195,6 +195,11 @@ def object_is_handled(app_: Flask, object_id: int) -> bool:
195195
return app_.name in handled_object and object_id in handled_object[app_.name]
196196

197197

198+
P = ParamSpec("P")
199+
R = TypeVar("R")
200+
201+
RateLimiter = Union[Limiter, list['RateLimiter'], dict[str, 'RateLimiter'], None]
202+
198203
def funix(
199204
path: Optional[str] = None,
200205
title: Optional[str] = None,
@@ -217,7 +222,7 @@ def funix(
217222
pre_fill: PreFillType = None,
218223
menu: Optional[str] = None,
219224
default: bool = False,
220-
rate_limit: Union[Limiter, list, dict, None] = None,
225+
rate_limit: RateLimiter = None,
221226
reactive: ReactiveType = None,
222227
print_to_web: bool = False,
223228
autorun: bool = False,
@@ -297,7 +302,7 @@ def funix(
297302
if app_.name not in handled_object:
298303
handled_object[app_.name] = []
299304

300-
def decorator(function: Callable) -> callable:
305+
def decorator(function: Callable[P, R]) -> Callable[P, R]:
301306
"""
302307
Decorator for functions to convert them to web apps
303308

backend/funix/hint/__init__.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
For yodas only, the destination of the page.
2424
"""
2525

26-
Parameters = str | tuple
26+
Parameters = str | tuple[str, ...]
2727
"""
2828
Parameters.
2929
@@ -52,9 +52,9 @@
5252
AcceptableWidgetsList = list(getattr(AcceptableWidgets, "__args__"))
5353

5454
WidgetsValue = (
55-
list[AcceptableWidgets | tuple[AcceptableWidgets, dict]]
55+
list[AcceptableWidgets | tuple[AcceptableWidgets, dict[str, Any]]]
5656
| AcceptableWidgets
57-
| tuple[AcceptableWidgets, dict]
57+
| tuple[AcceptableWidgets, dict[str, Any]]
5858
)
5959
"""
6060
The value of the `widgets`.
@@ -97,7 +97,7 @@
9797
{("a", "b"): "cell"} -> The parameter `a` and `b` are cells.
9898
"""
9999

100-
WhitelistValues = list[list] | list
100+
WhitelistValues = list[list[str]] | list[str]
101101
"""
102102
The value of the `whitelist`.
103103
@@ -116,7 +116,7 @@
116116
`["a", "b"]`, for `b` the whitelist is `["c", "d"]`.
117117
"""
118118

119-
ExamplesValues = list[list] | list
119+
ExamplesValues = list[list[str]] | list[str]
120120
"""
121121
The value of the `examples`.
122122
@@ -225,7 +225,7 @@ class ConditionalVisible(TypedDict):
225225
{"a": {"widget": "sheet"}} -> The parameter `a` has a widget, and the widget is `sheet`.
226226
"""
227227

228-
PreFillArgumentFrom = Callable | tuple[Callable, int]
228+
PreFillArgumentFrom = Callable[..., Any] | tuple[Callable[..., Any], int]
229229
"""
230230
Pre-fill argument from.
231231
@@ -245,7 +245,7 @@ class ConditionalVisible(TypedDict):
245245

246246
PreFillEmpty = TypeVar("PreFillEmpty")
247247

248-
ReactiveType = Optional[dict[str, Callable | tuple[Callable, dict[str, str]]]]
248+
ReactiveType = Optional[dict[str, Callable[..., Any] | tuple[Callable[..., Any], dict[str, str]]]]
249249
"""
250250
Document is on the way
251251
"""

backend/funix/py.typed

Whitespace-only changes.

pyproject.toml

+10
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,15 @@ homepage = "https://github.com/TexteaInc/funix"
5555
[project.scripts]
5656
funix = "funix.__main__:cli_main"
5757

58+
[tool.pyright]
59+
include = ["src"]
60+
exclude = ["**/node_modules", "**/__pycache__"]
61+
strict = ["src"]
62+
typeCheckingMode = "strict"
63+
64+
useLibraryCodeForTypes = true
65+
reportMissingImports = true
66+
reportMissingTypeStubs = false
67+
5868
[tool.setuptools.packages.find]
5969
where = ["backend"]

0 commit comments

Comments
 (0)