multiformats / multiformats/py-multihash

`decode()` error message uses broken format string

Open Beginner friendly
#47 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.