Skip to content

Commit d0ab95e

Browse files
authored
adding experimental __slots__ to some classes (#368)
* adding experimental __slots__ to some classes * adding more experimental __slots__ to some classes * remove redundant slots * added more experimental slots to classes * remove slots from buffer class
1 parent 59af244 commit d0ab95e

File tree

6 files changed

+81
-0
lines changed

6 files changed

+81
-0
lines changed

amqp/abstract_channel.py

+13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ def __init__(self, connection, channel_id):
3939

4040
self._setup_listeners()
4141

42+
__slots__ = (
43+
"is_closing",
44+
"connection",
45+
"channel_id",
46+
"method_queue",
47+
"auto_decode",
48+
"_pending",
49+
"_callbacks",
50+
# adding '__dict__' to get dynamic assignment
51+
"__dict__",
52+
"__weakref__",
53+
)
54+
4255
def __enter__(self):
4356
return self
4457

amqp/basic_message.py

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ def __init__(self, body='', children=None, channel=None, **properties):
107107
self.body = body
108108
self.channel = channel
109109

110+
__slots__ = (
111+
"delivery_info",
112+
"body",
113+
"channel",
114+
)
115+
110116
@property
111117
def headers(self):
112118
return self.properties.get('application_headers')

amqp/channel.py

+12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ def __init__(self, connection,
122122
if self.connection.confirm_publish:
123123
self.basic_publish = self.basic_publish_confirm
124124

125+
__slots__ = (
126+
"is_open",
127+
"active",
128+
"returned_messages",
129+
"callbacks",
130+
"cancel_callbacks",
131+
"events",
132+
"no_ack_consumers",
133+
"on_open",
134+
"_confirm_selected",
135+
)
136+
125137
def then(self, on_success, on_error=None):
126138
return self.on_open.then(on_success, on_error)
127139

amqp/sasl.py

+17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class PLAIN(SASL):
3434
def __init__(self, username, password):
3535
self.username, self.password = username, password
3636

37+
__slots__ = (
38+
"username",
39+
"password",
40+
)
41+
3742
def start(self, connection):
3843
if self.username is None or self.password is None:
3944
return NotImplemented
@@ -56,6 +61,11 @@ class AMQPLAIN(SASL):
5661
def __init__(self, username, password):
5762
self.username, self.password = username, password
5863

64+
__slots__ = (
65+
"username",
66+
"password",
67+
)
68+
5969
def start(self, connection):
6070
if self.username is None or self.password is None:
6171
return NotImplemented
@@ -104,6 +114,13 @@ def __init__(self, client_name=None, service=b'amqp',
104114
self.service = service
105115
self.rdns = rdns
106116

117+
__slots__ = (
118+
"client_name",
119+
"fail_soft",
120+
"service",
121+
"rdns"
122+
)
123+
107124
def get_hostname(self, connection):
108125
sock = connection.transport.sock
109126
if self.rdns and sock.family in (socket.AF_INET,

amqp/serialization.py

+13
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,19 @@ def __init__(self, frame_method=None, frame_args=None, **props):
488488
self.body_size = 0
489489
self.ready = False
490490

491+
__slots__ = (
492+
"frame_method",
493+
"frame_args",
494+
"properties",
495+
"_pending_chunks",
496+
"body_received",
497+
"body_size",
498+
"ready",
499+
# adding '__dict__' to get dynamic assignment
500+
"__dict__",
501+
"__weakref__",
502+
)
503+
491504
def __getattr__(self, name):
492505
# Look for additional properties in the 'properties'
493506
# dictionary, and if present - the 'delivery_info' dictionary.

amqp/transport.py

+20
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def __init__(self, host, connect_timeout=None,
9797
self.write_timeout = write_timeout
9898
self.socket_settings = socket_settings
9999

100+
__slots__ = (
101+
"connection",
102+
"sock",
103+
"raise_on_initial_eintr",
104+
"_read_buffer",
105+
"host",
106+
"port",
107+
"connect_timeout",
108+
"read_timeout",
109+
"write_timeout",
110+
"socket_settings",
111+
# adding '__dict__' to get dynamic assignment
112+
"__dict__",
113+
"__weakref__",
114+
)
115+
100116
def __repr__(self):
101117
if self.sock:
102118
src = f'{self.sock.getsockname()[0]}:{self.sock.getsockname()[1]}'
@@ -410,6 +426,10 @@ def __init__(self, host, connect_timeout=None, ssl=None, **kwargs):
410426
super().__init__(
411427
host, connect_timeout=connect_timeout, **kwargs)
412428

429+
__slots__ = (
430+
"sslopts",
431+
)
432+
413433
def _setup_transport(self):
414434
"""Wrap the socket in an SSL object."""
415435
self.sock = self._wrap_socket(self.sock, **self.sslopts)

0 commit comments

Comments
 (0)