Skip to content

⚡️ Speed up function _check_cryptography by 42% #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import urllib3

from .exceptions import RequestsDependencyWarning
from cryptography import __version__ as cryptography_version

try:
from charset_normalizer import __version__ as charset_normalizer_version
Expand Down Expand Up @@ -92,15 +93,16 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver

def _check_cryptography(cryptography_version):
# cryptography < 1.3.4
cryptography_version_list = cryptography_version.split(".")
if len(cryptography_version_list) != 3:
return
try:
cryptography_version = list(map(int, cryptography_version.split(".")))
major, minor, patch = map(int, cryptography_version_list)
except ValueError:
return

if cryptography_version < [1, 3, 4]:
warning = "Old version of cryptography ({}) may cause slowdown.".format(
cryptography_version
)
if (major, minor, patch) < (1, 3, 4):
warning = f"Old version of cryptography ({cryptography_version}) may cause slowdown."
warnings.warn(warning, RequestsDependencyWarning)


Expand Down