add more type annotations through the code
This commit is contained in:
parent
bcea79cd45
commit
4a65a97c21
@ -627,8 +627,8 @@ class App(MiddlewareMixin, LifespanMixin):
|
||||
Args:
|
||||
component: The component to display at the page.
|
||||
title: The title of the page.
|
||||
description: The description of the page.
|
||||
image: The image to display on the page.
|
||||
description: The description of the page.
|
||||
on_load: The event handler(s) that will be called each time the page load.
|
||||
meta: The metadata of the page.
|
||||
"""
|
||||
@ -1277,15 +1277,14 @@ async def process(
|
||||
if app._process_background(state, event) is not None:
|
||||
# `final=True` allows the frontend send more events immediately.
|
||||
yield StateUpdate(final=True)
|
||||
return
|
||||
else:
|
||||
# Process the event synchronously.
|
||||
async for update in state._process(event):
|
||||
# Postprocess the event.
|
||||
update = await app._postprocess(state, event, update)
|
||||
|
||||
# Process the event synchronously.
|
||||
async for update in state._process(event):
|
||||
# Postprocess the event.
|
||||
update = await app._postprocess(state, event, update)
|
||||
|
||||
# Yield the update.
|
||||
yield update
|
||||
# Yield the update.
|
||||
yield update
|
||||
except Exception as ex:
|
||||
telemetry.send_error(ex, context="backend")
|
||||
|
||||
@ -1476,7 +1475,7 @@ class EventNamespace(AsyncNamespace):
|
||||
super().__init__(namespace)
|
||||
self.app = app
|
||||
|
||||
def on_connect(self, sid, environ):
|
||||
def on_connect(self, sid: str, environ: dict):
|
||||
"""Event for when the websocket is connected.
|
||||
|
||||
Args:
|
||||
@ -1485,7 +1484,7 @@ class EventNamespace(AsyncNamespace):
|
||||
"""
|
||||
pass
|
||||
|
||||
def on_disconnect(self, sid):
|
||||
def on_disconnect(self, sid: str):
|
||||
"""Event for when the websocket disconnects.
|
||||
|
||||
Args:
|
||||
@ -1507,7 +1506,7 @@ class EventNamespace(AsyncNamespace):
|
||||
self.emit(str(constants.SocketEvent.EVENT), update.json(), to=sid)
|
||||
)
|
||||
|
||||
async def on_event(self, sid, data):
|
||||
async def on_event(self, sid: str, data: Any):
|
||||
"""Event for receiving front-end websocket events.
|
||||
|
||||
Raises:
|
||||
@ -1550,7 +1549,7 @@ class EventNamespace(AsyncNamespace):
|
||||
# Emit the update from processing the event.
|
||||
await self.emit_update(update=update, sid=sid)
|
||||
|
||||
async def on_ping(self, sid):
|
||||
async def on_ping(self, sid: str):
|
||||
"""Event for testing the API endpoint.
|
||||
|
||||
Args:
|
||||
|
@ -61,7 +61,7 @@ class LifespanMixin(AppMixin):
|
||||
|
||||
Args:
|
||||
task: The task to register.
|
||||
task_kwargs: The kwargs of the task.
|
||||
**task_kwargs: The kwargs of the task.
|
||||
|
||||
Raises:
|
||||
InvalidLifespanTaskType: If the task is a generator function.
|
||||
|
@ -79,7 +79,7 @@ class Base(BaseModel): # pyright: ignore [reportUnboundVariable]
|
||||
default=serialize,
|
||||
)
|
||||
|
||||
def set(self, **kwargs):
|
||||
def set(self, **kwargs: Any):
|
||||
"""Set multiple fields and return the object.
|
||||
|
||||
Args:
|
||||
|
@ -69,7 +69,7 @@ class ChartBase(RechartsCharts):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, **props) -> Component:
|
||||
def create(cls, *children: Any, **props: Any) -> Component:
|
||||
"""Create a chart component.
|
||||
|
||||
Args:
|
||||
|
@ -130,7 +130,7 @@ class ToastProps(PropsBase, NoExtrasAllowedProps):
|
||||
# Function that gets called when the toast disappears automatically after it's timeout (duration` prop).
|
||||
on_auto_close: Optional[Any]
|
||||
|
||||
def dict(self, *args, **kwargs) -> dict[str, Any]:
|
||||
def dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
|
||||
"""Convert the object to a dictionary.
|
||||
|
||||
Args:
|
||||
@ -165,7 +165,7 @@ class ToastProps(PropsBase, NoExtrasAllowedProps):
|
||||
class Toaster(Component):
|
||||
"""A Toaster Component for displaying toast notifications."""
|
||||
|
||||
library: str = "sonner@1.5.0"
|
||||
library = "sonner@1.5.0"
|
||||
|
||||
tag = "Toaster"
|
||||
|
||||
@ -226,7 +226,7 @@ class Toaster(Component):
|
||||
imports={
|
||||
"$/utils/state": [ImportVar(tag="refs")],
|
||||
self.library: [ImportVar(tag="toast", install=False)],
|
||||
}
|
||||
} # type: ignore
|
||||
),
|
||||
)
|
||||
return [hook]
|
||||
@ -263,12 +263,12 @@ class Toaster(Component):
|
||||
return run_script(toast_action)
|
||||
|
||||
@staticmethod
|
||||
def toast_info(message: str = "", **kwargs):
|
||||
def toast_info(message: str = "", **kwargs: Any):
|
||||
"""Display an info toast message.
|
||||
|
||||
Args:
|
||||
message: The message to display.
|
||||
kwargs: Additional toast props.
|
||||
**kwargs: Additional toast props.
|
||||
|
||||
Returns:
|
||||
The toast event.
|
||||
@ -276,12 +276,12 @@ class Toaster(Component):
|
||||
return Toaster.send_toast(message, level="info", **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def toast_warning(message: str = "", **kwargs):
|
||||
def toast_warning(message: str = "", **kwargs: Any):
|
||||
"""Display a warning toast message.
|
||||
|
||||
Args:
|
||||
message: The message to display.
|
||||
kwargs: Additional toast props.
|
||||
**kwargs: Additional toast props.
|
||||
|
||||
Returns:
|
||||
The toast event.
|
||||
@ -289,12 +289,12 @@ class Toaster(Component):
|
||||
return Toaster.send_toast(message, level="warning", **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def toast_error(message: str = "", **kwargs):
|
||||
def toast_error(message: str = "", **kwargs: Any):
|
||||
"""Display an error toast message.
|
||||
|
||||
Args:
|
||||
message: The message to display.
|
||||
kwargs: Additional toast props.
|
||||
**kwargs: Additional toast props.
|
||||
|
||||
Returns:
|
||||
The toast event.
|
||||
@ -302,12 +302,12 @@ class Toaster(Component):
|
||||
return Toaster.send_toast(message, level="error", **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def toast_success(message: str = "", **kwargs):
|
||||
def toast_success(message: str = "", **kwargs: Any):
|
||||
"""Display a success toast message.
|
||||
|
||||
Args:
|
||||
message: The message to display.
|
||||
kwargs: Additional toast props.
|
||||
**kwargs: Additional toast props.
|
||||
|
||||
Returns:
|
||||
The toast event.
|
||||
@ -339,7 +339,7 @@ class Toaster(Component):
|
||||
return run_script(dismiss_action)
|
||||
|
||||
@classmethod
|
||||
def create(cls, *children, **props) -> Component:
|
||||
def create(cls, *children: Any, **props: Any) -> Component:
|
||||
"""Create a toaster component.
|
||||
|
||||
Args:
|
||||
|
@ -51,7 +51,7 @@ class ToastProps(PropsBase, NoExtrasAllowedProps):
|
||||
on_dismiss: Optional[Any]
|
||||
on_auto_close: Optional[Any]
|
||||
|
||||
def dict(self, *args, **kwargs) -> dict[str, Any]: ...
|
||||
def dict(self, *args: Any, **kwargs: Any) -> dict[str, Any]: ...
|
||||
|
||||
class Toaster(Component):
|
||||
is_used: ClassVar[bool] = False
|
||||
@ -62,13 +62,13 @@ class Toaster(Component):
|
||||
message: str = "", level: str | None = None, **props
|
||||
) -> EventSpec: ...
|
||||
@staticmethod
|
||||
def toast_info(message: str = "", **kwargs): ...
|
||||
def toast_info(message: str = "", **kwargs: Any): ...
|
||||
@staticmethod
|
||||
def toast_warning(message: str = "", **kwargs): ...
|
||||
def toast_warning(message: str = "", **kwargs: Any): ...
|
||||
@staticmethod
|
||||
def toast_error(message: str = "", **kwargs): ...
|
||||
def toast_error(message: str = "", **kwargs: Any): ...
|
||||
@staticmethod
|
||||
def toast_success(message: str = "", **kwargs): ...
|
||||
def toast_success(message: str = "", **kwargs: Any): ...
|
||||
@staticmethod
|
||||
def toast_dismiss(id: Var | str | None = None): ...
|
||||
@overload
|
||||
|
@ -3,7 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
from typing import Dict, List, Literal, Optional, Tuple, Union
|
||||
from typing import Any, Dict, List, Literal, Optional, Tuple, Union
|
||||
|
||||
from reflex.base import Base
|
||||
from reflex.components.component import Component, NoSSRComponent
|
||||
@ -244,11 +244,13 @@ class Editor(NoSSRComponent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create(cls, set_options: Optional[EditorOptions] = None, **props) -> Component:
|
||||
def create(
|
||||
cls, set_options: Optional[EditorOptions] = None, **props: Any
|
||||
) -> Component:
|
||||
"""Create an instance of Editor. No children allowed.
|
||||
|
||||
Args:
|
||||
set_options(Optional[EditorOptions]): Configuration object to further configure the instance.
|
||||
set_options: Configuration object to further configure the instance.
|
||||
**props: Any properties to be passed to the Editor
|
||||
|
||||
Returns:
|
||||
|
@ -171,7 +171,7 @@ class Editor(NoSSRComponent):
|
||||
"""Create an instance of Editor. No children allowed.
|
||||
|
||||
Args:
|
||||
set_options(Optional[EditorOptions]): Configuration object to further configure the instance.
|
||||
set_options: Configuration object to further configure the instance.
|
||||
lang: Language of the editor. Alternatively to a string, a dict of your language can be passed to this prop. Please refer to the library docs for this. options: "en" | "da" | "de" | "es" | "fr" | "ja" | "ko" | "pt_br" | "ru" | "zh_cn" | "ro" | "pl" | "ckb" | "lv" | "se" | "ua" | "he" | "it" default : "en"
|
||||
name: This is used to set the HTML form name of the editor. This means on HTML form submission, it will be submitted together with contents of the editor by the name provided.
|
||||
default_value: Sets the default value of the editor. This is useful if you don't want the on_change method to be called on render. If you want the on_change method to be called on render please use the set_contents prop
|
||||
|
@ -49,7 +49,7 @@ class Tag:
|
||||
"""Set the tag's fields.
|
||||
|
||||
Args:
|
||||
kwargs: The fields to set.
|
||||
**kwargs: The fields to set.
|
||||
|
||||
Returns:
|
||||
The tag with the fields
|
||||
|
@ -83,7 +83,7 @@ def _get_package_config(exit_on_fail: bool = True) -> dict:
|
||||
The package configuration.
|
||||
|
||||
Raises:
|
||||
Exit: If the pyproject.toml file is not found.
|
||||
Exit: If the pyproject.toml file is not found and exit_on_fail is True.
|
||||
"""
|
||||
pyproject = Path(CustomComponents.PYPROJECT_TOML)
|
||||
try:
|
||||
|
@ -389,7 +389,7 @@ class Var(Generic[VAR_TYPE]):
|
||||
frozen=True,
|
||||
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
||||
)
|
||||
class ToVarOperation(ToOperation, cls):
|
||||
class ToVarOperation(ToOperation, cls): # type: ignore
|
||||
"""Base class of converting a var to another var type."""
|
||||
|
||||
_original: Var = dataclasses.field(
|
||||
@ -447,20 +447,30 @@ class Var(Generic[VAR_TYPE]):
|
||||
|
||||
@overload
|
||||
def _replace(
|
||||
self, _var_type: Type[OTHER_VAR_TYPE], merge_var_data=None, **kwargs: Any
|
||||
self,
|
||||
_var_type: Type[OTHER_VAR_TYPE],
|
||||
merge_var_data: VarData | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Var[OTHER_VAR_TYPE]: ...
|
||||
|
||||
@overload
|
||||
def _replace(
|
||||
self, _var_type: GenericType | None = None, merge_var_data=None, **kwargs: Any
|
||||
self,
|
||||
_var_type: GenericType | None = None,
|
||||
merge_var_data: VarData | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Self: ...
|
||||
|
||||
def _replace(
|
||||
self, _var_type: GenericType | None = None, merge_var_data=None, **kwargs: Any
|
||||
self,
|
||||
_var_type: GenericType | None = None,
|
||||
merge_var_data: VarData | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Self | Var:
|
||||
"""Make a copy of this Var with updated fields.
|
||||
|
||||
Args:
|
||||
_var_type: The new type of the Var.
|
||||
merge_var_data: VarData to merge into the existing VarData.
|
||||
**kwargs: Var fields to update.
|
||||
|
||||
@ -861,7 +871,7 @@ class Var(Generic[VAR_TYPE]):
|
||||
),
|
||||
).guess_type()
|
||||
|
||||
def __eq__(self, other: Var | Any) -> BooleanVar:
|
||||
def __eq__(self, other: Var | Any) -> BooleanVar: # type: ignore
|
||||
"""Check if the current variable is equal to the given variable.
|
||||
|
||||
Args:
|
||||
@ -874,7 +884,7 @@ class Var(Generic[VAR_TYPE]):
|
||||
|
||||
return equal_operation(self, other)
|
||||
|
||||
def __ne__(self, other: Var | Any) -> BooleanVar:
|
||||
def __ne__(self, other: Var | Any) -> BooleanVar: # type: ignore
|
||||
"""Check if the current object is not equal to the given object.
|
||||
|
||||
Parameters:
|
||||
@ -1292,7 +1302,7 @@ class LiteralVar(Var):
|
||||
_var_literal_subclasses.append((cls, var_subclass))
|
||||
|
||||
@classmethod
|
||||
def create(
|
||||
def create( # type: ignore
|
||||
cls,
|
||||
value: Any,
|
||||
_var_data: VarData | None = None,
|
||||
@ -1419,7 +1429,7 @@ T = TypeVar("T")
|
||||
|
||||
# NoReturn is used to match CustomVarOperationReturn with no type hint.
|
||||
@overload
|
||||
def var_operation(
|
||||
def var_operation( # type: ignore
|
||||
func: Callable[P, CustomVarOperationReturn[NoReturn]],
|
||||
) -> Callable[P, Var]: ...
|
||||
|
||||
@ -1469,7 +1479,7 @@ def var_operation(
|
||||
) -> Callable[P, Var[T]]: ...
|
||||
|
||||
|
||||
def var_operation(
|
||||
def var_operation( # type: ignore
|
||||
func: Callable[P, CustomVarOperationReturn[T]],
|
||||
) -> Callable[P, Var[T]]:
|
||||
"""Decorator for creating a var operation.
|
||||
@ -1715,7 +1725,7 @@ class CallableVar(Var):
|
||||
object.__setattr__(self, "fn", fn)
|
||||
object.__setattr__(self, "original_var", original_var)
|
||||
|
||||
def __call__(self, *args, **kwargs) -> Var:
|
||||
def __call__(self, *args: Any, **kwargs: Any) -> Var:
|
||||
"""Call the decorated function.
|
||||
|
||||
Args:
|
||||
@ -1876,10 +1886,16 @@ class ComputedVar(Var[RETURN_TYPE]):
|
||||
object.__setattr__(self, "_fget", fget)
|
||||
|
||||
@override
|
||||
def _replace(self, merge_var_data=None, **kwargs: Any) -> Self:
|
||||
def _replace(
|
||||
self,
|
||||
_var_type: Any = None,
|
||||
merge_var_data: VarData | None = None,
|
||||
**kwargs: Any,
|
||||
) -> Self:
|
||||
"""Replace the attributes of the ComputedVar.
|
||||
|
||||
Args:
|
||||
_var_type: ignored in ComputedVar.
|
||||
merge_var_data: VarData to merge into the existing VarData.
|
||||
**kwargs: Var fields to update.
|
||||
|
||||
@ -1992,7 +2008,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
||||
@overload
|
||||
def __get__(self, instance: BaseState, owner: Type) -> RETURN_TYPE: ...
|
||||
|
||||
def __get__(self, instance: BaseState | None, owner):
|
||||
def __get__(self, instance: BaseState | None, owner: Type):
|
||||
"""Get the ComputedVar value.
|
||||
|
||||
If the value is already cached on the instance, return the cached value.
|
||||
@ -2158,7 +2174,7 @@ class ComputedVar(Var[RETURN_TYPE]):
|
||||
self_is_top_of_stack = False
|
||||
return d
|
||||
|
||||
def mark_dirty(self, instance) -> None:
|
||||
def mark_dirty(self, instance: BaseState) -> None:
|
||||
"""Mark this ComputedVar as dirty.
|
||||
|
||||
Args:
|
||||
@ -2880,7 +2896,7 @@ BASE_TYPE = TypeVar("BASE_TYPE", bound=Base)
|
||||
class Field(Generic[T]):
|
||||
"""Shadow class for Var to allow for type hinting in the IDE."""
|
||||
|
||||
def __set__(self, instance, value: T):
|
||||
def __set__(self, instance: Any, value: T):
|
||||
"""Set the Var.
|
||||
|
||||
Args:
|
||||
|
@ -210,6 +210,7 @@ class FunctionStringVar(FunctionVar[CALLABLE_TYPE]):
|
||||
|
||||
Args:
|
||||
func: The function to call.
|
||||
_var_type: The type of the Var.
|
||||
_var_data: Additional hooks and imports associated with the Var.
|
||||
|
||||
Returns:
|
||||
@ -268,6 +269,7 @@ class VarOperationCall(Generic[P, R], CachedVarOperation, Var[R]):
|
||||
Args:
|
||||
func: The function to call.
|
||||
*args: The arguments to call the function with.
|
||||
_var_type: The type of the Var.
|
||||
_var_data: Additional hooks and imports associated with the Var.
|
||||
|
||||
Returns:
|
||||
@ -385,6 +387,7 @@ class ArgsFunctionOperation(CachedVarOperation, FunctionVar):
|
||||
return_expr: The return expression of the function.
|
||||
rest: The name of the rest argument.
|
||||
explicit_return: Whether to use explicit return syntax.
|
||||
_var_type: The type of the Var.
|
||||
_var_data: Additional hooks and imports associated with the Var.
|
||||
|
||||
Returns:
|
||||
@ -440,6 +443,7 @@ class ArgsFunctionOperationBuilder(CachedVarOperation, BuilderFunctionVar):
|
||||
return_expr: The return expression of the function.
|
||||
rest: The name of the rest argument.
|
||||
explicit_return: Whether to use explicit return syntax.
|
||||
_var_type: The type of the Var.
|
||||
_var_data: Additional hooks and imports associated with the Var.
|
||||
|
||||
Returns:
|
||||
|
@ -245,7 +245,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=dict):
|
||||
name: str,
|
||||
) -> ObjectItemOperation: ...
|
||||
|
||||
def __getattr__(self, name) -> Var:
|
||||
def __getattr__(self, name: str) -> Var:
|
||||
"""Get an attribute of the var.
|
||||
|
||||
Args:
|
||||
|
@ -743,7 +743,7 @@ class ConcatVarOperation(CachedVarOperation, StringVar[str]):
|
||||
"""Create a var from a string value.
|
||||
|
||||
Args:
|
||||
value: The values to concatenate.
|
||||
*value: The values to concatenate.
|
||||
_var_data: Additional hooks and imports associated with the Var.
|
||||
|
||||
Returns:
|
||||
@ -1286,6 +1286,7 @@ class LiteralArrayVar(CachedVarOperation, LiteralVar, ArrayVar[ARRAY_VAR_TYPE]):
|
||||
|
||||
Args:
|
||||
value: The value to create the var from.
|
||||
_var_type: The type of the var.
|
||||
_var_data: Additional hooks and imports associated with the Var.
|
||||
|
||||
Returns:
|
||||
|
Loading…
Reference in New Issue
Block a user