textual
textual copied to clipboard
Type warning with `AwaitComplete`
It seems that there is a type error when it comes to awaiting AwaitComplete. As an example, given this code:
from textual.app import App
from textual.widgets import TabbedContent, TabPane
class AwaitableTypeWarningApp(App[None]):
async def on_mount(self) -> None:
await self.query_one(TabbedContent).add_pane(TabPane("Test"))
await self.query_one(TabbedContent).remove_pane("some-tab")
pyright reports:
/Users/davep/develop/python/textual-sandbox/await_type_warning.py
/Users/davep/develop/python/textual-sandbox/await_type_warning.py:7:15 - error: "AwaitComplete" is not awaitable
"AwaitComplete" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
"__await__" is an incompatible type
Type "() -> Iterator[None]" cannot be assigned to type "() -> Generator[Any, None, _T_co@Awaitable]"
Function return type "Iterator[None]" is incompatible with type "Generator[Any, None, _T_co@Awaitable]"
"Iterator[None]" is incompatible with "Generator[Any, None, _T_co@Awaitable]" (reportGeneralTypeIssues)
/Users/davep/develop/python/textual-sandbox/await_type_warning.py:8:15 - error: "AwaitComplete" is not awaitable
"AwaitComplete" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
"__await__" is an incompatible type
Type "() -> Iterator[None]" cannot be assigned to type "() -> Generator[Any, None, _T_co@Awaitable]"
Function return type "Iterator[None]" is incompatible with type "Generator[Any, None, _T_co@Awaitable]"
"Iterator[None]" is incompatible with "Generator[Any, None, _T_co@Awaitable]" (reportGeneralTypeIssues)
2 errors, 0 warnings, 0 informations
I wonder if __await__ should return Iterator[Any] instead of Iterator[None]. I have no idea how to actually type this protocol...