removed even more optionals

This commit is contained in:
Khaleel Al-Adhami 2025-02-18 15:27:16 -08:00
parent 035e6a0bbf
commit a6b9f4f1c8
17 changed files with 37 additions and 54 deletions

View File

@ -26,7 +26,6 @@ from typing import (
Coroutine, Coroutine,
Dict, Dict,
MutableMapping, MutableMapping,
Optional,
Type, Type,
Union, Union,
get_args, get_args,
@ -360,7 +359,7 @@ class App(MiddlewareMixin, LifespanMixin):
html_lang: str | None = None html_lang: str | None = None
# Attributes to add to the html root tag of every page. # Attributes to add to the html root tag of every page.
html_custom_attrs: Optional[dict[str, str]] = None html_custom_attrs: dict[str, str] | None = None
# A map from a route to an unevaluated page. # A map from a route to an unevaluated page.
_unevaluated_pages: dict[str, UnevaluatedPage] = dataclasses.field( _unevaluated_pages: dict[str, UnevaluatedPage] = dataclasses.field(
@ -374,7 +373,7 @@ class App(MiddlewareMixin, LifespanMixin):
_api: FastAPI | None = None _api: FastAPI | None = None
# The state class to use for the app. # The state class to use for the app.
_state: Optional[Type[BaseState]] = None _state: Type[BaseState] | None = None
# Class to manage many client states. # Class to manage many client states.
_state_manager: StateManager | None = None _state_manager: StateManager | None = None
@ -985,9 +984,7 @@ class App(MiddlewareMixin, LifespanMixin):
for render, kwargs in DECORATED_PAGES[get_config().app_name]: for render, kwargs in DECORATED_PAGES[get_config().app_name]:
self.add_page(render, **kwargs) self.add_page(render, **kwargs)
def _validate_var_dependencies( def _validate_var_dependencies(self, state: Type[BaseState] | None = None) -> None:
self, state: Optional[Type[BaseState]] = None
) -> None:
"""Validate the dependencies of the vars in the app. """Validate the dependencies of the vars in the app.
Args: Args:

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING, Iterable, Optional, Sequence, Type from typing import TYPE_CHECKING, Iterable, Sequence, Type
from reflex import constants from reflex import constants
from reflex.compiler import templates, utils from reflex.compiler import templates, utils
@ -94,7 +94,7 @@ def _compile_theme(theme: str) -> str:
return templates.THEME.render(theme=theme) return templates.THEME.render(theme=theme)
def _compile_contexts(state: Optional[Type[BaseState]], theme: Component | None) -> str: def _compile_contexts(state: Type[BaseState] | None, theme: Component | None) -> str:
"""Compile the initial state and contexts. """Compile the initial state and contexts.
Args: Args:
@ -353,7 +353,7 @@ def _compile_tailwind(
def compile_document_root( def compile_document_root(
head_components: list[Component], head_components: list[Component],
html_lang: str | None = None, html_lang: str | None = None,
html_custom_attrs: Optional[dict[str, Var | str]] = None, html_custom_attrs: dict[str, Var | str] | None = None,
) -> tuple[str, str]: ) -> tuple[str, str]:
"""Compile the document root. """Compile the document root.
@ -415,7 +415,7 @@ def compile_theme(style: ComponentStyle) -> tuple[str, str]:
def compile_contexts( def compile_contexts(
state: Optional[Type[BaseState]], state: Type[BaseState] | None,
theme: Component | None, theme: Component | None,
) -> tuple[str, str]: ) -> tuple[str, str]:
"""Compile the initial state / context. """Compile the initial state / context.
@ -681,7 +681,7 @@ class ExecutorSafeFunctions:
COMPONENTS: dict[str, BaseComponent] = {} COMPONENTS: dict[str, BaseComponent] = {}
UNCOMPILED_PAGES: dict[str, UnevaluatedPage] = {} UNCOMPILED_PAGES: dict[str, UnevaluatedPage] = {}
STATE: Optional[Type[BaseState]] = None STATE: Type[BaseState] | None = None
@classmethod @classmethod
def compile_page(cls, route: str) -> tuple[str, str]: def compile_page(cls, route: str) -> tuple[str, str]:

View File

@ -7,7 +7,7 @@ import concurrent.futures
import traceback import traceback
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Optional, Type from typing import Any, Callable, Type
from urllib.parse import urlparse from urllib.parse import urlparse
from pydantic.v1.fields import ModelField from pydantic.v1.fields import ModelField
@ -346,7 +346,7 @@ def compile_custom_component(
def create_document_root( def create_document_root(
head_components: list[Component] | None = None, head_components: list[Component] | None = None,
html_lang: str | None = None, html_lang: str | None = None,
html_custom_attrs: Optional[dict[str, Var | str]] = None, html_custom_attrs: dict[str, Var | str] | None = None,
) -> Component: ) -> Component:
"""Create the document root. """Create the document root.

View File

@ -9,17 +9,7 @@ from abc import ABC, abstractmethod
from functools import lru_cache, wraps from functools import lru_cache, wraps
from hashlib import md5 from hashlib import md5
from types import SimpleNamespace from types import SimpleNamespace
from typing import ( from typing import Any, Callable, ClassVar, Iterator, List, Sequence, Type, Union
Any,
Callable,
ClassVar,
Iterator,
List,
Optional,
Sequence,
Type,
Union,
)
from typing_extensions import Self from typing_extensions import Self
@ -238,7 +228,7 @@ class Component(BaseComponent, ABC):
_memoization_mode: MemoizationMode = MemoizationMode() _memoization_mode: MemoizationMode = MemoizationMode()
# State class associated with this component instance # State class associated with this component instance
State: Optional[Type[reflex.state.State]] = None State: Type[reflex.state.State] | None = None
def add_imports(self) -> ImportDict | list[ImportDict]: def add_imports(self) -> ImportDict | list[ImportDict]:
"""Add imports for the component. """Add imports for the component.

View File

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
from pathlib import Path from pathlib import Path
from typing import Any, Callable, ClassVar, List, Optional from typing import Any, Callable, ClassVar, List
from reflex.components.base.fragment import Fragment from reflex.components.base.fragment import Fragment
from reflex.components.component import ( from reflex.components.component import (
@ -197,7 +197,7 @@ class Upload(MemoizationLeaf):
# The list of accepted file types. This should be a dictionary of MIME types as keys and array of file formats as # The list of accepted file types. This should be a dictionary of MIME types as keys and array of file formats as
# values. # values.
# supported MIME types: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types # supported MIME types: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
accept: Var[Optional[dict[str, List]]] accept: Var[dict[str, List] | None]
# Whether the dropzone is disabled. # Whether the dropzone is disabled.
disabled: Var[bool] disabled: Var[bool]

View File

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
from enum import Enum from enum import Enum
from typing import Any, Dict, Literal, Optional, TypedDict from typing import Any, Dict, Literal, TypedDict
from reflex.base import Base from reflex.base import Base
from reflex.components.component import Component, NoSSRComponent from reflex.components.component import Component, NoSSRComponent
@ -148,7 +148,7 @@ class GroupHeaderClickedEventArgs(TypedDict):
class GridCell(TypedDict): class GridCell(TypedDict):
"""The grid cell.""" """The grid cell."""
span: Optional[list[int]] span: list[int] | None
class GridColumn(TypedDict): class GridColumn(TypedDict):

View File

@ -118,7 +118,7 @@ class GroupHeaderClickedEventArgs(TypedDict):
scrollEdge: tuple[int, int] scrollEdge: tuple[int, int]
class GridCell(TypedDict): class GridCell(TypedDict):
span: Optional[list[int]] span: list[int] | None
class GridColumn(TypedDict): class GridColumn(TypedDict):
title: str title: str

View File

@ -4,7 +4,7 @@
# Style based on https://ui.shadcn.com/docs/components/drawer # Style based on https://ui.shadcn.com/docs/components/drawer
from __future__ import annotations from __future__ import annotations
from typing import Any, Literal, Optional from typing import Any, Literal
from reflex.components.component import Component, ComponentNamespace from reflex.components.component import Component, ComponentNamespace
from reflex.components.radix.primitives.base import RadixPrimitiveComponent from reflex.components.radix.primitives.base import RadixPrimitiveComponent
@ -58,7 +58,7 @@ class DrawerRoot(DrawerComponent):
handle_only: Var[bool] handle_only: Var[bool]
# Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up. Should go from least visible. Also Accept px values, which doesn't take screen height into account. # Array of numbers from 0 to 100 that corresponds to % of the screen a given snap point should take up. Should go from least visible. Also Accept px values, which doesn't take screen height into account.
snap_points: Optional[list[str | float]] snap_points: list[str | float] | None
# Index of a snapPoint from which the overlay fade should be applied. Defaults to the last snap point. # Index of a snapPoint from which the overlay fade should be applied. Defaults to the last snap point.
fade_from_index: Var[int] fade_from_index: Var[int]

View File

@ -17,7 +17,7 @@ rx.text(
from __future__ import annotations from __future__ import annotations
from typing import Any, Literal, Optional, Union, get_args from typing import Any, Literal, Union, get_args
from reflex.components.component import BaseComponent from reflex.components.component import BaseComponent
from reflex.components.core.cond import Cond, color_mode_cond, cond from reflex.components.core.cond import Cond, color_mode_cond, cond
@ -99,7 +99,7 @@ class ColorModeIconButton(IconButton):
"""Icon Button for toggling light / dark mode via toggle_color_mode.""" """Icon Button for toggling light / dark mode via toggle_color_mode."""
# The position of the icon button. Follow document flow if None. # The position of the icon button. Follow document flow if None.
position: Optional[Union[LiteralPosition, Var[LiteralPosition]]] = None position: Union[LiteralPosition, Var[LiteralPosition]] | None = None
# Allow picking the "system" value for the color mode. # Allow picking the "system" value for the color mode.
allow_system: bool = False allow_system: bool = False

View File

@ -2,7 +2,7 @@
from __future__ import annotations from __future__ import annotations
from typing import Literal, Optional, Union from typing import Literal
import reflex as rx import reflex as rx
from reflex.components.component import Component, ComponentNamespace from reflex.components.component import Component, ComponentNamespace
@ -118,7 +118,7 @@ class HighLevelRadioGroup(RadixThemesComponent):
@classmethod @classmethod
def create( def create(
cls, cls,
items: Var[list[Optional[Union[str, int, float, list, dict, bool]]]], items: Var[list[str | int | float | list | dict | bool | None]],
**props, **props,
) -> Component: ) -> Component:
"""Create a radio group component. """Create a radio group component.

View File

@ -3,7 +3,7 @@
from __future__ import annotations from __future__ import annotations
import enum import enum
from typing import Any, Dict, Literal, Optional, Union from typing import Any, Dict, Literal, Union
from reflex.base import Base from reflex.base import Base
from reflex.components.component import Component, NoSSRComponent from reflex.components.component import Component, NoSSRComponent
@ -65,7 +65,7 @@ class EditorOptions(Base):
rtl: bool | None = None rtl: bool | None = None
# List of buttons to use in the toolbar. # List of buttons to use in the toolbar.
button_list: Optional[list[Union[list[str], str]]] button_list: list[Union[list[str], str]] | None
def on_blur_spec(e: Var, content: Var[str]) -> tuple[Var[str]]: def on_blur_spec(e: Var, content: Var[str]) -> tuple[Var[str]]:

View File

@ -42,7 +42,7 @@ class EditorOptions(Base):
default_tag: str | None default_tag: str | None
mode: str | None mode: str | None
rtl: bool | None rtl: bool | None
button_list: Optional[list[Union[list[str], str]]] button_list: list[Union[list[str], str]] | None
def on_blur_spec(e: Var, content: Var[str]) -> tuple[Var[str]]: ... def on_blur_spec(e: Var, content: Var[str]) -> tuple[Var[str]]: ...
def on_paste_spec( def on_paste_spec(

View File

@ -23,7 +23,6 @@ from typing import (
Any, Any,
Callable, Callable,
Generic, Generic,
Optional,
TypeVar, TypeVar,
get_args, get_args,
get_origin, get_origin,
@ -789,7 +788,7 @@ class Config(Base):
cors_allowed_origins: list[str] = ["*"] cors_allowed_origins: list[str] = ["*"]
# Tailwind config. # Tailwind config.
tailwind: Optional[dict[str, Any]] = {"plugins": ["@tailwindcss/typography"]} tailwind: dict[str, Any] | None = {"plugins": ["@tailwindcss/typography"]}
# Timeout when launching the gunicorn server. TODO(rename this to backend_timeout?) # Timeout when launching the gunicorn server. TODO(rename this to backend_timeout?)
timeout: int = 120 timeout: int = 120

View File

@ -15,7 +15,6 @@ from typing import (
Callable, Callable,
Generic, Generic,
List, List,
Optional,
Protocol, Protocol,
Sequence, Sequence,
Type, Type,
@ -341,7 +340,7 @@ class CallableEventSpec(EventSpec):
API with functions that return a family of EventSpec. API with functions that return a family of EventSpec.
""" """
fn: Optional[Callable[..., EventSpec]] = None fn: Callable[..., EventSpec] | None = None
def __init__(self, fn: Callable[..., EventSpec] | None = None, **kwargs): def __init__(self, fn: Callable[..., EventSpec] | None = None, **kwargs):
"""Initialize a CallableEventSpec. """Initialize a CallableEventSpec.
@ -394,7 +393,7 @@ class EventChain(EventActionsMixin):
default_factory=list default_factory=list
) )
args_spec: Optional[Union[Callable, Sequence[Callable]]] = dataclasses.field( args_spec: Union[Callable, Sequence[Callable]] | None = dataclasses.field(
default=None default=None
) )

View File

@ -23,7 +23,7 @@ import zipfile
from datetime import datetime from datetime import datetime
from pathlib import Path from pathlib import Path
from types import ModuleType from types import ModuleType
from typing import Any, Callable, NamedTuple, Optional from typing import Any, Callable, NamedTuple
from urllib.parse import urlparse from urllib.parse import urlparse
import httpx import httpx
@ -886,7 +886,7 @@ def init_reflex_json(project_hash: int | None):
def update_next_config( def update_next_config(
export: bool = False, transpile_packages: Optional[list[str]] = None export: bool = False, transpile_packages: list[str] | None = None
): ):
"""Update Next.js config from Reflex config. """Update Next.js config from Reflex config.
@ -908,7 +908,7 @@ def update_next_config(
def _update_next_config( def _update_next_config(
config: Config, export: bool = False, transpile_packages: Optional[list[str]] = None config: Config, export: bool = False, transpile_packages: list[str] | None = None
): ):
next_config = { next_config = {
"basePath": config.frontend_path or "", "basePath": config.frontend_path or "",

View File

@ -28,7 +28,6 @@ from typing import (
Literal, Literal,
Mapping, Mapping,
NoReturn, NoReturn,
Optional,
ParamSpec, ParamSpec,
Sequence, Sequence,
Set, Set,
@ -1967,7 +1966,7 @@ class ComputedVar(Var[RETURN_TYPE]):
fget: Callable[[BASE_STATE], RETURN_TYPE], fget: Callable[[BASE_STATE], RETURN_TYPE],
initial_value: RETURN_TYPE | types.Unset = types.Unset(), initial_value: RETURN_TYPE | types.Unset = types.Unset(),
cache: bool = True, cache: bool = True,
deps: Optional[list[str | Var]] = None, deps: list[str | Var] | None = None,
auto_deps: bool = True, auto_deps: bool = True,
interval: int | datetime.timedelta | None = None, interval: int | datetime.timedelta | None = None,
backend: bool | None = None, backend: bool | None = None,
@ -2562,7 +2561,7 @@ def computed_var(
fget: None = None, fget: None = None,
initial_value: Any | types.Unset = types.Unset(), initial_value: Any | types.Unset = types.Unset(),
cache: bool = True, cache: bool = True,
deps: Optional[list[str | Var]] = None, deps: list[str | Var] | None = None,
auto_deps: bool = True, auto_deps: bool = True,
interval: datetime.timedelta | int | None = None, interval: datetime.timedelta | int | None = None,
backend: bool | None = None, backend: bool | None = None,
@ -2575,7 +2574,7 @@ def computed_var(
fget: Callable[[BASE_STATE], RETURN_TYPE], fget: Callable[[BASE_STATE], RETURN_TYPE],
initial_value: RETURN_TYPE | types.Unset = types.Unset(), initial_value: RETURN_TYPE | types.Unset = types.Unset(),
cache: bool = True, cache: bool = True,
deps: Optional[list[str | Var]] = None, deps: list[str | Var] | None = None,
auto_deps: bool = True, auto_deps: bool = True,
interval: datetime.timedelta | int | None = None, interval: datetime.timedelta | int | None = None,
backend: bool | None = None, backend: bool | None = None,
@ -2587,7 +2586,7 @@ def computed_var(
fget: Callable[[BASE_STATE], Any] | None = None, fget: Callable[[BASE_STATE], Any] | None = None,
initial_value: Any | types.Unset = types.Unset(), initial_value: Any | types.Unset = types.Unset(),
cache: bool = True, cache: bool = True,
deps: Optional[list[str | Var]] = None, deps: list[str | Var] | None = None,
auto_deps: bool = True, auto_deps: bool = True,
interval: datetime.timedelta | int | None = None, interval: datetime.timedelta | int | None = None,
backend: bool | None = None, backend: bool | None = None,

View File

@ -9,7 +9,6 @@ from typing import (
Callable, Callable,
Concatenate, Concatenate,
Generic, Generic,
Optional,
ParamSpec, ParamSpec,
Protocol, Protocol,
Sequence, Sequence,
@ -242,7 +241,7 @@ class FunctionStringVar(FunctionVar[CALLABLE_TYPE]):
class VarOperationCall(Generic[P, R], CachedVarOperation, Var[R]): class VarOperationCall(Generic[P, R], CachedVarOperation, Var[R]):
"""Base class for immutable vars that are the result of a function call.""" """Base class for immutable vars that are the result of a function call."""
_func: Optional[FunctionVar[ReflexCallable[P, R]]] = dataclasses.field(default=None) _func: FunctionVar[ReflexCallable[P, R]] | None = dataclasses.field(default=None)
_args: tuple[Var | Any, ...] = dataclasses.field(default_factory=tuple) _args: tuple[Var | Any, ...] = dataclasses.field(default_factory=tuple)
@cached_property_no_lock @cached_property_no_lock