-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
Description
Bug Report
__init__ definition is ignored when generating attrs.define custom version.
To Reproduce
import attrs
@attrs.define
class A:
x: int
def __init__(self, x: str) -> None: ...
@attrs.define(init=False)
class B:
x: int
def __init__(self, x: str) -> None: ...Expected Behavior
A(1) # error: Argument 1 to "A" has incompatible type "int"; expected "str" [arg-type]
A("1")
B(1) # error: Argument 1 to "B" has incompatible type "int"; expected "str" [arg-type]
B("1")Actual Behavior
A("1") # error: Argument 1 to "A" has incompatible type "str"; expected "int" [arg-type]
B(1) # error: Argument 1 to "B" has incompatible type "int"; expected "str" [arg-type]
B("1")Your Environment
- Mypy version used: mypy 1.20.0+dev
- Mypy command-line flags: file.py --show-traceback
- Mypy configuration options from
mypy.ini(and other config files): NA - Python version used: Python 3.13.9
Notes
I think the issue comes from:
Line 345 in a86f7e3
| init = _get_decorator_bool_argument(ctx, "init", True) |
as it does not check whether the
__init__ method exists, it only checks that init=False when attrs.define is called.Reactions are currently unavailable