From 1b4a85676726cd687e0953895c79ef364d19e09f Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Tue, 16 Sep 2025 10:41:56 +0530 Subject: [PATCH 1/7] Add a note to the platform.machine() documentation section --- Doc/library/platform.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index 37df13f8a1eb8c..3a48668ff72325 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -56,6 +56,13 @@ Cross platform Returns the machine type, e.g. ``'AMD64'``. An empty string is returned if the value cannot be determined. + .. note:: + + The output of :func:`platform.machine` is system-dependent and may differ in casing + and naming conventions across platforms. For example, on Apple Silicon macOS it may + return ``'arm64'`` (lowercase), while on Windows-on-ARM it may return ``'ARM64'`` (uppercase). + If you need consistent results, normalize the output in your code. + .. function:: node() From 08b07a24ec16cfc9bb5176f779a30e81a849ce2e Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Tue, 16 Sep 2025 14:29:20 +0530 Subject: [PATCH 2/7] Add a note to the platform.machine() documentation section --- Doc/library/platform.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index 3a48668ff72325..e8b331eea67412 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -58,10 +58,11 @@ Cross platform .. note:: - The output of :func:`platform.machine` is system-dependent and may differ in casing - and naming conventions across platforms. For example, on Apple Silicon macOS it may - return ``'arm64'`` (lowercase), while on Windows-on-ARM it may return ``'ARM64'`` (uppercase). - If you need consistent results, normalize the output in your code. + The output of :func:`platform.machine` is system-dependent and may differ + in casing and naming conventions across platforms. For example, on Apple + Silicon macOS it may return ``'arm64'`` (lowercase), while on Windows-on-ARM + it may return ``'ARM64'`` (uppercase). If you need consistent results, + normalize the output in your code. .. function:: node() From 3692677e33cbfa9a438f1c45923d7bcca1367db4 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 17 Sep 2025 03:46:14 +0530 Subject: [PATCH 3/7] Update dataclass documentation for new __eq__ behavior in 3.13 and add tests (#138991) --- Doc/library/dataclasses.rst | 10 +++++-- Lib/test/test_dataclasses/__init__.py | 39 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index 299c8aa399c25c..d1872262746e19 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -103,10 +103,16 @@ Module contents ignored. - *eq*: If true (the default), an :meth:`~object.__eq__` method will be - generated. This method compares the class as if it were a tuple - of its fields, in order. Both instances in the comparison must + generated. + + .. versionchanged:: 3.13 + The generated ``__eq__`` method now compares each field individually (e.g., ``self.a == other.a and self.b == other.b``), rather than comparing tuples of fields as in previous versions. + + This method compares the class by comparing each field in order. Both instances in the comparison must be of the identical type. + In Python 3.12 and earlier, the comparison was performed by creating tuples of the fields and comparing them (e.g., ``(self.a, self.b) == (other.a, other.b)``). + If the class already defines :meth:`!__eq__`, this parameter is ignored. diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py index e98a8f284cec9f..f0b19a1c3971ab 100644 --- a/Lib/test/test_dataclasses/__init__.py +++ b/Lib/test/test_dataclasses/__init__.py @@ -2597,6 +2597,45 @@ def __eq__(self, other): self.assertEqual(C(1), 5) self.assertNotEqual(C(1), 1) + def test_eq_field_by_field(self): + @dataclasses.dataclass + class Point: + x: int + y: int + + p1 = Point(1, 2) + p2 = Point(1, 2) + p3 = Point(2, 1) + self.assertTrue(p1 == p2) + self.assertFalse(p1 == p3) + + def test_eq_type_check(self): + @dataclasses.dataclass + class A: + x: int + + @dataclasses.dataclass + class B: + x: int + + a = A(1) + b = B(1) + self.assertFalse(a == b) + + def test_eq_custom_field(self): + class AlwaysEqual(int): + def __eq__(self, other): + return True + + @dataclasses.dataclass + class Foo: + x: AlwaysEqual + y: int + + f1 = Foo(AlwaysEqual(1), 2) + f2 = Foo(AlwaysEqual(2), 2) + self.assertTrue(f1 == f2) + class TestOrdering(unittest.TestCase): def test_functools_total_ordering(self): From 262f78538db6e01c5237e4fecfea22bcb51cd0b9 Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 17 Sep 2025 03:52:43 +0530 Subject: [PATCH 4/7] Update dataclass documentation for new __eq__ behavior in 3.13 and add tests --- Doc/library/platform.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Doc/library/platform.rst b/Doc/library/platform.rst index e8b331eea67412..37df13f8a1eb8c 100644 --- a/Doc/library/platform.rst +++ b/Doc/library/platform.rst @@ -56,14 +56,6 @@ Cross platform Returns the machine type, e.g. ``'AMD64'``. An empty string is returned if the value cannot be determined. - .. note:: - - The output of :func:`platform.machine` is system-dependent and may differ - in casing and naming conventions across platforms. For example, on Apple - Silicon macOS it may return ``'arm64'`` (lowercase), while on Windows-on-ARM - it may return ``'ARM64'`` (uppercase). If you need consistent results, - normalize the output in your code. - .. function:: node() From ada26a969c5ef9b489fab0e9a9c4e40f7190603c Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 17 Sep 2025 15:13:17 +0530 Subject: [PATCH 5/7] Update dataclass documentation for new __eq__ behavior in 3.13 and add tests --- Doc/library/dataclasses.rst | 12 ++++++++---- Lib/test/test_dataclasses/__init__.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index d1872262746e19..adc15cd3a59cd0 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -106,12 +106,16 @@ Module contents generated. .. versionchanged:: 3.13 - The generated ``__eq__`` method now compares each field individually (e.g., ``self.a == other.a and self.b == other.b``), rather than comparing tuples of fields as in previous versions. + The generated ``__eq__`` method now compares each field individually + (for example, ``self.a == other.a and self.b == other.b``), rather than + comparing tuples of fields as in previous versions. - This method compares the class by comparing each field in order. Both instances in the comparison must - be of the identical type. + This method compares the class by comparing each field in order. Both + instances in the comparison must be of the identical type. - In Python 3.12 and earlier, the comparison was performed by creating tuples of the fields and comparing them (e.g., ``(self.a, self.b) == (other.a, other.b)``). + In Python 3.12 and earlier, the comparison was performed by creating + tuples of the fields and comparing them (for example, + ``(self.a, self.b) == (other.a, other.b)``). If the class already defines :meth:`!__eq__`, this parameter is ignored. diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py index f0b19a1c3971ab..049457f200a6b0 100644 --- a/Lib/test/test_dataclasses/__init__.py +++ b/Lib/test/test_dataclasses/__init__.py @@ -2636,6 +2636,16 @@ class Foo: f2 = Foo(AlwaysEqual(2), 2) self.assertTrue(f1 == f2) + def test_eq_nan_field(self): + @dataclasses.dataclass + class D: + x: float + + nan = float('nan') + d1 = D(nan) + d2 = D(nan) + self.assertFalse(d1 == d2) + class TestOrdering(unittest.TestCase): def test_functools_total_ordering(self): From 571227962f79869ff301aab75bd47298a0f6aead Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Wed, 17 Sep 2025 16:45:58 +0530 Subject: [PATCH 6/7] Update dataclass documentation for new __eq__ behavior in 3.13 and add tests --- Doc/library/dataclasses.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index adc15cd3a59cd0..c6e8c88db508fd 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -105,20 +105,19 @@ Module contents - *eq*: If true (the default), an :meth:`~object.__eq__` method will be generated. + This method compares the class by comparing each field in order. Both + instances in the comparison must be of the identical type. + .. versionchanged:: 3.13 The generated ``__eq__`` method now compares each field individually (for example, ``self.a == other.a and self.b == other.b``), rather than comparing tuples of fields as in previous versions. - This method compares the class by comparing each field in order. Both - instances in the comparison must be of the identical type. - In Python 3.12 and earlier, the comparison was performed by creating tuples of the fields and comparing them (for example, ``(self.a, self.b) == (other.a, other.b)``). - If the class already defines :meth:`!__eq__`, this parameter is - ignored. + If the class already defines :meth:`!__eq__`, this parameter is ignored. - *order*: If true (the default is ``False``), :meth:`~object.__lt__`, :meth:`~object.__le__`, :meth:`~object.__gt__`, and :meth:`~object.__ge__` methods will be From 822bbaa457ef0902241f1dded9a2394d3c69878d Mon Sep 17 00:00:00 2001 From: Aniket Singh Yadav Date: Thu, 18 Sep 2025 21:08:12 +0530 Subject: [PATCH 7/7] Update dataclass documentation for new __eq__ behavior in 3.13 and add tests --- Lib/test/test_dataclasses/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_dataclasses/__init__.py b/Lib/test/test_dataclasses/__init__.py index 049457f200a6b0..618d4e5ccc409a 100644 --- a/Lib/test/test_dataclasses/__init__.py +++ b/Lib/test/test_dataclasses/__init__.py @@ -2606,8 +2606,8 @@ class Point: p1 = Point(1, 2) p2 = Point(1, 2) p3 = Point(2, 1) - self.assertTrue(p1 == p2) - self.assertFalse(p1 == p3) + self.assertEqual(p1, p2) + self.assertNotEqual(p1, p3) def test_eq_type_check(self): @dataclasses.dataclass @@ -2620,7 +2620,7 @@ class B: a = A(1) b = B(1) - self.assertFalse(a == b) + self.assertNotEqual(a, b) def test_eq_custom_field(self): class AlwaysEqual(int): @@ -2634,7 +2634,7 @@ class Foo: f1 = Foo(AlwaysEqual(1), 2) f2 = Foo(AlwaysEqual(2), 2) - self.assertTrue(f1 == f2) + self.assertEqual(f1, f2) def test_eq_nan_field(self): @dataclasses.dataclass @@ -2644,7 +2644,7 @@ class D: nan = float('nan') d1 = D(nan) d2 = D(nan) - self.assertFalse(d1 == d2) + self.assertNotEqual(d1, d2) class TestOrdering(unittest.TestCase):