Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/+upgrade-lint-typecheck-tooling.misc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade the locked dev tooling: `ruff` 0.15.12 -> 0.16.2, `pyright` 1.1.408 -> 1.1.411, `typer` 0.25.1 -> 0.27.1. Property docstrings are now noun phrases rather than "Get the ..." / "Return the ..." (ruff's new `D421`), and `typer.main.get_command()` is cast to `click.Command` because typer 0.27 vendors its own copy of click.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Property docstrings are now noun phrases rather than "Get the ..." / "Return the ..." (ruff 0.16's new `D421`). `chain_updates()` declares its `events` parameter as `Any`, matching the runtime validation it delegates to. `Field.default`, `Field.default_factory`, and `Field.default_value()` now admit `None`: a field whose annotated type has no computed default is given a `None` default and has its recorded annotation widened to match, so the static types were previously understating what these can hold. Internally, `ImportVar` and `unionize` are imported from the modules that define them instead of by way of `reflex_base.vars.base`, and two dead `is not None` guards were dropped from `_isinstance()` and the dependency-tracking bytecode scanner.
4 changes: 2 additions & 2 deletions packages/reflex-base/src/reflex_base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def prepend_backend_path(self, path: str) -> str:

@property
def app_module(self) -> ModuleType | None:
"""Return the app module if `app_module_import` is set.
"""The app module if `app_module_import` is set.

Returns:
The app module.
Expand All @@ -695,7 +695,7 @@ def app_module(self) -> ModuleType | None:

@property
def module(self) -> str:
"""Get the module name of the app.
"""The module name of the app.

Returns:
The module name.
Expand Down
6 changes: 3 additions & 3 deletions packages/reflex-base/src/reflex_base/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def _get_type_hints(self) -> dict[str, Any]:

@property
def state_full_name(self) -> str:
"""Get the full name of the state class this event handler is attached to.
"""The full name of the state class this event handler is attached to.

Returns:
The full name of the state class this event handler is attached to.
Expand All @@ -550,7 +550,7 @@ def get_parameters(self) -> Mapping[str, inspect.Parameter]:

@property
def _parameters(self) -> Mapping[str, inspect.Parameter]:
"""Get the parameters of the function.
"""The parameters of the function.

