Skip to content

Commit 10d44a6

Browse files
committed
Conditionally import ssl
Saves >=10ms on irrelevant platforms.
1 parent f315671 commit 10d44a6

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/pip/_internal/utils/inject_securetransport.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@
77
old to handle TLSv1.2.
88
"""
99

10-
try:
11-
import ssl
12-
except ImportError:
13-
pass
14-
else:
15-
import sys
10+
import sys
1611

17-
# Checks for OpenSSL 1.0.1 on MacOS
18-
if sys.platform == "darwin" and ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
19-
try:
20-
from pip._vendor.urllib3.contrib import securetransport
21-
except (ImportError, OSError):
22-
pass
23-
else:
24-
securetransport.inject_into_urllib3()
12+
13+
# Only relevant on macOS
14+
if sys.platform == "darwin":
15+
try:
16+
import ssl
17+
except ImportError:
18+
pass
19+
else:
20+
# Checks for OpenSSL 1.0.1
21+
if ssl.OPENSSL_VERSION_NUMBER < 0x1000100f:
22+
try:
23+
from pip._vendor.urllib3.contrib import securetransport
24+
except (ImportError, OSError):
25+
pass
26+
else:
27+
securetransport.inject_into_urllib3()

0 commit comments

Comments
 (0)