From 541018ba1f2be5fc22c9f6a3bac465f23b2cf18f Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 12 Mar 2024 20:55:18 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=92=85=20Address=20all=20instances=20?= =?UTF-8?q?of=20`BytesWarning`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Things like byte-to-int comparisons and interpolation of bytes into str were present in the code base. This patch fixes that by making sure that the variables are always of compatible types in these cases. --- cheroot/server.py | 6 +++++- cheroot/test/test_conn.py | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cheroot/server.py b/cheroot/server.py index bceeb2c95a..cd1cdc75d9 100644 --- a/cheroot/server.py +++ b/cheroot/server.py @@ -209,7 +209,11 @@ def __call__(self, rfile, hdict=None): # noqa: C901 # FIXME if not line.endswith(CRLF): raise ValueError('HTTP requires CRLF terminators') - if line[0] in (SPACE, TAB): + if line[:1] in (SPACE, TAB): + # NOTE: `type(line[0]) is int` and `type(line[:1]) is bytes`. + # NOTE: The former causes a the following warning: + # NOTE: `BytesWarning('Comparison between bytes and int')` + # NOTE: The latter is equivalent and does not. # It's a continuation line. v = line.strip() else: diff --git a/cheroot/test/test_conn.py b/cheroot/test/test_conn.py index b5e9c418f9..38a6245715 100644 --- a/cheroot/test/test_conn.py +++ b/cheroot/test/test_conn.py @@ -53,7 +53,8 @@ def upload(req, resp): "'POST' != request.method %r" % req.environ['REQUEST_METHOD'], ) - return "thanks for '%s'" % req.environ['wsgi.input'].read() + input_contents = req.environ['wsgi.input'].read().decode('utf-8') + return f"thanks for '{input_contents !s}'" def custom_204(req, resp): """Render response with status 204.""" @@ -917,7 +918,7 @@ def test_100_Continue(test_client): status_line, _actual_headers, actual_resp_body = webtest.shb(response) actual_status = int(status_line[:3]) assert actual_status == 200 - expected_resp_body = ("thanks for '%s'" % body).encode() + expected_resp_body = f"thanks for '{body.decode() !s}'".encode() assert actual_resp_body == expected_resp_body conn.close() @@ -987,7 +988,7 @@ def test_readall_or_close(test_client, max_request_body_size): status_line, actual_headers, actual_resp_body = webtest.shb(response) actual_status = int(status_line[:3]) assert actual_status == 200 - expected_resp_body = ("thanks for '%s'" % body).encode() + expected_resp_body = f"thanks for '{body.decode() !s}'".encode() assert actual_resp_body == expected_resp_body conn.close() From f011b8e5eb176c812d8915ad70e6b814c608e11e Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Tue, 12 Mar 2024 21:22:31 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A7=AA=20Stop=20tagging=20codecov=20u?= =?UTF-8?q?ploads=20w/=20wheel=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This seems to be what's breaking the uploader. It's likely because it's getting too long for Codecov to handle. --- .github/workflows/ci-cd.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ae5f7ebc21..f427a7d9ea 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -909,8 +909,7 @@ jobs: }}, Py-${{ steps.python-install.outputs.python-version - }}, - ${{ needs.pre-setup.outputs.wheel-artifact-name }} + }} check: # This job does nothing and is only used for the branch protection if: always()