You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A change between 19.3.0 → 20.1.0 which doesn't seem to be deliberate, but may be related to #635 is that inherited attributes no longer compare equal to the attributes of the base class. Here is a MWE:
importattr@attr.s()classBaseClass(object):
x=attr.ib()
@attr.s()classSubClass(BaseClass):
passassertattr.fields(BaseClass)[0].name==attr.fields(SubClass)[0].name# Succeeds in all versionsassertattr.fields(BaseClass)[0] ==attr.fields(SubClass)[0] # Fails in 20.1.0
Interestingly, if you shadow the attribute, it works as expected:
importattr@attr.s()classBaseClass(object):
x=attr.ib()
@attr.s()classSubClass(BaseClass):
x=attr.ib()
# Works in all versionsassertattr.fields(BaseClass)[0].name==attr.fields(SubClass)[0].nameassertattr.fields(BaseClass)[0] ==attr.fields(SubClass)[0]
I think the issue is that inherited is included in the calculation of whether two Attributes are equal or not.
I discovered this when upgrading some code that does something like this:
The idea there is that they want to pull out the subset of the structure that corresponds to the base class.
In this case, I can imagine working around it by pulling out the name attribute for each of the Attributes (since in this case I think they would want the subclass to pass along any attribute with the name of an attribute on the base class, not just ones that are configured the same way). I can imagine there might be other problems, though, if attr.filters.include(*attr.fields(BaseClass)) is a common pattern.
The text was updated successfully, but these errors were encountered:
Yeah for all practical purposes, I think we've got it wrong ATM. And I think hashing should also not take it into account. Technically it's wrong but in practice I think it makes it useless.
A change between 19.3.0 → 20.1.0 which doesn't seem to be deliberate, but may be related to #635 is that inherited attributes no longer compare equal to the attributes of the base class. Here is a MWE:
Interestingly, if you shadow the attribute, it works as expected:
I think the issue is that
inherited
is included in the calculation of whether twoAttribute
s are equal or not.I discovered this when upgrading some code that does something like this:
The idea there is that they want to pull out the subset of the structure that corresponds to the base class.
In this case, I can imagine working around it by pulling out the
name
attribute for each of theAttribute
s (since in this case I think they would want the subclass to pass along any attribute with the name of an attribute on the base class, not just ones that are configured the same way). I can imagine there might be other problems, though, ifattr.filters.include(*attr.fields(BaseClass))
is a common pattern.The text was updated successfully, but these errors were encountered: