Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ty 0.0.92 and later now type `var.to(StringVar)`, `var.to(StringVar, str)` and other `Var` subclasses passed as the output type as that subclass, as pyright does, instead of `Unknown`.
6 changes: 4 additions & 2 deletions packages/reflex-base/src/reflex_base/vars/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,10 +1150,12 @@ def to(
) -> ObjectVar[VAR_TYPE]: ...

@overload
def to(self, output: VAR_SUBCLASS, var_type: None = None) -> VAR_SUBCLASS: ...
def to(
self, output: type[VAR_SUBCLASS], var_type: types.GenericType | None = None
) -> VAR_SUBCLASS: ...

@overload
def to(
def to( # pyright: ignore[reportOverlappingOverload]
self,
output: type[OUTPUT] | types.GenericType,
var_type: types.GenericType | None = None,
Expand Down
7 changes: 7 additions & 0 deletions tests/type_checking/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
assert_type(_any_var.to(bool), BooleanVar)
assert_type(_any_var.to(str), StringVar[str])
assert_type(_any_var.to(int), NumberVar[int])
# A `Var` subclass as the output type returns that subclass, with or without a
# `var_type`. The overload took an instance of the subclass rather than the
# class and no `var_type`, so these fell through to the catch-all one, which ty
# 0.0.92 and later solve as `Unknown`.
assert_type(_any_var.to(StringVar), StringVar[str])
assert_type(_any_var.to(BooleanVar), BooleanVar)
assert_type(_any_var.to(StringVar, str), StringVar[str])

# `guess_type` narrows on the declared inner type via a `self` annotation, so
# the `Var[bool]` overload is the one the `bool` shadow affected.
Expand Down
42 changes: 21 additions & 21 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading