Skip to content

Commit a3c810b

Browse files
committed
fix matching args
1 parent 65f187a commit a3c810b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Lib/test/test_secrets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_bad_types(self):
4444

4545
def test_bool(self):
4646
# Test that compare_digest returns a bool.
47-
print(secrets.compare_digest("abc", "abc"))
4847
self.assertIsInstance(secrets.compare_digest("abc", "abc"), bool)
4948
self.assertIsInstance(secrets.compare_digest("abc", "xyz"), bool)
5049

stdlib/src/hashlib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,17 @@ pub mod _hashlib {
307307
b: ArgStrOrBytesLike,
308308
vm: &VirtualMachine,
309309
) -> PyResult<PyObjectRef> {
310-
if a.get_enum_int() != b.get_enum_int() {
311-
return Err(vm.new_type_error(format!(
312-
"different types in compare_digest {} and {} ",
313-
a.get_enum(),
314-
b.get_enum()
315-
)));
310+
311+
fn is_str(arg: &ArgStrOrBytesLike) -> bool {
312+
matches!(arg, ArgStrOrBytesLike::Str(_))
313+
}
314+
315+
if is_str(&a) != is_str(&b) {
316+
let err_msg = format!(
317+
"a bytes-like object is required, not '{}'",
318+
b.as_object().class().name()
319+
);
320+
return Err(vm.new_type_error(err_msg));
316321
}
317322

318323
let a_hash = a.borrow_bytes().to_vec();

0 commit comments

Comments
 (0)