Skip to content

[pyrefly] Diagnose duplicate dataclass KW_ONLY markers - #4373

Closed
vivekjm wants to merge 1 commit into
pyrefly-org:mainfrom
vivekjm:fix/duplicate-kw-only
Closed

vivekjm wants to merge 1 commit into
pyrefly-org:mainfrom
vivekjm:fix/duplicate-kw-only

Conversation

@vivekjm

@vivekjm vivekjm commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Report a bad-class-definition error on the second and subsequent dataclasses.KW_ONLY markers in a single dataclass. The diagnostic is attached to the duplicate declaration and matches the runtime rule enforced by dataclasses.

This keeps valid inheritance behavior unchanged because markers are counted independently in each class body.

Fixes #3737

Test Plan

  • CARGO_TARGET_DIR=/tmp/pyrefly-target cargo test test_duplicate_kw_only_sentinel
  • CARGO_TARGET_DIR=/tmp/pyrefly-target cargo test test::dataclasses:: (148 passed)
  • CARGO_TARGET_DIR=/tmp/pyrefly-target python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
  • git diff --check

AI disclosure: This change was prepared with an AI coding agent and manually validated against the repository tests and contribution guidance.

@meta-codesync

meta-codesync Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D114191657. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in 32bfc9d Jul 31, 2026
@meta-codesync meta-codesync Bot added the Merged label Jul 31, 2026
@meta-codesync

meta-codesync Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@yangdanny97 merged this pull request in 32bfc9d.

avokin2 pushed a commit to avokin2/pyrefly that referenced this pull request Aug 12, 2026
Summary:
Report a bad-class-definition error on the second and subsequent dataclasses.KW_ONLY markers in a single dataclass. The diagnostic is attached to the duplicate declaration and matches the runtime rule enforced by dataclasses.

This keeps valid inheritance behavior unchanged because markers are counted independently in each class body.

Fixes pyrefly-org#3737

Pull Request resolved: pyrefly-org#4373

Test Plan:
- CARGO_TARGET_DIR=/tmp/pyrefly-target cargo test test_duplicate_kw_only_sentinel
- CARGO_TARGET_DIR=/tmp/pyrefly-target cargo test test::dataclasses:: (148 passed)
- CARGO_TARGET_DIR=/tmp/pyrefly-target python3 test.py --no-test --no-tensor-shapes --no-conformance --no-jsonschema
- git diff --check

AI disclosure: This change was prepared with an AI coding agent and manually validated against the repository tests and contribution guidance.

Reviewed By: kinto0

Differential Revision: D114191657

Pulled By: yangdanny97

fbshipit-source-id: f572b8f5c4337738fd162995795d9ee9e7f22c9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new rule - duplicate KW_ONLY in dataclass

2 participants