textual icon indicating copy to clipboard operation
textual copied to clipboard

Type warning with `AwaitComplete`

Open davep opened this issue 1 year ago • 1 comments

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 

davep avatar Jan 31 '24 20:01 davep

I wonder if __await__ should return Iterator[Any] instead of Iterator[None]. I have no idea how to actually type this protocol...

darrenburns avatar Feb 01 '24 10:02 darrenburns

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Feb 29 '24 16:02 github-actions[bot]