From 71be4853379411bdb96e387de588eebf32a86e1c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 04:29:26 +0000 Subject: [PATCH] refactor: remove assert statement from non-test files Usage of `assert` statement in application logic is discouraged. `assert` is removed with compiling to optimized byte code. Consider raising an exception instead. Ideally, `assert` statement should be used only in tests. --- src/requests/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/requests/__init__.py b/src/requests/__init__.py index 051cda1340..be00221203 100644 --- a/src/requests/__init__.py +++ b/src/requests/__init__.py @@ -57,7 +57,8 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_version): urllib3_version = urllib3_version.split(".") - assert urllib3_version != ["dev"] # Verify urllib3 isn't installed from git. + if urllib3_version == ["dev"]: # Verify urllib3 isn't installed from git. + raise AssertionError() # Sometimes, urllib3 only reports its version as 16.1. if len(urllib3_version) == 2: @@ -67,21 +68,25 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver major, minor, patch = urllib3_version # noqa: F811 major, minor, patch = int(major), int(minor), int(patch) # urllib3 >= 1.21.1 - assert major >= 1 + if major < 1: + raise AssertionError() if major == 1: - assert minor >= 21 + if minor < 21: + raise AssertionError() # Check charset_normalizer for compatibility. if chardet_version: major, minor, patch = chardet_version.split(".")[:3] major, minor, patch = int(major), int(minor), int(patch) # chardet_version >= 3.0.2, < 6.0.0 - assert (3, 0, 2) <= (major, minor, patch) < (6, 0, 0) + if not ((3, 0, 2) <= (major, minor, patch) < (6, 0, 0)): + raise AssertionError() elif charset_normalizer_version: major, minor, patch = charset_normalizer_version.split(".")[:3] major, minor, patch = int(major), int(minor), int(patch) # charset_normalizer >= 2.0.0 < 4.0.0 - assert (2, 0, 0) <= (major, minor, patch) < (4, 0, 0) + if not ((2, 0, 0) <= (major, minor, patch) < (4, 0, 0)): + raise AssertionError() else: warnings.warn( "Unable to find acceptable character detection dependency "