Bug: Incompatible signatures when using WebsocketListener class
olzhasar opened this issue · 0 comments
olzhasar commented
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.