Skip to content

Commit 5ad64a3

Browse files
authored
satisfy pyright (#2793)
1 parent 48598a6 commit 5ad64a3

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

docs/examples/guide/input/binding01.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class Bar(Static):
88

99

1010
class BindingApp(App):
11-
1211
CSS_PATH = "binding01.css"
1312
BINDINGS = [
1413
("r", "add_bar('red')", "Add Red"),

src/textual/_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from typing_extensions import Protocol
44

55
if TYPE_CHECKING:
6+
from rich.segment import Segment
7+
68
from .message import Message
79

810

src/textual/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def animator(self) -> Animator:
721721
return self._animator
722722

723723
@property
724-
def screen(self) -> Screen:
724+
def screen(self) -> Screen[object]:
725725
"""The current active screen.
726726
727727
Returns:
@@ -834,8 +834,8 @@ def _log(
834834
def call_from_thread(
835835
self,
836836
callback: Callable[..., CallThreadReturnType | Awaitable[CallThreadReturnType]],
837-
*args,
838-
**kwargs,
837+
*args: object,
838+
**kwargs: object,
839839
) -> CallThreadReturnType:
840840
"""Run a callable from another thread, and return the result.
841841
@@ -1712,7 +1712,7 @@ def uninstall_screen(self, screen: Screen | str) -> str | None:
17121712
return name
17131713
return None
17141714

1715-
def pop_screen(self) -> Screen:
1715+
def pop_screen(self) -> Screen[object]:
17161716
"""Pop the current [screen](/guide/screens) from the stack, and switch to the previous screen.
17171717
17181718
Returns:

src/textual/dom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def parent(self) -> DOMNode | None:
457457
return cast("DOMNode | None", self._parent)
458458

459459
@property
460-
def screen(self) -> "Screen":
460+
def screen(self) -> "Screen[object]":
461461
"""The screen containing this node.
462462
463463
Returns:

src/textual/message_pump.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@
3131
from .timer import Timer, TimerCallback
3232

3333
if TYPE_CHECKING:
34+
from typing_extensions import TypeAlias
35+
3436
from .app import App
3537
from .css.model import SelectorSet
3638

3739

40+
Callback: TypeAlias = "Callable[..., Any] | Callable[..., Awaitable[Any]]"
41+
42+
3843
class CallbackError(Exception):
3944
pass
4045

@@ -174,7 +179,7 @@ def has_parent(self) -> bool:
174179
return self._parent is not None
175180

176181
@property
177-
def app(self) -> "App":
182+
def app(self) -> "App[object]":
178183
"""
179184
Get the current app.
180185
@@ -369,7 +374,7 @@ def set_interval(
369374
self._timers.add(timer)
370375
return timer
371376

372-
def call_after_refresh(self, callback: Callable, *args: Any, **kwargs: Any) -> bool:
377+
def call_after_refresh(self, callback: Callback, *args: Any, **kwargs: Any) -> bool:
373378
"""Schedule a callback to run after all messages are processed and the screen
374379
has been refreshed. Positional and keyword arguments are passed to the callable.
375380
@@ -387,7 +392,7 @@ def call_after_refresh(self, callback: Callable, *args: Any, **kwargs: Any) -> b
387392
message = messages.InvokeLater(partial(callback, *args, **kwargs))
388393
return self.post_message(message)
389394

390-
def call_later(self, callback: Callable, *args: Any, **kwargs: Any) -> bool:
395+
def call_later(self, callback: Callback, *args: Any, **kwargs: Any) -> bool:
391396
"""Schedule a callback to run after all messages are processed in this object.
392397
Positional and keywords arguments are passed to the callable.
393398
@@ -404,7 +409,7 @@ def call_later(self, callback: Callable, *args: Any, **kwargs: Any) -> bool:
404409
message = events.Callback(callback=partial(callback, *args, **kwargs))
405410
return self.post_message(message)
406411

407-
def call_next(self, callback: Callable, *args: Any, **kwargs: Any) -> None:
412+
def call_next(self, callback: Callback, *args: Any, **kwargs: Any) -> None:
408413
"""Schedule a callback to run immediately after processing the current message.
409414
410415
Args:

tests/test_concurrency.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_call_from_thread():
2020
class BackgroundThread(Thread):
2121
"""A background thread which will modify app in some way."""
2222

23-
def __init__(self, app: App) -> None:
23+
def __init__(self, app: App[object]) -> None:
2424
self.app = app
2525
super().__init__()
2626

@@ -33,7 +33,7 @@ def write_stuff(text: str) -> None:
3333
# Exit the app with a code we can assert
3434
self.app.call_from_thread(self.app.exit, 123)
3535

36-
class ThreadTestApp(App):
36+
class ThreadTestApp(App[object]):
3737
"""Trivial app with a single widget."""
3838

3939
def compose(self) -> ComposeResult:

0 commit comments

Comments
 (0)