Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 8, 2025
commit 2c9742b296f0eebb4af6f756313d89372831dfb3
3 changes: 1 addition & 2 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,7 @@ def collect_attributes(self) -> list[DataclassAttribute] | None:
has_post_init = cls.info.get("__post_init__") is not None
if not has_post_init:
self._api.fail(
f'Final field with init=False must have a default value',
stmt.rvalue
"Final field with init=False must have a default value", stmt.rvalue
)

if not has_default and self._spec is _TRANSFORM_SPEC_FOR_DATACLASSES:
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -2753,7 +2753,7 @@ from dataclasses import dataclass, field

@dataclass
class Foo:
a: Final[int] = field()
a: Final[int] = field()

Foo().a # E: Missing positional argument "a" in call to "Foo"
[builtins fixtures/dataclasses.pyi]
Expand All @@ -2764,9 +2764,9 @@ from dataclasses import dataclass, field

@dataclass
class Foo:
a: Final[int] = field()
a: Final[int] = field()

Foo(1).a
Foo(1).a
[builtins fixtures/dataclasses.pyi]

[case testFinalFieldPostInit]
Expand All @@ -2780,7 +2780,7 @@ class Foo:
def __post_init__(self):
self.a = 1

Foo().a
Foo().a
[builtins fixtures/dataclasses.pyi]

[case testFinalFieldInitFalseWithDefault]
Expand Down