Bug report
Bug description:
When running this code:
from dataclasses import dataclass
@dataclass
class A:
a: int = 1
@dataclass
class B(A):
b: int
def __init__(self, *args, **kwargs): ...
I got TypeError: non-default argument 'b' follows default argument
However, if I set init=False for the second dataclass, like this:
from dataclasses import dataclass
@dataclass
class A:
a: int = 1
@dataclass(init=False)
class B(A):
b: int
def __init__(self, *args, **kwargs): ...
There error disappeared.
I think the error comes from the process where dataclass tries to generate the default __init__() and checks the fields. But, if I understand correctly, this should not happen when the class already defines its own __init__().
Although I'm not sure whether the behavior should be defined as a bug, I do find the results inconsistant with the docs, which says
If the class already defines __init__(), this parameter (init) is ignored.
so, intuitively, adding init=False shouldn't have changed the result.
CPython versions tested on:
3.12, 3.13, 3.14
Operating systems tested on:
Windows
Bug report
Bug description:
When running this code:
I got
TypeError: non-default argument 'b' follows default argumentHowever, if I set
init=Falsefor the second dataclass, like this:There error disappeared.
I think the error comes from the process where dataclass tries to generate the default
__init__()and checks the fields. But, if I understand correctly, this should not happen when the class already defines its own__init__().Although I'm not sure whether the behavior should be defined as a bug, I do find the results inconsistant with the docs, which says
so, intuitively, adding
init=Falseshouldn't have changed the result.CPython versions tested on:
3.12, 3.13, 3.14
Operating systems tested on:
Windows