The TypeError in decode() uses "multihash should be bytes, not {}" without an f-string prefix, so the {} is printed literally instead of being replaced with the actual type.
Problem
In multihash/multihash.py, the decode() function:
def decode(multihash):
if not isinstance(multihash, bytes):
raise TypeError("multihash should be bytes, not {}", type(multihash))
# ↑ Missing 'f' prefix — {} is literal
When called with a non-bytes argument:
>>> decode("not bytes")
TypeError: multihash should be bytes, not {}
# Expected: TypeError: multihash should be bytes, not <class 'str'>
Proposed Solution
Fix the f-string:
def decode(multihash):
if not isinstance(multihash, bytes):
raise TypeError(f"multihash should be bytes, not {type(multihash)}")
Add a test:
def test_decode_type_error_message():
with pytest.raises(TypeError, match="multihash should be bytes, not"):
decode("not bytes")
Related
- File:
multihash/multihash.py, decode() function
The
TypeErrorindecode()uses"multihash should be bytes, not {}"without an f-string prefix, so the{}is printed literally instead of being replaced with the actual type.Problem
In
multihash/multihash.py, thedecode()function:When called with a non-bytes argument:
Proposed Solution
Fix the f-string:
Add a test:
Related
multihash/multihash.py,decode()function