unbreak ci

This commit is contained in:
Khaleel Al-Adhami 2025-01-07 16:44:12 -08:00
parent c3b8e7a5e1
commit 0430ab42c2
6 changed files with 29 additions and 28 deletions

View File

@ -26,6 +26,7 @@ from typing import (
Iterable, Iterable,
List, List,
Literal, Literal,
Mapping,
NoReturn, NoReturn,
Optional, Optional,
Set, Set,
@ -128,7 +129,7 @@ class VarData:
state: str = "", state: str = "",
field_name: str = "", field_name: str = "",
imports: ImportDict | ParsedImportDict | None = None, imports: ImportDict | ParsedImportDict | None = None,
hooks: dict[str, VarData | None] | None = None, hooks: Mapping[str, VarData | None] | None = None,
deps: list[Var] | None = None, deps: list[Var] | None = None,
position: Hooks.HookPosition | None = None, position: Hooks.HookPosition | None = None,
): ):
@ -644,8 +645,8 @@ class Var(Generic[VAR_TYPE]):
@overload @overload
def to( def to(
self, self,
output: type[dict], output: type[Mapping],
) -> ObjectVar[dict]: ... ) -> ObjectVar[Mapping]: ...
@overload @overload
def to( def to(
@ -823,7 +824,7 @@ class Var(Generic[VAR_TYPE]):
return False return False
if issubclass(type_, list): if issubclass(type_, list):
return [] return []
if issubclass(type_, dict): if issubclass(type_, Mapping):
return {} return {}
if issubclass(type_, tuple): if issubclass(type_, tuple):
return () return ()
@ -1029,7 +1030,7 @@ class Var(Generic[VAR_TYPE]):
f"$/{constants.Dirs.STATE_PATH}": [imports.ImportVar(tag="refs")] f"$/{constants.Dirs.STATE_PATH}": [imports.ImportVar(tag="refs")]
} }
), ),
).to(ObjectVar, Dict[str, str]) ).to(ObjectVar, Mapping[str, str])
return refs[LiteralVar.create(str(self))] return refs[LiteralVar.create(str(self))]
@deprecated("Use `.js_type()` instead.") @deprecated("Use `.js_type()` instead.")
@ -1376,7 +1377,7 @@ class LiteralVar(Var):
serialized_value = serializers.serialize(value) serialized_value = serializers.serialize(value)
if serialized_value is not None: if serialized_value is not None:
if isinstance(serialized_value, dict): if isinstance(serialized_value, Mapping):
return LiteralObjectVar.create( return LiteralObjectVar.create(
serialized_value, serialized_value,
_var_type=type(value), _var_type=type(value),
@ -1461,7 +1462,7 @@ def get_python_literal(value: Union[LiteralVar, Any]) -> Any | None:
P = ParamSpec("P") P = ParamSpec("P")
T = TypeVar("T") T = TypeVar("T", covariant=True)
# NoReturn is used to match CustomVarOperationReturn with no type hint. # NoReturn is used to match CustomVarOperationReturn with no type hint.
@ -1501,7 +1502,7 @@ def var_operation(
) -> Callable[P, ArrayVar[LIST_T]]: ... ) -> Callable[P, ArrayVar[LIST_T]]: ...
OBJECT_TYPE = TypeVar("OBJECT_TYPE", bound=Dict) OBJECT_TYPE = TypeVar("OBJECT_TYPE", bound=Mapping)
@overload @overload
@ -1576,8 +1577,8 @@ def figure_out_type(value: Any) -> types.GenericType:
return Set[unionize(*(figure_out_type(v) for v in value))] return Set[unionize(*(figure_out_type(v) for v in value))]
if isinstance(value, tuple): if isinstance(value, tuple):
return Tuple[unionize(*(figure_out_type(v) for v in value)), ...] return Tuple[unionize(*(figure_out_type(v) for v in value)), ...]
if isinstance(value, dict): if isinstance(value, Mapping):
return Dict[ return Mapping[
unionize(*(figure_out_type(k) for k in value)), unionize(*(figure_out_type(k) for k in value)),
unionize(*(figure_out_type(v) for v in value.values())), unionize(*(figure_out_type(v) for v in value.values())),
] ]
@ -2005,10 +2006,10 @@ class ComputedVar(Var[RETURN_TYPE]):
@overload @overload
def __get__( def __get__(
self: ComputedVar[dict[DICT_KEY, DICT_VAL]], self: ComputedVar[Mapping[DICT_KEY, DICT_VAL]],
instance: None, instance: None,
owner: Type, owner: Type,
) -> ObjectVar[dict[DICT_KEY, DICT_VAL]]: ... ) -> ObjectVar[Mapping[DICT_KEY, DICT_VAL]]: ...
@overload @overload
def __get__( def __get__(
@ -2960,8 +2961,8 @@ class Field(Generic[T]):
@overload @overload
def __get__( def __get__(
self: Field[Dict[str, V]], instance: None, owner self: Field[Mapping[str, V]], instance: None, owner
) -> ObjectVar[Dict[str, V]]: ... ) -> ObjectVar[Mapping[str, V]]: ...
@overload @overload
def __get__( def __get__(

View File

@ -74,7 +74,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
fixed_type = get_origin(self._var_type) or self._var_type fixed_type = get_origin(self._var_type) or self._var_type
if not isclass(fixed_type): if not isclass(fixed_type):
return Any return Any
args = get_args(self._var_type) if issubclass(fixed_type, dict) else () args = get_args(self._var_type) if issubclass(fixed_type, Mapping) else ()
return args[1] if args else Any return args[1] if args else Any
def keys(self) -> ArrayVar[List[str]]: def keys(self) -> ArrayVar[List[str]]:
@ -272,7 +272,7 @@ class ObjectVar(Var[OBJECT_TYPE], python_types=Mapping):
var_type = get_args(var_type)[0] var_type = get_args(var_type)[0]
fixed_type = var_type if isclass(var_type) else get_origin(var_type) fixed_type = var_type if isclass(var_type) else get_origin(var_type)
if (isclass(fixed_type) and not issubclass(fixed_type, dict)) or ( if (isclass(fixed_type) and not issubclass(fixed_type, Mapping)) or (
fixed_type in types.UnionTypes fixed_type in types.UnionTypes
): ):
attribute_type = get_attribute_access_type(var_type, name) attribute_type = get_attribute_access_type(var_type, name)
@ -389,7 +389,7 @@ class LiteralObjectVar(CachedVarOperation, ObjectVar[OBJECT_TYPE], LiteralVar):
@classmethod @classmethod
def create( def create(
cls, cls,
_var_value: dict, _var_value: Mapping,
_var_type: Type[OBJECT_TYPE] | None = None, _var_type: Type[OBJECT_TYPE] | None = None,
_var_data: VarData | None = None, _var_data: VarData | None = None,
) -> LiteralObjectVar[OBJECT_TYPE]: ) -> LiteralObjectVar[OBJECT_TYPE]:

View File

@ -1,4 +1,4 @@
from typing import Dict, List, Tuple from typing import List, Mapping, Tuple
import pytest import pytest
@ -67,7 +67,7 @@ def test_match_components():
assert fourth_return_value_render["children"][0]["contents"] == '{"fourth value"}' assert fourth_return_value_render["children"][0]["contents"] == '{"fourth value"}'
assert match_cases[4][0]._js_expr == '({ ["foo"] : "bar" })' assert match_cases[4][0]._js_expr == '({ ["foo"] : "bar" })'
assert match_cases[4][0]._var_type == Dict[str, str] assert match_cases[4][0]._var_type == Mapping[str, str]
fifth_return_value_render = match_cases[4][1].render() fifth_return_value_render = match_cases[4][1].render()
assert fifth_return_value_render["name"] == "RadixThemesText" assert fifth_return_value_render["name"] == "RadixThemesText"
assert fifth_return_value_render["children"][0]["contents"] == '{"fifth value"}' assert fifth_return_value_render["children"][0]["contents"] == '{"fifth value"}'

View File

@ -1,6 +1,6 @@
from __future__ import annotations from __future__ import annotations
from typing import Any, Dict from typing import Any, Mapping
import pytest import pytest
@ -379,7 +379,7 @@ class StyleState(rx.State):
{ {
"css": Var( "css": Var(
_js_expr=f'({{ ["color"] : ("dark"+{StyleState.color}) }})' _js_expr=f'({{ ["color"] : ("dark"+{StyleState.color}) }})'
).to(Dict[str, str]) ).to(Mapping[str, str])
}, },
), ),
( (

View File

@ -2,7 +2,7 @@ import json
import math import math
import sys import sys
import typing import typing
from typing import Dict, List, Optional, Set, Tuple, Union, cast from typing import Dict, List, Mapping, Optional, Set, Tuple, Union, cast
import pytest import pytest
from pandas import DataFrame from pandas import DataFrame
@ -270,7 +270,7 @@ def test_get_setter(prop: Var, expected):
([1, 2, 3], Var(_js_expr="[1, 2, 3]", _var_type=List[int])), ([1, 2, 3], Var(_js_expr="[1, 2, 3]", _var_type=List[int])),
( (
{"a": 1, "b": 2}, {"a": 1, "b": 2},
Var(_js_expr='({ ["a"] : 1, ["b"] : 2 })', _var_type=Dict[str, int]), Var(_js_expr='({ ["a"] : 1, ["b"] : 2 })', _var_type=Mapping[str, int]),
), ),
], ],
) )

View File

@ -1,4 +1,4 @@
from typing import Dict, List, Union from typing import List, Mapping, Union
import pytest import pytest
@ -37,12 +37,12 @@ class ChildGenericDict(GenericDict):
("a", str), ("a", str),
([1, 2, 3], List[int]), ([1, 2, 3], List[int]),
([1, 2.0, "a"], List[Union[int, float, str]]), ([1, 2.0, "a"], List[Union[int, float, str]]),
({"a": 1, "b": 2}, Dict[str, int]), ({"a": 1, "b": 2}, Mapping[str, int]),
({"a": 1, 2: "b"}, Dict[Union[int, str], Union[str, int]]), ({"a": 1, 2: "b"}, Mapping[Union[int, str], Union[str, int]]),
(CustomDict(), CustomDict), (CustomDict(), CustomDict),
(ChildCustomDict(), ChildCustomDict), (ChildCustomDict(), ChildCustomDict),
(GenericDict({1: 1}), Dict[int, int]), (GenericDict({1: 1}), Mapping[int, int]),
(ChildGenericDict({1: 1}), Dict[int, int]), (ChildGenericDict({1: 1}), Mapping[int, int]),
], ],
) )
def test_figure_out_type(value, expected): def test_figure_out_type(value, expected):