mypy icon indicating copy to clipboard operation
mypy copied to clipboard

feat: error for Final fields with init=False (#13119)

Open Benitex opened this issue 1 month ago • 1 comments

This Pull Request adds an error report when a dataclass field is declared as Final, has init=False, and lacks a default value, as discussed in Issue #13119. This change adds a check to detect this combination while avoiding complex control flow analysis, as requested. It also flags no error if there's a __post_init__ method, to avoid possible false positives.

Test cases were adapted from PR #14285. I also added a new test case for default values provided on the field declaration. Thanks to @jakezych for the original test cases.

Fixes #13119

Benitex avatar Dec 08 '25 23:12 Benitex

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

github-actions[bot] avatar Dec 09 '25 00:12 github-actions[bot]