-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra slots for slotted classes with inheritance #714
Comments
Trying to fix this in #718 It came to me as a surprise, that |
IIRC you don’t save mem by slotting inherited arguments but @Tinche might bring some light. Unrelatedly, am I missing something or didn’t you add a test that your change actually does what it’s supposed to do? |
You wouldn't save mem (as you are inheriting slots-class from dict-class, this it'll have a For the test - I've altered test named |
I've actually missed a broken compatibility in case of inheriting a slotted class from a dict-class that inherits from a slotted class and overrides member_descriptor for slot: @attr.s(slots=True)
class Parent:
x = attr.ib()
@attr.s
class Child(Parent):
@cached_property # So it can be deleted and re-used
def x(self):
...
@attr.s(slots=True)
class Grandchild(Child):
# Currently attrs adds `x` to `__slots__`, so `Grandchild.x` is a `member_descriptor`, but after my PR it would be a `cached_property`
x = attr.ib() Though I don't think that any sane person is actually doing things like that, I've fixed it in the PR. |
Eh since #718 has been merged, I consider this fixed? |
It seems that attrs creates a slot for every attr.ib() defined in class, even if parent class already has a slot for it:
If parent class is a dict-class, everything works fine, except slots tuple doesn't contain inherited attribs:
UPD: I've checked the docs on slotted classes. If they are inherited from a
__dict__
-class they wouldn't be a "normal" slotted class, so this is basically expected behaviour.The text was updated successfully, but these errors were encountered: