multiformats / multiformats/py-multihash
`decode()` error message uses broken format string
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17
- Forks
- 17
- Avg merge
- 1h 5m
- Merged PRs (30d)
- 3
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open multihash/multihash.py and inspect the decode() type check. Confirm the current TypeError prints the placeholder literally, then add the proposed regression test for a non-bytes argument. The work is done when the message includes the actual argument type and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100