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

Bug: Incompatible signatures when using WebsocketListener class #3763

Open
2 of 4 tasks
olzhasar opened this issue Sep 28, 2024 · 0 comments · May be fixed by #3765
Open
2 of 4 tasks

Bug: Incompatible signatures when using WebsocketListener class #3763

olzhasar opened this issue Sep 28, 2024 · 0 comments · May be fixed by #3765
Labels
Bug 🐛 This is something that is not working as expected

Comments

@olzhasar
Copy link

olzhasar commented Sep 28, 2024

Description

mypy complains about incompatible signatures when trying to use the WebsocketListener class.
The issue can be reproduced by running mypy over the documentation example.

mypy produces the following error:

docs/examples/websockets/listener_class_based_async.py:8: error: Signature of "on_accept" incompatible with supertype "WebsocketListener"  [override]
docs/examples/websockets/listener_class_based_async.py:8: note:      Superclass:
docs/examples/websockets/listener_class_based_async.py:8: note:          Optional[Callable[..., Any]]
docs/examples/websockets/listener_class_based_async.py:8: note:      Subclass:
docs/examples/websockets/listener_class_based_async.py:8: note:          def on_accept(self, socket: WebSocket[Any, Any, Any]) -> Coroutine[Any, Any, None]
docs/examples/websockets/listener_class_based_async.py:11: error: Signature of "on_disconnect" incompatible with supertype "WebsocketListener"  [override]
docs/examples/websockets/listener_class_based_async.py:11: note:      Superclass:
docs/examples/websockets/listener_class_based_async.py:11: note:          Optional[Callable[..., Any]]
docs/examples/websockets/listener_class_based_async.py:11: note:      Subclass:
docs/examples/websockets/listener_class_based_async.py:11: note:          def on_disconnect(self, socket: WebSocket[Any, Any, Any]) -> Coroutine[Any, Any, None]

I'm convinced that docs/examples should be typed checked, it seems that they are currently not.

URL to code causing the issue

No response

MCVE

from litestar import Litestar, WebSocket
from litestar.handlers import WebsocketListener


class Handler(WebsocketListener):
    path = "/"

    async def on_accept(self, socket: WebSocket) -> None:
        print("Connection accepted")

    async def on_disconnect(self, socket: WebSocket) -> None:
        print("Connection closed")

    async def on_receive(self, data: str) -> str:
        return data


app = Litestar([Handler])

Steps to reproduce

1. Run `mypy docs/examples/websockets/listener_class_based_async.py`

Logs

No response

Litestar Version

2.12.1

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@olzhasar olzhasar added the Bug 🐛 This is something that is not working as expected label Sep 28, 2024
@olzhasar olzhasar linked a pull request Sep 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant