alisaifee/limits

incorrect `__slots__`

cwells opened this issue · 3 comments

I'm presuming this was intended to be GRANULARITY:

__slots__ = ["namespace", "amount", "multiples", "granularity"]

Confusing when dir(rate) shows a non-existent attribute.

Actually it shouldn't be GRANULARITIES since that is a class, not instance var.

Thanks for the report, turns out the current implementation (even if we ignore the extra granularities slot), was actually
causing the objects to be as large as if they would be without __slots__

No Slots

>>> from pympler.asizeof import asizeof
>>> from limits import parse_many
>>> asizeof(parse_many(",".join(["1/second"] * 100000))) / 1024.0 / 1024.0
15.259986877441406

Slots declared on base class

>>> from pympler.asizeof import asizeof
>>> from limits import parse_many
>>> asizeof(parse_many(",".join(["1/second"] * 100000))) / 1024.0 / 1024.0
15.259811401367188

With slots declared on derived class (RateLimitIterPerSecond etc..)

>>> from pympler.asizeof import asizeof
>>> from limits import parse_many
>>> asizeof(parse_many(",".join(["1/second"] * 100000))) / 1024.0 / 1024.0
6.1045379638671875

Addressed in 2.6.0