Type annotations for reactive(monotonic) in the tutorial?
#3984
-
|
I needed a timer in the app I'm building, so I was delighted that your tutorial includes one. However, I'm stuck on what the proper type annotation is for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The proper type for diff --git a/docs/examples/tutorial/stopwatch05.py b/docs/examples/tutorial/stopwatch05.py
index 19f6366f7..66a2162a2 100644
--- a/docs/examples/tutorial/stopwatch05.py
+++ b/docs/examples/tutorial/stopwatch05.py
@@ -9,7 +9,7 @@ from textual.widgets import Button, Footer, Header, Static
class TimeDisplay(Static):
"""A widget to display elapsed time."""
- start_time = reactive(monotonic)
+ start_time: reactive[float] = reactive(monotonic)
time = reactive(0.0)
def on_mount(self) -> None:The reason is |
Beta Was this translation helpful? Give feedback.
The proper type for
start_timewould bereactive[float]:The reason is
start_timeis usingmonotonicas a dynamic default andmonotinicreturns afloat. This also explains why mypy…