Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-89529: disallowdefault_factory for fields in dataclasses without__init__#123070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
picnixz wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
frompicnixz:89529-dataclasses-default-factory-and-init

Conversation

picnixz
Copy link
Member

@picnixzpicnixz commentedAug 16, 2024
edited by bedevere-appbot
Loading

This is a proposal for rejectingdefault_factory on fields if the dataclass does not have an__init__ method.

@picnixz
Copy link
MemberAuthor

picnixz commentedAug 17, 2024
edited
Loading

Should we consider this a bugfix or a feature actually? (to determine whether it requires backports or not, and update the issue's labels, which I tagged as 3.12, 3.13 and 3.14 + bug).

@picnixz
Copy link
MemberAuthor

Friendly ping@ericvsmith

Copy link
Member

@sobolevnsobolevn left a comment

Choose a reason for hiding this comment

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

Technically, this is a breaking change. For example, it can break abstract dataclasses, which do not have__init__ on purpose. And their subclasses have__init__s.

But, I also see that this bug can indeed happen.

So, I am not sure what is best.

@picnixz
Copy link
MemberAuthor

For example, it can break abstract dataclasses, which do not haveinit on purpose. And their subclasses have __init__s

That's something I entirely missed. Maybe we can work out by checking if the class is abstract (namely, declared usingabc.ABC ormetaclass=abc.ABCMeta) and do not raise in this case? Otherwise we can drop this behaviour.

Anyway, this solves one of my question about whether this is a bug fix or a feature. Since itcould break something, whether we want it or not, I'd prefer tagging it as a feature rather than a bug fix.

@picnixz
Copy link
MemberAuthor

@ericvsmith friendly ping

@picnixz
Copy link
MemberAuthor

I don't think I'll land this one because of this:

For example, it can break abstract dataclasses, which do not have__init__ on purpose. And their subclasses have__init__s.

To be clear, it makes sense to indeed have an error but it's hard to know whether the error should be pre-caught as there are cases where it can be said that it would be unreachable (namely, we expect concrete classes to have their own__init__ and deal with what they need to I guess?).

So I'll mark this one as stale and a draft as I need to add tests for abstract classes as well..

@picnixzpicnixz marked this pull request as draftApril 25, 2025 08:55
@picnixzpicnixz added awaiting review staleStale PR or inactive for long period of time. labelsApr 25, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@sobolevnsobolevnsobolevn left review comments

@ericvsmithericvsmithAwaiting requested review from ericvsmithericvsmith is a code owner

Assignees
No one assigned
Labels
awaiting reviewstaleStale PR or inactive for long period of time.topic-dataclasses
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@picnixz@ericvsmith@sobolevn

[8]ページ先頭

©2009-2025 Movatter.jp