From d00c981ffb56f44e235bb076cee7517578dc3b1e Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 4 May 2026 06:09:33 +0300 Subject: [PATCH 1/7] gh-146238: add missing tests for 'e' type code in test_buffer.py This amends e79fd60. I'll not fix this for 'F'/'D' complex types as they might be removed. --- Lib/test/test_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 5a4f031e298c2f..8138fe7ad407c3 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -143,7 +143,7 @@ def native_type_range(fmt): # Format codes supported by array.array ARRAY = NATIVE.copy() for k in NATIVE: - if not k in "bBhHiIlLfd": + if not k in "bBhHiIlLefd": del ARRAY[k] BYTEFMT = NATIVE.copy() From b4569cbe97eb4a6ecbe5f8f933b0a5d6879dc041 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 05:24:17 +0300 Subject: [PATCH 2/7] + Zf/d --- Lib/test/test_buffer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 06fd05d8257c24..e7404586ea1c1e 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -143,7 +143,7 @@ def native_type_range(fmt): # Format codes supported by array.array ARRAY = NATIVE.copy() for k in NATIVE: - if not k in "bBhHiIlLefd": + if not k in list("bBhHiIlLefd") + ['Zf', 'Zd']: del ARRAY[k] BYTEFMT = NATIVE.copy() From 2e1c01bc1165d6b08e1a663ba8c0c067748d76f8 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 08:42:20 +0300 Subject: [PATCH 3/7] skip Zd in test_array_alignment() --- Lib/test/test_buffer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index e7404586ea1c1e..c6ab22c6c7b487 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -4495,8 +4495,8 @@ def test_bytearray_alignment(self): def test_array_alignment(self): # gh-140557: pointer alignment of buffers including empty allocation # should match the maximum array alignment. - align = max(struct.calcsize(fmt) for fmt in ARRAY) - cases = [array.array(fmt) for fmt in ARRAY] + align = max(struct.calcsize(fmt) for fmt in ARRAY if fmt != 'Zd') + cases = [array.array(fmt) for fmt in ARRAY if fmt != 'Zd'] # Empty arrays self.assertEqual( [_testcapi.buffer_pointer_as_int(case) % align for case in cases], From b97670b02c0362b6f900594d3bd992314c06a1d1 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 10:27:22 +0300 Subject: [PATCH 4/7] fix test --- Lib/test/test_buffer.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index c6ab22c6c7b487..9e91ef42f06d49 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -50,6 +50,7 @@ try: import _testcapi + import _testlimitedcapi except ImportError: _testcapi = None @@ -4495,8 +4496,11 @@ def test_bytearray_alignment(self): def test_array_alignment(self): # gh-140557: pointer alignment of buffers including empty allocation # should match the maximum array alignment. - align = max(struct.calcsize(fmt) for fmt in ARRAY if fmt != 'Zd') - cases = [array.array(fmt) for fmt in ARRAY if fmt != 'Zd'] + MAX_ALIGN = _testlimitedcapi.ALIGNOF_MAX_ALIGN_T + align = max(struct.calcsize(fmt) for fmt in ARRAY + if struct.calcsize(fmt) <= MAX_ALIGN) + cases = [array.array(fmt) for fmt in ARRAY + if struct.calcsize(fmt) <= MAX_ALIGN] # Empty arrays self.assertEqual( [_testcapi.buffer_pointer_as_int(case) % align for case in cases], From 71ab6d163cd8cfbc758dd76bf0234087b560f745 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 13:42:01 +0300 Subject: [PATCH 5/7] +1 --- Lib/test/test_buffer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 9e91ef42f06d49..d575661be22957 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -4507,7 +4507,9 @@ def test_array_alignment(self): [0] * len(cases), ) for case in cases: - case.append(0) + fmt = case.typecode + if struct.calcsize(fmt) <= MAX_ALIGN: + case.append(0) # Allocated arrays self.assertEqual( [_testcapi.buffer_pointer_as_int(case) % align for case in cases], From 7317fa02f77c55c6117f559201085bb62946f0b2 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 6 May 2026 05:43:13 +0300 Subject: [PATCH 6/7] address review --- Lib/test/test_buffer.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index d575661be22957..353718caf47b0b 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -50,7 +50,6 @@ try: import _testcapi - import _testlimitedcapi except ImportError: _testcapi = None @@ -144,7 +143,7 @@ def native_type_range(fmt): # Format codes supported by array.array ARRAY = NATIVE.copy() for k in NATIVE: - if not k in list("bBhHiIlLefd") + ['Zf', 'Zd']: + if k not in list("bBhHiIlLefd") + ['Zf', 'Zd']: del ARRAY[k] BYTEFMT = NATIVE.copy() @@ -4497,19 +4496,17 @@ def test_array_alignment(self): # gh-140557: pointer alignment of buffers including empty allocation # should match the maximum array alignment. MAX_ALIGN = _testlimitedcapi.ALIGNOF_MAX_ALIGN_T - align = max(struct.calcsize(fmt) for fmt in ARRAY - if struct.calcsize(fmt) <= MAX_ALIGN) - cases = [array.array(fmt) for fmt in ARRAY - if struct.calcsize(fmt) <= MAX_ALIGN] + formats = [fmt for fmt in ARRAY + if struct.calcsize(fmt) <= struct.calcsize('P')] + align = max(struct.calcsize(fmt) for fmt in formats) + cases = [array.array(fmt) for fmt in formats] # Empty arrays self.assertEqual( [_testcapi.buffer_pointer_as_int(case) % align for case in cases], [0] * len(cases), ) for case in cases: - fmt = case.typecode - if struct.calcsize(fmt) <= MAX_ALIGN: - case.append(0) + case.append(0) # Allocated arrays self.assertEqual( [_testcapi.buffer_pointer_as_int(case) % align for case in cases], From 788624655ecbd83964a98799336cbf166a41a852 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Wed, 6 May 2026 05:44:37 +0300 Subject: [PATCH 7/7] +1 --- Lib/test/test_buffer.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 353718caf47b0b..7454c8a15391e9 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -4495,7 +4495,6 @@ def test_bytearray_alignment(self): def test_array_alignment(self): # gh-140557: pointer alignment of buffers including empty allocation # should match the maximum array alignment. - MAX_ALIGN = _testlimitedcapi.ALIGNOF_MAX_ALIGN_T formats = [fmt for fmt in ARRAY if struct.calcsize(fmt) <= struct.calcsize('P')] align = max(struct.calcsize(fmt) for fmt in formats)