-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
When setting kw_only=True at class level with attrs, all fields are set to be keyword only. Since attrs=v25.4.0, individual attributes with kw_only=False are treated as positional (to be consistent with dataclasses, see python-attrs/attrs#1457).
But Mypy still considers attributes with kw_only=False to be keyword only.
To Reproduce
from attrs import define, field
@define(kw_only=True)
class Parent:
param: int = field(kw_only=False)
optional: bool = True
# Valid
p1 = Parent(1)
p2 = Parent(2, optional=False)
@define
class A:
a: int
b: int = field(kw_only=True, default=1)
@define(kw_only=True)
class B(A):
c: int = field(kw_only=False)
d: int = 3
# Valid
B(0, 1)
B(0, 1, b=3, d=4)Expected Behavior
Mypy should not return any error as it's valid behavior with attrs>=v25.4.0
Actual Behavior
test_mypy.py:12: error: Too many positional arguments for "Parent" [misc]
p1 = Parent(1)
^~~~~~~~~
test_mypy.py:13: error: Too many positional arguments for "Parent" [misc]
p2 = Parent(2, optional=False)
^~~~~~~~~~~~~~~~~~~~~~~~~
test_mypy.py:26: error: Too many positional arguments for "B" [misc]
B(0, 1)
^~~~~~~
test_mypy.py:26: error: Missing named argument "c" for "B" [call-arg]
B(0, 1)
^~~~~~~
test_mypy.py:27: error: "B" gets multiple values for keyword argument "b" [misc]
B(0, 1, b=3, d=4)
^~~~~~~~~~~~~~~~~
test_mypy.py:27: error: Missing named argument "c" for "B" [call-arg]
B(0, 1, b=3, d=4)
^~~~~~~~~~~~~~~~~
Found 6 errors in 1 file (checked 1 source file)
Your Environment
Python 3.14.3
mypy 1.19.1 (compiled: no)
attrs 25.4.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong