Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix dataclass field collection to only include class body fields#3347

Open
QEDady wants to merge 4 commits intofacebook:mainfacebook/pyrefly:mainfrom
QEDady:try-class-body-fields-onlyQEDady/pyrefly:try-class-body-fields-onlyCopy head branch name to clipboard
Open

Fix dataclass field collection to only include class body fields#3347
QEDady wants to merge 4 commits intofacebook:mainfacebook/pyrefly:mainfrom
QEDady:try-class-body-fields-onlyQEDady/pyrefly:try-class-body-fields-onlyCopy head branch name to clipboard

Conversation

@QEDady
Copy link
Copy Markdown
Contributor

@QEDady QEDady commented May 8, 2026

Summary

Restricts dataclass field collection in get_dataclass_fields to use class_body_fields() instead of names().

Previously, pyrefly collected all annotated fields for dataclasses, including those defined via assignments in methods (e.g., cls.field: Any = None in a class method). This caused issues when such an assignment shadowed a declaration in a base class decorated with @dataclass_transform, leading to false positive missing-argument errors at call sites.

By restricting collection to class body fields, we ensure that only fields declared in the class body are considered candidates for dataclass fields, aligning with standard dataclass semantics.

Fixes #3346

Test Plan

Added two new unit tests in dataclass_transform.rs to verify that fields shadowed by method assignments (both class methods and instance methods) are correctly ignored:

  • test_classmethod_shadowing_base_annotation_ignored
  • test_method_shadowing_base_annotation_ignored

@meta-cla meta-cla Bot added the cla signed label May 8, 2026
@github-actions github-actions Bot added the size/s label May 8, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

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

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.

False positive missing-argument in dataclass_transform due to method assignments

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.