Skip to content

Commit

Permalink
dataclasses plugin fix: arguments without a default cannot follow a…
Browse files Browse the repository at this point in the history
…ttributes with one
  • Loading branch information
embecka committed Sep 19, 2024
1 parent 4554bd0 commit 56bd7d7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def collect_attributes(self) -> list[DataclassAttribute] | None:
"Attributes without a default cannot follow attributes with one", context
)

found_default = found_default or (attr.has_default and attr.is_in_init)
found_default = found_default or (attr.has_default and attr.is_in_init and not attr.kw_only)
if found_kw_sentinel and self._is_kw_only_type(attr.type):
context = cls
if attr.name in current_attr_names:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ from dataclasses import dataclass, field, KW_ONLY
class Application:
_: KW_ONLY
name: str = 'Unnamed'
rating: int = field(kw_only=False) # E: Attributes without a default cannot follow attributes with one
rating: int = field(kw_only=False)

Application(name='name', rating=5)
Application() # E: Missing positional argument "name" in call to "Application"
Expand Down

0 comments on commit 56bd7d7

Please sign in to comment.