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

adding experimental __slots__ to some classes #368

Merged
merged 5 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions amqp/abstract_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def __init__(self, connection, channel_id):

self._setup_listeners()

__slots__ = (
"is_closing",
"connection",
"channel_id",
"method_queue",
"auto_decode",
"_pending",
"_callbacks",
# adding '__dict__' to get dynamic assignment
"__dict__",
"__weakref__",
)

def __enter__(self):
return self

Expand Down
10 changes: 10 additions & 0 deletions amqp/basic_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def __init__(self, body='', children=None, channel=None, **properties):
self.body = body
self.channel = channel

__slots__ = (
"delivery_info",
"body",
"channel",

# adding '__dict__' to get dynamic assignment
auvipy marked this conversation as resolved.
Show resolved Hide resolved
"__dict__",
"__weakref__",
)

@property
def headers(self):
return self.properties.get('application_headers')
Expand Down
13 changes: 13 additions & 0 deletions amqp/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,19 @@ def __init__(self, frame_method=None, frame_args=None, **props):
self.body_size = 0
self.ready = False

__slots__ = (
"frame_method",
"frame_args",
"properties",
"_pending_chunks",
"body_received",
"body_size",
"ready",
# adding '__dict__' to get dynamic assignment
"__dict__",
"__weakref__",
)

def __getattr__(self, name):
# Look for additional properties in the 'properties'
# dictionary, and if present - the 'delivery_info' dictionary.
Expand Down
16 changes: 16 additions & 0 deletions amqp/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ def __init__(self, host, connect_timeout=None,
self.write_timeout = write_timeout
self.socket_settings = socket_settings

__slots__ = (
"connection",
"sock",
"raise_on_initial_eintr",
"_read_buffer",
"host",
"port",
"connect_timeout",
"read_timeout",
"write_timeout",
"socket_settings",
# adding '__dict__' to get dynamic assignment
"__dict__",
"__weakref__",
)

def __repr__(self):
if self.sock:
src = f'{self.sock.getsockname()[0]}:{self.sock.getsockname()[1]}'
Expand Down