mypy
mypy copied to clipboard
feat: error for Final fields with init=False (#13119)
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
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