Skip to content

order of attributes is 'backwards' in case of multiple inheritance #298

@yarikoptic

Description

@yarikoptic

consider following code. I also added a dummy method m to show that precedence is "correct"ly follows for a basic method

from attr import attributes, attr

@attributes
class A(object):
    a = attr()
    def m(self):
        print("A.m")

@attributes
class B(object):
    b = attr()
    def m(self):
        print("B.m")

@attributes
class C(A, B):
    c = attr()

    def m(self):
        super(C, self).m()

    @classmethod
    def supers(cls):
        return cls.__bases__

c = C(1, 2, 3)

print(c)
c.m()
print("supers=%s" % str(c.supers()))

running it results in

C(b=1, a=2, c=3)
A.m
supers=(<class '__main__.A'>, <class '__main__.B'>)

so the first argument is (IMHO) incorrectly assigned to attribute b not a, and then 2nd one to a...

Before recent 3040bda quick and dirty (and possibly incomplete) fix was to remove reversed around mro within src/attr/_make.py but neither I have looked yet into how logic should be adjusted in the current state of affairs, nor I analyzed for why reversed was needed to start with

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions