Skip to content

Conversation

@Benitex
Copy link

@Benitex Benitex commented Dec 8, 2025

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 and others added 2 commits December 8, 2025 18:32
Test cases from PR python#14285, thanks to @jakezych.

Co-Authored-By: Jake Zych <56098501+jakezych@users.noreply.github.com>
Co-Authored-By: Rafael Christof <rafaeldana@danatelecom.com>
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no error when setting init=False on Final field in dataclass

1 participant