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.
Other static type checkers (Pytype and MyPy) are OK with the above and do not emit any errors.
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)]
Describe the Bug
Pyrefly incorrectly picks up fields from any class method assignments (e.g., inside
@classmethodor__init_subclass__). At runtime, these assignments are ignored by Python'sdataclasses.dataclassmechanism.This leads to a false positive
bad-class-definitionerror 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
Pyrefly reports:
Sandbox Link
https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAxAAQDqMUAxrgLYzUAuunAFuwAqkATjDBRS1AMoYcBADS8IcakuqpqxVAHMYAHXQ0A7nxHVSuAK7VGGaoaEQOMBXB6pTM6rHfo1eCxycpMQQ6FoqvoIcPLjohPqUCdQAEjAeHtaWxLDUYDCoHBYiyrhgispoWHj4iEkAtNQA4jCBIqhQdRwQbEHE7Ix8jADWoeF5MDiow-XUAKpw7CIAbvlQAPocwTAAFACUnNyhcH2MgaF5QiKYvfAzMPh9DmzogYaOPLzsAJIAIgCiuXyhWKvAKdnYcAsxGIuCEgW2MEIWkIagCuGYLGyLWc1C0uE6%2BMwolCjggsQUMRWQgULUYuxmtAcTjUWGoQgskVI0VimSJ1EwEBEp3EETMliE1GwQlwhgWQn03RhcN6o30%2BgAApsQmFCJgClMoKg4HANkIMHAwLCWHt9IxDcbqABZXCYCywABCRpgtV81EI-rV6DtRuUztdsG2YbdME9C12Puo1HVweNbG5mH0iaJZUtuG2drg%2BzqAD5qAA5WLezOJ6xQOCESAMTCIFU6gCC6AkAF5y5XAynlJIWO0oFGI2OYPHqzUIhx9CA5CAyCIxKRCFwWFAKDRBCuRZVZPhMuhIFoigUyXEkpIYOweBwOMQ4IgAPQv5eicSEWFaF8wdAvpg6JwC%2BzAnhAZ5ml0sQvrksJqEsqDQKg2A5GBp7ntBvi4MQWH1voZDcugdRUnAl7UD2uggAAzIQACMABMVH6AA2mk0pCHAAC6%2BgcoqsJOJgdQCkKXQrBR1AAOQQegsIwJJ%2BiyRwdQiAAjhYgoTHUQwwKQdRTIw8DKD2kmGD4CnoCAAC%2Bi5TGJMAAGLQDAFAHtUJDkFZQA
(Only applicable for extension issues) IDE Information
No response