KEMBAR78
Spurious error formatting bytes subclass with overridden __str__ · Issue #8180 · python/mypy · GitHub
Skip to content

Spurious error formatting bytes subclass with overridden __str__ #8180

@mystor

Description

@mystor
  • Please insert below the code you are checking with mypy.
class HexBytes(bytes):
    def __str__(self) -> str:
        return self.hex()

value = HexBytes(b"aaa")
print(f"{value}")
  • What is the actual behavior/output?
$ python3 mypy_bytes_subclass.py 
616161

$ mypy mypy_bytes_subclass.py 
mypy_bytes_subclass.py:6: error: On Python 3 '{}'.format(b'abc') produces "b'abc'"; use !r if this is a desired behavior
Found 1 error in 1 file (checked 1 source file)
  • What is the behavior/output you expect?

I would expect no error to be produced in this situation, as __str__ has been overridden, so the code does not exhibit the behaviour mentioned in the error.

  • What are the versions of mypy and Python you are using?
    Do you see the same issue after installing mypy from Git master?

mypy 0.760, python 3.7.5
The same issue appears with mypy-0.770+dev.e7866d0839202234db1f975a68a9284bb59d8544 (installed from git)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions