Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 526 Bytes

invalid-format-returned.md

File metadata and controls

27 lines (18 loc) · 526 Bytes

Pattern: __format__ does not return string

Issue: -

Description

Used when a __format__ method returns something which is not a string.

Example of incorrect code:

class BadFormat(object):
    """ __format__ returns bytes """

    def __format__(self, format_spec):  # [invalid-format-returned]
        return b"123"

Example of correct code:

class GoodFormat(object):
    """__format__ returns <type 'str'>"""

    def __format__(self, format_spec):
        return "some format"