-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Fix format of dataclasses' unsafe_hash
default value
#116532
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
base: main
Are you sure you want to change the base?
Conversation
The intent is that it's saying any value that evaluates as false in a boolean context. It's a little confusing to say "If false (the default is |
Doc/library/dataclasses.rst
Outdated
- *unsafe_hash*: If false (the default), a :meth:`~object.__hash__` method | ||
is generated according to how *eq* and *frozen* are set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps "If true, force dataclasses
to create a __hash__
method, even when it may not be safe to do so. Otherwise, generate a __hash__
method according to how eq and frozen are set. The default value is False
."
or words to that effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think this is the best approach. It could be extended to the default=True values as well: put the default at the end.
Doc/library/dataclasses.rst
Outdated
- *unsafe_hash*: If ``False`` (the default), a :meth:`~object.__hash__` method | ||
is generated according to how *eq* and *frozen* are set. | ||
- *unsafe_hash*: If true, force ``dataclasses`` to create a | ||
:meth:`~object.__hash__` method, even when it may not be safe to do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better. Maybe change "even when" to "even though"? We don't know for a fact it's unsafe.
And do we need to explain why it might be unsafe? I could go either way, but would like to hear opinions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be in line with the other parameters. I wonder what is the precedent here: should every default value be wrapped in preformatted text? For the other dataclass parameters, only the default value is, but not the actual if true/false:
📚 Documentation preview 📚: https://cpython-previews--116532.org.readthedocs.build/