From 665ecb89401761904cd2b6b7a7667633146c107a Mon Sep 17 00:00:00 2001 From: Carl Friedrich Bolz-Tereick Date: Sun, 21 Nov 2021 21:47:18 +0100 Subject: [PATCH 1/2] bpo-45859: fix test_field_descriptor in test_collections for pypy that test tries to pickle the descriptors of a namedtuple's fields, which is _collections._itemgetter on CPython. However, on PyPy that class doesn't exist. The code in collections deals fine with that fact, but the above-mentioned test does not make sense in that situation, since you can't pickle properties. --- Lib/test/test_collections.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 1bfd44f9547881..c27221ab7a4b7f 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -676,14 +676,17 @@ def test_field_descriptor(self): self.assertRaises(AttributeError, Point.x.__set__, p, 33) self.assertRaises(AttributeError, Point.x.__delete__, p) - class NewPoint(tuple): - x = pickle.loads(pickle.dumps(Point.x)) - y = pickle.loads(pickle.dumps(Point.y)) + # if there is no _itemgetter eg on PyPy, the rest doesn't make sense, + # because property isn't pickable + if type(Point.x) is not property: + class NewPoint(tuple): + x = pickle.loads(pickle.dumps(Point.x)) + y = pickle.loads(pickle.dumps(Point.y)) - np = NewPoint([1, 2]) + np = NewPoint([1, 2]) - self.assertEqual(np.x, 1) - self.assertEqual(np.y, 2) + self.assertEqual(np.x, 1) + self.assertEqual(np.y, 2) def test_new_builtins_issue_43102(self): obj = namedtuple('C', ()) From 428aa1b2e7d3fb53656aaab46336d7245f2f78c3 Mon Sep 17 00:00:00 2001 From: Carl Friedrich Bolz-Tereick Date: Mon, 22 Nov 2021 09:31:24 +0100 Subject: [PATCH 2/2] got with @cpython_only instead --- Lib/test/test_collections.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index c27221ab7a4b7f..48327bf50ea423 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -668,6 +668,7 @@ class Point(namedtuple('_Point', ['x', 'y'])): a.w = 5 self.assertEqual(a.__dict__, {'w': 5}) + @support.cpython_only def test_field_descriptor(self): Point = namedtuple('Point', 'x y') p = Point(11, 22) @@ -676,17 +677,14 @@ def test_field_descriptor(self): self.assertRaises(AttributeError, Point.x.__set__, p, 33) self.assertRaises(AttributeError, Point.x.__delete__, p) - # if there is no _itemgetter eg on PyPy, the rest doesn't make sense, - # because property isn't pickable - if type(Point.x) is not property: - class NewPoint(tuple): - x = pickle.loads(pickle.dumps(Point.x)) - y = pickle.loads(pickle.dumps(Point.y)) + class NewPoint(tuple): + x = pickle.loads(pickle.dumps(Point.x)) + y = pickle.loads(pickle.dumps(Point.y)) - np = NewPoint([1, 2]) + np = NewPoint([1, 2]) - self.assertEqual(np.x, 1) - self.assertEqual(np.y, 2) + self.assertEqual(np.x, 1) + self.assertEqual(np.y, 2) def test_new_builtins_issue_43102(self): obj = namedtuple('C', ())