From 1cc5d9e5d8c4d15a27ccced6def7845ef24f98f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@ericsson.com>
Date: Mon, 2 Sep 2024 16:17:03 +0200
Subject: [PATCH]  added extra __slots__ in Declarer

---
 CHANGELOG.md                         |  3 ++-
 coolamqp/__init__.py                 |  2 +-
 coolamqp/attaches/declarer.py        |  4 ++++
 coolamqp/attaches/utils.py           |  7 ++++---
 tests/test_attaches/test_declarer.py | 13 +++++++++++++
 5 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 tests/test_attaches/test_declarer.py

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33d80fc..e2d55be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,4 +7,5 @@ Since v1.3.2 they'll be put here and in release description.
 * compile_definitions will now depend on requests
 * added support for infinite (None) timeouts during start
 * stress tests will run for 120 seconds now
-* stress tests will be harder, and use more queues
\ No newline at end of file
+* stress tests will be harder, and use more queues
+* added extra __slots__ in Declarer
\ No newline at end of file
diff --git a/coolamqp/__init__.py b/coolamqp/__init__.py
index 9f915c8..19efb0b 100644
--- a/coolamqp/__init__.py
+++ b/coolamqp/__init__.py
@@ -1 +1 @@
-__version__ = '1.3.2b3'
+__version__ = '1.3.2b4'
diff --git a/coolamqp/attaches/declarer.py b/coolamqp/attaches/declarer.py
index e308deb..92601c5 100644
--- a/coolamqp/attaches/declarer.py
+++ b/coolamqp/attaches/declarer.py
@@ -150,6 +150,9 @@ class Operation(object):
 
 
 class DeleteQueue(Operation):
+
+    __slots__ = ()
+
     def __init__(self, declarer, queue, fut, span_parent=None, span_enqueued=None):
         super(DeleteQueue, self).__init__(declarer, queue, fut=fut, span_parent=span_parent,
                                           span_enqueued=span_enqueued)
@@ -181,6 +184,7 @@ class Declarer(Channeler, Synchronized):
 
     This also maintains a list of declared queues/exchanges, and redeclares them on each reconnect.
     """
+    __slots__ = ('in_process', 'on_discard', 'left_to_declare', 'declared', 'cluster')
 
     def __init__(self, cluster):
         """
diff --git a/coolamqp/attaches/utils.py b/coolamqp/attaches/utils.py
index 33dbfdf..70dc6d1 100644
--- a/coolamqp/attaches/utils.py
+++ b/coolamqp/attaches/utils.py
@@ -13,14 +13,14 @@ def close_future(fut, span):  # type: (Future, opentracing.Span) -> Future
     """
     To be called as a Future callback, means to close the span
     """
+    if span is None:
+        return fut
+
     try:
         import opentracing
     except ImportError:
         return fut
 
-    if span is None:
-        return fut
-
     def inner_close(fut):   # type: (Future) -> None
         exc = fut.exception()
         if exc is not None:
@@ -251,6 +251,7 @@ class Synchronized(object):
             ...
 
     """
+    __slots__ = ('_monitor_lock', )
 
     def __init__(self):
         self._monitor_lock = threading.Lock()
diff --git a/tests/test_attaches/test_declarer.py b/tests/test_attaches/test_declarer.py
new file mode 100644
index 0000000..6cc73b1
--- /dev/null
+++ b/tests/test_attaches/test_declarer.py
@@ -0,0 +1,13 @@
+import unittest
+
+from coolamqp.attaches import Declarer
+
+
+class TestDeclarer(unittest.TestCase):
+    def test_declarer_slots(self):
+        """Test that __slots__ are respected"""
+        d = Declarer(None)
+        def add_argument():
+            d.extra_argument = False
+
+        self.assertRaises(AttributeError, add_argument)
-- 
GitLab