Skip to content

attrs plugin does not implement the new attributes collection algorithm #16014

Open
@eltoder

Description

@eltoder

Bug Report

The attrs plugin does not implement the new attributes collection algorithm that is enabled with @attr.s(collect_by_mro=True) in the old API and is the only option in the new API.

To Reproduce

(mypy-play.net does not have stubs for attrs)

from attrs import define, field

@define
class A:
    f: int = field(kw_only=True)

@define
class B(A):
    pass

@define
class C(A):
    f: int = field()

@define
class D(B, C):
    pass

# D(f: int) for attrs.define, but D(*, f: int) for attr.s
d = D(123)
print(d.f)

Expected Behavior

The signature for D should be D(f: int), so this should type check. It works fine at run time.

Actual Behavior

attrs_mro.py:20: error: Too many positional arguments for "D"  [misc]

I get the same error if I replace @define and field with @attrs(collect_by_mro=True) and attrib from the old namespace respectively. Note that this behavior is correct when @attrs is used without collect_by_mro=True.

Your Environment

  • Mypy version used: 1.5.1
  • Python version used: 3.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions