From 1cffa1a8fde38bb6ae0827772fe3938822a68fff Mon Sep 17 00:00:00 2001 From: Sabfo Date: Wed, 19 Feb 2025 22:52:18 +0200 Subject: [PATCH 1/2] gh-130130: Clarify the meaning `dataclasses.field(..., hash=False)` --- Doc/library/dataclasses.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index e34b2db0210960..a2f462e13e9872 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -270,10 +270,11 @@ Module contents string returned by the generated :meth:`~object.__repr__` method. - *hash*: This can be a bool or ``None``. If true, this field is - included in the generated :meth:`~object.__hash__` method. If ``None`` (the - default), use the value of *compare*: this would normally be - the expected behavior. A field should be considered in the hash - if it's used for comparisons. Setting this value to anything + included in the generated :meth:`~object.__hash__` method. If false, + this field is excluded from the generated :meth:`~object.__hash__`. + If ``None`` (the default), use the value of *compare*: this would + normally be the expected behavior. A field should be considered in + the hash if it's used for comparisons. Setting this value to anything other than ``None`` is discouraged. One possible reason to set ``hash=False`` but ``compare=True`` From 4e78ef011b45ab1b6c3ae7ee95de81f8775e2dd9 Mon Sep 17 00:00:00 2001 From: Sabfo Date: Wed, 19 Feb 2025 23:01:20 +0200 Subject: [PATCH 2/2] gh-130130: Clarify the meaning `dataclasses.field(..., hash=False)` --- Doc/library/dataclasses.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index a2f462e13e9872..f63a01e9570791 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -270,11 +270,11 @@ Module contents string returned by the generated :meth:`~object.__repr__` method. - *hash*: This can be a bool or ``None``. If true, this field is - included in the generated :meth:`~object.__hash__` method. If false, + included in the generated :meth:`~object.__hash__` method. If false, this field is excluded from the generated :meth:`~object.__hash__`. If ``None`` (the default), use the value of *compare*: this would - normally be the expected behavior. A field should be considered in - the hash if it's used for comparisons. Setting this value to anything + normally be the expected behavior, since a field should be included + in the hash if it's used for comparisons. Setting this value to anything other than ``None`` is discouraged. One possible reason to set ``hash=False`` but ``compare=True``