Skip to content

Commit 824e5fc

Browse files
committed
fix: add isinstance(to, str) guard for pyright type narrowing
Pyright cannot narrow to str after isinstance(to, int) since bool is a subclass of int. Wrapping the string-only code path in an explicit isinstance(to, str) check resolves the type error.
1 parent 13ccbe4 commit 824e5fc

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/reactpy_router/components.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ def _navigate(to: str | int, replace: bool = False) -> VdomDict | None:
110110
def on_navigate_callback(_event: dict[str, Any]) -> None:
111111
set_location(Location(**_event))
112112

113-
if type(to) is int:
113+
if isinstance(to, int):
114114
# Integer navigation (go back/forward) — always delegate to JS;
115115
# the resulting popstate event is handled by the History component.
116116
return Navigate({"onNavigateCallback": on_navigate_callback, "to": to, "replace": replace})
117117

118-
new_path = to.split("?", 1)[0]
119-
if location.path != new_path:
120-
return Navigate({"onNavigateCallback": on_navigate_callback, "to": to, "replace": replace})
118+
if isinstance(to, str):
119+
new_path = to.split("?", 1)[0]
120+
if location.path != new_path:
121+
return Navigate({"onNavigateCallback": on_navigate_callback, "to": to, "replace": replace})
121122

122123
return None

0 commit comments

Comments
 (0)