Skip to content

Files

Latest commit

 

History

History
27 lines (18 loc) · 488 Bytes

invalid-bytes-returned.md

File metadata and controls

27 lines (18 loc) · 488 Bytes

Pattern: __bytes__ does not return bytes

Issue: -

Description

Used when a __bytes__ method returns something which is not bytes.

Example of incorrect code:

class BadBytes(object):
    """ __bytes__ returns bytes """

    def __bytes__(self):  # [invalid-bytes-returned]
        return "123"

Example of correct code:

class GoodBytes(object):
    """__bytes__ returns <type 'bytes'>"""

    def __bytes__(self):
        return b"some bytes"