Skip to content

Commit a30cf41

Browse files
committed
rework the conditional import for all its attrs
1 parent 5ae0915 commit a30cf41

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Lib/test/test_hashlib.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@
4040
openssl_hashlib = import_fresh_module('hashlib', fresh=['_hashlib'])
4141

4242
try:
43-
from _hashlib import HASH
43+
import _hashlib
4444
except ImportError:
45-
HASH = None
46-
47-
try:
48-
from _hashlib import HASHXOF, openssl_md_meth_names, get_fips_mode
49-
except ImportError:
50-
HASHXOF = None
51-
openssl_md_meth_names = frozenset()
52-
45+
_hashlib = None
46+
# The extension module may exist but only define some of these. gh-141907
47+
HASH = getattr(_hashlib, 'HASH', None)
48+
HASHXOF = getattr(_hashlib, 'HASHXOF', None)
49+
openssl_md_meth_names = getattr(_hashlib, 'openssl_md_meth_names', frozenset())
50+
get_fips_mode = getattr(_hashlib, 'get_fips_mode', None)
51+
if not get_fips_mode:
5352
def get_fips_mode():
5453
return 0
5554

0 commit comments

Comments
 (0)