Returns:
The parameters of the function.
Expand Down Expand Up @@ -3126,7 +3126,7 @@ def wrapper(

@property
def BaseState(self) -> "type[BaseState]": # noqa: N802
"""Get the BaseState class.
"""The BaseState class.

A reference to BaseState is needed for doc generation when resolving
type hints, so add it to the namespace late to avoid circular import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from reflex.event import Event, EventHandler, EventSpec
from reflex.event import Event, EventHandler
from reflex.state import BaseState

# Resolved once at import: find_spec on a missing package scans sys.path (~90us),
Expand Down Expand Up @@ -194,7 +194,7 @@ async def _route_events(ctx: EventContext, events: Sequence[Event]) -> None:


async def chain_updates(
events: EventSpec | list[EventSpec] | None,
events: Any,
handler_name: str,
root_state: BaseState | None = None,
) -> None:
Expand All @@ -204,7 +204,9 @@ async def chain_updates(
to be queued against the current EventContext.

Args:
events: The events to queue with the update.
events: Whatever the handler yielded; `_check_valid_yield` raises TypeError
for anything that is not an Event, EventHandler, EventSpec, a sequence
of those, or None.
handler_name: The name of the handler that yielded the events, used for error messages.
root_state: The root state of the app, no delta emitted if omitted.
"""
Expand Down
4 changes: 2 additions & 2 deletions packages/reflex-base/src/reflex_base/plugins/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class PageDefinition(Protocol):

@property
def route(self) -> str:
"""Return the route for this page definition."""
"""The route for this page definition."""
...

@property
def component(self) -> PageComponent:
"""Return the component or callable for this page definition."""
"""The component or callable for this page definition."""
...


Expand Down
4 changes: 2 additions & 2 deletions packages/reflex-base/src/reflex_base/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class RegistrationContext(BaseContext):

@property
def app(self) -> App:
"""Get the App instance associated with this context.
"""The App instance associated with this context.

Returns:
The App instance.
Expand All @@ -87,7 +87,7 @@ def app(self) -> App:

@property
def config(self) -> Config:
"""Get the Config associated with this context.
"""The Config associated with this context.

Returns:
The Config instance.
Expand Down
5 changes: 3 additions & 2 deletions packages/reflex-base/src/reflex_base/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import time
from pathlib import Path
from types import FrameType, ModuleType
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, cast

from rich.console import Console
from rich.errors import MarkupError
Expand Down Expand Up @@ -354,7 +354,8 @@ def log_file_stream() -> TextIO:
Returns:
The writable stream of the full-logging file.
"""
return _file_handler().stream
# The handler opens eagerly (delay=False), so its stream is never None.
return cast("TextIO", _file_handler().stream)


@once
Expand Down
2 changes: 1 addition & 1 deletion packages/reflex-base/src/reflex_base/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def _isinstance(
if cls is None or cls is type(None):
return obj is None

if cls is not None and is_union(cls):
if is_union(cls):
return any(
_isinstance(obj, arg, nested=nested, treat_var_as_type=treat_var_as_type)
for arg in get_args(cls)
Expand Down
22 changes: 13 additions & 9 deletions packages/reflex-base/src/reflex_base/vars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ def _replace(

@property
def _cache_attr(self) -> str:
"""Get the attribute used to cache the value on the instance.
"""The attribute used to cache the value on the instance.

Returns:
An attribute name.
Expand All @@ -2473,7 +2473,7 @@ def _cache_attr(self) -> str:

@property
def _last_updated_attr(self) -> str:
"""Get the attribute used to store the last updated timestamp.
"""The attribute used to store the last updated timestamp.

Returns:
An attribute name.
Expand Down Expand Up @@ -2724,7 +2724,7 @@ def _determine_var_type(self) -> type:

@property
def __class__(self) -> type:
"""Get the class of the var.
"""The class of the var.

Returns:
The class of the var.
Expand All @@ -2733,7 +2733,7 @@ def __class__(self) -> type:

@property
def fget(self) -> Callable[[BaseState], RETURN_TYPE]:
"""Get the getter function.
"""The getter function.

Returns:
The getter function.
Expand Down Expand Up @@ -2869,7 +2869,7 @@ async def _awaitable_result(instance: BaseState = instance) -> RETURN_TYPE:

@property
def fget(self) -> Callable[[BaseState], Coroutine[None, None, RETURN_TYPE]]:
"""Get the getter function.
"""The getter function.

Returns:
The getter function.
Expand Down Expand Up @@ -3485,8 +3485,8 @@ class Field(Generic[FIELD_TYPE]):

if TYPE_CHECKING:
type_: GenericType
default: FIELD_TYPE | _MISSING_TYPE
default_factory: Callable[[], FIELD_TYPE] | None
default: FIELD_TYPE | _MISSING_TYPE | None
default_factory: Callable[[], FIELD_TYPE | None] | None

def __init__(
self,
Expand Down Expand Up @@ -3520,7 +3520,11 @@ def __init__(
type_origin = get_origin(annotated_type) or annotated_type

if self.default is MISSING and self.default_factory is None:
default_value = types.get_default_value_for_type(annotated_type)
# A type with no computed default gets None, even when FIELD_TYPE
# itself excludes None; `annotated_type` is widened to match below.
default_value: FIELD_TYPE | None = types.get_default_value_for_type(
annotated_type
)
if default_value is None and not types.is_optional(annotated_type):
annotated_type = annotated_type | None
if types.is_immutable(default_value):
Expand All @@ -3547,7 +3551,7 @@ def __init__(
if key not in self.__dict__ and key not in _RESERVED_FIELD_ATTRS:
self.__dict__[key] = value

def default_value(self) -> FIELD_TYPE:
def default_value(self) -> FIELD_TYPE | None:
"""Get the default value for the field.

Returns:
Expand Down
2 changes: 1 addition & 1 deletion packages/reflex-base/src/reflex_base/vars/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from typing import Any, Literal, TypeVar

from reflex_base.utils.exceptions import VarTypeError
from reflex_base.utils.imports import ImportVar
from reflex_base.vars.number import BooleanVar

from .base import (
CustomVarOperationReturn,
ImportVar,
LiteralVar,
Var,
VarData,
Expand Down
4 changes: 3 additions & 1 deletion packages/reflex-base/src/reflex_base/vars/dep_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ def _populate_dependencies(self) -> None:
tracked_locals=self.tracked_locals,
)
)
elif instruction.opname == "IMPORT_NAME" and instruction.argval is not None:
elif instruction.opname == "IMPORT_NAME":
if instruction.argval is None:
continue
self.scan_status = ScanStatus.GETTING_IMPORT
self._last_import_name = instruction.argval
importlib.import_module(instruction.argval)
Expand Down
3 changes: 1 addition & 2 deletions packages/reflex-base/src/reflex_base/vars/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
VarValueError,
)
from reflex_base.utils.imports import ImportDict, ImportVar
from reflex_base.utils.types import safe_issubclass
from reflex_base.utils.types import safe_issubclass, unionize

from .base import (
CustomVarOperationReturn,
LiteralVar,
Var,
VarData,
unionize,
var_operation,
var_operation_return,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Property docstrings are now noun phrases rather than "Get the ..." / "Return the ..." (ruff 0.16's new `D421`).
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class UploadFile(StarletteUploadFile):

@property
def filename(self) -> str | None:
"""Get the name of the uploaded file.
"""The name of the uploaded file.

Returns:
The name of the uploaded file.
Expand All @@ -66,7 +66,7 @@ def filename(self) -> str | None:

@property
def name(self) -> str | None:
"""Get the name of the uploaded file.
"""The name of the uploaded file.

Returns:
The name of the uploaded file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class AccordionBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the accordion component."""
"""The import variable for the accordion component."""
return ImportVar(tag="Accordion", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AvatarBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the avatar component."""
"""The import variable for the avatar component."""
return ImportVar(tag="Avatar", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CheckboxBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the checkbox component."""
"""The import variable for the checkbox component."""
return ImportVar(tag="Checkbox", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CollapsibleBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the collapsible component."""
"""The import variable for the collapsible component."""
return ImportVar(tag="Collapsible", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ContextMenuBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the context menu component."""
"""The import variable for the context menu component."""
return ImportVar(tag="ContextMenu", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DialogBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the dialog component."""
"""The import variable for the dialog component."""
return ImportVar(tag="Dialog", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DrawerBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the drawer component."""
"""The import variable for the drawer component."""
return ImportVar(tag="Drawer", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InputBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the input component."""
"""The import variable for the input component."""
return ImportVar(tag="Input", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MenuBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the menu component."""
"""The import variable for the menu component."""
return ImportVar(tag="Menu", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class NavigationMenuBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the navigation menu component."""
"""The import variable for the navigation menu component."""
return ImportVar(tag="NavigationMenu", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NumberFieldBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the number field component."""
"""The import variable for the number field component."""
return ImportVar(tag="NumberField", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OTPFieldBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the OTP field component."""
"""The import variable for the OTP field component."""
return ImportVar(tag="OTPField", package_path="", install=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PopoverBaseComponent(BaseUIComponent):

@property
def import_var(self):
"""Return the import variable for the popover component."""
"""The import variable for the popover component."""
return ImportVar(tag="Popover", package_path="", install=False)


Expand Down
Loading
Loading