Skip to content

Type hint defaults don't work with inheritance #291

@leezu

Description

@leezu

Consider

In [12]: @attr.s(auto_attribs=True)
    ...: class A:
    ...:     a: int = 10
    ...:

In [13]: @attr.s(auto_attribs=True)
    ...: class B(A):
    ...:     pass
    ...:

In [14]: A()
Out[14]: A(a=10)

In [15]: B()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-1c5ecc61f85b> in <module>()
----> 1 B()

TypeError: __init__() missing 1 required positional argument: 'a'

This should work, given that the following works:

In [16]: @attr.s()
    ...: class A:
    ...:     a = attr.ib(default=10)
    ...:

In [17]: @attr.s()
    ...: class B(A):
    ...:     pass
    ...:

In [18]: A()
Out[18]: A(a=10)

In [19]: B()
Out[19]: B(a=10)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions