Skip to content

WebSocketResponse TypeError: Cannot be put into a weakref.WeakSet #4368

Closed
@frederikaalund

Description

Long story short

WebSocketResponse raises TypeError when I attempt to put it into a weakref.WeakSet.

Expected behaviour

I expect to be able to do the above. This is also the recommended graceful shutdown approach.

Actual behaviour

I get a TypeError. It worked previously. It was broken by commit c6e40e7.

Steps to reproduce

Just try to create a weakref.WeakSet and put an instance of WebSocketResponse in it.

Fix

aiohttp/web_ws.py: Add __weakref__ to WebSocketResponse.__slots__

WebSocketResponse can now be put into a WeakSet container again.
This feature was broken by commit c6e40e78ae8de51c02b5a17b8e5e882c910d3770.

Signed-off-by: Frederik Aalund <fpa@sbtinstruments.com>

--- a/aiohttp/web_ws.py	2019-11-21 15:22:37.253377093 +0100
+++ b/aiohttp/web_ws.py	2019-11-21 15:22:40.129377093 +0100
@@ -49,7 +49,7 @@ class WebSocketResponse(StreamResponse):
                  '_closing', '_conn_lost', '_close_code', '_loop', '_waiting',
                  '_exception', '_timeout', '_receive_timeout', '_autoclose',
                  '_autoping', '_heartbeat', '_heartbeat_cb', '_pong_heartbeat',
-                 '_pong_response_cb', '_compress', '_max_msg_size')
+                 '_pong_response_cb', '_compress', '_max_msg_size', '__weakref__')

     def __init__(self, *,
                  timeout: float=10.0, receive_timeout: Optional[float]=None,

Some reference: https://stackoverflow.com/a/19526505/554283

Miscellaneous

This also applies to all other classes that uses __slots__. I can't find a any reference to "__weakref__" when I search through aiohttps codebase.

Your environment

aiohttp v4.0.0a1

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions