remove other deprecated stuff

This commit is contained in:
Lendemor 2025-01-03 18:36:55 +01:00
parent 7cc78cd8ce
commit cdba3c1a11
7 changed files with 72 additions and 103 deletions

View File

@ -303,7 +303,6 @@ _MAPPING: dict = {
"event": [
"EventChain",
"EventHandler",
"background",
"call_script",
"call_function",
"run_script",

View File

@ -156,7 +156,6 @@ from .constants import Env as Env
from .constants.colors import Color as Color
from .event import EventChain as EventChain
from .event import EventHandler as EventHandler
from .event import background as background
from .event import call_function as call_function
from .event import call_script as call_script
from .event import clear_local_storage as clear_local_storage

View File

@ -25,7 +25,6 @@ from typing import (
overload,
)
import typing_extensions
from typing_extensions import (
Concatenate,
ParamSpec,
@ -98,32 +97,6 @@ class Event:
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(
init=True,
frozen=True,
@ -810,29 +783,10 @@ def server_side(name: str, sig: inspect.Signature, **kwargs) -> EventSpec:
)
@overload
def redirect(
path: str | Var[str],
is_external: Optional[bool] = None,
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:
"""Redirect to a new path.
@ -840,31 +794,15 @@ def redirect(
path: The path to redirect to.
is_external: Whether to open in new tab or not.
replace: If True, the current page will not create a new history entry.
external(Deprecated): Whether to open in new tab or not.
Returns:
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(
"_redirect",
get_fn_signature(redirect),
path=path,
external=is_external,
external=False if is_external is None else is_external,
replace=replace,
)
@ -1788,8 +1726,6 @@ V3 = TypeVar("V3")
V4 = TypeVar("V4")
V5 = TypeVar("V5")
background_event_decorator = background
class EventCallback(Generic[P, T]):
"""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.
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:
The wrapped function.
"""
@ -1970,7 +1909,13 @@ class EventNamespace(types.SimpleNamespace):
func: Callable[Concatenate[BASE_STATE, P], T],
) -> EventCallback[P, T]:
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
if func is not None:

View File

@ -102,6 +102,7 @@ from reflex.utils.exceptions import (
InvalidLockWarningThresholdError,
InvalidStateManagerMode,
LockExpiredError,
MismatchedArgumentTypeError,
ReflexRuntimeError,
SetUndefinedStateVarError,
StateSchemaMismatchError,
@ -1298,6 +1299,7 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
Raises:
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):
# 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):
field_type = Union[field_type, None]
if not _isinstance(value, field_type):
console.deprecate(
"mismatched-type-assignment",
f"Tried to assign value {value} of type {type(value)} to field {type(self).__name__}.{name} of type {field_type}."
" This might lead to unexpected behavior.",
"0.6.5",
"0.7.0",
raise MismatchedArgumentTypeError(
value,
f"{type(self).__name__}.{name}",
field_type,
)
# Set the attribute.

View File

@ -44,22 +44,7 @@ def set_log_level(log_level: LogLevel):
Args:
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
_LOG_LEVEL = log_level

View File

@ -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):
"""Custom ValueError for upload related errors."""

View File

@ -45,6 +45,8 @@ from reflex.base import Base
from reflex.constants.compiler import Hooks
from reflex.utils import console, exceptions, imports, serializers, types
from reflex.utils.exceptions import (
MismatchedComputedVarReturn,
UntypedComputedVarError,
VarAttributeError,
VarDependencyError,
VarTypeError,
@ -1830,19 +1832,14 @@ class ComputedVar(Var[RETURN_TYPE]):
Raises:
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(
"return", Any
)
if hint is Any:
console.deprecate(
"untyped-computed-var",
"ComputedVar should have a return type annotation.",
"0.6.5",
"0.7.0",
)
raise UntypedComputedVarError(var_name=fget.__name__)
kwargs.setdefault("_js_expr", fget.__name__)
kwargs.setdefault("_var_type", hint)
@ -2014,6 +2011,9 @@ class ComputedVar(Var[RETURN_TYPE]):
instance: the instance of the class accessing this computed var.
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:
The value of the var for the given instance.
"""
@ -2049,14 +2049,11 @@ class ComputedVar(Var[RETURN_TYPE]):
value = getattr(instance, self._cache_attr)
if not _isinstance(value, self._var_type):
console.deprecate(
"mismatched-computed-var-return",
f"Computed var {type(instance).__name__}.{self._js_expr} returned value of type {type(value)}, "
f"expected {self._var_type}. This might cause unexpected behavior.",
"0.6.5",
"0.7.0",
raise MismatchedComputedVarReturn(
var_name=f"{type(instance).__name__}.{self._js_expr}",
return_type=type(value),
expected_type=self._var_type,
)
return value
def _deps(