From 525534f0768b7315c2b5a455e3dfe674601dd468 Mon Sep 17 00:00:00 2001 From: Nicolas Braud-Santoni Date: Fri, 15 Mar 2019 18:53:04 +0100 Subject: [PATCH] Vector2: Support use of weak references tests/memory: Updated as Vector2 instances are now a tiny bit larger --- ppb_vector/vector2.py | 2 +- tests/test_memory.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ppb_vector/vector2.py b/ppb_vector/vector2.py index 86a1e1bf..80c76229 100644 --- a/ppb_vector/vector2.py +++ b/ppb_vector/vector2.py @@ -57,7 +57,7 @@ class Vector2: y: float # Tell CPython that this isn't an extendable dict - __slots__ = ('x', 'y') + __slots__ = ('x', 'y', '__weakref__') @typing.overload def __init__(self, x: typing.SupportsFloat, y: typing.SupportsFloat): pass diff --git a/tests/test_memory.py b/tests/test_memory.py index 2c1b3dca..0f1bf601 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -20,8 +20,8 @@ def __init__(self, x, y): @given(x=floats(), y=floats()) def test_object_size(x, y): - """Check that Vector2 is 3 times smaller than a naïve version.""" - assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 3 + """Check that Vector2 is 2 times smaller than a naïve version.""" + assert sizeof(Vector2(x, y)) < sizeof(DummyVector(x, y)) / 2 @given(v=vectors())