Skip to content

Do not add kw_only dataclass fields to __match_args__#18892

Merged
sobolevn merged 1 commit into
masterfrom
issue-18863
Apr 7, 2025
Merged

Do not add kw_only dataclass fields to __match_args__#18892
sobolevn merged 1 commit into
masterfrom
issue-18863

Conversation

@sobolevn

@sobolevn sobolevn commented Apr 7, 2025

Copy link
Copy Markdown
Member

@github-actions

github-actions Bot commented Apr 7, 2025

Copy link
Copy Markdown
Contributor

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

@sterliakov sterliakov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Consider also submitting a documentation bug to python/cpython: now the docs fail to mention this rather important aspect (and even seem to suggest the opposite?).

match_args: If true (the default is True), the match_args tuple will be created from the list of parameters to the generated init() method (even if init() is not generated, see above).

kw_only: If true (the default value is False), then all fields will be marked as keyword-only. If a field is marked as keyword-only, then the only effect is that the init() parameter generated from a keyword-only field must be specified with a keyword when init() is called. There is no effect on any other aspect of dataclasses. See the parameter glossary entry for details. Also see the KW_ONLY section.

@sobolevn

sobolevn commented Apr 7, 2025

Copy link
Copy Markdown
Member Author

Consider also submitting a documentation bug to python/cpython

Agreed, working on it!

Thanks!

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.

__match_args__ variable type differes when generating stubs for keyword only dataclasses

2 participants