-
-
Notifications
You must be signed in to change notification settings - Fork 137
Closed
Description
related: #416
It seems an empty __slots__
is forgotten in most base classes (like Immutable
, Equable
, etc.), greatly reducing the advantage (i.e. memory savings) of defining __slots__
in their subclasses (e.g. Result
, Maybe
). Unless I'm missing something, this is not intended. In that case I will gladly submit a PR fixing this.
Example
>>> from returns.result import Success # Result defines __slots__
>>> a = Success(4)
>>> a.__dict__ # this should not be present, but it is inherited anyway from base classes without __slots__
{}
>>> object.__setattr__(a, 'foo', 9) # We can technically set any attribute because there is a `__dict__`
>>> a.foo
9
>>> a.__dict__
{'foo': 9}
Expected behavior of slots classes
>>> class Base:
... __slots__ = () # necessary!
>>> class A(Base):
... __slots__ = ('foo', )
...
>>> a = A()
>>> a.foo = 4
>>> a.bar = 9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute 'bar'
>>> a.__dict__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute '__dict__'
Metadata
Metadata
Assignees
Labels
No labels