You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bad-class-definition due to Class Method Assignments when using dataclass_transform() #3259
Pyrefly incorrectly picks up fields from any class method assignments (e.g., inside @classmethod or __init_subclass__). At runtime, these assignments are ignored by Python's dataclasses.dataclass mechanism.
This leads to a false positive bad-class-definition error when a subclass defines a field without a default value.
Other static type checkers (Pytype and MyPy) are OK with the above and do not emit any errors.
Reproduction Example
importtyping@typing.dataclass_transform()classModuleBase:
...
classModule(ModuleBase):
@classmethoddeffoo(cls) ->None:
cls.field: typing.Any=NoneclassSmallModule(Module):
x: int
Pyrefly reports:
ERROR sandbox.py:21:3-4: Dataclass field `x` without a default may not follow dataclass field with a default [[bad-class-definition](https://pyrefly.org/en/docs/error-kinds/#bad-class-definition)]
Activity
QEDady commentedon Apr 28, 2026
I think I have a fix. Will open a PR
Fix false positive bad-class-definition for class methods (pyrefly-or…