From 0bdb82d45662bdfecfab410483d5bb4026dee418 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 19 May 2025 10:39:04 -0400 Subject: [PATCH 1/8] Add tests for zero-sized bytes objects in test_bytes.py --- Lib/test/test_capi/test_bytes.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py index 5b61c73381542d..3c47b82a872c96 100644 --- a/Lib/test/test_capi/test_bytes.py +++ b/Lib/test/test_capi/test_bytes.py @@ -29,8 +29,9 @@ def test_check(self): self.assertFalse(check(3)) self.assertFalse(check([])) self.assertFalse(check(object())) + self.assertTrue(check(b'')) - # CRASHES check(NULL) + # CRASHES check(NULL) #PyBytes_Check() expects PyObject* def test_checkexact(self): # Test PyBytes_CheckExact() @@ -43,8 +44,9 @@ def test_checkexact(self): self.assertFalse(check(3)) self.assertFalse(check([])) self.assertFalse(check(object())) + self.assertTrue(check(b'')) - # CRASHES check(NULL) + # CRASHES check(NULL) #PyBytes_CheckExact() expects PyObject* def test_fromstringandsize(self): # Test PyBytes_FromStringAndSize() @@ -73,7 +75,7 @@ def test_fromstring(self): self.assertEqual(fromstring(b'abc\0def'), b'abc') self.assertEqual(fromstring(b''), b'') - # CRASHES fromstring(NULL) + # CRASHES fromstring(NULL) def test_fromobject(self): # Test PyBytes_FromObject() @@ -108,6 +110,7 @@ def test_asstring(self): self.assertEqual(asstring(b'abc', 4), b'abc\0') self.assertEqual(asstring(b'abc\0def', 8), b'abc\0def\0') + self.assertEqual(asstring(b'', 1), b'\0') self.assertRaises(TypeError, asstring, 'abc', 0) self.assertRaises(TypeError, asstring, object(), 0) @@ -120,6 +123,7 @@ def test_asstringandsize(self): self.assertEqual(asstringandsize(b'abc', 4), (b'abc\0', 3)) self.assertEqual(asstringandsize(b'abc\0def', 8), (b'abc\0def\0', 7)) + self.assertEqual(asstringandsize(b'', 1), (b'\0', 0)) self.assertEqual(asstringandsize_null(b'abc', 4), b'abc\0') self.assertRaises(ValueError, asstringandsize_null, b'abc\0def', 8) self.assertRaises(TypeError, asstringandsize, 'abc', 0) @@ -163,6 +167,7 @@ def test_concat(self, concat=None): self.assertEqual(concat(b'', bytearray(b'def')), b'def') self.assertEqual(concat(memoryview(b'xabcy')[1:4], b'def'), b'abcdef') self.assertEqual(concat(b'abc', memoryview(b'xdefy')[1:4]), b'abcdef') + self.assertEqual(concat(b'', b''), b'') self.assertEqual(concat(b'abc', b'def', True), b'abcdef') self.assertEqual(concat(b'abc', bytearray(b'def'), True), b'abcdef') From 0d867377c6b102f489a348e4e0174949e5a5c3de Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 19 May 2025 11:18:52 -0400 Subject: [PATCH 2/8] Fix trailing whitespace --- Lib/test/test_capi/test_bytes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py index 3c47b82a872c96..31c13d71ea4328 100644 --- a/Lib/test/test_capi/test_bytes.py +++ b/Lib/test/test_capi/test_bytes.py @@ -75,7 +75,7 @@ def test_fromstring(self): self.assertEqual(fromstring(b'abc\0def'), b'abc') self.assertEqual(fromstring(b''), b'') - # CRASHES fromstring(NULL) + # CRASHES fromstring(NULL) def test_fromobject(self): # Test PyBytes_FromObject() From 33e688ac5a7d14d97fd96aa017a5d5b81789c2b4 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 19 May 2025 11:25:53 -0400 Subject: [PATCH 3/8] Fix trailing whitespace --- Lib/test/test_capi/test_bytes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py index 31c13d71ea4328..906faf11747440 100644 --- a/Lib/test/test_capi/test_bytes.py +++ b/Lib/test/test_capi/test_bytes.py @@ -31,7 +31,7 @@ def test_check(self): self.assertFalse(check(object())) self.assertTrue(check(b'')) - # CRASHES check(NULL) #PyBytes_Check() expects PyObject* + # CRASHES check(NULL) def test_checkexact(self): # Test PyBytes_CheckExact() @@ -46,7 +46,7 @@ def test_checkexact(self): self.assertFalse(check(object())) self.assertTrue(check(b'')) - # CRASHES check(NULL) #PyBytes_CheckExact() expects PyObject* + # CRASHES check(NULL) def test_fromstringandsize(self): # Test PyBytes_FromStringAndSize() From 570a334e0b98316af477912c01ef76dc8466171f Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 19 May 2025 15:15:46 -0400 Subject: [PATCH 4/8] Reorder lines --- Lib/test/test_capi/test_bytes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py index 906faf11747440..86d5692893fc98 100644 --- a/Lib/test/test_capi/test_bytes.py +++ b/Lib/test/test_capi/test_bytes.py @@ -22,6 +22,7 @@ def test_check(self): # Test PyBytes_Check() check = _testlimitedcapi.bytes_check self.assertTrue(check(b'abc')) + self.assertTrue(check(b'')) self.assertFalse(check('abc')) self.assertFalse(check(bytearray(b'abc'))) self.assertTrue(check(BytesSubclass(b'abc'))) @@ -29,7 +30,6 @@ def test_check(self): self.assertFalse(check(3)) self.assertFalse(check([])) self.assertFalse(check(object())) - self.assertTrue(check(b'')) # CRASHES check(NULL) @@ -37,6 +37,7 @@ def test_checkexact(self): # Test PyBytes_CheckExact() check = _testlimitedcapi.bytes_checkexact self.assertTrue(check(b'abc')) + self.assertTrue(check(b'')) self.assertFalse(check('abc')) self.assertFalse(check(bytearray(b'abc'))) self.assertFalse(check(BytesSubclass(b'abc'))) @@ -44,7 +45,6 @@ def test_checkexact(self): self.assertFalse(check(3)) self.assertFalse(check([])) self.assertFalse(check(object())) - self.assertTrue(check(b'')) # CRASHES check(NULL) From 961818aff96aa6d4f290f9c4be98b5065a5e1a89 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 19 May 2025 19:30:43 -0400 Subject: [PATCH 5/8] Fix CI jobs with the same concurrency group being canceled Addresses issue encountered during PyCon US sprints where having multiple workflows with the same concurrency group causes one of the two to be canceled. Co-authored-by: Sviatoslav Sydorenko Co-authored-by: C.A.M. Gerlach --- .github/workflows/build.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b192508c78685c..2709cfef6d9d45 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,15 @@ permissions: contents: read concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-reusable + group: >- + ${{ + github.workflow + }}-${{ + github.ref_name + }}-${{ + github.event.pull_request.number + || github.sha + }} cancel-in-progress: true env: From ba70d90694d2620d00be6bb0c5b44096c035fe22 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 20 May 2025 00:10:28 -0400 Subject: [PATCH 6/8] Revert changes made on the wrong branch --- Lib/test/test_capi/test_bytes.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Lib/test/test_capi/test_bytes.py b/Lib/test/test_capi/test_bytes.py index 86d5692893fc98..5b61c73381542d 100644 --- a/Lib/test/test_capi/test_bytes.py +++ b/Lib/test/test_capi/test_bytes.py @@ -22,7 +22,6 @@ def test_check(self): # Test PyBytes_Check() check = _testlimitedcapi.bytes_check self.assertTrue(check(b'abc')) - self.assertTrue(check(b'')) self.assertFalse(check('abc')) self.assertFalse(check(bytearray(b'abc'))) self.assertTrue(check(BytesSubclass(b'abc'))) @@ -37,7 +36,6 @@ def test_checkexact(self): # Test PyBytes_CheckExact() check = _testlimitedcapi.bytes_checkexact self.assertTrue(check(b'abc')) - self.assertTrue(check(b'')) self.assertFalse(check('abc')) self.assertFalse(check(bytearray(b'abc'))) self.assertFalse(check(BytesSubclass(b'abc'))) @@ -110,7 +108,6 @@ def test_asstring(self): self.assertEqual(asstring(b'abc', 4), b'abc\0') self.assertEqual(asstring(b'abc\0def', 8), b'abc\0def\0') - self.assertEqual(asstring(b'', 1), b'\0') self.assertRaises(TypeError, asstring, 'abc', 0) self.assertRaises(TypeError, asstring, object(), 0) @@ -123,7 +120,6 @@ def test_asstringandsize(self): self.assertEqual(asstringandsize(b'abc', 4), (b'abc\0', 3)) self.assertEqual(asstringandsize(b'abc\0def', 8), (b'abc\0def\0', 7)) - self.assertEqual(asstringandsize(b'', 1), (b'\0', 0)) self.assertEqual(asstringandsize_null(b'abc', 4), b'abc\0') self.assertRaises(ValueError, asstringandsize_null, b'abc\0def', 8) self.assertRaises(TypeError, asstringandsize, 'abc', 0) @@ -167,7 +163,6 @@ def test_concat(self, concat=None): self.assertEqual(concat(b'', bytearray(b'def')), b'def') self.assertEqual(concat(memoryview(b'xabcy')[1:4], b'def'), b'abcdef') self.assertEqual(concat(b'abc', memoryview(b'xdefy')[1:4]), b'abcdef') - self.assertEqual(concat(b'', b''), b'') self.assertEqual(concat(b'abc', b'def', True), b'abcdef') self.assertEqual(concat(b'abc', bytearray(b'def'), True), b'abcdef') From 1073529058229c0bf8f99db24041c655e856c3c2 Mon Sep 17 00:00:00 2001 From: Kira Kaviani Date: Tue, 20 May 2025 21:38:04 -0400 Subject: [PATCH 7/8] Update CI fix & add descriptive comments Proposed different fix after doing some further testing. This ensures that concurrency workflows will have a unique name in any situation that triggers them, and better navigates some quirks in github actions. The improved comments should make it more visible how the naming works. Co-authored-by: Sviatoslav Sydorenko Co-authored-by: C.A.M. Gerlach --- .github/workflows/build.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2709cfef6d9d45..10ceb2a4b08716 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,15 +15,15 @@ permissions: contents: read concurrency: - group: >- - ${{ - github.workflow - }}-${{ - github.ref_name - }}-${{ - github.event.pull_request.number - || github.sha - }} + # For PRs, this names the group after the workflow ('Tests'), + # the PR number followed by '/merge', and the name of the branch being merged + # example: Tests-123456/merge-mycoolbranch + # + # For anything else that triggers this workflow, it names the group after + # the workflow ('Tests'), the branch, and the sha hash + # example: Tests-main-(40 char sha hash) + # + group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.head_ref || github.sha }} cancel-in-progress: true env: From 2a193c4b803716d6600499add6a435ce5629039b Mon Sep 17 00:00:00 2001 From: Kira Date: Wed, 21 May 2025 10:57:32 -0400 Subject: [PATCH 8/8] Incorporate the triggering actor in concurrency group name Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- .github/workflows/build.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10ceb2a4b08716..54ebc914b46821 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,15 +15,13 @@ permissions: contents: read concurrency: - # For PRs, this names the group after the workflow ('Tests'), - # the PR number followed by '/merge', and the name of the branch being merged - # example: Tests-123456/merge-mycoolbranch - # - # For anything else that triggers this workflow, it names the group after - # the workflow ('Tests'), the branch, and the sha hash - # example: Tests-main-(40 char sha hash) - # - group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.head_ref || github.sha }} + # https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#concurrency + # 'group' must be a key uniquely representing a PR or push event. + # github.workflow is the workflow name + # github.actor is the user invoking the workflow + # github.head_ref is the source branch of the PR or otherwise blank + # github.run_id is a unique number for the current run + group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true env: