Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type warning with AwaitComplete #4088

Closed
davep opened this issue Jan 31, 2024 · 2 comments · Fixed by #4234
Closed

Type warning with AwaitComplete #4088

davep opened this issue Jan 31, 2024 · 2 comments · Fixed by #4234
Labels
bug Something isn't working enhancement New feature or request Task

Comments

@davep
Copy link
Contributor

davep commented Jan 31, 2024

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 davep added bug Something isn't working enhancement New feature or request Task labels Jan 31, 2024
@darrenburns
Copy link
Member

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

davep added a commit to davep/textual-sandbox that referenced this issue Feb 2, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants