From: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Date: Sat, 28 Jun 2025 08:15:49 +0000 (+0200) Subject: [3.13] gh-135571: Guard `_hashlib` usage in `test_hashlib.py` (GH-135572) (#136041) X-Git-Tag: v3.13.6~160 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d3bcecdcdbbc4bef1fbca8bcaeaa043a645c0e1e;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-135571: Guard `_hashlib` usage in `test_hashlib.py` (GH-135572) (#136041) (cherry picked from commit 065194c1a971b59547f1bb2cc64760c4bf0ee674) Co-authored-by: Will Childs-Klein --- diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 56d2f7002123..8eb0ac230bc7 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -264,7 +264,10 @@ class HashLibTestCase(unittest.TestCase): hashlib.new(digest_name, b'') hashlib.new(digest_name, data=b'') hashlib.new(digest_name, string=b'') - if self._hashlib: + # Make sure that _hashlib contains the constructor + # to test when using a combination of libcrypto and + # interned hash implementations. + if self._hashlib and digest_name in self._hashlib._constructors: self._hashlib.new(digest_name, b'') self._hashlib.new(digest_name, data=b'') self._hashlib.new(digest_name, string=b'') @@ -316,7 +319,8 @@ class HashLibTestCase(unittest.TestCase): with self.subTest(digest_name, args=args, kwds=kwds): with self.assertRaisesRegex(TypeError, errmsg): hashlib.new(digest_name, *args, **kwds) - if self._hashlib: + if (self._hashlib and + digest_name in self._hashlib._constructors): with self.assertRaisesRegex(TypeError, errmsg): self._hashlib.new(digest_name, *args, **kwds)