Skip to content

Commit

Permalink
Vector2: Support use of weak references
Browse files Browse the repository at this point in the history
tests/memory: Updated as Vector2 instances are now a tiny bit larger
  • Loading branch information
nbraud committed Mar 15, 2019
1 parent c7a946b commit 525534f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ppb_vector/vector2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 525534f

Please sign in to comment.