hashlib-digest-hex (FURB181)
Derived from the refurb linter.
Fix is sometimes available.
What it does
Checks for the use of .digest().hex()
on a hashlib hash, like sha512
.
Why is this bad?
When generating a hex digest from a hash, it's preferable to use the
.hexdigest()
method, rather than calling .digest()
and then .hex()
,
as the former is more concise and readable.
Example
Use instead:
Fix safety
This rule's fix is marked as unsafe, as the target of the .digest()
call
could be a user-defined class that implements a .hex()
method, rather
than a hashlib hash object.