Skip to content

hex() method behaves differently than the bytes type #14

@palkeo

Description

@palkeo

Hey,

The HexBytes type inherits from bytes, as can be seen in that code snippet:

>>> isinstance(HexBytes(b'\0'), bytes)
True

Because of that I would expect it to behave like bytes, only with added functionality but no breaking behavior.
However, it does add a 0x prefix:

>>> HexBytes(b'\0').hex()
'0x00'
>>> b'\0'.hex()
'00'

So if you pass HexBytes instance to well-behaved code that use the standard practice of checking isinstance(), this code would break.
I think it should either not inherit from bytes or not break existing bytes function, because this makes it confusing and likely to introduce bugs in existing code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions