Skip to content

Commit 6d34f26

Browse files
committed
fix pyright
1 parent 5436fd2 commit 6d34f26

4 files changed

Lines changed: 11 additions & 10 deletions

File tree

packages/reflex-core/src/reflex_core/vars/base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838

3939
from rich.markup import escape
40-
from typing_extensions import dataclass_transform, override
40+
from typing_extensions import LiteralString, dataclass_transform, override
4141

4242
from reflex_core import constants
4343
from reflex_core.constants.compiler import Hooks
@@ -85,6 +85,7 @@
8585
VAR_TYPE = TypeVar("VAR_TYPE", covariant=True)
8686
OTHER_VAR_TYPE = TypeVar("OTHER_VAR_TYPE")
8787
STRING_T = TypeVar("STRING_T", bound=str)
88+
LITERAL_STRING_T = TypeVar("LITERAL_STRING_T", bound=LiteralString)
8889
SEQUENCE_TYPE = TypeVar("SEQUENCE_TYPE", bound=Sequence)
8990

9091
warnings.filterwarnings("ignore", message="fields may not start with an underscore")
@@ -651,17 +652,17 @@ def create( # pyright: ignore [reportOverlappingOverload]
651652
@classmethod
652653
def create( # pyright: ignore [reportOverlappingOverload]
653654
cls,
654-
value: str,
655+
value: LITERAL_STRING_T,
655656
_var_data: VarData | None = None,
656-
) -> LiteralStringVar: ...
657+
) -> LiteralStringVar[LITERAL_STRING_T]: ...
657658

658659
@overload
659660
@classmethod
660661
def create( # pyright: ignore [reportOverlappingOverload]
661662
cls,
662663
value: STRING_T,
663664
_var_data: VarData | None = None,
664-
) -> StringVar[STRING_T]: ...
665+
) -> LiteralStringVar[STRING_T]: ...
665666

666667
@overload
667668
@classmethod

packages/reflex-core/src/reflex_core/vars/sequence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ def create(
573573
)
574574

575575

576-
STRING_TYPE = TypingExtensionsTypeVar("STRING_TYPE", default=str)
576+
STRING_TYPE = TypingExtensionsTypeVar("STRING_TYPE", default=str, covariant=True)
577577

578578

579579
class StringVar(Var[STRING_TYPE], python_types=str):
@@ -1153,7 +1153,7 @@ def get_decimal_string_operation(
11531153
frozen=True,
11541154
slots=True,
11551155
)
1156-
class LiteralStringVar(LiteralVar[str], StringVar[str]):
1156+
class LiteralStringVar(LiteralVar[STRING_TYPE], StringVar[STRING_TYPE]):
11571157
"""Base class for immutable literal string vars."""
11581158

11591159
_var_value: str = dataclasses.field(default="")

tests/units/components/core/test_cond.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any
2+
from typing import Any, Literal
33

44
import pytest
55
from reflex_components_core.base.fragment import Fragment
@@ -184,7 +184,7 @@ def test_cond_assert_types() -> None:
184184
_ = assert_type(cond(True, "hello", var_int), Var[str | int])
185185

186186
# Var[T], U -> Var[T | U]
187-
_ = assert_type(cond(True, var_str, 3), Var[str | int])
187+
_ = assert_type(cond(True, var_str, 3), Var[int | Literal["a"]])
188188

189189
# Var[T], Var[U] -> Var[T | U]
190-
_ = assert_type(cond(True, var_int, var_str), Var[int | str])
190+
_ = assert_type(cond(True, var_int, var_str), Var[int | Literal["a"]])

tests/units/experimental/test_memo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def conditional_slot(
117117
show: rx.Var[bool],
118118
first: rx.Var[rx.Component],
119119
second: rx.Var[rx.Component],
120-
) -> rx.Component:
120+
) -> rx.Var[rx.Component]:
121121
return rx.cond(show, first, second)
122122

123123
definition = EXPERIMENTAL_MEMOS["ConditionalSlot"]

0 commit comments

Comments
 (0)