remove other deprecated stuff
This commit is contained in:
parent
7cc78cd8ce
commit
cdba3c1a11
@ -303,7 +303,6 @@ _MAPPING: dict = {
|
|||||||
"event": [
|
"event": [
|
||||||
"EventChain",
|
"EventChain",
|
||||||
"EventHandler",
|
"EventHandler",
|
||||||
"background",
|
|
||||||
"call_script",
|
"call_script",
|
||||||
"call_function",
|
"call_function",
|
||||||
"run_script",
|
"run_script",
|
||||||
|
@ -156,7 +156,6 @@ from .constants import Env as Env
|
|||||||
from .constants.colors import Color as Color
|
from .constants.colors import Color as Color
|
||||||
from .event import EventChain as EventChain
|
from .event import EventChain as EventChain
|
||||||
from .event import EventHandler as EventHandler
|
from .event import EventHandler as EventHandler
|
||||||
from .event import background as background
|
|
||||||
from .event import call_function as call_function
|
from .event import call_function as call_function
|
||||||
from .event import call_script as call_script
|
from .event import call_script as call_script
|
||||||
from .event import clear_local_storage as clear_local_storage
|
from .event import clear_local_storage as clear_local_storage
|
||||||
|
@ -25,7 +25,6 @@ from typing import (
|
|||||||
overload,
|
overload,
|
||||||
)
|
)
|
||||||
|
|
||||||
import typing_extensions
|
|
||||||
from typing_extensions import (
|
from typing_extensions import (
|
||||||
Concatenate,
|
Concatenate,
|
||||||
ParamSpec,
|
ParamSpec,
|
||||||
@ -98,32 +97,6 @@ class Event:
|
|||||||
BACKGROUND_TASK_MARKER = "_reflex_background_task"
|
BACKGROUND_TASK_MARKER = "_reflex_background_task"
|
||||||
|
|
||||||
|
|
||||||
def background(fn, *, __internal_reflex_call: bool = False):
|
|
||||||
"""Decorator to mark event handler as running in the background.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
fn: The function to decorate.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The same function, but with a marker set.
|
|
||||||
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
TypeError: If the function is not a coroutine function or async generator.
|
|
||||||
"""
|
|
||||||
if not __internal_reflex_call:
|
|
||||||
console.deprecate(
|
|
||||||
"background-decorator",
|
|
||||||
"Use `rx.event(background=True)` instead.",
|
|
||||||
"0.6.5",
|
|
||||||
"0.7.0",
|
|
||||||
)
|
|
||||||
if not inspect.iscoroutinefunction(fn) and not inspect.isasyncgenfunction(fn):
|
|
||||||
raise TypeError("Background task must be async function or generator.")
|
|
||||||
setattr(fn, BACKGROUND_TASK_MARKER, True)
|
|
||||||
return fn
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(
|
@dataclasses.dataclass(
|
||||||
init=True,
|
init=True,
|
||||||
frozen=True,
|
frozen=True,
|
||||||
@ -810,29 +783,10 @@ def server_side(name: str, sig: inspect.Signature, **kwargs) -> EventSpec:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@overload
|
|
||||||
def redirect(
|
def redirect(
|
||||||
path: str | Var[str],
|
path: str | Var[str],
|
||||||
is_external: Optional[bool] = None,
|
is_external: Optional[bool] = None,
|
||||||
replace: bool = False,
|
replace: bool = False,
|
||||||
) -> EventSpec: ...
|
|
||||||
|
|
||||||
|
|
||||||
@overload
|
|
||||||
@typing_extensions.deprecated("`external` is deprecated use `is_external` instead")
|
|
||||||
def redirect(
|
|
||||||
path: str | Var[str],
|
|
||||||
is_external: Optional[bool] = None,
|
|
||||||
replace: bool = False,
|
|
||||||
external: Optional[bool] = None,
|
|
||||||
) -> EventSpec: ...
|
|
||||||
|
|
||||||
|
|
||||||
def redirect(
|
|
||||||
path: str | Var[str],
|
|
||||||
is_external: Optional[bool] = None,
|
|
||||||
replace: bool = False,
|
|
||||||
external: Optional[bool] = None,
|
|
||||||
) -> EventSpec:
|
) -> EventSpec:
|
||||||
"""Redirect to a new path.
|
"""Redirect to a new path.
|
||||||
|
|
||||||
@ -840,31 +794,15 @@ def redirect(
|
|||||||
path: The path to redirect to.
|
path: The path to redirect to.
|
||||||
is_external: Whether to open in new tab or not.
|
is_external: Whether to open in new tab or not.
|
||||||
replace: If True, the current page will not create a new history entry.
|
replace: If True, the current page will not create a new history entry.
|
||||||
external(Deprecated): Whether to open in new tab or not.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
An event to redirect to the path.
|
An event to redirect to the path.
|
||||||
"""
|
"""
|
||||||
if external is not None:
|
|
||||||
console.deprecate(
|
|
||||||
"The `external` prop in `rx.redirect`",
|
|
||||||
"use `is_external` instead.",
|
|
||||||
"0.6.6",
|
|
||||||
"0.7.0",
|
|
||||||
)
|
|
||||||
|
|
||||||
# is_external should take precedence over external.
|
|
||||||
is_external = (
|
|
||||||
(False if external is None else external)
|
|
||||||
if is_external is None
|
|
||||||
else is_external
|
|
||||||
)
|
|
||||||
|
|
||||||
return server_side(
|
return server_side(
|
||||||
"_redirect",
|
"_redirect",
|
||||||
get_fn_signature(redirect),
|
get_fn_signature(redirect),
|
||||||
path=path,
|
path=path,
|
||||||
external=is_external,
|
external=False if is_external is None else is_external,
|
||||||
replace=replace,
|
replace=replace,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1788,8 +1726,6 @@ V3 = TypeVar("V3")
|
|||||||
V4 = TypeVar("V4")
|
V4 = TypeVar("V4")
|
||||||
V5 = TypeVar("V5")
|
V5 = TypeVar("V5")
|
||||||
|
|
||||||
background_event_decorator = background
|
|
||||||
|
|
||||||
|
|
||||||
class EventCallback(Generic[P, T]):
|
class EventCallback(Generic[P, T]):
|
||||||
"""A descriptor that wraps a function to be used as an event."""
|
"""A descriptor that wraps a function to be used as an event."""
|
||||||
@ -1962,6 +1898,9 @@ class EventNamespace(types.SimpleNamespace):
|
|||||||
func: The function to wrap.
|
func: The function to wrap.
|
||||||
background: Whether the event should be run in the background. Defaults to False.
|
background: Whether the event should be run in the background. Defaults to False.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
TypeError: If background is True and the function is not a coroutine or async generator. # noqa: DAR402
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The wrapped function.
|
The wrapped function.
|
||||||
"""
|
"""
|
||||||
@ -1970,7 +1909,13 @@ class EventNamespace(types.SimpleNamespace):
|
|||||||
func: Callable[Concatenate[BASE_STATE, P], T],
|
func: Callable[Concatenate[BASE_STATE, P], T],
|
||||||
) -> EventCallback[P, T]:
|
) -> EventCallback[P, T]:
|
||||||
if background is True:
|
if background is True:
|
||||||
return background_event_decorator(func, __internal_reflex_call=True) # type: ignore
|
if not inspect.iscoroutinefunction(
|
||||||
|
func
|
||||||
|
) and not inspect.isasyncgenfunction(func):
|
||||||
|
raise TypeError(
|
||||||
|
"Background task must be async function or generator."
|
||||||
|
)
|
||||||
|
setattr(func, BACKGROUND_TASK_MARKER, True)
|
||||||
return func # type: ignore
|
return func # type: ignore
|
||||||
|
|
||||||
if func is not None:
|
if func is not None:
|
||||||
|
@ -102,6 +102,7 @@ from reflex.utils.exceptions import (
|
|||||||
InvalidLockWarningThresholdError,
|
InvalidLockWarningThresholdError,
|
||||||
InvalidStateManagerMode,
|
InvalidStateManagerMode,
|
||||||
LockExpiredError,
|
LockExpiredError,
|
||||||
|
MismatchedArgumentTypeError,
|
||||||
ReflexRuntimeError,
|
ReflexRuntimeError,
|
||||||
SetUndefinedStateVarError,
|
SetUndefinedStateVarError,
|
||||||
StateSchemaMismatchError,
|
StateSchemaMismatchError,
|
||||||
@ -1298,6 +1299,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
SetUndefinedStateVarError: If a value of a var is set without first defining it.
|
SetUndefinedStateVarError: If a value of a var is set without first defining it.
|
||||||
|
MismatchedArgumentTypeError: If the value of a var is not of the correct type.
|
||||||
"""
|
"""
|
||||||
if isinstance(value, MutableProxy):
|
if isinstance(value, MutableProxy):
|
||||||
# unwrap proxy objects when assigning back to the state
|
# unwrap proxy objects when assigning back to the state
|
||||||
@ -1335,12 +1337,10 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
if field.allow_none and not is_optional(field_type):
|
if field.allow_none and not is_optional(field_type):
|
||||||
field_type = Union[field_type, None]
|
field_type = Union[field_type, None]
|
||||||
if not _isinstance(value, field_type):
|
if not _isinstance(value, field_type):
|
||||||
console.deprecate(
|
raise MismatchedArgumentTypeError(
|
||||||
"mismatched-type-assignment",
|
value,
|
||||||
f"Tried to assign value {value} of type {type(value)} to field {type(self).__name__}.{name} of type {field_type}."
|
f"{type(self).__name__}.{name}",
|
||||||
" This might lead to unexpected behavior.",
|
field_type,
|
||||||
"0.6.5",
|
|
||||||
"0.7.0",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set the attribute.
|
# Set the attribute.
|
||||||
|
@ -44,22 +44,7 @@ def set_log_level(log_level: LogLevel):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
log_level: The log level to set.
|
log_level: The log level to set.
|
||||||
|
|
||||||
Raises:
|
|
||||||
ValueError: If the log level is invalid.
|
|
||||||
"""
|
"""
|
||||||
if not isinstance(log_level, LogLevel):
|
|
||||||
deprecate(
|
|
||||||
feature_name="Passing a string to set_log_level",
|
|
||||||
reason="use reflex.constants.LogLevel enum instead",
|
|
||||||
deprecation_version="0.6.6",
|
|
||||||
removal_version="0.7.0",
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
log_level = getattr(LogLevel, log_level.upper())
|
|
||||||
except AttributeError as ae:
|
|
||||||
raise ValueError(f"Invalid log level: {log_level}") from ae
|
|
||||||
|
|
||||||
global _LOG_LEVEL
|
global _LOG_LEVEL
|
||||||
_LOG_LEVEL = log_level
|
_LOG_LEVEL = log_level
|
||||||
|
|
||||||
|
@ -74,6 +74,50 @@ class VarAnnotationError(ReflexError, TypeError):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MismatchedArgumentTypeError(ReflexError, TypeError):
|
||||||
|
"""Custom TypeError for mismatched argument type errors."""
|
||||||
|
|
||||||
|
def __init__(self, value, field_name, expected_type):
|
||||||
|
"""Initialize the MismatchedArgumentError.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value: The name of the argument received.
|
||||||
|
field_name: The expected argument name.
|
||||||
|
expected_type: The expected argument type.
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
f"Expected field '{field_name}' to receive type '{expected_type}', but got '{value}' of type '{type(value)}'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MismatchedComputedVarReturn(ReflexError, TypeError):
|
||||||
|
"""Custom TypeError for mismatched computed var return type errors."""
|
||||||
|
|
||||||
|
def __init__(self, var_name, return_type, expected_type):
|
||||||
|
"""Initialize the MismatchedComputedVarReturn.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
var_name: The name of the computed var.
|
||||||
|
return_type: The return type of the computed var.
|
||||||
|
expected_type: The expected return type.
|
||||||
|
"""
|
||||||
|
super().__init__(
|
||||||
|
f"Computed var '{var_name}' must return type '{expected_type}', got '{return_type}'."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class UntypedComputedVarError(ReflexError, TypeError):
|
||||||
|
"""Custom TypeError for untyped computed var errors."""
|
||||||
|
|
||||||
|
def __init__(self, var_name):
|
||||||
|
"""Initialize the UntypedComputedVarError.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
var_name: The name of the computed var.
|
||||||
|
"""
|
||||||
|
super().__init__(f"Computed var '{var_name}' must have a type annotation.")
|
||||||
|
|
||||||
|
|
||||||
class UploadValueError(ReflexError, ValueError):
|
class UploadValueError(ReflexError, ValueError):
|
||||||
"""Custom ValueError for upload related errors."""
|
"""Custom ValueError for upload related errors."""
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@ from reflex.base import Base
|
|||||||
from reflex.constants.compiler import Hooks
|
from reflex.constants.compiler import Hooks
|
||||||
from reflex.utils import console, exceptions, imports, serializers, types
|
from reflex.utils import console, exceptions, imports, serializers, types
|
||||||
from reflex.utils.exceptions import (
|
from reflex.utils.exceptions import (
|
||||||
|
MismatchedComputedVarReturn,
|
||||||
|
UntypedComputedVarError,
|
||||||
VarAttributeError,
|
VarAttributeError,
|
||||||
VarDependencyError,
|
VarDependencyError,
|
||||||
VarTypeError,
|
VarTypeError,
|
||||||
@ -1830,19 +1832,14 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TypeError: If the computed var dependencies are not Var instances or var names.
|
TypeError: If the computed var dependencies are not Var instances or var names.
|
||||||
|
UntypedComputedVarError: If the computed var is untyped.
|
||||||
"""
|
"""
|
||||||
hint = kwargs.pop("return_type", None) or get_type_hints(fget).get(
|
hint = kwargs.pop("return_type", None) or get_type_hints(fget).get(
|
||||||
"return", Any
|
"return", Any
|
||||||
)
|
)
|
||||||
|
|
||||||
if hint is Any:
|
if hint is Any:
|
||||||
console.deprecate(
|
raise UntypedComputedVarError(var_name=fget.__name__)
|
||||||
"untyped-computed-var",
|
|
||||||
"ComputedVar should have a return type annotation.",
|
|
||||||
"0.6.5",
|
|
||||||
"0.7.0",
|
|
||||||
)
|
|
||||||
|
|
||||||
kwargs.setdefault("_js_expr", fget.__name__)
|
kwargs.setdefault("_js_expr", fget.__name__)
|
||||||
kwargs.setdefault("_var_type", hint)
|
kwargs.setdefault("_var_type", hint)
|
||||||
|
|
||||||
@ -2014,6 +2011,9 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|||||||
instance: the instance of the class accessing this computed var.
|
instance: the instance of the class accessing this computed var.
|
||||||
owner: the class that this descriptor is attached to.
|
owner: the class that this descriptor is attached to.
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
MismatchedComputedVarReturn: If the return type of the getter function does not match the var type.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The value of the var for the given instance.
|
The value of the var for the given instance.
|
||||||
"""
|
"""
|
||||||
@ -2049,14 +2049,11 @@ class ComputedVar(Var[RETURN_TYPE]):
|
|||||||
value = getattr(instance, self._cache_attr)
|
value = getattr(instance, self._cache_attr)
|
||||||
|
|
||||||
if not _isinstance(value, self._var_type):
|
if not _isinstance(value, self._var_type):
|
||||||
console.deprecate(
|
raise MismatchedComputedVarReturn(
|
||||||
"mismatched-computed-var-return",
|
var_name=f"{type(instance).__name__}.{self._js_expr}",
|
||||||
f"Computed var {type(instance).__name__}.{self._js_expr} returned value of type {type(value)}, "
|
return_type=type(value),
|
||||||
f"expected {self._var_type}. This might cause unexpected behavior.",
|
expected_type=self._var_type,
|
||||||
"0.6.5",
|
|
||||||
"0.7.0",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def _deps(
|
def _deps(
|
||||||
|
Loading…
Reference in New Issue
Block a user