Skip to content

Docs: dataclasses: wrong error documented #106107

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rschupp opened this issue Jun 26, 2023 · 3 comments
Closed

Docs: dataclasses: wrong error documented #106107

rschupp opened this issue Jun 26, 2023 · 3 comments
Labels
docs Documentation in the Doc dir

Comments

@rschupp
Copy link
Contributor

rschupp commented Jun 26, 2023

Documentation

Data Classes - Mutable default values says in the second blockquote

  x: list = []      # This code raises **ValueError**

but in the explanantion (two paragraphs down) it notes:

Instead, the dataclass decorator will raise a TypeError if it detects an unhashable default parameter.

This is inconsistent, in fact a ValueError is raised, cf. https://github.com/python/cpython/blob/e8e59ee474869e7c02e7cae3815c9c2183671b21/Lib/dataclasses.py#L848C1-L853C1

Linked PRs

@rschupp rschupp added the docs Documentation in the Doc dir label Jun 26, 2023
@Eclips4
Copy link
Member

Eclips4 commented Jun 26, 2023

Yeah, there should be a ValueError.
Would you like to send a PR?

@rschupp
Copy link
Contributor Author

rschupp commented Jun 26, 2023

Yeah, there should be a ValueError. Would you like to send a PR?

😄 #106109

ericvsmith pushed a commit that referenced this issue Jun 26, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 26, 2023
…default value for a field is detected (pythongh-106109)

(cherry picked from commit 512f299)

Co-authored-by: Roderich Schupp <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 26, 2023
…default value for a field is detected (pythongh-106109)

(cherry picked from commit 512f299)

Co-authored-by: Roderich Schupp <[email protected]>
@ericvsmith
Copy link
Member

Thanks, @rschupp !

ericvsmith pushed a commit that referenced this issue Jun 26, 2023
… default value for a field is detected (gh-106109) (gh-106116)

gh-106107: document correct error that's raised when a mutable default value for a field is detected (gh-106109)
(cherry picked from commit 512f299)

Co-authored-by: Roderich Schupp <[email protected]>
ericvsmith pushed a commit that referenced this issue Jun 26, 2023
… default value for a field is detected (gh-106109) (gh-106115)

gh-106107: document correct error that's raised when a mutable default value for a field is detected (gh-106109)
(cherry picked from commit 512f299)

Co-authored-by: Roderich Schupp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

3 participants