From 645e2172c3c777f0d01014ebaf4adfdf849c1692 Mon Sep 17 00:00:00 2001 From: CPython Developers <> Date: Sat, 14 Feb 2026 05:45:49 +0000 Subject: [PATCH 1/2] Update hmac from v3.14.3 --- Lib/hmac.py | 1 + Lib/test/test_hmac.py | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Lib/hmac.py b/Lib/hmac.py index 16022c9ceb5..2d6016cda11 100644 --- a/Lib/hmac.py +++ b/Lib/hmac.py @@ -159,6 +159,7 @@ def copy(self): # Call __new__ directly to avoid the expensive __init__. other = self.__class__.__new__(self.__class__) other.digest_size = self.digest_size + other.block_size = self.block_size if self._hmac: other._hmac = self._hmac.copy() other._inner = other._outer = None diff --git a/Lib/test/test_hmac.py b/Lib/test/test_hmac.py index d5023a6c1b3..3c91a1083a5 100644 --- a/Lib/test/test_hmac.py +++ b/Lib/test/test_hmac.py @@ -1066,6 +1066,14 @@ def test_hmac_digest_digestmod_parameter(self): ): self.hmac_digest(b'key', b'msg', value) + @unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'HMAC'. Did you mean: 'exc_type'? + def test_internal_types(self): + return super().test_internal_types() + + @unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'hmac_digest' + def test_digest(self): + return super().test_digest() + @unittest.expectedFailure # TODO: RUSTPYTHON def test_constructor(self): return super().test_constructor() @@ -1078,14 +1086,6 @@ def test_constructor_missing_digestmod(self): def test_constructor_unknown_digestmod(self): return super().test_constructor_unknown_digestmod() - @unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'HMAC'. Did you mean: 'exc_type'? - def test_internal_types(self): - return super().test_internal_types() - - @unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'hmac_digest' - def test_digest(self): - return super().test_digest() - class BuiltinConstructorTestCase(ThroughBuiltinAPIMixin, ExtensionConstructorTestCaseMixin, @@ -1137,6 +1137,15 @@ def test_properties(self): self.assertEqual(h.digest_size, self.digest_size) self.assertEqual(h.block_size, self.block_size) + def test_copy(self): + # Test a generic copy() and the attributes it exposes. + # See https://github.com/python/cpython/issues/142451. + h1 = self.hmac_new(b"my secret key", digestmod=self.digestname) + h2 = h1.copy() + self.assertEqual(h1.name, h2.name) + self.assertEqual(h1.digest_size, h2.digest_size) + self.assertEqual(h1.block_size, h2.block_size) + def test_repr(self): # HMAC object representation may differ across implementations raise NotImplementedError @@ -1160,7 +1169,6 @@ def test_repr(self): @hashlib_helper.requires_openssl_hashdigest('sha256') -@unittest.skip("TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'HMAC'") class OpenSSLSanityTestCase(ThroughOpenSSLAPIMixin, SanityTestCaseMixin, unittest.TestCase): @@ -1257,10 +1265,6 @@ def HMAC(self, key, msg=None): def gil_minsize(self): return _hashlib._GIL_MINSIZE - @unittest.expectedFailure # TODO: RUSTPYTHON - def test_update(self): - return super().test_update() - @unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute '_GIL_MINSIZE' def test_update_large(self): return super().test_update_large() @@ -1269,6 +1273,10 @@ def test_update_large(self): def test_update_exceptions(self): return super().test_update_exceptions() + @unittest.expectedFailure # TODO: RUSTPYTHON + def test_update(self): + return super().test_update() + class BuiltinUpdateTestCase(BuiltinModuleMixin, UpdateTestCaseMixin, unittest.TestCase): From 2ef592f4b6f0da6a586309966930e1d266cc1434 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 14 Feb 2026 13:01:35 +0000 Subject: [PATCH 2/2] Auto-format: cargo fmt --all --- crates/stdlib/src/hashlib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/stdlib/src/hashlib.rs b/crates/stdlib/src/hashlib.rs index 5a2a55b93a7..27e435725a1 100644 --- a/crates/stdlib/src/hashlib.rs +++ b/crates/stdlib/src/hashlib.rs @@ -701,9 +701,8 @@ pub mod _hashlib { if len < 1 { return Err(vm.new_value_error("key length must be greater than 0.".to_owned())); } - usize::try_from(len).map_err(|_| { - vm.new_overflow_error("key length is too great.".to_owned()) - })? + usize::try_from(len) + .map_err(|_| vm.new_overflow_error("key length is too great.".to_owned()))? } None => hash_digest_size(&name).ok_or_else(|| unsupported_hash(&name, vm))?, };