fix: remove mutable class-level data: list = [] from RingBuffer (#269)

The class-level annotation 'data: list = []' creates a single list shared
among all instances.  While __init__ already rebinds self.data = [], the
class-level default is confusing and fragile.

Remove the class-level default; move the annotation to __init__.

Closes #250
This commit is contained in:
2026-08-28 14:36:59 -04:00
committed by GitHub
parent 7a2ed79759
commit 868cb8c3dc
3 changed files with 17 additions and 2 deletions
+14
View File
@@ -142,3 +142,17 @@ class TestRingBuffer(unittest.TestCase):
result = rb.get()
self.assertEqual(len(result), 1)
self.assertIn(2, result)
def test_instances_do_not_share_data(self):
"""RingBuffer instances must not share the class-level data list.
Previously 'data: list = []' at class level created a single shared list
object. Even though __init__ rebinds self.data, this is a regression guard
to ensure two independently created instances have independent lists.
"""
rb1 = RingBuffer(5)
rb2 = RingBuffer(5)
rb1.append(42)
# rb2 should still be empty — class-level shared list would have 42 here
self.assertEqual(len(rb2), 0)
self.assertIsNot(rb1.data, rb2.data)