Skip to content
Open
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
23 changes: 16 additions & 7 deletions src/datastar_py/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def signals(
val = javascript(_as_javascript_expressions(signals) if expressions_ else signals)
return SignalsAttr(value=val, alias=self._alias)

def computed(self, computed_dict: Mapping | None = None, /, **computed: str) -> BaseAttr:
def computed(self, computed_dict: Mapping[str, str] | None = None, /, **computed: str) -> BaseAttr:
"""Create signals that are computed based on an expression."""
computed = {**(computed_dict or {}), **computed}
first, *rest = (
Expand All @@ -207,7 +207,7 @@ def ignore(self) -> IgnoreAttr:
"""Tell Datastar to ignore data-* attributes on the element."""
return IgnoreAttr(alias=self._alias)

def attr(self, attr_dict: Mapping | None = None, /, **attrs: str) -> BaseAttr:
def attr(self, attr_dict: Mapping[str, str] | None = None, /, **attrs: str) -> BaseAttr:
"""Set the value of any HTML attributes to expressions, and keep them in sync."""
attrs = {**(attr_dict or {}), **attrs}
return BaseAttr(
Expand All @@ -220,7 +220,7 @@ def bind(self, signal_name: str) -> BaseAttr:
"""Set up two-way data binding between a signal and an element's value."""
return BindAttr(value=signal_name, alias=self._alias)

def class_(self, class_dict: Mapping | None = None, /, **classes: str) -> BaseAttr:
def class_(self, class_dict: Mapping[str, str] | None = None, /, **classes: str) -> BaseAttr:
"""Add or removes classes to or from an element based on expressions."""
classes = {**(class_dict or {}), **classes}
return BaseAttr(
Expand Down Expand Up @@ -279,7 +279,7 @@ def show(self, expression: str) -> BaseAttr:
"""Show or hides an element based on whether an expression evaluates to true or false."""
return BaseAttr("show", value=expression, alias=self._alias)

def style(self, style_dict: Mapping | None = None, /, **styles: str) -> BaseAttr:
def style(self, style_dict: Mapping[str, str] | None = None, /, **styles: str) -> BaseAttr:
"""Set the value of inline CSS styles on an element based on an expression, and keeps them in sync."""
styles = {**(style_dict or {}), **styles}
return BaseAttr(
Expand Down Expand Up @@ -330,7 +330,7 @@ def query_string(self) -> QueryStringAttr:
return QueryStringAttr(alias=self._alias)


class BaseAttr(Mapping):
class BaseAttr(Mapping[str, str | Literal[True]]):
_attr: str

def __init__(
Expand Down Expand Up @@ -415,6 +415,8 @@ def __str__(self) -> str:


class TimingMod:
_mods: dict[str, list[str]]

def debounce(
self: Self,
wait: int | str,
Expand Down Expand Up @@ -461,6 +463,9 @@ def throttle(


class DelayMod:

_mods: dict[str, list[str]]

def delay(
self: Self,
wait: int | str,
Expand All @@ -474,6 +479,10 @@ def delay(


class ViewtransitionMod:


_mods: dict[str, list[str]]

@property
def viewtransition(self: Self) -> Self:
"""Wrap the expression in document.startViewTransition()."""
Expand Down Expand Up @@ -788,8 +797,8 @@ def _escape(s: str) -> str:
)


def _filter_dict(include: str | None = None, exclude: str | None = None) -> dict:
filter_dict = {}
def _filter_dict(include: str | None = None, exclude: str | None = None) -> dict[str, str]:
filter_dict: dict[str, str] = {}
if include:
filter_dict["include"] = include
if exclude:
Expand Down